index.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // pages/login/login.js
  2. const app = getApp();
  3. const { system, admin, county, user } = 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. if (data.is_routine && data.is_routine == '1') {
  26. wx.showToast({ title: `绑定微信成功`, icon: 'success', duration: 2000 })
  27. } else if (data.is_routine && data.is_routine == '2') {
  28. wx.clearStorage({
  29. key: 'toekn',
  30. success: res => {
  31. wx.showToast({ title: `退出登录成功`, icon: 'success', duration: 2000 })
  32. wx.redirectTo({ url: '/pages/login/index', })
  33. }
  34. })
  35. } else {
  36. wx.navigateTo({ url: `/pages/${data.router}/index` })
  37. }
  38. },
  39. /**
  40. * 生命周期函数--监听页面加载
  41. */
  42. onLoad: function (options) {
  43. // 查询用户是否登录
  44. wx.getStorage({
  45. key: 'token',
  46. success: res => {
  47. if (res.data) {
  48. let userInfo = app.globalData.userInfo;
  49. if (userInfo) this.setData({ userInfo: userInfo });
  50. // 查询菜单
  51. if (userInfo) this.searchRouter();
  52. } else {
  53. wx.redirectTo({ url: '/pages/login/index', })
  54. }
  55. }
  56. })
  57. // 计算高度
  58. this.searchHeight();
  59. },
  60. // 计算高度
  61. searchHeight: function () {
  62. let frameStyle = this.data.frameStyle;
  63. let client = app.globalData.client;
  64. // 减去状态栏
  65. let infoHeight = client.windowHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  66. // 是否减去底部菜单
  67. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  68. if (infoHeight) this.setData({ infoHeight: infoHeight })
  69. },
  70. // 查询菜单
  71. searchRouter() {
  72. wx.getStorage({
  73. key: 'role',
  74. success: res => {
  75. var data = [];
  76. if (res.data == '1') { data = [...admin, ...system] }
  77. else if (res.data == '2') { data = [...county, ...system] }
  78. else if (res.data == '3') { data = [...user, ...system] }
  79. this.setData({ routerList: data })
  80. }
  81. })
  82. },
  83. /**
  84. * 生命周期函数--监听页面初次渲染完成
  85. */
  86. onReady: function () {
  87. },
  88. /**
  89. * 生命周期函数--监听页面显示
  90. */
  91. onShow: function () {
  92. },
  93. /**
  94. * 生命周期函数--监听页面隐藏
  95. */
  96. onHide: function () {
  97. },
  98. /**
  99. * 生命周期函数--监听页面卸载
  100. */
  101. onUnload: function () {
  102. },
  103. /**
  104. * 页面相关事件处理函数--监听用户下拉动作
  105. */
  106. onPullDownRefresh: function () {
  107. },
  108. /**
  109. * 页面上拉触底事件的处理函数
  110. */
  111. onReachBottom: function () {
  112. },
  113. /**
  114. * 用户点击右上角分享
  115. */
  116. onShareAppMessage: function () {
  117. }
  118. })