UNPKG

yanzhen-design-vue

Version:

48 lines (47 loc) 1.27 kB
"use strict"; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const vue = require("vue"); const utilsVue = require("@yanzhen-libs/utils-vue"); const utils = require("@yanzhen-libs/utils"); const contacts = require("../constants/contacts.cjs"); function useSelectedIds() { const refs = utilsVue.useProps([...contacts.contactsModelValueType]); const config = vue.reactive({ ids: [] }); const watcher = utilsVue.createWatcher(); function hasValue(value) { return ["string", "number"].includes(typeof value); } function setIds() { const ids = []; const values = Object.values(utilsVue.unref(refs)); for (const value of values) { if (hasValue(value) && !ids.includes(value)) { ids.push(value); } else if (!utils.isEmptyArray(value)) { for (const val of value) { if (hasValue(val) && !ids.includes(val)) { ids.push(val); } } } } config.ids = ids; } watcher.set("ids", { source: () => utilsVue.unref(refs), handler() { setIds(); }, deep: true, debounce: 300 }); vue.onMounted(() => { setIds(); }); return vue.computed(() => { return config.ids; }); } exports.useSelectedIds = useSelectedIds;