From 08de1a6f19ad92b42249d62719d88620a216c08e Mon Sep 17 00:00:00 2001 From: dap <15891557205@163.com> Date: Thu, 5 Jun 2025 21:33:53 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BB=A3=E7=A0=81=E7=94=9F?= =?UTF-8?q?=E6=88=90=20=E5=AD=97=E5=85=B8=E4=B8=8B=E6=8B=89=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E6=94=B9=E4=B8=BA=E6=AF=8F=E6=AC=A1=E9=83=BD=E9=87=8D?= =?UTF-8?q?=E6=96=B0=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/tool/gen/edit-steps/gen-config.vue | 23 ++++++++++++++-- .../views/tool/gen/edit-steps/gen-data.tsx | 27 +++---------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/apps/web-antd/src/views/tool/gen/edit-steps/gen-config.vue b/apps/web-antd/src/views/tool/gen/edit-steps/gen-config.vue index 279194b1..cdb4b475 100644 --- a/apps/web-antd/src/views/tool/gen/edit-steps/gen-config.vue +++ b/apps/web-antd/src/views/tool/gen/edit-steps/gen-config.vue @@ -4,9 +4,10 @@ import type { Ref } from 'vue'; import type { VxeGridProps } from '#/adapter/vxe-table'; import type { GenInfo } from '#/api/tool/gen/model'; -import { inject } from 'vue'; +import { inject, onMounted, reactive } from 'vue'; import { useVbenVxeGrid } from '#/adapter/vxe-table'; +import { dictOptionSelectList } from '#/api/system/dict/dict-type'; import { validRules, vxeTableColumns } from './gen-data'; @@ -15,8 +16,26 @@ import { validRules, vxeTableColumns } from './gen-data'; */ const genInfoData = inject('genInfoData') as Ref; +const dictOptions = reactive<{ label: string; value: string }[]>([ + { label: '未设置', value: '' }, +]); + +/** + * 加载字典下拉数据 + */ +onMounted(async () => { + const resp = await dictOptionSelectList(); + + const options = resp.map((dict) => ({ + label: `${dict.dictName} | ${dict.dictType}`, + value: dict.dictType, + })); + + dictOptions.push(...options); +}); + const gridOptions: VxeGridProps = { - columns: vxeTableColumns, + columns: vxeTableColumns(dictOptions), keepSource: true, editConfig: { trigger: 'click', mode: 'cell', showStatus: true }, editRules: validRules, diff --git a/apps/web-antd/src/views/tool/gen/edit-steps/gen-data.tsx b/apps/web-antd/src/views/tool/gen/edit-steps/gen-data.tsx index 28684fc5..89078925 100644 --- a/apps/web-antd/src/views/tool/gen/edit-steps/gen-data.tsx +++ b/apps/web-antd/src/views/tool/gen/edit-steps/gen-data.tsx @@ -2,14 +2,10 @@ import type { Recordable } from '@vben/types'; import type { VxeGridProps } from '#/adapter/vxe-table'; -import { reactive } from 'vue'; - import { getPopupContainer } from '@vben/utils'; import { Checkbox, Input, Select } from 'ant-design-vue'; -import { dictOptionSelectList } from '#/api/system/dict/dict-type'; - const JavaTypes: string[] = [ 'Long', 'String', @@ -45,24 +41,6 @@ const componentsOptions = [ { label: '富文本', value: 'editor' }, ]; -const dictOptions = reactive<{ label: string; value: string }[]>([ - { label: '未设置', value: '' }, -]); -/** - * 在这里初始化字典下拉框 - */ -(async function init() { - const ret = await dictOptionSelectList(); - - ret.forEach((dict) => { - const option = { - label: `${dict.dictName} | ${dict.dictType}`, - value: dict.dictType, - }; - dictOptions.push(option); - }); -})(); - function renderBooleanTag(row: Recordable, field: string) { const value = row[field] ? '是' : '否'; const className = row[field] ? 'text-green-500' : 'text-red-500'; @@ -78,7 +56,10 @@ export const validRules: VxeGridProps['editRules'] = { javaField: [{ required: true, message: '请输入' }], }; -export const vxeTableColumns: VxeGridProps['columns'] = [ +// 内部依赖的字典从外部通过函数传入 +export const vxeTableColumns: ( + dictOptions: { label: string; value: string }[], +) => VxeGridProps['columns'] = (dictOptions) => [ { title: '序号', type: 'seq',