@ued_fpi/data-visual
Version:
<br /> <br /> <div style="text-align:center"> <b style="font-size:30px">@ued_fpi/data-visual</b> <p>基于Vite4+TypeScript的Vue3大屏组件库开发框架</p> <img style="display:inline" src="https://img.shields.io/npm/v/@ued_fpi/data-visual" />
93 lines (90 loc) • 2.57 kB
JavaScript
import { ref } from 'vue';
import Config from './wgms/config/index.mjs';
import Config$1 from './ipes/config/index.mjs';
import Config$2 from './aims/config/index.mjs';
import Config$3 from './bmp/config/index.mjs';
const install = (comp) => {
comp.install = (app) => {
const name = comp.name || comp.__name;
app.component(name, comp);
};
return comp;
};
const setDomain = (domain, type) => {
switch (type) {
case "aims":
Config$2.domain = domain;
break;
case "ipes":
Config$1.domain = domain;
break;
case "bmp":
Config$3.domain = domain;
break;
case "wgms":
Config.domain = domain;
break;
default:
Config.domain = domain;
Config$1.domain = domain;
Config$2.domain = domain;
Config$3.domain = domain;
break;
}
};
const useThemeValue = (styleVariables) => {
return getComputedStyle(document.documentElement).getPropertyValue(styleVariables);
};
const useThemeHook = () => {
const htmlDom = document.querySelector("html");
if (!htmlDom)
return { isDark: ref(false) };
const isDark = ref(!!htmlDom.classList.contains("dark"));
const observer = new MutationObserver((mutationsList) => {
for (const mutation of mutationsList) {
if (mutation.type === "attributes" && mutation.attributeName === "class") {
const currentClass = mutation.target.className;
isDark.value = currentClass.includes("dark");
}
}
});
const observerOptions = {
attributes: true,
attributeFilter: ["class"]
};
observer.observe(htmlDom, observerOptions);
return {
isDark
};
};
function replaceVarStrings(obj) {
const newObj = Array.isArray(obj) ? [] : {};
for (const key in obj) {
if (typeof obj[key] === "object") {
newObj[key] = replaceVarStrings(obj[key]);
} else if (typeof obj[key] === "string" && obj[key].startsWith("var(") && obj[key].endsWith(")")) {
const varContent = obj[key].slice(4, -1);
newObj[key] = useThemeValue(varContent);
} else {
newObj[key] = obj[key];
}
}
return newObj;
}
const setConfig = (type, resetFn) => {
switch (type) {
case "aims":
Object.assign(Config$2, resetFn(Config$2));
break;
case "wgms":
Object.assign(Config, resetFn(Config));
break;
case "ipes":
Object.assign(Config$1, resetFn(Config$1));
break;
case "bmp":
Object.assign(Config$3, resetFn(Config$3));
break;
}
};
export { install, replaceVarStrings, setConfig, setDomain, useThemeHook, useThemeValue };