From b4a679dd08e9c825dbeed9b3cde73ac1eb262365 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Tue, 25 Nov 2025 20:09:06 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E3=80=90antd/ele=E3=80=91=E3=80=90infr?= =?UTF-8?q?a=E3=80=91=E8=A1=A8=E5=8D=95=E8=AE=BE=E8=AE=A1=E5=99=A8?= =?UTF-8?q?=EF=BC=9A=E6=B7=BB=E5=8A=A0=E8=BF=94=E5=9B=9E=E5=80=BC=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E9=85=8D=E7=BD=AE=E5=88=B0=E9=83=A8=E9=97=A8=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../form-create/components/use-api-select.tsx | 24 +++++++++++++++---- .../src/components/form-create/helpers.ts | 12 ++++++++++ .../form-create/components/use-api-select.tsx | 24 +++++++++++++++---- .../src/components/form-create/helpers.ts | 12 ++++++++++ 4 files changed, 64 insertions(+), 8 deletions(-) diff --git a/apps/web-antd/src/components/form-create/components/use-api-select.tsx b/apps/web-antd/src/components/form-create/components/use-api-select.tsx index ead612517..5de9903ff 100644 --- a/apps/web-antd/src/components/form-create/components/use-api-select.tsx +++ b/apps/web-antd/src/components/form-create/components/use-api-select.tsx @@ -69,6 +69,11 @@ export function useApiSelect(option: ApiSelectProps) { type: String, default: 'label', }, + // 返回值类型(用于部门选择器等):id 返回 ID,name 返回名称 + returnType: { + type: String, + default: 'id', + }, }, setup(props) { const attrs = useAttrs(); @@ -129,10 +134,21 @@ export function useApiSelect(option: ApiSelectProps) { function parseOptions0(data: any[]) { if (Array.isArray(data)) { - options.value = data.map((item: any) => ({ - label: parseExpression(item, props.labelField), - value: parseExpression(item, props.valueField), - })); + options.value = data.map((item: any) => { + const label = parseExpression(item, props.labelField); + let value = parseExpression(item, props.valueField); + + // 根据 returnType 决定返回值 + // 如果设置了 returnType 为 'name',则返回 label 作为 value + if (props.returnType === 'name') { + value = label; + } + + return { + label: label, + value: value, + }; + }); return; } console.warn(`接口[${props.url}] 返回结果不是一个数组`); diff --git a/apps/web-antd/src/components/form-create/helpers.ts b/apps/web-antd/src/components/form-create/helpers.ts index 260170b51..cfc5de10b 100644 --- a/apps/web-antd/src/components/form-create/helpers.ts +++ b/apps/web-antd/src/components/form-create/helpers.ts @@ -194,6 +194,18 @@ export async function useFormCreateDesigner(designer: Ref) { name: 'DeptSelect', label: '部门选择器', icon: 'icon-tree', + props: [ + { + type: 'select', + field: 'returnType', + title: '返回值类型', + value: 'id', + options: [ + { label: '部门编号', value: 'id' }, + { label: '部门名称', value: 'name' } + ] + } + ] }); const dictSelectRule = useDictSelectRule(); const apiSelectRule0 = useSelectRule({ diff --git a/apps/web-ele/src/components/form-create/components/use-api-select.tsx b/apps/web-ele/src/components/form-create/components/use-api-select.tsx index 43a4856ee..12ceb4a69 100644 --- a/apps/web-ele/src/components/form-create/components/use-api-select.tsx +++ b/apps/web-ele/src/components/form-create/components/use-api-select.tsx @@ -69,6 +69,11 @@ export function useApiSelect(option: ApiSelectProps) { type: String, default: 'label', }, + // 返回值类型(用于部门选择器等):id 返回 ID,name 返回名称 + returnType: { + type: String, + default: 'id', + }, }, setup(props) { const attrs = useAttrs(); @@ -129,10 +134,21 @@ export function useApiSelect(option: ApiSelectProps) { function parseOptions0(data: any[]) { if (Array.isArray(data)) { - options.value = data.map((item: any) => ({ - label: parseExpression(item, props.labelField), - value: parseExpression(item, props.valueField), - })); + options.value = data.map((item: any) => { + const label = parseExpression(item, props.labelField); + let value = parseExpression(item, props.valueField); + + // 根据 returnType 决定返回值 + // 如果设置了 returnType 为 'name',则返回 label 作为 value + if (props.returnType === 'name') { + value = label; + } + + return { + label: label, + value: value, + }; + }); return; } console.warn(`接口[${props.url}] 返回结果不是一个数组`); diff --git a/apps/web-ele/src/components/form-create/helpers.ts b/apps/web-ele/src/components/form-create/helpers.ts index 5def589cf..3db5bb149 100644 --- a/apps/web-ele/src/components/form-create/helpers.ts +++ b/apps/web-ele/src/components/form-create/helpers.ts @@ -194,6 +194,18 @@ export async function useFormCreateDesigner(designer: Ref) { name: 'DeptSelect', label: '部门选择器', icon: 'icon-tree', + props: [ + { + type: 'select', + field: 'returnType', + title: '返回值类型', + value: 'id', + options: [ + { label: '部门编号', value: 'id' }, + { label: '部门名称', value: 'name' } + ] + } + ] }); const dictSelectRule = useDictSelectRule(); const apiSelectRule0 = useSelectRule({