| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- "use strict";
- const common_vendor = require("../../common/vendor.js");
- const common_assets = require("../../common/assets.js");
- const api_collection = require("../../api/collection.js");
- const api_message = require("../../api/message.js");
- const _sfc_main = {
- __name: "favorites",
- setup(__props) {
- const activeTab = common_vendor.ref("job");
- const tabs = [
- { name: "岗位", key: "job" },
- { name: "测评", key: "assessment" }
- ];
- const favoriteJobs = common_vendor.ref([]);
- const favoriteAssessments = common_vendor.ref([]);
- const loadData = async () => {
- common_vendor.index.showLoading({ title: "加载中..." });
- try {
- const userInfo = common_vendor.index.getStorageSync("userInfo");
- if (!userInfo || !userInfo.studentId)
- return;
- if (activeTab.value === "job") {
- const res = await api_collection.listCollection({ studentId: userInfo.studentId, type: "job" });
- if (res.code === 200) {
- favoriteJobs.value = (res.rows || res.data || []).map((item) => {
- const data = item.targetData || {};
- return {
- collectionId: item.id,
- id: item.targetId,
- title: data.postName || data.positionName || data.name || "未知岗位",
- salaryText: data.salaryRange || "面议",
- tags: [data.workCity, data.educationRequirementLabel || data.educationRequirement, data.gradeRequirementLabel || data.gradeRequirement].filter(Boolean),
- isUrgent: data.isUrgent === 1,
- count: data.recruitNum || 1,
- deadline: data.registrationEndDate ? data.registrationEndDate.split(" ")[0] : "长期有效",
- isExpiring: false,
- company: data.companyName || "平台推荐",
- location: (data.workProvince || "") + (data.workCity ? "·" + data.workCity : ""),
- logo: data.companyAvatar || "/static/icons/default-company.png"
- };
- });
- }
- } else {
- const res = await api_collection.listCollection({ studentId: userInfo.studentId, type: "assessment" });
- if (res.code === 200) {
- favoriteAssessments.value = (res.rows || res.data || []).map((item) => {
- const data = item.targetData || {};
- return {
- collectionId: item.id,
- id: item.targetId,
- title: data.evaluationName || data.title || data.name || "未知测评",
- level: data.gradeLabel || data.grade || "A1",
- type: data.positionTypeLabel || data.positionType || "",
- category: data.position || "",
- tags: data.tags ? data.tags.split(",") : [],
- desc: data.remark || data.detail || "暂无描述",
- cover: data.mainImageUrl || "/static/images/assess_cover.svg"
- };
- });
- }
- }
- } catch (err) {
- common_vendor.index.__f__("error", "at pages/my/favorites.vue:175", "加载收藏失败", err);
- } finally {
- common_vendor.index.hideLoading();
- }
- };
- common_vendor.watch(activeTab, () => {
- loadData();
- });
- common_vendor.onMounted(() => {
- loadData();
- });
- common_vendor.onPullDownRefresh(async () => {
- await loadData();
- common_vendor.index.stopPullDownRefresh();
- });
- const handleUnfavorite = (type, index) => {
- common_vendor.index.showModal({
- title: "提示",
- content: "确定要将该项从收藏夹移除吗?",
- success: async (res) => {
- if (res.confirm) {
- try {
- let collectionId;
- if (type === "job") {
- collectionId = favoriteJobs.value[index].collectionId;
- } else {
- collectionId = favoriteAssessments.value[index].collectionId;
- }
- common_vendor.index.showLoading({ title: "移除中..." });
- const delRes = await api_collection.delCollection(collectionId);
- common_vendor.index.hideLoading();
- if (delRes.code === 200) {
- if (type === "job") {
- favoriteJobs.value.splice(index, 1);
- } else {
- favoriteAssessments.value.splice(index, 1);
- }
- common_vendor.index.showToast({ title: "已移除收藏", icon: "success" });
- }
- } catch (err) {
- common_vendor.index.hideLoading();
- common_vendor.index.showToast({ title: "移除失败", icon: "none" });
- }
- }
- }
- });
- };
- const goToJobDetail = (item) => {
- common_vendor.index.navigateTo({
- url: `/pages/jobdetail/index?id=${item.id}&title=${encodeURIComponent(item.title)}`
- });
- };
- const goToAssessmentDetail = (item) => {
- common_vendor.index.navigateTo({
- url: `/pages/assessment/detail?id=${item.id}`
- });
- };
- const handleConsult = async (item) => {
- try {
- common_vendor.index.showLoading({ title: "正在连接客服..." });
- const userInfo = common_vendor.index.getStorageSync("userInfo") || {};
- const userId = userInfo.studentId || null;
- const userName = userInfo.name || "用户";
- const userAvatar = userInfo.avatarUrl || "/static/images/user_avatar.png";
- const res = await api_message.createOrGetSession({
- sessionType: 1,
- fromUserId: userId,
- fromUserName: userName,
- fromUserAvatar: userAvatar,
- sourceId: "assessment_" + ((item == null ? void 0 : item.id) || "")
- });
- common_vendor.index.hideLoading();
- if (res.data) {
- const session = res.data;
- common_vendor.index.navigateTo({
- url: `/pages/chat/chat?sessionId=${session.sessionId}&sessionNo=${session.sessionNo || ""}&fromUserId=${userId || ""}&userName=${encodeURIComponent(userName)}`
- });
- } else {
- common_vendor.index.showToast({ title: "创建会话失败", icon: "none" });
- }
- } catch (err) {
- common_vendor.index.hideLoading();
- common_vendor.index.__f__("error", "at pages/my/favorites.vue:267", "创建会话失败:", err);
- common_vendor.index.showToast({ title: "连接失败,请重试", icon: "none" });
- }
- };
- return (_ctx, _cache) => {
- return common_vendor.e({
- a: common_vendor.f(tabs, (tab, k0, i0) => {
- return {
- a: common_vendor.t(tab.name),
- b: tab.key,
- c: common_vendor.n(activeTab.value === tab.key ? "active" : ""),
- d: common_vendor.o(($event) => activeTab.value = tab.key, tab.key)
- };
- }),
- b: activeTab.value === "job"
- }, activeTab.value === "job" ? common_vendor.e({
- c: common_vendor.f(favoriteJobs.value, (item, index, i0) => {
- return common_vendor.e({
- a: common_vendor.t(item.title),
- b: item.isUrgent
- }, item.isUrgent ? {} : {}, {
- c: common_vendor.t(item.salaryText),
- d: common_vendor.f(item.tags, (tag, tagIdx, i1) => {
- return {
- a: common_vendor.t(tag),
- b: tagIdx
- };
- }),
- e: common_vendor.t(item.count),
- f: common_vendor.t(item.deadline),
- g: item.isExpiring
- }, item.isExpiring ? {} : {}, {
- h: item.logo,
- i: common_vendor.t(item.company),
- j: common_vendor.t(item.location),
- k: common_vendor.o(($event) => handleUnfavorite("job", index), item.id),
- l: item.id,
- m: common_vendor.o(($event) => goToJobDetail(item), item.id)
- });
- }),
- d: common_assets._imports_0$2,
- e: common_assets._imports_1$1,
- f: common_assets._imports_2$1,
- g: common_assets._imports_3$1,
- h: favoriteJobs.value.length === 0
- }, favoriteJobs.value.length === 0 ? {} : {}) : activeTab.value === "assessment" ? common_vendor.e({
- j: common_vendor.f(favoriteAssessments.value, (item, index, i0) => {
- return {
- a: item.cover,
- b: common_vendor.t(item.title),
- c: common_vendor.t(item.level),
- d: common_vendor.t(item.type),
- e: common_vendor.t(item.category),
- f: common_vendor.f(item.tags, (tag, tIdx, i1) => {
- return {
- a: common_vendor.t(tag),
- b: tIdx
- };
- }),
- g: common_vendor.t(item.desc),
- h: common_vendor.o(($event) => handleConsult(item), item.id),
- i: common_vendor.o(($event) => handleUnfavorite("assessment", index), item.id),
- j: item.id,
- k: common_vendor.o(($event) => goToAssessmentDetail(item), item.id)
- };
- }),
- k: common_assets._imports_3$1,
- l: favoriteAssessments.value.length === 0
- }, favoriteAssessments.value.length === 0 ? {} : {}) : {}, {
- i: activeTab.value === "assessment",
- m: activeTab.value === "job" && favoriteJobs.value.length > 0 || activeTab.value === "assessment" && favoriteAssessments.value.length > 0
- }, activeTab.value === "job" && favoriteJobs.value.length > 0 || activeTab.value === "assessment" && favoriteAssessments.value.length > 0 ? {} : {});
- };
- }
- };
- const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-1a2a9709"]]);
- wx.createPage(MiniProgramPage);
- //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/my/favorites.js.map
|