"use strict"; const common_vendor = require("../../common/vendor.js"); const api_student = require("../../api/student.js"); const api_dict = require("../../api/dict.js"); const utils_request = require("../../utils/request.js"); if (!Array) { const _easycom_step_layout2 = common_vendor.resolveComponent("step-layout"); _easycom_step_layout2(); } const _easycom_step_layout = () => "../../components/step-layout/step-layout.js"; if (!Math) { _easycom_step_layout(); } const _sfc_main = { __name: "profile", setup(__props) { const isEditMode = common_vendor.ref(false); const genderOptions = common_vendor.ref([ { dictLabel: "男", dictValue: "0" }, { dictLabel: "女", dictValue: "1" } ]); const normalizeGenderValue = (value) => { if (value === void 0 || value === null || value === "") { return "0"; } const gender = String(value).trim().toUpperCase(); if (gender === "M") return "0"; if (gender === "F") return "1"; if (gender === "0" || gender === "1" || gender === "2") return gender; return "0"; }; const loadGenderDict = async () => { try { const res = await api_dict.getDicts("sys_user_sex"); const data = (res == null ? void 0 : res.data) || []; if (Array.isArray(data) && data.length > 0) { genderOptions.value = data.filter((item) => item && item.dictValue !== "2").map((item) => ({ dictLabel: item.dictLabel, dictValue: String(item.dictValue) })); } } catch (error) { common_vendor.index.__f__("error", "at pages/profile/profile.vue:99", "加载性别字典失败", error); } }; const genderSliderClass = common_vendor.computed(() => { const currentIndex = genderOptions.value.findIndex((item) => item.dictValue === formData.gender); if (currentIndex <= 0) { return currentIndex === 0 ? "left" : "none"; } return "right"; }); common_vendor.onLoad(async (options) => { await loadGenderDict(); if (options.editMode === "1") { isEditMode.value = true; const userInfo = common_vendor.index.getStorageSync("userInfo"); if (userInfo && userInfo.studentId) { try { common_vendor.index.showLoading({ title: "加载中..." }); const res = await api_student.getStudent(userInfo.studentId); common_vendor.index.hideLoading(); if (res && res.data) { const data = res.data; Object.assign(formData, { avatarUrl: data.avatarUrl || "/static/images/default-avatar.svg", avatarId: data.avatar || null, name: data.name || "", gender: normalizeGenderValue(data.gender), idCard: data.idCardNumber || "", email: data.email || "" }); } } catch (err) { common_vendor.index.hideLoading(); common_vendor.index.__f__("error", "at pages/profile/profile.vue:138", "获取用户信息失败", err); common_vendor.index.showToast({ title: "加载数据失败", icon: "none" }); } } } }); const formData = common_vendor.reactive({ avatarUrl: "/static/images/default-avatar.svg", // 用于展示 avatarId: null, // 用于传给后端 name: "", gender: "0", idCard: "", email: "" }); const chooseAvatar = () => { common_vendor.index.chooseImage({ count: 1, success: (res) => { const tempFilePath = res.tempFilePaths[0]; formData.avatarUrl = tempFilePath; common_vendor.index.showLoading({ title: "上传头像中..." }); common_vendor.index.uploadFile({ url: utils_request.UPLOAD_URL + "/portal/oss/upload", filePath: tempFilePath, name: "file", header: { "clientid": "e5cd7e4891bf95d1d19206ce24a7b32e", "PLATFORM_CODE": "PINGTAIDUAN", "Authorization": common_vendor.index.getStorageSync("token") ? `Bearer ${common_vendor.index.getStorageSync("token")}` : "" }, success: (uploadFileRes) => { common_vendor.index.hideLoading(); const data = JSON.parse(uploadFileRes.data); if (data.code === 200) { formData.avatarId = data.data.ossId; common_vendor.index.showToast({ title: "上传成功", icon: "success" }); } else { common_vendor.index.showToast({ title: data.msg || "上传失败", icon: "none" }); } }, fail: (err) => { common_vendor.index.hideLoading(); common_vendor.index.__f__("error", "at pages/profile/profile.vue:184", "上传失败", err); common_vendor.index.showToast({ title: "上传失败", icon: "none" }); } }); } }); }; const setGender = (val) => { formData.gender = val; }; const goNext = async () => { if (!formData.name) { common_vendor.index.showToast({ title: "请输入您的真实姓名", icon: "none" }); return; } if (formData.idCard) { const idCardReg = /^[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]$/; if (!idCardReg.test(formData.idCard)) { common_vendor.index.showToast({ title: "请输入正确的身份证号", icon: "none" }); return; } } if (formData.email) { const emailReg = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/; if (!emailReg.test(formData.email)) { common_vendor.index.showToast({ title: "请输入正确的邮箱地址", icon: "none" }); return; } } common_vendor.index.showLoading({ title: "保存中..." }); try { const userInfo = common_vendor.index.getStorageSync("userInfo"); const studentId = userInfo ? userInfo.studentId : null; if (!studentId) { common_vendor.index.hideLoading(); common_vendor.index.showToast({ title: "用户信息失效,请重新登录", icon: "none" }); return; } const res = await api_student.updateStudent({ id: studentId, name: formData.name, gender: formData.gender, email: formData.email, idCardNumber: formData.idCard, avatar: formData.avatarId // 传入上传后的 ossId, 是 Long 类型的 }); common_vendor.index.hideLoading(); if (res.code === 200) { const url = isEditMode.value ? "/pages/experience/experience?editMode=1" : "/pages/experience/experience"; common_vendor.index.navigateTo({ url }); } else { common_vendor.index.showToast({ title: res.msg || "保存失败", icon: "none" }); } } catch (err) { common_vendor.index.hideLoading(); common_vendor.index.__f__("error", "at pages/profile/profile.vue:254", "保存个人信息异常", err); common_vendor.index.showToast({ title: "网络异常,请重试", icon: "none" }); } }; const goSkip = () => { common_vendor.index.navigateTo({ url: "/pages/experience/experience" }); }; return (_ctx, _cache) => { return { a: formData.avatarUrl, b: common_vendor.o(chooseAvatar), c: formData.name, d: common_vendor.o(($event) => formData.name = $event.detail.value), e: common_vendor.n(genderSliderClass.value), f: common_vendor.f(genderOptions.value, (item, k0, i0) => { return { a: common_vendor.t(item.dictLabel), b: item.dictValue, c: common_vendor.n(formData.gender === item.dictValue ? "active" : ""), d: common_vendor.o(($event) => setGender(item.dictValue), item.dictValue) }; }), g: formData.idCard, h: common_vendor.o(($event) => formData.idCard = $event.detail.value), i: formData.email, j: common_vendor.o(($event) => formData.email = $event.detail.value), k: common_vendor.o(goNext), l: common_vendor.o(goSkip), m: common_vendor.p({ title: "填写个人信息", showSkip: !isEditMode.value }) }; }; } }; const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-dd383ca2"]]); wx.createPage(MiniProgramPage); //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/profile/profile.js.map