3 lines
3.5 KiB
JavaScript
3 lines
3.5 KiB
JavaScript
"use strict";const e=require("../../common/vendor.js");Array||e.resolveComponent("uni-icons")();const h=()=>"../../uni_modules/uni-icons/components/uni-icons/uni-icons.js";Math||h();const y={__name:"userinfo",setup(l){const{proxy:c}=e.getCurrentInstance(),d=e.getCurrentInstance().appContext.config.globalProperties.$url,s=e.ref(!1),i=e.ref(!1),a=e.ref({avatar:"",patient_name:"",phone:"",nickname:"",sex:1,age:""});e.onMounted(()=>{v()});const v=async()=>{s.value=!0;try{const n=await c.apiUrl({url:"/api/user/info",method:"GET",data:{}});if(n.code===1){const t=n.data;a.value={avatar:t.avatar||"",patient_name:t.patient_name||t.nickname||"",phone:t.phone||"",nickname:t.nickname||"",sex:t.sex=="男"?1:2,age:t.age||""}}else e.index.showToast({title:n.msg||"加载失败",icon:"none"})}catch(n){e.index.__f__("error","at pages/user/userinfo.vue:142","加载用户信息失败:",n),e.index.showToast({title:"加载失败",icon:"none"})}finally{s.value=!1}},m=()=>{e.index.chooseImage({count:1,sizeType:["compressed"],sourceType:["album","camera"],success:async n=>{const t=n.tempFilePaths[0];try{e.index.showLoading({title:"上传中..."});const o=e.index.getStorageSync("token"),r=await new Promise((f,x)=>{e.index.uploadFile({url:d+"/api/upload/image",filePath:t,name:"file",header:{token:o,"content-type":"multipart/form-data"},success:u=>{const g=JSON.parse(u.data);f(g)},fail:u=>{x(u)}})});e.index.hideLoading(),r.code===1?(a.value.avatar=r.data.uri||r.data,e.index.showToast({title:"头像上传成功",icon:"success"})):e.index.showToast({title:r.msg||"上传失败",icon:"none"})}catch(o){e.index.hideLoading(),e.index.__f__("error","at pages/user/userinfo.vue:195","上传头像失败:",o),e.index.showToast({title:"上传失败",icon:"none"})}},fail:n=>{e.index.__f__("error","at pages/user/userinfo.vue:200","选择图片失败:",n),e.index.showToast({title:"选择图片失败",icon:"none"})}})},p=n=>n?/^1[3-9]\d{9}$/.test(n):!0,_=async()=>{if(!a.value.patient_name){e.index.showToast({title:"姓名不能为空",icon:"none"});return}if(a.value.phone&&!p(a.value.phone)){e.index.showToast({title:"手机号格式不正确",icon:"none"});return}i.value=!0;try{const n=await c.apiUrl({url:"/api/user/setInfo",method:"POST",data:{avatar:a.value.avatar,phone:a.value.phone,nickname:a.value.nickname,sex:a.value.sex,age:a.value.age,patient_name:a.value.patient_name}});if(n.code===1){const t=e.index.getStorageSync("userData"),o={...t,avatar:a.value.avatar,phone:a.value.phone,nickname:a.value.nickname,sex:a.value.sex,age:a.value.age,patient_name:a.value.patient_name,diagnosis:{...t.diagnosis,patient_name:a.value.patient_name}};e.index.setStorageSync("userData",o),e.index.showToast({title:"保存成功",icon:"success"}),setTimeout(()=>{e.index.navigateBack()},1500)}else e.index.showToast({title:n.msg||"保存失败",icon:"none"})}catch(n){e.index.__f__("error","at pages/user/userinfo.vue:269","保存失败:",n),e.index.showToast({title:"保存失败",icon:"none"})}finally{i.value=!1}};return(n,t)=>e.e({a:s.value},s.value?{}:{b:a.value.avatar,c:e.p({type:"upload-filled",size:"24",color:"#FFA500"}),d:e.o(m,"bf"),e:a.value.nickname,f:e.o(o=>a.value.nickname=o.detail.value,"6d"),g:a.value.sex===1?1:"",h:e.o(o=>a.value.sex=1,"e9"),i:a.value.sex===2?1:"",j:e.o(o=>a.value.sex=2,"53"),k:a.value.age,l:e.o(e.m(o=>a.value.age=o.detail.value,{number:!0}),"cf"),m:e.t(i.value?"保存中...":"保存修改"),n:e.o(_,"84"),o:i.value})}},w=e._export_sfc(y,[["__scopeId","data-v-103261b1"]]);wx.createPage(w);
|
|
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/user/userinfo.js.map
|