job-detail.vue 16 KB

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