job-detail.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. <template>
  2. <view class="job-detail-container">
  3. <!-- 顶部信息区域 -->
  4. <view class="job-header">
  5. <view class="job-title">{{ jobDetail.title }}</view>
  6. <view class="job-salary">{{ jobDetail.salary }}</view>
  7. <view class="job-department">{{ jobDetail.department }}</view>
  8. <view class="job-requirements">
  9. <view class="requirement-item">
  10. <view class="dot"></view>
  11. <text>{{ formatLocation(jobDetail.location) }}</text>
  12. </view>
  13. <view class="requirement-item">
  14. <view class="time-icon"></view>
  15. <text>{{ jobDetail.experience }}</text>
  16. </view>
  17. </view>
  18. </view>
  19. <!-- 工作地点区域 -->
  20. <view class="section">
  21. <view class="section-title">工作地点</view>
  22. <view class="map-container">
  23. <image class="map-image" src="https://data.qicai321.com/minlong/6be6ec51-d4a2-4f2b-9bfc-23e046a3db37.png" mode="aspectFill"></image>
  24. <!-- <view class="map-time">预计14:32到达</view> -->
  25. <view class="refresh-icon">
  26. <text class="iconfont icon-refresh"></text>
  27. </view>
  28. </view>
  29. </view>
  30. <!-- 福利待遇区域 -->
  31. <!-- <view class="section">
  32. <view class="section-title">福利待遇</view>
  33. <view class="benefits-list">
  34. <view class="benefit-tag" >暂无数据</view>
  35. </view>
  36. </view> -->
  37. <!-- 岗位介绍区域 -->
  38. <view class="section">
  39. <view class="section-title">岗位介绍</view>
  40. <view class="job-description">
  41. <!-- <view class="description-subtitle">{{ jobDetail.description[0].subtitle }}</view> -->
  42. <view class="description-content">
  43. <view class="description-item" v-for="(item, index) in jobDetail.description[0].items" :key="index">
  44. <view class="blue-dot"></view>
  45. <template v-if="hasHtmlTags(item)">
  46. <view class="description-text" v-html="item"></view>
  47. </template>
  48. <template v-else>
  49. <text style="color: #333;">{{ item }}</text>
  50. </template>
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. <!-- 右侧开始面试按钮 -->
  56. <view class="interview-button" @click="startInterview">
  57. <text>开始面试</text>
  58. </view>
  59. </view>
  60. </template>
  61. <script>
  62. import { apiBaseUrl } from '@/common/config.js';
  63. import { applyJob } from '@/api/user.js';
  64. export default {
  65. data() {
  66. return {
  67. jobDetail: {
  68. title: '',
  69. salary: '',
  70. department: '',
  71. location: '',
  72. experience: '',
  73. benefits: [],
  74. description: [
  75. {
  76. subtitle: '岗位要求',
  77. items: []
  78. }
  79. ]
  80. },
  81. selectedJobId: null,
  82. jobId: null
  83. }
  84. },
  85. onLoad(options) {
  86. this.jobId = options.id;
  87. this.getJobDetail(options.id);
  88. // 尝试从本地存储获取职位详情
  89. try {
  90. const jobDetailStr = uni.getStorageSync('currentJobDetail');
  91. if (jobDetailStr) {
  92. const jobData = JSON.parse(jobDetailStr);
  93. // 这里可以根据实际数据结构进行处理
  94. // 如果后端返回的数据结构与页面需要的不一致,可以在这里进行转换
  95. this.jobDetail = {
  96. ...this.jobDetail,
  97. title: jobData.title || this.jobDetail.title,
  98. salary: jobData.salary || this.jobDetail.salary,
  99. department: jobData.department || this.jobDetail.department,
  100. location: jobData.location || this.jobDetail.location,
  101. experience: jobData.experience || this.jobDetail.experience,
  102. benefits: jobData.benefits || this.jobDetail.benefits,
  103. description: jobData.description || this.jobDetail.description
  104. };
  105. }
  106. } catch (e) {
  107. console.error('获取职位详情失败:', e);
  108. }
  109. },
  110. methods: {
  111. async getJobDetail(jobId) {
  112. try {
  113. const { data } = await uni.request({
  114. url: `${apiBaseUrl}/api/mini/job/detail?id=${jobId}&tenant_id=1`,
  115. method: 'GET',
  116. });
  117. if (data.code === 2000) {
  118. // 处理富文本description
  119. let descriptionItems = [];
  120. if (data.data.description) {
  121. // 使用正则表达式提取<li>标签中的文本内容
  122. const liRegex = /<li[^>]*>(.*?)<\/li>/g;
  123. const stripTagsRegex = /<[^>]*>/g;
  124. let match;
  125. while ((match = liRegex.exec(data.data.description)) !== null) {
  126. // 移除剩余的HTML标签,并清理空白字符
  127. const text = match[1]
  128. .replace(stripTagsRegex, '')
  129. .replace(/&nbsp;/g, ' ')
  130. .trim();
  131. if (text) {
  132. descriptionItems.push(text);
  133. }
  134. }
  135. }
  136. // 如果requirements存在,添加到描述项前面
  137. if (data.data.requirements) {
  138. descriptionItems.unshift(data.data.requirements);
  139. }
  140. this.jobDetail = {
  141. id: data.data.id,
  142. title: data.data.title || '',
  143. salary: data.data.salary_range ? `${data.data.salary_range}/月` : '',
  144. department: `${data.data.department || ''} ${data.data.job_type === 1 ? '全职' : '兼职'}`,
  145. location: data.data.location || '',
  146. experience: data.data.work_experience_required || '不限',
  147. benefits: data.data.competency_tags || ['五险一金', '带薪年假', '定期体检'],
  148. description: [
  149. {
  150. subtitle: '岗位要求',
  151. items: descriptionItems
  152. }
  153. ]
  154. };
  155. } else {
  156. uni.showToast({
  157. title: '获取职位详情失败',
  158. icon: 'none'
  159. });
  160. }
  161. } catch (e) {
  162. console.error('获取职位详情失败:', e);
  163. uni.showToast({
  164. title: '获取职位详情失败',
  165. icon: 'none'
  166. });
  167. }
  168. },
  169. checkLogin() {
  170. const userInfo = uni.getStorageSync('userInfo');
  171. if (!userInfo) {
  172. uni.showToast({
  173. title: '请先登录',
  174. icon: 'none'
  175. });
  176. return false;
  177. }
  178. return true;
  179. },
  180. // 获取当前职位配置
  181. getConfig(){
  182. uni.request({
  183. url: `${apiBaseUrl}/api/job/config/position/${this.selectedJobId}`,
  184. method: 'GET',
  185. data: {
  186. openid: JSON.parse(uni.getStorageSync('userInfo')).openid
  187. },
  188. header: {
  189. 'content-type': 'application/x-www-form-urlencoded'
  190. },
  191. success: (res) => {
  192. // 身份验证成功后,继续提交用户信息
  193. console.log(res);
  194. if (res.statusCode === 200) {
  195. if (res.data.code === 2000) {
  196. uni.setStorageSync('configData', JSON.stringify(res.data.data))
  197. uni.navigateTo({
  198. url: '/pages/Personal/Personal',
  199. fail: (err) => {
  200. console.error('页面跳转失败:', err);
  201. uni.showToast({
  202. title: '页面跳转失败',
  203. icon: 'none'
  204. });
  205. }
  206. });
  207. } else {
  208. }
  209. } else {
  210. uni.hideLoading();
  211. }
  212. },
  213. fail: (err) => {
  214. uni.hideLoading();
  215. uni.showToast({
  216. title: '网络错误,请稍后重试',
  217. icon: 'none'
  218. });
  219. }
  220. });
  221. },
  222. async startInterview() {
  223. if (!this.checkLogin()) {
  224. return;
  225. }
  226. try {
  227. // 保存所选职位信息
  228. uni.setStorageSync('selectedJob', JSON.stringify(this.jobDetail));
  229. const userInfo = JSON.parse(uni.getStorageSync('userInfo'));
  230. const response = await applyJob({
  231. job_id: this.jobId,
  232. tenant_id: 1,
  233. openid: userInfo.openid
  234. });
  235. if (response && response.id) {
  236. // 保存应用ID到本地
  237. uni.setStorageSync('appId', response.id);
  238. // 更新userInfo对象
  239. try {
  240. userInfo.appId = response.id;
  241. uni.setStorageSync('userInfo', JSON.stringify(userInfo));
  242. } catch (e) {
  243. console.error('更新用户信息失败:', e);
  244. }
  245. this.getConfig()
  246. // 导航到摄像头页面
  247. uni.navigateTo({
  248. url: '/pages/Personal/Personal',
  249. fail: (err) => {
  250. console.error('页面跳转失败:', err);
  251. uni.showToast({
  252. title: '页面跳转失败',
  253. icon: 'none'
  254. });
  255. }
  256. });
  257. }
  258. } catch (err) {
  259. console.error('申请职位失败:', err);
  260. uni.showToast({
  261. title: '申请职位失败,请重试',
  262. icon: 'none'
  263. });
  264. }
  265. },
  266. hasHtmlTags(text) {
  267. // 检查文本是否包含HTML标签
  268. const htmlRegex = /<[^>]*>/;
  269. return htmlRegex.test(text);
  270. },
  271. formatLocation(location) {
  272. if (!location) return '';
  273. // 处理字符串形式的数组
  274. if (typeof location === 'string' && location.startsWith('[')) {
  275. try {
  276. const locationArray = JSON.parse(location.replace(/'/g, '"'));
  277. return locationArray.join(' ');
  278. } catch (e) {
  279. console.error('解析location失败:', e);
  280. return location;
  281. }
  282. }
  283. // 处理数组格式
  284. if (Array.isArray(location)) {
  285. return location.join(' ');
  286. }
  287. // 处理对象格式
  288. if (typeof location === 'object' && location !== null) {
  289. const { province, city, district } = location;
  290. if (province && city) {
  291. return province + ' ' + city + (district ? ' ' + district : '');
  292. }
  293. }
  294. // 处理普通字符串格式
  295. return location;
  296. }
  297. }
  298. }
  299. </script>
  300. <style lang="scss" scoped>
  301. .job-detail-container {
  302. padding: 20rpx;
  303. position: relative;
  304. background-color: #f5f5f5;
  305. min-height: 100vh;
  306. }
  307. .job-header {
  308. padding: 20rpx 0;
  309. }
  310. .job-title {
  311. font-size: 36rpx;
  312. font-weight: bold;
  313. color: #333;
  314. margin-bottom: 10rpx;
  315. }
  316. .job-salary {
  317. font-size: 32rpx;
  318. color: #ff6b00;
  319. margin-bottom: 10rpx;
  320. }
  321. .job-department {
  322. font-size: 28rpx;
  323. color: #666;
  324. margin-bottom: 20rpx;
  325. }
  326. .job-requirements {
  327. display: flex;
  328. align-items: center;
  329. margin-bottom: 20rpx;
  330. }
  331. .requirement-item {
  332. display: flex;
  333. align-items: center;
  334. margin-right: 30rpx;
  335. font-size: 26rpx;
  336. color: #666;
  337. }
  338. .dot {
  339. width: 16rpx;
  340. height: 16rpx;
  341. border-radius: 50%;
  342. background-color: #0052d9;
  343. margin-right: 10rpx;
  344. }
  345. .time-icon {
  346. width: 26rpx;
  347. height: 26rpx;
  348. background-color: #999;
  349. border-radius: 50%;
  350. margin-right: 10rpx;
  351. display: flex;
  352. justify-content: center;
  353. align-items: center;
  354. font-size: 18rpx;
  355. color: #fff;
  356. }
  357. .section {
  358. margin-bottom: 30rpx;
  359. background-color: #fff;
  360. border-radius: 16rpx;
  361. padding: 20rpx;
  362. }
  363. .section-title {
  364. font-size: 32rpx;
  365. font-weight: bold;
  366. color: #333;
  367. margin-bottom: 20rpx;
  368. }
  369. .map-container {
  370. position: relative;
  371. border-radius: 16rpx;
  372. overflow: hidden;
  373. }
  374. .map-image {
  375. width: 100%;
  376. height: 300rpx;
  377. border-radius: 16rpx;
  378. }
  379. .map-time {
  380. position: absolute;
  381. left: 20rpx;
  382. bottom: 20rpx;
  383. background-color: rgba(0, 0, 0, 0.6);
  384. color: #fff;
  385. font-size: 24rpx;
  386. padding: 6rpx 12rpx;
  387. border-radius: 6rpx;
  388. }
  389. .refresh-icon {
  390. position: absolute;
  391. right: 20rpx;
  392. bottom: 20rpx;
  393. width: 60rpx;
  394. height: 60rpx;
  395. background-color: #fff;
  396. border-radius: 50%;
  397. display: flex;
  398. justify-content: center;
  399. align-items: center;
  400. }
  401. .benefits-list {
  402. display: flex;
  403. flex-wrap: wrap;
  404. }
  405. .benefit-tag {
  406. background-color: #f5f5f5;
  407. color: #666;
  408. font-size: 26rpx;
  409. padding: 10rpx 20rpx;
  410. border-radius: 6rpx;
  411. margin-right: 20rpx;
  412. margin-bottom: 20rpx;
  413. }
  414. .description-subtitle {
  415. font-size: 28rpx;
  416. font-weight: bold;
  417. color: #333;
  418. margin-bottom: 20rpx;
  419. }
  420. .description-content {
  421. padding-left: 10rpx;
  422. }
  423. .description-item {
  424. display: flex;
  425. margin-bottom: 20rpx;
  426. /* * {
  427. background-color: #fff !important;
  428. color: #333 !important;
  429. }
  430. strong {
  431. font-weight: bold;
  432. } */
  433. }
  434. .blue-dot {
  435. min-width: 16rpx;
  436. height: 16rpx;
  437. border-radius: 50%;
  438. background-color: #0039b3 !important;
  439. margin-right: 10rpx;
  440. margin-top: 12rpx;
  441. }
  442. .description-item text {
  443. font-size: 26rpx;
  444. color: #666;
  445. line-height: 1.6;
  446. }
  447. .interview-button {
  448. position: fixed;
  449. right: 0;
  450. top: 50%;
  451. transform: translateY(-50%);
  452. background-color: #0039b3;
  453. color: #fff;
  454. writing-mode: vertical-lr;
  455. padding: 30rpx 20rpx;
  456. font-size: 32rpx;
  457. border-top-left-radius: 16rpx;
  458. border-bottom-left-radius: 16rpx;
  459. }
  460. .description-text {
  461. font-size: 26rpx;
  462. color: #333;
  463. line-height: 1.6;
  464. flex: 1;
  465. :deep(p) {
  466. margin: 0;
  467. }
  468. :deep(a) {
  469. color: #0039b3;
  470. text-decoration: none;
  471. }
  472. :deep(strong) {
  473. font-weight: bold;
  474. }
  475. }
  476. </style>