gengx
This commit is contained in:
@@ -1,193 +1,2 @@
|
||||
"use strict";
|
||||
const common_vendor = require("../../common/vendor.js");
|
||||
if (!Array) {
|
||||
const _easycom_uni_icons2 = common_vendor.resolveComponent("uni-icons");
|
||||
_easycom_uni_icons2();
|
||||
}
|
||||
const _easycom_uni_icons = () => "../../uni_modules/uni-icons/components/uni-icons/uni-icons.js";
|
||||
if (!Math) {
|
||||
_easycom_uni_icons();
|
||||
}
|
||||
const _sfc_main = {
|
||||
__name: "userinfo",
|
||||
setup(__props) {
|
||||
const { proxy } = common_vendor.getCurrentInstance();
|
||||
const instance = common_vendor.getCurrentInstance();
|
||||
const $url = instance.appContext.config.globalProperties.$url;
|
||||
const loading = common_vendor.ref(false);
|
||||
const submitting = common_vendor.ref(false);
|
||||
const formData = common_vendor.ref({
|
||||
avatar: "",
|
||||
patient_name: "",
|
||||
phone: "",
|
||||
nickname: "",
|
||||
sex: 1,
|
||||
age: ""
|
||||
});
|
||||
common_vendor.onMounted(() => {
|
||||
loadUserInfo();
|
||||
});
|
||||
const loadUserInfo = async () => {
|
||||
loading.value = true;
|
||||
try {
|
||||
const res = await proxy.apiUrl({
|
||||
url: "/api/user/info",
|
||||
method: "GET",
|
||||
data: {}
|
||||
});
|
||||
if (res.code === 1) {
|
||||
const userInfo = res.data;
|
||||
formData.value = {
|
||||
avatar: userInfo.avatar || "",
|
||||
patient_name: userInfo.patient_name || userInfo.nickname || "",
|
||||
phone: userInfo.phone || "",
|
||||
nickname: userInfo.nickname || "",
|
||||
sex: userInfo.sex == "男" ? 1 : 2,
|
||||
age: userInfo.age || ""
|
||||
};
|
||||
} else {
|
||||
common_vendor.index.showToast({ title: res.msg || "加载失败", icon: "none" });
|
||||
}
|
||||
} catch (err) {
|
||||
common_vendor.index.__f__("error", "at pages/user/userinfo.vue:142", "加载用户信息失败:", err);
|
||||
common_vendor.index.showToast({ title: "加载失败", icon: "none" });
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
const uploadAvatar = () => {
|
||||
common_vendor.index.chooseImage({
|
||||
count: 1,
|
||||
sizeType: ["compressed"],
|
||||
sourceType: ["album", "camera"],
|
||||
success: async (res) => {
|
||||
const tempFilePath = res.tempFilePaths[0];
|
||||
try {
|
||||
common_vendor.index.showLoading({ title: "上传中..." });
|
||||
const token = common_vendor.index.getStorageSync("token");
|
||||
const uploadRes = await new Promise((resolve, reject) => {
|
||||
common_vendor.index.uploadFile({
|
||||
url: $url + "/api/upload/image",
|
||||
filePath: tempFilePath,
|
||||
name: "file",
|
||||
header: {
|
||||
token,
|
||||
"content-type": "multipart/form-data"
|
||||
},
|
||||
success: (res2) => {
|
||||
const data = JSON.parse(res2.data);
|
||||
resolve(data);
|
||||
},
|
||||
fail: (err) => {
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
common_vendor.index.hideLoading();
|
||||
if (uploadRes.code === 1) {
|
||||
formData.value.avatar = uploadRes.data.uri || uploadRes.data;
|
||||
common_vendor.index.showToast({ title: "头像上传成功", icon: "success" });
|
||||
} else {
|
||||
common_vendor.index.showToast({ title: uploadRes.msg || "上传失败", icon: "none" });
|
||||
}
|
||||
} catch (err) {
|
||||
common_vendor.index.hideLoading();
|
||||
common_vendor.index.__f__("error", "at pages/user/userinfo.vue:195", "上传头像失败:", err);
|
||||
common_vendor.index.showToast({ title: "上传失败", icon: "none" });
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
common_vendor.index.__f__("error", "at pages/user/userinfo.vue:200", "选择图片失败:", err);
|
||||
common_vendor.index.showToast({ title: "选择图片失败", icon: "none" });
|
||||
}
|
||||
});
|
||||
};
|
||||
const validatePhone = (phone) => {
|
||||
if (!phone)
|
||||
return true;
|
||||
return /^1[3-9]\d{9}$/.test(phone);
|
||||
};
|
||||
const submitForm = async () => {
|
||||
if (!formData.value.patient_name) {
|
||||
common_vendor.index.showToast({ title: "姓名不能为空", icon: "none" });
|
||||
return;
|
||||
}
|
||||
if (formData.value.phone && !validatePhone(formData.value.phone)) {
|
||||
common_vendor.index.showToast({ title: "手机号格式不正确", icon: "none" });
|
||||
return;
|
||||
}
|
||||
submitting.value = true;
|
||||
try {
|
||||
const res = await proxy.apiUrl({
|
||||
url: "/api/user/setInfo",
|
||||
method: "POST",
|
||||
data: {
|
||||
avatar: formData.value.avatar,
|
||||
phone: formData.value.phone,
|
||||
nickname: formData.value.nickname,
|
||||
sex: formData.value.sex,
|
||||
age: formData.value.age,
|
||||
patient_name: formData.value.patient_name
|
||||
}
|
||||
});
|
||||
if (res.code === 1) {
|
||||
const userData = common_vendor.index.getStorageSync("userData");
|
||||
const updatedData = {
|
||||
...userData,
|
||||
avatar: formData.value.avatar,
|
||||
phone: formData.value.phone,
|
||||
nickname: formData.value.nickname,
|
||||
sex: formData.value.sex,
|
||||
age: formData.value.age,
|
||||
patient_name: formData.value.patient_name,
|
||||
diagnosis: {
|
||||
...userData.diagnosis,
|
||||
patient_name: formData.value.patient_name
|
||||
}
|
||||
};
|
||||
common_vendor.index.setStorageSync("userData", updatedData);
|
||||
common_vendor.index.showToast({ title: "保存成功", icon: "success" });
|
||||
setTimeout(() => {
|
||||
common_vendor.index.navigateBack();
|
||||
}, 1500);
|
||||
} else {
|
||||
common_vendor.index.showToast({ title: res.msg || "保存失败", icon: "none" });
|
||||
}
|
||||
} catch (err) {
|
||||
common_vendor.index.__f__("error", "at pages/user/userinfo.vue:269", "保存失败:", err);
|
||||
common_vendor.index.showToast({ title: "保存失败", icon: "none" });
|
||||
} finally {
|
||||
submitting.value = false;
|
||||
}
|
||||
};
|
||||
return (_ctx, _cache) => {
|
||||
return common_vendor.e({
|
||||
a: loading.value
|
||||
}, loading.value ? {} : {
|
||||
b: formData.value.avatar,
|
||||
c: common_vendor.p({
|
||||
type: "upload-filled",
|
||||
size: "24",
|
||||
color: "#FFA500"
|
||||
}),
|
||||
d: common_vendor.o(uploadAvatar, "bf"),
|
||||
e: formData.value.nickname,
|
||||
f: common_vendor.o(($event) => formData.value.nickname = $event.detail.value, "6d"),
|
||||
g: formData.value.sex === 1 ? 1 : "",
|
||||
h: common_vendor.o(($event) => formData.value.sex = 1, "e9"),
|
||||
i: formData.value.sex === 2 ? 1 : "",
|
||||
j: common_vendor.o(($event) => formData.value.sex = 2, "53"),
|
||||
k: formData.value.age,
|
||||
l: common_vendor.o(common_vendor.m(($event) => formData.value.age = $event.detail.value, {
|
||||
number: true
|
||||
}), "cf"),
|
||||
m: common_vendor.t(submitting.value ? "保存中..." : "保存修改"),
|
||||
n: common_vendor.o(submitForm, "84"),
|
||||
o: submitting.value
|
||||
});
|
||||
};
|
||||
}
|
||||
};
|
||||
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-103261b1"]]);
|
||||
wx.createPage(MiniProgramPage);
|
||||
"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
|
||||
|
||||
Reference in New Issue
Block a user