index.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. // pages/mine/mine.js
  2. const defaultAvatarUrl = "../../static/images/no-login.png"
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. showAuthorizedDialog: false,
  9. showTipsA: false,
  10. showTipsB: false,
  11. hasAuth: false,
  12. avatarUrl: defaultAvatarUrl,
  13. nickName: "用户登录",
  14. phoneNumber: "",
  15. menuCardList: [{
  16. icon: "../../static/index/icon/ic_fjkz.png",
  17. bgIcon: "../../static/index/bg/bg_fjkz.png",
  18. title: "房间控制",
  19. type: "navigate",
  20. color: "#3C84D9",
  21. bgColor: "#EEF4FF",
  22. url: "/subpages/main/main"
  23. }, {
  24. icon: "../../static/index/icon/ic_sm.png",
  25. bgIcon: "../../static/index/bg/bg_sm.png",
  26. title: "扫码",
  27. type: "navigate",
  28. color: "#10B09C",
  29. bgColor: "#E6FFFC",
  30. url: "/subpages/scan/scan"
  31. }, {
  32. icon: "../../static/index/icon/ic_jrsmbg.png",
  33. bgIcon: "../../static/index/bg/bg_jrsmbg.png",
  34. title: "今日睡眠报告",
  35. type: "navigate",
  36. color: "#8658B9",
  37. bgColor: "#F6F3FF",
  38. url: "/subpages/data/data"
  39. }, {
  40. icon: "../../static/index/icon/ic_lssmbg.png",
  41. bgIcon: "../../static/index/bg/bg_lssmbg.png",
  42. title: "历史睡眠报告",
  43. type: "navigate",
  44. color: "#BB6268",
  45. bgColor: "#FFF6F7",
  46. url: "/subpages/sleepReport/sleepReport"
  47. }, {
  48. icon: "../../static/index/icon/ic_wdcd.png",
  49. bgIcon: "../../static/index/bg/bg_wdcd.png",
  50. title: "我的床垫",
  51. type: "navigate",
  52. color: "#317A9B",
  53. bgColor: "#E6FFFC",
  54. url: ""
  55. }, {
  56. icon: "../../static/index/icon/ic_zxsc.png",
  57. bgIcon: "../../static/index/bg/bg_zxsc.png",
  58. title: "在线商城",
  59. type: "miniProgram",
  60. color: "#C2714B",
  61. bgColor: "#FFF8F4",
  62. appId: "wx63f79b3d61ba632b" || "gh_78da4ac5d0cc",
  63. url: "pages/home/dashboard/index"
  64. }],
  65. menuList: [{
  66. icon: "../../static/mine/dcwj.png",
  67. title: "调查问卷",
  68. type: "navigate",
  69. url: "/subpages/testSAS/testSAS"
  70. }, {
  71. icon: "../../static/mine/zxkf.png",
  72. title: "在线客服",
  73. type: "contact",
  74. url: ""
  75. }, {
  76. icon: "../../static/mine/bzzx.png",
  77. title: "帮助中心",
  78. type: "navigate",
  79. url: ""
  80. }, {
  81. icon: "../../static/mine/gywm.png",
  82. title: "关于我们",
  83. type: "navigate",
  84. url: ""
  85. }]
  86. },
  87. onCloseTipsDialog() {
  88. this.setData({
  89. showTipsA: false,
  90. showTipsB:false
  91. })
  92. },
  93. onMenuClick(e) {
  94. console.log(e.currentTarget.dataset);
  95. const { index } = e.currentTarget.dataset;
  96. var hasAuth = wx.getStorageSync("hasAuth");
  97. switch (index - 0) {
  98. case 0:
  99. case 1:
  100. // need Login
  101. if (hasAuth) {
  102. this.toPage(index);
  103. } else {
  104. this.showDialog();
  105. }
  106. break;
  107. default:
  108. this.toPage(index);
  109. break;
  110. }
  111. },
  112. toPage(index) {
  113. const type = this.data.menuList[index].type;
  114. const url = this.data.menuList[index].url;
  115. if (!url) {
  116. return
  117. }
  118. if (type == 'switchTab') {
  119. wx.switchTab({
  120. url: url
  121. })
  122. } else if (type == 'navigate') {
  123. wx.navigateTo({
  124. url: url
  125. })
  126. } else if (type == 'miniProgram') {
  127. //develop开发版;trial体验版;release正式版
  128. const appId = this.data.menuCardList[index].appId;
  129. wx.navigateToMiniProgram({
  130. appId: appId,
  131. path: url,
  132. extraData: {
  133. },
  134. envVersion: 'develop',
  135. success(res) {
  136. // 打开成功
  137. }
  138. })
  139. }
  140. },
  141. onMenuCardClick(e) {
  142. console.log(e.currentTarget.dataset);
  143. const { index } = e.currentTarget.dataset;
  144. var hasAuth = wx.getStorageSync("hasAuth");
  145. switch (index - 0) {
  146. case 0:
  147. case 1:
  148. // need Login
  149. if (hasAuth) {
  150. this.toCardPage(index);
  151. } else {
  152. this.showDialog();
  153. }
  154. break;
  155. default:
  156. this.toCardPage(index);
  157. break;
  158. }
  159. },
  160. toCardPage(index) {
  161. const type = this.data.menuCardList[index].type;
  162. const url = this.data.menuCardList[index].url;
  163. if (!url) {
  164. return
  165. }
  166. if (type == 'switchTab') {
  167. wx.switchTab({
  168. url: url
  169. })
  170. } else if (type == 'navigate') {
  171. wx.navigateTo({
  172. url: url
  173. })
  174. } else if (type == 'miniProgram') {
  175. //develop开发版;trial体验版;release正式版
  176. const appId = this.data.menuCardList[index].appId;
  177. wx.navigateToMiniProgram({
  178. appId: appId,
  179. path: url,
  180. extraData: {
  181. },
  182. envVersion: 'develop',
  183. success(res) {
  184. // 打开成功
  185. }
  186. })
  187. }
  188. },
  189. /**
  190. * 生命周期函数--监听页面加载
  191. */
  192. onLoad(options) {
  193. },
  194. /**
  195. * 生命周期函数--监听页面初次渲染完成
  196. */
  197. onReady() {
  198. },
  199. /**
  200. * 生命周期函数--监听页面显示
  201. */
  202. onShow() {
  203. this.checkAuth()
  204. },
  205. showDialog() {
  206. var hasAuth = wx.getStorageSync("hasAuth");
  207. if (hasAuth) {
  208. return
  209. }
  210. this.setData({
  211. showAuthorizedDialog: true
  212. })
  213. },
  214. checkAuth() {
  215. var hasAuth = wx.getStorageSync("hasAuth");
  216. this.setData({
  217. hasAuth: hasAuth
  218. })
  219. if (hasAuth) {
  220. var userInfo = wx.getStorageSync("userInfo");
  221. this.setData({
  222. nickName: userInfo.nickName || "用户登录",
  223. avatarUrl: userInfo.avatarUrl || defaultAvatarUrl,
  224. phoneNumber: userInfo.phoneNumber || ""
  225. })
  226. }
  227. return hasAuth;
  228. },
  229. authorizationSuccessful() {
  230. console.log("授权成功");
  231. this.setData({ showAuthorizedDialog: false })
  232. this.checkAuth();
  233. },
  234. /**
  235. * 生命周期函数--监听页面隐藏
  236. */
  237. onHide() {
  238. },
  239. /**
  240. * 生命周期函数--监听页面卸载
  241. */
  242. onUnload() {
  243. },
  244. /**
  245. * 页面相关事件处理函数--监听用户下拉动作
  246. */
  247. onPullDownRefresh() {
  248. },
  249. /**
  250. * 页面上拉触底事件的处理函数
  251. */
  252. onReachBottom() {
  253. },
  254. /**
  255. * 用户点击右上角分享
  256. */
  257. onShareAppMessage() {
  258. }
  259. })