job-detail.vue 15 KB

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