feat: 【antd/ele】【infra】表单设计器:添加返回值类型配置到部门选择器
This commit is contained in:
@@ -69,6 +69,11 @@ export function useApiSelect(option: ApiSelectProps) {
|
|||||||
type: String,
|
type: String,
|
||||||
default: 'label',
|
default: 'label',
|
||||||
},
|
},
|
||||||
|
// 返回值类型(用于部门选择器等):id 返回 ID,name 返回名称
|
||||||
|
returnType: {
|
||||||
|
type: String,
|
||||||
|
default: 'id',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
setup(props) {
|
setup(props) {
|
||||||
const attrs = useAttrs();
|
const attrs = useAttrs();
|
||||||
@@ -129,10 +134,21 @@ export function useApiSelect(option: ApiSelectProps) {
|
|||||||
|
|
||||||
function parseOptions0(data: any[]) {
|
function parseOptions0(data: any[]) {
|
||||||
if (Array.isArray(data)) {
|
if (Array.isArray(data)) {
|
||||||
options.value = data.map((item: any) => ({
|
options.value = data.map((item: any) => {
|
||||||
label: parseExpression(item, props.labelField),
|
const label = parseExpression(item, props.labelField);
|
||||||
value: parseExpression(item, props.valueField),
|
let value = parseExpression(item, props.valueField);
|
||||||
}));
|
|
||||||
|
// 根据 returnType 决定返回值
|
||||||
|
// 如果设置了 returnType 为 'name',则返回 label 作为 value
|
||||||
|
if (props.returnType === 'name') {
|
||||||
|
value = label;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
label: label,
|
||||||
|
value: value,
|
||||||
|
};
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.warn(`接口[${props.url}] 返回结果不是一个数组`);
|
console.warn(`接口[${props.url}] 返回结果不是一个数组`);
|
||||||
|
|||||||
@@ -194,6 +194,18 @@ export async function useFormCreateDesigner(designer: Ref) {
|
|||||||
name: 'DeptSelect',
|
name: 'DeptSelect',
|
||||||
label: '部门选择器',
|
label: '部门选择器',
|
||||||
icon: 'icon-tree',
|
icon: 'icon-tree',
|
||||||
|
props: [
|
||||||
|
{
|
||||||
|
type: 'select',
|
||||||
|
field: 'returnType',
|
||||||
|
title: '返回值类型',
|
||||||
|
value: 'id',
|
||||||
|
options: [
|
||||||
|
{ label: '部门编号', value: 'id' },
|
||||||
|
{ label: '部门名称', value: 'name' }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
});
|
});
|
||||||
const dictSelectRule = useDictSelectRule();
|
const dictSelectRule = useDictSelectRule();
|
||||||
const apiSelectRule0 = useSelectRule({
|
const apiSelectRule0 = useSelectRule({
|
||||||
|
|||||||
@@ -69,6 +69,11 @@ export function useApiSelect(option: ApiSelectProps) {
|
|||||||
type: String,
|
type: String,
|
||||||
default: 'label',
|
default: 'label',
|
||||||
},
|
},
|
||||||
|
// 返回值类型(用于部门选择器等):id 返回 ID,name 返回名称
|
||||||
|
returnType: {
|
||||||
|
type: String,
|
||||||
|
default: 'id',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
setup(props) {
|
setup(props) {
|
||||||
const attrs = useAttrs();
|
const attrs = useAttrs();
|
||||||
@@ -129,10 +134,21 @@ export function useApiSelect(option: ApiSelectProps) {
|
|||||||
|
|
||||||
function parseOptions0(data: any[]) {
|
function parseOptions0(data: any[]) {
|
||||||
if (Array.isArray(data)) {
|
if (Array.isArray(data)) {
|
||||||
options.value = data.map((item: any) => ({
|
options.value = data.map((item: any) => {
|
||||||
label: parseExpression(item, props.labelField),
|
const label = parseExpression(item, props.labelField);
|
||||||
value: parseExpression(item, props.valueField),
|
let value = parseExpression(item, props.valueField);
|
||||||
}));
|
|
||||||
|
// 根据 returnType 决定返回值
|
||||||
|
// 如果设置了 returnType 为 'name',则返回 label 作为 value
|
||||||
|
if (props.returnType === 'name') {
|
||||||
|
value = label;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
label: label,
|
||||||
|
value: value,
|
||||||
|
};
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.warn(`接口[${props.url}] 返回结果不是一个数组`);
|
console.warn(`接口[${props.url}] 返回结果不是一个数组`);
|
||||||
|
|||||||
@@ -194,6 +194,18 @@ export async function useFormCreateDesigner(designer: Ref) {
|
|||||||
name: 'DeptSelect',
|
name: 'DeptSelect',
|
||||||
label: '部门选择器',
|
label: '部门选择器',
|
||||||
icon: 'icon-tree',
|
icon: 'icon-tree',
|
||||||
|
props: [
|
||||||
|
{
|
||||||
|
type: 'select',
|
||||||
|
field: 'returnType',
|
||||||
|
title: '返回值类型',
|
||||||
|
value: 'id',
|
||||||
|
options: [
|
||||||
|
{ label: '部门编号', value: 'id' },
|
||||||
|
{ label: '部门名称', value: 'name' }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
});
|
});
|
||||||
const dictSelectRule = useDictSelectRule();
|
const dictSelectRule = useDictSelectRule();
|
||||||
const apiSelectRule0 = useSelectRule({
|
const apiSelectRule0 = useSelectRule({
|
||||||
|
|||||||
Reference in New Issue
Block a user