Files
timi-web/src/api/CommonAPI.ts
2026-04-10 12:47:50 +08:00

32 lines
1.0 KiB
TypeScript

import { TemplateBizType } from "../types";
import Toolkit from "../utils/Toolkit";
import { axios } from "./BaseAPI";
import TextFormat from "../utils/TextFormat";
const getCaptchaAPI = () => axios.defaults.baseURL + "/captcha";
const getAttachmentReadAPI = (mongoId: string) => `${axios.defaults.baseURL}/attachment/read/${mongoId}`;
async function getTemplate(bizType: TemplateBizType, code: string): Promise<string> {
return axios.get(`/template?bizType=${bizType}&bizCode=${code}`);
}
async function getSetting(key: string, args?: { [key: string]: any }): Promise<string> {
return axios.get(`/setting/${key}?${TextFormat.urlArgs(args)}`);
}
async function listSetting(keyMap: Map<string, object | undefined>): Promise<Map<string, string>> {
const result = await axios.post("/setting/map", Toolkit.toObject(keyMap));
const map = new Map<string, string>();
Object.entries(result).forEach(([key, value]) => map.set(key, value as string));
return map;
}
export default {
getCaptchaAPI,
getAttachmentReadAPI,
getTemplate,
getSetting,
listSetting
};