index.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. // pages/mine/mine.js
  2. const defaultAvatarUrl = "../../static/images/no-login.png"
  3. const homeApi_empower = "https://aipush.aidsleep.cn";
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. showAuthorizedDialog: false,
  10. showTipsA: false,
  11. showTipsB: false,
  12. hasAuth: false,
  13. avatarUrl: defaultAvatarUrl,
  14. nickName: "用户登录",
  15. phoneNumber: "",
  16. menuCardList: [{
  17. icon: "../../static/index/icon/ic_fjkz.png",
  18. bgIcon: "../../static/index/bg/bg_fjkz.png",
  19. title: "房间控制",
  20. type: "navigate",
  21. color: "#3C84D9",
  22. bgColor: "#EEF4FF",
  23. url: "/subpages/main/main"
  24. }, {
  25. icon: "../../static/index/icon/ic_sm.png",
  26. bgIcon: "../../static/index/bg/bg_sm.png",
  27. title: "扫码",
  28. type: "navigate",
  29. color: "#10B09C",
  30. bgColor: "#E6FFFC",
  31. url: "/subpages/scan/scan"
  32. }, {
  33. icon: "../../static/index/icon/ic_jrsmbg.png",
  34. bgIcon: "../../static/index/bg/bg_jrsmbg.png",
  35. title: "今日睡眠报告",
  36. type: "navigate",
  37. color: "#8658B9",
  38. bgColor: "#F6F3FF",
  39. url: "/subpages/data/data"
  40. }, {
  41. icon: "../../static/index/icon/ic_lssmbg.png",
  42. bgIcon: "../../static/index/bg/bg_lssmbg.png",
  43. title: "历史睡眠报告",
  44. type: "navigate",
  45. color: "#BB6268",
  46. bgColor: "#FFF6F7",
  47. url: "/subpages/sleepReport/sleepReport"
  48. }, {
  49. icon: "../../static/index/icon/ic_wdcd.png",
  50. bgIcon: "../../static/index/bg/bg_wdcd.png",
  51. title: "我的床垫",
  52. type: "navigate",
  53. color: "#317A9B",
  54. bgColor: "#E6FFFC",
  55. url: "/subpages/myMattress/myMattress"
  56. }, {
  57. icon: "../../static/index/icon/ic_zxsc.png",
  58. bgIcon: "../../static/index/bg/bg_zxsc.png",
  59. title: "在线商城",
  60. type: "miniProgram",
  61. color: "#C2714B",
  62. bgColor: "#FFF8F4",
  63. appId: "wx63f79b3d61ba632b" || "gh_78da4ac5d0cc",
  64. url: "pages/home/dashboard/index"
  65. }],
  66. menuList: [{
  67. icon: "../../static/mine/dcwj.png",
  68. title: "调查问卷",
  69. type: "navigate",
  70. url: "/subpages/testSAS/testSAS"
  71. }, {
  72. icon: "../../static/mine/zxkf.png",
  73. title: "在线客服",
  74. type: "contact",
  75. url: ""
  76. }, {
  77. icon: "../../static/mine/bzzx.png",
  78. title: "帮助中心",
  79. type: "navigate",
  80. url: ""
  81. }, {
  82. icon: "../../static/mine/gywm.png",
  83. title: "关于我们",
  84. type: "navigate",
  85. url: ""
  86. }]
  87. },
  88. onCloseTipsDialog() {
  89. this.setData({
  90. showTipsA: false,
  91. showTipsB:false
  92. })
  93. },
  94. onMenuClick(e) {
  95. console.log(e.currentTarget.dataset);
  96. const { index } = e.currentTarget.dataset;
  97. var hasAuth = wx.getStorageSync("hasAuth");
  98. switch (index - 0) {
  99. case 0:
  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. case 2:
  149. case 3:
  150. // need Login
  151. if (hasAuth) {
  152. if (index == 0) {
  153. var hasHotelAuth = wx.getStorageSync("hasHotelAuth");
  154. if (!hasHotelAuth) {
  155. this.setData({
  156. showTipsB:true
  157. })
  158. return
  159. }
  160. }
  161. if (index == 2) {
  162. var hasReportAuth = wx.getStorageSync("hasReportAuth");
  163. var unionid = wx.getStorageSync("unionid");
  164. if (!hasReportAuth || !unionid) {
  165. this.setData({
  166. showTipsA: true
  167. })
  168. return
  169. }
  170. }
  171. this.toCardPage(index);
  172. } else {
  173. this.showDialog();
  174. }
  175. break;
  176. default:
  177. this.toCardPage(index);
  178. break;
  179. }
  180. },
  181. toCardPage(index) {
  182. const type = this.data.menuCardList[index].type;
  183. const url = this.data.menuCardList[index].url;
  184. if (!url) {
  185. return
  186. }
  187. if (type == 'switchTab') {
  188. wx.switchTab({
  189. url: url
  190. })
  191. } else if (type == 'navigate') {
  192. wx.navigateTo({
  193. url: url
  194. })
  195. } else if (type == 'miniProgram') {
  196. //develop开发版;trial体验版;release正式版
  197. const appId = this.data.menuCardList[index].appId;
  198. wx.navigateToMiniProgram({
  199. appId: appId,
  200. path: url,
  201. extraData: {
  202. },
  203. envVersion: 'develop',
  204. success(res) {
  205. // 打开成功
  206. }
  207. })
  208. }
  209. },
  210. /**
  211. * 生命周期函数--监听页面加载
  212. */
  213. onLoad(options) {
  214. wx.hideTabBar()
  215. },
  216. /**
  217. * 生命周期函数--监听页面初次渲染完成
  218. */
  219. onReady() {
  220. wx.hideTabBar()
  221. },
  222. /**
  223. * 生命周期函数--监听页面显示
  224. */
  225. onShow() {
  226. wx.hideTabBar()
  227. this.checkAuth()
  228. },
  229. showDialog() {
  230. var hasAuth = wx.getStorageSync("hasAuth");
  231. if (hasAuth) {
  232. return
  233. }
  234. this.setData({
  235. showAuthorizedDialog: true
  236. })
  237. },
  238. checkAuth() {
  239. var hasAuth = wx.getStorageSync("hasAuth");
  240. this.setData({
  241. hasAuth: hasAuth
  242. })
  243. if (hasAuth) {
  244. var userInfo = wx.getStorageSync("userInfo");
  245. this.setData({
  246. nickName: userInfo.nickName || "用户登录",
  247. avatarUrl: userInfo.avatarUrl || defaultAvatarUrl,
  248. phoneNumber: userInfo.phoneNumber || ""
  249. })
  250. // 判断扫码控制权限
  251. wx.request({
  252. url: `${homeApi_empower}/wxstatus`,
  253. data: {
  254. unionid: wx.getStorageSync('unionid'),
  255. openid: wx.getStorageSync('openid'),
  256. token: wx.getStorageSync('token'),
  257. },
  258. method: 'POST',
  259. success: function (intervalRes) {
  260. console.log('intervalRes=' + JSON.stringify(intervalRes));
  261. console.log('intervalRes.data=' + JSON.stringify(intervalRes.data));
  262. //empower.js? [sm]:152 intervalRes.data={"st":"success","status":"0"}
  263. if (intervalRes.data && intervalRes.data.st && intervalRes.data.status && intervalRes.data.st == 'success' && intervalRes.data.status == '1') {
  264. wx.setStorageSync('hasHotelAuth', true);
  265. wx.setStorageSync('hotelEmpower', intervalRes.data.hotel);
  266. wx.setStorageSync('roomEmpower', intervalRes.data.room);
  267. wx.setStorageSync('hname', intervalRes.data.hname);
  268. wx.setStorageSync('rname', intervalRes.data.rname);
  269. } else {
  270. wx.setStorageSync('hasHotelAuth', false);
  271. }
  272. },
  273. fail: function (error) {
  274. }
  275. });
  276. }
  277. return hasAuth;
  278. },
  279. authorizationSuccessful() {
  280. console.log("授权成功");
  281. this.setData({ showAuthorizedDialog: false })
  282. this.checkAuth();
  283. },
  284. /**
  285. * 生命周期函数--监听页面隐藏
  286. */
  287. onHide() {
  288. },
  289. /**
  290. * 生命周期函数--监听页面卸载
  291. */
  292. onUnload() {
  293. },
  294. /**
  295. * 页面相关事件处理函数--监听用户下拉动作
  296. */
  297. onPullDownRefresh() {
  298. },
  299. /**
  300. * 页面上拉触底事件的处理函数
  301. */
  302. onReachBottom() {
  303. },
  304. /**
  305. * 用户点击右上角分享
  306. */
  307. onShareAppMessage() {
  308. }
  309. })