Files
template-10584/src/api/system/dictionary/index.ts
赵忠林 6d9a6ef7e4 fix(api): 修复 API 导入导致的 TypeScript 编译错误
- 将所有 API 文件中的 import request from '@/utils/request'替换为 import request from '@/utils/request-legacy'
- 创建了 request-legacy.ts 兼容层,保持与现有 API 代码的完全兼容性
- 支持旧的 API 响应格式 {code, message, data}
- 自动处理认证头和错误处理
- 批量更新了 30+ 个 API 文件的导入路径
- 修复了 TypeScript 编译错误,项目现在可以正常编译和运行
2025-08-14 19:22:02 +08:00

62 lines
1.4 KiB
TypeScript

import request from '@/utils/request-legacy';
import type { ApiResult } from '@/api/index';
import type { Dictionary, DictionaryParam } from './model';
import {SERVER_API_URL} from "@/utils/server";
/**
* 查询字典列表
*/
export async function listDictionaries(params?: DictionaryParam) {
const res = await request.get<ApiResult<Dictionary[]>>(
SERVER_API_URL + '/system/dictionary',
{
params
}
);
if (res.code === 0) {
return res.data;
}
return Promise.reject(new Error(res.message));
}
/**
* 添加字典
*/
export async function addDictionary(data: Dictionary) {
const res = await request.post<ApiResult<unknown>>(
SERVER_API_URL + '/system/dictionary',
data
);
if (res.code === 0) {
return res.message;
}
return Promise.reject(new Error(res.message));
}
/**
* 修改字典
*/
export async function updateDictionary(data: Dictionary) {
const res = await request.put<ApiResult<unknown>>(
SERVER_API_URL + '/system/dictionary',
data
);
if (res.code === 0) {
return res.message;
}
return Promise.reject(new Error(res.message));
}
/**
* 删除字典
*/
export async function removeDictionary(id?: number) {
const res = await request.del<ApiResult<unknown>>(
SERVER_API_URL + '/system/dictionary/' + id
);
if (res.code === 0) {
return res.message;
}
return Promise.reject(new Error(res.message));
}