出入码小程序刷新请求完成;优化调试输出;添加出入码接口mock;配置业务域名SSL证书
This commit is contained in:
parent
d4bc8c3f87
commit
88f3e0768c
@ -293,7 +293,7 @@ App.use(setGlobalDataPlugin, {
|
||||
})
|
||||
```
|
||||
|
||||
同时记得在小程序后台填写小程序的业务域名。
|
||||
同时记得在[微信小程序后台](https://mp.weixin.qq.com/)填写小程序的**服务器域名**→**request合法域名**(注意不是业务域名)。
|
||||
|
||||
##### 配置微信小程序appid
|
||||
|
||||
|
@ -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`);
|
||||
})
|
||||
|
@ -12,7 +12,7 @@ App.use(setGlobalDataPlugin, {
|
||||
globalData: {
|
||||
debugMode: true, // 是否展示调试内容
|
||||
baseUrl: true
|
||||
? "http://39.99.244.156:5203"
|
||||
? "https://epp.only4.work"
|
||||
: "http://localhost", // 不带最后的 /
|
||||
}
|
||||
})
|
||||
|
@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<view v-if="debugMode">
|
||||
<button @tap='debugCleanCache'>清除缓存</button>
|
||||
<textarea maxlength="-1" disabled="true" auto-height="true" :value="debugText"></textarea>
|
||||
<textarea maxlength="-1" disabled="true" auto-height="true" style="width: 100%" :value="debugText"></textarea>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
@ -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: {
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
<template>
|
||||
<view>
|
||||
<view style="text-align: center; margin-top: 100px;">
|
||||
<view><text>{{ id }} | {{ name }}</text></view>
|
||||
<view id="codeView" :style="{ display: isShow }">
|
||||
<view id="user-text"><text>{{ userText }}</text></view>
|
||||
<view id="time-text"><text>{{ time }}</text></view>
|
||||
<canvas type="2d" style="width: 70vw; height: 70vw;" id="myQrcode"></canvas>
|
||||
<view><text class="time-text">{{ time }}</text></view>
|
||||
</view>
|
||||
<view id="show-text"><text :style="{ color: showTextColor }">{{ showText }}</text></view>
|
||||
<view id="small-text"><text>下拉可刷新</text></view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
@ -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.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') {
|
||||
|
Loading…
Reference in New Issue
Block a user