uploadResume.js 8.0 KB

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