index.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. // pages/login/login.js
  2. const app = getApp();
  3. const { system, router_zero, router_one, router_two, router_thr, router_four, router_five, router_six, type } = require('../../utils/dict');
  4. const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. frameStyle: { useTop: true, name: '个人中心', leftArrow: false, useBar: false },
  11. // 主体高度
  12. infoHeight: '',
  13. avatarUrl: defaultAvatarUrl,
  14. userInfo: {},
  15. routerList: []
  16. },
  17. // 获取头像
  18. onChooseAvatar(e) {
  19. const { avatarUrl } = e.detail;
  20. this.setData({ avatarUrl })
  21. },
  22. // 跳转页面
  23. toPath: function (e) {
  24. const { data } = e.currentTarget.dataset;
  25. // 绑定微信
  26. if (data.is_routine && data.is_routine == '1') {
  27. wx.showModal({
  28. content: '您确定使用此微信绑定当前登录账号吗?',
  29. title: '绑定微信',
  30. success: (res) => {
  31. if (res.confirm) {
  32. wx.showToast({ title: `绑定微信成功`, icon: 'success', duration: 2000 })
  33. }
  34. },
  35. })
  36. // wx.getStorage({
  37. // key: 'user',
  38. // success: res => {
  39. // if (res.data) {
  40. // const { openid } = app.globalData.wxInfo;
  41. // wx.request({
  42. // url: app.globalData.publicUrl + `/api/hc/user/update/${res.data.id}`,
  43. // method: "post",
  44. // data: { openid: openid },
  45. // header: {},
  46. // success: (res) => {
  47. // if (res.data.errcode == '0') {
  48. // wx.showToast({ title: `绑定微信成功`, icon: 'success', duration: 2000 })
  49. // } else {
  50. // wx.showToast({ title: `${res.data.errmsg}`, icon: 'error', duration: 2000 })
  51. // }
  52. // },
  53. // })
  54. // }
  55. // }
  56. // })
  57. } else if (data.is_routine && data.is_routine == '2') {
  58. wx.clearStorage({
  59. key: 'user',
  60. success: res => {
  61. wx.showToast({ title: `退出登录成功`, icon: 'success', duration: 2000 })
  62. wx.redirectTo({ url: '/pages/login/index', })
  63. }
  64. })
  65. } else {
  66. wx.navigateTo({ url: `/pages/${data.router}/index` })
  67. }
  68. },
  69. /**
  70. * 生命周期函数--监听页面加载
  71. */
  72. onLoad: function (options) {
  73. // 监听用户是否登录
  74. this.watchLogin();
  75. // 计算高度
  76. this.searchHeight();
  77. },
  78. // 监听用户是否登录
  79. watchLogin: function () {
  80. let data = { type: '0' }
  81. this.searchRouter(data);
  82. // wx.getStorage({
  83. // key: 'user',
  84. // success: res => {
  85. // if (res.data) {
  86. // // 查询菜单
  87. // if (res.data) this.searchRouter(res.data);
  88. // res.data.type = type.find((i) => i.value == res.data.type).label;
  89. // if (res.data) this.setData({ userInfo: res.data });
  90. // if (res.data && res.data.avatarUrl) this.setData({ avatarUrl: res.data.avatarUrl });
  91. // } else {
  92. // wx.redirectTo({ url: '/pages/login/index', })
  93. // }
  94. // }
  95. // })
  96. },
  97. // 计算高度
  98. searchHeight: function () {
  99. let frameStyle = this.data.frameStyle;
  100. let client = app.globalData.client;
  101. // 减去状态栏
  102. let infoHeight = client.windowHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  103. // 是否减去底部菜单
  104. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  105. if (infoHeight) this.setData({ infoHeight: infoHeight })
  106. },
  107. // 查询菜单
  108. searchRouter(data) {
  109. // { value: '0', label: '超级管理员' },
  110. // { value: '1', label: '科室人员' },
  111. // { value: '2', label: '办公室人员' },
  112. // { value: '3', label: '采购部门' },
  113. // { value: '4', label: '入库管理部门' },
  114. // { value: '5', label: '财务部门' },
  115. // { value: '6', label: '供货单位' },
  116. var router = [];
  117. if (data.type == '0') { router = [...router_zero, ...system] }
  118. else if (data.type == '1') { router = [...router_one, ...system] }
  119. else if (data.type == '2') { router = [...router_two, ...system] }
  120. else if (data.type == '3') { router = [...router_thr, ...system] }
  121. else if (data.type == '4') { router = [...router_four, ...system] }
  122. else if (data.type == '5') { router = [...router_five, ...system] }
  123. else if (data.type == '6') { router = [...router_six, ...system] }
  124. this.setData({ routerList: router })
  125. },
  126. /**
  127. * 生命周期函数--监听页面初次渲染完成
  128. */
  129. onReady: function () {
  130. },
  131. /**
  132. * 生命周期函数--监听页面显示
  133. */
  134. onShow: function () {
  135. },
  136. /**
  137. * 生命周期函数--监听页面隐藏
  138. */
  139. onHide: function () {
  140. },
  141. /**
  142. * 生命周期函数--监听页面卸载
  143. */
  144. onUnload: function () {
  145. },
  146. /**
  147. * 页面相关事件处理函数--监听用户下拉动作
  148. */
  149. onPullDownRefresh: function () {
  150. },
  151. /**
  152. * 页面上拉触底事件的处理函数
  153. */
  154. onReachBottom: function () {
  155. },
  156. /**
  157. * 用户点击右上角分享
  158. */
  159. onShareAppMessage: function () {
  160. }
  161. })