index.js 5.2 KB

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