| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- // app.js
- const homeApi_empower = "https://aipush.aidsleep.cn";
- App({
- onLaunch() {
- // 在需要隐藏 tabBar 的页面的脚本中调用
- wx.hideTabBar({
- animation: false, // 是否需要动画效果,默认为 false
- success: function () {
- console.log('TabBar 已经被隐藏');
- },
- fail: function (err) {
- console.error('隐藏 TabBar 失败', err);
- }
- });
- // 展示本地存储能力
- // const logs = wx.getStorageSync('logs') || []
- // logs.unshift(Date.now())
- // wx.setStorageSync('logs', logs)
- // this.globalData.selectedTabIndex = wx.getStorageSync("selectedTabIndex") || 0;
- // 登录
- wx.login({
- success: res => {
- // 发送 res.code 到后台换取 openId, sessionKey, unionId
- wx.request({
- url: `${homeApi_empower}/wxssk`,
- method: 'POST',
- data: {
- code: res.code,
- },
- success: function (loginRes) {
- // 处理服务器返回的结果
- console.log('登录获取结果:', loginRes.data);
- if (loginRes.data) {
- wx.setStorageSync("openid", loginRes.data.openid);
- wx.setStorageSync("token", loginRes.data.token);
- wx.setStorageSync("unionid", loginRes.data.unionid);
- // 判断扫码控制权限
- wx.request({
- url: `${homeApi_empower}/wxstatus`,
- data: {
- unionid: wx.getStorageSync('unionid'),
- openid: wx.getStorageSync('openid'),
- token: wx.getStorageSync('token'),
- },
- 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 == '1') {
- wx.setStorageSync('hasHotelAuth', true);
- wx.setStorageSync('hotelEmpower', intervalRes.data.hotel);
- wx.setStorageSync('roomEmpower', intervalRes.data.room);
- } else {
- wx.setStorageSync('hasHotelAuth', false);
- }
- },
- fail: function (error) {
- }
- });
- // 判断今日睡眠报告权限
- wx.request({
- url: 'https://aipush.aidsleep.cn/srpwithrange',
- method: 'POST',
- data: {
- token: "89835e65993fee4a6a6cbbe4c271da51e5521822934e13769e61cadabaed72c3" || wx.getStorageSync('token'),
- udi: wx.getStorageSync('unionid'),
- pg: 1,
- lm: 1
- },
- success: (res) => {
- var loadData = res.data.data;
- if ((Array.isArray(loadData) && loadData.length > 0) || (loadData && !Array.isArray(loadData)) ) {
- wx.setStorageSync('hasReportAuth', true);
- } else {
- wx.setStorageSync('hasReportAuth', false);
- }
- },
- fail: () => {
- wx.setStorageSync('hasReportAuth', false);
- }
- });
- }
- }
- })
- }
- })
- },
- onShow() {
- wx.hideTabBar()
- },
- globalData: {
- userInfo: null,
- selectedTabIndex: 0
- }
- })
|