// pages/mine/mine.js const defaultAvatarUrl = "../../static/images/no-login.png" 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: "" }, { 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: case 1: // 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: // need Login if (hasAuth) { 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) { }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { 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 || "" }) } return hasAuth; }, authorizationSuccessful() { console.log("授权成功"); this.setData({ showAuthorizedDialog: false }) this.checkAuth(); }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })