Skip to content

Commit 89d1d2c

Browse files
committed
feat: 增加分批拉取首页数据和随机生成海报图片功能
1 parent d53214b commit 89d1d2c

13 files changed

Lines changed: 236 additions & 112 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,7 @@ typings/
114114
.dynamodb/
115115

116116
# End of https://www.gitignore.io/api/node,macos
117+
118+
/miniprogram/config.js
119+
120+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"permissions": {
3+
"openapi": [
4+
]
5+
}
6+
}

cloudfunctions/getStore/index.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const cloud = require('wx-server-sdk')
2+
cloud.init({
3+
traceUser: true,
4+
env: "map-4g0ciu1x80002ab0"
5+
})
6+
const db = cloud.database()
7+
const MAX_LIMIT = 100
8+
exports.main = async (event, context) => {
9+
// 先取出集合记录总数
10+
const countResult = await db.collection('store').count()
11+
const total = countResult.total
12+
// 计算需分几次取
13+
const batchTimes = Math.ceil(total / 100)
14+
// 承载所有读操作的 promise 的数组
15+
const tasks = []
16+
for (let i = 0; i < batchTimes; i++) {
17+
const promise = db.collection('store').skip(i * MAX_LIMIT).limit(MAX_LIMIT).get()
18+
tasks.push(promise)
19+
}
20+
// 等待所有
21+
return (await Promise.all(tasks)).reduce((acc, cur) => {
22+
return {
23+
data: acc.data.concat(cur.data),
24+
errMsg: acc.errMsg,
25+
}
26+
})
27+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "getStore",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "",
10+
"license": "ISC",
11+
"dependencies": {
12+
"wx-server-sdk": "~2.4.0"
13+
}
14+
}

miniprogram/components/shareBox/index.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ Component({
4242
title: "生成中",
4343
});
4444
if (this.data.drawData.context1 === "已经第") {
45+
let numberId = "";
46+
if (this.data.drawData.numberId <= 10) {
47+
numberId = " " + this.data.drawData.numberId
48+
} else {
49+
numberId = "" + this.data.drawData.numberId
50+
}
51+
console.log("numberId", numberId)
4552
// 下次这个画布宽度最好就按iphone6的750rpx定
4653
this.setData({
4754
imgDraw: {
@@ -105,7 +112,7 @@ Component({
105112
},
106113
{
107114
type: "text",
108-
text: "" + this.data.drawData.numberId,
115+
text: numberId,
109116
css: {
110117
top: "500rpx",
111118
left: "440rpx",
@@ -143,7 +150,7 @@ Component({
143150
// 二维码
144151
{
145152
type: "image",
146-
url: "https://6d61-map-4g0ciu1x80002ab0-1305236624.tcb.qcloud.la/share/qrcode.jpg?sign=198fafc5be17490aad24413bab88ef70&t=1617611739",
153+
url: "https://6d61-map-4g0ciu1x80002ab0-1305236624.tcb.qcloud.la/share/qr-code2.jpg?sign=e9272e95a564b5b62bd327f02c7be7a1&t=1618475799",
147154
css: {
148155
bottom: "80rpx",
149156
left: "180rpx",
@@ -195,6 +202,13 @@ Component({
195202
},
196203
});
197204
} else {
205+
// let numberId = "";
206+
// if (this.data.drawData.numberId <= 10) {
207+
// numberId = " " + this.data.drawData.numberId
208+
// } else {
209+
// numberId = "" + this.data.drawData.numberId
210+
// }
211+
// console.log("numberId", numberId)
198212
this.setData({
199213
imgDraw: {
200214
width: "1210rpx",
@@ -295,7 +309,7 @@ Component({
295309
// 二维码
296310
{
297311
type: "image",
298-
url: "https://6d61-map-4g0ciu1x80002ab0-1305236624.tcb.qcloud.la/share/qrcode.jpg?sign=198fafc5be17490aad24413bab88ef70&t=1617611739",
312+
url: "https://6d61-map-4g0ciu1x80002ab0-1305236624.tcb.qcloud.la/share/qr-code2.jpg?sign=e9272e95a564b5b62bd327f02c7be7a1&t=1618475799",
299313
css: {
300314
bottom: "80rpx",
301315
left: "180rpx",

miniprogram/pages/add/add.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ Page({
115115
iconPath: this.data.iconPath,
116116
images: this.data.images,
117117
content: event.detail.value.content,
118+
userName: wx.getStorageSync('nickName')
118119
},
119120
})
120121
.then((res) => {
@@ -142,7 +143,9 @@ Page({
142143
sourceType: ['album', 'camera'],
143144
success: res => {
144145

145-
wx.showLoading({ title: '上传中' })
146+
wx.showLoading({
147+
title: '上传中'
148+
})
146149
let tempFilePaths = res.tempFilePaths
147150
let items = [];
148151
for (const tempFilePath of tempFilePaths) {
@@ -162,14 +165,22 @@ Page({
162165
images: urls
163166
}, res => {
164167
wx.hideLoading();
165-
wx.showToast({ title: '上传图片成功', icon: 'success' })
168+
wx.showToast({
169+
title: '上传图片成功',
170+
icon: 'success'
171+
})
166172
})
167173
}).catch(() => {
168174
wx.hideLoading()
169-
wx.showToast({ title: '上传图片错误', icon: 'error' })
175+
wx.showToast({
176+
title: '上传图片错误',
177+
icon: 'error'
178+
})
170179
})
171180

172-
this.setData({ tempPhoto: items })
181+
this.setData({
182+
tempPhoto: items
183+
})
173184
}
174185
})
175186
},

miniprogram/pages/index/index.wxml

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,4 @@
11
<!-- 新手引导弹出层 -->
2-
<!-- <van-popup closeable close-icon="close" show="{{ isShowIntroduction }}" bind:close="onCloseIntroduction">
3-
<image class="introduction-image" mode="widthFix" src="https://6d61-map-4g0ciu1x80002ab0-1305236624.tcb.qcloud.la/introduction/introduction.jpg?sign=0d8be4112215554ac6b51f648c7eecb3&t=1616247894"></image>
4-
</van-popup> -->
5-
<!-- <view class="page">
6-
<image class="introduction-image" src="https://6d61-map-4g0ciu1x80002ab0-1305236624.tcb.qcloud.la/introduction/introduction.jpg?sign=1f8a2d647cacd20c63cea2d4977b5f8d&t=1616225044" mode="widthFix" bindtap="onCloseIntroduction"></image>
7-
</view> -->
8-
9-
<!-- <view class="page">
10-
<view class="top-image">
11-
<view class="tips-image">
12-
<image src="../../images/intro/tips3.png" class="tips" mode="widthFix" bindtap="onCloseIntroduction"></image>
13-
<image src="../../images/intro/nav.png" class="nav" mode="widthFix" bindtap="onCloseIntroduction"></image>
14-
</view>
15-
</view>
16-
</view> -->
17-
182
<map id="map" class="map" enable-building="true" enable-3D="true">
193
<!-- 问题数量表 -->
204
<cover-view class="numberList">
@@ -43,10 +27,13 @@
4327
</cover-view>
4428
</cover-view>
4529

30+
<!-- 定位 -->
31+
<cover-view class="getLocation">
32+
<cover-image src="../../images/home/getLocation.png"></cover-image>
33+
</cover-view>
34+
4635
<cover-view class="tips-image" bindtap="onCloseIntroduction">
4736
<cover-image src="../../images/intro/tips3.png" class="tips" mode="widthFix"></cover-image>
4837
<cover-image src="../../images/intro/nav2.png" class="nav" mode="widthFix"></cover-image>
49-
<!-- <image src="../../images/intro/tips3.png" class="tips" mode="widthFix"></image>
50-
<image src="../../images/intro/nav2.png" class="nav" mode="widthFix"></image> -->
5138
</cover-view>
5239
</map>

miniprogram/pages/index/index.wxss

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,15 @@
7979
.numberList-item-text {
8080
font-size: 14px;
8181
}
82+
83+
84+
.getLocation {
85+
position: absolute;
86+
left: 12px;
87+
bottom: 120px;
88+
text-align: center;
89+
width: 20px;
90+
background-color: #fff;
91+
padding: 10px;
92+
box-shadow: 1px 2px 3px #999999;
93+
}

miniprogram/pages/map/map.js

Lines changed: 80 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -74,53 +74,67 @@ Page({
7474
title: "数据加载中...",
7575
});
7676

77-
store.get().then((res) => {
78-
let data = res.data;
79-
/**
80-
* 处理 occurpyProblemNumber,errorProblemNumber,designProblemNumber
81-
*/
82-
let occurpyProblemNumber = 0;
83-
let errorProblemNumber = 0;
84-
let designProblemNumber = 0;
85-
res.data.forEach((item) => {
86-
if (item.problemLabel === "盲道破损") {
87-
errorProblemNumber++;
88-
} else if (item.problemLabel === "盲道占用") {
89-
occurpyProblemNumber++;
90-
} else if (item.problemLabel === "盲道设计") {
91-
designProblemNumber++;
92-
}
93-
});
77+
wx.cloud
78+
.callFunction({
79+
name: "getStore",
80+
})
81+
.then((res) => {
82+
console.log("云函数获取store", res.result)
83+
if (res.result.errMsg = "collection.get:ok") {
84+
let data = res.result.data;
85+
/**
86+
* 处理 occurpyProblemNumber,errorProblemNumber,designProblemNumber
87+
*/
88+
let occurpyProblemNumber = 0;
89+
let errorProblemNumber = 0;
90+
let designProblemNumber = 0;
91+
res.result.data.forEach((item) => {
92+
if (item.problemLabel === "盲道破损") {
93+
errorProblemNumber++;
94+
} else if (item.problemLabel === "盲道占用") {
95+
occurpyProblemNumber++;
96+
} else if (item.problemLabel === "盲道设计") {
97+
designProblemNumber++;
98+
}
99+
});
94100

95-
this.setData({
96-
occurpyProblemNumber,
97-
errorProblemNumber,
98-
designProblemNumber,
99-
});
101+
this.setData({
102+
occurpyProblemNumber,
103+
errorProblemNumber,
104+
designProblemNumber,
105+
});
100106

101-
/***
102-
* 处理marker
103-
* 将 _id 给 id ,确保 marker 事件的正确触发
104-
*/
105-
data.map((item, index) => {
106-
item.id = index;
107-
item.width = 20;
108-
item.height = 25;
109-
item.title = item.problemLabel;
110-
// item.customCallout = {
111-
// anchorX: 0,
112-
// anchorY: -20,
113-
// display: "BYCLICK"
114-
// }
115-
});
116-
this.setData({
117-
stores: data,
118-
},
119-
() => {
120-
wx.hideLoading();
107+
/***
108+
* 处理marker
109+
* 将 _id 给 id ,确保 marker 事件的正确触发
110+
*/
111+
data.map((item, index) => {
112+
item.id = index;
113+
item.width = 20;
114+
item.height = 25;
115+
item.title = item.problemLabel;
116+
// item.customCallout = {
117+
// anchorX: 0,
118+
// anchorY: -20,
119+
// display: "BYCLICK"
120+
// }
121+
});
122+
this.setData({
123+
stores: data,
124+
},
125+
() => {
126+
wx.hideLoading();
127+
}
128+
);
129+
} else {
130+
() => {
131+
wx.showToast({
132+
title: '获取数据失败',
133+
})
134+
wx.hideLoading();
135+
}
121136
}
122-
);
123-
});
137+
});
124138
},
125139

126140
getUserInfo: function (e) {
@@ -250,10 +264,28 @@ Page({
250264
});
251265
},
252266

253-
addMarker: function () {
254-
wx.navigateTo({
255-
url: "../add/add",
256-
});
267+
addMarker: async function () {
268+
const nickName = wx.getStorageSync('nickName')
269+
if (!nickName) {
270+
wx.getUserProfile({
271+
desc: '用于记录上传者信息',
272+
success: (res) => {
273+
this.setData({
274+
nickName: res.userInfo.nickName,
275+
avatarUrl: res.userInfo.avatarUrl,
276+
})
277+
wx.setStorageSync("avatarUrl", res.userInfo.avatarUrl);
278+
wx.setStorageSync("nickName", res.userInfo.nickName);
279+
wx.navigateTo({
280+
url: "../add/add",
281+
});
282+
}
283+
})
284+
} else {
285+
wx.navigateTo({
286+
url: "../add/add",
287+
});
288+
}
257289
},
258290

259291
goArticle: function () {

miniprogram/pages/map/map.wxml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
</cover-view>
5858
</cover-view>
5959
</cover-view>
60+
<!-- 悬浮的上传按钮 -->
6061
<cover-view class="postion-add" bindtap='addMarker'>
6162
<cover-image class="nav-tabbar-image" src="../../images/nav/add.png" open-type='getUserInfo'></cover-image>
6263
<cover-view>上传</cover-view>

0 commit comments

Comments
 (0)