代码拉取完成,页面将自动刷新
import getConfig from 'next/config';
const { publicRuntimeConfig = {} } = getConfig() || {};
const { next_dynamic_antd_theme = {} } = publicRuntimeConfig;
const { themes, lessFilePath, lessJSPath } = next_dynamic_antd_theme;
function loadJS(src, callback) {
const script = document.createElement('script');
script.src = src; //'https://cdnjs.cloudflare.com/ajax/libs/less.js/2.7.2/less.min.js';
script.onload = callback;
document.body.append(script);
}
function loadLess(src) {
const link = document.createElement('link');
link.rel = 'stylesheet/less';
link.type = 'text/css';
link.href = src;
return link;
}
function loadLessAndJS(callback) {
if (!window.less) {
loadJS(lessJSPath, () => {
window.less.options.javascriptEnabled = true;
window.less.sheets = [loadLess(lessFilePath)];
if (!!callback) callback();
});
}
}
function modifyVars(vars) {
if (!!window.less) {
window.less.modifyVars(vars).catch((error) => {
console.log(`Failed to update theme`, error);
});
} else {
console.log('Theme only change in client side render, not server side render');
}
}
function __changeTheme(theme) {
if (!theme) modifyVars();
else if (typeof theme === 'string' || theme == 'dark')
modifyVars({ ...themes.default, ...themes[theme] });
else modifyVars({ ...themes.default, ...theme });
}
export default function changeTheme(theme = {}) {
if (!!window.less) {
__changeTheme(theme);
} else {
loadLessAndJS(() => __changeTheme(theme));
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。