Merge branch 'main' of https://github.com/vbenjs/vue-vben-admin into dev
This commit is contained in:
@@ -59,9 +59,15 @@ interface Props {
|
||||
* - `first`:自动选择第一个选项
|
||||
* - `last`:自动选择最后一个选项
|
||||
* - `one`: 当请求的结果只有一个选项时,自动选择该选项
|
||||
* - 函数:自定义选择逻辑,函数的参数为请求的结果数组,返回值为选择的选项
|
||||
* - false:不自动选择(默认)
|
||||
*/
|
||||
autoSelect?: 'first' | 'last' | 'one' | false;
|
||||
autoSelect?:
|
||||
| 'first'
|
||||
| 'last'
|
||||
| 'one'
|
||||
| ((item: OptionsItem[]) => OptionsItem)
|
||||
| false;
|
||||
}
|
||||
|
||||
defineOptions({ name: 'ApiComponent', inheritAttrs: false });
|
||||
@@ -209,29 +215,37 @@ function emitChange() {
|
||||
unref(getOptions).length > 0
|
||||
) {
|
||||
let firstOption;
|
||||
switch (props.autoSelect) {
|
||||
case 'first': {
|
||||
firstOption = unref(getOptions)[0];
|
||||
break;
|
||||
}
|
||||
case 'last': {
|
||||
firstOption = unref(getOptions)[unref(getOptions).length - 1];
|
||||
break;
|
||||
}
|
||||
case 'one': {
|
||||
if (unref(getOptions).length === 1) {
|
||||
if (isFunction(props.autoSelect)) {
|
||||
firstOption = props.autoSelect(unref(getOptions));
|
||||
} else {
|
||||
switch (props.autoSelect) {
|
||||
case 'first': {
|
||||
firstOption = unref(getOptions)[0];
|
||||
break;
|
||||
}
|
||||
case 'last': {
|
||||
firstOption = unref(getOptions)[unref(getOptions).length - 1];
|
||||
break;
|
||||
}
|
||||
case 'one': {
|
||||
if (unref(getOptions).length === 1) {
|
||||
firstOption = unref(getOptions)[0];
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (firstOption) modelValue.value = firstOption[props.valueField];
|
||||
if (firstOption) modelValue.value = firstOption.value;
|
||||
}
|
||||
emit('optionsChange', unref(getOptions));
|
||||
}
|
||||
const componentRef = ref();
|
||||
defineExpose({
|
||||
/** 获取options数据 */
|
||||
getOptions: () => unref(getOptions),
|
||||
/** 获取当前值 */
|
||||
getValue: () => unref(modelValue),
|
||||
/** 获取被包装的组件实例 */
|
||||
getComponentRef: <T = any,>() => componentRef.value as T,
|
||||
/** 更新Api参数 */
|
||||
|
Reference in New Issue
Block a user