sard-uniapp
Version:
sard-uniapp 是一套基于 Uniapp + Vue3 框架开发的兼容多端的 UI 组件库
33 lines (32 loc) • 1.14 kB
JavaScript
import { computed, unref } from 'vue';
import { chainGet, isObject } from '../utils';
export const defaultOptonKeys = {
label: 'label',
value: 'value',
disabled: 'disabled',
children: 'children',
isLeaf: 'isLeaf',
};
export function useOptionKeys(props) {
const aliasProps = computed(() => ({
...defaultOptonKeys,
...unref(props).fieldKeys,
...unref(props).optionKeys,
}));
const valueKey = computed(() => unref(props).valueKey);
const getLabel = (option) => chainGet(option, aliasProps.value.label);
const getValue = (option) => chainGet(option, aliasProps.value.value);
const getIsLeaf = (option) => chainGet(option, aliasProps.value.isLeaf);
const getDisabled = (option) => chainGet(option, aliasProps.value.disabled);
const getChildren = (option) => chainGet(option, aliasProps.value.children);
const getKey = (value) => isObject(value) && valueKey.value ? chainGet(value, valueKey.value) : value;
return {
aliasProps,
getLabel,
getValue,
getIsLeaf,
getDisabled,
getChildren,
getKey,
};
}