uploadResume.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const common_config = require("../../common/config.js");
  4. const _sfc_main = {
  5. data() {
  6. return {
  7. fileType: ["pdf", "doc", "docx"],
  8. maxSize: 30 * 1024 * 1024,
  9. // 30MB in bytes
  10. uploadedFile: null
  11. };
  12. },
  13. methods: {
  14. // 调用简历解析接口
  15. /* async parseResume(fileUrl) {
  16. try {
  17. const userInfo = JSON.parse(uni.getStorageSync('userInfo') || '{}');
  18. const userId = userInfo.id;
  19. const openid = userInfo.openid;
  20. const tenant_id = userInfo.tenant_id;
  21. if (!userId) {
  22. uni.showToast({
  23. title: '用户信息不完整,请重新登录',
  24. icon: 'none'
  25. });
  26. return false;
  27. }
  28. const response = await uni.request({
  29. url: `${apiBaseUrl}/api/system/resume-parsing-tasks/upload_resume/`,
  30. method: 'POST',
  31. data: {
  32. openid: openid,
  33. tenant_id: tenant_id,
  34. user_id: userId,
  35. file: fileUrl,
  36. description: '候选人简历'
  37. },
  38. header: {
  39. 'content-type': 'application/json'
  40. }
  41. });
  42. if (response.statusCode === 200 && response.data.code === 2000) {
  43. return true;
  44. } else {
  45. throw new Error(response.data.msg || '简历解析失败');
  46. }
  47. } catch (error) {
  48. console.error('简历解析失败:', error);
  49. uni.showToast({
  50. title: error.message || '简历解析失败',
  51. icon: 'none'
  52. });
  53. return false;
  54. }
  55. }, */
  56. clearFile() {
  57. common_vendor.index.showModal({
  58. title: "提示",
  59. content: "确定要删除已上传的文件吗?",
  60. success: (res) => {
  61. if (res.confirm) {
  62. this.uploadedFile = null;
  63. common_vendor.index.showToast({
  64. title: "文件已删除",
  65. icon: "success"
  66. });
  67. }
  68. }
  69. });
  70. },
  71. formatFileSize(size) {
  72. if (size < 1024) {
  73. return size + "B";
  74. } else if (size < 1024 * 1024) {
  75. return (size / 1024).toFixed(2) + "KB";
  76. } else {
  77. return (size / (1024 * 1024)).toFixed(2) + "MB";
  78. }
  79. },
  80. chooseFile() {
  81. if (this.uploadedFile) {
  82. common_vendor.index.showToast({
  83. title: "请先删除已上传的文件",
  84. icon: "none"
  85. });
  86. return;
  87. }
  88. common_vendor.index.chooseMessageFile({
  89. count: 1,
  90. type: "file",
  91. extension: this.fileType,
  92. success: (res) => {
  93. if (res.tempFiles[0].size > this.maxSize) {
  94. common_vendor.index.showToast({
  95. title: "文件大小不能超过30MB",
  96. icon: "none"
  97. });
  98. return;
  99. }
  100. this.uploadFile(res.tempFiles[0]);
  101. }
  102. });
  103. },
  104. async uploadFile(file) {
  105. try {
  106. common_vendor.index.showLoading({
  107. title: "上传中..."
  108. });
  109. const userInfo = JSON.parse(common_vendor.index.getStorageSync("userInfo") || "{}");
  110. console.log(userInfo);
  111. const openid = userInfo.openid || "";
  112. const tenant_id = userInfo.tenant_id || 1;
  113. const userId = userInfo.id;
  114. console.log(openid, tenant_id);
  115. if (!openid || !tenant_id || !userId) {
  116. common_vendor.index.hideLoading();
  117. common_vendor.index.showToast({
  118. title: "用户信息不完整,请重新登录",
  119. icon: "none"
  120. });
  121. return;
  122. }
  123. common_vendor.index.uploadFile({
  124. url: `${common_config.apiBaseUrl}/api/system/resume-parsing-tasks/upload_resume/`,
  125. filePath: file.path,
  126. name: "file",
  127. formData: {
  128. openid,
  129. tenant_id,
  130. user_id: userId,
  131. description: "候选人简历"
  132. },
  133. success: (uploadRes) => {
  134. try {
  135. const res = JSON.parse(uploadRes.data);
  136. console.log(res);
  137. if (res.code === 2e3) {
  138. this.uploadedFile = {
  139. name: file.name || "未命名文件",
  140. size: file.size,
  141. uploadTime: (/* @__PURE__ */ new Date()).toLocaleString(),
  142. url: res.data.url || ""
  143. };
  144. common_vendor.index.showToast({
  145. title: "上传成功",
  146. icon: "success",
  147. duration: 2e3
  148. });
  149. let seconds = 30;
  150. common_vendor.index.showLoading({
  151. title: `正在处理中,请稍候...(${seconds}秒)`,
  152. mask: true
  153. });
  154. const timer = setInterval(() => {
  155. seconds--;
  156. if (seconds > 0) {
  157. common_vendor.index.showLoading({
  158. title: `正在处理中,请稍候...(${seconds}秒)`,
  159. mask: true
  160. });
  161. } else {
  162. clearInterval(timer);
  163. common_vendor.index.hideLoading();
  164. common_vendor.index.showToast({
  165. title: "处理完成",
  166. icon: "success"
  167. });
  168. }
  169. }, 1e3);
  170. } else {
  171. common_vendor.index.showToast({
  172. title: res.msg || "上传失败",
  173. icon: "none"
  174. });
  175. }
  176. } catch (error) {
  177. common_vendor.index.showToast({
  178. title: "上传失败",
  179. icon: "none"
  180. });
  181. }
  182. },
  183. fail: (err) => {
  184. console.error("上传失败:", err);
  185. common_vendor.index.showToast({
  186. title: "网络错误,请重试",
  187. icon: "none"
  188. });
  189. },
  190. complete: () => {
  191. if (!this.uploadedFile) {
  192. common_vendor.index.hideLoading();
  193. }
  194. }
  195. });
  196. } catch (error) {
  197. common_vendor.index.hideLoading();
  198. common_vendor.index.showToast({
  199. title: "系统错误,请重试",
  200. icon: "none"
  201. });
  202. }
  203. }
  204. }
  205. };
  206. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  207. return common_vendor.e({
  208. a: common_vendor.t($data.uploadedFile ? "已上传文件" : "选择并上传文件"),
  209. b: common_vendor.o((...args) => $options.chooseFile && $options.chooseFile(...args)),
  210. c: !!$data.uploadedFile,
  211. d: $data.uploadedFile
  212. }, $data.uploadedFile ? {
  213. e: common_vendor.o((...args) => $options.clearFile && $options.clearFile(...args)),
  214. f: common_vendor.t($data.uploadedFile.name),
  215. g: common_vendor.t($options.formatFileSize($data.uploadedFile.size)),
  216. h: common_vendor.t($data.uploadedFile.uploadTime)
  217. } : {});
  218. }
  219. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
  220. wx.createPage(MiniProgramPage);