yanzhen-design-vue
Version:
51 lines (50 loc) • 1.74 kB
JavaScript
import { computed } from "vue";
import { useProp, unref, buildProps, definePropType, useDynamicProps } from "@yanzhen-libs/utils-vue";
import { kebabCase } from "@yanzhen-libs/utils";
import { flattenDeep, uniq } from "lodash-es";
import { Contacts, contactsTypes, contactsModelValueType } from "../constants/contacts.mjs";
import { userTypes } from "../constants/user.mjs";
function useContactsTitle() {
const title = useProp("title");
return computed(() => {
return unref(title) ?? "";
});
}
const showUserTabKeyPropValues = userTypes.map((k) => `${k}-${Contacts.USER}`);
const showTabKeyPropValues = [...showUserTabKeyPropValues, ...contactsTypes];
const showTabKeysProps = buildProps({
showTabKeys: {
type: definePropType(Array),
values: showTabKeyPropValues,
default: () => []
}
});
function useContactsShowTabKeys() {
const dynamicProps = useDynamicProps(true);
const _showTabKeys = useProp("showTabKeys");
const propsTabKeys = computed(
() => contactsModelValueType.filter((key) => {
var _a;
return key !== "value" && ((_a = unref(dynamicProps)) == null ? void 0 : _a.includes(key));
}).map((key) => kebabCase(key).split("-")[0])
);
return computed(() => {
const tabKeys = unref(propsTabKeys);
const showTabKeys = flattenDeep([unref(_showTabKeys)]);
if (showTabKeys.length === 0 && tabKeys.length === 0) {
return [...contactsTypes];
}
const keys = uniq([...showTabKeys, ...tabKeys]);
if (keys.includes("user") && !keys.includes(Contacts.USUALLY)) {
keys.push(Contacts.USUALLY);
}
return keys;
});
}
export {
showTabKeyPropValues,
showTabKeysProps,
showUserTabKeyPropValues,
useContactsShowTabKeys,
useContactsTitle
};