Skip to content

Commit 5753787

Browse files
committed
feat: add cart page
1 parent 85ed6c2 commit 5753787

File tree

11 files changed

+272
-8
lines changed

11 files changed

+272
-8
lines changed

cloudfunctions/updateViews/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ const cloud = require('wx-server-sdk')
22
cloud.init()
33
const db = cloud.database()
44
const _ = db.command
5-
const collection = db.collection('cookbook_views')
5+
const collection = db.collection('views')
66

77
// 云函数入口函数
88
exports.main = async (event) => {
9-
const { id } = event;
9+
const { id, type = 'cookbook' } = event;
1010
const { stats } = await collection.where({ id }).update({
1111
data: {
1212
views: _.inc(1)
@@ -17,7 +17,8 @@ exports.main = async (event) => {
1717
data: {
1818
id,
1919
createTime: new Date(),
20-
views: 1
20+
views: 1,
21+
type
2122
}
2223
})
2324
}

miniprogram/app.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"pages/changelog/index",
88
"pages/changelog/detail",
99
"pages/learn/index",
10-
"pages/learn/detail"
10+
"pages/learn/detail",
11+
"pages/cart/index"
1112
],
1213
"window": {
1314
"backgroundColor": "#f6f6f6",

miniprogram/pages/cart/index.js

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
// pages/cart/index.js
2+
Page({
3+
4+
/**
5+
* 页面的初始数据
6+
*/
7+
data: {
8+
list: [{
9+
name: 'pupu',
10+
logo: 'pupu.webp',
11+
title: '朴朴',
12+
desc: '朴朴一下,又快又好',
13+
appid: 'wx122ef876a7132eb4',
14+
tag: '生鲜电商'
15+
}, {
16+
name: 'dingdong',
17+
logo: 'dingdong.jpeg',
18+
title: '叮咚买菜',
19+
desc: '让美好的食材像自来水一样',
20+
appid: 'wx1e113254eda17715',
21+
tag: '生鲜电商'
22+
}, {
23+
name: 'qixian',
24+
logo: 'qixian.jpeg',
25+
title: '京东七鲜',
26+
desc: '好生活,七鲜',
27+
appid: 'wxb8c24a764d1e1e6d',
28+
tag: '生鲜电商'
29+
}, {
30+
name: 'baiguoyuan',
31+
logo: 'baiguoyuan.jpeg',
32+
title: '百果园+',
33+
desc: '🐼 熊猫大鲜,品质生鲜超市',
34+
appid: 'wx1f9ea355b47256dd',
35+
tag: '生鲜电商'
36+
}, {
37+
name: 'meituan',
38+
logo: 'meituan.jpeg',
39+
title: '美团',
40+
desc: '帮大家吃得更好,生活更好',
41+
appid: 'wxde8ac0a21135c07d',
42+
tag: '生鲜电商'
43+
}, {
44+
name: 'meiriyouxian',
45+
logo: 'meiriyouxian.jpeg',
46+
title: '每日优鲜',
47+
desc: '每日供应优质新鲜食材',
48+
appid: 'wxebf773691904eee9',
49+
tag: '生鲜电商'
50+
}, {
51+
name: 'qiandama',
52+
logo: 'qiandama.jpeg',
53+
title: '钱大妈',
54+
desc: '新鲜不隔夜,天亮即出发',
55+
appid: 'wx94679e209a2b069d',
56+
tag: '生鲜电商'
57+
}, {
58+
name: 'tianhong',
59+
logo: 'tianhong.jpeg',
60+
title: '天虹',
61+
desc: '综合超市',
62+
appid: 'wx83b25ac313aea733',
63+
tag: '综合商超'
64+
}, {
65+
name: 'baijiahua',
66+
logo: 'baijiahua.jpeg',
67+
title: '百佳华',
68+
desc: '精选50多个国家和地区优质商品',
69+
appid: 'wx3cdd1f26cc0c7b25',
70+
tag: '综合商超'
71+
}, {
72+
name: 'jialefu',
73+
logo: 'jialefu.jpeg',
74+
title: '家乐福',
75+
desc: '苏宁易购旗下综合超市',
76+
appid: 'wxbff87cc25bc11305',
77+
tag: '综合商超'
78+
}, {
79+
name: 'yonghui',
80+
logo: 'yonghui.jpeg',
81+
title: '永辉生活',
82+
desc: '新鲜蔬果肉禽,食品百货,应用尽有',
83+
appid: 'wxc9cf7c95499ee604',
84+
tag: '综合商超'
85+
}, {
86+
name: 'woerma',
87+
logo: 'woerma.jpeg',
88+
title: '沃尔玛',
89+
desc: '一家美国的世界性连锁企业',
90+
appid: 'wx83231ee9993066b7',
91+
tag: '综合商超'
92+
}, {
93+
name: 'yongwang',
94+
logo: 'yongwang.jpeg',
95+
title: '永旺',
96+
desc: '日本著名零售集团公司',
97+
appid: 'wx55996449c48dd8c7',
98+
tag: '综合商超'
99+
}, {
100+
name: 'shanmu',
101+
logo: 'shanmu.jpeg',
102+
title: '山姆',
103+
desc: '美国沃尔玛旗下高端会员制商店',
104+
appid: 'wxb344a8513eaaf849',
105+
tag: '综合商超'
106+
}, {
107+
name: 'jingxi',
108+
logo: 'jingxi.jpeg',
109+
title: '京喜拼拼',
110+
desc: '京东旗下生活消费商城',
111+
appid: 'wxf95d0d80e9d5bfc0',
112+
tag: '社区电商'
113+
}, {
114+
name: 'xingsheng',
115+
logo: 'xingsheng.jpeg',
116+
title: '兴盛优选',
117+
desc: '一家有温度的社区电商',
118+
appid: 'wx6025c5470c3cb50c',
119+
tag: '社区电商'
120+
}, {
121+
name: 'tudigong',
122+
logo: 'tudigong.jpeg',
123+
title: '土地公',
124+
desc: '花更少的钱 享美好生活',
125+
appid: 'wx264657535896c762',
126+
tag: '社区电商'
127+
}],
128+
value: 'cart',
129+
tabbars: [{
130+
text: '首页',
131+
value: 'index',
132+
icon: 'home'
133+
}, {
134+
text: '买菜',
135+
value: 'cart',
136+
icon: 'cart'
137+
}, {
138+
text: '技巧',
139+
value: 'learn',
140+
icon: 'tips'
141+
}, {
142+
text: '个人中心',
143+
value: 'my',
144+
icon: 'user'
145+
}]
146+
},
147+
148+
onShow: function (options) {
149+
const arr = wx.getStorageSync('miniprogram_clicked') || []
150+
const { list } = this.data;
151+
152+
if (arr.length > 0) {
153+
arr.forEach(appid => {
154+
const target = list.find(item => item.appid == appid)
155+
if (target) {
156+
target.clicked = true
157+
}
158+
})
159+
list.sort(item => item.clicked ? -1 : 1)
160+
}
161+
162+
this.setData({ list })
163+
},
164+
165+
handleRedirect({ currentTarget }) {
166+
const { appid } = currentTarget.dataset;
167+
168+
wx.navigateToMiniProgram({
169+
appId: appid
170+
}).then(() => {
171+
this.updateViews(appid)
172+
this.storageAction(appid)
173+
}).catch(err => {
174+
console.log(err);
175+
})
176+
},
177+
178+
storageAction(appid) {
179+
const arr = wx.getStorageSync('miniprogram_clicked') || []
180+
181+
if (arr.indexOf(appid) > -1) return;
182+
183+
arr.push(appid)
184+
wx.setStorageSync('miniprogram_clicked', arr)
185+
},
186+
187+
handleTabbarChange({ detail }) {
188+
const { value } = detail;
189+
190+
wx.redirectTo({
191+
url: `../${value}/index`
192+
})
193+
},
194+
195+
updateViews(appid) {
196+
wx.cloud.callFunction({
197+
name: 'updateViews',
198+
data: {
199+
id: appid,
200+
type: 'miniprogram'
201+
},
202+
})
203+
},
204+
205+
onShareAppMessage() {
206+
return {
207+
title: '所有的买菜 APP 尽在这里',
208+
path: '/pages/cart/index'
209+
}
210+
},
211+
})

miniprogram/pages/cart/index.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"usingComponents": {}
3+
}

miniprogram/pages/cart/index.less

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.logo {
2+
width: 100rpx;
3+
height: 100rpx;
4+
border-radius: 50%;
5+
}
6+
7+
.container {
8+
padding: 48rpx 0 200rpx;
9+
}
10+
11+
.tags {
12+
display: flex;
13+
flex-direction: row;
14+
}

miniprogram/pages/cart/index.wxml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
<view class="container">
3+
<block wx:for="{{list}}" wx:key="index">
4+
<t-cell title="{{item.title}}" description="{{item.desc}}" data-appid="{{item.appid}}" bind:click="handleRedirect" arrow hover>
5+
<image src="cloud://cloud1-9g17b7v0e010c809.636c-cloud1-9g17b7v0e010c809-1309933988/cart/{{item.logo}}" class="logo" slot="left-icon"/>
6+
<view class="tags" slot="note">
7+
<t-tag wx:if="{{item.clicked}}" size="small" variant="light" style="margin-right: 8rpx">访问过</t-tag>
8+
<t-tag size="small" variant="light" theme="{{item.tag == '生鲜电商' ? 'success' : (item.tag == '社区电商' ? 'warning' : 'primary')}}">{{item.tag}}</t-tag>
9+
</view>
10+
</t-cell>
11+
</block>
12+
</view>
13+
14+
<include src="/templates/tabbar.wxml" />

miniprogram/pages/detail/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ Page({
7676
const { id } = this.data;
7777
wx.cloud.callFunction({
7878
name: 'updateViews',
79-
data: { id }
79+
data: { id },
80+
type: 'cookbook'
8081
})
8182
},
8283

miniprogram/pages/index/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ Page({
1010
text: '首页',
1111
value: 'index',
1212
icon: 'home'
13-
},{
13+
}, {
14+
text: '买菜',
15+
value: 'cart',
16+
icon: 'cart'
17+
}, {
1418
text: '技巧',
1519
value: 'learn',
1620
icon: 'tips'

miniprogram/pages/learn/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ Page({
99
text: '首页',
1010
value: 'index',
1111
icon: 'home'
12-
},{
12+
}, {
13+
text: '买菜',
14+
value: 'cart',
15+
icon: 'cart'
16+
}, {
1317
text: '技巧',
1418
value: 'learn',
1519
icon: 'tips'

miniprogram/pages/my/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ Page({
1010
text: '首页',
1111
value: 'index',
1212
icon: 'home'
13-
},{
13+
}, {
14+
text: '买菜',
15+
value: 'cart',
16+
icon: 'cart'
17+
}, {
1418
text: '技巧',
1519
value: 'learn',
1620
icon: 'tips'

0 commit comments

Comments
 (0)