From fb923c92bde65c04ed2a06189d7f3d227a8183ad Mon Sep 17 00:00:00 2001 From: hyunfa <1598047833@qq.com> Date: Thu, 5 Sep 2024 22:38:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=BF=E6=8D=A2=E8=A1=A8=E5=8D=95=20?= =?UTF-8?q?#=20Reviewed,=20transaction=20id:=2021590?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/package.json | 1 + .../src/components/RussianDolls/create.ts | 108 +++++++++++++++ .../plugin-rule/plugin-rule-create/index.vue | 6 + .../plugin-rule-create/params-config.vue | 124 ++++++++++++------ 4 files changed, 198 insertions(+), 41 deletions(-) diff --git a/frontend/package.json b/frontend/package.json index 686407982..e81da8f36 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -42,6 +42,7 @@ } }, "dependencies": { + "@blueking/bkui-form": "^0.0.42-beta.14", "@blueking/crypto-js-sdk": "0.0.4", "@blueking/ip-selector": "0.2.0-beta", "@blueking/login-modal": "^1.0.1", diff --git a/frontend/src/components/RussianDolls/create.ts b/frontend/src/components/RussianDolls/create.ts index 403db524a..be77092cf 100644 --- a/frontend/src/components/RussianDolls/create.ts +++ b/frontend/src/components/RussianDolls/create.ts @@ -184,6 +184,114 @@ export function initSchema(schema: IItem): Doll[] { // return formatSchema(schema, schema.property) } +export const transformSchema = (schema: any, parentRequired: any[] = [], key: string = '') => { + if (!schema || typeof schema !== 'object') return schema; + + // 处理对象类型的属性 + if (schema.type === 'object' && schema.properties) { + const requiredProps = []; + for (const key in schema.properties) { + const prop = schema.properties[key]; + if (typeof prop.required !== 'undefined') { + if (prop.required) { + requiredProps.push(key); + if (prop.type === 'array') { + prop['minItems'] = 1; + prop['ui:group'] = { + "props": { + "verifiable": true, + }, + }; + } + prop['ui:rules'] = ['required']; // 增加 ui:rules + } + // 删除所有的 required,无论是 true 还是 false + delete prop.required; + } + // 递归处理子属性 + transformSchema(prop, requiredProps, key); + } + if (schema.required !== undefined) { + if (schema.required) { + parentRequired.push(key); + } + // 处理对象类型中的 required 属性 + delete schema.required; + } + + if (requiredProps.length > 0) { + schema.required = requiredProps; + } + } + + // 处理数组类型的项 + if (schema.type === 'array' && schema.items) { + const itemRequiredProps: any = []; + // 递归处理数组的每个项 + transformSchema(schema.items, itemRequiredProps, key); + if (schema.required !== undefined) { + delete schema.required; // 删除数组项中的 required + } + // 处理描述信息 + if (schema.description) { + schema['ui:group'] = { + "props": { + "description": schema.description, + }, + }; + } + if (schema.items.properties && Object.keys(schema.items.properties).length >= 2) { + // 如果是 key 和 value,添加 ui:component + if (schema.items.properties.key && schema.items.properties.value) { + schema['ui:component'] = { "name": "bfArray" }; + } + schema.items['ui:group'] = { + "props": { + "type": "card", + }, + "style": { + "background": "#F5F7FA", + }, + }; + } + if (schema.items.type === 'string' || schema.items.type === 'boolean' || schema.items.type === 'integer') { + parentRequired.push(key); + } + } + + // 转换 ui_component 属性到 ui:component + if (schema.ui_component && schema.ui_component.type === 'select') { + const datasource = []; + for (const optionKey in schema.ui_component.properties) { + const option = schema.ui_component.properties[optionKey]; + datasource.push({ + label: option.title, + value: option.value + }); + } + schema['ui:component'] = { + name: 'select', + props: { + datasource, + clearable: false + } + }; + delete schema.ui_component; // 删除原始的 ui_component + } + + // 处理字符串、布尔和整数类型的属性,删除 required + if (schema.type === 'string' || schema.type === 'boolean' || schema.type === 'integer') { + if (schema.required !== undefined) { + if (schema.required) { + schema['ui:rules'] = ['required']; + } + // 删除 required + delete schema.required; + } + } + + return schema; +} export const createItem = (property: string, params: IItem, id?: string): Doll => { console.log('property: ', property, params.type, '; params: ', params); return { diff --git a/frontend/src/views/plugin/plugin-rule/plugin-rule-create/index.vue b/frontend/src/views/plugin/plugin-rule/plugin-rule-create/index.vue index 47459181f..b5cb65825 100644 --- a/frontend/src/views/plugin/plugin-rule/plugin-rule-create/index.vue +++ b/frontend/src/views/plugin/plugin-rule/plugin-rule-create/index.vue @@ -418,6 +418,7 @@ $bgColor: #f5f7fa; } } .rule-create { + height: 100%; display: flex; flex-direction: column; overflow: hidden; @@ -433,3 +434,8 @@ $bgColor: #f5f7fa; } } + diff --git a/frontend/src/views/plugin/plugin-rule/plugin-rule-create/params-config.vue b/frontend/src/views/plugin/plugin-rule/plugin-rule-create/params-config.vue index d1f862a33..ecfc87848 100644 --- a/frontend/src/views/plugin/plugin-rule/plugin-rule-create/params-config.vue +++ b/frontend/src/views/plugin/plugin-rule/plugin-rule-create/params-config.vue @@ -47,16 +47,25 @@ - + @change="formChange" /> --> - + +