index.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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. // need Login
  100. if (hasAuth) {
  101. this.toPage(index);
  102. } else {
  103. this.showDialog();
  104. }
  105. break;
  106. default:
  107. this.toPage(index);
  108. break;
  109. }
  110. },
  111. toPage(index) {
  112. const type = this.data.menuList[index].type;
  113. const url = this.data.menuList[index].url;
  114. if (!url) {
  115. return
  116. }
  117. if (type == 'switchTab') {
  118. wx.switchTab({
  119. url: url
  120. })
  121. } else if (type == 'navigate') {
  122. wx.navigateTo({
  123. url: url
  124. })
  125. } else if (type == 'miniProgram') {
  126. //develop开发版;trial体验版;release正式版
  127. const appId = this.data.menuCardList[index].appId;
  128. wx.navigateToMiniProgram({
  129. appId: appId,
  130. path: url,
  131. extraData: {
  132. },
  133. envVersion: 'develop',
  134. success(res) {
  135. // 打开成功
  136. }
  137. })
  138. }
  139. },
  140. onMenuCardClick(e) {
  141. console.log(e.currentTarget.dataset);
  142. const { index } = e.currentTarget.dataset;
  143. var hasAuth = wx.getStorageSync("hasAuth");
  144. switch (index - 0) {
  145. case 0:
  146. case 1:
  147. case 2:
  148. case 3:
  149. // need Login
  150. if (hasAuth) {
  151. if (index == 0 || index == 1) {
  152. var hasHotelAuth = wx.getStorageSync("hasHotelAuth");
  153. if (!hasHotelAuth) {
  154. this.setData({
  155. showTipsB:true
  156. })
  157. return
  158. }
  159. }
  160. if (index == 2) {
  161. var hasReportAuth = wx.getStorageSync("hasReportAuth");
  162. var unionid = wx.getStorageSync("unionid");
  163. if (!hasReportAuth || !unionid) {
  164. this.setData({
  165. showTipsA: true
  166. })
  167. return
  168. }
  169. }
  170. this.toCardPage(index);
  171. } else {
  172. this.showDialog();
  173. }
  174. break;
  175. default:
  176. this.toCardPage(index);
  177. break;
  178. }
  179. },
  180. toCardPage(index) {
  181. const type = this.data.menuCardList[index].type;
  182. const url = this.data.menuCardList[index].url;
  183. if (!url) {
  184. return
  185. }
  186. if (type == 'switchTab') {
  187. wx.switchTab({
  188. url: url
  189. })
  190. } else if (type == 'navigate') {
  191. wx.navigateTo({
  192. url: url
  193. })
  194. } else if (type == 'miniProgram') {
  195. //develop开发版;trial体验版;release正式版
  196. const appId = this.data.menuCardList[index].appId;
  197. wx.navigateToMiniProgram({
  198. appId: appId,
  199. path: url,
  200. extraData: {
  201. },
  202. envVersion: 'develop',
  203. success(res) {
  204. // 打开成功
  205. }
  206. })
  207. }
  208. },
  209. /**
  210. * 生命周期函数--监听页面加载
  211. */
  212. onLoad(options) {
  213. },
  214. /**
  215. * 生命周期函数--监听页面初次渲染完成
  216. */
  217. onReady() {
  218. },
  219. /**
  220. * 生命周期函数--监听页面显示
  221. */
  222. onShow() {
  223. this.checkAuth()
  224. },
  225. showDialog() {
  226. var hasAuth = wx.getStorageSync("hasAuth");
  227. if (hasAuth) {
  228. return
  229. }
  230. this.setData({
  231. showAuthorizedDialog: true
  232. })
  233. },
  234. checkAuth() {
  235. var hasAuth = wx.getStorageSync("hasAuth");
  236. this.setData({
  237. hasAuth: hasAuth
  238. })
  239. if (hasAuth) {
  240. var userInfo = wx.getStorageSync("userInfo");
  241. this.setData({
  242. nickName: userInfo.nickName || "用户登录",
  243. avatarUrl: userInfo.avatarUrl || defaultAvatarUrl,
  244. phoneNumber: userInfo.phoneNumber || ""
  245. })
  246. }
  247. return hasAuth;
  248. },
  249. authorizationSuccessful() {
  250. console.log("授权成功");
  251. this.setData({ showAuthorizedDialog: false })
  252. this.checkAuth();
  253. },
  254. /**
  255. * 生命周期函数--监听页面隐藏
  256. */
  257. onHide() {
  258. },
  259. /**
  260. * 生命周期函数--监听页面卸载
  261. */
  262. onUnload() {
  263. },
  264. /**
  265. * 页面相关事件处理函数--监听用户下拉动作
  266. */
  267. onPullDownRefresh() {
  268. },
  269. /**
  270. * 页面上拉触底事件的处理函数
  271. */
  272. onReachBottom() {
  273. },
  274. /**
  275. * 用户点击右上角分享
  276. */
  277. onShareAppMessage() {
  278. }
  279. })