| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- // miniprogram/pages/testSAS/testSAS.js
- // const db = wx.cloud.database()
- const homeApi_empower = "https://aipush.aidsleep.cn";
- const token_empower = "b74fd5754c5ef24cf600c39194abdaeb";
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- intervalId: null,//解除授权定时任务
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- console.log('hasAuth===data='+wx.getStorageSync('hasAuth'));
- if(!wx.getStorageSync('userInfo_em') || !wx.getStorageSync('unionid') || !wx.getStorageSync('openid') || !wx.getStorageSync('hasAuth')){
- // wx.showModal({
- // title: '提示',
- // content: '请进行授权',
- // showCancel: false
- // });
- wx.showToast({
- title: '请进行授权',
- icon: 'none',
- duration: 2000
- });
-
- setTimeout(function() {
- wx.reLaunch({
- url: '/pages/empower/empower',
- })
- }, 2500) // 设置延时时间,单位为毫秒
- }else{
- if (!wx.getStorageSync('res') || !wx.getStorageSync('res').result) {
- wx.showModal({
- title: '提示',
- content: '请先扫描房间二维码',
- showCancel: false
- });
-
- setTimeout(function () {
- wx.reLaunch({
- url: '/pages/scan/scan',
- })
- }, 2000) // 设置延时时间,单位为毫秒
- } else {
-
- var that = this;
-
- let hotelcodeTemp = '';
- let roomcodeTemp = '';
- if (wx.getStorageSync('res').result.split('|').length != 2) {
- wx.showModal({
- title: '提示',
- content: '房间二维码不正确,请重新扫码',
- showCancel: false
- });
-
- setTimeout(function () {
- wx.reLaunch({
- url: '/pages/scan/scan',
- })
- }, 2000) // 设置延时时间,单位为毫秒
- }
- hotelcodeTemp = wx.getStorageSync('res').result.split('|')[0];
- roomcodeTemp = wx.getStorageSync('res').result.split('|')[1];
- console.log('hotelcodeTemp=+='+hotelcodeTemp);
- console.log('roomcodeTemp=+='+roomcodeTemp);
- const hotelEmpower = wx.getStorageSync('hotelEmpower');
- const roomEmpower = wx.getStorageSync('roomEmpower');
-
- if (hotelcodeTemp != hotelEmpower || roomcodeTemp != roomEmpower) {
- wx.showModal({
- title: '提示',
- content: '授权配置错误,或者您没有使用权限',
- showCancel: false
- });
-
- setTimeout(function () {
- wx.reLaunch({
- url: '/pages/scan/scan',
- })
- }, 2000) // 设置延时时间,单位为毫秒
- }
- }
- }
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
-
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- const app = getApp();
- app.globalData.selectedTabIndex = 3;
- this.getTabBar().setData({
- selected: 3
- })
- var that = this;
- if (!that.data.intervalId) {
- that.data.intervalId = setInterval(() => {
- // 这里执行你的代码
- console.log('testSAS页面:'+Date.now());
- if(wx.getStorageSync('userInfo_em') && wx.getStorageSync('unionid') && wx.getStorageSync('openid') && wx.getStorageSync('hasAuth')){
- wx.request({
- url: `${homeApi_empower}/wxstatus`,
- data: {
- unionid: wx.getStorageSync('unionid'),
- openid: wx.getStorageSync('openid'),
- //phoneNumber: that.data.phoneNumber,
- token: token_empower,
- },
- method: 'POST',
- success: function(intervalRes) {
- console.log('intervalRes='+JSON.stringify(intervalRes));
- console.log('intervalRes.data='+JSON.stringify(intervalRes.data));
- //empower.js? [sm]:152 intervalRes.data={"st":"success","status":"0"}
- if (intervalRes.data && intervalRes.data.st && intervalRes.data.status && intervalRes.data.st == 'success' && intervalRes.data.status == '0' ) {
- wx.showToast({
- title: '授权已过期',
- icon: 'none'
- });
- wx.removeStorageSync('userInfo_em');
- wx.removeStorageSync('phoneNumber');
- wx.removeStorageSync('unionid');
- wx.removeStorageSync('openid');
- wx.removeStorageSync('hasAuth');
- wx.removeStorageSync('hotelEmpower');
- wx.removeStorageSync('roomEmpower');
- setTimeout(function() {
- wx.reLaunch({
- url: '/pages/empower/empower',
- })
- }, 2000) // 设置延时时间,单位为毫秒
- }
- },
- });
- }
-
- }, 10000);
- }
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
-
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
-
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
-
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
-
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
-
- }
- })
|