Files
certd/packages/ui/certd-client/src/views/sys/plugin/crud.tsx

433 lines
11 KiB
TypeScript
Raw Normal View History

2024-10-13 01:27:08 +08:00
import * as api from "./api";
import { useI18n } from "vue-i18n";
import { computed, Ref, ref } from "vue";
import { useRouter } from "vue-router";
2025-04-06 18:06:21 +08:00
import { AddReq, compute, CreateCrudOptionsProps, CreateCrudOptionsRet, DelReq, dict, EditReq, UserPageQuery, UserPageRes, utils } from "@fast-crud/fast-crud";
2024-10-13 01:27:08 +08:00
import { useUserStore } from "/src/store/modules/user";
import { useSettingStore } from "/src/store/modules/settings";
import { Modal } from "ant-design-vue";
//@ts-ignore
import yaml from "js-yaml";
2024-10-13 01:27:08 +08:00
export default function ({ crudExpose, context }: CreateCrudOptionsProps): CreateCrudOptionsRet {
const router = useRouter();
const { t } = useI18n();
const pageRequest = async (query: UserPageQuery): Promise<UserPageRes> => {
return await api.GetList(query);
};
const editRequest = async ({ form, row }: EditReq) => {
form.id = row.id;
const res = await api.UpdateObj(form);
return res;
};
const delRequest = async ({ row }: DelReq) => {
return await api.DelObj(row.id);
};
const addRequest = async ({ form }: AddReq) => {
const res = await api.AddObj(form);
return res;
};
const userStore = useUserStore();
const settingStore = useSettingStore();
const selectedRowKeys: Ref<any[]> = ref([]);
context.selectedRowKeys = selectedRowKeys;
return {
crudOptions: {
settings: {
plugins: {
//这里使用行选择插件生成行选择crudOptions配置最终会与crudOptions合并
rowSelection: {
enabled: true,
order: -2,
before: true,
// handle: (pluginProps,useCrudProps)=>CrudOptions,
props: {
multiple: true,
crossPage: true,
2025-04-01 22:34:15 +08:00
selectedRowKeys,
},
},
},
2024-10-13 01:27:08 +08:00
},
request: {
pageRequest,
addRequest,
editRequest,
2025-04-01 22:34:15 +08:00
delRequest,
2024-10-13 01:27:08 +08:00
},
actionbar: {
buttons: {
add: {
2025-04-06 18:06:21 +08:00
show: true,
text: "自定义插件",
2025-04-01 22:34:15 +08:00
},
},
2024-10-13 01:27:08 +08:00
},
rowHandle: {
2025-04-06 18:06:21 +08:00
show: true,
2024-10-13 01:27:08 +08:00
minWidth: 200,
fixed: "right",
buttons: {
edit: {
2025-04-06 18:06:21 +08:00
show: compute(({ row }) => {
return row.type === "custom";
}),
2024-10-14 00:19:55 +08:00
},
copy: {
2025-04-06 18:06:21 +08:00
show: compute(({ row }) => {
return row.type === "custom";
}),
2024-10-14 00:19:55 +08:00
},
remove: {
2025-04-06 18:06:21 +08:00
show: compute(({ row }) => {
return row.type === "custom";
}),
2025-04-01 22:34:15 +08:00
},
},
2024-10-13 01:27:08 +08:00
},
2024-10-14 14:57:09 +08:00
table: {
2025-04-01 22:34:15 +08:00
rowKey: "name",
2024-10-14 14:57:09 +08:00
},
2025-04-06 18:06:21 +08:00
tabs: {
name: "type",
show: true,
defaultOption: {
show: false,
},
},
2024-10-13 01:27:08 +08:00
columns: {
2024-10-14 14:57:09 +08:00
// id: {
// title: "ID",
// key: "id",
// type: "number",
// column: {
// width: 100
// },
// form: {
// show: false
// }
// },
2024-10-13 01:27:08 +08:00
name: {
title: "插件名称",
type: "text",
search: {
2025-04-01 22:34:15 +08:00
show: true,
2024-10-13 01:27:08 +08:00
},
form: {
2025-04-06 18:06:21 +08:00
show: true,
order: 0,
2025-04-10 00:22:05 +08:00
helper: "必须为英文,驼峰命名,类型作为前缀\n例如AliyunDeployToCDN\n插件一旦被使用不要修改名称",
2025-04-06 18:06:21 +08:00
rules: [{ required: true }],
},
column: {
width: 250,
cellRender({ row }) {
if (row.author) {
return <fs-copyable model-value={`${row.author}/${row.name}`} />;
} else {
return <fs-copyable model-value={row.name} />;
}
},
},
},
author: {
title: "作者",
type: "text",
search: {
show: true,
},
form: {
show: true,
order: 0,
2025-04-10 00:22:05 +08:00
helper: "上传到插件商店时,将作为插件名称前缀,例如greper/pluginName",
2025-04-06 18:06:21 +08:00
rules: [{ required: true }],
2024-10-13 01:27:08 +08:00
},
column: {
2025-04-01 22:34:15 +08:00
width: 200,
2025-04-06 18:06:21 +08:00
show: false,
2025-04-01 22:34:15 +08:00
},
2024-10-14 00:19:55 +08:00
},
icon: {
title: "图标",
2025-04-06 18:06:21 +08:00
type: "icon",
2024-10-14 00:19:55 +08:00
form: {
2025-04-06 18:06:21 +08:00
rules: [{ required: true }],
2024-10-14 00:19:55 +08:00
},
column: {
2025-04-06 18:06:21 +08:00
width: 70,
2024-10-14 00:19:55 +08:00
align: "center",
component: {
name: "fs-icon",
vModel: "icon",
style: {
2025-04-01 22:34:15 +08:00
fontSize: "22px",
},
},
},
2024-10-13 01:27:08 +08:00
},
2025-04-06 18:06:21 +08:00
2024-10-13 01:27:08 +08:00
title: {
title: "标题",
type: "text",
2025-04-06 18:06:21 +08:00
form: {
order: 0,
helper: "插件中文名称",
rules: [{ required: true }],
},
2024-10-13 01:27:08 +08:00
column: {
2025-04-01 22:34:15 +08:00
width: 300,
2025-04-06 18:06:21 +08:00
cellRender({ row }) {
if (row.type === "custom") {
return <router-link to={`/sys/plugin/edit?id=${row.id}`}>{row.title}</router-link>;
}
return <div>{row.title}</div>;
},
2025-04-01 22:34:15 +08:00
},
2024-10-13 01:27:08 +08:00
},
desc: {
title: "描述",
2025-04-10 00:22:05 +08:00
type: "textarea",
2025-04-06 18:06:21 +08:00
helper: "插件的描述",
2024-10-13 01:27:08 +08:00
column: {
2025-04-01 22:34:15 +08:00
width: 300,
2025-04-06 18:06:21 +08:00
show: false,
},
},
type: {
title: "来源",
type: "dict-select",
search: {
show: true,
},
form: {
value: "custom",
component: {
disabled: true,
},
},
dict: dict({
data: [
{ label: "内置", value: "builtIn" },
{ label: "自建", value: "custom" },
{ label: "商店", value: "store" },
],
}),
column: {
width: 70,
align: "center",
component: {
color: "auto",
},
},
},
pluginType: {
title: "插件类型",
type: "dict-select",
search: {
show: true,
},
form: {
rules: [{ required: true }],
},
2025-04-10 00:22:05 +08:00
editForm: {
component: {
disabled: true,
},
},
2025-04-06 18:06:21 +08:00
dict: dict({
data: [
{ label: "授权", value: "access" },
{ label: "DNS", value: "dnsProvider" },
{ label: "部署插件", value: "deploy" },
2025-04-06 18:06:21 +08:00
],
}),
column: {
width: 100,
align: "center",
component: {
color: "auto",
},
2025-04-01 22:34:15 +08:00
},
2024-10-13 01:27:08 +08:00
},
2025-04-10 00:22:05 +08:00
version: {
title: "版本",
type: "text",
column: {
width: 100,
align: "center",
},
},
2024-10-13 01:27:08 +08:00
group: {
title: "分组",
2025-04-06 18:06:21 +08:00
type: "dict-select",
dict: dict({
url: "/pi/plugin/groupsList",
label: "title",
value: "key",
}),
form: {
rules: [{ required: true }],
},
2024-10-13 01:27:08 +08:00
column: {
2024-10-14 00:19:55 +08:00
width: 100,
2025-04-06 18:06:21 +08:00
align: "left",
component: {
color: "auto",
},
2025-04-01 22:34:15 +08:00
},
2024-10-13 01:27:08 +08:00
},
"extra.dependLibs": {
title: "第三方依赖",
type: "text",
form: {
helper: "依赖的第三方库,package.dependencies的格式name[:^version]",
component: {
name: "a-select",
mode: "tags",
allowClear: true,
open: false,
},
},
column: {
show: false,
},
},
"extra.dependPlugins": {
title: "插件依赖",
type: "text",
form: {
component: {
name: "a-select",
mode: "tags",
open: false,
allowClear: true,
},
helper: "安装时会先安装依赖的插件,格式:[author/]pluginName[:version]",
},
column: {
show: false,
},
},
"extra.showRunStrategy": {
title: "可修改运行策略",
type: "dict-switch",
dict: dict({
data: [
{ value: false, label: "不可修改" },
{ value: true, label: "可修改" },
],
}),
form: {
value: false,
rules: [{ required: true }],
},
column: {
width: 100,
align: "left",
show: false,
},
},
"extra.default.strategy.runStrategy": {
2025-04-10 00:22:05 +08:00
title: "运行策略",
type: "dict-select",
dict: dict({
data: [
{ value: 0, label: "正常运行" },
{ value: 1, label: "成功后跳过(部署任务)" },
],
}),
form: {
value: 1,
rules: [{ required: true }],
helper: "默认运行策略",
show: compute(({ form }) => {
return form.extra.showRunStrategy;
}),
2025-04-10 00:22:05 +08:00
},
column: {
width: 100,
align: "left",
component: {
color: "auto",
},
show: false,
2025-04-10 00:22:05 +08:00
},
valueBuilder({ row }) {
if (row.extra) {
row.extra = yaml.load(row.extra);
}
},
valueResolve({ row }) {
if (row.extra) {
row.extra = yaml.dump(row.extra);
}
},
2025-04-10 00:22:05 +08:00
},
2024-10-13 01:27:08 +08:00
disabled: {
2024-10-14 14:57:09 +08:00
title: "点击禁用/启用",
2024-10-13 01:27:08 +08:00
type: "dict-switch",
dict: dict({
data: [
{ label: "启用", value: false, color: "success" },
2025-04-01 22:34:15 +08:00
{ label: "禁用", value: true, color: "error" },
],
2024-10-13 01:27:08 +08:00
}),
form: {
2025-04-10 00:22:05 +08:00
title: "禁用/启用",
2025-04-01 22:34:15 +08:00
value: false,
2024-10-13 01:27:08 +08:00
},
column: {
2024-10-14 14:57:09 +08:00
width: 120,
2024-10-14 00:19:55 +08:00
align: "center",
2024-10-13 01:27:08 +08:00
component: {
title: "点击可禁用/启用",
on: {
async click({ value, row }) {
Modal.confirm({
title: "提示",
content: `确定要${!value ? "禁用" : "启用"}吗?`,
onOk: async () => {
2024-10-14 00:19:55 +08:00
await api.SetDisabled({
id: row.id,
name: row.name,
type: row.type,
2025-04-01 22:34:15 +08:00
disabled: !value,
2024-10-14 00:19:55 +08:00
});
2024-10-13 01:27:08 +08:00
await crudExpose.doRefresh();
2025-04-01 22:34:15 +08:00
},
2024-10-13 01:27:08 +08:00
});
2025-04-01 22:34:15 +08:00
},
},
},
},
2024-10-13 01:27:08 +08:00
},
createTime: {
title: "创建时间",
type: "datetime",
form: {
2025-04-01 22:34:15 +08:00
show: false,
2024-10-13 01:27:08 +08:00
},
column: {
sorter: true,
width: 160,
2025-04-01 22:34:15 +08:00
align: "center",
},
2024-10-13 01:27:08 +08:00
},
updateTime: {
title: "更新时间",
type: "datetime",
form: {
2025-04-01 22:34:15 +08:00
show: false,
2024-10-13 01:27:08 +08:00
},
column: {
2025-04-01 22:34:15 +08:00
show: true,
},
},
},
},
2024-10-13 01:27:08 +08:00
};
}