favorites.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. <template>
  2. <view class="container">
  3. <!-- Tabs -->
  4. <view class="tab-header">
  5. <view
  6. v-for="tab in tabs"
  7. :key="tab.key"
  8. :class="['tab-item', activeTab === tab.key ? 'active' : '']"
  9. @click="activeTab = tab.key"
  10. >
  11. {{ tab.name }}
  12. </view>
  13. </view>
  14. <!-- Content List -->
  15. <scroll-view class="content-scroll" scroll-y>
  16. <!-- 岗位收藏列表 -->
  17. <view v-if="activeTab === 'job'" class="list-wrap">
  18. <view
  19. v-for="(item, index) in favoriteJobs"
  20. :key="item.id"
  21. class="job-card card-anim"
  22. @click="goToJobDetail(item)"
  23. >
  24. <view class="job-header">
  25. <view class="job-title-box">
  26. <text class="job-title">{{ item.title }}</text>
  27. <text class="urge-tag" v-if="item.isUrgent">急招</text>
  28. </view>
  29. <text class="job-salary">{{ item.salaryText }}</text>
  30. </view>
  31. <view class="tags-row">
  32. <text class="tag" v-for="(tag, tagIdx) in item.tags" :key="tagIdx">{{ tag }}</text>
  33. </view>
  34. <view class="info-row">
  35. <image src="/static/icons/user.svg" class="info-icon" mode="aspectFit"></image>
  36. <text class="info-text">招录 {{ item.count }} 人</text>
  37. </view>
  38. <view class="info-row">
  39. <image src="/static/icons/time.svg" class="info-icon" mode="aspectFit"></image>
  40. <text class="info-text">截止时间:{{ item.deadline }}</text>
  41. <text class="danger-text" v-if="item.isExpiring">即将截止</text>
  42. </view>
  43. <view class="company-row">
  44. <view class="company-info-wrap">
  45. <image :src="item.logo" class="company-logo" mode="aspectFill"></image>
  46. <view class="company-text-col">
  47. <view class="company-name-box">
  48. <text class="company-name">{{ item.company }}</text>
  49. <image src="/static/icons/verified.svg" class="verified-icon" mode="aspectFit"></image>
  50. </view>
  51. <text class="company-location">{{ item.location }}</text>
  52. </view>
  53. </view>
  54. <image src="/static/icons/close.svg" class="close-icon" mode="aspectFit" @click.stop="handleUnfavorite('job', index)"></image>
  55. </view>
  56. </view>
  57. <view v-if="favoriteJobs.length === 0" class="empty-status">
  58. <text>暂无收藏岗位</text>
  59. </view>
  60. </view>
  61. <!-- 测评收藏列表 -->
  62. <view v-else-if="activeTab === 'assessment'" class="list-wrap">
  63. <view
  64. v-for="(item, index) in favoriteAssessments"
  65. :key="item.id"
  66. class="assessment-card card-anim"
  67. @click="goToAssessmentDetail(item)"
  68. >
  69. <view class="card-left">
  70. <image :src="item.cover" class="cover-img" mode="aspectFill"></image>
  71. </view>
  72. <view class="card-right">
  73. <view class="top-line">
  74. <text class="job-title">{{ item.title }}</text>
  75. <text class="job-level-tag">{{ item.level }}</text>
  76. </view>
  77. <view class="tag-row">
  78. <text class="tag-badge type-tag">{{ item.type }}</text>
  79. <text class="tag-badge category-tag">{{ item.category }}</text>
  80. <text class="tag-badge" v-for="(tag, tIdx) in item.tags" :key="tIdx">{{ tag }}</text>
  81. </view>
  82. <view class="desc-text text-ellipsis-2">
  83. {{ item.desc }}
  84. </view>
  85. <view class="btn-wrap">
  86. <button class="consult-btn" @click.stop="handleConsult(item)">咨询</button>
  87. </view>
  88. </view>
  89. <view class="collect-icon-wrap" @click.stop="handleUnfavorite('assessment', index)">
  90. <image src="/static/icons/close.svg" class="collect-icon" mode="aspectFit"></image>
  91. </view>
  92. </view>
  93. <view v-if="favoriteAssessments.length === 0" class="empty-status">
  94. <text>暂无收藏测评</text>
  95. </view>
  96. </view>
  97. <view v-if="(activeTab === 'job' && favoriteJobs.length > 0) || (activeTab === 'assessment' && favoriteAssessments.length > 0)" class="no-more">—— 已到底啦~ ——</view>
  98. </scroll-view>
  99. </view>
  100. </template>
  101. <script setup>
  102. import { ref, computed, onMounted, watch } from 'vue';
  103. import { onShow, onPullDownRefresh } from '@dcloudio/uni-app';
  104. import { listCollection, delCollection } from '../../api/collection.js';
  105. import { createOrGetSession } from '../../api/message.js';
  106. const activeTab = ref('job');
  107. const tabs = [
  108. { name: '岗位', key: 'job' },
  109. { name: '测评', key: 'assessment' }
  110. ];
  111. const favoriteJobs = ref([]);
  112. const favoriteAssessments = ref([]);
  113. // 加载收藏列表
  114. const loadData = async () => {
  115. uni.showLoading({ title: '加载中...' });
  116. try {
  117. const userInfo = uni.getStorageSync('userInfo');
  118. if (!userInfo || !userInfo.studentId) return;
  119. // 加载岗位收藏
  120. if (activeTab.value === 'job') {
  121. const res = await listCollection({ studentId: userInfo.studentId, type: 'job' });
  122. if (res.code === 200) {
  123. // 假设后端返回的数据中包含 targetData 对象存储岗位详情
  124. favoriteJobs.value = (res.rows || res.data || []).map(item => {
  125. const data = item.targetData || {};
  126. return {
  127. collectionId: item.id,
  128. id: item.targetId,
  129. title: data.postName || data.positionName || data.name || '未知岗位',
  130. salaryText: data.salaryRange || '面议',
  131. tags: [data.workCity, data.educationRequirementLabel || data.educationRequirement, data.gradeRequirementLabel || data.gradeRequirement].filter(Boolean),
  132. isUrgent: data.isUrgent === 1,
  133. count: data.recruitNum || 1,
  134. deadline: data.registrationEndDate ? data.registrationEndDate.split(' ')[0] : '长期有效',
  135. isExpiring: false,
  136. company: data.companyName || '平台推荐',
  137. location: (data.workProvince || '') + (data.workCity ? '·' + data.workCity : ''),
  138. logo: data.companyAvatar || '/static/icons/default-company.png'
  139. };
  140. });
  141. }
  142. }
  143. // 加载测评收藏
  144. else {
  145. const res = await listCollection({ studentId: userInfo.studentId, type: 'assessment' });
  146. if (res.code === 200) {
  147. favoriteAssessments.value = (res.rows || res.data || []).map(item => {
  148. const data = item.targetData || {};
  149. return {
  150. collectionId: item.id,
  151. id: item.targetId,
  152. title: data.evaluationName || data.title || data.name || '未知测评',
  153. level: data.gradeLabel || data.grade || 'A1',
  154. type: data.positionTypeLabel || data.positionType || '',
  155. category: data.position || '',
  156. tags: data.tags ? data.tags.split(',') : [],
  157. desc: data.remark || data.detail || '暂无描述',
  158. cover: data.mainImageUrl || '/static/images/assess_cover.svg'
  159. };
  160. });
  161. }
  162. }
  163. } catch (err) {
  164. console.error('加载收藏失败', err);
  165. } finally {
  166. uni.hideLoading();
  167. }
  168. };
  169. // 监听Tab切换,重新加载数据
  170. watch(activeTab, () => {
  171. loadData();
  172. });
  173. onMounted(() => {
  174. loadData();
  175. });
  176. onPullDownRefresh(async () => {
  177. await loadData();
  178. uni.stopPullDownRefresh();
  179. });
  180. const handleUnfavorite = (type, index) => {
  181. uni.showModal({
  182. title: '提示',
  183. content: '确定要将该项从收藏夹移除吗?',
  184. success: async (res) => {
  185. if (res.confirm) {
  186. try {
  187. let collectionId;
  188. if (type === 'job') {
  189. collectionId = favoriteJobs.value[index].collectionId;
  190. } else {
  191. collectionId = favoriteAssessments.value[index].collectionId;
  192. }
  193. uni.showLoading({ title: '移除中...' });
  194. const delRes = await delCollection(collectionId);
  195. uni.hideLoading();
  196. if (delRes.code === 200) {
  197. if (type === 'job') {
  198. favoriteJobs.value.splice(index, 1);
  199. } else {
  200. favoriteAssessments.value.splice(index, 1);
  201. }
  202. uni.showToast({ title: '已移除收藏', icon: 'success' });
  203. }
  204. } catch (err) {
  205. uni.hideLoading();
  206. uni.showToast({ title: '移除失败', icon: 'none' });
  207. }
  208. }
  209. }
  210. });
  211. };
  212. const goToJobDetail = (item) => {
  213. uni.navigateTo({
  214. url: `/pages/jobdetail/index?id=${item.id}&title=${encodeURIComponent(item.title)}`
  215. });
  216. };
  217. const goToAssessmentDetail = (item) => {
  218. uni.navigateTo({
  219. url: `/pages/assessment/detail?id=${item.id}`
  220. });
  221. };
  222. const handleConsult = async (item) => {
  223. try {
  224. uni.showLoading({ title: '正在连接客服...' });
  225. const userInfo = uni.getStorageSync('userInfo') || {};
  226. const userId = userInfo.studentId || null;
  227. const userName = userInfo.name || '用户';
  228. const userAvatar = userInfo.avatarUrl || '/static/images/user_avatar.png';
  229. const res = await createOrGetSession({
  230. sessionType: 1,
  231. fromUserId: userId,
  232. fromUserName: userName,
  233. fromUserAvatar: userAvatar,
  234. sourceId: 'assessment_' + (item?.id || '')
  235. });
  236. uni.hideLoading();
  237. if (res.data) {
  238. const session = res.data;
  239. uni.navigateTo({
  240. url: `/pages/chat/chat?sessionId=${session.sessionId}&sessionNo=${session.sessionNo || ''}&fromUserId=${userId || ''}&userName=${encodeURIComponent(userName)}`
  241. });
  242. } else {
  243. uni.showToast({ title: '创建会话失败', icon: 'none' });
  244. }
  245. } catch (err) {
  246. uni.hideLoading();
  247. console.error('创建会话失败:', err);
  248. uni.showToast({ title: '连接失败,请重试', icon: 'none' });
  249. }
  250. };
  251. </script>
  252. <style lang="scss" scoped>
  253. .container {
  254. min-height: 100vh;
  255. background-color: #F8F9FB;
  256. display: flex;
  257. flex-direction: column;
  258. }
  259. .tab-header {
  260. display: flex;
  261. background-color: #FFF;
  262. padding: 0 80rpx;
  263. border-bottom: 2rpx solid #F0F2F5;
  264. .tab-item {
  265. flex: 1;
  266. height: 100rpx;
  267. line-height: 100rpx;
  268. text-align: center;
  269. font-size: 30rpx;
  270. color: #666;
  271. position: relative;
  272. &.active {
  273. color: #1F6CFF;
  274. font-weight: bold;
  275. &::after {
  276. content: '';
  277. position: absolute;
  278. bottom: 0;
  279. left: 50%;
  280. transform: translateX(-50%);
  281. width: 40rpx;
  282. height: 6rpx;
  283. background-color: #1F6CFF;
  284. border-radius: 3rpx;
  285. }
  286. }
  287. }
  288. }
  289. .content-scroll {
  290. flex: 1;
  291. .list-wrap {
  292. padding: 30rpx 40rpx;
  293. display: flex;
  294. flex-direction: column;
  295. gap: 30rpx;
  296. }
  297. }
  298. /* 岗位卡片 - 同步 jobs.vue 样式 */
  299. .job-card {
  300. background: #FFFFFF;
  301. border-radius: 24rpx;
  302. padding: 30rpx;
  303. position: relative;
  304. box-shadow: 0 4rpx 12rpx rgba(0,0,0,0.03);
  305. .job-header {
  306. display: flex;
  307. justify-content: space-between;
  308. align-items: center;
  309. margin-bottom: 20rpx;
  310. .job-title-box {
  311. display: flex;
  312. align-items: center;
  313. .job-title {
  314. font-size: 32rpx;
  315. font-weight: bold;
  316. color: #1A1A1A;
  317. margin-right: 16rpx;
  318. }
  319. .urge-tag {
  320. font-size: 20rpx;
  321. color: #FF3B30;
  322. border: 1rpx solid #FF3B30;
  323. padding: 2rpx 10rpx;
  324. border-radius: 12rpx;
  325. }
  326. }
  327. .job-salary {
  328. font-size: 32rpx;
  329. font-weight: bold;
  330. color: #1F6CFF;
  331. }
  332. }
  333. .tags-row {
  334. display: flex;
  335. flex-wrap: wrap;
  336. gap: 16rpx;
  337. margin-bottom: 24rpx;
  338. .tag {
  339. background: #F4F5F7;
  340. color: #666666;
  341. font-size: 22rpx;
  342. padding: 6rpx 16rpx;
  343. border-radius: 8rpx;
  344. }
  345. }
  346. .info-row {
  347. display: flex;
  348. align-items: center;
  349. margin-bottom: 12rpx;
  350. .info-icon {
  351. width: 26rpx;
  352. height: 26rpx;
  353. margin-right: 12rpx;
  354. opacity: 0.5;
  355. }
  356. .info-text {
  357. font-size: 24rpx;
  358. color: #888888;
  359. margin-right: 16rpx;
  360. }
  361. .danger-text {
  362. font-size: 24rpx;
  363. color: #FF3B30;
  364. }
  365. }
  366. .company-row {
  367. display: flex;
  368. justify-content: space-between;
  369. align-items: center;
  370. margin-top: 24rpx;
  371. padding-top: 24rpx;
  372. border-top: 1rpx dashed #EEEEEE;
  373. .company-info-wrap {
  374. display: flex;
  375. align-items: center;
  376. .company-logo {
  377. width: 80rpx;
  378. height: 80rpx;
  379. border-radius: 16rpx;
  380. margin-right: 20rpx;
  381. background-color: #f5f5f5;
  382. border: 1rpx solid #f0f0f0;
  383. }
  384. .company-text-col {
  385. display: flex;
  386. flex-direction: column;
  387. .company-name-box {
  388. display: flex;
  389. align-items: center;
  390. margin-bottom: 6rpx;
  391. .company-name {
  392. font-size: 28rpx;
  393. font-weight: 600;
  394. color: #1A1A1A;
  395. margin-right: 10rpx;
  396. }
  397. .verified-icon {
  398. width: 24rpx;
  399. height: 24rpx;
  400. }
  401. }
  402. .company-location {
  403. font-size: 24rpx;
  404. color: #888888;
  405. }
  406. }
  407. }
  408. .close-icon {
  409. width: 32rpx;
  410. height: 32rpx;
  411. opacity: 0.3;
  412. }
  413. }
  414. }
  415. /* 测评卡片 - 同步 assessment.vue 样式 */
  416. .assessment-card {
  417. background: #FFF; border-radius: 32rpx; padding: 24rpx; display: flex;
  418. box-shadow: 0 4rpx 24rpx rgba(0,0,0,0.03);
  419. position: relative;
  420. .card-left {
  421. width: 220rpx; height: 220rpx; flex-shrink: 0; margin-right: 24rpx;
  422. .cover-img { width: 100%; height: 100%; border-radius: 16rpx; }
  423. }
  424. .card-right {
  425. flex: 1; display: flex; flex-direction: column; justify-content: space-between;
  426. .top-line {
  427. display: flex; justify-content: space-between; align-items: center;
  428. .job-title { font-size: 34rpx; font-weight: bold; color: #1A1A1A; }
  429. .job-level-tag { font-size: 22rpx; color: #1F6CFF; background: rgba(31, 108, 255, 0.1); padding: 4rpx 12rpx; border-radius: 8rpx; }
  430. }
  431. .tag-row {
  432. display: flex; gap: 10rpx; margin: 12rpx 0;
  433. .tag-badge {
  434. font-size: 20rpx; color: #999; background: #F5F7FA; padding: 6rpx 14rpx; border-radius: 6rpx;
  435. &.type-tag { color: #1F6CFF; background: rgba(31, 108, 255, 0.08); }
  436. &.category-tag { color: #FF9500; background: rgba(255, 149, 0, 0.08); }
  437. }
  438. }
  439. .desc-text { font-size: 24rpx; color: #888; line-height: 1.4; margin-bottom: 16rpx; }
  440. .btn-wrap {
  441. display: flex; justify-content: flex-end;
  442. .consult-btn {
  443. margin: 0; background: #FFB700; color: #FFF; border-radius: 30rpx; height: 56rpx; line-height: 56rpx; padding: 0 36rpx; font-size: 26rpx; font-weight: bold;
  444. &::after { border:none; }
  445. }
  446. }
  447. }
  448. .collect-icon-wrap {
  449. position: absolute;
  450. top: 24rpx;
  451. right: 24rpx;
  452. width: 48rpx;
  453. height: 48rpx;
  454. display: flex;
  455. align-items: center;
  456. justify-content: center;
  457. background: rgba(255, 255, 255, 0.95);
  458. border-radius: 50%;
  459. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.1);
  460. z-index: 10;
  461. .collect-icon {
  462. width: 32rpx;
  463. height: 32rpx;
  464. }
  465. }
  466. }
  467. .text-ellipsis-2 {
  468. display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden;
  469. }
  470. .empty-status { padding-top: 200rpx; text-align: center; color: #CCC; font-size: 28rpx; }
  471. .no-more { text-align: center; color: #CCC; font-size: 24rpx; padding: 40rpx 0; }
  472. .card-anim {
  473. animation: slideUp 0.4s ease-out backwards;
  474. @for $i from 1 through 10 { &:nth-child(#{$i}) { animation-delay: #{$i * 0.08s}; } }
  475. }
  476. @keyframes slideUp {
  477. from { transform: translateY(20rpx); opacity: 0; }
  478. to { transform: translateY(0); opacity: 1; }
  479. }
  480. </style>