index.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. // pages/login/login.js
  2. import WxValidate from '../../utils/wxValidate'
  3. const app = getApp()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. frameStyle: { useTop: true, name: '用户管理', leftArrow: true, useBar: false },
  10. // 主体高度
  11. infoHeight: '',
  12. // 信息列表
  13. list: [],
  14. // 弹框
  15. dialog: { title: '详细信息', show: false, type: '1' },
  16. // 详细信息
  17. info: {},
  18. },
  19. back: function () {
  20. wx.navigateBack({ url: '/pages/home/index' })
  21. },
  22. // 添加用户
  23. toAdd: function () {
  24. wx.navigateTo({ url: '/pages/user/detail' })
  25. },
  26. // 详细信息
  27. toView: function (e) {
  28. this.setData({ dialog: { title: '详细信息', show: true, type: '1' } })
  29. },
  30. // 信息变更
  31. toEdit: function (e) {
  32. const { id } = e.currentTarget.dataset;
  33. wx.navigateTo({ url: `/pages/user/detail?id=${id}` })
  34. },
  35. // 密码重置
  36. toReset: function (e) {
  37. wx.showModal({
  38. content: '您确定密码重置吗?',
  39. title: '密码重置',
  40. success: (res) => {
  41. if (res.confirm) {
  42. wx.showToast({ title: `密码重置成功`, icon: 'success', duration: 2000 })
  43. }
  44. },
  45. })
  46. },
  47. // 刪除信息
  48. toDel: function (e) {
  49. wx.showModal({
  50. content: '您确定刪除信息吗?',
  51. title: '刪除信息',
  52. success: (res) => {
  53. if (res.confirm) {
  54. wx.showToast({ title: `刪除信息成功`, icon: 'success', duration: 2000 })
  55. }
  56. },
  57. })
  58. },
  59. /**
  60. * 生命周期函数--监听页面加载
  61. */
  62. onLoad: function (options) {
  63. // 监听用户是否登录
  64. this.watchLogin();
  65. // 计算高度
  66. this.searchHeight()
  67. },
  68. // 监听用户是否登录
  69. watchLogin: function () {
  70. let data = [{ id: '1234567', name: '测试人员', phone: '12345678901', email: '123456@qq.com' }]
  71. this.setData({ list: data })
  72. // wx.getStorage({
  73. // key: 'user',
  74. // success: res => {
  75. // if (res.data) {
  76. // // 查询菜单
  77. // if (res.data) this.searchRouter(res.data);
  78. // res.data.type = type.find((i) => i.value == res.data.type).label;
  79. // if (res.data) this.setData({ userInfo: res.data });
  80. // if (res.data && res.data.avatarUrl) this.setData({ avatarUrl: res.data.avatarUrl });
  81. // } else {
  82. // wx.redirectTo({ url: '/pages/login/index', })
  83. // }
  84. // }
  85. // })
  86. },
  87. // 计算高度
  88. searchHeight: function () {
  89. let frameStyle = this.data.frameStyle;
  90. let client = app.globalData.client;
  91. let infoHeight = client.windowHeight;
  92. // 是否去掉状态栏
  93. if (frameStyle.useTop) infoHeight = infoHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  94. // 是否减去底部菜单
  95. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  96. if (infoHeight) this.setData({ infoHeight: infoHeight })
  97. },
  98. /**
  99. * 生命周期函数--监听页面初次渲染完成
  100. */
  101. onReady: function () {
  102. },
  103. /**
  104. * 生命周期函数--监听页面显示
  105. */
  106. onShow: function () {
  107. },
  108. /**
  109. * 生命周期函数--监听页面隐藏
  110. */
  111. onHide: function () {
  112. },
  113. /**
  114. * 生命周期函数--监听页面卸载
  115. */
  116. onUnload: function () {
  117. },
  118. /**
  119. * 页面相关事件处理函数--监听用户下拉动作
  120. */
  121. onPullDownRefresh: function () {
  122. },
  123. /**
  124. * 页面上拉触底事件的处理函数
  125. */
  126. onReachBottom: function () {
  127. },
  128. /**
  129. * 用户点击右上角分享
  130. */
  131. onShareAppMessage: function () {
  132. }
  133. })