index.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. /**
  111. * 删除文件
  112. */
  113. export async function removeFile(data) {
  114. const res = await request.post(
  115. `/main/file/delete?fileId=${data.fileId}`,
  116. data
  117. );
  118. if (res.data.code === '0') {
  119. return res.data.message;
  120. }
  121. return Promise.reject(new Error(res.data.message));
  122. }
  123. /**
  124. * 文件列表
  125. */
  126. export async function getFileList(data) {
  127. const res = await request.post(`/main/file/list`, data);
  128. if (res.data.code === '0') {
  129. return res.data.data;
  130. }
  131. return Promise.reject(new Error(res.data.message));
  132. }
  133. /**
  134. * 导入文件 批量
  135. * @param file 文件
  136. */
  137. export async function importBatch(data) {
  138. const formData = new FormData();
  139. data.multiPartFiles.forEach((item, index) => {
  140. formData.append(`multiPartFiles`, item);
  141. });
  142. const res = await request.post(
  143. `/main/file/importBatch?module=${data.module}`,
  144. formData
  145. );
  146. if (res.data.code === '0') {
  147. return res.data;
  148. }
  149. return Promise.reject(new Error(res.data.message));
  150. }
  151. // 通用上传接口
  152. export async function commUpload(data) {
  153. const formData = new FormData();
  154. data.multiPartFiles.forEach((item, index) => {
  155. formData.append(`multiPartFiles`, item);
  156. });
  157. const res = await request.post(`${data.url}`, formData);
  158. if (res.data.code === '0') {
  159. return res.data;
  160. }
  161. return Promise.reject(new Error(res.data.message));
  162. }
  163. // 导入pbom
  164. export async function importPBom(data) {
  165. const formData = new FormData();
  166. data.multiPartFiles.forEach((item, index) => {
  167. formData.append(`multiPartFiles`, item);
  168. });
  169. const res = await request.post(`/main/bomCategory/importPBom`, formData);
  170. if (res.data.code === '0') {
  171. return res.data;
  172. }
  173. return Promise.reject(new Error(res.data.message));
  174. }