index.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. import request from '@/utils/request';
  2. import { download } from '@/utils/file';
  3. /**
  4. * 上传文件
  5. * @param file 文件
  6. */
  7. export async function uploadFile(data) {
  8. const formData = new FormData();
  9. formData.append('multiPartFile', data.multiPartFile);
  10. formData.append('module', data.module);
  11. const res = await request.post('/main/file/upload', formData);
  12. if (res.data.code === '0') {
  13. return res.data;
  14. }
  15. return Promise.reject(new Error(res.data.message));
  16. }
  17. /**
  18. * 导入文件 批量
  19. * @param file 文件
  20. */
  21. export async function uploadBatch(data) {
  22. const formData = new FormData();
  23. data.multiPartFiles.forEach((item, index) => {
  24. formData.append(`multiPartFiles`, item);
  25. });
  26. const res = await request.post(
  27. `/main/file/uploadBatch?module=${data.module}`,
  28. formData
  29. );
  30. if (res.data.code === '0') {
  31. return res.data;
  32. }
  33. return Promise.reject(new Error(res.data.message));
  34. }
  35. /**
  36. * 获取文件路径
  37. */
  38. export async function getPathAddress() {
  39. const res = await request.post('/main/file/getPathAddress');
  40. if (res.data.code === '0') {
  41. return res.data.data;
  42. }
  43. return Promise.reject();
  44. }
  45. /**
  46. * 获取文件
  47. */
  48. export async function getFile(params, fileName) {
  49. const res = await request.get('/main/file/getFile', {
  50. params,
  51. responseType: 'blob'
  52. });
  53. const arr = params.objectName.split('/');
  54. download(res.data, fileName || arr[arr.length - 1]);
  55. // if (res.data.code === '0') {
  56. // return res.data.data;
  57. // }
  58. // return Promise.reject();
  59. }
  60. /**
  61. * 下载模板
  62. */
  63. export async function downLoadTemplate() {
  64. const res = await request.post(
  65. '/main/user/downLoadTemplate',
  66. {},
  67. {
  68. responseType: 'blob'
  69. }
  70. );
  71. console.log(res.data, '***********');
  72. download(res.data, '员工档案导入模板.xlsx');
  73. }
  74. /**
  75. * 下载模板
  76. */
  77. export async function downLoadTemplateNew(url, fileName) {
  78. const res = await request.post(
  79. url,
  80. {},
  81. {
  82. responseType: 'blob'
  83. }
  84. );
  85. console.log(res.data, '***********');
  86. download(res.data, fileName);
  87. }
  88. export async function downLoadScript() {
  89. // 发送请求,下载模板
  90. const res = await request.post(
  91. '/main/file/downLoadScript',
  92. {},
  93. {
  94. responseType: 'blob'
  95. }
  96. );
  97. download(res.data, '脚本文件.zip');
  98. }
  99. export async function downLoadFiexs() {
  100. // 发送请求,下载模板
  101. const res = await request.post(
  102. '/main/file/downLoadCourse',
  103. {},
  104. {
  105. responseType: 'blob'
  106. }
  107. );
  108. download(res.data, 'CS配置教程.docx');
  109. }
  110. export async function downLoadBom() {
  111. const res = await request.post(
  112. '/main/bomCategory/downLoadTemplate',
  113. {},
  114. {
  115. responseType: 'blob'
  116. }
  117. );
  118. console.log(res.data, '***********');
  119. download(res.data, 'BOM导入模板.xls');
  120. }
  121. //批量导入BOM模板
  122. export async function downBatchLoadBom() {
  123. const res = await request.post(
  124. '/main/bomCategory/downLoadTemplateBatch',
  125. {},
  126. {
  127. responseType: 'blob'
  128. }
  129. );
  130. console.log(res.data, '***********');
  131. download(res.data, 'BOM批量导入模板.xls');
  132. }
  133. /**
  134. * 删除文件
  135. */
  136. export async function removeFile(data) {
  137. const res = await request.post(
  138. `/main/file/delete?fileId=${data.fileId}`,
  139. data
  140. );
  141. if (res.data.code === '0') {
  142. return res.data.message;
  143. }
  144. return Promise.reject(new Error(res.data.message));
  145. }
  146. /**
  147. * 文件列表
  148. */
  149. export async function getFileList(data) {
  150. const res = await request.post(`/main/file/list`, data);
  151. if (res.data.code === '0') {
  152. return res.data.data;
  153. }
  154. return Promise.reject(new Error(res.data.message));
  155. }
  156. /**
  157. * 导入文件 批量
  158. * @param file 文件
  159. */
  160. export async function importBatch(data) {
  161. const formData = new FormData();
  162. data.multiPartFiles.forEach((item, index) => {
  163. formData.append(`multiPartFiles`, item);
  164. });
  165. const res = await request.post(
  166. `/main/file/importBatch?module=${data.module}`,
  167. formData
  168. );
  169. if (res.data.code === '0') {
  170. return res.data;
  171. }
  172. return Promise.reject(new Error(res.data.message));
  173. }
  174. /**
  175. * 导入文件 批量
  176. * @param file 文件
  177. */
  178. export async function importBatchNew(data) {
  179. const formData = new FormData();
  180. data.multiPartFiles.forEach((item, index) => {
  181. formData.append(`multiPartFiles`, item);
  182. });
  183. const res = await request.post(data.apiUrl, formData);
  184. if (res.data.code === '0') {
  185. return res.data;
  186. }
  187. return Promise.reject(new Error(res.data.message));
  188. }
  189. // 通用上传接口
  190. export async function commUpload(data) {
  191. const formData = new FormData();
  192. data.multiPartFiles.forEach((item, index) => {
  193. formData.append(`multiPartFiles`, item);
  194. });
  195. const res = await request.post(`${data.url}`, formData);
  196. if (res.data.code === '0') {
  197. return res.data;
  198. }
  199. return Promise.reject(new Error(res.data.message));
  200. }
  201. // 导入pbom
  202. export async function importPBom(data) {
  203. const formData = new FormData();
  204. data.multiPartFiles.forEach((item, index) => {
  205. formData.append(`multiPartFiles`, item);
  206. });
  207. formData.append(`categoryId`, data.categoryId);
  208. const res = await request.post(`/main/bomCategory/importPBom`, formData);
  209. if (res.data.code === '0') {
  210. return res.data;
  211. }
  212. return Promise.reject(new Error(res.data.message));
  213. }
  214. //批量导入
  215. export async function batchImportPBom(data) {
  216. const formData = new FormData();
  217. data.multiPartFiles.forEach((item, index) => {
  218. formData.append(`multiPartFiles`, item);
  219. });
  220. const res = await request.post(`/main/bomCategory/batchImportPBom`, formData);
  221. if (res.data.code === '0') {
  222. return res.data;
  223. }
  224. return Promise.reject(new Error(res.data.message));
  225. }