favorites.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const common_assets = require("../../common/assets.js");
  4. const api_collection = require("../../api/collection.js");
  5. const api_message = require("../../api/message.js");
  6. const _sfc_main = {
  7. __name: "favorites",
  8. setup(__props) {
  9. const activeTab = common_vendor.ref("job");
  10. const tabs = [
  11. { name: "岗位", key: "job" },
  12. { name: "测评", key: "assessment" }
  13. ];
  14. const favoriteJobs = common_vendor.ref([]);
  15. const favoriteAssessments = common_vendor.ref([]);
  16. const loadData = async () => {
  17. common_vendor.index.showLoading({ title: "加载中..." });
  18. try {
  19. const userInfo = common_vendor.index.getStorageSync("userInfo");
  20. if (!userInfo || !userInfo.studentId)
  21. return;
  22. if (activeTab.value === "job") {
  23. const res = await api_collection.listCollection({ studentId: userInfo.studentId, type: "job" });
  24. if (res.code === 200) {
  25. favoriteJobs.value = (res.rows || res.data || []).map((item) => {
  26. const data = item.targetData || {};
  27. return {
  28. collectionId: item.id,
  29. id: item.targetId,
  30. title: data.postName || data.positionName || data.name || "未知岗位",
  31. salaryText: data.salaryRange || "面议",
  32. tags: [data.workCity, data.educationRequirementLabel || data.educationRequirement, data.gradeRequirementLabel || data.gradeRequirement].filter(Boolean),
  33. isUrgent: data.isUrgent === 1,
  34. count: data.recruitNum || 1,
  35. deadline: data.registrationEndDate ? data.registrationEndDate.split(" ")[0] : "长期有效",
  36. isExpiring: false,
  37. company: data.companyName || "平台推荐",
  38. location: (data.workProvince || "") + (data.workCity ? "·" + data.workCity : ""),
  39. logo: data.companyAvatar || "/static/icons/default-company.png"
  40. };
  41. });
  42. }
  43. } else {
  44. const res = await api_collection.listCollection({ studentId: userInfo.studentId, type: "assessment" });
  45. if (res.code === 200) {
  46. favoriteAssessments.value = (res.rows || res.data || []).map((item) => {
  47. const data = item.targetData || {};
  48. return {
  49. collectionId: item.id,
  50. id: item.targetId,
  51. title: data.evaluationName || data.title || data.name || "未知测评",
  52. level: data.gradeLabel || data.grade || "A1",
  53. type: data.positionTypeLabel || data.positionType || "",
  54. category: data.position || "",
  55. tags: data.tags ? data.tags.split(",") : [],
  56. desc: data.remark || data.detail || "暂无描述",
  57. cover: data.mainImageUrl || "/static/images/assess_cover.svg"
  58. };
  59. });
  60. }
  61. }
  62. } catch (err) {
  63. common_vendor.index.__f__("error", "at pages/my/favorites.vue:175", "加载收藏失败", err);
  64. } finally {
  65. common_vendor.index.hideLoading();
  66. }
  67. };
  68. common_vendor.watch(activeTab, () => {
  69. loadData();
  70. });
  71. common_vendor.onMounted(() => {
  72. loadData();
  73. });
  74. common_vendor.onPullDownRefresh(async () => {
  75. await loadData();
  76. common_vendor.index.stopPullDownRefresh();
  77. });
  78. const handleUnfavorite = (type, index) => {
  79. common_vendor.index.showModal({
  80. title: "提示",
  81. content: "确定要将该项从收藏夹移除吗?",
  82. success: async (res) => {
  83. if (res.confirm) {
  84. try {
  85. let collectionId;
  86. if (type === "job") {
  87. collectionId = favoriteJobs.value[index].collectionId;
  88. } else {
  89. collectionId = favoriteAssessments.value[index].collectionId;
  90. }
  91. common_vendor.index.showLoading({ title: "移除中..." });
  92. const delRes = await api_collection.delCollection(collectionId);
  93. common_vendor.index.hideLoading();
  94. if (delRes.code === 200) {
  95. if (type === "job") {
  96. favoriteJobs.value.splice(index, 1);
  97. } else {
  98. favoriteAssessments.value.splice(index, 1);
  99. }
  100. common_vendor.index.showToast({ title: "已移除收藏", icon: "success" });
  101. }
  102. } catch (err) {
  103. common_vendor.index.hideLoading();
  104. common_vendor.index.showToast({ title: "移除失败", icon: "none" });
  105. }
  106. }
  107. }
  108. });
  109. };
  110. const goToJobDetail = (item) => {
  111. common_vendor.index.navigateTo({
  112. url: `/pages/jobdetail/index?id=${item.id}&title=${encodeURIComponent(item.title)}`
  113. });
  114. };
  115. const goToAssessmentDetail = (item) => {
  116. common_vendor.index.navigateTo({
  117. url: `/pages/assessment/detail?id=${item.id}`
  118. });
  119. };
  120. const handleConsult = async (item) => {
  121. try {
  122. common_vendor.index.showLoading({ title: "正在连接客服..." });
  123. const userInfo = common_vendor.index.getStorageSync("userInfo") || {};
  124. const userId = userInfo.studentId || null;
  125. const userName = userInfo.name || "用户";
  126. const userAvatar = userInfo.avatarUrl || "/static/images/user_avatar.png";
  127. const res = await api_message.createOrGetSession({
  128. sessionType: 1,
  129. fromUserId: userId,
  130. fromUserName: userName,
  131. fromUserAvatar: userAvatar,
  132. sourceId: "assessment_" + ((item == null ? void 0 : item.id) || "")
  133. });
  134. common_vendor.index.hideLoading();
  135. if (res.data) {
  136. const session = res.data;
  137. common_vendor.index.navigateTo({
  138. url: `/pages/chat/chat?sessionId=${session.sessionId}&sessionNo=${session.sessionNo || ""}&fromUserId=${userId || ""}&userName=${encodeURIComponent(userName)}`
  139. });
  140. } else {
  141. common_vendor.index.showToast({ title: "创建会话失败", icon: "none" });
  142. }
  143. } catch (err) {
  144. common_vendor.index.hideLoading();
  145. common_vendor.index.__f__("error", "at pages/my/favorites.vue:267", "创建会话失败:", err);
  146. common_vendor.index.showToast({ title: "连接失败,请重试", icon: "none" });
  147. }
  148. };
  149. return (_ctx, _cache) => {
  150. return common_vendor.e({
  151. a: common_vendor.f(tabs, (tab, k0, i0) => {
  152. return {
  153. a: common_vendor.t(tab.name),
  154. b: tab.key,
  155. c: common_vendor.n(activeTab.value === tab.key ? "active" : ""),
  156. d: common_vendor.o(($event) => activeTab.value = tab.key, tab.key)
  157. };
  158. }),
  159. b: activeTab.value === "job"
  160. }, activeTab.value === "job" ? common_vendor.e({
  161. c: common_vendor.f(favoriteJobs.value, (item, index, i0) => {
  162. return common_vendor.e({
  163. a: common_vendor.t(item.title),
  164. b: item.isUrgent
  165. }, item.isUrgent ? {} : {}, {
  166. c: common_vendor.t(item.salaryText),
  167. d: common_vendor.f(item.tags, (tag, tagIdx, i1) => {
  168. return {
  169. a: common_vendor.t(tag),
  170. b: tagIdx
  171. };
  172. }),
  173. e: common_vendor.t(item.count),
  174. f: common_vendor.t(item.deadline),
  175. g: item.isExpiring
  176. }, item.isExpiring ? {} : {}, {
  177. h: item.logo,
  178. i: common_vendor.t(item.company),
  179. j: common_vendor.t(item.location),
  180. k: common_vendor.o(($event) => handleUnfavorite("job", index), item.id),
  181. l: item.id,
  182. m: common_vendor.o(($event) => goToJobDetail(item), item.id)
  183. });
  184. }),
  185. d: common_assets._imports_0$2,
  186. e: common_assets._imports_1$1,
  187. f: common_assets._imports_2$1,
  188. g: common_assets._imports_3$1,
  189. h: favoriteJobs.value.length === 0
  190. }, favoriteJobs.value.length === 0 ? {} : {}) : activeTab.value === "assessment" ? common_vendor.e({
  191. j: common_vendor.f(favoriteAssessments.value, (item, index, i0) => {
  192. return {
  193. a: item.cover,
  194. b: common_vendor.t(item.title),
  195. c: common_vendor.t(item.level),
  196. d: common_vendor.t(item.type),
  197. e: common_vendor.t(item.category),
  198. f: common_vendor.f(item.tags, (tag, tIdx, i1) => {
  199. return {
  200. a: common_vendor.t(tag),
  201. b: tIdx
  202. };
  203. }),
  204. g: common_vendor.t(item.desc),
  205. h: common_vendor.o(($event) => handleConsult(item), item.id),
  206. i: common_vendor.o(($event) => handleUnfavorite("assessment", index), item.id),
  207. j: item.id,
  208. k: common_vendor.o(($event) => goToAssessmentDetail(item), item.id)
  209. };
  210. }),
  211. k: common_assets._imports_3$1,
  212. l: favoriteAssessments.value.length === 0
  213. }, favoriteAssessments.value.length === 0 ? {} : {}) : {}, {
  214. i: activeTab.value === "assessment",
  215. m: activeTab.value === "job" && favoriteJobs.value.length > 0 || activeTab.value === "assessment" && favoriteAssessments.value.length > 0
  216. }, activeTab.value === "job" && favoriteJobs.value.length > 0 || activeTab.value === "assessment" && favoriteAssessments.value.length > 0 ? {} : {});
  217. };
  218. }
  219. };
  220. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-1a2a9709"]]);
  221. wx.createPage(MiniProgramPage);
  222. //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/my/favorites.js.map