chore: plugin default

This commit is contained in:
xiaojunnuo
2025-04-10 00:22:05 +08:00
parent 7545194f97
commit 0e36f03954
5 changed files with 336 additions and 25 deletions
@@ -117,7 +117,7 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
form: {
show: true,
order: 0,
helper: "必须为英文,驼峰命名,类型作为前缀\n例如AliyunDeployToCDN",
helper: "必须为英文,驼峰命名,类型作为前缀\n例如AliyunDeployToCDN\n插件一旦被使用,不要修改名称",
rules: [{ required: true }],
},
column: {
@@ -140,7 +140,7 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
form: {
show: true,
order: 0,
helper: "上传到应用商店时,将作为插件名称前缀,例如:greper/pluginName",
helper: "上传到插件商店时,将作为插件名称前缀,例如:greper/pluginName",
rules: [{ required: true }],
},
column: {
@@ -187,7 +187,7 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
},
desc: {
title: "描述",
type: "text",
type: "textarea",
helper: "插件的描述",
column: {
width: 300,
@@ -230,6 +230,11 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
form: {
rules: [{ required: true }],
},
editForm: {
component: {
disabled: true,
},
},
dict: dict({
data: [
{ label: "授权", value: "access" },
@@ -245,6 +250,14 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
},
},
},
version: {
title: "版本",
type: "text",
column: {
width: 100,
align: "center",
},
},
group: {
title: "分组",
type: "dict-select",
@@ -264,6 +277,29 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
},
},
},
"default.strategy.runStrategy": {
title: "运行策略",
type: "dict-select",
dict: dict({
data: [
{ value: 0, label: "正常运行" },
{ value: 1, label: "成功后跳过(部署任务)" },
],
}),
form: {
value: 1,
rules: [{ required: true }],
helper: "默认运行策略",
},
column: {
width: 100,
align: "left",
component: {
color: "auto",
},
},
},
disabled: {
title: "点击禁用/启用",
type: "dict-switch",
@@ -274,6 +310,7 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
],
}),
form: {
title: "禁用/启用",
value: false,
},
column: {
@@ -13,29 +13,39 @@
</div>
</template>
<div class="pi-plugin-editor">
<div class="base">
<a-tabs type="card">
<a-tab-pane key="base" tab="插件信息"> </a-tab-pane>
</a-tabs>
<div class="base-body">
<fs-form ref="baseFormRef" v-bind="formOptionsRef"></fs-form>
</div>
</div>
<div class="metadata">
<a-tabs type="card">
<a-tab-pane key="editor" tab="元数据"> </a-tab-pane>
</a-tabs>
<div class="metadata-body">
<code-editor id="metadata" v-model:model-value="plugin.metadata" language="yaml"></code-editor>
<code-editor id="metadata" v-model:model-value="plugin.metadata" language="yaml" @save="doSave"></code-editor>
</div>
</div>
<div class="script">
<a-tabs type="card">
<a-tab-pane key="script" tab="脚本"> </a-tab-pane>
</a-tabs>
<code-editor id="content" v-model:model-value="plugin.content" language="javascript"></code-editor>
<code-editor id="content" v-model:model-value="plugin.content" language="javascript" @save="doSave"></code-editor>
</div>
</div>
</fs-page>
</template>
<script lang="ts" setup>
import { onMounted, provide, ref } from "vue";
import { onMounted, provide, ref, Ref } from "vue";
import { useRoute } from "vue-router";
import * as api from "./api";
import yaml from "js-yaml";
import { notification } from "ant-design-vue";
import createCrudOptions from "./crud";
import { useColumns } from "@fast-crud/fast-crud";
const CertApplyPluginNames = ["CertApply", "CertApplyLego", "CertApplyUpload"];
defineOptions({
@@ -44,25 +54,49 @@ defineOptions({
const route = useRoute();
const plugin = ref<any>({});
const formOptionsRef: Ref = ref();
const baseFormRef: Ref = ref({});
function initFormOptions() {
const formCrudOptions = createCrudOptions({
crudExpose: {},
context: {},
});
const { buildFormOptions } = useColumns();
const formOptions = buildFormOptions(formCrudOptions.crudOptions, {});
formOptions.col = {
span: 24,
};
formOptions.labelCol = {
style: {
width: "100px",
},
};
formOptionsRef.value = formOptions;
}
initFormOptions();
async function getPlugin() {
const id = route.query.id;
const pluginObj = await api.GetObj(id);
if (!pluginObj.metadata) {
pluginObj.metadata = yaml.dump({
input: {
cert: {
title: "前置任务生成的证书",
component: {
name: "output-selector",
from: [...CertApplyPluginNames],
},
},
},
output: {},
if (pluginObj.metadata) {
const metadata = yaml.load(pluginObj.metadata);
pluginObj.default = metadata.default || {};
delete metadata.default;
pluginObj.metadata = yaml.dump(metadata, {
indent: 2,
});
}
plugin.value = pluginObj;
const baseFrom = {
...pluginObj,
};
delete baseFrom.metadata;
delete baseFrom.content;
baseFormRef.value.setFormData(baseFrom);
}
onMounted(async () => {
@@ -76,8 +110,16 @@ provide("get:plugin", () => {
const saveLoading = ref(false);
async function doSave() {
saveLoading.value = true;
const baseForm = baseFormRef.value.getFormData();
const metadata = yaml.load(plugin.value.metadata);
metadata.default = baseForm.default;
const form = {
...plugin.value,
...baseForm,
metadata: yaml.dump(metadata, { indent: 2 }),
};
try {
await api.UpdateObj(plugin.value);
await api.UpdateObj(form);
notification.success({
message: "保存成功",
});
@@ -112,9 +154,18 @@ async function doTest() {
flex: 1;
}
.base {
width: 400px;
max-width: 30%;
margin-right: 20px;
display: flex;
flex-direction: column;
height: 100%;
}
.metadata {
width: 600px;
max-width: 50%;
max-width: 30%;
margin-right: 20px;
display: flex;
flex-direction: column;