重构解析驱动, 替换默认支持配置文件格式为 yaml

develop
就眠仪式 2020-12-06 13:25:55 +08:00
parent c916582785
commit aeedc9acef
7 changed files with 2143 additions and 86 deletions

View File

@ -1,10 +1,11 @@
layui.define(['table', 'jquery', 'element', 'form', 'tab', 'menu', 'frame'],
layui.define(['table', 'jquery', 'element', 'yaml','form', 'tab', 'menu', 'frame'],
function(exports) {
"use strict";
const $ = layui.jquery,
form = layui.form,
element = layui.element,
yaml = layui.yaml,
pearTab = layui.tab,
pearMenu = layui.menu,
pearFrame = layui.frame;
@ -27,19 +28,13 @@ layui.define(['table', 'jquery', 'element', 'form', 'tab', 'menu', 'frame'],
if (initConfig !== undefined) {
applyConfig(initConfig);
} else {
pearAdmin.readConfig().then(function(param) {
applyConfig(param);
});
applyConfig(pearAdmin.readConfig());
}
}
this.readConfig = function() {
const defer = $.Deferred();
const configUrl = (configPath === '' ? "pear.config.json" : configPath) + "?fresh=" + Math.random();
$.getJSON(configUrl, function(result) {
defer.resolve(result)
});
return defer.promise();
const configUrl = configPath === '' ? "pear.config.yml" : configPath;
return yaml.load(configUrl);
}
this.logoRender = function(param) {

File diff suppressed because it is too large Load Diff

View File

@ -40,5 +40,6 @@ layui.config({
loading: "loading", // 加载组件
cropper:"cropper", // 裁剪组件
convert:"convert", // 数据转换
context:"context" // 上下文组件
context:"context", // 上下文组件
yaml:"yaml"
});

View File

@ -40,5 +40,6 @@ layui.config({
loading: "loading", // 加载组件
cropper:"cropper", // 裁剪组件
convert:"convert", // 数据转换
context:"context" // 上下文组件
context:"context", // 上下文组件
yaml:"yaml"
});

View File

@ -1,71 +0,0 @@
{
"logo": {
"title": "Pear Admin",
"image": "admin/images/logo.png"
},
"menu": {
"data": "admin/data/menu.json",
"accordion": true,
"control": false,
"select": "10",
"async": true
},
"tab": {
"muiltTab": true,
"keepState": true,
"tabMax": 30,
"index": {
"id": "10",
"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-website",
"title": "官方网站",
"href": "http://www.pearadmin.com"
},
{
"icon": "layui-icon layui-icon-read",
"title": "开发文档",
"href": "http://www.pearadmin.com/doc/"
},
{
"icon": "layui-icon layui-icon-fonts-code",
"title": "开源地址",
"href": "https://gitee.com/pear-admin/Pear-Admin-Layui"
},
{
"icon": "layui-icon layui-icon-survey",
"title": "问答社区",
"href": "http://forum.pearadmin.com/"
}
],
"other": {
"keepLoad": 1200
}
}

70
config/pear.config.yml Normal file
View File

@ -0,0 +1,70 @@
---
## 网站配置
logo:
## 网站名称
title: "Pear Admin"
## 网站图标
image: "admin/images/logo.png"
## 菜单配置
menu:
## 菜单数据来源
data: "admin/data/menu.json"
## 是否同时只打开一个菜单目录
accordion: true
## 是否开启多系统菜单模式
control: false
## 默认选中的菜单项
select: "10"
## 是否开启异步菜单false 时 data 属性设置为菜单数据false 时为 json 文件或后端接口
async: true
## 视图内容配置
tab:
## 是否开启多选项卡
muiltTab: true
## 切换选项卡时,是否刷新页面状态
keepState: true
## 最大可打开的选项卡数量
tabMax: "30"
## 默认选项卡数据
index:
id: "10" ## 标识 ID , 建议与菜单项中的 ID 一致
href: "view/console/console1.html" ## 页面地址
title: "首页" ## 标题
## 主题配置
theme:
## 默认主题色,对应 colors 配置中的 ID 标识
defaultColor: "2"
## 默认的菜单主题 dark-theme 黑 / light 白
defaultMenu: "dark-theme"
## 是否允许用户自定义切换主题false 时关闭界面自定义主题面板
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-website"
title: "官方网站"
href: "http://www.pearadmin.com"
- icon: "layui-icon layui-icon-read"
title: "开发文档"
href: "http://www.pearadmin.com/doc/"
- icon: "layui-icon layui-icon-fonts-code"
title: "开源地址"
href: "https://gitee.com/pear-admin/Pear-Admin-Layui"
- icon: "layui-icon layui-icon-survey"
title: "问答社区"
href: "http://forum.pearadmin.com/"
## 其他配置
other:
## 主页默认加载动画时长
keepLoad: "1200"

View File

@ -78,7 +78,7 @@
<script>
layui.use(['admin','jquery',"convert"], function() {
var admin = layui.admin,
$ = layui.jquery;
$ = layui.jquery,
convert = layui.convert;
var image = new Image();
@ -86,9 +86,9 @@
image.onload = function(){
$(".layui-nav-img").attr("src", convert.imageToBase64(image));
}
// 重新设置配置文件读取路径,默认为同级目录下的 pear.config.json
admin.setConfigPath("config/pear.config.json");
admin.setConfigPath("config/pear.config.yml");
// 进行框架初始化
admin.render();