Skip to content

Commit

Permalink
新增云开发
Browse files Browse the repository at this point in the history
  • Loading branch information
zwpro committed Nov 30, 2020
1 parent ada8417 commit 8030966
Show file tree
Hide file tree
Showing 12 changed files with 220 additions and 96 deletions.
6 changes: 6 additions & 0 deletions App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ export default {
},
onHide: function() {
console.log('App Hide');
},
globalData: {
api: {
home: 'https://055cfd20-bfe4-4b9a-be9d-f7c2cac59a57.bspapp.com/http/api/home',
},
}
};
</script>

Expand Down
23 changes: 23 additions & 0 deletions cloudfunctions-aliyun/api/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';
const response = require('response')
const homeModel = require('./models/home')
exports.main = async (event, context) => {
//event为客户端上传的参数
console.log('event : ', event)
var resp = {}
//简单路由判断
switch (event.path) {
//首页
case '/home':
var homeModelTabs = await homeModel.tabs()
resp.tabs = homeModelTabs.data
var homeModelCoupons = await homeModel.coupons()
resp.coupons = homeModelCoupons.data
return response.success(resp)
break;
default:

}
//返回数据给客户端
return response.success()
};
14 changes: 14 additions & 0 deletions cloudfunctions-aliyun/api/models/home.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const db = uniCloud.database();

var home = {
tabs: () => {
let tabs = db.collection('tab').get();
return tabs
},
coupons: () => {
let coupons = db.collection('coupon').get();
return coupons
},
}

module.exports = home;
11 changes: 11 additions & 0 deletions cloudfunctions-aliyun/api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions cloudfunctions-aliyun/api/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "api",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"response": "file:../common/response"
}
}
14 changes: 14 additions & 0 deletions cloudfunctions-aliyun/common/response/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
exports.success = (data = null, msg = 'success', code = 200) => {
return {
data,
msg,
code,
}
}
exports.error = (data = null, msg = 'fail', code = 400) => {
return {
data,
msg,
code,
}
}
12 changes: 12 additions & 0 deletions cloudfunctions-aliyun/common/response/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "response",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
88 changes: 88 additions & 0 deletions cloudfunctions-aliyun/db_init.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// 在本文件中可配置云数据库初始化,数据格式见:https://uniapp.dcloud.io/uniCloud/cf-database?id=db_init

// 编写完毕后对本文件点右键,可按配置规则创建表和添加数据

{
"coupon": { // 集合(表名)
"data": [ // 数据
{
"name": "饿了么红包",
"icon": "/static/coupon/ele.png",
"bannerPic": "/static/coupon/ele_banner.png",
"url": "https://s.click.ele.me/frZOjvu",
"type": 1,
"tabId": 1,
"minapp": {
"appid": "wxece3a9a4c82f58c9",
"path": "pages/sharePid/web/index?scene=https://s.click.ele.me/wR9ecuu"
}
},
{
"name": "美团外卖红包",
"icon": "/static/coupon/meituan.png",
"bannerPic": "/static/coupon/meituan_banner.png",
"url": "https://runion.meituan.com/url?key=cd23768d09c339d1641b2738df39aa67&url=https%3A%2F%2Fi.meituan.com%2Fawp%2Fhfe%2Fblock%2Fa945391288b790d558b7%2F78716%2Findex.html%3Fappkey%3Dcd23768d09c339d1641b2738df39aa67%3Ajuhe&sid=juhe",
"type": 1,
"tabId": 2,
"minapp": {
"appid": "wxde8ac0a21135c07d",
"path": "/index/pages/h5/h5?weburl=https%3A%2F%2Frunion.meituan.com%2Furl%3Fkey%3D591ec05930c57331c1212b936e6785c1%26url%3Dhttps%253A%252F%252Fi.meituan.com%252Fawp%252Fhfe%252Fblock%252Fa13b87919a9ace9cfab4%252F89400%252Findex.html%253Fappkey%253D591ec05930c57331c1212b936e6785c1%253A000001%26sid%3D000001&lch=cps:waimai:5:591ec05930c57331c1212b936e6785c1:000001&f_token=1&f_userId=1"
}
},
{
"name": "三只松鼠大礼包",
"icon": "/static/coupon/jd.png",
"bannerPic": "/static/coupon/sanzhisongshu.png",
"url":"https://u.jd.com/tFDejq",
"type": 0,
"tabId": 3,
"minapp": {
"appid": "wx91d27dbf599dff74",
"path": "pages/proxy/union/union"
}
}
],
"schema": {
"bsonType": "object",
"permission": {
".read": true,
".create": false,
".update": false,
".delete": false
}
}
},
"tab": { // 集合(表名)
"data": [ // 数据
{
"icon": "/static/all.png",
"text": "全部",
"tabId": 0
},
{
"icon": "/static/ele.png",
"text": "饿了么",
"tabId": 1
},
{
"icon": "/static/meituan.png",
"text": "美团",
"tabId": 2
},
{
"icon": "/static/jd.png",
"text": "京东",
"tabId": 3
}
],
"schema": {
"bsonType": "object",
"permission": {
".read": true,
".create": false,
".update": false,
".delete": false
}
}
}
}
Binary file added examples/微信图片_20201107165410.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/微信图片_20201107165417.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name" : "外卖专享优惠",
"appid" : "",
"appid" : "__UNI__45597DA",
"description" : "",
"versionName" : "1.0.0",
"versionCode" : "100",
Expand Down Expand Up @@ -42,7 +42,7 @@
},
"quickapp" : {},
"mp-weixin" : {
"appid" : "",
"appid" : "wx2a191430f31c00f1",
"setting" : {
"urlCheck" : true
}
Expand Down
129 changes: 35 additions & 94 deletions pages/index/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,104 +25,13 @@ export default {
data() {
return {
current: 0,
tabs: [
{
icon: '/static/all.png',
text: '全部',
tabId: 0,
},
{
icon: '/static/ele.png',
text: '饿了么',
tabId: 1,
},
{
icon: '/static/meituan.png',
text: '美团',
tabId: 2,
},
{
icon: '/static/11.png',
text: '双十一',
tabId: 5,
},
{
icon: '/static/jd.png',
text: '京东',
tabId: 3,
},
{
icon: '/static/vip.png',
text: 'VIP会员',
tabId: 4,
}
],
tabs: [],
couponList: [],
coupons: [
{
name: '饿了么红包',
icon: '/static/coupon/ele.png',
bannerPic: '/static/coupon/ele_banner.png',
url: 'https://s.click.ele.me/frZOjvu',
type: 1,
tabId: 1,
minapp: {
appid: 'wxece3a9a4c82f58c9',
path: 'pages/sharePid/web/index?scene=https://s.click.ele.me/wR9ecuu'
}
},
{
name: '美团外卖红包',
icon: '/static/coupon/meituan.png',
bannerPic: '/static/coupon/meituan_banner.png',
url:'https://runion.meituan.com/url?key=cd23768d09c339d1641b2738df39aa67&url=https%3A%2F%2Fi.meituan.com%2Fawp%2Fhfe%2Fblock%2Fa945391288b790d558b7%2F78716%2Findex.html%3Fappkey%3Dcd23768d09c339d1641b2738df39aa67%3Ajuhe&sid=juhe',
type: 1,
tabId: 2,
minapp: {
appid: 'wxde8ac0a21135c07d',
path: '/index/pages/h5/h5?weburl=https%3A%2F%2Frunion.meituan.com%2Furl%3Fkey%3D591ec05930c57331c1212b936e6785c1%26url%3Dhttps%253A%252F%252Fi.meituan.com%252Fawp%252Fhfe%252Fblock%252Fa13b87919a9ace9cfab4%252F89400%252Findex.html%253Fappkey%253D591ec05930c57331c1212b936e6785c1%253A000001%26sid%3D000001&lch=cps:waimai:5:591ec05930c57331c1212b936e6785c1:000001&f_token=1&f_userId=1'
}
},
{
name: '爱奇艺会员',
icon: '/static/coupon/vip.png',
bannerPic: '/static/coupon/vip_banner.png',
url:'https://p.pinduoduo.com/VJ7bHo5d',
type: 2,
tabId: 4
},
{
name: '三只松鼠大礼包',
icon: '/static/coupon/jd.png',
bannerPic: '/static/coupon/sanzhisongshu.png',
url:'https://u.jd.com/tFDejq',
type: 0,
tabId: 3
},
{
name: '饿了么果蔬',
icon: '/static/coupon/ele.png',
bannerPic: '/static/coupon/ele_guosu.png',
url:'https://s.click.ele.me/RpRFhvu',
type: 1,
tabId: 1,
minapp: {
appid: 'wxece3a9a4c82f58c9',
path: 'pages/sharePid/web/index?scene=https://s.click.ele.me/I4Yacuu'
}
},
{
name: '抽红包立减',
icon: '/static/11.png',
bannerPic: '/static/coupon/11.jpg',
url:'https://s.click.taobao.com/Gcs9vuu',
type: 2,
tabId: 5
},
]
coupons: []
};
},
onLoad(e) {
this.getHome()
//#ifdef H5
let tabId = this.$route.query.tabId ? parseInt(this.$route.query.tabId) : 0
//#endif
Expand All @@ -143,6 +52,27 @@ export default {
},{
title: '吃了这么多年外卖,你知道这个秘密吗?',
path: '/pages/index/index'
},{
title: '这样点外卖,一年省下一个亿',
path: '/pages/index/index'
},{
title: '点外卖前先领券,吃霸王餐',
path: '/pages/index/index'
},{
title: '美团饿了么内部优惠券,手慢无',
path: '/pages/index/index'
},{
title: '点外卖不用优惠券,你就out了',
path: '/pages/index/index'
},{
title: '外卖不为人知的秘密,点这解密',
path: '/pages/index/index'
},{
title: '震惊!小伙点外卖竟然花了1分钱',
path: '/pages/index/index'
},{
title: '从这点外卖,你也可以吃霸王餐',
path: '/pages/index/index'
}];
return messages[Math.floor(Math.random()*messages.length)];
},
Expand Down Expand Up @@ -189,6 +119,16 @@ export default {
})
}
//#endif
},
getHome(){
uni.request({
url: getApp().globalData.api.home,
success: (res) => {
this.tabs = res.data.data.tabs
this.coupons = res.data.data.coupons
this.changeTab(0)
}
});
}
}
};
Expand All @@ -210,6 +150,7 @@ page {
}
.coupon {
padding-top: 200rpx;
padding-bottom: 10rpx;
.item {
background-color: #ffffff;
margin: 30rpx;
Expand Down

0 comments on commit 8030966

Please sign in to comment.