UNPKG

yanzhen-design-vue

Version:

50 lines (49 loc) 1.19 kB
import { ref, computed } from "vue"; import { unref } from "@yanzhen-libs/utils-vue"; import { handleActiveTabKey } from "../utils/handleActiveTabKey.mjs"; function useContactsLoading({ activeTab, userActiveTab }) { const loadings = ref({ loading: false }); const getLoadingKey = () => handleActiveTabKey({ activeTab, userActiveTab }, "loading"); const loading = computed({ get() { const key = getLoadingKey(); return unref(loadings)[key]; }, set(loading2) { const key = getLoadingKey(); unref(loadings)[key] = loading2; for (const [k] of Object.entries(unref(loadings))) { if (key !== k) { unref(loadings)[k] = false; } } } }); const mores = ref({ more: false }); const getMoreKey = () => handleActiveTabKey({ activeTab, userActiveTab }, "more"); const more = computed({ get() { const key = getMoreKey(); return unref(mores)[key]; }, set(more2) { const key = getMoreKey(); unref(mores)[key] = more2; } }); return { loading, loadings, getLoadingKey, more, mores, getMoreKey }; } export { useContactsLoading };