| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- import request from '@/utils/request';
- import { download } from '@/utils/file';
- /**
- * 上传文件
- * @param file 文件
- */
- export async function uploadFile(data) {
- const formData = new FormData();
- formData.append('multiPartFile', data.multiPartFile);
- formData.append('module', data.module);
- const res = await request.post('/main/file/upload', formData);
- if (res.data.code === '0') {
- return res.data;
- }
- return Promise.reject(new Error(res.data.message));
- }
- /**
- * 导入文件 批量
- * @param file 文件
- */
- export async function uploadBatch(data) {
- const formData = new FormData();
- data.multiPartFiles.forEach((item, index) => {
- formData.append(`multiPartFiles`, item);
- });
- const res = await request.post(
- `/main/file/uploadBatch?module=${data.module}`,
- formData
- );
- if (res.data.code === '0') {
- return res.data;
- }
- return Promise.reject(new Error(res.data.message));
- }
- /**
- * 获取文件路径
- */
- export async function getPathAddress() {
- const res = await request.post('/main/file/getPathAddress');
- if (res.data.code === '0') {
- return res.data.data;
- }
- return Promise.reject();
- }
- /**
- * 获取文件
- */
- export async function getFile(params, fileName) {
- const res = await request.get('/main/file/getFile', {
- params,
- responseType: 'blob'
- });
- const arr = params.objectName.split('/');
- download(res.data, fileName || arr[arr.length - 1]);
- // if (res.data.code === '0') {
- // return res.data.data;
- // }
- // return Promise.reject();
- }
- /**
- * 下载模板
- */
- export async function downLoadTemplate() {
- const res = await request.post(
- '/main/user/downLoadTemplate',
- {},
- {
- responseType: 'blob'
- }
- );
- console.log(res.data, '***********');
- download(res.data, '员工档案导入模板.xlsx');
- }
- /**
- * 下载模板
- */
- export async function downLoadTemplateNew(url, fileName) {
- const res = await request.post(
- url,
- {},
- {
- responseType: 'blob'
- }
- );
- console.log(res.data, '***********');
- download(res.data, fileName);
- }
- export async function downLoadScript() {
- // 发送请求,下载模板
- const res = await request.post(
- '/main/file/downLoadScript',
- {},
- {
- responseType: 'blob'
- }
- );
- download(res.data, '脚本文件.zip');
- }
- export async function downLoadFiexs() {
- // 发送请求,下载模板
- const res = await request.post(
- '/main/file/downLoadCourse',
- {},
- {
- responseType: 'blob'
- }
- );
- download(res.data, 'CS配置教程.docx');
- }
- export async function downLoadBom() {
- const res = await request.post(
- '/main/bomCategory/downLoadTemplate',
- {},
- {
- responseType: 'blob'
- }
- );
- console.log(res.data, '***********');
- download(res.data, 'BOM导入模板.xls');
- }
- //批量导入BOM模板
- export async function downBatchLoadBom() {
- const res = await request.post(
- '/main/bomCategory/downLoadTemplateBatch',
- {},
- {
- responseType: 'blob'
- }
- );
- console.log(res.data, '***********');
- download(res.data, 'BOM批量导入模板.xls');
- }
- /**
- * 删除文件
- */
- export async function removeFile(data) {
- const res = await request.post(
- `/main/file/delete?fileId=${data.fileId}`,
- data
- );
- if (res.data.code === '0') {
- return res.data.message;
- }
- return Promise.reject(new Error(res.data.message));
- }
- /**
- * 文件列表
- */
- export async function getFileList(data) {
- const res = await request.post(`/main/file/list`, data);
- if (res.data.code === '0') {
- return res.data.data;
- }
- return Promise.reject(new Error(res.data.message));
- }
- /**
- * 导入文件 批量
- * @param file 文件
- */
- export async function importBatch(data) {
- const formData = new FormData();
- data.multiPartFiles.forEach((item, index) => {
- formData.append(`multiPartFiles`, item);
- });
- const res = await request.post(
- `/main/file/importBatch?module=${data.module}`,
- formData
- );
- if (res.data.code === '0') {
- return res.data;
- }
- return Promise.reject(new Error(res.data.message));
- }
- /**
- * 导入文件 批量
- * @param file 文件
- */
- export async function importBatchNew(data) {
- const formData = new FormData();
- data.multiPartFiles.forEach((item, index) => {
- formData.append(`multiPartFiles`, item);
- });
- const res = await request.post(data.apiUrl, formData);
- if (res.data.code === '0') {
- return res.data;
- }
- return Promise.reject(new Error(res.data.message));
- }
- // 通用上传接口
- export async function commUpload(data) {
- const formData = new FormData();
- data.multiPartFiles.forEach((item, index) => {
- formData.append(`multiPartFiles`, item);
- });
- const res = await request.post(`${data.url}`, formData);
- if (res.data.code === '0') {
- return res.data;
- }
- return Promise.reject(new Error(res.data.message));
- }
- // 导入pbom
- export async function importPBom(data) {
- const formData = new FormData();
- data.multiPartFiles.forEach((item, index) => {
- formData.append(`multiPartFiles`, item);
- });
- formData.append(`categoryId`, data.categoryId);
- const res = await request.post(`/main/bomCategory/importPBom`, formData);
- if (res.data.code === '0') {
- return res.data;
- }
- return Promise.reject(new Error(res.data.message));
- }
- //批量导入
- export async function batchImportPBom(data) {
- const formData = new FormData();
- data.multiPartFiles.forEach((item, index) => {
- formData.append(`multiPartFiles`, item);
- });
- const res = await request.post(`/main/bomCategory/batchImportPBom`, formData);
- if (res.data.code === '0') {
- return res.data;
- }
- return Promise.reject(new Error(res.data.message));
- }
|