mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-06 03:58:04 +08:00
[更新]修改后台管理控制JS
This commit is contained in:
parent
6454207b0a
commit
a21ca2337c
275
static/admin.js
275
static/admin.js
@ -117,7 +117,7 @@ $(function () {
|
|||||||
this.errMsg = '{status}服务器繁忙,请稍候再试!';
|
this.errMsg = '{status}服务器繁忙,请稍候再试!';
|
||||||
// 内容区域动态加载后初始化
|
// 内容区域动态加载后初始化
|
||||||
this.reInit = function ($container) {
|
this.reInit = function ($container) {
|
||||||
$.validate.listen.call(this), JPlaceHolder.init();
|
$.vali.listen(this), JPlaceHolder.init();
|
||||||
$container.find('[required]').parent().prevAll('label').addClass('label-required');
|
$container.find('[required]').parent().prevAll('label').addClass('label-required');
|
||||||
};
|
};
|
||||||
// 在内容区显示视图
|
// 在内容区显示视图
|
||||||
@ -214,53 +214,101 @@ $(function () {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
// 上传单个图片
|
/*! 后台菜单辅助插件 */
|
||||||
$.fn.uploadOneImage = function () {
|
$.menu = new function () {
|
||||||
var name = $(this).attr('name') || 'image';
|
// 计算URL地址中有效的URI
|
||||||
var type = $(this).data('type') || 'png,jpg';
|
this.getUri = function (uri) {
|
||||||
var $tpl = $('<a data-file="one" data-field="' + name + '" data-type="' + type + '" class="uploadimage"></a>');
|
uri = uri || window.location.href;
|
||||||
$(this).hide().attr('name', name).after($tpl).on('change', function () {
|
uri = (uri.indexOf(window.location.host) > -1 ? uri.split(window.location.host)[1] : uri).split('?')[0];
|
||||||
$tpl.get(0).style = this.value ? 'background-image:url(' + this.value + ')' : '';
|
return (uri.indexOf('#') !== -1 ? uri.split('#')[1] : uri);
|
||||||
}).trigger('change');
|
};
|
||||||
};
|
// 通过URI查询最有可能的菜单NODE
|
||||||
|
this.queryNode = function (url) {
|
||||||
// 上传多个图片
|
var node = location.href.replace(/.*spm=([\d\-m]+).*/ig, '$1');
|
||||||
$.fn.uploadMultipleImage = function () {
|
if (!/^m\-/.test(node)) {
|
||||||
var type = $(this).data('type') || 'png,jpg';
|
var $menu = $('[data-menu-node][data-open*="' + url.replace(/\.html$/ig, '') + '"]');
|
||||||
var name = $(this).attr('name') || 'umt-image';
|
return $menu.size() ? $menu.get(0).getAttribute('data-menu-node') : '';
|
||||||
var $tpl = $('<a data-file="mut" data-field="' + name + '" data-type="' + type + '" class="uploadimage"></a>');
|
|
||||||
$(this).hide().attr('name', name).after($tpl).on('change', function () {
|
|
||||||
var input = this, values = [], srcs = this.value.split('|');
|
|
||||||
$(this).prevAll('.uploadimage').map(function () {
|
|
||||||
values.push($(this).attr('data-tips-image'));
|
|
||||||
}), $(this).prevAll('.uploadimage').remove(), values.reverse();
|
|
||||||
for (var i in srcs) {
|
|
||||||
srcs[i] && values.push(srcs[i]);
|
|
||||||
}
|
}
|
||||||
this.value = values.join('|');
|
return node;
|
||||||
for (var i in values) {
|
};
|
||||||
var tpl = '<div class="uploadimage uploadimagemtl"><a class="layui-icon">ဆ</a></div>';
|
// URL转URI
|
||||||
var $tpl = $(tpl).attr('data-tips-image', values[i]).css('backgroundImage', 'url(' + values[i] + ')');
|
this.parseUri = function (uri, obj) {
|
||||||
$tpl.data('input', input).data('srcs', values).data('index', i);
|
var params = {};
|
||||||
$tpl.on('click', 'a', function (e) {
|
if (uri.indexOf('?') > -1) {
|
||||||
e.stopPropagation();
|
var serach = uri.split('?')[1].split('&');
|
||||||
var $cur = $(this).parent();
|
for (var i in serach) {
|
||||||
var dialogIndex = $.msg.confirm('确定要移除这张图片吗?', function () {
|
if (serach[i].indexOf('=') > -1) {
|
||||||
var data = $cur.data('srcs'), tmp = [];
|
var arr = serach[i].split('=');
|
||||||
for (var i in data) {
|
try {
|
||||||
i !== $cur.data('index') && tmp.push(data[i]);
|
params[arr[0]] = window.decodeURIComponent(window.decodeURIComponent(arr[1].replace(/%2B/ig, ' ')));
|
||||||
|
} catch (e) {
|
||||||
|
console.log([e, uri, serach, arr]);
|
||||||
}
|
}
|
||||||
$cur.data('input').value = tmp.join('|');
|
}
|
||||||
$cur.remove(), $.msg.close(dialogIndex);
|
}
|
||||||
});
|
|
||||||
});
|
|
||||||
$(this).before($tpl);
|
|
||||||
}
|
}
|
||||||
}).trigger('change');
|
uri = this.getUri(uri);
|
||||||
|
params.spm = obj && obj.getAttribute('data-menu-node') || this.queryNode(uri);
|
||||||
|
delete params[""];
|
||||||
|
var query = '?' + $.param(params);
|
||||||
|
return uri + (query !== '?' ? query : '');
|
||||||
|
};
|
||||||
|
// 后台菜单动作初始化
|
||||||
|
this.listen = function () {
|
||||||
|
var self = this;
|
||||||
|
// 左则二级菜单展示
|
||||||
|
$('[data-submenu-layout]>a').on('click', function () {
|
||||||
|
$(this).parent().toggleClass('open');
|
||||||
|
self.syncOpenStatus(1);
|
||||||
|
});
|
||||||
|
// 同步二级菜单展示状态
|
||||||
|
this.syncOpenStatus = function (mode) {
|
||||||
|
$('[data-submenu-layout]').map(function () {
|
||||||
|
var node = $(this).attr('data-submenu-layout');
|
||||||
|
if (mode === 1) {
|
||||||
|
var type = (this.className || '').indexOf('open') > -1 ? 2 : 1;
|
||||||
|
layui.data('menu', {key: node, value: type});
|
||||||
|
} else {
|
||||||
|
var type = layui.data('menu')[node] || 2;
|
||||||
|
(type === 2) && $(this).addClass('open');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
window.onhashchange = function () {
|
||||||
|
var hash = window.location.hash || '';
|
||||||
|
if (hash.length < 1) {
|
||||||
|
return $('[data-menu-node][data-open!="#"]:first').trigger('click');
|
||||||
|
}
|
||||||
|
$.form.load(hash);
|
||||||
|
self.syncOpenStatus(2);
|
||||||
|
// 菜单选择切换
|
||||||
|
var node = self.queryNode(self.getUri());
|
||||||
|
if (/^m\-/.test(node)) {
|
||||||
|
var $all = $('a[data-menu-node]'), tmp = node.split('-'), tmpNode = tmp.shift();
|
||||||
|
while (tmp.length > 0) {
|
||||||
|
tmpNode = tmpNode + '-' + tmp.shift();
|
||||||
|
$all = $all.not($('a[data-menu-node="' + tmpNode + '"]').addClass('active'));
|
||||||
|
}
|
||||||
|
$all.removeClass('active');
|
||||||
|
// 菜单模式切换
|
||||||
|
if (node.split('-').length > 2) {
|
||||||
|
var _tmp = node.split('-'), _node = _tmp.shift() + '-' + _tmp.shift();
|
||||||
|
$('[data-menu-layout]').not($('[data-menu-layout="' + _node + '"]').removeClass('hide')).addClass('hide');
|
||||||
|
$('[data-menu-node="' + node + '"]').parent('div').parent('div').addClass('open');
|
||||||
|
$('body.framework').removeClass('mini');
|
||||||
|
} else {
|
||||||
|
$('body.framework').addClass('mini');
|
||||||
|
}
|
||||||
|
self.syncOpenStatus(1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// URI初始化动作
|
||||||
|
window.onhashchange.call(this);
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
// 注册对象到Jq
|
// 注册对象到Jq
|
||||||
$.validate = function (form, callback, options) {
|
$.vali = function (form, callback, options) {
|
||||||
return (new function () {
|
return (new function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
// 表单元素
|
// 表单元素
|
||||||
@ -400,17 +448,12 @@ $(function () {
|
|||||||
}).check(form, callback, options);
|
}).check(form, callback, options);
|
||||||
};
|
};
|
||||||
|
|
||||||
// 注册对象到JqFn
|
|
||||||
$.fn.validate = function (callback, options) {
|
|
||||||
return $.validate(this, callback, options);
|
|
||||||
};
|
|
||||||
|
|
||||||
// 自动监听规则内表单
|
// 自动监听规则内表单
|
||||||
$.validate.listen = function () {
|
$.vali.listen = function () {
|
||||||
$('form[data-auto]').map(function () {
|
$('form[data-auto]').map(function () {
|
||||||
if ($(this).attr('data-listen') !== 'true') {
|
if ($(this).attr('data-listen') !== 'true') {
|
||||||
var callbackname = $(this).attr('data-callback');
|
var callbackname = $(this).attr('data-callback');
|
||||||
$(this).attr('data-listen', 'true').validate(function (data) {
|
$(this).attr('data-listen', 'true').vali(function (data) {
|
||||||
var method = this.getAttribute('method') || 'POST';
|
var method = this.getAttribute('method') || 'POST';
|
||||||
var tips = this.getAttribute('data-tips') || undefined;
|
var tips = this.getAttribute('data-tips') || undefined;
|
||||||
var url = this.getAttribute('action') || window.location.href;
|
var url = this.getAttribute('action') || window.location.href;
|
||||||
@ -426,98 +469,54 @@ $(function () {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 注册对象到JqFn
|
||||||
|
$.fn.vali = function (callback, options) {
|
||||||
|
return $.vali(this, callback, options);
|
||||||
|
};
|
||||||
|
|
||||||
/*! 后台菜单辅助插件 */
|
// 上传单个图片
|
||||||
$.menu = new function () {
|
$.fn.uploadOneImage = function () {
|
||||||
// 计算URL地址中有效的URI
|
var name = $(this).attr('name') || 'image';
|
||||||
this.getUri = function (uri) {
|
var type = $(this).data('type') || 'png,jpg';
|
||||||
uri = uri || window.location.href;
|
var $tpl = $('<a data-file="one" data-field="' + name + '" data-type="' + type + '" class="uploadimage"></a>');
|
||||||
uri = (uri.indexOf(window.location.host) > -1 ? uri.split(window.location.host)[1] : uri).split('?')[0];
|
$(this).hide().attr('name', name).after($tpl).on('change', function () {
|
||||||
return (uri.indexOf('#') !== -1 ? uri.split('#')[1] : uri);
|
$tpl.get(0).style = this.value ? 'background-image:url(' + this.value + ')' : '';
|
||||||
};
|
}).trigger('change');
|
||||||
// 通过URI查询最有可能的菜单NODE
|
};
|
||||||
this.queryNode = function (url) {
|
|
||||||
var node = location.href.replace(/.*spm=([\d\-m]+).*/ig, '$1');
|
// 上传多个图片
|
||||||
if (!/^m\-/.test(node)) {
|
$.fn.uploadMultipleImage = function () {
|
||||||
var $menu = $('[data-menu-node][data-open*="' + url.replace(/\.html$/ig, '') + '"]');
|
var type = $(this).data('type') || 'png,jpg';
|
||||||
return $menu.size() ? $menu.get(0).getAttribute('data-menu-node') : '';
|
var name = $(this).attr('name') || 'umt-image';
|
||||||
|
var $tpl = $('<a data-file="mut" data-field="' + name + '" data-type="' + type + '" class="uploadimage"></a>');
|
||||||
|
$(this).hide().attr('name', name).after($tpl).on('change', function () {
|
||||||
|
var input = this, values = [], srcs = this.value.split('|');
|
||||||
|
$(this).prevAll('.uploadimage').map(function () {
|
||||||
|
values.push($(this).attr('data-tips-image'));
|
||||||
|
}), $(this).prevAll('.uploadimage').remove(), values.reverse();
|
||||||
|
for (var i in srcs) {
|
||||||
|
srcs[i] && values.push(srcs[i]);
|
||||||
}
|
}
|
||||||
return node;
|
this.value = values.join('|');
|
||||||
};
|
for (var i in values) {
|
||||||
// URL转URI
|
var tpl = '<div class="uploadimage uploadimagemtl"><a class="layui-icon">ဆ</a></div>';
|
||||||
this.parseUri = function (uri, obj) {
|
var $tpl = $(tpl).attr('data-tips-image', values[i]).css('backgroundImage', 'url(' + values[i] + ')');
|
||||||
var params = {};
|
$tpl.data('input', input).data('srcs', values).data('index', i);
|
||||||
if (uri.indexOf('?') > -1) {
|
$tpl.on('click', 'a', function (e) {
|
||||||
var serach = uri.split('?')[1].split('&');
|
e.stopPropagation();
|
||||||
for (var i in serach) {
|
var $cur = $(this).parent();
|
||||||
if (serach[i].indexOf('=') > -1) {
|
var dialogIndex = $.msg.confirm('确定要移除这张图片吗?', function () {
|
||||||
var arr = serach[i].split('=');
|
var data = $cur.data('srcs'), tmp = [];
|
||||||
try {
|
for (var i in data) {
|
||||||
params[arr[0]] = window.decodeURIComponent(window.decodeURIComponent(arr[1].replace(/%2B/ig, ' ')));
|
i !== $cur.data('index') && tmp.push(data[i]);
|
||||||
} catch (e) {
|
|
||||||
console.log([e, uri, serach, arr]);
|
|
||||||
}
|
}
|
||||||
}
|
$cur.data('input').value = tmp.join('|');
|
||||||
}
|
$cur.remove(), $.msg.close(dialogIndex);
|
||||||
}
|
});
|
||||||
uri = this.getUri(uri);
|
|
||||||
params.spm = obj && obj.getAttribute('data-menu-node') || this.queryNode(uri);
|
|
||||||
delete params[""];
|
|
||||||
var query = '?' + $.param(params);
|
|
||||||
return uri + (query !== '?' ? query : '');
|
|
||||||
};
|
|
||||||
// 后台菜单动作初始化
|
|
||||||
this.listen = function () {
|
|
||||||
var self = this;
|
|
||||||
// 左则二级菜单展示
|
|
||||||
$('[data-submenu-layout]>a').on('click', function () {
|
|
||||||
$(this).parent().toggleClass('open');
|
|
||||||
self.syncOpenStatus(1);
|
|
||||||
});
|
|
||||||
// 同步二级菜单展示状态
|
|
||||||
this.syncOpenStatus = function (mode) {
|
|
||||||
$('[data-submenu-layout]').map(function () {
|
|
||||||
var node = $(this).attr('data-submenu-layout');
|
|
||||||
if (mode === 1) {
|
|
||||||
var type = (this.className || '').indexOf('open') > -1 ? 2 : 1;
|
|
||||||
layui.data('menu', {key: node, value: type});
|
|
||||||
} else {
|
|
||||||
var type = layui.data('menu')[node] || 2;
|
|
||||||
(type === 2) && $(this).addClass('open');
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
};
|
$(this).before($tpl);
|
||||||
window.onhashchange = function () {
|
}
|
||||||
var hash = window.location.hash || '';
|
}).trigger('change');
|
||||||
if (hash.length < 1) {
|
|
||||||
return $('[data-menu-node][data-open!="#"]:first').trigger('click');
|
|
||||||
}
|
|
||||||
$.form.load(hash);
|
|
||||||
self.syncOpenStatus(2);
|
|
||||||
// 菜单选择切换
|
|
||||||
var node = self.queryNode(self.getUri());
|
|
||||||
if (/^m\-/.test(node)) {
|
|
||||||
var $all = $('a[data-menu-node]'), tmp = node.split('-'), tmpNode = tmp.shift();
|
|
||||||
while (tmp.length > 0) {
|
|
||||||
tmpNode = tmpNode + '-' + tmp.shift();
|
|
||||||
$all = $all.not($('a[data-menu-node="' + tmpNode + '"]').addClass('active'));
|
|
||||||
}
|
|
||||||
$all.removeClass('active');
|
|
||||||
// 菜单模式切换
|
|
||||||
if (node.split('-').length > 2) {
|
|
||||||
var _tmp = node.split('-'), _node = _tmp.shift() + '-' + _tmp.shift();
|
|
||||||
$('[data-menu-layout]').not($('[data-menu-layout="' + _node + '"]').removeClass('hide')).addClass('hide');
|
|
||||||
$('[data-menu-node="' + node + '"]').parent('div').parent('div').addClass('open');
|
|
||||||
$('body.framework').removeClass('mini');
|
|
||||||
} else {
|
|
||||||
$('body.framework').addClass('mini');
|
|
||||||
}
|
|
||||||
self.syncOpenStatus(1);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
// URI初始化动作
|
|
||||||
window.onhashchange.call(this);
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*! 注册 data-load 事件行为 */
|
/*! 注册 data-load 事件行为 */
|
||||||
@ -658,5 +657,5 @@ $(function () {
|
|||||||
|
|
||||||
/*! 初始化 */
|
/*! 初始化 */
|
||||||
$.menu.listen();
|
$.menu.listen();
|
||||||
$.validate.listen(this);
|
$.vali.listen();
|
||||||
});
|
});
|
Loading…
x
Reference in New Issue
Block a user