// components/authorize/index.ts import fetchutil from '../../utils/http' var { CDN_URL, API_BASE_URL } = require('../../utils/util') const app = getApp() Component({ /** * 组件的属性列表 */ properties: { }, /** * 组件的初始数据 */ data: { inputNickName: '', inputPhone: '', avatarUrl: `${CDN_URL}images/default.png`, CDN_URL }, /** * 组件的方法列表 */ methods: { bindKeyInput(e) { console.log(e.detail.value); this.setData({ inputNickName: e.detail.value }) }, bindKeyPhone(e) { this.setData({ inputPhone: e.detail.value }) }, onChooseAvatar(e) { const { avatarUrl } = e.detail this.setData({ avatarUrl, }) }, onCancel() { this.triggerEvent('onCancel') }, onComfirm() { this.updateUserInfo(() => { this.triggerEvent('onComfirm') }) }, onChooseAvatar(e) { const { avatarUrl } = e.detail console.log(e); let loginSessionKey = wx.getStorageSync("token"); wx.uploadFile({ filePath: avatarUrl, name: 'file', url: API_BASE_URL + 'api/cms/wxUser/upload', header: { token: loginSessionKey }, formData: { type: 'img' }, success: (res) => { let respon = JSON.parse(res.data) this.setData({ avatarUrl: API_BASE_URL + (API_BASE_URL.length > 10 ? '' : '') + respon.data.filePath }) }, fail: function (res) { console.log(res); //发送失败回调,可以在这里了解失败原因 } }) }, updateUserInfo(cb = () => { }) { if (!this.data.avatarUrl || !this.data.inputNickName.trim() || !this.data.inputPhone.trim()||this.data.inputPhone.length<11) { wx.showToast({ title: '请补充完整信息~', icon: 'error' }) return } fetchutil.post(`api/cms/wxUser/update`, { "avatarUrl": this.data.avatarUrl, "nickName": this.data.inputNickName, "phone": this.data.inputPhone, }, {}).then((res) => { app.globalData.userInfo = res.data; cb() }).catch(() => { }) }, } })