index.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const store_user = require("../../store/user.js");
  4. const utils_defaultUtils = require("../../utils/defaultUtils.js");
  5. if (!Math) {
  6. NavBar();
  7. }
  8. const NavBar = () => "../components/NavBar/NavBar.js";
  9. const _sfc_main = {
  10. __name: "index",
  11. setup(__props) {
  12. const navBarRef = common_vendor.ref(null);
  13. const navHeight = common_vendor.ref(135);
  14. common_vendor.onMounted(async () => {
  15. var _a;
  16. await common_vendor.nextTick$1();
  17. navHeight.value = ((_a = navBarRef.value) == null ? void 0 : _a.totalNavHeight.value) || 135;
  18. common_vendor.watch(
  19. () => {
  20. var _a2;
  21. return (_a2 = navBarRef.value) == null ? void 0 : _a2.totalNavHeight.value;
  22. },
  23. (val) => {
  24. if (val)
  25. navHeight.value = val;
  26. },
  27. { immediate: true }
  28. );
  29. });
  30. const userStore = store_user.useUserStore();
  31. const showCamera = common_vendor.ref(false);
  32. const showPhotoModal = common_vendor.ref(false);
  33. const avatarConfig = common_vendor.computed(() => utils_defaultUtils.getUserAvatarConfig(userStore.userInfo));
  34. const onAvatarTouchStart = () => {
  35. showCamera.value = true;
  36. };
  37. const onAvatarTouchEnd = () => {
  38. showCamera.value = false;
  39. };
  40. const showPhotoOptions = () => {
  41. showPhotoModal.value = true;
  42. };
  43. const hidePhotoOptions = () => {
  44. showPhotoModal.value = false;
  45. };
  46. const resetAvatar = () => {
  47. userStore.resetToDefaultAvatar();
  48. hidePhotoOptions();
  49. common_vendor.index.showToast({ title: "已恢复默认头像", duration: 2e3 });
  50. };
  51. const chooseFromAlbum = () => {
  52. common_vendor.index.chooseImage({
  53. count: 1,
  54. sizeType: ["compressed"],
  55. sourceType: ["album"],
  56. success: (res) => {
  57. userStore.setCustomAvatar(res.tempFilePaths[0]);
  58. hidePhotoOptions();
  59. common_vendor.index.showToast({ title: "头像更新成功", duration: 2e3 });
  60. },
  61. fail: () => {
  62. common_vendor.index.showToast({ title: "选择照片失败", icon: "none" });
  63. }
  64. });
  65. };
  66. const takePhoto = () => {
  67. common_vendor.index.chooseImage({
  68. count: 1,
  69. sizeType: ["compressed"],
  70. sourceType: ["camera"],
  71. success: (res) => {
  72. userStore.setCustomAvatar(res.tempFilePaths[0]);
  73. hidePhotoOptions();
  74. common_vendor.index.showToast({ title: "头像更新成功", duration: 2e3 });
  75. },
  76. fail: () => {
  77. common_vendor.index.showToast({ title: "拍照失败", icon: "none" });
  78. }
  79. });
  80. };
  81. const editField = common_vendor.ref("");
  82. const editValue = common_vendor.ref("");
  83. function beginEdit(field, val) {
  84. editField.value = field;
  85. editValue.value = val || "";
  86. }
  87. function saveEdit(field) {
  88. if (editField.value !== field)
  89. return;
  90. userStore.setUserInfo({ [field]: editValue.value.trim() });
  91. editField.value = "";
  92. editValue.value = "";
  93. common_vendor.index.showToast({ title: "修改成功", icon: "success", duration: 1500 });
  94. }
  95. const genderList = ["男", "女", "未知"];
  96. const genderIndex = common_vendor.ref(0);
  97. common_vendor.onMounted(() => {
  98. setGenderPickerIndex();
  99. });
  100. function setGenderPickerIndex() {
  101. let idx = 2;
  102. if (userStore.userInfo.gender === "MALE" || userStore.userInfo.gender === 1 || userStore.userInfo.gender === "男")
  103. idx = 0;
  104. if (userStore.userInfo.gender === "FEMALE" || userStore.userInfo.gender === 0 || userStore.userInfo.gender === "女")
  105. idx = 1;
  106. genderIndex.value = idx;
  107. }
  108. function onGenderChange(e) {
  109. let val = e.detail ? e.detail.value : e;
  110. genderIndex.value = val;
  111. let g = genderList[val];
  112. let realVal = g === "男" ? "MALE" : g === "女" ? "FEMALE" : "";
  113. userStore.setUserInfo({ gender: realVal });
  114. }
  115. const editBirthday = common_vendor.ref("");
  116. function onBirthdayChange(e) {
  117. let dateStr = e.detail ? e.detail.value : e;
  118. editBirthday.value = dateStr;
  119. userStore.setUserInfo({ birthday: dateStr });
  120. }
  121. const roleList = ["学生", "教师"];
  122. const roleIndex = common_vendor.ref(0);
  123. common_vendor.onMounted(() => {
  124. setRolePickerIndex();
  125. });
  126. function setRolePickerIndex() {
  127. let role = userStore.userInfo.role || "";
  128. let idx = roleList.findIndex((r) => formatRoleEn(r) === role);
  129. roleIndex.value = idx >= 0 ? idx : 0;
  130. }
  131. function onRoleChange(e) {
  132. let idx = e.detail ? e.detail.value : e;
  133. roleIndex.value = idx;
  134. let enMap = ["STUDENT", "TEACHER"];
  135. userStore.setUserInfo({ role: enMap[idx] });
  136. }
  137. function formatRole(role) {
  138. const roleMap = { STUDENT: "学生", TEACHER: "教师" };
  139. return roleMap[role] || "未设置";
  140. }
  141. function formatRoleEn(cn) {
  142. const map = { "学生": "STUDENT", "教师": "TEACHER" };
  143. return map[cn] || "";
  144. }
  145. function formatGender(gender) {
  146. if (gender === null || gender === void 0 || gender === "")
  147. return "未设置";
  148. const genderMap = { MALE: "男", FEMALE: "女", male: "男", female: "女", 1: "男", 0: "女", "男": "男", "女": "女" };
  149. return genderMap[gender] || "未设置";
  150. }
  151. function formatBirthday(birthday) {
  152. if (!birthday)
  153. return "未设置";
  154. if (typeof birthday === "number")
  155. return new Date(birthday).toLocaleDateString();
  156. return birthday;
  157. }
  158. function goToPasswordChange() {
  159. common_vendor.index.showToast({
  160. title: "页面尚未开发",
  161. icon: "error"
  162. });
  163. }
  164. return (_ctx, _cache) => {
  165. return common_vendor.e({
  166. a: common_vendor.sr(navBarRef, "201c0da5-0", {
  167. "k": "navBarRef"
  168. }),
  169. b: !avatarConfig.value.isDefault
  170. }, !avatarConfig.value.isDefault ? {
  171. c: avatarConfig.value.src
  172. } : !showCamera.value ? {
  173. e: common_vendor.t(avatarConfig.value.text)
  174. } : {}, {
  175. d: !showCamera.value,
  176. f: showCamera.value
  177. }, showCamera.value ? {} : {}, {
  178. g: showCamera.value ? 1 : "",
  179. h: common_vendor.s(avatarConfig.value.style),
  180. i: common_vendor.o(onAvatarTouchStart),
  181. j: common_vendor.o(onAvatarTouchEnd),
  182. k: common_vendor.t(avatarConfig.value.isDefault ? "默认头像" : "自定义头像"),
  183. l: common_vendor.o(showPhotoOptions),
  184. m: editField.value === "name"
  185. }, editField.value === "name" ? {
  186. n: common_vendor.o(($event) => saveEdit("name")),
  187. o: common_vendor.o(($event) => saveEdit("name")),
  188. p: editValue.value,
  189. q: common_vendor.o(($event) => editValue.value = $event.detail.value)
  190. } : {
  191. r: common_vendor.t(common_vendor.unref(userStore).userInfo.name || "未设置"),
  192. s: common_vendor.o(($event) => beginEdit("name", common_vendor.unref(userStore).userInfo.name))
  193. }, {
  194. t: editField.value === "englishName"
  195. }, editField.value === "englishName" ? {
  196. v: common_vendor.o(($event) => saveEdit("englishName")),
  197. w: common_vendor.o(($event) => saveEdit("englishName")),
  198. x: editValue.value,
  199. y: common_vendor.o(($event) => editValue.value = $event.detail.value)
  200. } : {
  201. z: common_vendor.t(common_vendor.unref(userStore).userInfo.englishName || "未设置"),
  202. A: common_vendor.o(($event) => beginEdit("englishName", common_vendor.unref(userStore).userInfo.englishName))
  203. }, {
  204. B: editField.value === "phone"
  205. }, editField.value === "phone" ? {
  206. C: common_vendor.o(($event) => saveEdit("phone")),
  207. D: common_vendor.o(($event) => saveEdit("phone")),
  208. E: editValue.value,
  209. F: common_vendor.o(($event) => editValue.value = $event.detail.value)
  210. } : {
  211. G: common_vendor.t(common_vendor.unref(userStore).userInfo.phone || "未设置"),
  212. H: common_vendor.o(($event) => beginEdit("phone", common_vendor.unref(userStore).userInfo.phone))
  213. }, {
  214. I: common_vendor.t(formatGender(common_vendor.unref(userStore).userInfo.gender)),
  215. J: genderList,
  216. K: genderIndex.value,
  217. L: common_vendor.o(onGenderChange),
  218. M: common_vendor.t(formatBirthday(common_vendor.unref(userStore).userInfo.birthday)),
  219. N: editBirthday.value,
  220. O: common_vendor.o(onBirthdayChange),
  221. P: common_vendor.t(formatRole(common_vendor.unref(userStore).userInfo.role)),
  222. Q: roleList,
  223. R: roleIndex.value,
  224. S: common_vendor.o(onRoleChange),
  225. T: editField.value === "officialEmail"
  226. }, editField.value === "officialEmail" ? {
  227. U: common_vendor.o(($event) => saveEdit("officialEmail")),
  228. V: common_vendor.o(($event) => saveEdit("officialEmail")),
  229. W: editValue.value,
  230. X: common_vendor.o(($event) => editValue.value = $event.detail.value)
  231. } : {
  232. Y: common_vendor.t(common_vendor.unref(userStore).userInfo.officialEmail || "未设置"),
  233. Z: common_vendor.o(($event) => beginEdit("officialEmail", common_vendor.unref(userStore).userInfo.officialEmail))
  234. }, {
  235. aa: editField.value === "contentEmail"
  236. }, editField.value === "contentEmail" ? {
  237. ab: common_vendor.o(($event) => saveEdit("contentEmail")),
  238. ac: common_vendor.o(($event) => saveEdit("contentEmail")),
  239. ad: editValue.value,
  240. ae: common_vendor.o(($event) => editValue.value = $event.detail.value)
  241. } : {
  242. af: common_vendor.t(common_vendor.unref(userStore).userInfo.contentEmail || "未设置"),
  243. ag: common_vendor.o(($event) => beginEdit("contentEmail", common_vendor.unref(userStore).userInfo.contentEmail))
  244. }, {
  245. ah: editField.value === "officialNumber"
  246. }, editField.value === "officialNumber" ? {
  247. ai: common_vendor.o(($event) => saveEdit("officialNumber")),
  248. aj: common_vendor.o(($event) => saveEdit("officialNumber")),
  249. ak: editValue.value,
  250. al: common_vendor.o(($event) => editValue.value = $event.detail.value)
  251. } : {
  252. am: common_vendor.t(common_vendor.unref(userStore).userInfo.officialNumber || "未设置"),
  253. an: common_vendor.o(($event) => beginEdit("officialNumber", common_vendor.unref(userStore).userInfo.officialNumber))
  254. }, {
  255. ao: common_vendor.o(goToPasswordChange),
  256. ap: showPhotoModal.value
  257. }, showPhotoModal.value ? common_vendor.e({
  258. aq: common_vendor.o(chooseFromAlbum),
  259. ar: common_vendor.o(takePhoto),
  260. as: !avatarConfig.value.isDefault
  261. }, !avatarConfig.value.isDefault ? {
  262. at: common_vendor.o(resetAvatar)
  263. } : {}, {
  264. av: common_vendor.o(() => {
  265. }),
  266. aw: common_vendor.o(hidePhotoOptions)
  267. }) : {}, {
  268. ax: navHeight.value + "px"
  269. });
  270. };
  271. }
  272. };
  273. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-201c0da5"]]);
  274. wx.createPage(MiniProgramPage);
  275. //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/profile/index.js.map