123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- "use strict";
- const common_vendor = require("../../common/vendor.js");
- const common_config = require("../../common/config.js");
- const _sfc_main = {
- data() {
- return {
- fileType: ["pdf", "doc", "docx"],
- maxSize: 30 * 1024 * 1024,
- // 30MB in bytes
- uploadedFile: null
- };
- },
- methods: {
- // 调用简历解析接口
- /* async parseResume(fileUrl) {
- try {
- const userInfo = JSON.parse(uni.getStorageSync('userInfo') || '{}');
- const userId = userInfo.id;
- const openid = userInfo.openid;
- const tenant_id = userInfo.tenant_id;
-
- if (!userId) {
- uni.showToast({
- title: '用户信息不完整,请重新登录',
- icon: 'none'
- });
- return false;
- }
-
- const response = await uni.request({
- url: `${apiBaseUrl}/api/system/resume-parsing-tasks/upload_resume/`,
- method: 'POST',
- data: {
- openid: openid,
- tenant_id: tenant_id,
- user_id: userId,
- file: fileUrl,
- description: '候选人简历'
- },
- header: {
- 'content-type': 'application/json'
- }
- });
-
- if (response.statusCode === 200 && response.data.code === 2000) {
- return true;
- } else {
- throw new Error(response.data.msg || '简历解析失败');
- }
- } catch (error) {
- console.error('简历解析失败:', error);
- uni.showToast({
- title: error.message || '简历解析失败',
- icon: 'none'
- });
- return false;
- }
- }, */
- clearFile() {
- common_vendor.index.showModal({
- title: "提示",
- content: "确定要删除已上传的文件吗?",
- success: (res) => {
- if (res.confirm) {
- this.uploadedFile = null;
- common_vendor.index.showToast({
- title: "文件已删除",
- icon: "success"
- });
- }
- }
- });
- },
- formatFileSize(size) {
- if (size < 1024) {
- return size + "B";
- } else if (size < 1024 * 1024) {
- return (size / 1024).toFixed(2) + "KB";
- } else {
- return (size / (1024 * 1024)).toFixed(2) + "MB";
- }
- },
- chooseFile() {
- if (this.uploadedFile) {
- common_vendor.index.showToast({
- title: "请先删除已上传的文件",
- icon: "none"
- });
- return;
- }
- common_vendor.index.chooseMessageFile({
- count: 1,
- type: "file",
- extension: this.fileType,
- success: (res) => {
- if (res.tempFiles[0].size > this.maxSize) {
- common_vendor.index.showToast({
- title: "文件大小不能超过30MB",
- icon: "none"
- });
- return;
- }
- this.uploadFile(res.tempFiles[0]);
- }
- });
- },
- async uploadFile(file) {
- try {
- common_vendor.index.showLoading({
- title: "上传中..."
- });
- const userInfo = JSON.parse(common_vendor.index.getStorageSync("userInfo") || "{}");
- console.log(userInfo);
- const openid = userInfo.openid || "";
- const tenant_id = userInfo.tenant_id || 1;
- const userId = userInfo.id;
- console.log(openid, tenant_id);
- if (!openid || !tenant_id || !userId) {
- common_vendor.index.hideLoading();
- common_vendor.index.showToast({
- title: "用户信息不完整,请重新登录",
- icon: "none"
- });
- return;
- }
- common_vendor.index.uploadFile({
- url: `${common_config.apiBaseUrl}/api/system/resume-parsing-tasks/upload_resume/`,
- filePath: file.path,
- name: "file",
- formData: {
- openid,
- tenant_id,
- user_id: userId,
- description: "候选人简历"
- },
- success: (uploadRes) => {
- try {
- const res = JSON.parse(uploadRes.data);
- console.log(res);
- if (res.code === 2e3) {
- this.uploadedFile = {
- name: file.name || "未命名文件",
- size: file.size,
- uploadTime: (/* @__PURE__ */ new Date()).toLocaleString(),
- url: res.data.url || ""
- };
- common_vendor.index.showToast({
- title: "上传成功",
- icon: "success",
- duration: 2e3
- });
- let seconds = 30;
- common_vendor.index.showLoading({
- title: `正在处理中,请稍候...(${seconds}秒)`,
- mask: true
- });
- const timer = setInterval(() => {
- seconds--;
- if (seconds > 0) {
- common_vendor.index.showLoading({
- title: `正在处理中,请稍候...(${seconds}秒)`,
- mask: true
- });
- } else {
- clearInterval(timer);
- common_vendor.index.hideLoading();
- common_vendor.index.showToast({
- title: "处理完成",
- icon: "success"
- });
- }
- }, 1e3);
- } else {
- common_vendor.index.showToast({
- title: res.msg || "上传失败",
- icon: "none"
- });
- }
- } catch (error) {
- common_vendor.index.showToast({
- title: "上传失败",
- icon: "none"
- });
- }
- },
- fail: (err) => {
- console.error("上传失败:", err);
- common_vendor.index.showToast({
- title: "网络错误,请重试",
- icon: "none"
- });
- },
- complete: () => {
- if (!this.uploadedFile) {
- common_vendor.index.hideLoading();
- }
- }
- });
- } catch (error) {
- common_vendor.index.hideLoading();
- common_vendor.index.showToast({
- title: "系统错误,请重试",
- icon: "none"
- });
- }
- }
- }
- };
- function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
- return common_vendor.e({
- a: common_vendor.t($data.uploadedFile ? "已上传文件" : "选择并上传文件"),
- b: common_vendor.o((...args) => $options.chooseFile && $options.chooseFile(...args)),
- c: !!$data.uploadedFile,
- d: $data.uploadedFile
- }, $data.uploadedFile ? {
- e: common_vendor.o((...args) => $options.clearFile && $options.clearFile(...args)),
- f: common_vendor.t($data.uploadedFile.name),
- g: common_vendor.t($options.formatFileSize($data.uploadedFile.size)),
- h: common_vendor.t($data.uploadedFile.uploadTime)
- } : {});
- }
- const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
- wx.createPage(MiniProgramPage);
|