index.js 5.1 KB

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