出入码小程序刷新请求完成;优化调试输出;添加出入码接口mock;配置业务域名SSL证书
This commit is contained in:
		@@ -293,7 +293,7 @@ App.use(setGlobalDataPlugin, {
 | 
				
			|||||||
})
 | 
					})
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
同时记得在小程序后台填写小程序的业务域名。
 | 
					同时记得在[微信小程序后台](https://mp.weixin.qq.com/)填写小程序的**服务器域名**→**request合法域名**(注意不是业务域名)。
 | 
				
			||||||
 | 
					
 | 
				
			||||||
##### 配置微信小程序appid
 | 
					##### 配置微信小程序appid
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,6 +2,7 @@ const sleepTime = 0; // 模拟弱网环境等待时间
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// 1. 导入http模块
 | 
					// 1. 导入http模块
 | 
				
			||||||
const http = require("http");
 | 
					const http = require("http");
 | 
				
			||||||
 | 
					var url = require("url");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 2. 创建一个web服务器对象
 | 
					// 2. 创建一个web服务器对象
 | 
				
			||||||
const server = http.createServer();
 | 
					const server = http.createServer();
 | 
				
			||||||
@@ -14,6 +15,9 @@ server.on("request", async (req, res) => {
 | 
				
			|||||||
    //res.write()表示向客户端输出的方法
 | 
					    //res.write()表示向客户端输出的方法
 | 
				
			||||||
    // res.write("hello world,你好nodejs")
 | 
					    // 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');
 | 
					    res.setHeader('Content-Type', 'text/json;charset=utf-8');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let result = {};
 | 
					    let result = {};
 | 
				
			||||||
@@ -39,18 +43,37 @@ server.on("request", async (req, res) => {
 | 
				
			|||||||
            // msg: "用户名或密码不正确",
 | 
					            // msg: "用户名或密码不正确",
 | 
				
			||||||
            // data: null
 | 
					            // 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 {
 | 
					    } else {
 | 
				
			||||||
        result = {
 | 
					        result = {
 | 
				
			||||||
            success: false,
 | 
					            success: false,
 | 
				
			||||||
            msg: "服务器内部错误",
 | 
					            msg: "服务器内部错误",
 | 
				
			||||||
            data: null,
 | 
					            data: null,
 | 
				
			||||||
            // extra: {
 | 
					            extra: {
 | 
				
			||||||
            //     url: req.url,
 | 
					                url: req.url,
 | 
				
			||||||
            //     method: req.method,
 | 
					                query: query,
 | 
				
			||||||
            //     headers: req.headers,
 | 
					                urlObj: urlObj,
 | 
				
			||||||
            //     req: Object.keys(req),
 | 
					                method: req.method,
 | 
				
			||||||
            //     res: Object.keys(res)
 | 
					                headers: req.headers,
 | 
				
			||||||
            // }
 | 
					                req: Object.keys(req),
 | 
				
			||||||
 | 
					                res: Object.keys(res)
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    res.write(JSON.stringify(result));
 | 
					    res.write(JSON.stringify(result));
 | 
				
			||||||
@@ -71,4 +94,5 @@ server.listen(80, () => {
 | 
				
			|||||||
    console.log(`服务启动成功: ${baseUrl}/`);
 | 
					    console.log(`服务启动成功: ${baseUrl}/`);
 | 
				
			||||||
    console.log();
 | 
					    console.log();
 | 
				
			||||||
    console.log(`${baseUrl}/user/login`);
 | 
					    console.log(`${baseUrl}/user/login`);
 | 
				
			||||||
 | 
					    console.log(`${baseUrl}/access/getCodeInfo`);
 | 
				
			||||||
}) 
 | 
					}) 
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,7 +12,7 @@ App.use(setGlobalDataPlugin, {
 | 
				
			|||||||
  globalData: {
 | 
					  globalData: {
 | 
				
			||||||
    debugMode: true, // 是否展示调试内容
 | 
					    debugMode: true, // 是否展示调试内容
 | 
				
			||||||
    baseUrl: true
 | 
					    baseUrl: true
 | 
				
			||||||
      ? "http://39.99.244.156:5203"
 | 
					      ? "https://epp.only4.work"
 | 
				
			||||||
      : "http://localhost", // 不带最后的 /
 | 
					      : "http://localhost", // 不带最后的 /
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,7 +1,7 @@
 | 
				
			|||||||
<template>
 | 
					<template>
 | 
				
			||||||
  <view v-if="debugMode">
 | 
					  <view v-if="debugMode">
 | 
				
			||||||
    <button @tap='debugCleanCache'>清除缓存</button>
 | 
					    <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>
 | 
					  </view>
 | 
				
			||||||
</template>
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -12,22 +12,25 @@ import { eventCenter, getCurrentInstance } from '@tarojs/taro'
 | 
				
			|||||||
export default {
 | 
					export default {
 | 
				
			||||||
  data() {
 | 
					  data() {
 | 
				
			||||||
    return {
 | 
					    return {
 | 
				
			||||||
      userInfo: null,
 | 
					 | 
				
			||||||
      debugMode: Taro.getApp().globalData.debugMode,
 | 
					      debugMode: Taro.getApp().globalData.debugMode,
 | 
				
			||||||
      debugText: "",
 | 
					      debugText: "",
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  mounted() {
 | 
					  mounted() {
 | 
				
			||||||
    eventCenter.once(getCurrentInstance().router.onShow, () => {
 | 
					    eventCenter.once(getCurrentInstance().router.onShow, () => {
 | 
				
			||||||
      this.userInfo = Taro.getStorageSync("userInfo");
 | 
					      const res = Taro.getStorageInfoSync()
 | 
				
			||||||
      this.displayUsername = this.userInfo?.username ?? "请登录";
 | 
					      let storage = {};
 | 
				
			||||||
 | 
					      res.keys.forEach(key => storage[key] = Taro.getStorageSync(key))
 | 
				
			||||||
      this.debugText = JSON.stringify({
 | 
					      this.debugText = JSON.stringify({
 | 
				
			||||||
        "TARO_ENV": process.env.TARO_ENV,
 | 
					        TARO_ENV: process.env.TARO_ENV,
 | 
				
			||||||
        // "isVisitor": this.isVisitor,
 | 
					        globalData: Taro.getApp().globalData,
 | 
				
			||||||
        // "isUser": this.isUser,
 | 
					        storage: storage,
 | 
				
			||||||
        // "isAdmin": this.isAdmin,
 | 
					        // storageInfo: {
 | 
				
			||||||
        "userInfo": this.userInfo || 'null'
 | 
					        //   keys: res.keys,
 | 
				
			||||||
      }, null, 4)
 | 
					        //   currentSize: res.currentSize,
 | 
				
			||||||
 | 
					        //   limitSize: res.limitSize
 | 
				
			||||||
 | 
					        // },
 | 
				
			||||||
 | 
					      }, null, 8)
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  methods: {
 | 
					  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-weight: bold;
 | 
				
			||||||
 | 
					  font-size: 40px;
 | 
				
			||||||
 | 
					  margin-top: 50px;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#myQrcode {
 | 
					#myQrcode {
 | 
				
			||||||
  display: block;
 | 
					  display: block;
 | 
				
			||||||
  margin: 0 auto;
 | 
					  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>
 | 
					<template>
 | 
				
			||||||
  <view>
 | 
					  <view id="codeView" :style="{ display: isShow }">
 | 
				
			||||||
    <view style="text-align: center; margin-top: 100px;">
 | 
					    <view id="user-text"><text>{{ userText }}</text></view>
 | 
				
			||||||
      <view><text>{{ id }} | {{ name }}</text></view>
 | 
					    <view id="time-text"><text>{{ time }}</text></view>
 | 
				
			||||||
    <canvas type="2d" style="width: 70vw; height: 70vw;" id="myQrcode"></canvas>
 | 
					    <canvas type="2d" style="width: 70vw; height: 70vw;" id="myQrcode"></canvas>
 | 
				
			||||||
      <view><text class="time-text">{{ time }}</text></view>
 | 
					    <view id="show-text"><text :style="{ color: showTextColor }">{{ showText }}</text></view>
 | 
				
			||||||
    </view>
 | 
					    <view id="small-text"><text>下拉可刷新</text></view>
 | 
				
			||||||
  </view>
 | 
					  </view>
 | 
				
			||||||
</template>
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -21,13 +21,14 @@ export default {
 | 
				
			|||||||
      ...Taro.getApp().globalData,
 | 
					      ...Taro.getApp().globalData,
 | 
				
			||||||
      userInfo: null,
 | 
					      userInfo: null,
 | 
				
			||||||
      timeInterval: null,
 | 
					      timeInterval: null,
 | 
				
			||||||
      id: '',
 | 
					      isShow: 'none',
 | 
				
			||||||
      name: '',
 | 
					      userText: '',
 | 
				
			||||||
 | 
					      showText: '',
 | 
				
			||||||
 | 
					      showTextColor: '',
 | 
				
			||||||
      time: '',
 | 
					      time: '',
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // 对应 onShow
 | 
					 | 
				
			||||||
  onShow() {
 | 
					  onShow() {
 | 
				
			||||||
    console.log('onShow')
 | 
					    console.log('onShow')
 | 
				
			||||||
    setTimeout(() => {
 | 
					    setTimeout(() => {
 | 
				
			||||||
@@ -35,31 +36,65 @@ export default {
 | 
				
			|||||||
    }, 100)
 | 
					    }, 100)
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // 对应 onHide
 | 
					 | 
				
			||||||
  onHide() {
 | 
					  onHide() {
 | 
				
			||||||
    console.log('onHide')
 | 
					    console.log('onHide')
 | 
				
			||||||
    clearInterval(this.timeInterval);
 | 
					    clearInterval(this.timeInterval);
 | 
				
			||||||
 | 
					    this.isShow = 'none'
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // 对应 onPullDownRefresh
 | 
					 | 
				
			||||||
  onPullDownRefresh() {
 | 
					  onPullDownRefresh() {
 | 
				
			||||||
    console.log('onPullDownRefresh')
 | 
					    console.log('onPullDownRefresh')
 | 
				
			||||||
    Taro.showNavigationBarLoading();
 | 
					    Taro.showNavigationBarLoading();
 | 
				
			||||||
    clearInterval(this.timeInterval);
 | 
					    clearInterval(this.timeInterval);
 | 
				
			||||||
    this.id = ''
 | 
					    this.isShow = 'none'
 | 
				
			||||||
    this.name = ''
 | 
					 | 
				
			||||||
    this.time = ''
 | 
					 | 
				
			||||||
    this.userInfo = Taro.getStorageSync("userInfo");
 | 
					    this.userInfo = Taro.getStorageSync("userInfo");
 | 
				
			||||||
    if (!this.userInfo) {
 | 
					    if (!this.userInfo) {
 | 
				
			||||||
      Taro.redirectTo({
 | 
					      Taro.redirectTo({
 | 
				
			||||||
        url: '/pages/index/login'
 | 
					        url: '/pages/index/login'
 | 
				
			||||||
      })
 | 
					      })
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    this.id = this.userInfo.id
 | 
					    Taro.showLoading({ title: '加载中' })
 | 
				
			||||||
    this.name = this.userInfo.realname
 | 
					    var that = this;
 | 
				
			||||||
    this.drawCode()
 | 
					    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.stopPullDownRefresh();
 | 
				
			||||||
        Taro.hideNavigationBarLoading();
 | 
					        Taro.hideNavigationBarLoading();
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  methods: {
 | 
					  methods: {
 | 
				
			||||||
    drawCode(text = 'https://www.baidu.com/', foreground = 'red') {
 | 
					    drawCode(text = 'https://www.baidu.com/', foreground = 'red') {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user