From 88f3e0768c07729d042df7b148d2ce250942fdb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=91=98=E5=B0=8F=E5=A2=A8?= <2291200076@qq.com> Date: Sat, 26 Nov 2022 17:57:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=87=BA=E5=85=A5=E7=A0=81=E5=B0=8F=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E5=88=B7=E6=96=B0=E8=AF=B7=E6=B1=82=E5=AE=8C=E6=88=90?= =?UTF-8?q?=EF=BC=9B=E4=BC=98=E5=8C=96=E8=B0=83=E8=AF=95=E8=BE=93=E5=87=BA?= =?UTF-8?q?=EF=BC=9B=E6=B7=BB=E5=8A=A0=E5=87=BA=E5=85=A5=E7=A0=81=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3mock=EF=BC=9B=E9=85=8D=E7=BD=AE=E4=B8=9A=E5=8A=A1?= =?UTF-8?q?=E5=9F=9F=E5=90=8DSSL=E8=AF=81=E4=B9=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- backend-mock/index.js | 38 +++++++++--- miniprogram/src/app.js | 2 +- miniprogram/src/components/DebugComp.vue | 23 ++++---- miniprogram/src/pages/residents/code.css | 27 +++++++-- miniprogram/src/pages/residents/code.vue | 73 ++++++++++++++++++------ 6 files changed, 123 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index e1d5144..3791adb 100644 --- a/README.md +++ b/README.md @@ -293,7 +293,7 @@ App.use(setGlobalDataPlugin, { }) ``` -同时记得在小程序后台填写小程序的业务域名。 +同时记得在[微信小程序后台](https://mp.weixin.qq.com/)填写小程序的**服务器域名**→**request合法域名**(注意不是业务域名)。 ##### 配置微信小程序appid diff --git a/backend-mock/index.js b/backend-mock/index.js index d885b88..90afb33 100644 --- a/backend-mock/index.js +++ b/backend-mock/index.js @@ -2,6 +2,7 @@ const sleepTime = 0; // 模拟弱网环境等待时间 // 1. 导入http模块 const http = require("http"); +var url = require("url"); // 2. 创建一个web服务器对象 const server = http.createServer(); @@ -14,6 +15,9 @@ server.on("request", async (req, res) => { //res.write()表示向客户端输出的方法 // res.write("hello world,你好nodejs") + let urlObj = url.parse(req.url, true); + let query = urlObj.query; + res.setHeader('Content-Type', 'text/json;charset=utf-8'); let result = {}; @@ -39,18 +43,37 @@ server.on("request", async (req, res) => { // msg: "用户名或密码不正确", // data: null }; + } else if (req.url.startsWith('/access/getCodeInfo')) { + result = { + success: true, + msg: "成功", + data: { + id: query.id, + qrcodeColor: "green", + infoText: "绿码 请通行", + infoTextColor: "green", + // qrcodeColor: "red", + // infoText: "红码 禁止通行", + // infoTextColor: "red", + } + // success: false, + // msg: "用户名或密码不正确", + // data: null + }; } else { result = { success: false, msg: "服务器内部错误", data: null, - // extra: { - // url: req.url, - // method: req.method, - // headers: req.headers, - // req: Object.keys(req), - // res: Object.keys(res) - // } + extra: { + url: req.url, + query: query, + urlObj: urlObj, + method: req.method, + headers: req.headers, + req: Object.keys(req), + res: Object.keys(res) + } }; } res.write(JSON.stringify(result)); @@ -71,4 +94,5 @@ server.listen(80, () => { console.log(`服务启动成功: ${baseUrl}/`); console.log(); console.log(`${baseUrl}/user/login`); + console.log(`${baseUrl}/access/getCodeInfo`); })  diff --git a/miniprogram/src/app.js b/miniprogram/src/app.js index 76613cf..a899384 100644 --- a/miniprogram/src/app.js +++ b/miniprogram/src/app.js @@ -12,7 +12,7 @@ App.use(setGlobalDataPlugin, { globalData: { debugMode: true, // 是否展示调试内容 baseUrl: true - ? "http://39.99.244.156:5203" + ? "https://epp.only4.work" : "http://localhost", // 不带最后的 / } }) diff --git a/miniprogram/src/components/DebugComp.vue b/miniprogram/src/components/DebugComp.vue index 3caf6a7..11c5cfe 100644 --- a/miniprogram/src/components/DebugComp.vue +++ b/miniprogram/src/components/DebugComp.vue @@ -1,7 +1,7 @@ @@ -12,22 +12,25 @@ import { eventCenter, getCurrentInstance } from '@tarojs/taro' export default { data() { return { - userInfo: null, debugMode: Taro.getApp().globalData.debugMode, debugText: "", } }, mounted() { eventCenter.once(getCurrentInstance().router.onShow, () => { - this.userInfo = Taro.getStorageSync("userInfo"); - this.displayUsername = this.userInfo?.username ?? "请登录"; + const res = Taro.getStorageInfoSync() + let storage = {}; + res.keys.forEach(key => storage[key] = Taro.getStorageSync(key)) this.debugText = JSON.stringify({ - "TARO_ENV": process.env.TARO_ENV, - // "isVisitor": this.isVisitor, - // "isUser": this.isUser, - // "isAdmin": this.isAdmin, - "userInfo": this.userInfo || 'null' - }, null, 4) + TARO_ENV: process.env.TARO_ENV, + globalData: Taro.getApp().globalData, + storage: storage, + // storageInfo: { + // keys: res.keys, + // currentSize: res.currentSize, + // limitSize: res.limitSize + // }, + }, null, 8) }) }, methods: { diff --git a/miniprogram/src/pages/residents/code.css b/miniprogram/src/pages/residents/code.css index 85da619..3185fc3 100644 --- a/miniprogram/src/pages/residents/code.css +++ b/miniprogram/src/pages/residents/code.css @@ -1,11 +1,30 @@ -.time-text { +#codeView { + text-align: center; + margin-top: 100px; +} + +#user-text { + font-size: 35px; +} + +#time-text { font-weight: bold; + font-size: 40px; + margin-top: 50px; } #myQrcode { display: block; margin: 0 auto; - - margin-top: 50px; - margin-bottom: 40px; +} + +#show-text { + font-weight: bold; + font-size: 45px; +} + +#small-text { + margin-top: 80px; + color: grey; + font-size: small; } diff --git a/miniprogram/src/pages/residents/code.vue b/miniprogram/src/pages/residents/code.vue index cb40912..f4c4e46 100644 --- a/miniprogram/src/pages/residents/code.vue +++ b/miniprogram/src/pages/residents/code.vue @@ -1,10 +1,10 @@ @@ -21,13 +21,14 @@ export default { ...Taro.getApp().globalData, userInfo: null, timeInterval: null, - id: '', - name: '', + isShow: 'none', + userText: '', + showText: '', + showTextColor: '', time: '', } }, - // 对应 onShow onShow() { console.log('onShow') setTimeout(() => { @@ -35,31 +36,65 @@ export default { }, 100) }, - // 对应 onHide onHide() { console.log('onHide') clearInterval(this.timeInterval); + this.isShow = 'none' }, - // 对应 onPullDownRefresh onPullDownRefresh() { console.log('onPullDownRefresh') Taro.showNavigationBarLoading(); clearInterval(this.timeInterval); - this.id = '' - this.name = '' - this.time = '' + this.isShow = 'none' this.userInfo = Taro.getStorageSync("userInfo"); if (!this.userInfo) { Taro.redirectTo({ url: '/pages/index/login' }) } - this.id = this.userInfo.id - this.name = this.userInfo.realname - this.drawCode() - Taro.stopPullDownRefresh(); - Taro.hideNavigationBarLoading(); + Taro.showLoading({ title: '加载中' }) + var that = this; + Taro.request({ + url: `${this.baseUrl}/access/getCodeInfo`, + method: "POST", + header: { + "Content-Type": "application/x-www-form-urlencoded" //用于post + }, + data: { + id: this.userInfo.id, + }, + success: function (d) { + Taro.hideLoading() + let result = d.data; + if (result.success) { + console.log(result.data); + that.userText = `${that.userInfo.id} | ${that.userInfo.realname}` + that.showText = result.data.infoText + that.showTextColor = result.data.infoTextColor + that.drawCode(`https://epp.cxyxiaomo.com/access/validCode?id=${result.data.id}&t=${Date.now()}`, result.data.qrcodeColor) + } else { + Taro.showToast({ + title: result.msg, + icon: 'error', + duration: 2000 + }) + } + that.isShow = '' + }, + fail: function () { + Taro.hideLoading() + Taro.showToast({ + title: "请求失败", + icon: 'error', + duration: 2000 + }) + }, + complete: function () { + Taro.stopPullDownRefresh(); + Taro.hideNavigationBarLoading(); + } + }) }, methods: { drawCode(text = 'https://www.baidu.com/', foreground = 'red') {