This commit is contained in:
dap
2026-04-16 19:56:08 +08:00
74 changed files with 3040 additions and 267 deletions

View File

@@ -17,6 +17,7 @@ defineOptions({ name: 'ApiComponent', inheritAttrs: false });
const props = withDefaults(defineProps<ApiComponentProps>(), {
labelField: 'label',
valueField: 'value',
labelFn: undefined,
disabledField: 'disabled',
childrenField: '',
optionsPropName: 'options',
@@ -54,33 +55,37 @@ const hasPendingRequest = ref(false);
const getOptions = computed(() => {
const {
labelField,
labelFn,
valueField,
disabledField,
childrenField,
numberToString,
} = props;
const refOptionsData = unref(refOptions);
function transformData(data: OptionsItem[]): OptionsItem[] {
function transformData(data: OptionsItem[] = []): OptionsItem[] {
return data.map((item) => {
const value = get(item, valueField);
const disabled = get(item, disabledField);
const children = childrenField ? get(item, childrenField) : item.children;
return {
...objectOmit(item, [labelField, valueField, disabled, childrenField]),
label: get(item, labelField),
...objectOmit(item, [
labelField,
valueField,
disabledField,
...(childrenField ? [childrenField] : []),
]),
label: labelFn ? labelFn(item) : get(item, labelField),
value: numberToString ? `${value}` : value,
disabled: get(item, disabledField),
...(childrenField && item[childrenField]
? { children: transformData(item[childrenField]) }
...(Array.isArray(children) && children.length > 0
? { children: transformData(children) }
: {}),
};
});
}
const data: OptionsItem[] = transformData(refOptionsData);
const data = transformData(unref(refOptions));
return data.length > 0 ? data : props.options;
return data.length > 0 ? data : transformData(props.options);
});
const bindProps = computed(() => {

View File

@@ -1,5 +1,6 @@
export { default as ApiComponent } from './api-component.vue';
export type {
ApiComponentLabelFn,
ApiComponentOptionsItem,
ApiComponentProps,
ApiComponentSharedProps,

View File

@@ -10,6 +10,8 @@ export type ApiComponentOptionsItem = {
value?: number | string;
};
export type ApiComponentLabelFn = (item: ApiComponentOptionsItem) => string;
export interface ApiComponentProps {
/** 组件 */
component: Component;
@@ -23,6 +25,8 @@ export interface ApiComponentProps {
resultField?: string;
/** label字段名 */
labelField?: string;
/** 通过选项数据自定义label */
labelFn?: ApiComponentLabelFn;
/** children字段名需要层级数据的组件可用 */
childrenField?: string;
/** value字段名 */

View File

@@ -27,6 +27,7 @@ export {
VbenContextMenu,
VbenCountToAnimator,
VbenFullScreen,
VbenIconButton,
VbenInputPassword,
VbenLoading,
VbenLogo,