@zhsz/cool-design-crud
Version:
70 lines (69 loc) • 1.6 kB
JavaScript
;
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const vue = require("vue");
const index = require("../utils/index.js");
function useRefs() {
const refs = vue.reactive({});
function setRefs(name) {
return (el) => {
refs[name] = el;
};
}
return { refs, setRefs };
}
function useGlobal() {
return vue.inject("globalOptions");
}
function useTools() {
const browser = vue.inject("browser");
const global = useGlobal();
const slots = vue.useSlots();
function getValue(data, params) {
if (vue.isRef(data)) {
return data.value;
} else {
if (index.isFunction(data)) {
return data(params);
} else {
return data;
}
}
}
return { browser, ...global, slots, getValue };
}
function useCore() {
const crud = vue.inject("crud");
const mitt = vue.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 = vue.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();
}
exports.useConfig = useConfig;
exports.useCore = useCore;
exports.useElApi = useElApi;
exports.useEventListener = useEventListener;
exports.useGlobal = useGlobal;
exports.useRefs = useRefs;
exports.useTools = useTools;