UNPKG

@zhsz/cool-design-crud

Version:

70 lines (69 loc) 1.39 kB
import { reactive, inject, useSlots, isRef } from "vue"; import { isFunction } from "../utils/index.mjs"; function useRefs() { const refs = reactive({}); function setRefs(name) { return (el) => { refs[name] = el; }; } return { refs, setRefs }; } function useGlobal() { return inject("globalOptions"); } function useTools() { const browser = inject("browser"); const global = useGlobal(); const slots = useSlots(); function getValue(data, params) { if (isRef(data)) { return data.value; } else { if (isFunction(data)) { return data(params); } else { return data; } } } return { browser, ...global, slots, getValue }; } function useCore() { const crud = inject("crud"); const mitt = inject("mitt"); return { crud, mitt }; } function useElApi(keys, el) { const apis = {}; keys.forEach((e) => { apis[e] = (...args) => { return el.value[e](...args); }; }); return apis; } function useConfig({ props }) { const config = reactive(props); function setConfig(data) { Object.assign(config, data); } return { setConfig, ...config }; } function useEventListener(name, cb) { window.removeEventListener(name, cb); window.addEventListener(name, cb); cb(); } export { useConfig, useCore, useElApi, useEventListener, useGlobal, useRefs, useTools };