| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446 |
- "use strict";
- const common_vendor = require("../../common/vendor.js");
- const common_config = require("../../common/config.js");
- const api_user = require("../../api/user.js");
- const _sfc_main = {
- data() {
- return {
- jobDetail: {
- title: "",
- salary: "",
- department: "",
- location: "",
- experience: "",
- benefits: [],
- detailed_address: "",
- description: [
- {
- subtitle: "岗位要求",
- items: []
- }
- ]
- },
- selectedJobId: null,
- jobId: null,
- mapInfo: {
- latitude: 0,
- longitude: 0,
- markers: []
- },
- tenant_id: ""
- // 租户ID
- };
- },
- onLoad(options) {
- this.jobId = options.id;
- this.getJobDetail(options.id);
- this.getTenantId();
- try {
- const jobDetailStr = common_vendor.index.getStorageSync("currentJobDetail");
- if (jobDetailStr) {
- const jobData = JSON.parse(jobDetailStr);
- this.jobDetail = {
- ...this.jobDetail,
- title: jobData.title || this.jobDetail.title,
- salary: jobData.salary || this.jobDetail.salary,
- department: jobData.department || this.jobDetail.department,
- location: jobData.location || this.jobDetail.location,
- experience: jobData.experience || this.jobDetail.experience,
- benefits: jobData.benefits || this.jobDetail.benefits,
- description: jobData.description || this.jobDetail.description,
- detailed_address: jobData.detailed_address || this.jobDetail.detailed_address
- };
- }
- } catch (e) {
- console.error("获取职位详情失败:", e);
- }
- },
- methods: {
- // 获取本地存储的tenant_id
- getTenantId() {
- const tenantId = common_vendor.index.getStorageSync("tenant_id");
- if (tenantId) {
- this.tenant_id = tenantId;
- return tenantId;
- }
- return null;
- },
- async getJobDetail(jobId) {
- try {
- const { data } = await common_vendor.index.request({
- url: `${common_config.apiBaseUrl}/api/mini/job/detail?id=${jobId}&tenant_id=${this.tenant_id || (() => {
- try {
- const s = common_vendor.index.getStorageSync("userInfo");
- return s ? JSON.parse(s).tenant_id || 1 : 1;
- } catch {
- return 1;
- }
- })()}`,
- method: "GET"
- });
- if (data.code === 2e3) {
- let descriptionItems = [];
- if (data.data.description) {
- const liRegex = /<li[^>]*>(.*?)<\/li>/g;
- const stripTagsRegex = /<[^>]*>/g;
- let match;
- while ((match = liRegex.exec(data.data.description)) !== null) {
- const text = match[1].replace(stripTagsRegex, "").replace(/ /g, " ").trim();
- if (text) {
- descriptionItems.push(text);
- }
- }
- }
- if (data.data.requirements) {
- descriptionItems.unshift(data.data.requirements);
- }
- this.jobDetail = {
- id: data.data.id,
- title: data.data.title || "",
- salary: data.data.salary_range ? `${data.data.salary_range}/月` : "",
- department: data.data.job_type_name,
- //`${data.data.department || ''} ${data.data.job_type === 1 ? '全职' : '兼职'}`,
- location: data.data.location || "",
- experience: data.data.work_experience_required || "不限",
- benefits: data.data.competency_tags || ["五险一金", "带薪年假", "定期体检"],
- detailed_address: data.data.detailed_address || "",
- description: [
- {
- subtitle: "岗位要求",
- items: descriptionItems
- }
- ]
- };
- this.updateMapLocation(data.data.location, data.data.detailed_address);
- } else {
- common_vendor.index.showToast({
- title: "获取职位详情失败",
- icon: "none"
- });
- }
- } catch (e) {
- console.error("获取职位详情失败:", e);
- common_vendor.index.showToast({
- title: "获取职位详情失败",
- icon: "none"
- });
- }
- },
- checkLogin() {
- const userInfo = common_vendor.index.getStorageSync("userInfo");
- if (!userInfo) {
- common_vendor.index.showToast({
- title: "请先登录",
- icon: "none"
- });
- return false;
- }
- return true;
- },
- // 获取当前职位配置
- /* getConfig(selectedJobId){
- uni.request({
- url: `${apiBaseUrl}/api/job/config/position/${this.jobId}`,
- method: 'GET',
- data: {
- openid: JSON.parse(uni.getStorageSync('userInfo')).openid
- },
- header: {
- 'content-type': 'application/x-www-form-urlencoded'
- },
- success: (res) => {
- // 身份验证成功后,继续提交用户信息
- console.log(res);
- if (res.statusCode === 200) {
- if (res.data.code === 2000) {
- uni.setStorageSync('configData', JSON.stringify(res.data.data))
- uni.navigateTo({
- url: '/pages/Personal/Personal',
- fail: (err) => {
- console.error('页面跳转失败:', err);
- uni.showToast({
- title: '页面跳转失败',
- icon: 'none'
- });
- }
- });
- } else {
-
- }
- } else {
- uni.hideLoading();
-
- }
- },
- fail: (err) => {
- uni.hideLoading();
- uni.showToast({
- title: '网络错误,请稍后重试',
- icon: 'none'
- });
- }
- });
- }, */
- // 处理用户信息获取和页面跳转逻辑
- handleUserInfoAndNavigation() {
- const openid = JSON.parse(common_vendor.index.getStorageSync("userInfo")).openid;
- common_vendor.index.request({
- url: `${common_config.apiBaseUrl}/api/wechat/user/get_full_info?tenant_id=${this.tenant_id || JSON.parse(common_vendor.index.getStorageSync("userInfo")).tenant_id || 1}&openid=${openid}`,
- method: "GET",
- success: (infoRes) => {
- if (infoRes.statusCode === 200 && infoRes.data && infoRes.data.data && infoRes.data.data.profile) {
- const resumeUrl = infoRes.data.data.profile.resume_url || "";
- if (!resumeUrl) {
- common_vendor.index.navigateTo({
- url: "/pages/uploadResume/uploadResume",
- // 假设跳转到上传简历页面
- fail: (err) => {
- console.error("页面跳转失败:", err);
- common_vendor.index.showToast({
- title: "页面跳转失败",
- icon: "none"
- });
- }
- });
- } else {
- common_vendor.index.navigateTo({
- url: "/pages/Personal/Personal",
- fail: (err) => {
- console.error("页面跳转失败:", err);
- common_vendor.index.showToast({
- title: "页面跳转失败",
- icon: "none"
- });
- }
- });
- }
- } else {
- common_vendor.index.navigateTo({
- url: "/pages/Personal/Personal",
- fail: (err) => {
- console.error("页面跳转失败:", err);
- common_vendor.index.showToast({
- title: "页面跳转失败",
- icon: "none"
- });
- }
- });
- }
- },
- fail: (err) => {
- console.error("获取用户信息失败:", err);
- common_vendor.index.navigateTo({
- url: "/pages/Personal/Personal",
- fail: (err2) => {
- console.error("页面跳转失败:", err2);
- common_vendor.index.showToast({
- title: "页面跳转失败",
- icon: "none"
- });
- }
- });
- }
- });
- },
- // 获取当前职位配置
- getConfig(selectedJobId) {
- common_vendor.index.request({
- url: `${common_config.apiBaseUrl}/api/job/config/position/${this.jobId}`,
- method: "GET",
- data: {
- openid: JSON.parse(common_vendor.index.getStorageSync("userInfo")).openid
- },
- header: {
- "content-type": "application/x-www-form-urlencoded"
- },
- success: (res) => {
- console.log(res);
- if (res.statusCode === 200) {
- if (res.data.code === 2e3) {
- common_vendor.index.setStorageSync("configData", JSON.stringify(res.data.data));
- const configData = res.data.data;
- const enableVideoPresentation = (configData == null ? void 0 : configData.enable_video_presentation) || false;
- if (enableVideoPresentation) {
- const videoUrl = (configData == null ? void 0 : configData.video_presentation_url) || "";
- const nextPage = "/pages/Personal/Personal";
- common_vendor.index.navigateTo({
- url: `/pages/video-briefing/video-briefing?src=${encodeURIComponent(videoUrl)}&next=${encodeURIComponent(nextPage)}`,
- fail: (err) => {
- console.error("跳转到视频宣讲页面失败:", err);
- this.handleUserInfoAndNavigation();
- }
- });
- } else {
- this.handleUserInfoAndNavigation();
- }
- }
- } else {
- common_vendor.index.hideLoading();
- }
- },
- fail: (err) => {
- common_vendor.index.hideLoading();
- common_vendor.index.showToast({
- title: "网络错误,请稍后重试",
- icon: "none"
- });
- }
- });
- },
- async startInterview() {
- if (!this.checkLogin()) {
- return;
- }
- try {
- common_vendor.index.setStorageSync("selectedJob", JSON.stringify(this.jobDetail));
- const userInfo = JSON.parse(common_vendor.index.getStorageSync("userInfo"));
- const response = await api_user.applyJob({
- job_id: this.jobId,
- tenant_id: this.tenant_id || JSON.parse(common_vendor.index.getStorageSync("userInfo")).tenant_id || 1,
- openid: userInfo.openid
- });
- if (response && response.id) {
- common_vendor.index.setStorageSync("appId", response.id);
- try {
- userInfo.appId = response.id;
- common_vendor.index.setStorageSync("userInfo", JSON.stringify(userInfo));
- } catch (e) {
- console.error("更新用户信息失败:", e);
- }
- this.getConfig(userInfo.appId);
- }
- } catch (err) {
- console.error("申请职位失败:", err);
- common_vendor.index.showToast({
- title: "申请职位失败,请重试",
- icon: "none"
- });
- }
- },
- hasHtmlTags(text) {
- const htmlRegex = /<[^>]*>/;
- return htmlRegex.test(text);
- },
- formatLocation(location) {
- if (!location)
- return "";
- if (typeof location === "string" && location.startsWith("[")) {
- try {
- const locationArray = JSON.parse(location.replace(/'/g, '"'));
- return locationArray.join(" ") + "" + this.jobDetail.detailed_address || JSON.parse(common_vendor.index.getStorageSync("currentJobDetail")).detailed_address;
- } catch (e) {
- console.error("解析location失败:", e);
- return location;
- }
- }
- if (Array.isArray(location)) {
- return location.join(" ") + "" + this.jobDetail.detailed_address || JSON.parse(common_vendor.index.getStorageSync("currentJobDetail")).detailed_address;
- }
- if (typeof location === "object" && location !== null) {
- const { province, city, district } = location;
- if (province && city) {
- return province + " " + city + (district ? " " + district : "");
- }
- }
- return location + "" + this.jobDetail.detailed_address || JSON.parse(common_vendor.index.getStorageSync("currentJobDetail")).detailed_address;
- },
- // 更新地图位置信息
- async updateMapLocation(location, address) {
- try {
- let addressStr = "";
- if (typeof location === "string" && location.startsWith("[")) {
- try {
- const locationArray = JSON.parse(location.replace(/'/g, '"'));
- addressStr = locationArray.join("") + address;
- } catch (e) {
- addressStr = location + address;
- }
- } else if (Array.isArray(location)) {
- addressStr = location.join("") + address;
- } else if (typeof location === "object" && location !== null) {
- const { province, city, district } = location;
- addressStr = `${province || ""}${city || ""}${district || ""}${address}`;
- } else {
- addressStr = location + address;
- }
- console.log(addressStr, address);
- common_vendor.index.request({
- url: `https://apis.map.qq.com/ws/geocoder/v1/?address=${encodeURIComponent(addressStr)}&key=ZS4BZ-NKAA7-4VLXR-PHVI4-HAGPH-Z4FJ3`,
- // 需要替换为实际的地图Key
- success: (res) => {
- if (res.data.status === 0) {
- const { lat, lng } = res.data.result.location;
- this.mapInfo.latitude = lat;
- this.mapInfo.longitude = lng;
- this.mapInfo.markers = [{
- id: 1,
- latitude: lat,
- longitude: lng,
- title: addressStr
- }];
- } else {
- console.error("地址解析失败:", res);
- }
- },
- fail: (err) => {
- console.error("地址解析请求失败:", err);
- }
- });
- } catch (error) {
- console.error("更新地图位置失败:", error);
- }
- },
- openLocation() {
- if (this.mapInfo.latitude && this.mapInfo.longitude) {
- common_vendor.index.openLocation({
- latitude: this.mapInfo.latitude,
- longitude: this.mapInfo.longitude,
- name: this.formatLocation(this.jobDetail.location),
- // address: this.formatLocation(this.jobDetail.location),
- success: function() {
- console.log("导航打开成功");
- },
- fail: function(err) {
- console.error("导航打开失败:", err);
- common_vendor.index.showToast({
- title: "导航打开失败",
- icon: "none"
- });
- }
- });
- } else {
- common_vendor.index.showToast({
- title: "暂无位置信息",
- icon: "none"
- });
- }
- }
- }
- };
- function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
- return {
- a: common_vendor.t($data.jobDetail.title),
- b: common_vendor.t($data.jobDetail.salary),
- c: common_vendor.t($data.jobDetail.department),
- d: common_vendor.t($options.formatLocation($data.jobDetail.location)),
- e: common_vendor.t($data.jobDetail.experience),
- f: $data.mapInfo.latitude,
- g: $data.mapInfo.longitude,
- h: $data.mapInfo.markers,
- i: common_vendor.o((...args) => $options.openLocation && $options.openLocation(...args)),
- j: common_vendor.f($data.jobDetail.description[0].items, (item, index, i0) => {
- return common_vendor.e({
- a: $options.hasHtmlTags(item)
- }, $options.hasHtmlTags(item) ? {
- b: item
- } : {
- c: common_vendor.t(item)
- }, {
- d: index
- });
- }),
- k: common_vendor.o((...args) => $options.startInterview && $options.startInterview(...args))
- };
- }
- const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-2bde8e2a"]]);
- wx.createPage(MiniProgramPage);
|