order.ts
3.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import axios from 'axios';
import { defHttp } from '/@/utils/http/axios';
import { useUserStoreWithOut } from '/@/store/modules/user';
import { useOrderStoreWithOut } from '/@/store/modules/order';
enum Api {
ORDER_CREATE = '/order/erp/order/add',
UPDATE = '/order/erp/order/edit',
ORDER = '/order/erp/order/list_by_page',
FIELD_AUTH = '/order/erp/order/field_unlock_apply',
EXPORT = '/order/erp/order/export',
UPLOAD = '/api/localStorage/upload',
DICT_INIT = '/order/erp/dictionary/get_all',
DICT_ADD = '/order/erp/dictionary/add',
DICT_UPDATE = '/order/erp/dictionary/edit',
DICT_DELETE = '/order/erp/dictionary/delete',
DICT_LIST = '/order/erp/dictionary/list_by_page',
ANALYSIS = '/order/erp/profit/analysis',
}
export const orderCreate = async (data: any) => {
const res = await defHttp.post<any>({ url: Api.ORDER_CREATE, data }, { message: '保存成功' });
return res;
};
export const orderUpdate = async (data: any) => {
const res = await defHttp.post<any>({ url: Api.UPDATE, data });
return res;
};
export const orderAuth = (data: any) =>
defHttp.post<any>({ url: Api.FIELD_AUTH, data }, { message: '操作成功' });
export const orderAnalysis = async (data: any) => {
const res = await defHttp.post<any>({ url: Api.ANALYSIS, data });
return res;
};
export const orderExport = async (data: any = {}) => {
// const res = await defHttp.post<any>({ url: Api.EXPORT, data });
const userStore = useUserStoreWithOut();
const token = userStore.getToken;
axios({
url: '/basic-api' + Api.EXPORT,
method: 'post',
responseType: 'blob',
headers: { Authorization: `Bearer ${token}` },
data,
})
.then((response) => {
// 创建一个新的 Blob 对象,它包含了服务器响应的数据(即你的 Excel 文件)
const blob = new Blob([response.data]); // Excel 的 MIME 类型
const downloadUrl = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = downloadUrl;
a.download = '订单.xlsx'; // 你可以为文件命名
document.body.appendChild(a);
a.click(); // 模拟点击操作来下载文件
URL.revokeObjectURL(downloadUrl); // 释放掉 blob 对象所占用的内存
document.body.removeChild(a);
})
.catch((error) => {
// 处理错误
console.error('导出错误', error);
});
};
export const getInitDictData = async () => {
const res = await defHttp.post({
url: Api.DICT_INIT,
});
return res;
};
export async function uploadImg(params, onUploadProgress: (progressEvent: ProgressEvent) => void) {
const res = await defHttp.uploadFile(
{
url: Api.UPLOAD,
onUploadProgress,
},
{
file: params.file,
data: { name: params.file.name },
},
);
return Promise.resolve({ data: { thumbUrl: res.data } });
}
export const getOrderList = async (params: DemoParams) => {
const res = await defHttp.post<DemoListGetResultModel>({
url: Api.ORDER,
params,
headers: {
// @ts-ignore
ignoreCancelToken: true,
},
});
const orderStore = useOrderStoreWithOut();
orderStore.setTotal(res.total);
return new Promise((resolve) => {
resolve({
items: res.records,
total: res.total,
});
});
};
export const dictCreate = async (data: any) => {
const res = await defHttp.post<any>({ url: Api.DICT_ADD, data }, { message: '保存成功' });
return res;
};
export const dictUpdate = async (data: any) => {
const res = await defHttp.post<any>({ url: Api.DICT_UPDATE, data }, { message: '保存成功' });
return res;
};
export const dictDelete = async (data: any) => {
const res = await defHttp.post<any>({ url: Api.DICT_DELETE, data }, { message: '保存成功' });
return res;
};
export const dictList = async (data: any) => {
const res = await defHttp.post<any>({ url: Api.DICT_LIST, data: { ...data, pageSize: 1000 } });
return res;
};