index.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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.showToast({ title: `暂无用户信息,无法查看`, icon: 'none' });
  29. }
  30. },
  31. // 获取头像
  32. async toAvatarUrl(e) {
  33. const that = this;
  34. const { avatarUrl } = e.detail
  35. let res = await app.$apifile('files/ball/users/upload', null, avatarUrl)
  36. res = JSON.parse(res);
  37. if (res.errcode == '0') {
  38. let icon = [{ id: res.id, name: res.name, uri: res.uri, url: `${app.globalData.fileserverUrl}` + res.uri }]
  39. let arr = await app.$api(`user/${that.data.user._id}`, 'POST', { icon: icon });
  40. if (arr.errcode == '0') {
  41. wx.showToast({ title: `头像上传成功`, icon: 'success' });
  42. that.search()
  43. } else {
  44. wx.showToast({ title: `${arr.errmsg}`, icon: 'error' });
  45. }
  46. }
  47. },
  48. /**
  49. * 生命周期函数--监听页面加载
  50. */
  51. async onLoad(options) {
  52. const that = this;
  53. wx.showLoading({ title: '加载中', mask: true })
  54. await that.searchOther();
  55. await that.searchConfig();
  56. await that.search()
  57. wx.hideLoading()
  58. },
  59. searchConfig() {
  60. const that = this;
  61. wx.getStorage({
  62. key: 'config',
  63. async success(res) {
  64. // 管理员。
  65. if (res.data && res.data.logo_url && res.data.logo_url.length > 0) {
  66. let logo = res.data.logo_url[0].url
  67. that.setData({ logo })
  68. }
  69. },
  70. fail(err) {
  71. console.log(err);
  72. }
  73. })
  74. },
  75. async search() {
  76. const that = this;
  77. wx.getStorage({
  78. key: 'token',
  79. async success(res) {
  80. let arr = await app.$api(`user/${res.data._id}`, 'GET', {})
  81. if (arr.errcode == '0') {
  82. let user = arr.data;
  83. // 审核字段处理
  84. user.status_name = that.getDict(user.status, 'statusList')
  85. // 头像字段处理
  86. if (user.icon && user.icon.length > 0) {
  87. let avatarUrl = user.icon[0].url
  88. that.setData({ avatarUrl })
  89. }
  90. that.setData({ user })
  91. } else {
  92. wx.showToast({ title: `${arr.errmsg}`, icon: 'error' });
  93. }
  94. },
  95. fail(err) {
  96. console.log(err);
  97. }
  98. })
  99. },
  100. // 过滤字典表
  101. getDict(value, model) {
  102. const that = this;
  103. if (value) {
  104. let list = that.data.statusList
  105. let data = list.find(i => i.value == value);
  106. if (data) return data.label
  107. else return '暂无'
  108. }
  109. },
  110. // 查询其他信息
  111. async searchOther() {
  112. const that = this;
  113. let res;
  114. // 状态
  115. res = await app.$api(`dictData`, 'GET', { type: 'status', is_use: '0' });
  116. if (res.errcode == '0') that.setData({ statusList: res.data })
  117. },
  118. /**
  119. * 生命周期函数--监听页面初次渲染完成
  120. */
  121. onReady() {
  122. },
  123. /**
  124. * 生命周期函数--监听页面显示
  125. */
  126. onShow() {
  127. },
  128. /**
  129. * 生命周期函数--监听页面隐藏
  130. */
  131. onHide() {
  132. },
  133. /**
  134. * 生命周期函数--监听页面卸载
  135. */
  136. onUnload() {
  137. },
  138. /**
  139. * 页面相关事件处理函数--监听用户下拉动作
  140. */
  141. onPullDownRefresh() {
  142. },
  143. /**
  144. * 页面上拉触底事件的处理函数
  145. */
  146. onReachBottom() {
  147. },
  148. /**
  149. * 用户点击右上角分享
  150. */
  151. onShareAppMessage() {
  152. }
  153. })