| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- // logs.js
- const util = require('../../utils/util.js')
- Page({
- data: {
- showAuthorizedDialog: false,
- hasAuth: false,
- activeIcon: "/subpages/icons/ic_selected_radio.svg",
- normalIcon: "/subpages/icons/ic_radio.svg",
- logs: [],
- checkedPrivacy: false,
- canGetPhoneNumber: false,
- },
- onSaveExitState: function () {
- // wx.clearStorage();
- console.log("onSaveExitState=");
- // 返回保存的数据和超时时间(可选)
- return {
- expireTimeStamp: Date.now() + 24 * 60 * 60 * 1000 // 超时时间戳,例如设置为1天后过期
- };
- },
- onChangePrivacy(event) {
- const check = event.detail;
- this.setData({
- checkedPrivacy: check
- });
- },
- //扫码
- tapScan() {
- if (!this.data.hasAuth) {
- this.showDialog();
- return;
- }
- if (!this.data.checkedPrivacy) {
- wx.showToast({
- title: '请先阅读并同意《舒眠大健康用户服务协议》和《舒眠大健康隐私保护政策》',
- icon: 'none',
- duration: 2000
- })
- return;
- }
- wx.scanCode({
- success: function (res) {
- console.log('扫码获取的参数', res);
- if (res.result) {
- let hotelcodeTemp = res.result.split('|')[0];
- let roomcodeTemp = res.result.split('|')[1];
- // wx.clearStorage();
- var userInfo = wx.getStorageSync("userInfo") || {};
- if (hotelcodeTemp == userInfo.hotel && roomcodeTemp == userInfo.room) {
- wx.setStorageSync('res', res);
- wx.setStorageSync('scanResultExpiresAt', Date.now() + 2 * 60 * 60 * 1000); // 超时时间戳,例如设置为2小时后过期
- wx.reLaunch({
- url: '/pages/index/index?res=' + res,//传res
- })
- } else {
- wx.showToast({
- title: '暂无权限,请先办理入住',
- icon: 'none'
- });
- }
- }
- }
- })
- },
- onLoad() {
- console.log("scan页面");
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- const app = getApp();
- app.globalData.selectedTabIndex = 4;
- this.getTabBar().setData({
- selected: 4
- })
- this.checkAuth()
- },
- showDialog() {
- this.setData({
- showAuthorizedDialog: true
- })
- },
- checkAuth() {
- var hasAuth = wx.getStorageSync("hasAuth") || false;
- this.setData({
- hasAuth: hasAuth
- })
- // if (hasAuth) {
- // var userInfo = wx.getStorageSync("userInfo");
- // this.setData({
- // userName: userInfo.userName || "用户登录",
- // avatarUrl: userInfo.avatarUrl || defaultAvatarUrl,
- // phoneNumber: userInfo.phoneNumber || ""
- // })
- // }
- return hasAuth;
- },
- authorizationSuccessful() {
- console.log("授权成功");
- this.setData({ showAuthorizedDialog: false })
- this.checkAuth();
- },
- login: function () {
- var that = this;
- wx.login({
- success: res => {
- if (res.code) {
- // 发送 code 到服务器换取 session_key, openid
- wx.request({
- url: 'https://yourserver.com/api/login',
- data: {
- code: res.code
- },
- success: function (loginRes) {
- if (loginRes.data.success) {
- wx.setStorageSync('session_key', loginRes.data.session_key);
- wx.setStorageSync('openid', loginRes.data.openid);
- // 可以在这里提示用户进行手机号授权
- this.setData({
- canGetPhoneNumber: true
- });
- }
- }
- });
- }
- }
- });
- },
- getPhoneNumber: function (e) {
- if (e.detail.errMsg !== "getPhoneNumber:ok") {
- return;
- }
- const { encryptedData, iv } = e.detail;
- wx.request({
- url: 'https://yourserver.com/api/decrypt_phone',
- data: {
- encryptedData,
- iv,
- session_key: wx.getStorageSync('session_key')
- },
- success: function (decryptRes) {
- if (decryptRes.data.success) {
- console.log('解密后的手机号:', decryptRes.data.phoneNumber);
- // 处理解密后的手机号
- }
- }
- });
- },
- // 绑定按钮点击事件
- bindGetPhoneNumber: function () {
- if (this.data.canGetPhoneNumber) {
- wx.getPhoneNumber({
- success: this.getPhoneNumber
- });
- }
- }
- })
|