profile.js 4.0 KB

1
  1. "use strict";const e=require("../../common/vendor.js"),a=require("../../api/student.js"),t=require("../../api/dict.js"),i=require("../../utils/request.js");if(!Array){e.resolveComponent("step-layout")()}Math;const n={__name:"profile",setup(n){const d=e.ref(!1),o=e.ref([{dictLabel:"男",dictValue:"0"},{dictLabel:"女",dictValue:"1"}]),r=e=>{if(null==e||""===e)return"0";const a=String(e).trim().toUpperCase();return"M"===a?"0":"F"===a?"1":"0"===a||"1"===a||"2"===a?a:"0"},s=e.computed((()=>{const e=o.value.findIndex((e=>e.dictValue===l.gender));return e<=0?0===e?"left":"none":"right"}));e.onLoad((async i=>{if(await(async()=>{try{const e=await t.getDicts("sys_user_sex"),a=(null==e?void 0:e.data)||[];Array.isArray(a)&&a.length>0&&(o.value=a.filter((e=>e&&"2"!==e.dictValue)).map((e=>({dictLabel:e.dictLabel,dictValue:String(e.dictValue)}))))}catch(e){console.error("加载性别字典失败",e)}})(),"1"===i.editMode){d.value=!0;const t=e.index.getStorageSync("userInfo");if(t&&t.studentId)try{e.index.showLoading({title:"加载中..."});const i=await a.getStudent(t.studentId);if(e.index.hideLoading(),i&&i.data){const e=i.data;Object.assign(l,{avatarUrl:e.avatarUrl||"/static/images/default-avatar.svg",avatarId:e.avatar||null,name:e.name||"",gender:r(e.gender),idCard:e.idCardNumber||"",email:e.email||""})}}catch(n){e.index.hideLoading(),console.error("获取用户信息失败",n),e.index.showToast({title:"加载数据失败",icon:"none"})}}}));const l=e.reactive({avatarUrl:"/static/images/default-avatar.svg",avatarId:null,name:"",gender:"0",idCard:"",email:""}),c=()=>{e.index.chooseImage({count:1,success:a=>{const t=a.tempFilePaths[0];l.avatarUrl=t,e.index.showLoading({title:"上传头像中..."}),e.index.uploadFile({url:i.UPLOAD_URL+"/portal/oss/upload",filePath:t,name:"file",header:{clientid:"e5cd7e4891bf95d1d19206ce24a7b32e",PLATFORM_CODE:"PINGTAIDUAN",Authorization:e.index.getStorageSync("token")?`Bearer ${e.index.getStorageSync("token")}`:""},success:a=>{e.index.hideLoading();const t=JSON.parse(a.data);200===t.code?(l.avatarId=t.data.ossId,e.index.showToast({title:"上传成功",icon:"success"})):e.index.showToast({title:t.msg||"上传失败",icon:"none"})},fail:a=>{e.index.hideLoading(),console.error("上传失败",a),e.index.showToast({title:"上传失败",icon:"none"})}})}})},u=async()=>{if(l.name){if(l.idCard){if(!/^[1-9]\d{5}(18|19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}[\dXx]$/.test(l.idCard))return void e.index.showToast({title:"请输入正确的身份证号",icon:"none"})}if(l.email){if(!/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(l.email))return void e.index.showToast({title:"请输入正确的邮箱地址",icon:"none"})}e.index.showLoading({title:"保存中..."});try{const t=e.index.getStorageSync("userInfo"),i=t?t.studentId:null;if(!i)return e.index.hideLoading(),void e.index.showToast({title:"用户信息失效,请重新登录",icon:"none"});const n=await a.updateStudent({id:i,name:l.name,gender:l.gender,email:l.email,idCardNumber:l.idCard,avatar:l.avatarId});if(e.index.hideLoading(),200===n.code){const a=d.value?"/pages/experience/experience?editMode=1":"/pages/experience/experience";e.index.navigateTo({url:a})}else e.index.showToast({title:n.msg||"保存失败",icon:"none"})}catch(t){e.index.hideLoading(),console.error("保存个人信息异常",t),e.index.showToast({title:"网络异常,请重试",icon:"none"})}}else e.index.showToast({title:"请输入您的真实姓名",icon:"none"})},g=()=>{e.index.navigateTo({url:"/pages/experience/experience"})};return(a,t)=>({a:l.avatarUrl,b:e.o(c),c:l.name,d:e.o((e=>l.name=e.detail.value)),e:e.n(s.value),f:e.f(o.value,((a,t,i)=>({a:e.t(a.dictLabel),b:a.dictValue,c:e.n(l.gender===a.dictValue?"active":""),d:e.o((e=>{return t=a.dictValue,void(l.gender=t);var t}),a.dictValue)}))),g:l.idCard,h:e.o((e=>l.idCard=e.detail.value)),i:l.email,j:e.o((e=>l.email=e.detail.value)),k:e.o(u),l:e.o(g),m:e.p({title:"填写个人信息",showSkip:!d.value})})}},d=e._export_sfc(n,[["__scopeId","data-v-b29ee7ad"]]);wx.createPage(d);