Files
certd/packages/ui/certd-client/src/store/plugin/api.plugin.ts
T

83 lines
2.0 KiB
TypeScript
Raw Normal View History

2023-01-29 13:44:19 +08:00
import { request } from "/src/api/service";
2024-11-08 23:43:19 +08:00
import * as _ from "lodash-es";
import { PluginConfigBean, PluginSysSetting } from "/@/views/sys/plugin/api";
2023-01-29 13:44:19 +08:00
const apiPrefix = "/pi/plugin";
const defaultInputDefine = {
component: {
name: "a-input",
2025-03-19 00:28:50 +08:00
vModel: "modelValue",
},
2023-01-29 13:44:19 +08:00
};
function initPlugins(plugins: any) {
2025-04-12 23:59:03 +08:00
const checkedComponents = ["a-checkbox", "a-radio", "a-switch"];
2023-01-29 13:44:19 +08:00
for (const plugin of plugins) {
for (const key in plugin.input) {
const field = _.merge({}, defaultInputDefine, plugin.input[key]);
2025-04-12 23:59:03 +08:00
const componentName = field.component.name;
if (componentName.startsWith("a-")) {
if (checkedComponents.includes(componentName)) {
field.component.vModel = "checked";
} else {
field.component.vModel = "value";
}
2023-01-29 13:44:19 +08:00
}
//嵌套对象
field.key = ["input", key];
if (field.required) {
// delete field.required;
2023-01-29 13:44:19 +08:00
if (field.rules == null) {
field.rules = [];
}
field.rules.push({ required: true, message: "此项必填" });
}
plugin.input[key] = field;
}
}
}
export async function GetList(query: any) {
const plugins = await request({
url: apiPrefix + "/list",
method: "post",
2025-03-19 00:28:50 +08:00
params: query,
});
initPlugins(plugins);
2023-01-29 13:44:19 +08:00
return plugins;
}
export async function GetGroups(query: any) {
const groups = await request({
url: apiPrefix + "/groups",
method: "post",
2025-03-19 00:28:50 +08:00
params: query,
});
const plugins: any = [];
for (const groupKey in groups) {
plugins.push(...groups[groupKey].plugins);
}
initPlugins(plugins);
return groups;
}
2024-12-03 00:55:37 +08:00
export async function GetPluginDefine(type: string) {
const define = await request({
url: apiPrefix + "/getDefineByType",
method: "post",
data: {
2025-03-19 00:28:50 +08:00
type,
},
2024-12-03 00:55:37 +08:00
});
initPlugins([define]);
return define;
}
export async function GetPluginConfig(req: { id?: number; name: string; type: string }): Promise<PluginConfigBean> {
return await request({
url: apiPrefix + "/config",
method: "post",
2025-03-19 00:28:50 +08:00
data: req,
});
}