job-detail.vue 16 KB

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