123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322 |
- "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: [],
- description: [
- {
- subtitle: "岗位要求",
- items: []
- }
- ]
- },
- selectedJobId: null,
- jobId: null,
- mapInfo: {
- latitude: 0,
- longitude: 0,
- markers: []
- }
- };
- },
- onLoad(options) {
- this.jobId = options.id;
- this.getJobDetail(options.id);
- 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
- };
- }
- } catch (e) {
- console.error("获取职位详情失败:", e);
- }
- },
- methods: {
- async getJobDetail(jobId) {
- try {
- const { data } = await common_vendor.index.request({
- url: `${common_config.apiBaseUrl}/api/mini/job/detail?id=${jobId}&tenant_id=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.department || ""} ${data.data.job_type === 1 ? "全职" : "兼职"}`,
- location: data.data.location || "",
- experience: data.data.work_experience_required || "不限",
- benefits: data.data.competency_tags || ["五险一金", "带薪年假", "定期体检"],
- description: [
- {
- subtitle: "岗位要求",
- items: descriptionItems
- }
- ]
- };
- this.updateMapLocation(data.data.location);
- } 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() {
- common_vendor.index.request({
- url: `${common_config.apiBaseUrl}/api/job/config/position/${this.selectedJobId}`,
- 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));
- common_vendor.index.navigateTo({
- url: "/pages/Personal/Personal",
- fail: (err) => {
- console.error("页面跳转失败:", err);
- common_vendor.index.showToast({
- title: "页面跳转失败",
- icon: "none"
- });
- }
- });
- }
- } 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: 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();
- common_vendor.index.navigateTo({
- url: "/pages/Personal/Personal",
- fail: (err) => {
- console.error("页面跳转失败:", err);
- common_vendor.index.showToast({
- title: "页面跳转失败",
- icon: "none"
- });
- }
- });
- }
- } 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(" ");
- } catch (e) {
- console.error("解析location失败:", e);
- return location;
- }
- }
- if (Array.isArray(location)) {
- return location.join(" ");
- }
- if (typeof location === "object" && location !== null) {
- const { province, city, district } = location;
- if (province && city) {
- return province + " " + city + (district ? " " + district : "");
- }
- }
- return location;
- },
- // 更新地图位置信息
- async updateMapLocation(location) {
- try {
- let addressStr = "";
- if (typeof location === "string" && location.startsWith("[")) {
- try {
- const locationArray = JSON.parse(location.replace(/'/g, '"'));
- addressStr = locationArray.join("");
- } catch (e) {
- addressStr = location;
- }
- } else if (Array.isArray(location)) {
- addressStr = location.join("");
- } else if (typeof location === "object" && location !== null) {
- const { province, city, district } = location;
- addressStr = `${province || ""}${city || ""}${district || ""}`;
- } else {
- addressStr = location;
- }
- common_vendor.index.request({
- url: `https://apis.map.qq.com/ws/geocoder/v1/?address=${encodeURIComponent(addressStr)}&key=WJLBZ-SMQYZ-3RNX5-7J4LI-XTZD6-7IBZR`,
- // 需要替换为实际的地图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.jobDetail.title,
- 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);
|