增加 yml / json 配置文件格式兼容

develop
就眠仪式 2021-01-01 20:17:19 +08:00
parent b51a0ce64d
commit 9962790b3d
6 changed files with 98 additions and 10 deletions

View File

@ -341,7 +341,7 @@
left: 50%;
width: 1px;
height: 0;
border: 1px solid #F2F2F2;
border: 2px solid #F2F2F2;
transition: all .3s;
-webkit-transition: all .3s;
opacity: 0;

View File

@ -18,11 +18,17 @@ layui.define(['table', 'jquery', 'element', 'yaml','form', 'tab', 'menu', 'frame
const pearAdmin = new function() {
let configPath = '';
// 默认配置
let configType = 'yml';
let configPath = 'pear.config.yml';
this.setConfigPath = function(path) {
configPath = path;
}
this.setConfigType = function(type) {
configType = type;
}
this.render = function(initConfig) {
if (initConfig !== undefined) {
@ -33,8 +39,23 @@ layui.define(['table', 'jquery', 'element', 'yaml','form', 'tab', 'menu', 'frame
}
this.readConfig = function() {
const configUrl = configPath === '' ? "pear.config.yml" : configPath;
return yaml.load(configUrl);
if(configType === "yml"){
return yaml.load(configPath);
}
else
{
let data;
$.ajax({
url:configPath,
type:'get',
dataType:'json',
async: false,
success:function(result){
data = result;
}
})
return data;
}
}
this.logoRender = function(param) {
@ -205,7 +226,7 @@ layui.define(['table', 'jquery', 'element', 'yaml','form', 'tab', 'menu', 'frame
// 自 定 义 样 式 选 择 边 框 配 色
style +=
'.pearone-color .color-content li.layui-this:after, .pearone-color .color-content li:hover:after {border: ' +
color + ' 2px solid!important;}';
color + ' 3px solid!important;}';
style += '.layui-nav .layui-nav-child dd.layui-this a, .layui-nav-child dd.layui-this{background-color:' + color +
'!important}';

View File

@ -7,11 +7,11 @@ window.rootPath = (function(src) {
})();
/**
* 扩展包集成
* 核心依赖
* */
layui.config({
base: rootPath + "modules/",
version: true
version: "3.3.9.Release"
}).extend({
admin: "admin", // 框架布局组件
menu: "menu", // 数据菜单组件
@ -43,4 +43,4 @@ layui.config({
yaml:"yaml", // yaml 解析组件
context: "context", // 上下文组件
http: "http" // ajax请求组件
});
});

View File

@ -7,11 +7,11 @@ window.rootPath = (function(src) {
})();
/**
* 扩展包集成
* 核心依赖
* */
layui.config({
base: rootPath + "modules/",
version: true
version: "3.3.9.Release"
}).extend({
admin: "admin", // 框架布局组件
menu: "menu", // 数据菜单组件

65
config/pear.config.json Normal file
View File

@ -0,0 +1,65 @@
{
"logo": {
"title": "Pear Admin",
"image": "admin/images/logo.png"
},
"menu": {
"data": "admin/data/menu.json",
"accordion": true,
"control": false,
"select": "0"
},
"tab": {
"muiltTab": true,
"keepState": true,
"tabMax": 30,
"index": {
"id": "0",
"href": "view/console/console1.html",
"title": "首页"
}
},
"theme": {
"defaultColor": "2",
"defaultMenu": "dark-theme",
"allowCustom": true
},
"colors": [{
"id": "1",
"color": "#FF5722"
},
{
"id": "2",
"color": "#5FB878"
},
{
"id": "3",
"color": "#1E9FFF"
}, {
"id": "4",
"color": "#FFB800"
}, {
"id": "5",
"color": "darkgray"
}
],
"links": [{
"icon": "layui-icon layui-icon-auz",
"title": "官方网站",
"href": "http://www.pearadmin.com"
},
{
"icon": "layui-icon layui-icon-auz",
"title": "开发文档",
"href": "http://www.pearadmin.com"
},
{
"icon": "layui-icon layui-icon-auz",
"title": "开源地址",
"href": "https://gitee.com/Jmysy/Pear-Admin-Layui"
}
],
"other": {
"keepLoad": 1200
}
}

View File

@ -90,6 +90,8 @@
}
// 框架初始化时会读取 根目录下 pear.config.yml 文件作为初始化配置
// 你可以通过 admin.setConfigPath 方法修改配置文件位置
// 你可以通过 admin.setConfigType 方法修改配置文件类型
admin.setConfigType("yml");
admin.setConfigPath("config/pear.config.yml");
admin.render();
})