| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327 |
- // pages/mine/mine.js
- const defaultAvatarUrl = "../../static/images/no-login.png"
- const homeApi_empower = "https://aipush.aidsleep.cn";
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- showAuthorizedDialog: false,
- showTipsA: false,
- showTipsB: false,
- hasAuth: false,
- avatarUrl: defaultAvatarUrl,
- nickName: "用户登录",
- phoneNumber: "",
- menuCardList: [{
- icon: "../../static/index/icon/ic_fjkz.png",
- bgIcon: "../../static/index/bg/bg_fjkz.png",
- title: "房间控制",
- type: "navigate",
- color: "#3C84D9",
- bgColor: "#EEF4FF",
- url: "/subpages/main/main"
- }, {
- icon: "../../static/index/icon/ic_sm.png",
- bgIcon: "../../static/index/bg/bg_sm.png",
- title: "扫码",
- type: "navigate",
- color: "#10B09C",
- bgColor: "#E6FFFC",
- url: "/subpages/scan/scan"
- }, {
- icon: "../../static/index/icon/ic_jrsmbg.png",
- bgIcon: "../../static/index/bg/bg_jrsmbg.png",
- title: "今日睡眠报告",
- type: "navigate",
- color: "#8658B9",
- bgColor: "#F6F3FF",
- url: "/subpages/data/data"
- }, {
- icon: "../../static/index/icon/ic_lssmbg.png",
- bgIcon: "../../static/index/bg/bg_lssmbg.png",
- title: "历史睡眠报告",
- type: "navigate",
- color: "#BB6268",
- bgColor: "#FFF6F7",
- url: "/subpages/sleepReport/sleepReport"
- }, {
- icon: "../../static/index/icon/ic_wdcd.png",
- bgIcon: "../../static/index/bg/bg_wdcd.png",
- title: "我的床垫",
- type: "navigate",
- color: "#317A9B",
- bgColor: "#E6FFFC",
- url: "/subpages/myMattress/myMattress"
- }, {
- icon: "../../static/index/icon/ic_zxsc.png",
- bgIcon: "../../static/index/bg/bg_zxsc.png",
- title: "在线商城",
- type: "miniProgram",
- color: "#C2714B",
- bgColor: "#FFF8F4",
- appId: "wx63f79b3d61ba632b" || "gh_78da4ac5d0cc",
- url: "pages/home/dashboard/index"
- }],
- menuList: [{
- icon: "../../static/mine/dcwj.png",
- title: "调查问卷",
- type: "navigate",
- url: "/subpages/testSAS/testSAS"
- }, {
- icon: "../../static/mine/zxkf.png",
- title: "在线客服",
- type: "contact",
- url: ""
- }, {
- icon: "../../static/mine/bzzx.png",
- title: "帮助中心",
- type: "navigate",
- url: ""
- }, {
- icon: "../../static/mine/gywm.png",
- title: "关于我们",
- type: "navigate",
- url: ""
- }]
- },
- onCloseTipsDialog() {
- this.setData({
- showTipsA: false,
- showTipsB:false
- })
- },
- onMenuClick(e) {
- console.log(e.currentTarget.dataset);
- const { index } = e.currentTarget.dataset;
- var hasAuth = wx.getStorageSync("hasAuth");
- switch (index - 0) {
- case 0:
- // need Login
- if (hasAuth) {
- this.toPage(index);
- } else {
- this.showDialog();
- }
- break;
- default:
- this.toPage(index);
- break;
- }
- },
- toPage(index) {
- const type = this.data.menuList[index].type;
- const url = this.data.menuList[index].url;
- if (!url) {
- return
- }
- if (type == 'switchTab') {
- wx.switchTab({
- url: url
- })
- } else if (type == 'navigate') {
- wx.navigateTo({
- url: url
- })
- } else if (type == 'miniProgram') {
- //develop开发版;trial体验版;release正式版
- const appId = this.data.menuCardList[index].appId;
- wx.navigateToMiniProgram({
- appId: appId,
- path: url,
- extraData: {
- },
- envVersion: 'develop',
- success(res) {
- // 打开成功
- }
- })
- }
- },
- onMenuCardClick(e) {
- console.log(e.currentTarget.dataset);
- const { index } = e.currentTarget.dataset;
- var hasAuth = wx.getStorageSync("hasAuth");
- switch (index - 0) {
- case 0:
- case 1:
- case 2:
- case 3:
- // need Login
- if (hasAuth) {
- if (index == 0) {
- var hasHotelAuth = wx.getStorageSync("hasHotelAuth");
- if (!hasHotelAuth) {
- this.setData({
- showTipsB:true
- })
- return
- }
- }
- if (index == 2) {
- var hasReportAuth = wx.getStorageSync("hasReportAuth");
- var unionid = wx.getStorageSync("unionid");
- if (!hasReportAuth || !unionid) {
- this.setData({
- showTipsA: true
- })
- return
- }
- }
- this.toCardPage(index);
- } else {
- this.showDialog();
- }
- break;
- default:
- this.toCardPage(index);
- break;
- }
- },
- toCardPage(index) {
- const type = this.data.menuCardList[index].type;
- const url = this.data.menuCardList[index].url;
- if (!url) {
- return
- }
- if (type == 'switchTab') {
- wx.switchTab({
- url: url
- })
- } else if (type == 'navigate') {
- wx.navigateTo({
- url: url
- })
- } else if (type == 'miniProgram') {
- //develop开发版;trial体验版;release正式版
- const appId = this.data.menuCardList[index].appId;
- wx.navigateToMiniProgram({
- appId: appId,
- path: url,
- extraData: {
- },
- envVersion: 'develop',
- success(res) {
- // 打开成功
- }
- })
- }
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- wx.hideTabBar()
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- wx.hideTabBar()
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- wx.hideTabBar()
- this.checkAuth()
- },
- showDialog() {
- var hasAuth = wx.getStorageSync("hasAuth");
- if (hasAuth) {
- return
- }
- this.setData({
- showAuthorizedDialog: true
- })
- },
- checkAuth() {
- var hasAuth = wx.getStorageSync("hasAuth");
- this.setData({
- hasAuth: hasAuth
- })
- if (hasAuth) {
- var userInfo = wx.getStorageSync("userInfo");
- this.setData({
- nickName: userInfo.nickName || "用户登录",
- avatarUrl: userInfo.avatarUrl || defaultAvatarUrl,
- phoneNumber: userInfo.phoneNumber || ""
- })
- // 判断扫码控制权限
- 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) {
- }
- });
- }
- return hasAuth;
- },
- authorizationSuccessful() {
- console.log("授权成功");
- this.setData({ showAuthorizedDialog: false })
- this.checkAuth();
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- }
- })
|