| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275 |
- "use strict";
- const common_vendor = require("../../common/vendor.js");
- const store_user = require("../../store/user.js");
- const utils_defaultUtils = require("../../utils/defaultUtils.js");
- if (!Math) {
- NavBar();
- }
- const NavBar = () => "../components/NavBar/NavBar.js";
- const _sfc_main = {
- __name: "index",
- setup(__props) {
- const navBarRef = common_vendor.ref(null);
- const navHeight = common_vendor.ref(135);
- common_vendor.onMounted(async () => {
- var _a;
- await common_vendor.nextTick$1();
- navHeight.value = ((_a = navBarRef.value) == null ? void 0 : _a.totalNavHeight.value) || 135;
- common_vendor.watch(
- () => {
- var _a2;
- return (_a2 = navBarRef.value) == null ? void 0 : _a2.totalNavHeight.value;
- },
- (val) => {
- if (val)
- navHeight.value = val;
- },
- { immediate: true }
- );
- });
- const userStore = store_user.useUserStore();
- const showCamera = common_vendor.ref(false);
- const showPhotoModal = common_vendor.ref(false);
- const avatarConfig = common_vendor.computed(() => utils_defaultUtils.getUserAvatarConfig(userStore.userInfo));
- const onAvatarTouchStart = () => {
- showCamera.value = true;
- };
- const onAvatarTouchEnd = () => {
- showCamera.value = false;
- };
- const showPhotoOptions = () => {
- showPhotoModal.value = true;
- };
- const hidePhotoOptions = () => {
- showPhotoModal.value = false;
- };
- const resetAvatar = () => {
- userStore.resetToDefaultAvatar();
- hidePhotoOptions();
- common_vendor.index.showToast({ title: "已恢复默认头像", duration: 2e3 });
- };
- const chooseFromAlbum = () => {
- common_vendor.index.chooseImage({
- count: 1,
- sizeType: ["compressed"],
- sourceType: ["album"],
- success: (res) => {
- userStore.setCustomAvatar(res.tempFilePaths[0]);
- hidePhotoOptions();
- common_vendor.index.showToast({ title: "头像更新成功", duration: 2e3 });
- },
- fail: () => {
- common_vendor.index.showToast({ title: "选择照片失败", icon: "none" });
- }
- });
- };
- const takePhoto = () => {
- common_vendor.index.chooseImage({
- count: 1,
- sizeType: ["compressed"],
- sourceType: ["camera"],
- success: (res) => {
- userStore.setCustomAvatar(res.tempFilePaths[0]);
- hidePhotoOptions();
- common_vendor.index.showToast({ title: "头像更新成功", duration: 2e3 });
- },
- fail: () => {
- common_vendor.index.showToast({ title: "拍照失败", icon: "none" });
- }
- });
- };
- const editField = common_vendor.ref("");
- const editValue = common_vendor.ref("");
- function beginEdit(field, val) {
- editField.value = field;
- editValue.value = val || "";
- }
- function saveEdit(field) {
- if (editField.value !== field)
- return;
- userStore.setUserInfo({ [field]: editValue.value.trim() });
- editField.value = "";
- editValue.value = "";
- common_vendor.index.showToast({ title: "修改成功", icon: "success", duration: 1500 });
- }
- const genderList = ["男", "女", "未知"];
- const genderIndex = common_vendor.ref(0);
- common_vendor.onMounted(() => {
- setGenderPickerIndex();
- });
- function setGenderPickerIndex() {
- let idx = 2;
- if (userStore.userInfo.gender === "MALE" || userStore.userInfo.gender === 1 || userStore.userInfo.gender === "男")
- idx = 0;
- if (userStore.userInfo.gender === "FEMALE" || userStore.userInfo.gender === 0 || userStore.userInfo.gender === "女")
- idx = 1;
- genderIndex.value = idx;
- }
- function onGenderChange(e) {
- let val = e.detail ? e.detail.value : e;
- genderIndex.value = val;
- let g = genderList[val];
- let realVal = g === "男" ? "MALE" : g === "女" ? "FEMALE" : "";
- userStore.setUserInfo({ gender: realVal });
- }
- const editBirthday = common_vendor.ref("");
- function onBirthdayChange(e) {
- let dateStr = e.detail ? e.detail.value : e;
- editBirthday.value = dateStr;
- userStore.setUserInfo({ birthday: dateStr });
- }
- const roleList = ["学生", "教师"];
- const roleIndex = common_vendor.ref(0);
- common_vendor.onMounted(() => {
- setRolePickerIndex();
- });
- function setRolePickerIndex() {
- let role = userStore.userInfo.role || "";
- let idx = roleList.findIndex((r) => formatRoleEn(r) === role);
- roleIndex.value = idx >= 0 ? idx : 0;
- }
- function onRoleChange(e) {
- let idx = e.detail ? e.detail.value : e;
- roleIndex.value = idx;
- let enMap = ["STUDENT", "TEACHER"];
- userStore.setUserInfo({ role: enMap[idx] });
- }
- function formatRole(role) {
- const roleMap = { STUDENT: "学生", TEACHER: "教师" };
- return roleMap[role] || "未设置";
- }
- function formatRoleEn(cn) {
- const map = { "学生": "STUDENT", "教师": "TEACHER" };
- return map[cn] || "";
- }
- function formatGender(gender) {
- if (gender === null || gender === void 0 || gender === "")
- return "未设置";
- const genderMap = { MALE: "男", FEMALE: "女", male: "男", female: "女", 1: "男", 0: "女", "男": "男", "女": "女" };
- return genderMap[gender] || "未设置";
- }
- function formatBirthday(birthday) {
- if (!birthday)
- return "未设置";
- if (typeof birthday === "number")
- return new Date(birthday).toLocaleDateString();
- return birthday;
- }
- function goToPasswordChange() {
- common_vendor.index.showToast({
- title: "页面尚未开发",
- icon: "error"
- });
- }
- return (_ctx, _cache) => {
- return common_vendor.e({
- a: common_vendor.sr(navBarRef, "201c0da5-0", {
- "k": "navBarRef"
- }),
- b: !avatarConfig.value.isDefault
- }, !avatarConfig.value.isDefault ? {
- c: avatarConfig.value.src
- } : !showCamera.value ? {
- e: common_vendor.t(avatarConfig.value.text)
- } : {}, {
- d: !showCamera.value,
- f: showCamera.value
- }, showCamera.value ? {} : {}, {
- g: showCamera.value ? 1 : "",
- h: common_vendor.s(avatarConfig.value.style),
- i: common_vendor.o(onAvatarTouchStart),
- j: common_vendor.o(onAvatarTouchEnd),
- k: common_vendor.t(avatarConfig.value.isDefault ? "默认头像" : "自定义头像"),
- l: common_vendor.o(showPhotoOptions),
- m: editField.value === "name"
- }, editField.value === "name" ? {
- n: common_vendor.o(($event) => saveEdit("name")),
- o: common_vendor.o(($event) => saveEdit("name")),
- p: editValue.value,
- q: common_vendor.o(($event) => editValue.value = $event.detail.value)
- } : {
- r: common_vendor.t(common_vendor.unref(userStore).userInfo.name || "未设置"),
- s: common_vendor.o(($event) => beginEdit("name", common_vendor.unref(userStore).userInfo.name))
- }, {
- t: editField.value === "englishName"
- }, editField.value === "englishName" ? {
- v: common_vendor.o(($event) => saveEdit("englishName")),
- w: common_vendor.o(($event) => saveEdit("englishName")),
- x: editValue.value,
- y: common_vendor.o(($event) => editValue.value = $event.detail.value)
- } : {
- z: common_vendor.t(common_vendor.unref(userStore).userInfo.englishName || "未设置"),
- A: common_vendor.o(($event) => beginEdit("englishName", common_vendor.unref(userStore).userInfo.englishName))
- }, {
- B: editField.value === "phone"
- }, editField.value === "phone" ? {
- C: common_vendor.o(($event) => saveEdit("phone")),
- D: common_vendor.o(($event) => saveEdit("phone")),
- E: editValue.value,
- F: common_vendor.o(($event) => editValue.value = $event.detail.value)
- } : {
- G: common_vendor.t(common_vendor.unref(userStore).userInfo.phone || "未设置"),
- H: common_vendor.o(($event) => beginEdit("phone", common_vendor.unref(userStore).userInfo.phone))
- }, {
- I: common_vendor.t(formatGender(common_vendor.unref(userStore).userInfo.gender)),
- J: genderList,
- K: genderIndex.value,
- L: common_vendor.o(onGenderChange),
- M: common_vendor.t(formatBirthday(common_vendor.unref(userStore).userInfo.birthday)),
- N: editBirthday.value,
- O: common_vendor.o(onBirthdayChange),
- P: common_vendor.t(formatRole(common_vendor.unref(userStore).userInfo.role)),
- Q: roleList,
- R: roleIndex.value,
- S: common_vendor.o(onRoleChange),
- T: editField.value === "officialEmail"
- }, editField.value === "officialEmail" ? {
- U: common_vendor.o(($event) => saveEdit("officialEmail")),
- V: common_vendor.o(($event) => saveEdit("officialEmail")),
- W: editValue.value,
- X: common_vendor.o(($event) => editValue.value = $event.detail.value)
- } : {
- Y: common_vendor.t(common_vendor.unref(userStore).userInfo.officialEmail || "未设置"),
- Z: common_vendor.o(($event) => beginEdit("officialEmail", common_vendor.unref(userStore).userInfo.officialEmail))
- }, {
- aa: editField.value === "contentEmail"
- }, editField.value === "contentEmail" ? {
- ab: common_vendor.o(($event) => saveEdit("contentEmail")),
- ac: common_vendor.o(($event) => saveEdit("contentEmail")),
- ad: editValue.value,
- ae: common_vendor.o(($event) => editValue.value = $event.detail.value)
- } : {
- af: common_vendor.t(common_vendor.unref(userStore).userInfo.contentEmail || "未设置"),
- ag: common_vendor.o(($event) => beginEdit("contentEmail", common_vendor.unref(userStore).userInfo.contentEmail))
- }, {
- ah: editField.value === "officialNumber"
- }, editField.value === "officialNumber" ? {
- ai: common_vendor.o(($event) => saveEdit("officialNumber")),
- aj: common_vendor.o(($event) => saveEdit("officialNumber")),
- ak: editValue.value,
- al: common_vendor.o(($event) => editValue.value = $event.detail.value)
- } : {
- am: common_vendor.t(common_vendor.unref(userStore).userInfo.officialNumber || "未设置"),
- an: common_vendor.o(($event) => beginEdit("officialNumber", common_vendor.unref(userStore).userInfo.officialNumber))
- }, {
- ao: common_vendor.o(goToPasswordChange),
- ap: showPhotoModal.value
- }, showPhotoModal.value ? common_vendor.e({
- aq: common_vendor.o(chooseFromAlbum),
- ar: common_vendor.o(takePhoto),
- as: !avatarConfig.value.isDefault
- }, !avatarConfig.value.isDefault ? {
- at: common_vendor.o(resetAvatar)
- } : {}, {
- av: common_vendor.o(() => {
- }),
- aw: common_vendor.o(hidePhotoOptions)
- }) : {}, {
- ax: navHeight.value + "px"
- });
- };
- }
- };
- const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-201c0da5"]]);
- wx.createPage(MiniProgramPage);
- //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/profile/index.js.map
|