| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- // 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(() => { })
- },
- }
- })
|