first commit
Some checks failed
Node CI / build (14.x, macOS-latest) (push) Has been cancelled
Node CI / build (14.x, ubuntu-latest) (push) Has been cancelled
Node CI / build (14.x, windows-latest) (push) Has been cancelled
Node CI / build (16.x, macOS-latest) (push) Has been cancelled
Node CI / build (16.x, ubuntu-latest) (push) Has been cancelled
Node CI / build (16.x, windows-latest) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
coverage CI / build (push) Has been cancelled
Node pnpm CI / build (16.x, macOS-latest) (push) Has been cancelled
Node pnpm CI / build (16.x, ubuntu-latest) (push) Has been cancelled
Node pnpm CI / build (16.x, windows-latest) (push) Has been cancelled
Some checks failed
Node CI / build (14.x, macOS-latest) (push) Has been cancelled
Node CI / build (14.x, ubuntu-latest) (push) Has been cancelled
Node CI / build (14.x, windows-latest) (push) Has been cancelled
Node CI / build (16.x, macOS-latest) (push) Has been cancelled
Node CI / build (16.x, ubuntu-latest) (push) Has been cancelled
Node CI / build (16.x, windows-latest) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
coverage CI / build (push) Has been cancelled
Node pnpm CI / build (16.x, macOS-latest) (push) Has been cancelled
Node pnpm CI / build (16.x, ubuntu-latest) (push) Has been cancelled
Node pnpm CI / build (16.x, windows-latest) (push) Has been cancelled
This commit is contained in:
144
src/services/system/dict.ts
Normal file
144
src/services/system/dict.ts
Normal file
@@ -0,0 +1,144 @@
|
||||
import { request } from '@umijs/max';
|
||||
import { DictValueEnumObj } from '@/components/DictTag';
|
||||
import { HttpResult } from '@/enums/httpEnum';
|
||||
import { downLoadXlsx } from '@/utils/downloadfile';
|
||||
|
||||
/* *
|
||||
*
|
||||
* @author whiteshader@163.com
|
||||
* @datetime 2021/09/16
|
||||
*
|
||||
* */
|
||||
|
||||
// 查询字典类型列表
|
||||
export async function getDictTypeList(params?: API.DictTypeListParams) {
|
||||
return request(`/api/cms/dict/type/list`, {
|
||||
params: {
|
||||
...params,
|
||||
},
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json;charset=UTF-8',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// 查询字典类型详细
|
||||
export function getDictType(dictId: string) {
|
||||
return request(`/api/cms/dict/type/${dictId}`, {
|
||||
method: 'GET',
|
||||
});
|
||||
}
|
||||
|
||||
// 查询字典数据详细
|
||||
export async function getDictValueEnum(
|
||||
dictType: string,
|
||||
isDigital?: boolean,
|
||||
isCms?: boolean,
|
||||
): Promise<DictValueEnumObj> {
|
||||
let resp = null;
|
||||
if (isCms) {
|
||||
resp = await request<API.System.DictTypeResult>(`/api/cms/dict/data/type/${dictType}`, {
|
||||
method: 'GET',
|
||||
});
|
||||
} else {
|
||||
resp = await request<API.System.DictTypeResult>(`/api/system/dict/data/type/${dictType}`, {
|
||||
method: 'GET',
|
||||
});
|
||||
}
|
||||
|
||||
if (resp.code === HttpResult.SUCCESS) {
|
||||
const opts: DictValueEnumObj = {};
|
||||
resp.data.forEach((item: any) => {
|
||||
opts[item.dictValue] = {
|
||||
text: item.dictLabel,
|
||||
label: item.dictLabel,
|
||||
value: isDigital ? Number(item.dictValue) : item.dictValue,
|
||||
key: item.dictCode,
|
||||
listClass: item.listClass,
|
||||
status: item.listClass,
|
||||
};
|
||||
});
|
||||
return opts;
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
export async function getDictSelectOption(dictType: string, isDigital?: boolean, isCms?: boolean) {
|
||||
let resp = null;
|
||||
if (isCms) {
|
||||
resp = await request<API.System.DictTypeResult>(`/api/cms/dict/data/type/${dictType}`, {
|
||||
method: 'GET',
|
||||
});
|
||||
} else {
|
||||
resp = await request<API.System.DictTypeResult>(`/api/system/dict/data/type/${dictType}`, {
|
||||
method: 'GET',
|
||||
});
|
||||
}
|
||||
if (resp.code === 200) {
|
||||
const options: DictValueEnumObj[] = resp.data.map((item) => {
|
||||
return {
|
||||
text: item.dictLabel,
|
||||
label: item.dictLabel,
|
||||
value: isDigital ? Number(item.dictValue) : item.dictValue,
|
||||
key: item.dictCode,
|
||||
listClass: item.listClass,
|
||||
status: item.listClass,
|
||||
};
|
||||
});
|
||||
return options;
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
// 新增字典类型
|
||||
export async function addDictType(params: API.System.DictType) {
|
||||
return request<API.Result>('/api/cms/dict/type', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json;charset=UTF-8',
|
||||
},
|
||||
data: params,
|
||||
});
|
||||
}
|
||||
|
||||
// 修改字典类型
|
||||
export async function updateDictType(params: API.System.DictType) {
|
||||
return request<API.Result>('/api/cms/dict/type', {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json;charset=UTF-8',
|
||||
},
|
||||
data: params,
|
||||
});
|
||||
}
|
||||
|
||||
// 删除字典类型
|
||||
export async function removeDictType(ids: string) {
|
||||
return request<API.Result>(`/api/cms/dict/type/${ids}`, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
}
|
||||
|
||||
// 导出字典类型
|
||||
export function exportDictType(params?: API.System.DictTypeListParams) {
|
||||
return downLoadXlsx(
|
||||
`/api/cms/dict/type/export`,
|
||||
{ params },
|
||||
`dict_type_${new Date().getTime()}.xlsx`,
|
||||
);
|
||||
}
|
||||
|
||||
// 获取字典选择框列表
|
||||
export async function getDictTypeOptionSelect(params?: API.DictTypeListParams) {
|
||||
return request('/api/cms/dict/type/optionselect', {
|
||||
params: {
|
||||
...params,
|
||||
},
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json;charset=UTF-8',
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user