index.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. const app = getApp()
  2. import { my_menu } from "../../utils/site";
  3. Page({
  4. data: {
  5. logo: '',
  6. avatarUrl: '',
  7. user: {},
  8. // 按钮
  9. menuList: my_menu,
  10. // 状态
  11. statusList: []
  12. },
  13. toPath(e) {
  14. let data = e.detail;
  15. let url = `/${data.route}`;
  16. if (data.type == '0') wx.navigateTo({ url })
  17. else if (data.type == '1') wx.redirectTo({ url })
  18. else if (data.type == '2') wx.relaunch({ url })
  19. else if (data.type == '3') wx.switchTab({ url })
  20. },
  21. // 我的服务-功能按钮
  22. toCommon: function (e) {
  23. const that = this;
  24. if (that.data.user._id) {
  25. let { route } = e.currentTarget.dataset;
  26. if (route) wx.navigateTo({ url: `/${route}` })
  27. else {
  28. wx.showModal({
  29. title: '提示',
  30. content: '是否确认退出登录',
  31. success(res) {
  32. if (res.confirm) {
  33. wx.removeStorage({
  34. key: 'token',
  35. success(res) {
  36. return wx.redirectTo({ url: '/pagesHome/home/index' })
  37. }
  38. })
  39. }
  40. }
  41. })
  42. }
  43. } else {
  44. wx.showToast({ title: `暂无用户信息,无法查看`, icon: 'none' });
  45. wx.navigateTo({ url: '/pagesCommon/login/index' })
  46. }
  47. },
  48. // 获取头像
  49. async toAvatarUrl(e) {
  50. const that = this;
  51. const { avatarUrl } = e.detail
  52. let res = await app.$apifile('files/ball/users/upload', null, avatarUrl)
  53. res = JSON.parse(res);
  54. if (res.errcode == '0') {
  55. let icon = [{ id: res.id, name: res.name, uri: res.uri, url: `${app.globalData.fileserverUrl}` + res.uri }]
  56. let arr = await app.$api(`user/${that.data.user._id}`, 'POST', { icon: icon });
  57. if (arr.errcode == '0') {
  58. wx.showToast({ title: `头像上传成功`, icon: 'success' });
  59. that.search()
  60. } else {
  61. wx.showToast({ title: `${arr.errmsg}`, icon: 'error' });
  62. }
  63. }
  64. },
  65. /**
  66. * 生命周期函数--监听页面加载
  67. */
  68. async onLoad(options) {
  69. const that = this;
  70. wx.showLoading({ title: '加载中', mask: true })
  71. await that.searchOther();
  72. await that.searchConfig();
  73. await that.search()
  74. wx.hideLoading()
  75. },
  76. searchConfig() {
  77. const that = this;
  78. wx.getStorage({
  79. key: 'config',
  80. async success(res) {
  81. // 管理员。
  82. if (res.data && res.data.logo_url && res.data.logo_url.length > 0) {
  83. let logo = res.data.logo_url[0].url
  84. that.setData({ logo })
  85. }
  86. },
  87. fail(err) {
  88. console.log(err);
  89. }
  90. })
  91. },
  92. async search() {
  93. const that = this;
  94. wx.getStorage({
  95. key: 'token',
  96. async success(res) {
  97. let arr = await app.$api(`user/${res.data._id}`, 'GET', {})
  98. if (arr.errcode == '0') {
  99. let user = arr.data;
  100. // 审核字段处理
  101. user.status_name = that.getDict(user.status, 'statusList')
  102. // 头像字段处理
  103. if (user.icon && user.icon.length > 0) {
  104. let avatarUrl = user.icon[0].url
  105. that.setData({ avatarUrl })
  106. }
  107. that.setData({ user })
  108. } else {
  109. wx.showToast({ title: `${arr.errmsg}`, icon: 'error' });
  110. }
  111. },
  112. fail(err) {
  113. wx.navigateTo({ url: '/pagesCommon/login/index' })
  114. }
  115. })
  116. },
  117. // 过滤字典表
  118. getDict(value, model) {
  119. const that = this;
  120. if (value) {
  121. let list = that.data.statusList
  122. let data = list.find(i => i.value == value);
  123. if (data) return data.label
  124. else return '暂无'
  125. }
  126. },
  127. // 查询其他信息
  128. async searchOther() {
  129. const that = this;
  130. let res;
  131. // 状态
  132. res = await app.$api(`dictData`, 'GET', { type: 'status', is_use: '0' });
  133. if (res.errcode == '0') that.setData({ statusList: res.data })
  134. },
  135. /**
  136. * 生命周期函数--监听页面初次渲染完成
  137. */
  138. onReady() {
  139. },
  140. /**
  141. * 生命周期函数--监听页面显示
  142. */
  143. onShow() {
  144. },
  145. /**
  146. * 生命周期函数--监听页面隐藏
  147. */
  148. onHide() {
  149. },
  150. /**
  151. * 生命周期函数--监听页面卸载
  152. */
  153. onUnload() {
  154. },
  155. /**
  156. * 页面相关事件处理函数--监听用户下拉动作
  157. */
  158. onPullDownRefresh() {
  159. },
  160. /**
  161. * 页面上拉触底事件的处理函数
  162. */
  163. onReachBottom() {
  164. },
  165. /**
  166. * 用户点击右上角分享
  167. */
  168. onShareAppMessage() {
  169. }
  170. })