config.ts
1.98 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
import { AttributeData, Option, QueryForPaginationParams, QueryForParams, ServiceResponse } from '@/types/global';
import { SystemConfig } from '@/types/system-config';
import axios from 'axios';
import { first } from 'lodash';
export default class useConfigApi {
static statusOptions = [
{ label: '启用', value: 1 },
{ label: '禁用', value: 0 },
];
static contentOptions = [
{ label: '无内容', value: 'none' },
{
label: '文本内容',
value: 'string',
children: [
{ label: '短文本', value: 'input' },
{ label: '长文本', value: 'textarea' },
],
},
{
label: '上传链接',
value: 'upload',
children: [
{ label: '图片链接', value: 'image' },
{ label: '视频链接', value: 'video' },
{ label: '音频链接', value: 'audio' },
{ label: '文件链接', value: 'file' },
],
},
];
static get(params?: QueryForParams | QueryForPaginationParams): Promise<ServiceResponse<SystemConfig[]>> {
return axios.get('system/configs', { params });
}
static async create(data: AttributeData) {
return axios.post('system/configs', data).then((res) => Promise.resolve(res.data));
}
static async update(id: number, data: AttributeData) {
return axios.put(`system/configs/${id}`, data).then((res) => Promise.resolve(res.data));
}
static async changeStatus(id: number, status: number) {
return axios.put(`system/configs/${id}/change-status`, { status });
}
static async getOne(params?: QueryForParams): Promise<SystemConfig | undefined> {
return useConfigApi.get({ ...params, parent_id: '', fetchType: 'all' }).then(({ data }) => first(data));
}
static async getOption(params?: QueryForParams): Promise<Option[]> {
return useConfigApi.get({ parent_id: '', ...params, fetchType: 'all' }).then(({ data }) =>
data?.map((item) => {
return {
value: item.identifier,
label: item.name,
};
})
);
}
}