- API 层所有 Info/Request 接口添加 version 字段,update 函数传递 version
- delete 函数改为 client.delete(url, { data: { version } }) 发送 JSON body
- LanguageInfo.enabled → is_active,匹配后端 LanguageResp 字段名
- LanguageManager 编辑弹窗简化为只读详情(后端仅支持 is_active 切换)
- SystemSettings 设置值显示改用 JSON.stringify 而非 String()
- SystemSettings updateSetting 发送解析后的 JSON 对象而非字符串
112 lines
2.7 KiB
TypeScript
112 lines
2.7 KiB
TypeScript
import client from './client';
|
|
import type { PaginatedResponse } from './types';
|
|
|
|
export interface DictionaryItemInfo {
|
|
id: string;
|
|
dictionary_id: string;
|
|
label: string;
|
|
value: string;
|
|
sort_order: number;
|
|
color?: string;
|
|
version: number;
|
|
}
|
|
|
|
export interface DictionaryInfo {
|
|
id: string;
|
|
name: string;
|
|
code: string;
|
|
description?: string;
|
|
items: DictionaryItemInfo[];
|
|
version: number;
|
|
}
|
|
|
|
export interface CreateDictionaryRequest {
|
|
name: string;
|
|
code: string;
|
|
description?: string;
|
|
}
|
|
|
|
export interface UpdateDictionaryRequest {
|
|
name?: string;
|
|
description?: string;
|
|
version: number;
|
|
}
|
|
|
|
export async function listDictionaries(page = 1, pageSize = 20) {
|
|
const { data } = await client.get<{ success: boolean; data: PaginatedResponse<DictionaryInfo> }>(
|
|
'/config/dictionaries',
|
|
{ params: { page, page_size: pageSize } },
|
|
);
|
|
return data.data;
|
|
}
|
|
|
|
export async function createDictionary(req: CreateDictionaryRequest) {
|
|
const { data } = await client.post<{ success: boolean; data: DictionaryInfo }>(
|
|
'/config/dictionaries',
|
|
req,
|
|
);
|
|
return data.data;
|
|
}
|
|
|
|
export async function updateDictionary(id: string, req: UpdateDictionaryRequest) {
|
|
const { data } = await client.put<{ success: boolean; data: DictionaryInfo }>(
|
|
`/config/dictionaries/${id}`,
|
|
req,
|
|
);
|
|
return data.data;
|
|
}
|
|
|
|
export async function deleteDictionary(id: string, version: number) {
|
|
await client.delete(`/config/dictionaries/${id}`, { data: { version } });
|
|
}
|
|
|
|
export async function listItemsByCode(code: string) {
|
|
const { data } = await client.get<{ success: boolean; data: DictionaryItemInfo[] }>(
|
|
'/config/dictionaries/items',
|
|
{ params: { code } },
|
|
);
|
|
return data.data;
|
|
}
|
|
|
|
export interface CreateDictionaryItemRequest {
|
|
label: string;
|
|
value: string;
|
|
sort_order?: number;
|
|
color?: string;
|
|
}
|
|
|
|
export interface UpdateDictionaryItemRequest {
|
|
label?: string;
|
|
value?: string;
|
|
sort_order?: number;
|
|
color?: string;
|
|
version: number;
|
|
}
|
|
|
|
export async function createDictionaryItem(
|
|
dictionaryId: string,
|
|
req: CreateDictionaryItemRequest,
|
|
) {
|
|
const { data } = await client.post<{ success: boolean; data: DictionaryItemInfo }>(
|
|
`/config/dictionaries/${dictionaryId}/items`,
|
|
req,
|
|
);
|
|
return data.data;
|
|
}
|
|
|
|
export async function updateDictionaryItem(
|
|
dictionaryId: string,
|
|
itemId: string,
|
|
req: UpdateDictionaryItemRequest,
|
|
) {
|
|
const { data } = await client.put<{ success: boolean; data: DictionaryItemInfo }>(
|
|
`/config/dictionaries/${dictionaryId}/items/${itemId}`,
|
|
req,
|
|
);
|
|
return data.data;
|
|
}
|
|
|
|
export async function deleteDictionaryItem(dictionaryId: string, itemId: string, version: number) {
|
|
await client.delete(`/config/dictionaries/${dictionaryId}/items/${itemId}`, { data: { version } });
|
|
}
|