UNPKG

yanzhen-design-vue

Version:

63 lines (62 loc) 1.86 kB
import { inject, computed, unref, provide } from "vue"; import { useProp } from "@yanzhen-libs/utils-vue"; import { VxeTableConfigContextKey, defaultVxeTableConfig } from "../constants.mjs"; function useVxeTableConfig(key, defaultValue) { const config = inject(VxeTableConfigContextKey, defaultVxeTableConfig()); if (key) { return computed(() => { var _a; const ref = (_a = unref(config)) == null ? void 0 : _a[key]; return unref(ref) ?? unref(defaultValue); }); } return config; } function provideVxeTableConfig(props) { const config = Object.entries(defaultVxeTableConfig()).reduce((prev, [key, defaultValue]) => { const oldValue = useVxeTableConfig(key, defaultValue); prev[key] = computed( () => { var _a; return unref((_a = unref(props)) == null ? void 0 : _a[key]) ?? unref(oldValue); } ); return prev; }, {}); provide(VxeTableConfigContextKey, config); } function useVxeTableTagConfig(props) { const tagRef = useProp("tag"); const tag = useVxeTableConfig("tag"); const isATableTag = computed(() => { const tagKey = "a-table"; switch (true) { case unref(props == null ? void 0 : props.tag) === tagKey: case unref(tagRef) === tagKey: case unref(tag) === tagKey: return true; } return false; }); const isElTableTag = computed(() => { const tagKey = "el-table"; switch (true) { case unref(props == null ? void 0 : props.tag) === tagKey: case unref(tagRef) === tagKey: case unref(tag) === tagKey: return true; } return false; }); const isVxeTable = computed(() => ![unref(isElTableTag), unref(isElTableTag)].includes(true)); return { isATableTag, isElTableTag, isVxeTable }; } export { provideVxeTableConfig, useVxeTableConfig, useVxeTableTagConfig };