my.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const common_assets = require("../../common/assets.js");
  4. const api_student = require("../../api/student.js");
  5. const utils_request = require("../../utils/request.js");
  6. if (!Math) {
  7. CustomTabbar();
  8. }
  9. const CustomTabbar = () => "../../components/custom-tabbar/custom-tabbar.js";
  10. const _sfc_main = {
  11. __name: "my",
  12. setup(__props) {
  13. const navFullHeight = common_vendor.ref(80);
  14. const showResumeModal = common_vendor.ref(false);
  15. const studentInfo = common_vendor.ref({
  16. id: null,
  17. name: "",
  18. avatarUrl: "",
  19. schoolName: "",
  20. education: "",
  21. educationLabel: "",
  22. jobType: "",
  23. jobTypeLabel: "",
  24. resumeFile: null,
  25. educationList: []
  26. // 教育经历列表
  27. });
  28. const educationLabel = common_vendor.computed(() => {
  29. if (studentInfo.value.educationList && studentInfo.value.educationList.length > 0) {
  30. const educationLevel = { "初中及以下": 1, "高中": 2, "中专": 2, "大专": 3, "本科": 4, "硕士": 5, "博士": 6 };
  31. let highestEdu = studentInfo.value.educationList[0];
  32. let maxLevel = educationLevel[highestEdu.education] || 0;
  33. for (const edu of studentInfo.value.educationList) {
  34. const level = educationLevel[edu.education] || 0;
  35. if (level > maxLevel) {
  36. maxLevel = level;
  37. highestEdu = edu;
  38. }
  39. }
  40. return highestEdu.education || "";
  41. }
  42. if (studentInfo.value.educationLabel)
  43. return studentInfo.value.educationLabel;
  44. const val = studentInfo.value.education;
  45. if (!val || val === "0" || val === 0)
  46. return "";
  47. return /^\d+$/.test(String(val)) ? "" : val;
  48. });
  49. const jobTypeMap = { "1": "全职", "2": "实习", "3": "兼职", "全职": "全职", "实习": "实习", "兼职": "兼职" };
  50. const jobTypeLabel = common_vendor.computed(() => {
  51. if (studentInfo.value.jobTypeLabel)
  52. return studentInfo.value.jobTypeLabel;
  53. const val = studentInfo.value.jobType;
  54. return jobTypeMap[val] || val || "";
  55. });
  56. const schoolNameLabel = common_vendor.computed(() => {
  57. if (studentInfo.value.educationList && studentInfo.value.educationList.length > 0) {
  58. const educationLevel = { "初中及以下": 1, "高中": 2, "中专": 2, "大专": 3, "本科": 4, "硕士": 5, "博士": 6 };
  59. let highestEdu = studentInfo.value.educationList[0];
  60. let maxLevel = educationLevel[highestEdu.education] || 0;
  61. for (const edu of studentInfo.value.educationList) {
  62. const level = educationLevel[edu.education] || 0;
  63. if (level > maxLevel) {
  64. maxLevel = level;
  65. highestEdu = edu;
  66. }
  67. }
  68. return highestEdu.school || "";
  69. }
  70. const val = studentInfo.value.schoolName;
  71. if (!val || /^\d+$/.test(val))
  72. return "";
  73. return val;
  74. });
  75. const hasResume = common_vendor.computed(() => !!studentInfo.value.resumeFile);
  76. const loadUserInfo = async () => {
  77. const userInfo = common_vendor.index.getStorageSync("userInfo");
  78. if (!userInfo || !userInfo.studentId)
  79. return;
  80. try {
  81. const res = await api_student.getStudent(userInfo.studentId);
  82. if (res && res.data) {
  83. const data = res.data;
  84. studentInfo.value = {
  85. id: data.id,
  86. name: data.name || userInfo.name || "",
  87. avatarUrl: data.avatarUrl || userInfo.avatarUrl || "",
  88. schoolName: data.schoolName || "",
  89. education: data.education || "",
  90. educationLabel: data.educationLabel || "",
  91. jobType: data.jobType || "",
  92. jobTypeLabel: data.jobTypeLabel || "",
  93. resumeFile: data.resumeFile || null,
  94. educationList: data.educationList || []
  95. };
  96. }
  97. } catch (err) {
  98. common_vendor.index.__f__("error", "at pages/my/my.vue:230", "获取用户详情失败", err);
  99. }
  100. fetchAppendixList();
  101. };
  102. common_vendor.onMounted(async () => {
  103. try {
  104. const menuButton = common_vendor.index.getMenuButtonBoundingClientRect();
  105. if (menuButton) {
  106. navFullHeight.value = menuButton.bottom + 10;
  107. }
  108. } catch (e) {
  109. common_vendor.index.__f__("error", "at pages/my/my.vue:243", "导航栏高度计算失败", e);
  110. }
  111. const userInfo = common_vendor.index.getStorageSync("userInfo");
  112. if (!userInfo || !userInfo.studentId) {
  113. common_vendor.index.reLaunch({ url: "/pages/login/login" });
  114. return;
  115. }
  116. studentInfo.value.id = userInfo.studentId;
  117. studentInfo.value.name = userInfo.name || "";
  118. studentInfo.value.avatarUrl = userInfo.avatarUrl || "";
  119. await loadUserInfo();
  120. });
  121. common_vendor.onShow(async () => {
  122. const userInfo = common_vendor.index.getStorageSync("userInfo");
  123. if (userInfo && userInfo.studentId) {
  124. await loadUserInfo();
  125. }
  126. });
  127. common_vendor.onPullDownRefresh(async () => {
  128. await loadUserInfo();
  129. common_vendor.index.stopPullDownRefresh();
  130. });
  131. const fetchAppendixList = async () => {
  132. try {
  133. const userInfo = common_vendor.index.getStorageSync("userInfo");
  134. if (userInfo && userInfo.studentId) {
  135. const res = await api_student.getAppendixList(userInfo.studentId);
  136. if (res && res.code === 200) {
  137. resumeList.value = res.data.map((item) => ({
  138. id: item.id,
  139. name: item.fileName,
  140. url: item.url,
  141. ossId: item.ossId
  142. }));
  143. }
  144. }
  145. } catch (err) {
  146. common_vendor.index.__f__("error", "at pages/my/my.vue:292", "获取附件列表失败", err);
  147. }
  148. };
  149. const handleOnlineResume = () => {
  150. if (!hasResume.value) {
  151. showResumeModal.value = true;
  152. } else {
  153. common_vendor.index.navigateTo({ url: "/pages/my/resume_view" });
  154. }
  155. };
  156. const confirmToFill = () => {
  157. showResumeModal.value = false;
  158. common_vendor.index.navigateTo({ url: "/pages/profile/profile?editMode=1" });
  159. };
  160. const navigateTo = (type) => {
  161. const routes = {
  162. "collection": "/pages/my/favorites",
  163. "intention": "/pages/intention/intention?editMode=1",
  164. "assessment": "/pages/my/assessment-records",
  165. "order": "/pages/my/orders"
  166. };
  167. if (routes[type]) {
  168. common_vendor.index.navigateTo({ url: routes[type] });
  169. }
  170. };
  171. const handleOffer = () => {
  172. common_vendor.index.navigateTo({ url: "/pages/my/offer" });
  173. };
  174. const handlePrivacy = () => {
  175. common_vendor.index.navigateTo({ url: "/pages/my/privacy_policy" });
  176. };
  177. const resumeList = common_vendor.ref([]);
  178. const uploadFromWechat = () => {
  179. if (resumeList.value.length >= 3) {
  180. common_vendor.index.showToast({ title: "最多上传3份简历", icon: "none" });
  181. return;
  182. }
  183. common_vendor.index.chooseMessageFile({
  184. count: 1,
  185. type: "file",
  186. extension: ["pdf"],
  187. success: (res) => {
  188. const file = res.tempFiles[0];
  189. processUpload(file.name, file.path, file.size);
  190. }
  191. });
  192. };
  193. const uploadFromLocal = () => {
  194. uploadFromWechat();
  195. };
  196. const processUpload = (name, path, size) => {
  197. if (!name.toLowerCase().endsWith(".pdf")) {
  198. common_vendor.index.showToast({ title: "仅支持 PDF 格式文件", icon: "none" });
  199. return;
  200. }
  201. common_vendor.index.showLoading({ title: "上传中..." });
  202. const baseUrl = utils_request.UPLOAD_URL;
  203. common_vendor.index.uploadFile({
  204. url: baseUrl + "/portal/oss/upload",
  205. filePath: path,
  206. name: "file",
  207. header: {
  208. "Authorization": common_vendor.index.getStorageSync("token") ? `Bearer ${common_vendor.index.getStorageSync("token")}` : "",
  209. "PLATFORM_CODE": "PINGTAIDUAN"
  210. },
  211. success: async (uploadRes) => {
  212. const uploadData = JSON.parse(uploadRes.data);
  213. if (uploadData.code === 200) {
  214. const ossId = uploadData.data.ossId;
  215. try {
  216. const userInfo = common_vendor.index.getStorageSync("userInfo");
  217. const saveRes = await api_student.addAppendix({
  218. studentId: userInfo.studentId,
  219. ossId,
  220. fileName: name,
  221. fileSize: size
  222. });
  223. common_vendor.index.hideLoading();
  224. if (saveRes.code === 200) {
  225. common_vendor.index.showToast({ title: "上传成功", icon: "success" });
  226. fetchAppendixList();
  227. } else {
  228. common_vendor.index.showToast({ title: saveRes.msg || "保存失败", icon: "none" });
  229. }
  230. } catch (e) {
  231. common_vendor.index.hideLoading();
  232. common_vendor.index.showToast({ title: "服务器异常", icon: "none" });
  233. }
  234. } else {
  235. common_vendor.index.hideLoading();
  236. common_vendor.index.showToast({ title: uploadData.msg || "上传失败", icon: "none" });
  237. }
  238. },
  239. fail: (err) => {
  240. common_vendor.index.hideLoading();
  241. common_vendor.index.showToast({ title: "网络上传失败", icon: "none" });
  242. }
  243. });
  244. };
  245. const removeResume = (index) => {
  246. const target = resumeList.value[index];
  247. common_vendor.index.showModal({
  248. title: "提示",
  249. content: "确定要删除这份简历吗?",
  250. success: async (res) => {
  251. if (res.confirm) {
  252. try {
  253. common_vendor.index.showLoading({ title: "删除中..." });
  254. const delRes = await api_student.removeAppendix(target.id);
  255. common_vendor.index.hideLoading();
  256. if (delRes.code === 200) {
  257. resumeList.value.splice(index, 1);
  258. common_vendor.index.showToast({ title: "已删除", icon: "none" });
  259. } else {
  260. common_vendor.index.showToast({ title: delRes.msg || "删除失败", icon: "none" });
  261. }
  262. } catch (e) {
  263. common_vendor.index.hideLoading();
  264. common_vendor.index.showToast({ title: "网络异常", icon: "none" });
  265. }
  266. }
  267. }
  268. });
  269. };
  270. const handleLogout = () => {
  271. common_vendor.index.showModal({
  272. title: "提示",
  273. content: "确定要退出登录吗?",
  274. success: (res) => {
  275. if (res.confirm) {
  276. common_vendor.index.removeStorageSync("token");
  277. common_vendor.index.removeStorageSync("userInfo");
  278. common_vendor.index.reLaunch({ url: "/pages/login/login" });
  279. }
  280. }
  281. });
  282. };
  283. return (_ctx, _cache) => {
  284. return common_vendor.e({
  285. a: navFullHeight.value + "px",
  286. b: studentInfo.value.avatarUrl || "/static/images/hr_avatar.svg",
  287. c: common_vendor.t(studentInfo.value.name || "加载中..."),
  288. d: common_assets._imports_0$10,
  289. e: common_assets._imports_0$11,
  290. f: common_vendor.o(handleOnlineResume),
  291. g: schoolNameLabel.value
  292. }, schoolNameLabel.value ? {
  293. h: common_vendor.t(schoolNameLabel.value)
  294. } : {}, {
  295. i: educationLabel.value
  296. }, educationLabel.value ? {
  297. j: common_vendor.t(educationLabel.value)
  298. } : {}, {
  299. k: jobTypeLabel.value
  300. }, jobTypeLabel.value ? {
  301. l: common_vendor.t(jobTypeLabel.value)
  302. } : {}, {
  303. m: common_assets._imports_2$5,
  304. n: common_vendor.o(($event) => navigateTo("collection")),
  305. o: common_assets._imports_3$3,
  306. p: common_vendor.o(($event) => navigateTo("intention")),
  307. q: common_assets._imports_4$1,
  308. r: common_vendor.o(($event) => navigateTo("assessment")),
  309. s: common_assets._imports_5$1,
  310. t: common_vendor.o(($event) => navigateTo("order")),
  311. v: common_vendor.t(resumeList.value.length),
  312. w: common_vendor.o(uploadFromWechat),
  313. x: common_vendor.o(uploadFromLocal),
  314. y: resumeList.value.length > 0
  315. }, resumeList.value.length > 0 ? {
  316. z: common_vendor.f(resumeList.value, (file, idx, i0) => {
  317. return {
  318. a: common_vendor.t(file.name),
  319. b: common_vendor.o(($event) => removeResume(idx), file.id),
  320. c: file.id
  321. };
  322. }),
  323. A: common_assets._imports_0$9,
  324. B: common_assets._imports_7$1
  325. } : {}, {
  326. C: common_assets._imports_8,
  327. D: common_vendor.o(handleOffer),
  328. E: common_assets._imports_8,
  329. F: common_vendor.o(handlePrivacy),
  330. G: common_vendor.o(handleLogout),
  331. H: showResumeModal.value
  332. }, showResumeModal.value ? {
  333. I: common_vendor.o(($event) => showResumeModal.value = false),
  334. J: common_vendor.o(confirmToFill),
  335. K: common_vendor.o(() => {
  336. })
  337. } : {}, {
  338. L: common_vendor.p({
  339. activeIndex: 3
  340. })
  341. });
  342. };
  343. }
  344. };
  345. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-2f1ef635"]]);
  346. wx.createPage(MiniProgramPage);
  347. //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/my/my.js.map