bonree-custom-utils
Advanced tools
Comparing version 0.0.6 to 0.0.7
45
index.js
@@ -124,2 +124,3 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
var CSSLinkId = "customCss"; | ||
// 获取定制配置项 | ||
@@ -190,2 +191,44 @@ function getConfig(key) { | ||
} | ||
// 插入css | ||
function setTheme(url) { | ||
var linkExisted = document.getElementById(CSSLinkId); | ||
if (linkExisted) { | ||
var link = document.getElementById(CSSLinkId); | ||
link.href = url; | ||
} | ||
else { | ||
var link = document.createElement("link"); | ||
link.rel = "stylesheet"; | ||
link.type = "text/css"; | ||
link.href = url; | ||
link.id = "customCss"; | ||
var head = document.getElementsByTagName("head")[0]; | ||
head.appendChild(link); | ||
} | ||
} | ||
// 初始化主题 | ||
function initTheme() { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var theme; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, getTheme()]; | ||
case 1: | ||
theme = _a.sent(); | ||
if (theme) { | ||
if (theme.css) { | ||
setTheme(String("/" + theme.css)); | ||
} | ||
else { | ||
console.error("未构建样式或样式构建失败"); | ||
} | ||
} | ||
else { | ||
console.error("themes.json加载失败!"); | ||
} | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
} | ||
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({ | ||
@@ -195,2 +238,4 @@ getConfig: getConfig, | ||
getTheme: getTheme, | ||
initTheme: initTheme, | ||
setTheme: setTheme, | ||
}); | ||
@@ -197,0 +242,0 @@ |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("axios")):"function"==typeof define&&define.amd?define(["axios"],t):"object"==typeof exports?exports.index=t(require("axios")):e.index=t(e.axios)}(self,(function(e){return(()=>{"use strict";var t={300:t=>{t.exports=e}},n={};function r(e){var o=n[e];if(void 0!==o)return o.exports;var u=n[e]={exports:{}};return t[e](u,u.exports,r),u.exports}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var o={};return(()=>{r.d(o,{default:()=>i});var e=r(300),t=r.n(e),n=function(e,t,n,r){return new(n||(n=Promise))((function(o,u){function i(e){try{c(r.next(e))}catch(e){u(e)}}function s(e){try{c(r.throw(e))}catch(e){u(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,s)}c((r=r.apply(e,t||[])).next())}))},u=function(e,t){var n,r,o,u,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return u={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u;function s(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return i.label++,{value:u[1],done:!1};case 5:i.label++,r=u[1],u=[0];continue;case 7:u=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){i=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){i.label=u[1];break}if(6===u[0]&&i.label<o[1]){i.label=o[1],o=u;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(u);break}o[2]&&i.ops.pop(),i.trys.pop();continue}u=t.call(e,i)}catch(e){u=[6,e],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}};const i={getConfig:function(e){return n(this,void 0,void 0,(function(){var n;return u(this,(function(r){switch(r.label){case 0:return[4,t().get("/customs/configs.json?t="+(new Date).getTime())];case 1:return 200==(n=r.sent()).status?[2,(n.data||[]).find((function(t){return t.key===e}))]:(console.error("获取定制配置项失败,请确认public/customs/configs.json文件是否存在"),[2,null])}}))}))},getConfigs:function(e){return n(this,void 0,void 0,(function(){var n;return u(this,(function(r){switch(r.label){case 0:return[4,t().get("/customs/configs.json?t="+(new Date).getTime())];case 1:return 200==(n=r.sent()).status?[2,(n.data||[]).filter((function(t){return null!=e.find((function(e){return t.key===e}))}))]:(console.error("获取定制配置项失败,请确认public/customs/configs.json文件是否存在"),[2,null])}}))}))},getTheme:function(){return n(this,void 0,void 0,(function(){var e;return u(this,(function(n){switch(n.label){case 0:return[4,t().get("/customs/themes.json?t="+(new Date).getTime())];case 1:return 200==(e=n.sent()).status?[2,(e.data||[]).find((function(e){return 1==e.enable}))]:(console.error("获取定制主题失败,请确认public/customs/themes.json文件是否存在"),[2,null])}}))}))}}})(),o=o.default})()})); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("axios")):"function"==typeof define&&define.amd?define(["axios"],t):"object"==typeof exports?exports.index=t(require("axios")):e.index=t(e.axios)}(self,(function(e){return(()=>{"use strict";var t={300:t=>{t.exports=e}},n={};function r(e){var o=n[e];if(void 0!==o)return o.exports;var s=n[e]={exports:{}};return t[e](s,s.exports,r),s.exports}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var o={};return(()=>{r.d(o,{default:()=>a});var e=r(300),t=r.n(e),n=function(e,t,n,r){return new(n||(n=Promise))((function(o,s){function u(e){try{c(r.next(e))}catch(e){s(e)}}function i(e){try{c(r.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(u,i)}c((r=r.apply(e,t||[])).next())}))},s=function(e,t){var n,r,o,s,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return s={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function i(s){return function(i){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return u.label++,{value:s[1],done:!1};case 5:u.label++,r=s[1],s=[0];continue;case 7:s=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){u=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){u.label=s[1];break}if(6===s[0]&&u.label<o[1]){u.label=o[1],o=s;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(s);break}o[2]&&u.ops.pop(),u.trys.pop();continue}s=t.call(e,u)}catch(e){s=[6,e],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,i])}}},u="customCss";function i(){return n(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return[4,t().get("/customs/themes.json?t="+(new Date).getTime())];case 1:return 200==(e=n.sent()).status?[2,(e.data||[]).find((function(e){return 1==e.enable}))]:(console.error("获取定制主题失败,请确认public/customs/themes.json文件是否存在"),[2,null])}}))}))}function c(e){var t;document.getElementById(u)?(t=document.getElementById(u)).href=e:((t=document.createElement("link")).rel="stylesheet",t.type="text/css",t.href=e,t.id="customCss",document.getElementsByTagName("head")[0].appendChild(t))}const a={getConfig:function(e){return n(this,void 0,void 0,(function(){var n;return s(this,(function(r){switch(r.label){case 0:return[4,t().get("/customs/configs.json?t="+(new Date).getTime())];case 1:return 200==(n=r.sent()).status?[2,(n.data||[]).find((function(t){return t.key===e}))]:(console.error("获取定制配置项失败,请确认public/customs/configs.json文件是否存在"),[2,null])}}))}))},getConfigs:function(e){return n(this,void 0,void 0,(function(){var n;return s(this,(function(r){switch(r.label){case 0:return[4,t().get("/customs/configs.json?t="+(new Date).getTime())];case 1:return 200==(n=r.sent()).status?[2,(n.data||[]).filter((function(t){return null!=e.find((function(e){return t.key===e}))}))]:(console.error("获取定制配置项失败,请确认public/customs/configs.json文件是否存在"),[2,null])}}))}))},getTheme:i,initTheme:function(){return n(this,void 0,void 0,(function(){var e;return s(this,(function(t){switch(t.label){case 0:return[4,i()];case 1:return(e=t.sent())?e.css?c(String("/"+e.css)):console.error("未构建样式或样式构建失败"):console.error("themes.json加载失败!"),[2]}}))}))},setTheme:c}})(),o=o.default})()})); | ||
//# sourceMappingURL=index.min.js.map |
{ | ||
"name": "bonree-custom-utils", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "bonree-custom-utils", | ||
@@ -5,0 +5,0 @@ "main": "./index.min.js", |
@@ -19,2 +19,4 @@ export interface Config { | ||
declare function getTheme(): Promise<Theme | null>; | ||
declare function setTheme(url: string): void; | ||
declare function initTheme(): Promise<void>; | ||
declare const _default: { | ||
@@ -24,4 +26,6 @@ getConfig: typeof getConfig; | ||
getTheme: typeof getTheme; | ||
initTheme: typeof initTheme; | ||
setTheme: typeof setTheme; | ||
}; | ||
export default _default; | ||
//# sourceMappingURL=index.d.ts.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
32006
282