diff --git a/App.vue b/App.vue index 0e512da..e8a9f2d 100644 --- a/App.vue +++ b/App.vue @@ -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', + }, } + }; diff --git a/cloudfunctions-aliyun/api/index.js b/cloudfunctions-aliyun/api/index.js new file mode 100644 index 0000000..f64353b --- /dev/null +++ b/cloudfunctions-aliyun/api/index.js @@ -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() +}; diff --git a/cloudfunctions-aliyun/api/models/home.js b/cloudfunctions-aliyun/api/models/home.js new file mode 100644 index 0000000..4736505 --- /dev/null +++ b/cloudfunctions-aliyun/api/models/home.js @@ -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; diff --git a/cloudfunctions-aliyun/api/package-lock.json b/cloudfunctions-aliyun/api/package-lock.json new file mode 100644 index 0000000..30861e8 --- /dev/null +++ b/cloudfunctions-aliyun/api/package-lock.json @@ -0,0 +1,11 @@ +{ + "name": "api", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "response": { + "version": "file:../common/response" + } + } +} diff --git a/cloudfunctions-aliyun/api/package.json b/cloudfunctions-aliyun/api/package.json new file mode 100644 index 0000000..2688678 --- /dev/null +++ b/cloudfunctions-aliyun/api/package.json @@ -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" + } +} diff --git a/cloudfunctions-aliyun/common/response/index.js b/cloudfunctions-aliyun/common/response/index.js new file mode 100644 index 0000000..018a092 --- /dev/null +++ b/cloudfunctions-aliyun/common/response/index.js @@ -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, + } +} \ No newline at end of file diff --git a/cloudfunctions-aliyun/common/response/package.json b/cloudfunctions-aliyun/common/response/package.json new file mode 100644 index 0000000..4afbcab --- /dev/null +++ b/cloudfunctions-aliyun/common/response/package.json @@ -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" +} diff --git a/cloudfunctions-aliyun/db_init.json b/cloudfunctions-aliyun/db_init.json new file mode 100644 index 0000000..49557d3 --- /dev/null +++ b/cloudfunctions-aliyun/db_init.json @@ -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 + } + } + } +} diff --git a/examples/微信图片_20201107165410.png b/examples/微信图片_20201107165410.png new file mode 100644 index 0000000..1f11951 Binary files /dev/null and b/examples/微信图片_20201107165410.png differ diff --git a/examples/微信图片_20201107165417.jpg b/examples/微信图片_20201107165417.jpg new file mode 100644 index 0000000..6cd5b04 Binary files /dev/null and b/examples/微信图片_20201107165417.jpg differ diff --git a/manifest.json b/manifest.json index 5d2e83d..d6c174f 100644 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,6 @@ { "name" : "外卖专享优惠", - "appid" : "", + "appid" : "__UNI__45597DA", "description" : "", "versionName" : "1.0.0", "versionCode" : "100", @@ -42,7 +42,7 @@ }, "quickapp" : {}, "mp-weixin" : { - "appid" : "", + "appid" : "wx2a191430f31c00f1", "setting" : { "urlCheck" : true } diff --git a/pages/index/index.vue b/pages/index/index.vue index 1905ae6..293ae6a 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -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 @@ -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)]; }, @@ -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) + } + }); } } }; @@ -210,6 +150,7 @@ page { } .coupon { padding-top: 200rpx; + padding-bottom: 10rpx; .item { background-color: #ffffff; margin: 30rpx;