job-detail.vue 14 KB

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