vitesse-yitisheng-web/src/service/api/dict.ts

52 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 字典API服务
* 用于获取动态字典数据
*/
import request from '~/service/request'
// 字典项接口
export interface DictItem {
label: string
value: string | number
disabled?: boolean
color?: string
order?: number
[key: string]: any
}
// 字典响应数据接口
export interface DictData {
type: string
items: DictItem[]
}
/**
* 获取字典列表
* @param types 字典类型列表,如果为空则获取所有字典
* @returns 字典数据列表
*/
export function getDictionaryList(types?: string[]): Promise<DictData[]> {
const params: any = {}
if (types && types.length > 0) {
params.types = types.join(',')
}
return request.get<DictData[]>('/dict/list', {
params,
showLoading: false
})
}
/**
* 获取单个字典类型的数据
* @param type 字典类型
* @returns 字典项列表
*/
export function getDictionaryByType(type: string): Promise<DictItem[]> {
return request.get<DictItem[]>(`/dict/type/${type}`, {
showLoading: false
})
}
// 如果需要其他字典相关API可以在这里添加