2 lines
1.6 KiB
JavaScript
2 lines
1.6 KiB
JavaScript
"use strict";const e=require("../../common/vendor.js"),n=require("../../config/api.js"),i={data:()=>({nickname:""}),onLoad(){this.loadProfile()},methods:{loadProfile(){const n=e.index.getStorageSync("userInfo");n&&(this.nickname=n.nickname||"")},async saveProfile(){if(!this.nickname.trim())return void e.index.showToast({title:"请输入昵称",icon:"none"});const i=e.index.getStorageSync("userInfo")||{},o=i.id||e.index.getStorageSync("userId");if(!o)return void e.index.showToast({title:"请先登录",icon:"none"});e.index.showLoading({title:"保存中..."});const t=e.index.getStorageSync("token");e.index.request({url:`${n.API_BASE}/api/users/profile/${o}`,method:"PUT",header:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},data:{nickname:this.nickname.trim()},success:n=>{console.log("[EditProfile] API响应:",n.data),200===n.statusCode&&n.data.success?(i.nickname=this.nickname,e.index.setStorageSync("userInfo",i),e.index.setStorageSync("nickname",this.nickname),e.index.setStorageSync("userNickname",this.nickname),e.index.showToast({title:"保存成功",icon:"success"}),setTimeout((()=>{e.index.navigateBack()}),1500)):e.index.showToast({title:n.data.message||"保存失败",icon:"none"})},fail:n=>{console.error("[EditProfile] 请求失败:",n),e.index.showToast({title:"网络错误,请重试",icon:"none"})},complete:()=>{e.index.hideLoading()}})}}};const o=e._export_sfc(i,[["render",function(n,i,o,t,a,s){return{a:a.nickname,b:e.o((e=>a.nickname=e.detail.value)),c:e.o(((...e)=>s.saveProfile&&s.saveProfile(...e)))}}],["__scopeId","data-v-39fc78b0"]]);wx.createPage(o);
|