const app = getApp() import { my_menu } from "../../utils/site"; Page({ data: { logo: '', avatarUrl: '', user: {}, // 按钮 menuList: my_menu, // 状态 statusList: [] }, toPath(e) { let data = e.detail; let url = `/${data.route}`; if (data.type == '0') wx.navigateTo({ url }) else if (data.type == '1') wx.redirectTo({ url }) else if (data.type == '2') wx.relaunch({ url }) else if (data.type == '3') wx.switchTab({ url }) }, // 我的服务-功能按钮 toCommon: function (e) { const that = this; if (that.data.user._id) { let { route } = e.currentTarget.dataset; if (route) wx.navigateTo({ url: `/${route}` }) else { wx.showModal({ title: '提示', content: '是否确认退出登录', success(res) { if (res.confirm) { wx.removeStorage({ key: 'user', success(res) { return wx.redirectTo({ url: '/pagesMy/home/index' }) } }) } } }) } } else { wx.showToast({ title: `暂无用户信息,无法查看`, icon: 'none' }); wx.navigateTo({ url: '/pagesCommon/login/index' }) } }, // 去登录 toLogin() { wx.navigateTo({ url: '/pagesCommon/login/index' }) }, // 获取头像 async toAvatarUrl(e) { const that = this; const { avatarUrl } = e.detail let res = await app.$apifile('files/ball/users/upload', null, avatarUrl) res = JSON.parse(res); if (res.errcode == '0') { let icon = [{ id: res.id, name: res.name, uri: res.uri, url: `${app.globalData.fileserverUrl}` + res.uri }] let arr = await app.$api(`user/${that.data.user._id}`, 'POST', { icon: icon }); if (arr.errcode == '0') { const user = await app.$api(`user/${that.data.user._id}`, 'get', {}); if (user.errcode == '0') wx.setStorage({ key: "user", data: user.data })// 存用户信息到storage,以便之后判断用户是否登录 wx.showToast({ title: `头像上传成功`, icon: 'success' }); that.search() } else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error' }); } } }, // 过滤字典表 getDict(value, model) { const that = this; if (value) { let list = that.data.statusList let data = list.find(i => i.value == value); if (data) return data.label else return '暂无' } }, /** * 生命周期函数--监听页面加载 */ async onLoad(options) { }, /** * 生命周期函数--监听页面显示 */ async onShow() { const that = this; wx.showLoading({ title: '加载中', mask: true }) await that.searchConfig(); await that.searchOther(); await that.search() wx.hideLoading() }, searchConfig() { const that = this; wx.getStorage({ key: 'config', async success(res) { // 管理员。 if (res.data && res.data.logo_url && res.data.logo_url.length > 0) { let logo = res.data.logo_url[0].url that.setData({ logo }) } }, fail(err) { // console.log(err); } }) }, // 查询其他信息 async searchOther() { const that = this; let res; // 状态 res = await app.$api(`dictData`, 'GET', { type: 'status', is_use: '0' }); if (res.errcode == '0') that.setData({ statusList: res.data }) }, async search() { const that = this; wx.getStorage({ key: 'user', async success(res) { let arr = await app.$api(`user/${res.data._id}`, 'GET', {}) if (arr.errcode == '0') { let user = arr.data; // 审核字段处理 user.status_name = that.getDict(user.status, 'statusList') // 头像字段处理 if (user.icon && user.icon.length > 0) { let avatarUrl = user.icon[0].url that.setData({ avatarUrl }) } that.setData({ user }) } else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error' }); } }, fail(err) { // console.log(err); } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })