Skip to content

Commit

Permalink
feat: 增加分批拉取首页数据和随机生成海报图片功能
Browse files Browse the repository at this point in the history
  • Loading branch information
Volcano-Yang committed Apr 28, 2021
1 parent d53214b commit 89d1d2c
Show file tree
Hide file tree
Showing 13 changed files with 236 additions and 112 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,7 @@ typings/
.dynamodb/

# End of https://www.gitignore.io/api/node,macos

/miniprogram/config.js


6 changes: 6 additions & 0 deletions cloudfunctions/getStore/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"permissions": {
"openapi": [
]
}
}
27 changes: 27 additions & 0 deletions cloudfunctions/getStore/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const cloud = require('wx-server-sdk')
cloud.init({
traceUser: true,
env: "map-4g0ciu1x80002ab0"
})
const db = cloud.database()
const MAX_LIMIT = 100
exports.main = async (event, context) => {
// 先取出集合记录总数
const countResult = await db.collection('store').count()
const total = countResult.total
// 计算需分几次取
const batchTimes = Math.ceil(total / 100)
// 承载所有读操作的 promise 的数组
const tasks = []
for (let i = 0; i < batchTimes; i++) {
const promise = db.collection('store').skip(i * MAX_LIMIT).limit(MAX_LIMIT).get()
tasks.push(promise)
}
// 等待所有
return (await Promise.all(tasks)).reduce((acc, cur) => {
return {
data: acc.data.concat(cur.data),
errMsg: acc.errMsg,
}
})
}
14 changes: 14 additions & 0 deletions cloudfunctions/getStore/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "getStore",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"wx-server-sdk": "~2.4.0"
}
}
20 changes: 17 additions & 3 deletions miniprogram/components/shareBox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ Component({
title: "生成中",
});
if (this.data.drawData.context1 === "已经第") {
let numberId = "";
if (this.data.drawData.numberId <= 10) {
numberId = " " + this.data.drawData.numberId
} else {
numberId = "" + this.data.drawData.numberId
}
console.log("numberId", numberId)
// 下次这个画布宽度最好就按iphone6的750rpx定
this.setData({
imgDraw: {
Expand Down Expand Up @@ -105,7 +112,7 @@ Component({
},
{
type: "text",
text: "" + this.data.drawData.numberId,
text: numberId,
css: {
top: "500rpx",
left: "440rpx",
Expand Down Expand Up @@ -143,7 +150,7 @@ Component({
// 二维码
{
type: "image",
url: "https://6d61-map-4g0ciu1x80002ab0-1305236624.tcb.qcloud.la/share/qrcode.jpg?sign=198fafc5be17490aad24413bab88ef70&t=1617611739",
url: "https://6d61-map-4g0ciu1x80002ab0-1305236624.tcb.qcloud.la/share/qr-code2.jpg?sign=e9272e95a564b5b62bd327f02c7be7a1&t=1618475799",
css: {
bottom: "80rpx",
left: "180rpx",
Expand Down Expand Up @@ -195,6 +202,13 @@ Component({
},
});
} else {
// let numberId = "";
// if (this.data.drawData.numberId <= 10) {
// numberId = " " + this.data.drawData.numberId
// } else {
// numberId = "" + this.data.drawData.numberId
// }
// console.log("numberId", numberId)
this.setData({
imgDraw: {
width: "1210rpx",
Expand Down Expand Up @@ -295,7 +309,7 @@ Component({
// 二维码
{
type: "image",
url: "https://6d61-map-4g0ciu1x80002ab0-1305236624.tcb.qcloud.la/share/qrcode.jpg?sign=198fafc5be17490aad24413bab88ef70&t=1617611739",
url: "https://6d61-map-4g0ciu1x80002ab0-1305236624.tcb.qcloud.la/share/qr-code2.jpg?sign=e9272e95a564b5b62bd327f02c7be7a1&t=1618475799",
css: {
bottom: "80rpx",
left: "180rpx",
Expand Down
19 changes: 15 additions & 4 deletions miniprogram/pages/add/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ Page({
iconPath: this.data.iconPath,
images: this.data.images,
content: event.detail.value.content,
userName: wx.getStorageSync('nickName')
},
})
.then((res) => {
Expand Down Expand Up @@ -142,7 +143,9 @@ Page({
sourceType: ['album', 'camera'],
success: res => {

wx.showLoading({ title: '上传中' })
wx.showLoading({
title: '上传中'
})
let tempFilePaths = res.tempFilePaths
let items = [];
for (const tempFilePath of tempFilePaths) {
Expand All @@ -162,14 +165,22 @@ Page({
images: urls
}, res => {
wx.hideLoading();
wx.showToast({ title: '上传图片成功', icon: 'success' })
wx.showToast({
title: '上传图片成功',
icon: 'success'
})
})
}).catch(() => {
wx.hideLoading()
wx.showToast({ title: '上传图片错误', icon: 'error' })
wx.showToast({
title: '上传图片错误',
icon: 'error'
})
})

this.setData({ tempPhoto: items })
this.setData({
tempPhoto: items
})
}
})
},
Expand Down
23 changes: 5 additions & 18 deletions miniprogram/pages/index/index.wxml
Original file line number Diff line number Diff line change
@@ -1,20 +1,4 @@
<!-- 新手引导弹出层 -->
<!-- <van-popup closeable close-icon="close" show="{{ isShowIntroduction }}" bind:close="onCloseIntroduction">
<image class="introduction-image" mode="widthFix" src="https://6d61-map-4g0ciu1x80002ab0-1305236624.tcb.qcloud.la/introduction/introduction.jpg?sign=0d8be4112215554ac6b51f648c7eecb3&t=1616247894"></image>
</van-popup> -->
<!-- <view class="page">
<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>
</view> -->

<!-- <view class="page">
<view class="top-image">
<view class="tips-image">
<image src="../../images/intro/tips3.png" class="tips" mode="widthFix" bindtap="onCloseIntroduction"></image>
<image src="../../images/intro/nav.png" class="nav" mode="widthFix" bindtap="onCloseIntroduction"></image>
</view>
</view>
</view> -->

<map id="map" class="map" enable-building="true" enable-3D="true">
<!-- 问题数量表 -->
<cover-view class="numberList">
Expand Down Expand Up @@ -43,10 +27,13 @@
</cover-view>
</cover-view>

<!-- 定位 -->
<cover-view class="getLocation">
<cover-image src="../../images/home/getLocation.png"></cover-image>
</cover-view>

<cover-view class="tips-image" bindtap="onCloseIntroduction">
<cover-image src="../../images/intro/tips3.png" class="tips" mode="widthFix"></cover-image>
<cover-image src="../../images/intro/nav2.png" class="nav" mode="widthFix"></cover-image>
<!-- <image src="../../images/intro/tips3.png" class="tips" mode="widthFix"></image>
<image src="../../images/intro/nav2.png" class="nav" mode="widthFix"></image> -->
</cover-view>
</map>
12 changes: 12 additions & 0 deletions miniprogram/pages/index/index.wxss
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,15 @@
.numberList-item-text {
font-size: 14px;
}


.getLocation {
position: absolute;
left: 12px;
bottom: 120px;
text-align: center;
width: 20px;
background-color: #fff;
padding: 10px;
box-shadow: 1px 2px 3px #999999;
}
128 changes: 80 additions & 48 deletions miniprogram/pages/map/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,53 +74,67 @@ Page({
title: "数据加载中...",
});

store.get().then((res) => {
let data = res.data;
/**
* 处理 occurpyProblemNumber,errorProblemNumber,designProblemNumber
*/
let occurpyProblemNumber = 0;
let errorProblemNumber = 0;
let designProblemNumber = 0;
res.data.forEach((item) => {
if (item.problemLabel === "盲道破损") {
errorProblemNumber++;
} else if (item.problemLabel === "盲道占用") {
occurpyProblemNumber++;
} else if (item.problemLabel === "盲道设计") {
designProblemNumber++;
}
});
wx.cloud
.callFunction({
name: "getStore",
})
.then((res) => {
console.log("云函数获取store", res.result)
if (res.result.errMsg = "collection.get:ok") {
let data = res.result.data;
/**
* 处理 occurpyProblemNumber,errorProblemNumber,designProblemNumber
*/
let occurpyProblemNumber = 0;
let errorProblemNumber = 0;
let designProblemNumber = 0;
res.result.data.forEach((item) => {
if (item.problemLabel === "盲道破损") {
errorProblemNumber++;
} else if (item.problemLabel === "盲道占用") {
occurpyProblemNumber++;
} else if (item.problemLabel === "盲道设计") {
designProblemNumber++;
}
});

this.setData({
occurpyProblemNumber,
errorProblemNumber,
designProblemNumber,
});
this.setData({
occurpyProblemNumber,
errorProblemNumber,
designProblemNumber,
});

/***
* 处理marker
* 将 _id 给 id ,确保 marker 事件的正确触发
*/
data.map((item, index) => {
item.id = index;
item.width = 20;
item.height = 25;
item.title = item.problemLabel;
// item.customCallout = {
// anchorX: 0,
// anchorY: -20,
// display: "BYCLICK"
// }
});
this.setData({
stores: data,
},
() => {
wx.hideLoading();
/***
* 处理marker
* 将 _id 给 id ,确保 marker 事件的正确触发
*/
data.map((item, index) => {
item.id = index;
item.width = 20;
item.height = 25;
item.title = item.problemLabel;
// item.customCallout = {
// anchorX: 0,
// anchorY: -20,
// display: "BYCLICK"
// }
});
this.setData({
stores: data,
},
() => {
wx.hideLoading();
}
);
} else {
() => {
wx.showToast({
title: '获取数据失败',
})
wx.hideLoading();
}
}
);
});
});
},

getUserInfo: function (e) {
Expand Down Expand Up @@ -250,10 +264,28 @@ Page({
});
},

addMarker: function () {
wx.navigateTo({
url: "../add/add",
});
addMarker: async function () {
const nickName = wx.getStorageSync('nickName')
if (!nickName) {
wx.getUserProfile({
desc: '用于记录上传者信息',
success: (res) => {
this.setData({
nickName: res.userInfo.nickName,
avatarUrl: res.userInfo.avatarUrl,
})
wx.setStorageSync("avatarUrl", res.userInfo.avatarUrl);
wx.setStorageSync("nickName", res.userInfo.nickName);
wx.navigateTo({
url: "../add/add",
});
}
})
} else {
wx.navigateTo({
url: "../add/add",
});
}
},

goArticle: function () {
Expand Down
1 change: 1 addition & 0 deletions miniprogram/pages/map/map.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
</cover-view>
</cover-view>
</cover-view>
<!-- 悬浮的上传按钮 -->
<cover-view class="postion-add" bindtap='addMarker'>
<cover-image class="nav-tabbar-image" src="../../images/nav/add.png" open-type='getUserInfo'></cover-image>
<cover-view>上传</cover-view>
Expand Down
Loading

0 comments on commit 89d1d2c

Please sign in to comment.