const { user, index, util } = getApp().globalData Page({ data: { ossUrl: 'https://losta.oss-cn-shanghai.aliyuncs.com', userInfo: {}, fileList: [], customItem: '全部', showSchool: false, showUserName: false }, onLoad: function (options) { if (util.checkIsLogin()) { let info = wx.getStorageSync('user') if (info.user_city.length != 0) { info.user_city = info.user_city.split(",") } this.setData({ userInfo: info }); this.setData({ fileList: [ { url: this.data.userInfo.user_portrait, name: '图片1', } ] }) } }, async edit() { let { userInfo } = this.data; userInfo.user_city = userInfo.user_city.toString(); console.log("userInfo : ", userInfo) let res = await user.edit(userInfo) console.log(res) wx.setStorageSync('user', userInfo); util.showToast({ title: '修改成功', icon: 'success', duration: 2000, // close: () => wx.switchTab({ url: '/pages/index/index' }) }) }, async afterRead(event) { const { file } = event.detail; this.setData({ fileList: [ file ] }) console.log("file === ", file) let arr = file.url.split(".") let fileType = arr[arr.length - 1]; // 文件后缀 let ossConfig = await index.token(); let fileName = `${util.random()}.${fileType}`; console.log("fileName === ", fileName) wx.uploadFile({ url: this.data.ossUrl, filePath: file.url, name: 'file', formData: { key: fileName, ...ossConfig }, success: (res) => { console.log("uploadFile success : ", res) if (res.statusCode == 204) { this.setData({ ['userInfo.user_portrait']: `${this.data.ossUrl}/${fileName}` }); } else { wx.showToast({ title: "图片上传错误,稍后再试", icon: 'none', duration: 3000 }); } } }); }, bindRegionChange: function (e) { this.setData({ 'userInfo.user_city': e.detail.value }) }, onSchoolChange(e) { this.setData({ 'userInfo.user_school': e.detail }) }, onUserNameChange(e) { this.setData({ 'userInfo.user_name': e.detail }) }, showSheet() { this.setData({showSchool: true}) }, showNameSheet() { this.setData({showUserName: true}) }, onUserClose() { this.setData({showUserName: false}) }, onClose() { this.setData({showSchool: false}) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })