123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752 |
- (function (w) {
- if (!("WebSocket" in w && 2 === w.WebSocket.CLOSING)) {
- document.body.innerHTML = '<div class="version-debug">您使用的浏览器已经<strong>过时</strong>,建议使用最新版本的谷歌浏览器。<a target="_blank" href="https://pc.qq.com/detail/1/detail_2661.html" class="layui-btn layui-btn-primary">立即下载</a></div>';
- }
- }(window));
- if (typeof jQuery === 'undefined') window.$ = window.jQuery = layui.$;
- window.form = layui.form, window.layer = layui.layer, window.laydate = layui.laydate;
- window.baseRoot = (function (src) {
- src = document.scripts[document.scripts.length - 1].src;
- return src.substring(0, src.lastIndexOf("/") + 1);
- })();
- require.config({
- waitSeconds: 60,
- baseUrl: baseRoot,
- map: {'*': {css: baseRoot + 'plugs/require/css.js'}},
- paths: {
- 'md5': ['plugs/jquery/md5.min'],
- 'spop': ['plugs/spop/spop.min'],
- 'json': ['plugs/jquery/json.min'],
- 'upload': ['plugs/plupload/build'],
- 'base64': ['plugs/jquery/base64.min'],
- 'echarts': ['plugs/echarts/echarts.min'],
- 'angular': ['plugs/angular/angular.min'],
- 'ckeditor': ['plugs/ckeditor/ckeditor'],
- 'plupload': ['plugs/plupload/plupload.full.min'],
- 'websocket': ['plugs/socket/websocket'],
- 'pcasunzips': ['plugs/jquery/pcasunzips'],
- 'jquery.ztree': ['plugs/ztree/ztree.all.min'],
- 'jquery.masonry': ['plugs/jquery/masonry.min'],
- 'jquery.autocompleter': ['plugs/jquery/autocompleter.min'],
- },
- shim: {
- 'spop': {deps: ['css!' + baseRoot + 'plugs/spop/spop.min.css']},
- 'websocket': {deps: [baseRoot + 'plugs/socket/swfobject.min.js']},
- 'jquery.ztree': {deps: ['jquery', 'css!' + baseRoot + 'plugs/ztree/zTreeStyle/zTreeStyle.css']},
- 'jquery.autocompleter': {deps: ['jquery', 'css!' + baseRoot + 'plugs/jquery/autocompleter.css']},
- }
- });
- define('jquery', [], function () {
- return layui.$;
- });
- $(function () {
- window.$body = $('body');
-
- $.msg = new function (that) {
- that = this;
- this.indexs = [];
- this.shade = [0.02, '#000'];
-
- this.close = function (index) {
- return layer.close(index);
- };
-
- this.alert = function (msg, callback) {
- var index = layer.alert(msg, {end: callback, scrollbar: false});
- return this.indexs.push(index), index;
- };
-
- this.confirm = function (msg, ok, no) {
- var index = layer.confirm(msg, {title: '操作确认', btn: ['确认', '取消']}, function () {
- typeof ok === 'function' && ok.call(this, index);
- }, function () {
- typeof no === 'function' && no.call(this, index);
- that.close(index);
- });
- return index;
- };
-
- this.success = function (msg, time, callback) {
- var index = layer.msg(msg, {icon: 1, shade: this.shade, scrollbar: false, end: callback, time: (time || 2) * 1000, shadeClose: true});
- return this.indexs.push(index), index;
- };
-
- this.error = function (msg, time, callback) {
- var index = layer.msg(msg, {icon: 2, shade: this.shade, scrollbar: false, time: (time || 3) * 1000, end: callback, shadeClose: true});
- return this.indexs.push(index), index;
- };
-
- this.tips = function (msg, time, callback) {
- var index = layer.msg(msg, {time: (time || 3) * 1000, shade: this.shade, end: callback, shadeClose: true});
- return this.indexs.push(index), index;
- };
-
- this.loading = function (msg, callback) {
- var index = msg ? layer.msg(msg, {icon: 16, scrollbar: false, shade: this.shade, time: 0, end: callback}) : layer.load(2, {time: 0, scrollbar: false, shade: this.shade, end: callback});
- return this.indexs.push(index), index;
- };
-
- this.auto = function (ret, time) {
- var url = ret.url || (typeof ret.data === 'string' ? ret.data : '');
- var msg = ret.msg || (typeof ret.info === 'string' ? ret.info : '');
- if (parseInt(ret.code) === 1 && time === 'false') {
- return url ? (window.location.href = url) : $.form.reload();
- }
- return (parseInt(ret.code) === 1) ? this.success(msg, time, function () {
- url ? (window.location.href = url) : $.form.reload();
- for (var i in that.indexs) layer.close(that.indexs[i]);
- that.indexs = [];
- }) : this.error(msg, 3, function () {
- url ? window.location.href = url : '';
- });
- };
- };
-
- $.form = new function (that) {
- that = this;
-
- this.selecter = '.layui-layout-admin>.layui-body';
-
- this.reload = function () {
- window.onhashchange.call(this);
- };
-
- this.reInit = function ($dom) {
- $.vali.listen(this);
- $dom = $dom || $(this.selecter);
- $dom.find('[required]').map(function ($parent) {
- if (($parent = $(this).parent()) && $parent.is('label')) {
- $parent.addClass('label-required-prev');
- } else {
- $parent.prevAll('label').addClass('label-required-next');
- }
- });
- $dom.find('input[data-date-range]').map(function () {
- this.setAttribute('autocomplete', 'off');
- laydate.render({
- type: this.getAttribute('data-date-range') || 'date',
- range: true, elem: this, done: function (value) {
- $(this.elem).val(value).trigger('change');
- }
- });
- });
- $dom.find('[data-file]:not([data-inited])').map(function (index, elem, $this, field) {
- $this = $(elem), field = $this.attr('data-field') || 'file';
- if (!$this.data('input')) $this.data('input', $('[name="' + field + '"]').get(0));
- $this.uploadFile(function (url) {
- $($this.data('input')).val(url).trigger('change');
- });
- });
- };
-
- this.show = function (html) {
- $(this.selecter).html(html);
- this.reInit($(this.selecter));
- setTimeout(function () {
- that.reInit($(that.selecter));
- }, 500);
- };
-
- this.href = function (url, obj) {
- if (url !== '#') {
- window.location.href = '#' + $.menu.parseUri(url, obj);
- } else if (obj && obj.getAttribute('data-menu-node')) {
- $('[data-menu-node^="' + obj.getAttribute('data-menu-node') + '-"][data-open!="#"]:first').trigger('click');
- }
- };
-
- this.load = function (url, data, method, callback, loading, tips, time, headers) {
- var index = loading !== false ? $.msg.loading(tips) : 0;
- if (typeof data === 'object' && typeof data['_csrf_'] === 'string') {
- headers = headers || {};
- headers['User-Token-Csrf'] = data['_csrf_'];
- delete data['_csrf_'];
- }
- $.ajax({
- data: data || {}, type: method || 'GET', url: $.menu.parseUri(url), beforeSend: function (xhr) {
- if (typeof Pace === 'object') Pace.restart();
- if (typeof headers === 'object') for (var i in headers) xhr.setRequestHeader(i, headers[i]);
- }, error: function (XMLHttpRequest) {
- if (parseInt(XMLHttpRequest.status) === 200) this.success(XMLHttpRequest.responseText);
- else $.msg.tips('E' + XMLHttpRequest.status + ' - 服务器繁忙,请稍候再试!');
- }, success: function (ret) {
- if (typeof callback === 'function' && callback.call(that, ret) === false) return false;
- return typeof ret === 'object' ? $.msg.auto(ret, time || ret.wait || undefined) : that.show(ret);
- }, complete: function () {
- $.msg.close(index);
- }
- });
- };
-
- this.open = function (url, data, callback, loading, tips) {
- this.load(url, data, 'get', function (ret) {
- return (typeof ret === 'object' ? $.msg.auto(ret) : that.show(ret)), false;
- }, loading, tips);
- };
-
- this.iframe = function (url, title, area) {
- return layer.open({title: title || '窗口', type: 2, area: area || ['800px', '580px'], fix: true, maxmin: false, content: url});
- };
-
- this.modal = function (url, data, title, callback, loading, tips) {
- this.load(url, data, 'GET', function (res, index) {
- if (typeof (res) === 'object') return $.msg.auto(res), false;
- index = layer.open({
- type: 1, btn: false, area: "800px", content: res, title: title || '', success: function (dom, index) {
- $(dom).find('[data-close]').off('click').on('click', function () {
- if ($(this).attr('data-confirm')) return $.msg.confirm($(this).attr('data-confirm'), function (_index) {
- layer.close(_index), layer.close(index);
- }), false;
- layer.close(index);
- });
- $.form.reInit($(dom));
- }
- });
- $.msg.indexs.push(index);
- return (typeof callback === 'function') && callback.call(that);
- }, loading, tips);
- };
- };
-
- $.menu = new function (that) {
- that = this;
-
- this.getUri = function (uri) {
- uri = uri || window.location.href;
- uri = (uri.indexOf(window.location.host) > -1 ? uri.split(window.location.host)[1] : uri);
- return (uri.indexOf('#') > -1 ? uri.split('#')[1] : uri).split('?')[0];
- };
-
- this.queryNode = function (url, node) {
- node = node || location.href.replace(/.*spm=([\d\-m]+).*/ig, '$1');
- if (!/^m-/.test(node)) {
- var $menu = $('[data-menu-node][data-open*="' + url.replace(/\.html$/ig, '') + '"]');
- return $menu.size() ? $menu.get(0).getAttribute('data-menu-node') : '';
- }
- return node;
- };
-
- this.parseUri = function (uri, obj) {
- var params = {};
- if (uri.indexOf('?') > -1) {
- var attrs = uri.split('?')[1].split('&');
- for (var i in attrs) if (attrs[i].indexOf('=') > -1) {
- var tmp = attrs[i].split('=').slice();
- if (typeof tmp[0] === 'string' && tmp[0].length > 0) {
- params[tmp[0]] = decodeURIComponent(tmp[1].replace(/%2B/ig, '%20'));
- }
- }
- }
- uri = this.getUri(uri);
- if (typeof params.spm !== 'string') {
- params.spm = obj && obj.getAttribute('data-menu-node') || this.queryNode(uri);
- }
- if (typeof params.spm !== 'string' || params.spm.length < 1) delete params.spm;
- var query = '?' + $.param(params);
- return uri + (query === '?' ? '' : query);
- };
-
- this.listen = function () {
-
- (function ($menu, miniClass) {
-
- if (layui.data('admin-menu-type')['type-min']) $menu.addClass(miniClass);
- $body.on('click', '[data-target-menu-type]', function () {
- $menu.toggleClass(miniClass);
- layui.data('admin-menu-type', {key: 'type-min', value: $menu.hasClass(miniClass)});
- }).on('resize', function () {
- if ($body.width() > 1000) {
- layui.data('admin-menu-type')['type-min'] ? $menu.addClass(miniClass) : $menu.removeClass(miniClass);
- } else {
- $menu.addClass(miniClass);
- }
- }).trigger('resize');
-
- $('[data-target-tips]').mouseenter(function () {
- if ($menu.hasClass(miniClass)) {
- $(this).attr('index', layer.tips($(this).attr('data-target-tips') || '', this));
- }
- }).mouseleave(function () {
- layer.close($(this).attr('index'));
- });
- })($('.layui-layout-admin'), 'layui-layout-left-mini');
-
- $('[data-submenu-layout]>a').on('click', function () {
- that.syncOpenStatus(1);
- });
-
- this.syncOpenStatus = function (mode) {
- $('[data-submenu-layout]').map(function (node) {
- node = $(this).attr('data-submenu-layout');
- if (mode === 1) layui.data('menu', {key: node, value: $(this).hasClass('layui-nav-itemed') ? 2 : 1});
- else if ((layui.data('menu')[node] || 2) === 2) $(this).addClass('layui-nav-itemed');
- });
- };
- window.onhashchange = function (hash, node) {
- hash = window.location.hash || '';
- if (hash.length < 1) return $('[data-menu-node][data-open!="#"]:first').trigger('click');
- $.form.load(hash), that.syncOpenStatus(2);
-
- node = that.queryNode(that.getUri());
- if (/^m-/.test(node)) {
- var $all = $('a[data-menu-node]').parent(), tmp = node.split('-'), tmpNode = tmp.shift();
- while (tmp.length > 0) {
- tmpNode = tmpNode + '-' + tmp.shift();
- $all = $all.not($('a[data-menu-node="' + tmpNode + '"]').parent().addClass('layui-this'));
- }
- $all.removeClass('layui-this');
-
- if (node.split('-').length > 2) {
- var _tmp = node.split('-'), _node = _tmp.shift() + '-' + _tmp.shift();
- $('[data-menu-layout]').not($('[data-menu-layout="' + _node + '"]').removeClass('layui-hide')).addClass('layui-hide');
- $('[data-menu-node="' + node + '"]').parent().parent().parent().addClass('layui-nav-itemed');
- $('.layui-layout-admin').removeClass('layui-layout-left-hide');
- } else $('.layui-layout-admin').addClass('layui-layout-left-hide');
- that.syncOpenStatus(1);
- }
- };
-
- window.onhashchange.call(this);
- };
- };
-
- $.vali = function (form, callback, options) {
- return (new function (that) {
- that = this;
-
- this.tags = 'input,textarea,select';
-
- this.checkEvent = {change: true, blur: true, keyup: false};
-
- this.trim = function (str) {
- return str.replace(/(^\s*)|(\s*$)/g, '');
- };
-
- this.isVisible = function (ele) {
- return $(ele).is(':visible');
- };
-
- this.hasProp = function (ele, prop) {
- if (typeof prop !== "string") return false;
- var attrProp = ele.getAttribute(prop);
- return (typeof attrProp !== 'undefined' && attrProp !== null && attrProp !== false);
- };
-
- this.isEmpty = function (ele, value) {
- var trim = this.trim(ele.value);
- value = value || ele.getAttribute('placeholder');
- return (trim === "" || trim === value);
- };
-
- this.isRegex = function (ele, regex, params) {
- var input = $(ele).val(), real = this.trim(input);
- regex = regex || ele.getAttribute('pattern');
- if (real === "" || !regex) return true;
- return new RegExp(regex, params || 'i').test(real);
- };
-
- this.checkAllInput = function () {
- var isPass = true;
- $(form).find(this.tags).each(function () {
- if (that.checkInput(this) === false) return $(this).focus(), isPass = false;
- });
- return isPass;
- };
-
- this.checkInput = function (input) {
- var tag = input.tagName.toLowerCase(), need = this.hasProp(input, "required");
- var type = (input.getAttribute("type") || '').replace(/\W+/, "").toLowerCase();
- if (this.hasProp(input, 'data-auto-none')) return true;
- var ingoreTags = ['select'], ingoreType = ['radio', 'checkbox', 'submit', 'reset', 'image', 'file', 'hidden'];
- for (var i in ingoreTags) if (tag === ingoreTags[i]) return true;
- for (var i in ingoreType) if (type === ingoreType[i]) return true;
- if (need && this.isEmpty(input)) return this.remind(input);
- return this.isRegex(input) ? (this.hideError(input), true) : this.remind(input);
- };
-
- this.remind = function (input) {
- if (!this.isVisible(input)) return true;
- this.showError(input, input.getAttribute('title') || input.getAttribute('placeholder') || '输入错误');
- return false;
- };
-
- this.showError = function (ele, content) {
- $(ele).addClass('validate-error'), this.insertError(ele);
- $($(ele).data('input-info')).addClass('layui-anim layui-anim-fadein').css({width: 'auto'}).html(content);
- };
-
- this.hideError = function (ele) {
- $(ele).removeClass('validate-error'), this.insertError(ele);
- $($(ele).data('input-info')).removeClass('layui-anim-fadein').css({width: '30px'}).html('');
- };
-
- this.insertError = function (ele) {
- var $html = $('<span style="padding-right:12px;color:#a94442;position:absolute;right:0;font-size:12px;z-index:2;display:block;width:34px;text-align:center;pointer-events:none"></span>');
- $html.css({top: $(ele).position().top + 'px', paddingBottom: $(ele).css('paddingBottom'), lineHeight: $(ele).css('height')});
- $(ele).data('input-info') || $(ele).data('input-info', $html.insertAfter(ele));
- };
-
- this.check = function (form, callback) {
- $(form).attr("novalidate", "novalidate");
- $(form).find(that.tags).map(function () {
- this.bindEventMethod = function () {
- that.checkInput(this);
- };
- for (var e in that.checkEvent) if (that.checkEvent[e] === true) {
- $(this).off(e, this.bindEventMethod).on(e, this.bindEventMethod);
- }
- });
- $(form).bind("submit", function (event) {
- if (that.checkAllInput() && typeof callback === 'function') {
- if (typeof CKEDITOR === 'object' && typeof CKEDITOR.instances === 'object') {
- for (var i in CKEDITOR.instances) CKEDITOR.instances[i].updateElement();
- }
- callback.call(this, $(form).formToJson());
- }
- return event.preventDefault(), false;
- });
- $(form).find('[data-form-loaded]').map(function () {
- $(this).html(this.getAttribute('data-form-loaded') || this.innerHTML);
- $(this).removeAttr('data-form-loaded').removeClass('layui-disabled');
- });
- return $(form).data('validate', this);
- };
- }).check(form, callback, options);
- };
-
- $.vali.listen = function () {
- $('form[data-auto]').map(function () {
- if ($(this).attr('data-listen') !== 'true') $(this).attr('data-listen', 'true').vali(function (data) {
- var call = $(this).attr('data-callback') || '_default_callback';
- var type = this.getAttribute('method') || 'POST', tips = this.getAttribute('data-tips') || undefined;
- var time = this.getAttribute('data-time') || undefined, href = this.getAttribute('action') || window.location.href;
- $.form.load(href, data, type, window[call] || undefined, true, tips, time);
- });
- });
- };
-
- $.fn.vali = function (callback, options) {
- return $.vali(this, callback, options);
- };
-
- $.fn.formToJson = function () {
- var self = this, data = {}, pushCounters = {};
- var patterns = {"key": /[a-zA-Z0-9_]+|(?=\[\])/g, "push": /^$/, "fixed": /^\d+$/, "named": /^[a-zA-Z0-9_]+$/};
- this.build = function (base, key, value) {
- base[key] = value;
- return base;
- };
- this.pushCounter = function (name) {
- if (pushCounters[name] === undefined) pushCounters[name] = 0;
- return pushCounters[name]++;
- };
- $.each($(this).serializeArray(), function () {
- var key, keys = this.name.match(patterns.key), merge = this.value, name = this.name;
- while ((key = keys.pop()) !== undefined) {
- name = name.replace(new RegExp("\\[" + key + "\\]$"), '');
- if (key.match(patterns.push)) {
- merge = self.build([], self.pushCounter(name), merge);
- } else if (key.match(patterns.fixed)) {
- merge = self.build([], key, merge);
- } else if (key.match(patterns.named)) {
- merge = self.build({}, key, merge);
- }
- }
- data = $.extend(true, data, merge);
- });
- return data;
- };
-
- $.fn.uploadFile = function (callback) {
- if (this.attr('data-inited')) return false;
- var that = this, mode = $(this).attr('data-file') || 'one';
- this.attr('data-inited', true).attr('data-multiple', (mode !== 'btn' && mode !== 'one') ? 1 : 0);
- require(['upload'], function (apply) {
- apply(that, null, callback);
- });
- };
-
- $.fn.uploadOneImage = function () {
- var name = $(this).attr('name') || 'image', type = $(this).data('type') || 'png,jpg,gif';
- var $tpl = $('<a data-file="btn" class="uploadimage"></a>').attr('data-field', name).attr('data-type', type);
- $(this).attr('name', name).after($tpl.data('input', this)).on('change', function () {
- if (this.value) $tpl.css('backgroundImage', 'url(' + this.value + ')');
- }).trigger('change');
- };
-
- $.fn.uploadMultipleImage = function () {
- var type = $(this).data('type') || 'png,jpg,gif', name = $(this).attr('name') || 'umt-image';
- var $tpl = $('<a class="uploadimage"></a>').attr('data-file', 'mul').attr('data-field', name).attr('data-type', type);
- $(this).attr('name', name).after($tpl.data('input', this)).on('change', function () {
- var input = this;
- this.setImageData = function () {
- input.value = input.getImageData().join('|');
- };
- this.getImageData = function () {
- var values = [];
- $(input).prevAll('.uploadimage').map(function () {
- values.push($(this).attr('data-tips-image'));
- });
- return values.reverse(), values;
- };
- var urls = this.getImageData(), srcs = this.value.split('|');
- for (var i in srcs) if (srcs[i]) urls.push(srcs[i]);
- $(this).prevAll('.uploadimage').remove();
- this.value = urls.join('|');
- for (var i in urls) {
- var tpl = '<div class="uploadimage uploadimagemtl"><a class="layui-icon margin-right-5"></a><a class="layui-icon margin-right-5">ဆ</a><a class="layui-icon margin-right-5"></a></div>';
- var $tpl = $(tpl).attr('data-tips-image', urls[i]).css('backgroundImage', 'url(' + urls[i] + ')').on('click', 'a', function (e) {
- e.stopPropagation();
- var $cur = $(this).parent();
- switch ($(this).index()) {
- case 1:
- return $.msg.confirm('确定要移除这张图片吗?', function (index) {
- $cur.remove(), input.setImageData(), $.msg.close(index);
- });
- case 0:
- var lenght = $cur.siblings('div.uploadimagemtl').length;
- if ($cur.index() !== lenght) $cur.next().after($cur);
- return input.setImageData();
- case 2:
- if ($cur.index() !== 0) $cur.prev().before($cur);
- return input.setImageData();
- }
- });
- $(this).before($tpl);
- }
- }).trigger('change');
- };
-
- $body.on('click', '[data-load]', function () {
- var url = $(this).attr('data-load'), tips = $(this).attr('data-tips'), time = $(this).attr('data-time');
- if ($(this).attr('data-confirm')) return $.msg.confirm($(this).attr('data-confirm'), function () {
- $.form.load(url, {}, 'get', null, true, tips, time);
- });
- $.form.load(url, {}, 'get', null, true, tips, time);
- });
-
- $body.on('submit', 'form.form-search', function () {
- var url = $(this).attr('action').replace(/&?page=\d+/g, ''), split = url.indexOf('?') === -1 ? '?' : '&';
- if ((this.method || 'get').toLowerCase() === 'get') {
- return window.location.href = '#' + $.menu.parseUri(url + split + $(this).serialize());
- }
- $.form.load(url, this, 'post');
- });
-
- $body.on('click', '[data-modal]', function () {
- return $.form.modal($(this).attr('data-modal'), 'open_type=modal', $(this).attr('data-title') || $(this).text() || '编辑');
- });
-
- $body.on('click', '[data-open]', function () {
- $.form.href($(this).attr('data-open'), this);
- });
-
- $body.on('dblclick', '[data-dbclick]', function () {
- $(this).find(this.getAttribute('data-dbclick') || '[data-dbclick]').trigger('click');
- });
-
- $body.on('click', '[data-reload]', function () {
- $.form.reload();
- });
-
- $body.on('click', '[data-check-target]', function () {
- var checked = !!this.checked;
- $($(this).attr('data-check-target')).map(function () {
- this.checked = checked;
- $(this).trigger('change');
- });
- });
-
- $body.on('click', '[data-action]', function () {
- var $this = $(this), data = {}, time = $this.attr('data-time'), action = $this.attr('data-action');
- var loading = $this.attr('data-loading'), method = $this.attr('data-method') || 'post';
- var rule = $this.attr('data-value') || (function (rule, ids) {
- $($this.attr('data-target') || 'input[type=checkbox].list-check-box').map(function () {
- (this.checked) && ids.push(this.value);
- });
- return ids.length > 0 ? rule.replace('{key}', ids.join(',')) : '';
- }).call(this, $this.attr('data-rule') || '', []) || '';
- if (rule.length < 1) return $.msg.tips('请选择需要更改的数据!');
- var rules = rule.split(';');
- for (var i in rules) {
- if (rules[i].length < 2) return $.msg.tips('异常的数据操作规则,请修改规则!');
- data[rules[i].split('#')[0]] = rules[i].split('#')[1];
- }
- data['_csrf_'] = $this.attr('data-token') || $this.attr('data-csrf') || '--';
- var load = loading !== 'false', tips = typeof loading === 'string' ? loading : undefined;
- if (!$this.attr('data-confirm')) $.form.load(action, data, method, false, load, tips, time);
- else $.msg.confirm($this.attr('data-confirm'), function () {
- $.form.load(action, data, method, false, load, tips, time);
- });
- });
-
- $body.on('blur', '[data-action-blur]', function () {
- var data = {}, that = this, $this = $(this), action = $this.attr('data-action-blur');
- var time = $this.attr('data-time'), loading = $this.attr('data-loading') || false;
- var load = loading !== 'false', tips = typeof loading === 'string' ? loading : undefined;
- var method = $this.attr('data-method') || 'post', confirm = $this.attr('data-confirm');
- var attrs = $this.attr('data-value').replace('{value}', $this.val()).split(';');
- for (var i in attrs) {
- if (attrs[i].length < 2) return $.msg.tips('异常的数据操作规则,请修改规则!');
- data[attrs[i].split('#')[0]] = attrs[i].split('#')[1];
- }
- that.callback = function (ret) {
- $this.css('border', (ret && ret.code) ? '1px solid #e6e6e6' : '1px solid red');
- return false;
- };
- data['_csrf_'] = $this.attr('data-token') || $this.attr('data-csrf') || '--';
- if (!confirm) return $.form.load(action, data, method, that.callback, load, tips, time);
- $.msg.confirm(confirm, function () {
- $.form.load(action, data, method, that.callback, load, tips, time);
- });
- });
-
- $body.on('click', '[data-href]', function (href) {
- href = $(this).attr('data-href');
- if (href && href.indexOf('#') !== 0) window.location.href = href;
- });
-
- $body.on('click', '[data-iframe]', function (index) {
- index = $.form.iframe($(this).attr('data-iframe'), $(this).attr('data-title') || '窗口');
- $(this).attr('data-index', index);
- });
-
- $body.on('click', '[data-icon]', function (field, location) {
- field = $(this).attr('data-icon') || $(this).attr('data-field') || 'icon';
- location = window.ROOT_URL + '?s=admin/api.plugs/icon.html&field=' + field;
- $.form.iframe(location, '图标选择');
- });
-
- $body.on('click', '[data-copy]', function () {
- $.copyToClipboard(this.getAttribute('data-copy'));
- });
- $.copyToClipboard = function (content, input) {
- input = document.createElement('textarea');
- input.style.position = 'absolute', input.style.left = '-100000px';
- input.style.width = '1px', input.style.height = '1px', input.innerText = content;
- document.body.appendChild(input), input.select(), setTimeout(function () {
- document.execCommand('Copy') ? $.msg.tips('复制成功') : $.msg.tips('复制失败,请使用鼠标操作复制!');
- document.body.removeChild(input);
- }, 100);
- };
-
- $body.on('mouseenter', '[data-tips-text]', function () {
- $(this).attr('index', layer.tips($(this).attr('data-tips-text'), this, {tips: [$(this).attr('data-tips-type') || 3, '#78BA32']}));
- }).on('mouseleave', '[data-tips-text]', function () {
- layer.close($(this).attr('index'));
- });
-
- $body.on('click', '[data-tips-image]', function () {
- $.previewImage(this.getAttribute('data-tips-image') || this.src, this.getAttribute('data-width'));
- });
- $.previewImage = function (src, area) {
- var img = new Image(), index = $.msg.loading();
- img.style.background = '#fff', img.style.display = 'none';
- img.style.height = 'auto', img.style.width = area || '480px';
- document.body.appendChild(img), img.onerror = function () {
- $.msg.close(index);
- }, img.onload = function () {
- layer.open({
- type: 1, shadeClose: true, success: img.onerror, content: $(img), title: false,
- area: area || '480px', closeBtn: 1, skin: 'layui-layer-nobg', end: function () {
- document.body.removeChild(img);
- }
- });
- };
- img.src = src;
- };
-
- $body.on('click', '[data-phone-view]', function () {
- $.previewPhonePage(this.getAttribute('data-phone-view') || this.href);
- });
- $.previewPhonePage = function (href, title) {
- var tpl = '<div><div class="mobile-preview pull-left"><div class="mobile-header">_TITLE_</div><div class="mobile-body"><iframe id="phone-preview" src="_URL_" frameborder="0" marginheight="0" marginwidth="0"></iframe></div></div></div>';
- layer.style(layer.open({type: true, scrollbar: false, area: ['320px', '600px'], title: false, closeBtn: true, shadeClose: false, skin: 'layui-layer-nobg', content: $(tpl.replace('_TITLE_', title || '公众号').replace('_URL_', href)).html(),}), {boxShadow: 'none'});
- };
-
- $body.on('click', '[data-history-back]', function (title) {
- title = this.getAttribute('data-history-back') || '确定要返回上一页吗?';
- $.msg.confirm(title, function (index) {
- history.back();
- $.msg.close(index);
- })
- });
-
- $body.on('blur', '[data-blur-number]', function (fiexd) {
- fiexd = this.getAttribute('data-blur-number') || 0;
- this.value = (parseFloat(this.value) || 0).toFixed(fiexd);
- });
-
- $body.find('[data-login-form]').map(function () {
- require(["md5"], function (md5) {
- $("form").vali(function (data) {
- data['password'] = md5.hash(md5.hash(data['password']) + data['skey']);
- if (data['skey']) delete data['skey'];
- $.form.load(location.href, data, "post", null, null, null, 'false');
- });
- });
- });
-
- document.addEventListener('error', function (e, elem) {
- elem = e.target;
- if (elem.tagName.toLowerCase() === 'img') {
- elem.src = baseRoot + 'theme/img/404_icon.png';
- }
- }, true);
-
- $.menu.listen();
- $.vali.listen();
- });
|