var cuiClass = [function(require, module, exports) { var Class = function() {}; //基类增加一个extend方法 Class.extend = function(prop) { var _super = this.prototype; //父类的实例赋给变量prototype var prototype = new this(); //把要扩展的属性复制到prototype变量上 for(var keyName in prop) { //下面代码是让ctor里可以直接访问使用this._super访问父类构造函数,除了ctor的其他方法,this._super都是访问父类的实例 prototype[keyName] = keyName == "ctor" && typeof prop[keyName] == "function" && typeof _super[keyName] == "function" ? (function(name, fn) { return function() { //备份一下this._super var tmp = this._super; //替换成父类的同名ctor方法 this._super = _super[name]; //执行,此时fn中的this里面的this._super已经换成了_super[name],即父类的同名方法 var ret = fn.apply(this, arguments); //把备份的还原回去 this._super = tmp; return ret; }; })(keyName, prop[keyName]) : prop[keyName]; } //假的构造函数 function Class() { //执行真正的ctor构造函数 this.ctor && this.ctor.apply(this, arguments); } //继承父类的静态属性 for(var key in this) { if(this.hasOwnProperty(key) && key != "extend") Class[key] = this[key]; } // 子类的原型指向父类的实例 Class.prototype = prototype; //这里一定要用new this //不能Class.prototype._super = prototype;(这里明显错误,prototype这时已经被copy进去了新的属性) //或者Class.prototype._super = _super;(这里会导致_super instanceof 不准确 ) Class.prototype._super = new this(); //覆盖父类的静态属性 if(prop.statics) { for(var name in prop.statics) { if(prop.statics.hasOwnProperty(name)) { Class[name] = prop.statics[name]; if(name == "ctor") { Class[name](); } } } } Class.prototype.constructor = Class; //原型可扩展 Class.extendPrototype = function(prop) { for(var name in prop) { prototype[name] = prop[name]; } }; //任何Class.extend的返回对象都将具备extend方法 Class.extend = arguments.callee; return Class; }; module.exports = Class; }, {}]; var cuiCore = [function (require, module, exports) { ; module.exports = (function (global) { if (global.cui) { return global.cui; } var cui = global.cui = { version: '2.0.0' }; var config = cui.config = { debug: true }; var DIRNAME_RE = /[^?#]*\//; function dirname(path) { return path.match(DIRNAME_RE)[0] } var doc = window.document, loc = window.location, cwd = dirname(loc.href), ArrayProto = Array.prototype, ObjProto = Object.prototype, FunProto = Function.prototype, LocalStorage = window.localStorage; cui.indexOf = function (target, arr) { if (ArrayProto.indexOf) { return arr.indexOf(target); } else { for (var i = 0, len = arr.length; i < len; i++) { if (arr[i] === target) { return i; } } } return -1; }; /** * @param {Function} 地图显示和查询方法. * 显示功能包括:包括经纬度、TGDID、地址、基站。 * 查询功能包括:经纬度、地址。 * @param {Oject} [options]存数相关数据。 * 由于地图组件要求跨域访问,所以IE暂不支持。 */ // 获取cui的路径. var scripts = doc.getElementsByTagName('script'), cuiScript = doc.getElementById('cuinode'), src, cuiDir; if (!cuiScript) { for (var i = 0, len = scripts.length; i < len; i++) { src = scripts[i].hasAttribute ? scripts[i].src : scripts[i].getAttribute("src", 4); if (src.indexOf('cui') !== -1) { cuiDir = dirname(src); break; } } } cui.cuiDir = cuiDir; var isType = function (type) { return function (object) { return ObjProto.toString.call(object) === "[object " + type + "]"; } } var type = cui.type = {}; var isObject = type.isObject = isType("Object"); var isString = type.isString = isType("String"); var isArray = type.isArray = Array.isArray || isType("Array"); var isFunction = type.isFunction = isType("Function"); var support = cui.support = { "placeholder": !!("placeholder" in document.createElement('input')) } /** * 使一个函数在规定的时间间隔内只执行一次(函数节流). * @param {Function} 需要节流的方法. * @param {Object} [context] 运行方法的上下文 * @param {Number} [ms] 运行方法的间隔时间,-1时节流不生效,默认为150. * @return {Function} 返回一个方法用以节流调用fn函数。 */ cui.throttle = function (fn, ms, context) { ms = ms || 150; if (ms === -1) { return (function () { fn.apply(context || this, arguments); }); } var start = new Date().getTime(); return (function () { var now = new Date().getTime(); if (now - start > ms) { start = now; fn.apply(context || this, arguments); } }); }; cui.stringFormat = function () { var a = arguments; if (a.length === 0) { return this; } return this.replace(/{(\d+)}/g, function (c, b) { return typeof a[b] != "undefined" ? a[b] : c; }); }; /* * 移除数组中的一项 * @param target 需要删除的目标。 * @param array 需要删除的数组。 * @return 返回新的数组。 */ cui.erase = function (target, array) { for (var i = 0, arrLen = array.length; i < arrLen; i++) { if (target === array[i]) { array.splice(i, 1); return array; } } ; }; /* * 在数组中添加一项 * @param target 需要添加的项 * @param index 需要添加的位置 * @param array 需要添加的数组 * @return 返回添加后的数组 */ cui.addArrItem = function (target, index, array) { var array = $.extend(true, [], array), tempfront = array.splice(0, index), tempfinale = array; tempfront.push(target); return tempfront.concat(tempfinale); }; // var private_loader = document.createElement('div'); // var private_body = document.getElementsByTagName('body')[0]; // private_loader.setAttribute('data-cuiloader', 'loader'); // private_body && private_body.appendChild(private_loader); var header = document.getElementsByTagName('head')[0]; /* * 获取不跨域的最顶层的window对象 * @return 最顶层的window对象 **/ cui.getTopWindow = function () { var twin = window; while (twin.parent && twin.parent != twin) { try { if (twin.parent.document.domain != document.domain) { break; } } catch (e) { break; } twin = twin.parent; } return twin; }; /* * 动态加载js */ var loadJS = cui.loadJS = function (url, fn) { // if (!private_body) { // private_body = document.getElementsByTagName('body')[0]; // private_body.appendChild(private_loader); // } var script = document.createElement('script'); script.type = 'text/javascript'; script.charset = 'UTF-8'; if (script.readyState) { // IE浏览器 script.onreadystatechange = function () { if (script.readyState == 'loaded' || script.readyState == "complete") { script.onreadystatechange = null; fn && fn(); } } } else { script.onload = function () { fn && fn(); } } script.src = url; //private_loader.appendChild(script); header.appendChild(script); }; var loadCss = cui.loadCss = function (url) { var link = document.createElement('link'); link.type = "text/css"; link.rel = "stylesheet"; link.href = url; document.getElementsByTagName('head')[0].appendChild(link); }; /* * 加载一个html片段模版 * @param url 需要加载的内容url * @param jqObj 需要将内容注入的区域jquery对象 * @注入完成后需要执行的回调函数 */ cui.loadTpl = function (jqObj, url, callback) { jqObj.load(url, function (data) { if (data.indexOf('placeholder') !== -1) { $('[placeholder]').cuiInput(); } else if (data.indexOf('select') !== -1) { $('select').cuiSelect(); } callback && callback(); }); }; cui.DBC2SBC = function (str) { var result = ""; if (!str) { return result; } for (var i = 0; i < str.length; i++) { code = str.charCodeAt(i); if (code >= 65281 && code <= 65373) { result += String.fromCharCode(str.charCodeAt(i) - 65248); } else if (code == 12288) { result += String.fromCharCode(str.charCodeAt(i) - 12288 + 32); } else { result += str.charAt(i); } } return result; }; /** * 提供兼容性的本地存储 */ if (!LocalStorage) { LocalStorage = { userData: null, name: location.hostname, init: function () { if (!LocalStorage.userData) { try { LocalStorage.userData = document.createElement("INPUT"); LocalStorage.userData.type = "hidden"; LocalStorage.userData.style.display = "none"; LocalStorage.userData.addBehavior("#default#userData"); var expires = new Date(); expires.setDate(expires.getDate() + 365); LocalStorage.userData.expires = expires.toUTCString(); } catch (e) { return false; } } return true; }, setItem: function (key, value) { if (LocalStorage.init()) { LocalStorage.userData.load(LocalStorage.name); LocalStorage.userData.setAttribute(key, value); LocalStorage.userData.save(LocalStorage.name); } }, getItem: function (key) { if (LocalStorage.init()) { LocalStorage.userData.load(LocalStorage.name); return LocalStorage.userData.getAttribute(key); } }, remove: function (key) { if (LocalStorage.init()) { LocalStorage.userData.load(LocalStorage.name); LocalStorage.userData.removeAttribute(key); LocalStorage.userData.save(LocalStorage.name); } } }; } cui.LocalStorage = this.LocalStorage = LocalStorage; /* * 判断浏览器是否支持console对象,log->alert, 增加console.time和console.timeEnd * 如果不支持(IE且未打开调试工具时,将console.log指向window.alert) */ window.cui_property = {}; /*if (!window.console) { window.console = {}; window.console.log = function(msg) { window.alert(msg); } }*/ // 重置掉console. window.console || (window.console = { log: function () { }, error: function () { } }); if (!window.console.time) { window.console.time = function (name) { window.cui_property[name] = +new Date(); } window.console.timeEnd = function (name) { var tempTime = +new Date(); window.console.log(name + '---耗时:' + (tempTime - window.cui_property[name]) + 'ms'); } } cui.baseModel = Class.extend({ statics: { baseUrl: '/test', save: function (data, url) { return $.ajax({ url: url || this.baseUrl, type: 'POST', data: data, async: false }); }, update: function (data, url) { return $.ajax({ url: url || (this.baseUrl + '/' + (data.id || '')), type: 'POST', async: false, data: $.extend({ _method: 'PUT' }, data) }) }, // 通过ajax获取数据,获取完毕以后,可以做展示前的处理:格式转换、特殊内容解析等 list: function (condition, url) { return $.ajax({ url: url || this.baseUrl, type: 'GET', data: condition }) }, 'delete': function (data, url) { return $.ajax({ url: url || (this.baseUrl + '/' + (data.id || '')), type: 'POST', async: false, data: $.extend({ _method: 'DELETE' }, data) }) } } }); // 浏览器判断 var ua = (window.navigator.userAgent || "").toLowerCase(), isIE7 = ua.indexOf("msie 7") !== -1, isIE8 = ua.indexOf("msie 8") !== -1; cui.browser = { isIE: ua.indexOf("msie") !== -1, isIE7: isIE7, isIE8: isIE8 }; return cui; })(window); }, {}]; var cuiEventAction = [function(require, module, exports) { /* * eventAction */ module.exports = function() { /* * 事件注册函数 */ 'use strict'; var action = {}; var selector = '[data-action]'; var _actionList = {}; function _getActionName($elemet) { var result = $elemet.data('action') || ''; if(!result) { var href = $.trim($elemet.attr('href')); if(href && href.indexOf('#') === 0) result = href; } return _formatActionName(result); } function _formatActionName(s) { return s ? $.trim(String(s).replace(/^[#!\s]+/, '')) : ''; } function _init() { var $wrapper = $(document.body || document.documentElement); $wrapper.on('click', selector, function(ev) { if($(this).data('action-preventdefault') !== false) { ev.preventDefault(); } var $elemet = $(this); var actionName = _getActionName($elemet); return _handle(actionName, this, ev); }); } function _handle(actionName, context, ev) { if(!actionName) { console.warn('[Action] Empty action. Do nothing.'); return; } var fn = _actionList[actionName]; if(fn && $.isFunction(fn)) { return fn.call(context || window, ev); } else { dialog.alert('[Action] 没有找到action:' + actionName); // if (dialog && typeof dialog.open === 'function') { // dialog.open({ // title: '错误!', // content: '[Action] 没有找到action:' + actionName, // btn: ['确定'] // }); // } console.error('[Action] Not found action %s', actionName); } } // api action.add = function(actionSet, ctx) { if($.isPlainObject(actionSet)) { $.each(actionSet, function(key, value) { var actionName = _formatActionName(key); if(actionName) { if($.isFunction(value)) { if(_actionList[actionName]) { console.warn('[Action] The existed action %s has been overriden', actionName); } var fun = ctx ? value.bind(ctx) : value; _actionList[actionName] = fun; } else { console.error('[Action] The function for action %s is invalid', actionName) } } else { console.error('[Action] The action name %s is invalid.', key); } }); } else { console.warn('[Action] Param must be a plain object'); } } action.trigger = function(actionName, context) { return _handle(_formatActionName(actionName), context); } // init _init(); window.eventAction = action; return action; } }, {}]; var cuiFactory = [function(require, module, exports) { /** * 所有ui组件的核心工厂方法。 * @ version 1.0.0 */ /* * @param name即是组件名,示例cuiDialog * @param prototype为name组件对应的原型方法 */ (function() { /** * cache all ui widget this page */ cui.uiWidget = {}; $.cuiFactory = function(name, prototype) { var uiName = name; // 给组件创建选择器 $.expr[":"][name] = function(elem) { return !!$.data(elem, name); }; $['cui'] = $['cui'] || {}; // 组件的构造器 $['cui'][name] = function(options, element) { if(arguments.length) { this._createCui(options, element); } }; // 属性的继承 var basePrototype = new $.CuiFactory(); // 深度合并为basePrototype添加属性 basePrototype.options = $.extend(true, {}, basePrototype.options); $['cui'][name].prototype = $.extend(true, basePrototype, { namespace: 'cui', uiName: uiName, widgetBaseClass: name }, prototype); $.cuiFactory.bridge(name, $['cui'][name]); }; $.cuiFactory.bridge = function(name, object) { $.fn[name] = function(options, element) { var query = arguments[0], methodInvoked = (typeof query == 'string'), queryArguments = [].slice.call(arguments, 1), returnValue = $(this); // 方法调用 if(methodInvoked) { this.each(function() { var instance = $.data(this, name); if(!instance) throw Error(name + '还没有被初始化'); if(instance.invoke[query]) { var methodValue = instance.invoke[query].apply(instance, queryArguments); if(methodValue !== instance && methodValue !== undefined) { returnValue = methodValue; return false; } } else { console.warn(query + '---方法不存在'); console.info(name + ' 组件你可以调用以下方法'); if(console.table) { console.table(instance.invoke); } else { console.info(instance.invoke); } } }); } else { // 初始化 this.each(function(index) { var instance = $.data(this, name); if(!instance) { /** * 增加组件实例id,可以通过该id获取到ui组件的实例 * 使用实例可以调用到组件的函数,及绑定事件 */ instance = new object(options, this); var id = instance._id; /** * 如果存在id,则生成id * 如果多个元素公用一个id,则用id+index来合并:id-1 */ id = index > 0 ? id + '-' + index : id; id && (cui.uiWidget[id] = instance); // if(id) { // cui.uiWidget[id] = instance; // for(var func in instance.invoke){ // instance[func] = instance.invoke[func]; // } // } $.data(this, name, instance); } }); } return returnValue; } }; $.CuiFactory = function(options, element) { if(arguments.length) { this._createCui(options, element); } }; $.CuiFactory.prototype = { _createCui: function(_options, element) { // 缓存数据 this.$el = $(element); // 合并所有的配置项,包括绑定在dom节点上的。 this.DEFAULTS = $.extend(true, {}, this.options); var options = this.options = $.extend(true, {}, this.options, this._getElementOptions(), _options); /** * 增加组件实例id,可以通过该id获取到ui组件的实例 * 使用实例可以调用到组件的函数,及绑定事件 */ this._id = options.uiId; this.onCreate = options.onCreate; // 新增组件是否已经创建完成标识。 this.__isCreated__ = false; // 有模版文件则执行模版文件,并将预编译的模版文件存放到this.tpl中 if(this._template) { this.tpl = this._template(); } // 执行_create方法 var _createValue = this._create(); this.__isCreated__ = true; // 触发_create事件 if(this.onCreate) { this.onCreate.call(this); } // 如果_create方法返回false,则退出创建UI对象。 if(_createValue === false) { return false; } // 绑定事件 this._bindUiEvents(); var that = this; // 覆盖默认的对外方法。 this.invoke = $.extend(true, { show: function() { that.$el.show(); }, hide: function() { that.$el.hide(); }, destroy: function() { that.$el.unbind('.' + this.uiName).removeData(this.uiName); //$(document).unbind('.' + this.uiName); }, // 获取(设置)一个组件对象的option.key option: function(key) { if(typeof key === 'string') { return that.options[key]; } }, getDefaults: function() { return that.DEFAULTS; } }, this.invoke); }, // 从元素中获取配置项。 _getElementOptions: function() { var options = this.$el.data(), reg = new RegExp('^' + this.uiName, 'i'), tempOptions = {}, tempDataName; for(var dataName in options) { if(reg.test(dataName)) { tempDataName = dataName.replace(reg, ''); tempDataName = tempDataName.charAt(0).toLowerCase() + tempDataName.substr(1); tempOptions[tempDataName] = options[dataName]; } } return tempOptions; }, _create: function() {}, on: function(eventname, func) { this.$el.on(eventname + '.' + this.uiName, func); }, off: function(eventname, func) { this.$el.off(eventname + '.' + this.uiName, func); }, icall: function(callname) { var argument = Array.prototype.slice.call(arguments); argument = argument.splice(1); var result = argument ? this.invoke[callname].apply(this, argument) : this.invoke[callname].apply(this); return result; }, /* * 绑定事件,在具体的组件类里需要有events对象 * events: { * 'click li': '_liClick', * 'hover .item': '_itemHover' * } */ _bindUiEvents: function() { var $el = this.$el, self = this, _eventsTarget, _eventsType, _eventsArr, _event_callback, expr = /(\S+)\s(.+)/, target = $el; if(this.events) { if('target' in this.events) { target = _.isFunction(this.events['target']) ? this.events['target'].call(this) : this.events['target']; } for(var _evets in this.events) { if(_evets === 'target') { continue; } _eventsArr = _evets.match(expr); _eventsTarget = _eventsArr[2]; _eventsType = _eventsArr[1]; _event_callback = null; if($.isFunction(this.events[_evets])) { _event_callback = this.events[_evets]; } else { _event_callback = this[this.events[_evets]]; } (function(_callback) { target.on(_eventsType + '.' + self.uiName, _eventsTarget, function(evt) { if(_callback.call(self, this, evt) === false) { return false; } }); })(_event_callback); } _eventsArr = null; _eventsTarget = null; _eventsType = null; _event_callback = null; } }, /* * 调用对外方法。 * @param {string} callname 对外方法函数名。 * @param {Array} 需要传递的参数。 * @return 返回对外方法的返回值。 * this.invokeCall('show', [akdlaskda,jja]); */ _iCall: function(callname, argumentA) { var result = argumentA ? this.invoke[callname].apply(this, argumentA) : this.invoke[callname].apply(this); return result; }, /** * 触发事件函数。 * @param {string} 需要触发的事件名 * @param {Array} 需要传递的参数。 * this._emit('onSelect', [id, value]) */ _emit: function(eventname, argumentA) { this.$el.trigger(eventname + '.' + this.uiName, argumentA); } }; })() }, {}]; var cuiForm = [function(require, module, exports) { module.exports = function() { var dateFormat = function(dateRange) { var dfString = "yyyy-MM-dd"; return util.dateFormat(dateRange[0], dfString) + " - " + util.dateFormat(dateRange[1], dfString); } var timeToString = { 365: function() { var t = util.time.getNearOneYear(); return dateFormat(t); }, 180: function() { var t = util.time.getNearHalfYear(); return dateFormat(t); }, 90: function() { var t = util.time.getNearThreeMonths(); return dateFormat(t); }, 30: function() { var t = util.time.getNearOneMonth(); return dateFormat(t); }, 7: function() { var t = util.time.getNearOneWeek(); return dateFormat(t); }, 3: function() { var t = util.time.getNearThreeDays(); return dateFormat(t); }, '-365': function() { var t = util.time.getFutureOneYear(); return dateFormat(t); }, '-180': function() { var t = util.time.getFutureHalfYear(); return dateFormat(t); }, '-90': function() { var t = util.time.getFutureThreeMonths(); return dateFormat(t); }, '-30': function() { var t = util.time.getFutureOneMonth(); return dateFormat(t); }, '-7': function() { var t = util.time.getFutureOneWeek(); return dateFormat(t); }, '-3': function() { var t = util.time.getFutureThreeDays(); return dateFormat(t); } } $(document).on("click", "form .cui-single-select .cui-single-select-item", function() { var $a = $(this).find("a"), timeRange = $(this).data("time-range"), $time = $(this).closest(".cui-single-select").find(".cui-user-define-range"), $timeText = $(this).closest(".cui-single-select").find(".cui-user-define-text"), valueType = $(this).data('value'), value; if($a.hasClass("cui-user-define-time-range")) { $time.css("display", "inline"); $timeText.css("display", "none"); $timeText.text(""); if(!$time.data("cuiCalendar")) { $time.cuiCalendar({ type: 'range', supportInput: $a.hasClass("support-input") ? true : false }); } } else if($a.hasClass("cui-user-define-time-end")) { $time.css("display", "inline"); $timeText.css("display", "none"); $timeText.text(""); if(!$time.data("cuiCalendar")) { $time.find("input").cuiCalendar({ range: [new Date(), new Date(2100, 0, 1)], supportInput: $a.hasClass("support-input") ? true : false }); } $time.find(".cui-user-define-range-start").text(util.dateFormat(new Date(), "yyyy-MM-dd")); } else if(timeRange !== "infinite" && timeRange !== undefined) { $time.css("display", "none"); $timeText.css("display", "inline"); $timeText.text(timeToString[timeRange]()); if(valueType === 'end') { value = timeToString[timeRange]().split(' - ')[1]; } else { value = timeToString[timeRange](); } $(this).find('input[type="radio"]').val(value); $(this).siblings('.cui-user-define-range').find('input[type="text"]').val(value); } else { $time.css("display", "none"); $timeText.css("display", "none"); $timeText.text(""); } $(this).siblings().find("a").removeClass("active"); $a.addClass("active"); }) $(document).on("click", "form .cui-muti-select a", function() { var $a = $(this); $a.toggleClass("active"); }) var deleteBtn = '删除' eventAction.add({ 'clone-add': function() { var $parent = $(this).closest(".cui-clone-input"), $dom, $cloneDom, newDom = '
添加
', $newDom; if(!$parent.data("cloneStatus")) { $parent.data("cloneStatus", true); $cloneDom = $parent.find(".cui-clone-wrap").clone(); $cloneDom.find("input[type='text']").val('').end().find("textarea").val('').end().find("input[type='checkbox']").prop("checked", false); $parent.data("cloneDom", $cloneDom); } $dom = $parent.data("cloneDom").clone(); $newDom = $(newDom); $newDom.find("a").before($dom); $parent.find(".row").eq(0).find('a[data-action="clone-add"]').remove().end().find('.cui-clone-wrap').after(deleteBtn).end().before($newDom); }, 'clone-delete': function() { var $parent = $(this).closest(".row"); $parent.remove(); } }) } }, {}]; var cuiFormUtils = [function(require, module, exports) {; module.exports = (function() { cui.form = { objectify: function($form, filter) { var returnObject = {}; var formArray = $form.serializeArray(); for(var i = 0; i < formArray.length; i++) { var item = formArray[i]; var value = filter ? filter(item.name, item.value) : item.value, name = item.name; if(returnObject[name] !== undefined) { if(!returnObject[name].push) { returnObject[name] = [returnObject[name]] } returnObject[name].push(value || ''); } else { returnObject[name] = value || ''; } } $form.find('input[type=checkbox]').each(function(index, item) { var $item = $(item), name = $item.attr('name'); if(!_.isArray(returnObject[name])) { returnObject[name] = []; } if($item.is(':checked')) { var value = filter ? filter(name, $item.val()) : $item.val(); if (!returnObject[name].contains(value)) { returnObject[name].push(value); } } }); return returnObject; } }; })() }, {}]; var cuiGlobal = [function(require, module, exports) { /* * @desc 一些常用的html样式的js */ module.exports = function() { //左侧菜单点击事件 $(document).on("click.left-menu", ".cui-left-menu li", function() { $(this).addClass('active').siblings().removeClass('active'); }); $(document).on("click.left-menu", ".cui-left-menu .cui-menu-toggle", function() { var _menu = $(this).closest('.cui-left-menu'); if(_menu.hasClass('menu-open')) { _menu.removeClass('menu-open'); _menu.stop().animate({ left: -156 }, 500); $(this).parents(".has-left-menu").animate({ paddingLeft: 0 }, 500); } else { _menu.addClass('menu-open'); _menu.stop().animate({ left: 0 }, 500); $(this).parents(".has-left-menu").animate({ paddingLeft: 157 }, 500); } }); $(".cui-menu-toggle").hover(function() { $(this).closest('.cui-left-menu').addClass('hover'); }, function() { $(this).closest('.cui-left-menu').removeClass('hover'); }); //切换按钮 $(document).on('click.switch-btn', '.cui-switch-btn li', function(event) { $(this).addClass('active').siblings().removeClass('active'); }); /* *多级分栏 *eszhang 2016-7-25增 */ //多级分栏 $(document).on('click.cui-tabs', '.cui-tabs .tab-items li', function(event) { $(this).siblings().removeClass('current').end().addClass('current'); }); } }, {}]; var cuiPositionUtils = [function(require, module, exports) { /* * @desc 位置基础服务 */ (function() { var position = { getPosition: function($el, $viewport, direction) { var $elH = $el.outerHeight(), $elW = $el.outerWidth(), $elOffsetX = $el.offset().left, $elOffsetY = $el.offset().top, $viewportH = $viewport.outerHeight(), $viewportW = $viewport.outerWidth(), position; if(direction === "right") { position = { left: $elW + $elOffsetX + 10, top: $elH / 2 + $elOffsetY - $viewportH / 2 }; } if(direction === "left") { position = { left: $elOffsetX - $viewportW - 10, top: $elH / 2 + $elOffsetY - $viewportH / 2 }; } if(direction === "top") { position = { left: $elOffsetX - ($viewportW / 2 - $elW / 2), top: $elOffsetY - $viewportH - 10 }; } if(direction === "bottom") { position = { left: $elOffsetX - ($viewportW / 2 - $elW / 2), top: $elOffsetY + $elH + 10 }; } return position; } } module.exports = position; })(); }, {}]; var cuiStartup = [function(require, module, exports) { /* * cui.js 入口文件 相关component的注册 */ /*依赖插件库*/ window.Class = require('./cui/base/class'); require('./cui/base/core'); window._ = require("./plugins/lodash/lodash"); // window._JQ = require("./lib/jquery/1.8.3/jquery"); window.template = require("./lib/template/template"); // window.cui = {}; /* 挂载cui下的模块*/ require('./cui/base/Nuts'); window.util = cui.util = require("./cui/base/util/index"); /*组件库*/ [ //全局的组件(base) require("./cui/base/uifactory/index"), // require("./cui/base/ajax/index"), require("./cui/base/eventAction/index"), require("./cui/base/form/index"), require("./cui/base/global/index"), //私有的组件(components) require("./cui/components/numberRoll/index"), require("./cui/components/pagin/index"), require("./cui/components/dialog/index"), require("./cui/components/dropdown/index"), require("./cui/components/calendar/index"), require("./cui/components/guide/index"), require("./cui/components/filter/index"), require("./cui/components/formtip/index"), require("./cui/components/sticky/index"), require("./cui/components/grid/index"), require("./cui/components/collapse/index"), require("./cui/components/select/index"), require("./cui/components/gridTree/index"), require("./cui/components/position/index"), require("./cui/components/overlay/index"), require("./cui/components/popover/index"), require("./cui/components/placeholder/index"), require("./cui/components/scrollspy/index"), require("./cui/components/operate/index"), require("./cui/components/tabsCard/index"), require("./cui/components/thinkInput/index"), require("./cui/components/tooltip/index"), require("./cui/components/tree/index"), require("./cui/components/treeEnhance/index"), require("./cui/components/nprogress/index"), // require("./cui/components/uploader/index"), //bootstrap(lib) // require("./lib/bootstrap/3.2.0/bootstrap"), //外部组件(plugins) require("./plugins/jquery-validate/jquery.validate"), require("./plugins/jquery-cookie/jquery-cookie"), // require("./plugins/nprogress/nprogress"), // require("./plugins/bs-datetimepicker/bs-datetimepicker"), require("./plugins/cui-map/index"), // require("./plugins/path/path"), // require("./plugins/umeditor/umeditor"), // require("./plugins/webuploader/cropper/cropper"), // require("./plugins/webuploader/webuploader.nolog") ].forEach(function(module) { (typeof module === "function") && module(); }) }, { "./lib/template/template": 2, "./cui/base/Nuts": 4, "./cui/base/class": 5, "./cui/base/core": 6, "./cui/base/eventAction/index": 7, "./cui/base/form/index": 8, "./cui/base/global/index": 9, "./cui/base/uifactory/index": 11, "./cui/base/util/index": 12, "./cui/components/calendar/index": 17, "./cui/components/collapse/index": 18, "./cui/components/dialog/index": 20, "./cui/components/dropdown/index": 21, "./cui/components/filter/index": 25, "./cui/components/formtip/index": 26, "./cui/components/grid/index": 30, "./cui/components/gridTree/index": 29, "./cui/components/guide/index": 39, "./cui/components/nprogress/index": 40, "./cui/components/numberRoll/index": 41, "./cui/components/operate/index": 46, "./cui/components/overlay/index": 48, "./cui/components/pagin/index": 49, "./cui/components/placeholder/index": 51, "./cui/components/popover/index": 52, "./cui/components/position/index": 53, "./cui/components/scrollspy/index": 54, "./cui/components/select/index": 55, "./cui/components/sticky/index": 57, "./cui/components/tabsCard/index": 58, "./cui/components/thinkInput/index": 64, "./cui/components/tooltip/index": 66, "./cui/components/tree/index": 71, "./cui/components/treeEnhance/index": 67, "./plugins/jquery-cookie/jquery-cookie": 74, "./plugins/jquery-validate/jquery.validate": 75, "./plugins/lodash/lodash": 77, "./plugins/cui-map/index": 80 }]; var cuiUtils = [function(require, module, exports) { module.exports = { newLine2br: function(str) { return (str || '').replace(/[\r\n]/g, '
') }, /** * [hasSameElement 比较两个数组是否有相同元素(使用数字型/字符串型)] * @DateTime 2017-07-13 * @copyright [copyright] * @license [license] * @version [version] * @param {[type]} firstArray [description] * @param {[type]} secondArray [description] * @return {Boolean} [返回true说明有相同元素] */ hasSameElement: function(firstArray, secondArray) { return(firstArray.length + secondArray.length) !== _.xor(firstArray, secondArray).length }, /** * [makeData2Tree 树节点转化] * @DateTime 2017-07-10 * @copyright [copyright] * @license [license] * @version [version] * @param {[type]} data [定义时以pid作为key定义父节点 父节点不存在传-1] * @return {[type]} [以父节点为key,所有的子节点的集合组成数组] */ makeData2TreeObject: function(data) { var groupedByParents = _.groupBy(data, 'pid'); var catsById = _.indexBy(data, 'id'); _.each(_.omit(groupedByParents, ''), function(children, parentId) { if(parentId !== '-1') { catsById['' + parentId].children = children; } }); _.each(catsById, function(cat) { cat.isParent = !_.isEmpty(cat.children); }); return groupedByParents; }, /** * [makeData2TreeList list形式] * @DateTime 2017-07-10 * @copyright [copyright] * @license [license] * @version [version] * @param {[type]} data [description] * @return {[type]} [description] */ makeData2TreeList: function(data) { var treeList = []; var groupedByParents = _.groupBy(data, 'pid'); var catsById = _.indexBy(data, 'id'); _.each(_.omit(groupedByParents, ''), function(children, parentId) { if(parentId !== '-1') { (catsById['' + parentId] || {}).children = children; } }); _.each(catsById, function(cat) { cat.isParent = !_.isEmpty(cat.children); }); treeList = groupedByParents['-1']; return treeList; }, /* * get a uuid whih prefix */ getUID: function(prefix) { do prefix += ~~(Math.random() * 1000000); while (document.getElementById(prefix)); return prefix; }, DBC2SBC: function(str) { var result = ""; if(!str) { return result; } for(var i = 0; i < str.length; i++) { code = str.charCodeAt(i); if(code >= 65281 && code <= 65373) { result += String.fromCharCode(str.charCodeAt(i) - 65248); } else if(code == 12288) { result += String.fromCharCode(str.charCodeAt(i) - 12288 + 32); } else { result += str.charAt(i); } } return result; }, /** * 获取url后面的参数 * @param 参数key * @return 参数值 */ getQueryString: function(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); var r = window.location.search.substr(1).match(reg); if(r != null) return r[2]; return null; }, Cookie: { set: function(name, value, expire) { var exp = new Date(); exp.setTime(exp.getTime() + expire * 24 * 60 * 60 * 1000); document.cookie = name + "=" + encodeURIComponent(value, "UTF-8") + ";expires=" + exp.toGMTString() + ";domain=passport.jd.com;path=/"; }, get: function(key) { var cookies = document.cookie ? document.cookie.split('; ') : []; for(var i = 0, l = cookies.length; i < l; i++) { var parts = cookies[i].split('='); var name = parts.shift(); var cookie = parts.join('='); if(key && key === name) { return cookie; } } }, setALCookie: function() { if($("input[name='rememberme']").prop("checked")) { var Days = 3 * 30; this.set("alpin", $("#handle").val(), Days); } else { var v = this.get("alpin"); if(v) { this.set("alpin", "", -100); } } } }, hashGoBack: function() { var prevHash = Path.routes.previous; if(prevHash) { location.hash = prevHash; } else { location.hash = ''; } }, dateFormat: function(date, format) { date = new Date(date); var map = { "M": date.getMonth() + 1, //月份 "d": date.getDate(), //日 "h": date.getHours(), //小时 "m": date.getMinutes(), //分 "s": date.getSeconds(), //秒 "q": Math.floor((date.getMonth() + 3) / 3), //季度 "S": date.getMilliseconds() //毫秒 }; format = format.replace(/([yMdhmsqS])+/g, function(all, t) { var v = map[t]; if(v !== undefined) { if(all.length > 1) { v = '0' + v; v = v.substr(v.length - 2); } return v; } else if(t === 'y') { return(date.getFullYear() + '').substr(4 - all.length); } return all; }); return format; }, time: { getYesterday: function() { var now = new Date(); return [new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1, 0, 0, 0), new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1, 23, 59, 59)]; }, getToday: function() { var now = new Date(); return [new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0), now]; }, getNearOneDay: function() { var now = new Date(); return [new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1, 0, 0, 0), now]; }, getNearThreeDays: function() { var now = new Date(); return [new Date(now.getFullYear(), now.getMonth(), now.getDate() - 3, 0, 0, 0), now]; }, getNearOneWeek: function() { var now = new Date(); return [new Date(now.getFullYear(), now.getMonth(), now.getDate() - 7, 0, 0, 0), now]; }, getNearOneMonth: function() { var now = new Date(); return [new Date(now.getFullYear(), now.getMonth(), now.getDate() - 30, 0, 0, 0), now]; }, getNearTwoMonths: function() { var now = new Date(); return [new Date(now.getFullYear(), now.getMonth(), now.getDate() - 60, 0, 0, 0), now]; }, getNearThreeMonths: function() { var now = new Date(); return [new Date(now.getFullYear(), now.getMonth(), now.getDate() - 90, 0, 0, 0), now]; }, getNearHalfYear: function() { var now = new Date(); return [new Date(now.getFullYear(), now.getMonth(), now.getDate() - 180, 0, 0, 0), now]; }, getNearOneYear: function() { var now = new Date(); return [new Date(now.getFullYear() - 1, now.getMonth(), now.getDate(), 0, 0, 0), now]; }, getFutureOneDay: function() { var now = new Date(); return [now, new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1, 0, 0, 0)]; }, getFutureThreeDays: function() { var now = new Date(); return [now, new Date(now.getFullYear(), now.getMonth(), now.getDate() + 3, 0, 0, 0)]; }, getFutureOneWeek: function() { var now = new Date(); return [now, new Date(now.getFullYear(), now.getMonth(), now.getDate() + 7, 0, 0, 0)]; }, getFutureOneMonth: function() { var now = new Date(); return [now, new Date(now.getFullYear(), now.getMonth(), now.getDate() + 30, 0, 0, 0)]; }, getFutureTwoMonths: function() { var now = new Date(); return [now, new Date(now.getFullYear(), now.getMonth(), now.getDate() + 60, 0, 0, 0)]; }, getFutureThreeMonths: function() { var now = new Date(); return [now, new Date(now.getFullYear(), now.getMonth(), now.getDate() + 90, 0, 0, 0)]; }, getFutureHalfYear: function() { var now = new Date(); return [now, new Date(now.getFullYear(), now.getMonth(), now.getDate() + 180, 0, 0, 0)]; }, getFutureOneYear: function() { var now = new Date(); return [now, new Date(now.getFullYear() + 1, now.getMonth(), now.getDate(), 0, 0, 0)]; }, date2day: function(targetDate) { var nowDate = new Date(), nowYear = nowDate.getFullYear(), nowMonth = nowDate.getMonth(), nowDay = nowDate.getDate(), targetYear = targetDate.getFullYear(), targetMonth = targetDate.getMonth(), targetDay = targetDate.getDate(), res; res = new Date(targetYear, targetMonth, targetDay) - new Date(nowYear, nowMonth, nowDay); res = Math.floor(res / 24 / 60 / 60 / 1000); return res; }, day2date: function(day) { var nowDate = new Date(), nowYear = nowDate.getFullYear(), nowMonth = nowDate.getMonth(), nowDay = nowDate.getDate(), nowHour = nowDate.getHours(), nowMinute = nowDate.getMinutes(), nowSecond = nowDate.getSeconds(); return new Date(nowYear, nowMonth, nowDay + day, nowHour, nowMinute, nowSecond); } }, /** * 获取可以滚动的元素,overflow:auto的儿子元素 * rewrite by clu on 2018-11-12 10:18:31 修复IE10、11下的获取异常 * @param {Object} node */ getScrollParent: function(node) { var currentNode = $(node); var parentNode = $(node).parent(); while (parentNode.length > 0) { if (parentNode.scrollTop() > 0 || // add by clu on 2020-7-14 16:30:35 对layui做兼容 parentNode.hasClass('layui-layer-content')) { return currentNode; } else { currentNode = parentNode; parentNode = parentNode.parent(); } } return null; /*if(node === null) { return null; } if(node.scrollHeight > node.clientHeight) { return node; } else { return this.getScrollParent(node.parentNode); }*/ } }; }, {}]; var cuiBrowserifyCss = [function(require, module, exports) { 'use strict'; // For more information about browser field, check out the browser field at https://github.com/substack/browserify-handbook#browser-field. var styleElementsInsertedAtTop = []; var insertStyleElement = function(styleElement, options) { var head = document.head || document.getElementsByTagName('head')[0]; var lastStyleElementInsertedAtTop = styleElementsInsertedAtTop[styleElementsInsertedAtTop.length - 1]; options = options || {}; options.insertAt = options.insertAt || 'bottom'; if(options.insertAt === 'top') { if(!lastStyleElementInsertedAtTop) { head.insertBefore(styleElement, head.firstChild); } else if(lastStyleElementInsertedAtTop.nextSibling) { head.insertBefore(styleElement, lastStyleElementInsertedAtTop.nextSibling); } else { head.appendChild(styleElement); } styleElementsInsertedAtTop.push(styleElement); } else if(options.insertAt === 'bottom') { head.appendChild(styleElement); } else { throw new Error('Invalid value for parameter \'insertAt\'. Must be \'top\' or \'bottom\'.'); } }; module.exports = { // Create a tag with optional data attributes createLink: function(href, attributes) { var head = document.head || document.getElementsByTagName('head')[0]; var link = document.createElement('link'); link.href = href; link.rel = 'stylesheet'; for(var key in attributes) { if(!attributes.hasOwnProperty(key)) { continue; } var value = attributes[key]; link.setAttribute('data-' + key, value); } head.appendChild(link); }, // Create a ').appendTo('head'); $(window).on('scroll.cui-grid', function() { self._adjustScroll(); }); setTimeout(function() { self._adjustScroll(); }, 40); break; case 0: headFixed.show = false; $el.find('.cui-grid-head').cuiSticky("unstick"); $el.find('.cui-grid-thead').cuiSticky("unstick"); $(window).off("scroll.cui-grid"); $el.removeClass('has-scrollh-fixed'); $el.find('.cui-grid-scroll-h').outerWidth("auto"); break; } }, //2017-07-06 add 添加新样式 _fixedStyle: function() { var that = this, $el = this.$el, $srollH = $el.find('.cui-grid-scroll-h'), srollHSL = $srollH.scrollLeft(), srollHWrapWidth, scrollHContentWidth; srollHWrapWidth = $srollH.width(); scrollHContentWidth = $srollH.find('>div').outerWidth(); $el.find(".cui-grid-tbody .grid-front-fixed").removeClass("grid-front-fixed-shadow"); $el.find(".cui-grid-tbody .grid-finale-fixed").removeClass("grid-finale-fixed-shadow"); if(srollHWrapWidth < scrollHContentWidth) { if(srollHSL == 0) { $el.find(".cui-grid-tbody .grid-finale-fixed").addClass("grid-finale-fixed-shadow") } else if(srollHSL == scrollHContentWidth - srollHWrapWidth) { $el.find(".cui-grid-tbody .grid-front-fixed").addClass("grid-front-fixed-shadow") } else { $el.find(".cui-grid-tbody .grid-front-fixed").addClass("grid-front-fixed-shadow"); $el.find(".cui-grid-tbody .grid-finale-fixed").addClass("grid-finale-fixed-shadow"); } } }, invoke: { /* * 设置表格数据。 * @param body 为表格体数据。 * @param head 为表格头部数据。 * 当只有一个参数时,为body,当两个参数时,为head和body。 */ data: function(head, body) { var $el = this.$el, options = this.options; if(arguments.length === 1) { body = head; head = null; } this.isStickWidth = false; if(body && !head) { options.body = body; // 如果没有渲染,则退出 if(!options.autoRender && !this.renderdy) return; this._iCall('colOpts', [options.colOpts.data]); this._renderBody(); this._adjustGrid(); return this; } if(body && head) { options.body = body; options.head = head; // 如果没有渲染,则退出 if(!options.autoRender && !this.renderdy) return; this._createTable(); return this; } }, /* * 设置行操作。 * @param data 操作数据 */ colOpts: function(data) { var options = this.options, hasOptData = options.colOpts.data, body = options.body; if(!!!data || !!!body) return; options.colOpts.data = data; // 如果默认不渲染且表格没有渲染,则退出 if(!options.autoRender && !this.renderdy) return; (!hasOptData) && this._renderHead(); this._renderBody(); this._adjustGrid(); }, /** * 更新分页信息 * @param {Number} current 当前页码 * @param {Number} total 总页码数 */ updatePagin: function(current, total) { if(current) { this.$el.find('.cui-grid-pagin').cuiPagin('current', current); this._model.condition.page = current; } if(total) { this.$el.find('.cui-grid-pagin').cuiPagin('total', total); } }, reload: function(condition) { dialog.load(); var that = this; if(!this._model) return; condition = condition ? condition : {}; condition = $.extend(this._model.condition, condition); this._model.list(condition).then(function(res) { that._iCall('data', [res.data]); if (_.isObject(res.pagin)) { that.$el.find('.cui-grid-pagin').cuiPagin('total', res.pagin.records); // add by clu on 2018-9-30 14:12:09 页数不够,后台会修改,前台界面要更新 that._model.condition.page = res.pagin.page; that.$el.find('.cui-grid-pagin').cuiPagin('current', res.pagin.page); } dialog.closeAll('loading'); // that._initPagin({ // page: condition.page, // pageItems: condition.pagesize, // records: res.pagin.records // }); }); }, /* * 获取checkbox选中的索引 */ getCheckedIndex: function() { var indexs = this.checkedArray, i, len, selectRows = []; if(this.tempBody && indexs) { for(i = 0, len = indexs.length; i < len; i++) { selectRows.push(this.tempBody[indexs[i]]); } } var result = { selectIndexs: indexs, selectRows: selectRows }; return result; }, getSelectedRow: function(modelData) { var $tr = this.$el.find('.cui-grid-active').eq(0); // add by clu on 2018-9-14 14:20:15 添加对带有checkbox模式下找不到选中行的问题 // 没有CheckBox的时候,点击行操作列中的按钮的时候,会先选中当前行,然后再触发删除事件,带有CheckBox以后,就不会自动选中了 if($tr.length == 0 && modelData && modelData.self) { $tr = $(modelData.self).parents('tr'); } var row; if(this.tempBody && $tr && $tr.length > 0) { row = this.tempBody[$tr.index()] } return row; }, getSelectedRows: function() { var $trs = this.$el.find('.cui-grid-table .cui-grid-active'), rows = [], that = this; if(this.tempBody && $trs.size()) { $trs.each(function(index, item) { rows.push(that.tempBody[$(item).index()]) }); } return rows; }, addRowRemote: function(row, callback) { var that = this; // add by clu on 2018年11月17日17:27:23 增加对remoteHandler的支持 var jqXHR; if (typeof that.options.remoteHandler.add === 'function') { jqXHR = that.options.remoteHandler.add.call(that, row, callback); } if (jqXHR === undefined) { if(this._model) { jqXHR = this._model.save(row, that.options.getUrl(that.options.url, 'save')); } } jqXHR.then(function(res) { if(res.code === 0) { dialog.msg('添加成功', { icon: 1 }); that._iCall('reload'); } else { dialog.msg(res.msg, { icon: 11 }) } callback && callback(res); }); }, // 远程删除一行, 默认为选中的 deleteRowRemote: function(row, callback) { var that = this; if(arguments.length === 1) { callback = row; row = null; } if(!this._model) return; if(!row) { row = this._iCall('getSelectedRow'); } if(!row) { dialog.msg('请选择一条数据', { icon: 11 }); return; } // add by clu on 2018年11月17日17:27:23 增加对remoteHandler的支持 var jqXHR; if (typeof that.options.remoteHandler.delete === 'function') { jqXHR = that.options.remoteHandler.delete.call(that, row, callback); } if (jqXHR === undefined) { if (this._model) { jqXHR = this._model.delete(row, that.options.getUrl(that.options.url, 'delete', row)); } } jqXHR.then(function(res) { res = res || { code: -1, msg: '服务端响应数据错误!' }; if(res.code === 0) { dialog.msg('删除成功', { icon: 1 }); that._iCall('reload'); } else { dialog.msg(res.msg, { icon: 11 }) } callback && callback(res); }); }, updateRowRemote: function(row, callback) { var that = this; // add by clu on 2018年11月17日17:27:23 增加对remoteHandler的支持 var jqXHR; if (typeof that.options.remoteHandler.update === 'function') { jqXHR = that.options.remoteHandler.update.call(that, row, callback); } if (jqXHR === undefined) { if(this._model) { jqXHR = this._model.update(row, that.options.getUrl(that.options.url, 'update', row)); } } if (jqXHR) { jqXHR.then(function (res) { if(res.code === 0) { dialog.msg('更新成功', { icon: 1 }); that._iCall('reload'); } else { dialog.msg(res.msg, { icon: 11 }) } callback && callback(res); }); } }, /* * 渲染表格 */ render: function() { var options = this.options; if(!options.autoRender && this.renderdy) return; this.render(); }, /* * 获取表格search关键词 */ getSearchKeyword: function() { return this.$el.find("#grid-search-input").val(); }, /* * 拖拽列启动关闭 */ setColDrag: function(typeBollen) { var type = (!!typeBollen) ? 1 : 0; if(this.minWidth) return; this._colDragEvent(type); }, setHeadFixed: function(typeBollen, topSpacing) { var headFixed = this.options.headSettings.headFixed, type = (!!typeBollen) ? 1 : 0; if((this.options.type === "simple") || (headFixed.show == (!!typeBollen))) return; if(typeBollen) { headFixed.fixedTop = topSpacing || 0; } this._setHeadFixed(type); }, /** * 扩展行数据 * @param key * @param value */ setRowExtendData: function(key, value) { this.rowExtendData[key] = value; }, //2017-07-05 add checkbox切换对外方法 toggleRowSelected: function(rowArr) { var that = this, $el = this.$el, tempBody = this.tempBody, checkedIndexArr = [], matchIndex = -1, trIndex = -1, $trCheckbox; var $table_doms = $el.find('.cui-grid-tbody').find("table"); if(!_.isArray(rowArr)) { rowArr = [rowArr] } _(rowArr).forEach(function(n) { trIndex = -1; matchIndex = -1; //考虑id有可能为0 if(_.isNumber(n)) { trIndex = n; } else if(n && _.isNumber(n.id - 0)) { _(tempBody).forEach(function(m, mIndex) { if(m.id == n.id) { matchIndex = mIndex } }).value(); (matchIndex !== -1) && (trIndex = matchIndex) } if(trIndex !== -1) { checkedIndexArr.push(trIndex); $trCheckbox = $el.find('.cui-grid-tbody').find('.grid-front-fixed').find('.cui-grid-checkbox').find('input[type=checkbox]').eq(trIndex); tempBody[trIndex].checked = true; if(!$trCheckbox.attr("disabled")) { $trCheckbox.prop("checked", true); $table_doms.find('tr:eq(' + trIndex + ')').addClass('cui-grid-active') } } }).value(); this._updateCheckArray(); }, createModel: function(createModelData) { var that = this, createTpl = this._model.tpl.create; createModelData = $.extend({_action: 'create'}, createModelData); if (!createTpl || typeof createTpl.tpl !== 'function') { dialog.alert('您未设置modelTpl'); console.error('您未设置modelTpl'); return; } var a = dialog.open({ title: createModelData.modelData.createModelTitle || '新建', btn: ['确定', '取消'], type: 1, content: createTpl.tpl(createModelData), area: [createTpl.width, createTpl.height], success: function(layero, index) { // 触发duringCreateModel事件,便于处理 var layerContent = layero[0].children[1]; that._emit('duringCreateModel', [layerContent, index, createModelData]); }, maxmin: true, yes: function(index) { var $form = $('#layui-layer' + index).find('form'); if(!$form.valid()) return false; var user = cui.form.objectify($form); that._iCall('addRowRemote', [user, function(res) { if(res.code === 0) { dialog.close(index); } that._emit('afterCreateModel', [res]); }]); } }); }, updateModel: function(updateModelData) { var row = this._iCall('getSelectedRow', [updateModelData]), updateTpl = this._model.tpl.update, that = this; if(!row) { dialog.msg('请指定需要修改的数据', { icon: 11 }); return; } updateModelData = $.extend({_action: 'update'}, updateModelData); var title = updateModelData.self && updateModelData.self && $(updateModelData.self).attr('data-title') || '编辑'; dialog.open({ title: title, btn: ['确定', '取消'], type: 1, content: updateTpl.tpl($.extend(updateModelData, row)), area: [updateTpl.width, updateTpl.height], maxmin: true, success: function(layero, index) { // 打开编辑框的时候触发一下duringUpdateModel事件,便于处理 var layerContent = layero[0].children[1]; that._emit('duringUpdateModel', [layerContent, index, updateModelData]); }, yes: function(index, layero) { var $form = $('#layui-layer' + index).find('form'); if(!$form.valid()) return false; // add by clu on 2018-11-20 20:43:40 添加更新前的回调 if (typeof that.options.handlers.beforeUpdate === 'function') { if (that.options.handlers.beforeUpdate.call(that) === false) { return false; } } var user = cui.form.objectify($($form)); user = $.extend({}, { id: row.id }, user); that._iCall('updateRowRemote', [user, function(res) { if(res.code === 0) { dialog.close(index); } that._emit('afterUpdateModel', [res]); }]); } }); }, deleteModel: function(deleteModelData) { var row = this._iCall('getSelectedRow', [deleteModelData]), that = this; if(!row) { dialog.msg('请指定需要删除的数据', { icon: 11 }); return; } else { dialog.confirm('确定要删除该条记录吗?', function() { that._iCall('deleteRowRemote', [row, function(res) { that._emit('afterDeleteModel', [res]); }]); }); } }, detailModel: function(detailModelData) { var row = this._iCall('getSelectedRow', [detailModelData]), detailTpl = this._model.tpl.detail, that = this; detailModelData = $.extend({_action: 'detail'}, detailModelData); dialog.open({ title: '详情', type: 1, content: detailTpl.tpl($.extend(detailModelData, row)), area: [detailTpl.width, detailTpl.height], maxmin: true, success: function(layero, index) { // 触发duringDetailModel事件,便于处理 var layerContent = layero[0].children[1]; that._emit('duringDetailModel', [layerContent, index, detailModelData]); }, btn: ['关闭'] }); } } }); } }, { "./simpleTable.tpl": [function(require, module, exports) { module.exports = "
\n
"; }, {}], "./simpleTbody.tpl": [function(require, module, exports) { module.exports = "\n\t{{each bodyCenter}}\n\t\t\n\t\t\t{{each $value}}\n\t\t\t\t\t\n\t\t\t\t\t\t
{{#$value}}
\n\t\t\t\t\t\n\t\t\t{{/each}}\n\t\t\n\t{{/each}}\n"; }, {}], "./simpleThead.tpl": [function(require, module, exports) { module.exports = "\n \n {{each headCenter}}\t \n \n {{/each}}\n \n\t\n\t\t\n\t\t\t{{each headCenter}}\n\t\t\t\t\n\t\t\t\t\t
{{#$value.label}}{{if $value.sort}}{{/if}}
\n\t\t\t\t\n\t\t\t{{/each}}\n\t\t
\n\t\n
"; }, {}], "./table.tpl": [function(require, module, exports) { module.exports = "
\n \n\n \n {{if opts!== null || settings.filter}}\n
\n
\n {{if opts !== null}}\n \t\t\t\t
\n \t\t\t\t\t{{each opts}}\n \t\t\t\t\t \n \t\t\t\t\t\t\t\t\n \t\t\t\t\t\t\t\t{{$value.label}}\n \t\t\t\t\t \n \t\t\t\t\t{{/each}}\n \t\t\t\t
\n \t\t\t{{/if}}\n {{if settings.filter}}\n
\n {{if settings.filter === true}}\n
\n
\n
\n
\n \n 查询\n
\n
\n
\n
\n {{/if}}\n
\n {{/if}}\n\t\t
\n
\n {{/if}}\n \n
\n
\n \n
\n
\n \n
\n
\n
"; }, {}], "./tbody.tpl": [function(require, module, exports) { module.exports = "{{if checkbox === true || (headFront.length>0)}}\n
\n\t \n\t \n\t {{if checkbox === true }}\n\t \n\t {{/if}}\n\t\t {{each headFront}}\t \n\t \n\t\t {{/each}}\n \n\t\t\t\n\t\t\t\t{{each bodyFront}}\n\t\t\t\t\t\n\t\t\t\t\t\t{{if checkbox === true}}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t{{/if}}\n\t\t\t\t\t\t{{each $value}}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t
{{#$value}}
\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t{{/each}}\n\t\t\t\t\t
\n\t\t\t\t{{/each}}\n\t\t\t\n\t\t
\n\t\t\t\t\t\t\t\t
\n\t\t\t\t\t\t\t\t \n\t\t\t\t\t\t\t\t
\n\t\t\t\t\t\t\t
\n\t
\n{{/if}}\n
\n\t\n\t \n\t\t {{each headCenter}}\t \n\t\t \n\t\t\t {{/each}}\n\t\t\t\n\t\t \n\t\t\t {{each bodyCenter}}\n\t\t\t\t \n\t\t\t\t\t\t{{each $value}}\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t
{{#$value}}
\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t{{/each}}\n\t\t\t\t\t
\n\t\t\t\t{{/each}}\n\t\t\t\n\t
\n
\n{{if colOpts.data || (headFinale.length>0)}}\n\t
\n\t\t\n\t\t \n\t\t\t {{each headFinale}}\t \n\t\t \n\t\t\t {{/each}}\n\t\t\t {{if colOpts.data }}\n\t \n\t {{/if}}\n\t\t\t\n\t\t\t\n\t\t\t\t{{each bodyFinale}}\n\t\t\t\t\t\n\t\t\t\t\t\t{{each $value}}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t
{{#$value}}
\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t{{/each}}\n\t\t\t\t\t\t{{if colOpts.data}}\n\t\t\t\t\t\t\t
\t\n\t\t\t\t\t {{/if}}\n\t\t\t\t\t\n\t\t\t\t{{/each}}\n\t\t\t\n\t\t
\n\t\t\t\t\t\t\t\t
\n\t\t\t\t\t\t\t\t\t{{if colOpts.type === \"panel\"}}\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t操作\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t{{else}}\n\t\t\t\t\t\t\t\t\t{{each colOpts.data[$index] as $value i}}\n\t\t\t\t\t\t\t\t\t {{if $value.icon}}{{/if}}{{if $value.label}}{{$value.label}}{{/if}}\n\t\t\t\t\t\t\t\t\t{{/each}}\n\t\t\t\t\t\t\t\t {{/if}}\n\t\t\t\t\t\t\t\t
\n\t\t\t\t\t\t\t
\n\t
\n{{/if}}"; }, {}], "./tbodyNoData.tpl": [function(require, module, exports) { module.exports = "
\n
\n\t \n\t 暂无数据\n\t
\n
"; }, {}], "./thead.tpl": [function(require, module, exports) { module.exports = "\n{{if checkbox === true || (headFront.length>0)}}\n
\n \n \n {{if checkbox === true }}\n \n {{/if}}\n {{each headFront}}\n \n {{/each}}\n \n \n \n {{if checkbox === true }}\n \n {{/if}}\n {{each headFront}}\n \n
\n {{#$value.label}}\n {{if $value.sort}}\n \n {{/if}}\n
\n \n {{/each}}\n
\n \n
\n
\n
\n
\n{{/if}}\n\n
\n \n \n {{each headCenter}}\n \n {{/each}}\n \n \n \n {{each headCenter}}\n \n
\n \n {{#$value.label}}\n {{if $value.sort}}\n \n {{/if}}\n {{if $value.title}}\n \n {{/if}}\n
\n \n {{/each}}\n
\n \n
\n
\n\n{{if colOpts.data || (headFinale.length>0)}}\n
\n \n \n {{each headFinale}}\n \n {{/each}}\n {{if colOpts.data }}\n \n {{/if}}\n \n \n \n {{each headFinale}}\n \n
\n {{#$value.label}}\n {{if $value.sort}}\n \n {{/if}}\n
\n \n {{/each}}\n {{if colOpts.data }}\n
\n {{/if}}\n \n \n
\n
操作!!!!
\n
\n
\n{{/if}}"; }, {}], } ]; var cuiGuideImpl = [function(require, module, exports) { /* * @desc formtip组件 * @Date 2016-04-06 */ var guideTpl = template.compile(require("./guide.tpl")) module.exports = function() { $.cuiFactory("cuiGuide", { options: { //分布引导样式,目前分为styleA,styleB两级 style: 'styleA', //分步的标题 data: null, //当前的位置 current: 1 }, _create: function() { this._preRenderData(); }, // 准备所有需要渲染的数据 _preRenderData: function() { var options = this.options, _renderData = {}, data = this.data || (this.data = options.data), current = options.current; this._renderData = _renderData = { data: data, current: current }; this._createDom(); }, /**创建dom节点**/ _createDom: function() { var html = guideTpl(this._renderData), $el = this.$el, options = this.options; $el.addClass('cui-guide').addClass(options.style); $el.empty().append(html); }, invoke: { //设置current current: function(_current) { var options = this.options; options.current = _current; this._preRenderData(); } } }); } }, { "./guide.tpl": [function(require, module, exports) { module.exports = ""; }, {}] }]; var cuiGridTreeImpl = [function (require, module, exports) { var treeTpl = template.compile(require("./gridTree.tpl")), treeRootTpl = template.compile(require("./gridTree_root.tpl")); module.exports = function () { $.cuiFactory("cuiGridTree", { VERSION: '1.0.0', options: { //根节点数据:{icon:"",label:"",selected:false} root: null, //表头部分数据 head: null, //树的数据集合:[{icon:"",label:"",id:"",pid:"",disabled:false}] data: [], url: null, //树数据的数据形式,“array”为一维数组形式,“tree”树形形式 dataType: "array", //树有大小两种无数据样式0:小样式,1:大样式 noDataStyle: 0, // 表格的操作数据。 opts: null, //组件初始化展示方式:0:展示一级菜单其余全部收起;1:全部展开,显示所有节点;2:收起全部 showType: 1 }, _create: function () { this._renderTree(); if (!!this.options.url) { this._initModel(); } }, // 实际初始化和渲染树的方法 _renderTree: function () { this.bakData = $.extend(true, [], this.options.data); this.nodesString = []; this.arrayTypeData = []; this.tempBody = []; this._tidyData(); this._generateKv(); this._preRenderData(); this._createDom(this._renderData); this._generateKv(); }, // 初始化数据渲染(当通过url传递数据时) _initModel: function () { var that = this, modelTpl = this.options.modelTpl, _tpls; if (!that.options.url) return; that._model = cui.baseModel.extend({ statics: { baseUrl: that.options.url } }); _tpls = this._model.tpl = {}; /** * this.model.tpl 缓存改模型的模版 * 包含:create,update,detail */ if (_.isObject(modelTpl)) { for (var action in modelTpl) { $tplDom = $('#' + modelTpl[action]); _tpls[action] = { tpl: template.compile($tplDom.html()), width: $tplDom.attr('width'), height: $tplDom.attr('height') } } } else { /** String时 */ _tpls.create = _tpls.detail = _tpls.update = { tpl: template.compile($('#' + modelTpl).html()), width: $('#' + modelTpl).attr('width'), height: $('#' + modelTpl).attr('height') } } that._model.list().then(function (res) { if (res.code === 0) { that._iCall('data', [res.data]); that._emit('afterRender', [res.data]); } }); }, //判断传过来的数据是树形结构还是数组结构 _tidyData: function () { var data = this.bakData; var that = this; if (this.options.dataType === "tree") { this._tree2Array(data); this.bakData = this.arrayTypeData; } _.forEach(this.bakData, function (node, i) { //为了减少循环次数把这块逻辑加进来 if (that.options.dataType === "tree" && node.childList) { delete node.childList; } }) }, //树形数据转换成数组 _tree2Array: function (data) { for (var i = 0; i < data.length; i++) { this.arrayTypeData.push(data[i]); if (data[i].childList && data[i].childList.length > 0) { this._tree2Array(data[i].childList); } } ; }, events: { //指定绑定事件的元素 'target': function () { return this.$el; }, 'click td.td-first>a': function (self, evt) { var isParent = $(self).closest("tr").attr("isparent"); var nexts = null; if (isParent === "true") { nexts = $(self).closest("tr").nextAll("[pid=" + $(self).closest("tr").attr("tid") + "]"); $(self).closest("tr").toggleClass("open"); if ($(self).closest("tr").hasClass("open")) { nexts.removeClass("tr-hide"); this._findNexts(nexts); } else { nexts.addClass("tr-hide"); this._findNexts(nexts, 1); } } }, 'click td.td-root>a': function (self, evt) { var nexts = $(self).closest("tr").nextAll("[tlevel=0]"); $(self).closest("tr").toggleClass("open"); if ($(self).closest("tr").hasClass("open")) { nexts.removeClass("tr-hide"); this._findNexts(nexts); } else { nexts.addClass("tr-hide"); this._findNexts(nexts, 1); } }, 'click [data-role="createModel"]': function (self, evt) { var that = this; setTimeout(function () { that._iCall('createModel', [that._getModelData(self, 'createModel')]); }, 0); }, 'click [data-role="updateModel"]': function (self, evt) { var that = this; setTimeout(function () { that._iCall('updateModel', [that._getModelData(self, 'updateModel')]); }, 0); }, 'click [data-role="deleteModel"]': function (self, evt) { var that = this; setTimeout(function () { that._iCall('deleteModel', [that._getModelData(self, 'deleteModel')]); }, 0); }, 'click [data-role="detailModel"]': function () { var that = this; setTimeout(function () { that._iCall('detailModel', [that._getModelData(self, 'detailModel')]); }, 0); }, // 表格操作按钮点击事件 'click .cui-grid-opt-btn': function (self, evt) { if (!$(self).hasClass('cui-disabled')) { var index = $(self).index(); this._emit('optsClick', [this.options.opts[index], this.checkedArray]); } }, // 行hover事件 'mouseover tr': function (self, evt) { var $tbody = this.$el.find('.cui-gridTree-tbody'); if (!!$(self).closest('.cui-gridTree-tbody').size()) { $tbody.find('tr').removeClass('cui-gridTree-hover'); var index = $(self).index(); $tbody.find('tr').eq(index).addClass('cui-gridTree-hover'); } }, // 行hover操作 'mouseout tr': function (self, evt) { (!!$(self).closest('.cui-gridTree-tbody').size()) && this.$el.find('.cui-gridTree-tbody tr').removeClass('cui-gridTree-hover'); }, 'click tr': function (self, evt) { var index = $(self).index(); this._selectOneRow(index); this._emit('rowSelected', [$(self), index]); } }, // 获取按钮绑定的初始化数据,在调用create、update、delete、detail模板渲染的时候,会传入相关参数 _getModelData: function (self, dataRole) { var data = { self: self }, $self = $(self); data.modelData = $.extend({}, $.parseJSON($self.attr('data-modelData') || '{}'), $self.data('data-modelData') || {}); return data; }, _selectOneRow: function (index) { this.$el.find('.cuiGridTree tbody tr').removeClass('cui-gridTree-active'); this.$el.find('.cuiGridTree tbody tr').eq(index).addClass('cui-gridTree-active'); }, _findNexts: function (nodes, status) { var tempNexts = $.extend(true, [], nodes); var that = this; _.forEach(tempNexts, function (node, i) { var isParent = $(node).attr("isparent"); var isOpen = $(node).hasClass("open"); if (isParent === "true") { var subs = $(node).nextAll("[pid=" + $(node).attr("tid") + "]"); if (status) { subs.addClass("tr-hide"); } else { isOpen ? subs.removeClass("tr-hide") : subs.addClass("tr-hide"); } if (status) { that._findNexts(subs, 1); } else { that._findNexts(subs); } } }); }, //创建数据 _convert: function () { var data = this.bakData, result = []; for (var i = 0; i < data.length; i++) { var ri = data[i]; data[i].checkType = this.options.checkType; for (var j = 0; j < data.length; j++) { data[j].isParent = false; for (var k = 0; k < data.length; k++) { if (data[k].pid == data[j].id) { data[j].isParent = true; break; } } } if (ri.pid != null && ri.pid != 'null' && ri.pid != -1) { for (var j = 0; j < data.length; j++) { var rj = data[j]; if (rj.id == ri.pid) { rj.childList = !rj.childList ? [] : rj.childList; rj.childList.push(ri); break; } } } if (ri.pid == undefined || ri.pid == null || ri.pid == 'null' || ri.pid == -1 || this.kvNodes['' + ri.pid] === undefined) { result.push(ri); } } return result; }, _transformTozTreeFormat: function () { var sNodes = this.bakData; var i, l; var r = []; var tmpMap = []; for (i = 0, l = sNodes.length; i < l; i++) { sNodes[i].checkType = this.options.checkType; sNodes[i].isParent = false; tmpMap[sNodes[i]["id"]] = sNodes[i]; } for (i = 0, l = sNodes.length; i < l; i++) { let node = sNodes[i], pid = sNodes[i]["pid"], id = sNodes[i]["id"], pNode = tmpMap[pid]; if (pNode && id !== pid) { pNode.isParent = true; if (!pNode["childList"]) pNode["childList"] = []; pNode["childList"].push(node); } else { r.push(node); } } return r; }, //整合成kv数据,方便查找 _generateKv: function () { var data = this.bakData; var that = this; this.kvNodes = {}; _.forEach(data, function (node, i) { that.kvNodes['' + node.id] = node; }); }, _getParentNode: function (id) { return this.kvNodes['' + this.kvNodes['' + id].pid]; }, //创建树子节点 _createDom: function (data) { var $el = this.$el; var temp = {}; // 用于存放 root 节点的row形式数据 var tempArr = []; temp.hasRoot = false; temp.nodata = false; temp.head = this.options.head; if (this.options.root != null) { temp.hasRoot = true; temp.root = this.options.root; } if (this.options.opts !== null) { temp.opts = this.options.opts; } if (this.options.root != null) { var head = this.options.head; //根节点row加入 根节点数据 tempArr.push(temp.root); for (var i = 1; i < head.length; i++) { var converter = head[i]["dataRender"]; if (converter && (typeof converter === 'string')) { var value = template.compile(converter)(temp.root); temp.root[head[i]["name"]] = value; //根节点row加入模板形式 tempArr.push(value); } else { temp.root[head[i]["name"]] = temp.root[head[i]["name"]]; //根节点row加入 tempArr.push(temp.root[head[i]["name"]]); } } ; // 将根节点row加入tempBody this.tempBody.push(temp.root); } if (data.length === 0) { temp.nodata = true; temp.noDataStyle = this.options.noDataStyle; $el.empty().append(treeRootTpl(temp)); return; } else { $el.empty().append(treeRootTpl(temp)); } this.nodeLevel = 0; for (var i = 0; i < data.length; i++) { data[i].isFirstNode = (i == 0) ? true : false; data[i].isLastNode = (i == data.length - 1) ? true : false; this._loopNodes(data[i], 0); } if ($el.find(".gridTree-root") && $el.find(".gridTree-root").size() > 0) { $el.find(".gridTree-root").after(this.nodesString.join('')); } else { $el.find("tbody").append(this.nodesString.join('')); } }, //递归树节点 _loopNodes: function (node, isSelf) { if (!isSelf) { this.nodeLevel = 0; node.level = this.nodeLevel; } node.isOpen = false; this.nodesString.push(treeTpl(this._tidyTreeData(node))); if (node.childList && node.childList.length > 0) { this.nodeLevel = node.level; this.nodeLevel++; for (var i = 0; i < node.childList.length; i++) { node.childList[i].level = this.nodeLevel; node.childList[i].isHide = (!node.isOpen) ? true : false; node.childList[i].isFirstNode = (i == 0) ? true : false; node.childList[i].isLastNode = (i == node.childList.length - 1) ? true : false; } for (var j = 0; j < node.childList.length; j++) { this._loopNodes(node.childList[j], 1); } } }, _tidyTreeData: function (node) { var tempObj = {}; var tempArr = []; tempObj.node = node; var head = this.options.head; tempArr.push(node); for (var i = 1; i < head.length; i++) { var converter = head[i]["dataRender"]; if (converter && (typeof converter === 'string')) { var value = template.compile(converter)(node); tempArr.push(value); } else { tempArr.push(node[head[i]["name"]]); } } ; tempObj.data = tempArr; this.tempBody.push(node); return tempObj; }, _preRenderData: function () { this._renderData = this._transformTozTreeFormat(); }, _nodeData2nodeObj: function (v) { var nodeObj = {}; nodeObj.checkType = this.options.checkType; nodeObj.disable = this.options.disable; v.id !== undefined ? (nodeObj.id = v.id) : undefined; v.label !== undefined ? (nodeObj.label = v.label) : undefined; v.pid !== undefined ? (nodeObj.pid = v.pid) : undefined; v.isParent !== undefined ? (nodeObj.isParent = v.isParent) : (nodeObj.isParent = false); return nodeObj; }, invoke: { //重置树节点数据 data: function (data) { this.options.data = data; this._renderTree(); }, createModel: function (createModelData) { //传入触发元素的jquery对象 var that = this, createTpl = this._model.tpl.create; var a = dialog.open({ title: '新建', btn: ['确定', '取消'], type: 1, content: createTpl.tpl($.extend({ _action: 'create' }, createModelData)), area: [createTpl.width, createTpl.height], yes: function (index) { var $form = $('#layui-layer' + index).find('form'); if (!$form.valid()) return; var obj = cui.form.objectify($($form)); obj = $.extend(true, {}, obj); that._iCall('addRowRemote', [obj, function (res) { if (res.code === 0) { dialog.close(index); } that._emit('afterCreateModel', [res]); }]); } }); }, updateModel: function (updateModelData) { var row = this._iCall('getSelectedRow'), updateTpl = this._model.tpl.update, that = this; if (!row) { dialog.msg('请指定需要修改的数据', { icon: 11 }); return; } dialog.open({ title: '编辑', btn: ['确定', '取消'], type: 1, content: updateTpl.tpl($.extend({ _action: 'update' }, updateModelData, row)), area: [updateTpl.width, updateTpl.height], yes: function (index) { var $form = $('#layui-layer' + index).find('form'); if (!$form.valid()) return; var obj = cui.form.objectify($($form)); obj = $.extend({}, { id: row.id }, obj); that._iCall('updateRowRemote', [obj, function (res) { if (res.code === 0) { dialog.close(index); } that._emit('afterUpdateModel', [res]); }]); } }) }, deleteModel: function (deleteModelData) { var row = this._iCall('getSelectedRow'), that = this; if (!row) { dialog.msg('请指定需要删除的数据', { icon: 11 }); return; } dialog.confirm('确定要删除该条记录吗?', function () { that._iCall('deleteRowRemote', [row.id, function (res) { that._emit('afterDeleteModel', [res]); }]); }); }, detailModel: function (detailModelData) { var row = this._iCall('getSelectedRow'), detailTpl = this._model.tpl.detail; dialog.open({ title: '详情', type: 1, content: detailTpl.tpl($.extend({ _action: 'detail' }, detailModelData, row)), area: [detailTpl.width, detailTpl.height], btn: ['关闭'] }); }, addRowRemote: function (obj, callback) { var that = this; if (this._model) { this._model.save(obj).then(function (res) { if (res.code === 0) { that.options.data.push(res.data); dialog.msg(res.msg, { icon: 1 }); var maxIndex = that.$el.find('.cuiGridTree tbody tr[pid="' + res.data.pid + '"]').length - 1; //没有父节点 if (res.data.pid === '-1') { res.data.level = 0; res.data.isParent = false; $(treeTpl(that._tidyTreeData(res.data))).appendTo(that.$el.find('.cuiGridTree tbody')); //有父节点没有同级子节点 } else if (maxIndex === -1) { res.data.level = (+that.$el.find('.cuiGridTree tbody tr[id="' + res.data.pid + '"]').attr('tlevel')) + 1; res.data.isParent = false; $(treeTpl(that._tidyTreeData(res.data))).insertAfter(that.$el.find('.cuiGridTree tbody tr[id="' + res.data.pid + '"]')); } else { //有同级子节点 res.data.level = (+that.$el.find('.cuiGridTree tbody tr[pid="' + res.data.pid + '"]').attr('tlevel')); res.data.isParent = false; $(treeTpl(that._tidyTreeData(res.data))).insertAfter(that.$el.find('.cuiGridTree tbody tr[pid="' + res.data.pid + '"]:eq(' + maxIndex + ')')); } // that._iCall('data', [that.options.data]); } else { dialog.msg(res.msg, { icon: 11 }) } callback && callback(res); }); } }, updateRowRemote: function (obj, callback) { var that = this; if (this._model) { this._model.update(obj).then(function (res) { if (res.code === 0) { for (var i = 0; i < that.options.data.length; i++) { if (that.options.data[i].id === res.data.id) { that.options.data[i] = res.data } } dialog.msg(res.msg, { icon: 1 }); res.data.level = +that.$el.find('.cuiGridTree tbody tr[tid="' + res.data.id + '"]').attr('tlevel'); res.data.isParent = that.$el.find('.cuiGridTree tbody tr[tid="' + res.data.id + '"]').attr('isParent') === 'true' ? true : false; that.$el.find('.cuiGridTree tbody tr[tid="' + res.data.id + '"]').replaceWith(treeTpl(that._tidyTreeData(res.data))); // that._iCall('data', [that.options.data]); } else { dialog.msg(res.msg, { icon: 11 }) } callback && callback(res); }); } }, deleteRowRemote: function (nodeid, callback) { var that = this, node = {}; node.id = nodeid; if (!this._model) return; this._model.delete(node).then(function (res) { if (res.code === 0) { var newData = that.options.data; newData.forEach(function (v, i) { if (v.id == node.id) { _.remove(newData, v); } }); !function getNeedDeleteNodes(id) { var currentId, delArr = []; newData.forEach(function (v, i) { if (v.pid == id) { delArr.push(v) } }); delArr.forEach(function (v) { _.remove(newData, v); getNeedDeleteNodes(v.id); }); }(node.id); // 删除元素 that.$el.find('.cuiGridTree tbody tr[tid="' + node.id + '"]').remove(); that.$el.find('.cuiGridTree tbody tr[pid="' + node.id + '"]').remove(); // that._iCall('data', [newData]); dialog.msg(res.msg, { icon: 1 }); } else { dialog.msg(res.msg, { icon: 11 }) } callback && callback(res); }); }, disable: function (nodeid) { var that = this; var newData = $.extend(true, [], that.options.data); console.log(newData); newData.forEach(function (v, i) { if (v.id == nodeid) { _.remove(newData, v); } }); !function getNeedNotDisableNodes(id) { var currentId, delArr = []; newData.forEach(function (v, i) { if (v.pid == id) { delArr.push(v) } }); delArr.forEach(function (v) { _.remove(newData, v); getNeedNotDisableNodes(v.id); }); }(nodeid); for (var i = 0; i < that.options.data.length; i++) { for (var j = 0; j < newData.length; j++) { if (newData[j].id === that.options.data[i].id) { continue; } else if (newData[j].id !== that.options.data[i].id && j == (newData.length - 1)) { that.options.data[i].disabled = true; } } } that._iCall('data', [that.options.data]); }, /** * [getSelectedRow description] * @DateTime 2017-07-08 * @copyright [copyright] * @license [license] * @version [version] * @return {[type]} [返回数组,依次为每列的数据,其中第一列为节点数据] */ getSelectedRow: function (modelData) { //获取单行 var $tr = this.$el.find('.cui-gridTree-active').eq(0); var row; if (this.tempBody && $tr) { _.filter(this.tempBody, function (o) { if (o.id === $tr.attr('tid')) { row = o; } }); } return row; } } }); } }, { "./gridTree.tpl": [function (require, module, exports) { module.exports = "\n\t{{each $data.data}}\n\t\t{{if $index == 0}}\n\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t{{$value.label}}\n\t\t\t\t\n\t\t\t\t\n\t\t{{else}}\n\t\t\t{{#$value}}\n\t\t{{/if}}\n\t{{/each}}\n"; }, {}], "./gridTree_root.tpl": [function (require, module, exports) { module.exports = "{{if opts !== null}}\n\t
\n\t
\n\t\t\t
\n\t\t\t\t{{each opts}}\n\t\t\t\t \n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t{{$value.label}}\n\t\t\t\t \n\t\t\t\t{{/each}}\n\t\t\t
\n\t\t
\n\t
\n{{/if}}\n\n\t\n\t\t\n\t\t\t{{each $data.head}}\n\t\t\t\t\n\t\t\t{{/each}}\n\t\t\n\t\n\t\n\t\t{{if $data.hasRoot && !$data.nodata}}\n\t\t\n\t\t\t{{each $data.head}}\n\t\t\t\t{{if $index == 0}}\n\t\t\t\t\t\n\t\t\t\t{{else}}\n\t\t\t\t\t\n\t\t\t\t{{/if}}\n\t\t\t{{/each}}\n\t\t\n\t\t{{/if}}\n\t\t{{if $data.nodata}}\n\t\t\t\n\t\t\t\t\n\t\t\t\n\t\t{{/if}}\n\t\n
{{#$value.label}}
\n\t\t\t\t\t\t\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t{{$data.root.label}}\n\t\t\t\t\t\t\n\t\t\t\t\t{{#$data.root[$value.name]}}
对不起,暂无数据
"; }, {}] }]; var cuiJQueryCookieImpl = [function(require, module, exports) { /*! jQuery Cookie Plugin v1.4.1 * $.cooke('name'); $.cookie('name', 'value'); $.cookie('name', 'value', {expires:2, path:'/', domain:'', secure:true|false}); $.removeCookie(key, {...}); */ ; (function(a) { if(typeof define === "function" && define.amd) { define(["jquery"], a) } else { if(typeof exports === "object") { a(jQuery) } else { a(jQuery) } } }(function(f) { var a = /\+/g; function d(i) { return b.raw ? i : encodeURIComponent(i) } function g(i) { return b.raw ? i : decodeURIComponent(i) } function h(i) { return d(b.json ? JSON.stringify(i) : String(i)) } function c(i) { if(i.indexOf('"') === 0) { i = i.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, "\\") } try { i = decodeURIComponent(i.replace(a, " ")); return b.json ? JSON.parse(i) : i } catch(j) {} } function e(j, i) { var k = b.raw ? j : c(j); return f.isFunction(i) ? i(k) : k } var b = f.cookie = function(q, p, v) { if(p !== undefined && !f.isFunction(p)) { v = f.extend({}, b.defaults, v); if(typeof v.expires === "number") { var r = v.expires, u = v.expires = new Date(); u.setTime(+u + r * 86400000) } return(document.cookie = [d(q), "=", h(p), v.expires ? "; expires=" + v.expires.toUTCString() : "", v.path ? "; path=" + v.path : "", v.domain ? "; domain=" + v.domain : "", v.secure ? "; secure" : ""].join("")) } var w = q ? undefined : {}; var s = document.cookie ? document.cookie.split("; ") : []; for(var o = 0, m = s.length; o < m; o++) { var n = s[o].split("="); var j = g(n.shift()); var k = n.join("="); if(q && q === j) { w = e(k, p); break } if(!q && (k = e(k)) !== undefined) { w[j] = k } } return w }; b.defaults = {}; f.removeCookie = function(j, i) { if(f.cookie(j) === undefined) { return false } f.cookie(j, "", f.extend({}, i, { expires: -1 })); return !f.cookie(j) } })); }, {}]; var cuiJQueryValidateImpl = [function(require, module, exports) { /* * Metadata - jQuery plugin for parsing metadata from elements * * Copyright (c) 2006 John Resig, Yehuda Katz, J�örn Zaefferer, Paul McLanahan * * Dual licensed under the MIT and GPL licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html * * Revision: $Id: jquery.metadata.js 4187 2007-12-16 17:15:27Z joern.zaefferer $ * */ /** * Sets the type of metadata to use. Metadata is encoded in JSON, and each property * in the JSON will become a property of the element itself. * * There are three supported types of metadata storage: * * attr: Inside an attribute. The name parameter indicates *which* attribute. * * class: Inside the class attribute, wrapped in curly braces: { } * * elem: Inside a child element (e.g. a script tag). The * name parameter indicates *which* element. * * The metadata for an element is loaded the first time the element is accessed via jQuery. * * As a result, you can define the metadata type, use $(expr) to load the metadata into the elements * matched by expr, then redefine the metadata type and run another $(expr) for other elements. * * @name $.metadata.setType * * @example

This is a p

* @before $.metadata.setType("class") * @after $("#one").metadata().item_id == 1; $("#one").metadata().item_label == "Label" * @desc Reads metadata from the class attribute * * @example

This is a p

* @before $.metadata.setType("attr", "data") * @after $("#one").metadata().item_id == 1; $("#one").metadata().item_label == "Label" * @desc Reads metadata from a "data" attribute * * @example

This is a p

* @before $.metadata.setType("elem", "script") * @after $("#one").metadata().item_id == 1; $("#one").metadata().item_label == "Label" * @desc Reads metadata from a nested script element * * @param String type The encoding type * @param String name The name of the attribute to be used to get metadata (optional) * @cat Plugins/Metadata * @descr Sets the type of encoding to be used when loading metadata for the first time * @type undefined * @see metadata() */ (function($) { $.extend({ metadata: { defaults: { type: 'class', name: 'validate', cre: /({.*})/, single: 'validate' }, setType: function(type, name) { this.defaults.type = type; this.defaults.name = name; }, get: function(elem, opts) { var settings = $.extend({}, this.defaults, opts); // check for empty string in single property if(!settings.single.length) settings.single = 'metadata'; var data = $.data(elem, settings.single); // returned cached data if it already exists if(data) return data; data = "{}"; if(settings.type == "class") { var m = settings.cre.exec(elem.className); if(m) data = m[1]; } else if(settings.type == "elem") { if(!elem.getElementsByTagName) return undefined; var e = elem.getElementsByTagName(settings.name); if(e.length) data = $.trim(e[0].innerHTML); } else if(elem.getAttribute != undefined) { var attr = elem.getAttribute(settings.name); if(attr) data = attr; } if(data.indexOf('{') < 0) data = "{" + data + "}"; data = eval("(" + data + ")"); $.data(elem, settings.single, data); return data; } } }); /** * Returns the metadata object for the first member of the jQuery object. * * @name metadata * @descr Returns element's metadata object * @param Object opts An object contianing settings to override the defaults * @type jQuery * @cat Plugins/Metadata */ $.fn.metadata = function(opts) { return $.metadata.get(this[0], opts); }; })(jQuery); //使用 metadate元素验证 validate 属性 $.metadata.setType("attr", "validate"); /*! * jQuery Validation Plugin v1.13.1 * * http://jqueryvalidation.org/ * * Copyright (c) 2014 Jörn Zaefferer * Released under the MIT license */ (function(factory) { if(typeof define === "function" && define.amd) { define(["jquery"], factory); } else { factory(jQuery); } }(function($) { $.extend($.fn, { // http://jqueryvalidation.org/validate/ validate: function(options) { // if nothing is selected, return nothing; can't chain anyway if(!this.length) { if(options && options.debug && window.console) { console.warn("Nothing selected, can't validate, returning nothing."); } return; } // check if a validator for this form was already created var validator = $.data(this[0], "validator"); if(validator) { return validator; } // Add novalidate tag if HTML5. this.attr("novalidate", "novalidate"); // add by clu on 2020-7-17 16:14:51 将container默认改为this options = Object.assign(options || {}, {container: this}); validator = new $.validator(options, this[0]); $.data(this[0], "validator", validator); if(validator.settings.onsubmit) { this.validateDelegate(":submit", "click", function(event) { if(validator.settings.submitHandler) { validator.submitButton = event.target; } // allow suppressing validation by adding a cancel class to the submit button if($(event.target).hasClass("cancel")) { validator.cancelSubmit = true; } // allow suppressing validation by adding the html5 formnovalidate attribute to the submit button if($(event.target).attr("formnovalidate") !== undefined) { validator.cancelSubmit = true; } }); // validate the form on submit this.submit(function(event) { if(validator.settings.debug) { // prevent form submit to be able to see console output event.preventDefault(); } function handle() { var hidden, result; if(validator.settings.submitHandler) { if(validator.submitButton) { // insert a hidden input as a replacement for the missing submit button hidden = $("").attr("name", validator.submitButton.name).val($(validator.submitButton).val()).appendTo(validator.currentForm); } result = validator.settings.submitHandler.call(validator, validator.currentForm, event); if(validator.submitButton) { // and clean up afterwards; thanks to no-block-scope, hidden can be referenced hidden.remove(); } if(result !== undefined) { return result; } return false; } return true; } // prevent submit for invalid forms or custom submit handlers if(validator.cancelSubmit) { validator.cancelSubmit = false; return handle(); } if(validator.form()) { if(validator.pendingRequest) { validator.formSubmitted = true; return false; } return handle(); } else { validator.focusInvalid(); return false; } }); } return validator; }, // http://jqueryvalidation.org/valid/ valid: function() { var valid, validator; if($(this[0]).is("form")) { valid = this.validate().form(); } else { valid = true; validator = $(this[0].form).validate(); this.each(function() { valid = validator.element(this) && valid; }); } return valid; }, // attributes: space separated list of attributes to retrieve and remove removeAttrs: function(attributes) { var result = {}, $element = this; $.each(attributes.split(/\s/), function(index, value) { result[value] = $element.attr(value); $element.removeAttr(value); }); return result; }, // http://jqueryvalidation.org/rules/ rules: function(command, argument) { var element = this[0], settings, staticRules, existingRules, data, param, filtered; settings = $.data(element.form, "validator").settings; if(command) { staticRules = settings.rules; existingRules = $.validator.staticRules(element); switch(command) { case "add": $.extend(existingRules, $.validator.normalizeRule(argument)); // remove messages from rules, but allow them to be set separately delete existingRules.messages; staticRules[element.name] = existingRules; if(argument.messages) { settings.messages[element.name] = $.extend(settings.messages[element.name], argument.messages); } break; case "remove": if(!argument) { delete staticRules[element.name]; return existingRules; } filtered = {}; $.each(argument.split(/\s/), function(index, method) { filtered[method] = existingRules[method]; delete existingRules[method]; if(method === "required") { $(element).removeAttr("aria-required"); } }); return filtered; } } data = $.validator.normalizeRules($.extend({}, $.validator.metadataRules(element), $.validator.classRules(element), $.validator.attributeRules(element), $.validator.dataRules(element), $.validator.staticRules(element)), element); // make sure required is at front if(data.required) { param = data.required; delete data.required; data = $.extend({ required: param }, data); $(element).attr("aria-required", "true"); } // make sure remote is at back if(data.remote) { param = data.remote; delete data.remote; data = $.extend(data, { remote: param }); } return data; } }); // Custom selectors $.extend($.expr[":"], { // http://jqueryvalidation.org/blank-selector/ blank: function(a) { return !$.trim("" + $(a).val()); }, // http://jqueryvalidation.org/filled-selector/ filled: function(a) { return !!$.trim("" + $(a).val()); }, // http://jqueryvalidation.org/unchecked-selector/ unchecked: function(a) { return !$(a).prop("checked"); } }); // constructor for validator $.validator = function(options, form) { this.settings = $.extend(true, {}, $.validator.defaults, options); this.currentForm = form; this.init(); }; //http://jqueryvalidation.org/jQuery.validator.format/ $.validator.format = function(source, params) { if(arguments.length === 1) { return function() { var args = $.makeArray(arguments); args.unshift(source); return $.validator.format.apply(this, args); }; } if(arguments.length > 2 && params.constructor !== Array) { params = $.makeArray(arguments).slice(1); } if(params.constructor !== Array) { params = [params]; } $.each(params, function(i, n) { source = source.replace(new RegExp("\\{" + i + "\\}", "g"), function() { return n; }); }); return source; }; $.extend($.validator, { defaults: { formOnlyName: true, messages: {}, groups: {}, rules: {}, errorClass: "error", validClass: "valid", errorElement: "label", focusCleanup: false, focusInvalid: true, errorContainer: $([]), errorLabelContainer: $([]), onsubmit: true, ignore: ":hidden", ignoreTitle: false, checkHidden: false, onfocusin: function(element) { this.lastActive = element; // Hide error label and remove error class on focus if enabled if(this.settings.focusCleanup) { if(this.settings.unhighlight) { this.settings.unhighlight.call(this, element, this.settings.errorClass, this.settings.validClass); } this.hideThese(this.errorsFor(element)); } }, onfocusout: function(element) { if(!this.checkable(element) && (element.name in this.submitted || !this.optional(element))) { this.element(element); } }, onchange: function(element) { this.element(element); }, onkeyup: function(element, event) { if(event.which === 9 && this.elementValue(element) === "") { return; } else if(element.name in this.submitted || element === this.lastElement) { this.element(element); } }, onclick: function(element) { // click on selects, radiobuttons and checkboxes if(element.name in this.submitted) { this.element(element); // or option elements, check parent select in that case } else if(element.parentNode.name in this.submitted) { this.element(element.parentNode); } }, highlight: function(element, errorClass, validClass) { if(element.type === "radio") { this.findByName(element.name).addClass(errorClass).removeClass(validClass); } else { $(element).addClass(errorClass).removeClass(validClass); } }, unhighlight: function(element, errorClass, validClass) { if(element.type === "radio") { this.findByName(element.name).removeClass(errorClass).addClass(validClass); } else { $(element).removeClass(errorClass).addClass(validClass); } } }, // http://jqueryvalidation.org/jQuery.validator.setDefaults/ setDefaults: function(settings) { $.extend($.validator.defaults, settings); }, messages: { required: "请输入值!", remote: "请检查该值的正确性!", email: "请输入正确格式的Email地址!", url: "请输入正确格式的URL地址!", date: "Please enter a valid date.", dateISO: "Please enter a valid date ( ISO ).", number: "请输入数字!", digits: "请输入整型数字!", creditcard: "Please enter a valid credit card number.", equalTo: "两次输入的值不一致!", isIP: "Please enter a valid ip.", isMAC: "Please enter a valid mac.", isIdCard: "Please enter a valid idcard number.", isMobile: "Please enter a valid monile number.", isSpecialStr: "Please enter a valid string.", isQQ: "请输入一个正确的QQ号", maxlength: $.validator.format("输入的字符长度超出了 {0} 位!"), minlength: $.validator.format("请输入至少 {0} 位长度的字符!"), rangelength: $.validator.format("请输入 {0} - {1} 位长度的字符!"), range: $.validator.format("请输入 {0} - {1} 范围之间的值!"), max: $.validator.format("请输入不大于 {0} 的值!"), min: $.validator.format("请输入不小于 {0} 的值!"), invalidChar: $.validator.format("信息中含有非法字符 {0}"), compareTime: $.validator.format("日期比较不满足比较运算符{1}"), date: $.validator.format("日期格式不正确!格式为:{0}"), compareTo: $.validator.format("不满足比较运算符{1}"), regExp: "输入的信息不匹配定义的规则!", CNRangeLength: $.validator.format("请输入{0}-{1}个字符或{0}-{3}个汉字!"), postalcode: "请输入正确的邮政编码!", IP: "请输入正确的IP地址!", MAC: "请输入正确的MAC地址(以 - 分隔)!", telephone: "请输入正确的固定电话号码!格式:区号-号码", mobile: "请输入正确的手机号码!", dateCN: "请输入正确格式的日期(yyyy-MM-dd)!", chinese: "请输入中文字符!", validChar: "输入信息中含有非法字符 ` ' \" ~ ^ ", IDCard: "请输入正确的身份证号码!", accept: "输入的信息不匹配定义的规则!", lte: '输入的值必须小于或等于{}', gte: '输入的值必须大于或等于{}' }, autoCreateRanges: false, prototype: { init: function() { this.labelContainer = $(this.settings.errorLabelContainer); this.errorContext = this.labelContainer.length && this.labelContainer || $(this.currentForm); this.containers = $(this.settings.errorContainer).add(this.settings.errorLabelContainer); this.submitted = {}; this.valueCache = {}; this.pendingRequest = 0; this.pending = {}; this.invalid = {}; this.reset(); var groups = (this.groups = {}), rules; $.each(this.settings.groups, function(key, value) { if(typeof value === "string") { value = value.split(/\s/); } $.each(value, function(index, name) { groups[name] = key; }); }); rules = this.settings.rules; $.each(rules, function(key, value) { rules[key] = $.validator.normalizeRule(value); }); function delegate(event) { var validator = $.data(this[0].form, "validator"), eventType = "on" + event.type.replace(/^validate/, ""), settings = validator.settings; if(settings[eventType]) { if((this.next('.cui-select').size() > 0 && this.is(settings.ignore)) || (!this.is(settings.ignore))) { settings[eventType].call(validator, this[0], event); } } } $(this.currentForm).validateDelegate(":text, [type='password'], [type='file'], select, textarea, " + "[type='number'], [type='search'] ,[type='tel'], [type='url'], " + "[type='email'], [type='datetime'], [type='date'], [type='month'], " + "[type='week'], [type='time'], [type='datetime-local'], " + "[type='range'], [type='color'], [type='radio'], [type='checkbox']", "focusin focusout keyup change", delegate) // Support: Chrome, oldIE // "select" is provided as event.target when clicking a option .validateDelegate("select, option, [type='radio'], [type='checkbox']", "click", delegate); // 兼容cui的select $(this.currentForm).find('select').change(function(e) { delegate.call($(this), e); }); if(this.settings.invalidHandler) { $(this.currentForm).bind("invalid-form.validate", this.settings.invalidHandler); } // Add aria-required to any Static/Data/Class required fields before first validation // Screen readers require this attribute to be present before the initial submission http://www.w3.org/TR/WCAG-TECHS/ARIA2.html $(this.currentForm).find("[required], [data-rule-required], .required").attr("aria-required", "true"); }, // http://jqueryvalidation.org/Validator.form/ form: function() { this.checkForm(); $.extend(this.submitted, this.errorMap); this.invalid = $.extend({}, this.errorMap); if(!this.valid()) { $(this.currentForm).triggerHandler("invalid-form", [this]); } this.showErrors(); // 表单验证 return this.valid(); }, checkForm: function() { this.prepareForm(); for(var i = 0, elements = (this.currentElements = this.elements()); elements[i]; i++) { this.check(elements[i]); } return this.valid(); }, // http://jqueryvalidation.org/Validator.element/ element: function(element, fromSelf) { // edit by clu on 2020-7-22 11:08:54 如果是compareTo规则,则需要触发一下另一个值的检查,因为修改完一个后,另一个的值应该变成合法 var rules = $(element).rules(); if (!fromSelf) { var compareParams = rules['compareTo']; if (rules && Array.isArray(compareParams)) { this.element(compareParams[0], true); } } var cleanElement = this.clean(element), checkElement = this.validationTargetFor(cleanElement), result = true; this.lastElement = checkElement; if(checkElement === undefined) { delete this.invalid[cleanElement.name]; } else { this.prepareElement(checkElement); this.currentElements = $(checkElement); result = this.check(checkElement) !== false; if(result) { delete this.invalid[checkElement.name]; } else { this.invalid[checkElement.name] = true; } } // Add aria-invalid status for screen readers $(element).attr("aria-invalid", !result); if(!this.numberOfInvalids()) { // Hide error containers on last error this.toHide = this.toHide.add(this.containers); } this.showErrors(); // 单个元素验证 return result; }, // http://jqueryvalidation.org/Validator.showErrors/ showErrors: function(errors) { if(errors) { // add items to error list and map $.extend(this.errorMap, errors); this.errorList = []; for(var name in errors) { this.errorList.push({ message: errors[name], element: this.findByName(name)[0] }); } // remove items from success list this.successList = $.grep(this.successList, function(element) { return !(element.name in errors); }); } if(this.settings.showErrors) { this.settings.showErrors.call(this, this.errorMap, this.errorList, this.currentElements); } else { this.defaultShowErrors(); } }, // http://jqueryvalidation.org/Validator.resetForm/ resetForm: function() { if($.fn.resetForm) { $(this.currentForm).resetForm(); } this.submitted = {}; this.lastElement = null; this.prepareForm(); this.hideErrors(); this.elements().removeClass(this.settings.errorClass).removeData("previousValue").removeAttr("aria-invalid"); }, numberOfInvalids: function() { return this.objectLength(this.invalid); }, objectLength: function(obj) { /* jshint unused: false */ var count = 0, i; for(i in obj) { count++; } return count; }, hideErrors: function() { this.hideThese(this.toHide); }, hideThese: function(errors) { errors.not(this.containers).text(""); this.addWrapper(errors).hide(); }, valid: function() { return this.size() === 0; }, size: function() { return this.errorList.length; }, focusInvalid: function() { if(this.settings.focusInvalid) { try { $(this.findLastActive() || this.errorList.length && this.errorList[0].element || []).filter(":visible").focus() // manually trigger focusin event; without it, focusin handler isn't called, findLastActive won't have anything to find .trigger("focusin"); } catch(e) { // ignore IE throwing errors when focusing hidden elements } } }, findLastActive: function() { var lastActive = this.lastActive; return lastActive && $.grep(this.errorList, function(n) { return n.element.name === lastActive.name; }).length === 1 && lastActive; }, elements: function() { var validator = this, rulesCache = {}, $tempElemets, settings = this.settings; // select all valid inputs inside the form (no submit or reset buttons) $tempElemets = $(this.currentForm).find("input, select, textarea").not(":submit, :reset, :image, [disabled]").filter(function() { if(!this.name && validator.settings.debug && window.console) { console.error("%o has no name assigned", this); } // select only the first element for each name, and only those with rules specified if((this.name in rulesCache && settings.formOnlyName) || !validator.objectLength($(this).rules())) { return false; } rulesCache[this.name] = true; return true; }); return $tempElemets; }, clean: function(selector) { return $(selector)[0]; }, errors: function() { var errorClass = this.settings.errorClass.split(" ").join("."); return $(this.settings.errorElement + "." + errorClass, this.errorContext); }, reset: function() { this.successList = []; this.errorList = []; this.errorMap = {}; this.toShow = $([]); this.toHide = $([]); this.currentElements = $([]); }, prepareForm: function() { this.reset(); this.toHide = this.errors().add(this.containers); }, prepareElement: function(element) { this.reset(); this.toHide = this.errorsFor(element); }, elementValue: function(element) { var val, $element = $(element), type = element.type; if(type === "radio" || type === "checkbox") { return $("input[name='" + element.name + "']:checked").val(); } else if(type === "number" && typeof element.validity !== "undefined") { return element.validity.badInput ? false : $element.val(); } val = $element.val(); if(typeof val === "string") { return val.replace(/\r/g, ""); } return val; }, check: function(element) { element = this.validationTargetFor(this.clean(element)); if(!element) return; var rules = $(element).rules(), rulesCount = $.map(rules, function(n, i) { return i; }).length, dependencyMismatch = false, val = this.elementValue(element), result, methodName, rule; for(methodName in rules) { rule = { method: methodName, parameters: rules[methodName] }; try { if(methodName === "messages") return; var method = $.validator.methods[methodName]; if (typeof method !== 'function') { console.error("无效的规则:" + methodName); } result = method.call(this, val, element, rule.parameters); // if a method indicates that the field is optional and therefore valid, // don't mark it as valid when there are no other rules if(result === "dependency-mismatch" && rulesCount === 1) { dependencyMismatch = true; continue; } dependencyMismatch = false; if(result === "pending") { this.toHide = this.toHide.not(this.errorsFor(element)); return; } if(!result) { this.formatAndAdd(element, rule); return false; } } catch(e) { if(this.settings.debug && window.console) { console.log("Exception occurred when checking element " + element.id + ", check the '" + rule.method + "' method.", e); } throw e; } } if(dependencyMismatch) { return; } if(this.objectLength(rules)) { this.successList.push(element); } return true; }, // return the custom message for the given element and validation method // specified in the element's HTML5 data attribute // return the generic message if present and no method specific message is present customDataMessage: function(element, method) { return $(element).data("msg" + method.charAt(0).toUpperCase() + method.substring(1).toLowerCase()) || $(element).data("msg"); }, // return the custom message for the given element name and validation method customMessage: function(name, method) { var m = this.settings.messages[name]; return m && (m.constructor === String ? m : m[method]); }, // return the first defined argument, allowing empty strings findDefined: function() { for(var i = 0; i < arguments.length; i++) { if(arguments[i] !== undefined) { return arguments[i]; } } return undefined; }, getAttrMessage: function(element, method) { var messages = $(element).rules().messages; return(messages && messages[method]) ? messages[method] : undefined; }, defaultMessage: function(element, method) { return this.findDefined(this.getAttrMessage(element, method), this.customMessage(element.name, method), this.customDataMessage(element, method), // title is never undefined, so handle empty string as undefined !this.settings.ignoreTitle && element.title || undefined, $.validator.messages[method], "Warning: No message defined for " + element.name + ""); }, formatAndAdd: function(element, rule) { var message = this.defaultMessage(element, rule.method), theregex = /\$?\{(\d+)\}/g; if(typeof message === "function") { message = message.call(this, rule.parameters, element); } else if(theregex.test(message)) { message = $.validator.format(message.replace(theregex, "{$1}"), rule.parameters); } this.errorList.push({ message: message, element: element, method: rule.method }); this.errorMap[element.name] = message; this.submitted[element.name] = message; }, addWrapper: function(toToggle) { if(this.settings.wrapper) { toToggle = toToggle.add(toToggle.parent(this.settings.wrapper)); } return toToggle; }, defaultShowErrors: function() { var i, elements, error; for(i = 0; this.errorList[i]; i++) { error = this.errorList[i]; if(this.settings.highlight) { this.settings.highlight.call(this, error.element, this.settings.errorClass, this.settings.validClass); } this.showLabel(error.element, error.message); } if(this.errorList.length) { this.toShow = this.toShow.add(this.containers); } if(this.settings.success) { for(i = 0; this.successList[i]; i++) { this.showLabel(this.successList[i]); } } if(this.settings.unhighlight) { for(i = 0, elements = this.validElements(); elements[i]; i++) { this.settings.unhighlight.call(this, elements[i], this.settings.errorClass, this.settings.validClass); } } this.toHide = this.toHide.not(this.toShow); this.hideErrors(); this.addWrapper(this.toShow).show(); }, validElements: function() { return this.currentElements.not(this.invalidElements()); }, invalidElements: function() { return $(this.errorList).map(function() { return this.element; }); }, showLabel: function(element, message) { var place, group, errorID, error = this.errorsFor(element), elementID = this.idOrName(element), describedBy = $(element).attr("aria-describedby"); if(error.length) { // refresh error/success class error.removeClass(this.settings.validClass).addClass(this.settings.errorClass); // replace message on existing label error.html(message); } else { // create error element error = $("<" + this.settings.errorElement + ">").attr("id", elementID + "-error").addClass(this.settings.errorClass).html(message || ""); // Maintain reference to the element to be placed into the DOM place = error; if(this.settings.wrapper) { // make sure the element is visible, even in IE // actually showing the wrapped element is handled elsewhere place = error.hide().show().wrap("<" + this.settings.wrapper + "/>").parent(); } if(this.labelContainer.length) { this.labelContainer.append(place); } else if(this.settings.errorPlacement) { this.settings.errorPlacement(place, $(element)); } else { place.insertAfter(element); } // Link error back to the element if(error.is("label")) { // If the error is a label, then associate using 'for' error.attr("for", elementID); } else if(error.parents("label[for='" + elementID + "']").length === 0) { // If the element is not a child of an associated label, then it's necessary // to explicitly apply aria-describedby errorID = error.attr("id").replace(/(:|\.|\[|\])/g, "\\$1"); // Respect existing non-error aria-describedby if(!describedBy) { describedBy = errorID; } else if(!describedBy.match(new RegExp("\\b" + errorID + "\\b"))) { // Add to end of list if not already present describedBy += " " + errorID; } $(element).attr("aria-describedby", describedBy); // If this element is grouped, then assign to all elements in the same group group = this.groups[element.name]; if(group) { $.each(this.groups, function(name, testgroup) { if(testgroup === group) { $("[name='" + name + "']", this.currentForm).attr("aria-describedby", error.attr("id")); } }); } } } if(!message && this.settings.success) { error.text(""); if(typeof this.settings.success === "string") { error.addClass(this.settings.success); } else { this.settings.success(error, element); } } this.toShow = this.toShow.add(error); }, errorsFor: function(element) { var name = this.idOrName(element), describer = $(element).attr("aria-describedby"), selector = "label[for='" + name + "'], label[for='" + name + "'] *"; // aria-describedby should directly reference the error element if(describer) { selector = selector + ", #" + describer.replace(/\s+/g, ", #"); } return this.errors().filter(selector); }, idOrName: function(element) { return this.groups[element.name] || (this.checkable(element) ? element.name : element.id || element.name); }, validationTargetFor: function(element) { // If radio/checkbox, validate first element in group instead var _self = this; if(this.checkable(element)) { element = this.findByName(element.name); } return $(element).filter(function() { if($(this).is('select') && $(this).next('.cui-select').size() > 0) { return true; } else if(_self.settings.ignore && $(this).is(':hidden')) { return false; } return true })[0]; // Always apply ignore filter // return $( element )( this.settings.ignore )[ 0 ]; }, checkable: function(element) { return(/radio|checkbox/i).test(element.type); }, findByName: function(name) { return $(this.currentForm).find("[name='" + name + "']"); }, getLength: function(value, element) { switch(element.nodeName.toLowerCase()) { case "select": return $("option:selected", element).length; case "input": if(this.checkable(element)) { return this.findByName(element.name).filter(":checked").length; } } return value.length; }, depend: function(param, element) { return this.dependTypes[typeof param] ? this.dependTypes[typeof param](param, element) : true; }, dependTypes: { "boolean": function(param) { return param; }, "string": function(param, element) { return !!$(param, element.form).length; }, "function": function(param, element) { return param(element); } }, optional: function(element) { var val = this.elementValue(element); return !$.validator.methods.required.call(this, val, element) && "dependency-mismatch"; }, startRequest: function(element) { if(!this.pending[element.name]) { this.pendingRequest++; this.pending[element.name] = true; } }, stopRequest: function(element, valid) { this.pendingRequest--; // sometimes synchronization fails, make sure pendingRequest is never < 0 if(this.pendingRequest < 0) { this.pendingRequest = 0; } delete this.pending[element.name]; if(valid && this.pendingRequest === 0 && this.formSubmitted && this.form()) { $(this.currentForm).submit(); this.formSubmitted = false; } else if(!valid && this.pendingRequest === 0 && this.formSubmitted) { $(this.currentForm).triggerHandler("invalid-form", [this]); this.formSubmitted = false; } }, previousValue: function(element) { return $.data(element, "previousValue") || $.data(element, "previousValue", { old: null, valid: true, message: this.defaultMessage(element, "remote") }); } }, classRuleSettings: { required: { required: true }, email: { email: true }, url: { url: true }, date: { date: true }, dateISO: { dateISO: true }, number: { number: true }, digits: { digits: true }, creditcard: { creditcard: true } }, addClassRules: function(className, rules) { if(className.constructor === String) { this.classRuleSettings[className] = rules; } else { $.extend(this.classRuleSettings, className); } }, classRules: function(element) { var rules = {}, classes = $(element).attr("class"); if(classes) { $.each(classes.split(" "), function() { if(this in $.validator.classRuleSettings) { $.extend(rules, $.validator.classRuleSettings[this]); } }); } return rules; }, attributeRules: function(element) { var rules = {}, $element = $(element), type = element.getAttribute("type"), method, value; for(method in $.validator.methods) { // support for in both html5 and older browsers if(method === "required") { value = element.getAttribute(method); // Some browsers return an empty string for the required attribute // and non-HTML5 browsers might have required="" markup if(value === "") { value = true; } // force non-HTML5 browsers to return bool value = !!value; } else { value = $element.attr(method); } // convert the value to a number for number inputs, and for text for backwards compability // allows type="date" and others to be compared as strings if(/min|max/.test(method) && (type === null || /number|range|text/.test(type))) { value = Number(value); } if(value || value === 0) { rules[method] = value; } else if(type === method && type !== "range") { // exception: the jquery validate 'range' method // does not test for the html5 'range' type rules[method] = true; } } // maxlength may be returned as -1, 2147483647 ( IE ) and 524288 ( safari ) for text inputs if(rules.maxlength && /-1|2147483647|524288/.test(rules.maxlength)) { delete rules.maxlength; } return rules; }, dataRules: function(element) { var method, value, rules = {}, $element = $(element); for(method in $.validator.methods) { value = $element.data("rule" + method.charAt(0).toUpperCase() + method.substring(1).toLowerCase()); if(value !== undefined) { rules[method] = value; } } return rules; }, metadataRules: function(element) { if(!$.metadata) return {}; var meta = $.data(element.form, 'validator').settings.meta; return meta ? $(element).metadata()[meta] : $(element).metadata(); }, staticRules: function(element) { var rules = {}, validator = $.data(element.form, "validator"); if(validator.settings.rules) { rules = $.validator.normalizeRule(validator.settings.rules[element.name]) || {}; } return rules; }, normalizeRules: function(rules, element) { // handle dependency check $.each(rules, function(prop, val) { // ignore rule when param is explicitly false, eg. required:false if(val === false) { delete rules[prop]; return; } if(val.param || val.depends) { var keepRule = true; switch(typeof val.depends) { case "string": keepRule = !!$(val.depends, element.form).length; break; case "function": keepRule = val.depends.call(element, element); break; } if(keepRule) { rules[prop] = val.param !== undefined ? val.param : true; } else { delete rules[prop]; } } }); // evaluate parameters $.each(rules, function(rule, parameter) { rules[rule] = $.isFunction(parameter) ? parameter(element) : parameter; }); // clean number parameters $.each(["minlength", "maxlength"], function() { if(rules[this]) { rules[this] = Number(rules[this]); } }); $.each(["rangelength", "range"], function() { var parts; if(rules[this]) { if($.isArray(rules[this])) { rules[this] = [Number(rules[this][0]), Number(rules[this][1])]; } else if(typeof rules[this] === "string") { parts = rules[this].replace(/[\[\]]/g, "").split(/[\s,]+/); rules[this] = [Number(parts[0]), Number(parts[1])]; } } }); if($.validator.autoCreateRanges) { // auto-create ranges if(rules.min != null && rules.max != null) { rules.range = [rules.min, rules.max]; delete rules.min; delete rules.max; } if(rules.minlength != null && rules.maxlength != null) { rules.rangelength = [rules.minlength, rules.maxlength]; delete rules.minlength; delete rules.maxlength; } } return rules; }, // Converts a simple string to a {string: true} rule, e.g., "required" to {required:true} normalizeRule: function(data) { if(typeof data === "string") { var transformed = {}; $.each(data.split(/\s/), function() { transformed[this] = true; }); data = transformed; } return data; }, // http://jqueryvalidation.org/jQuery.validator.addMethod/ addMethod: function(name, method, message) { $.validator.methods[name] = method; $.validator.messages[name] = message !== undefined ? message : $.validator.messages[name]; if(method.length < 3) { $.validator.addClassRules(name, $.validator.normalizeRule(name)); } }, methods: { // http://jqueryvalidation.org/required-method/ required: function(value, element, param) { // check if dependency is met if(!this.depend(param, element)) { return "dependency-mismatch"; } if(element.nodeName.toLowerCase() === "select") { // could be an array for select-multiple or a string, both are fine this way var val = $(element).val(); return val && val.length > 0; } if(this.checkable(element)) { return this.getLength(value, element) > 0; } return $.trim(value).length > 0; }, // http://jqueryvalidation.org/email-method/ email: function(value, element) { // From http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html#e-mail-state-%28type=email%29 // Retrieved 2014-01-14 // If you have a problem with this implementation, report a bug against the above spec // Or use custom methods to implement your own email validation return this.optional(element) || /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test(value); }, // http://jqueryvalidation.org/url-method/ url: function(value, element) { // contributed by Scott Gonzalez: http://projects.scottsplayground.com/iri/ return this.optional(element) || /^(https?|s?ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(value); }, // http://jqueryvalidation.org/date-method/ date: function(value, element) { return this.optional(element) || !/Invalid|NaN/.test(new Date(value).toString()); }, // http://jqueryvalidation.org/dateISO-method/ dateISO: function(value, element) { return this.optional(element) || /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$/.test(value); }, // http://jqueryvalidation.org/number-method/ number: function(value, element) { return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/.test(value); }, // http://jqueryvalidation.org/digits-method/ digits: function(value, element) { return this.optional(element) || /^\d+$/.test(value); }, // http://jqueryvalidation.org/creditcard-method/ // based on http://en.wikipedia.org/wiki/Luhn/ creditcard: function(value, element) { if(this.optional(element)) { return "dependency-mismatch"; } // accept only spaces, digits and dashes if(/[^0-9 \-]+/.test(value)) { return false; } var nCheck = 0, nDigit = 0, bEven = false, n, cDigit; value = value.replace(/\D/g, ""); // Basing min and max length on // http://developer.ean.com/general_info/Valid_Credit_Card_Types if(value.length < 13 || value.length > 19) { return false; } for(n = value.length - 1; n >= 0; n--) { cDigit = value.charAt(n); nDigit = parseInt(cDigit, 10); if(bEven) { if((nDigit *= 2) > 9) { nDigit -= 9; } } nCheck += nDigit; bEven = !bEven; } return(nCheck % 10) === 0; }, // http://jqueryvalidation.org/minlength-method/ minlength: function(value, element, param) { value = value.replace(/[^\x00-\xff]/g, 'xxx'); var length = $.isArray(value) ? value.length : this.getLength(value, element); return this.optional(element) || length >= param; }, // http://jqueryvalidation.org/maxlength-method/ maxlength: function(value, element, param) { value = value.replace(/[^\x00-\xff]/g, 'xxx'); var length = $.isArray(value) ? value.length : this.getLength(value, element); return this.optional(element) || length <= param; }, // http://jqueryvalidation.org/rangelength-method/ rangelength: function(value, element, param) { value = value.replace(/[^\x00-\xff]/g, 'xxx'); var length = $.isArray(value) ? value.length : this.getLength(value, element); return this.optional(element) || (length >= param[0] && length <= param[1]); }, // http://jqueryvalidation.org/min-method/ min: function(value, element, param) { return this.optional(element) || value >= param; }, // http://jqueryvalidation.org/max-method/ max: function(value, element, param) { return this.optional(element) || value <= param; }, // http://jqueryvalidation.org/range-method/ range: function(value, element, param) { return this.optional(element) || (value >= param[0] && value <= param[1]); }, // http://jqueryvalidation.org/equalTo-method/ equalTo: function(value, element, param) { // bind to the blur event of the target in order to revalidate whenever the target field is updated // _TODO find a way to bind the event just once, avoiding the unbind-rebind overhead var target = $(param); if(this.settings.onfocusout) { target.unbind(".validate-equalTo").bind("blur.validate-equalTo", function() { $(element).valid(); }); } return value === target.val(); }, // http://jqueryvalidation.org/remote-method/ remote: function(value, element, param) { if(this.optional(element)) { return "dependency-mismatch"; } var previous = this.previousValue(element), validator, data; if(!this.settings.messages[element.name]) { this.settings.messages[element.name] = {}; } previous.originalMessage = this.settings.messages[element.name].remote; this.settings.messages[element.name].remote = previous.message; param = typeof param === "string" && { url: param } || param; if(previous.old === value) { return previous.valid; } previous.old = value; validator = this; this.startRequest(element); data = {}; data[element.name] = value; $.ajax($.extend(true, { url: param, mode: "abort", port: "validate" + element.name, dataType: "json", data: data, async: false, context: validator.currentForm, success: function(response) { var valid, errors, message, submitted; if(typeof response === 'object') { if(response.meta && response.meta.status == 0) { valid = true; } else { valid = false; } } else { valid = response === true || response === "true"; } validator.settings.messages[element.name].remote = previous.originalMessage; if(valid) { submitted = validator.formSubmitted; validator.prepareElement(element); validator.formSubmitted = submitted; validator.successList.push(element); delete validator.invalid[element.name]; validator.showErrors(); } else { errors = {}; message = response || validator.defaultMessage(element, "remote"); if(typeof response === 'object') { message = validator.settings.messages[element.name].remote; } errors[element.name] = previous.message = $.isFunction(message) ? message(value) : message; validator.invalid[element.name] = true; validator.showErrors(errors); } previous.valid = valid; validator.stopRequest(element, valid); } }, param)); return "pending"; }, //ip校验 isIP: function(value, element) { return this.optional(element) || (/^((25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(25[0-5]|2[0-4]\d|1?\d?\d)$/.test(value)); }, //Mac地址校验 isMAC: function(value, element) { return this.optional(element) || (/^[A-F\d]{2}[:-][A-F\d]{2}[:-][A-F\d]{2}[:-][A-F\d]{2}[:-][A-F\d]{2}[:-][A-F\d]{2}$/.test(value)); }, //身份证校验 isIdCard: function(value, element) { var area = { 11: "北京", 12: "天津", 13: "河北", 14: "山西", 15: "内蒙古", 21: "辽宁", 22: "吉林", 23: "黑龙江", 31: "上海", 32: "江苏", 33: "浙江", 34: "安徽", 35: "福建", 36: "江西", 37: "山东", 41: "河南", 42: "湖北", 43: "湖南", 44: "广东", 45: "广西", 46: "海南", 50: "重庆", 51: "四川", 52: "贵州", 53: "云南", 54: "西藏", 61: "陕西", 62: "甘肃", 63: "青海", 64: "宁夏", 65: "新疆", 71: "台湾", 81: "香港", 82: "澳门", 91: "国外" }; var Y, JYM; var S, M; var result = true; var idcard_array = new Array(); idcard_array = value.split(""); //地区检验 if(area[parseInt(value.substr(0, 2))] == null) { result = false; } //身份号码位数及格式检验 switch(value.length) { case 15: if((parseInt(value.substr(6, 2)) + 1900) % 4 == 0 || ((parseInt(value.substr(6, 2)) + 1900) % 100 == 0 && (parseInt(value.substr(6, 2)) + 1900) % 4 == 0)) { ereg = /^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}$/; //测试出生日期的合法性 } else { ereg = /^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}$/; //测试出生日期的合法性 } if(!ereg.test(value)) { result = false; } break; case 18: //18位身份号码检测 //出生日期的合法性检查 //闰年月日:((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9])) //平年月日:((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8])) var year = parseInt(value.substr(6, 4)); if(year % 4 == 0 && year % 100 != 0 || year % 400 == 0) { ereg = /^[1-9][0-9]{5}(19|20)[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}[0-9Xx]$/; //闰年出生日期的合法性正则表达式 } else { ereg = /^[1-9][0-9]{5}(19|20)[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}[0-9Xx]$/; //平年出生日期的合法性正则表达式 } if(ereg.test(value)) { //测试出生日期的合法性 //计算校验位 S = (parseInt(idcard_array[0]) + parseInt(idcard_array[10])) * 7 + (parseInt(idcard_array[1]) + parseInt(idcard_array[11])) * 9 + (parseInt(idcard_array[2]) + parseInt(idcard_array[12])) * 10 + (parseInt(idcard_array[3]) + parseInt(idcard_array[13])) * 5 + (parseInt(idcard_array[4]) + parseInt(idcard_array[14])) * 8 + (parseInt(idcard_array[5]) + parseInt(idcard_array[15])) * 4 + (parseInt(idcard_array[6]) + parseInt(idcard_array[16])) * 2 + parseInt(idcard_array[7]) * 1 + parseInt(idcard_array[8]) * 6 + parseInt(idcard_array[9]) * 3; Y = S % 11; M = "F"; JYM = "10X98765432"; M = JYM.substr(Y, 1); //判断校验位 if(!(M == idcard_array[17])) { result = false; //检测ID的校验位 } } else { result = false; } break; default: result = false; break; } return this.optional(element) || result; }, //手机号校验 isMobile: function(value, element) { return this.optional(element) || (/^(13[0-9]|14[0-9]|15[0-9]|17[0-9]|18[0-9])\d{8}$/.test(value)); }, //特殊字符 isSpecialStr: function(value, element) { return this.optional(element) || (/^[^\^\.<>%&';=?$":#!~\]\[{}\\/\|]*$/.test(value)); }, //特殊字符 isQQ: function(value, element) { return this.optional(element) || (/^[1-9][0-9]{4,11}$/.test(value)); }, /* * 扩展jquery validator验证规则,添加网综之前使用的规则 */ // 自定义验证输入的非法字符 // invalidChar:"'`~^\"" invalidChar: function(value, element, param) { var reg = new RegExp("[" + param + "]+"); return this.optional(element) || !reg.test(value); }, // 自定义日期格式,比较大小 // ["#endTime", "<=", "yyyy-MM-dd"] compareTime: function(value, element, param) { var oper = param[1] || ">", fmt = param[2] || "yyyy-MM-dd"; return this.optional(element) || _compareTime_(value, $(param[0]).val(), oper, fmt); }, // 自定义日期格式的日期验证 date: function(value, element, param) { var fDate = new Date(value).format(param); return this.optional(element) || (value === fDate); }, // 自定义大小比较 // param[0] -- #ele, param[1] -- == != > < >= <= 等 compareTo: function(value, element, param) { var tEle = $(param[0]), oper = param[1]; if($.trim(value) !== "" && $.trim(tEle.val()) !== "") { try { return(new Function("return " + (value + oper + tEle.val()) + ";"))(); } catch(e) { return false; } } else { return true; } }, // 自定义正则匹配 regExp: function(value, element, param) { param = typeof param == "string" ? new RegExp(param) : param; return this.optional(element) || (param.test(value)); }, // 自定义正则匹配 accept: function(value, element, param) { param = typeof param == "string" ? new RegExp(param) : param; return this.optional(element) || (param.test(value)); }, // 1. 中文字节长度验证(在UTF8编码下一个汉字占 3 个字节) CNRangeLength: function(value, element, param) { var byteLen = value.replace(/[^\x00-\xff]/g, '***').length; //param[-1]=3; param[3] = parseInt(param[1] / 3, 10); return this.optional(element) || (byteLen >= param[0] && byteLen < param[1]); }, // 2. 验证邮政编码 postalcode: function(value, element) { return this.optional(element) || (/^[1-9]\d{5}(?!\d)$/.test(value)); }, // 3. 验证IP IP: function(value, element) { return this.optional(element) || (/^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$/.test($.trim(value))); }, // 4. 验证MAC,以-分隔 MAC: function(value, element) { return this.optional(element) || (/^([0-9a-fA-F]){2}(([\s-][0-9a-fA-F]{2}){5})$/.test($.trim(value))); }, // 5. 验证固定电话号码 telephone: function(value, element) { return this.optional(element) || (/^(\d{3,4}-)\d{7,8}$/.test($.trim(value))); }, // 6. 验证手机号码 mobile: function(value, element) { return this.optional(element) || (/^(13[0-9]|15[0-9]|18[0-9]|14[0-9]|17[0-9])\d{8}$/.test($.trim(value))); }, // 7. 中文日期格式验证 dateCN: function(value, element) { var _dateReg = /^(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29)$/; return this.optional(element) || (_dateReg.test($.trim(value))); }, // 8. 只能输入中文 chinese: function(value, element) { value = value.replace(/(^\s*)|(\s*$)/g, ""); return this.optional(element) || (/^[\u4e00-\u9fa5]+$/gi.test($.trim(value))); }, // 9. 检测特殊字符 ' " ? & $ ~ ^ % 等 validChar: function(value, element) { // [`&~%\^\$\?\'\"] return this.optional(element) || (!(/[`~\^\'\"]+/g.test($.trim(value)))); }, //10. 验证身份证号码 IDCard: function(value, element) { return this.optional(element) || _checkIDCard_($.trim(value)); } } }); $.format = function deprecated() { throw "$.format has been deprecated. Please use $.validator.format instead."; }; // ajax mode: abort // usage: $.ajax({ mode: "abort"[, port: "uniqueport"]}); // if mode:"abort" is used, the previous request on that port (port can be undefined) is aborted via XMLHttpRequest.abort() var pendingRequests = {}, ajax; // Use a prefilter if available (1.5+) if($.ajaxPrefilter) { $.ajaxPrefilter(function(settings, _, xhr) { var port = settings.port; if(settings.mode === "abort") { if(pendingRequests[port]) { pendingRequests[port].abort(); } pendingRequests[port] = xhr; } }); } else { // Proxy ajax ajax = $.ajax; $.ajax = function(settings) { var mode = ("mode" in settings ? settings : $.ajaxSettings).mode, port = ("port" in settings ? settings : $.ajaxSettings).port; if(mode === "abort") { if(pendingRequests[port]) { pendingRequests[port].abort(); } pendingRequests[port] = ajax.apply(this, arguments); return pendingRequests[port]; } return ajax.apply(this, arguments); }; } // provides delegate(type: String, delegate: Selector, handler: Callback) plugin for easier event delegation // handler is only called when $(event.target).is(delegate), in the scope of the jquery-object for event.target $.extend($.fn, { validateDelegate: function(delegate, type, handler) { return this.bind(type, function(event) { var target = $(event.target); if(target.is(delegate)) { return handler.apply(target, arguments); } }); } }); // 验证身份证号码,用于 jQuery.validator.addMethod('IDCard', ...); function _checkIDCard_(idcard) { var res = false; var areas = { 11: "北京", 12: "天津", 13: "河北", 14: "山西", 15: "内蒙古", 21: "辽宁", 22: "吉林", 23: "黑龙江", 31: "上海", 32: "江苏", 33: "浙江", 34: "安徽", 35: "福建", 36: "江西", 37: "山东", 41: "河南", 42: "湖北", 43: "湖南", 44: "广东", 45: "广西", 46: "海南", 50: "重庆", 51: "四川", 52: "贵州", 53: "云南", 54: "西藏", 61: "陕西", 62: "甘肃", 63: "青海", 64: "宁夏", 65: "新疆", 71: "台湾", 81: "香港", 82: "澳门", 91: "国外" }; // 检测出生日期合法性的方法 var isValidDate = function(_date) { var dateReg = /^(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29)$/; if(dateReg.test(_date)) { return true; } else { return false; } } if(!(/(^\d{15}$)|(^\d{17}([0-9]|X|x)$)/).test(idcard)) { //alert("您的身份证号码非法!\n\n请输入15位或18位身份证号码!"); res = false; return false; } else { // 地区检验 if(areas[idcard.substr(0, 2)] == null || areas[idcard.substring(0, 2)] == "") { //alert("您的身份证号码的前2位号码非法!请输入合法的身份证号码!"); res = false; return false; } else { switch(idcard.length) { case 15: // 检测出生日期合法性 if(!isValidDate(parseInt(idcard.substr(6, 2), 10) + 1900 + "-" + idcard.substr(8, 2) + "-" + idcard.substr(10, 2))) { //alert("您的15位身份证号码的“出生日期”非法!请输入合法的出生日期!"); res = false; return false; } else { res = true; } break; case 18: // 检测出生日期合法性 if(!isValidDate(idcard.substr(6, 4) + "-" + idcard.substr(10, 2) + "-" + idcard.substr(12, 2))) { // alert("您的18位身份证号码的“出生日期”非法!请输入合法的出生日期!"); res = false; return false; } // 检验校验码合法性 var idcard_arr = idcard.split(""); var S = (parseInt(idcard_arr[0], 10) + parseInt(idcard_arr[10], 10)) * 7 + (parseInt(idcard_arr[1], 10) + parseInt(idcard_arr[11], 10)) * 9 + (parseInt(idcard_arr[2], 10) + parseInt(idcard_arr[12], 10)) * 10 + (parseInt(idcard_arr[3], 10) + parseInt(idcard_arr[13], 10)) * 5 + (parseInt(idcard_arr[4], 10) + parseInt(idcard_arr[14], 10)) * 8 + (parseInt(idcard_arr[5], 10) + parseInt(idcard_arr[15], 10)) * 4 + (parseInt(idcard_arr[6], 10) + parseInt(idcard_arr[16], 10)) * 2 + parseInt(idcard_arr[7], 10) * 1 + parseInt(idcard_arr[8], 10) * 6 + parseInt(idcard_arr[9], 10) * 3; var Y = S % 11; //校验码 var JYM = "10X98765432"; //计算出的校验位 if(JYM.substr(Y, 1) != idcard_arr[17]) { //alert("您的18位身份证号码的最后一位号码非法!请输入合法的身份证号码!"); res = false; return false; } res = true; break; } } } return res; } function _compareTime_(t1, t2, oper, fmt) { t1 = t1 || "0000-00-00", t2 = t2 || "0000-00-00"; oper = oper || ">", fmt = fmt || "yyyy-MM-dd"; var f = { 'yyyy': 1, 'MM': 2, 'dd': 3, 'HH': 4, 'mm': 5, 'ss': 6 }; var x = [], f = fmt.replace(/(\w+)/g, function(a, b) { return f[b]; }).match(/\w+/g).sort(function(a, b) { x.push(a - b); return a - b; }); function _formatTime_(t) { var i = 0; r = t.match(/\d+/g).sort(function() { return x[i++]; }); return new Date(r[0] + '/' + r[1] + '/' + r[2] + ' ' + (r[3] || '00') + ':' + (r[4] || '00') + ':' + (r[5] || '00')); } switch($.trim(oper)) { case '>': return _formatTime_(t1) > _formatTime_(t2); break; case '>=': return _formatTime_(t1) >= _formatTime_(t2); break; case '<': return _formatTime_(t1) < _formatTime_(t2); break; case '<=': return _formatTime_(t1) <= _formatTime_(t2); break; case '==': case '===': return _formatTime_(t1) === _formatTime_(t2); break; case '!=': case '!==': return _formatTime_(t1) !== _formatTime_(t2); break; default: return _formatTime_(t1) > _formatTime_(t2); break; } } /** * 格式化日期显示样式 * eg. new Date().format("yyyy-MM-dd"); */ Date.prototype.format = function(format) { format = format || "yyyy-MM-dd HH:mm:ss"; var fm = { "M+": this.getMonth() + 1, "d+": this.getDate(), "H+": this.getHours(), "m+": this.getMinutes(), "s+": this.getSeconds(), "q+": Math.floor((this.getMonth() + 3) / 3), "S": this.getMilliseconds() }; if(/(y+)/.test(format)) { format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); } for(var f in fm) { if(new RegExp("(" + f + ")").test(format)) { format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? fm[f] : ("00" + fm[f]).substr(("" + fm[f]).length)); } } return format; }; })); }, {}]; /* 例子 //信息框-例1 layer.alert('见到你真的很高兴', {icon: 6}); //信息框-例2 layer.msg('你确定你很帅么?', { time: 0 //不自动关闭 ,btn: ['必须啊', '丑到爆'] ,yes: function(index){ layer.close(index); layer.msg('雅蠛蝶 O.o', { icon: 6 ,btn: ['嗷','嗷','嗷'] }); } }); //信息框-例3 layer.msg('这是最常用的吧'); //信息框-例4 layer.msg('不开心。。', {icon: 5}); //信息框-例5 layer.msg('玩命卖萌中', function(){ //关闭后的操作 }); //页面层-自定义 layer.open({ type: 1, title: false, closeBtn: 0, shadeClose: true, skin: 'yourclass', content: '自定义HTML内容' }); //页面层-佟丽娅 layer.open({ type: 1, title: false, closeBtn: 0, area: '516px', skin: 'layui-layer-nobg', //没有背景色 shadeClose: true, content: $('#tong') }); //iframe层-父子操作 layer.open({ type: 2, area: ['700px', '450px'], fixed: false, //不固定 maxmin: true, content: 'test/iframe.html' }); //iframe层-多媒体 layer.open({ type: 2, title: false, area: ['630px', '360px'], shade: 0.8, closeBtn: 0, shadeClose: true, content: '//player.youku.com/embed/XMjY3MzgzODg0' }); layer.msg('点击任意处关闭'); //iframe层-禁滚动条 layer.open({ type: 2, area: ['360px', '500px'], skin: 'layui-layer-rim', //加上边框 content: ['mobile/', 'no'] }); //加载层-默认风格 layer.load(); //此处演示关闭 setTimeout(function(){ layer.closeAll('loading'); }, 2000); //加载层-风格2 layer.load(1); //此处演示关闭 setTimeout(function(){ layer.closeAll('loading'); }, 2000); //加载层-风格3 layer.load(2); //此处演示关闭 setTimeout(function(){ layer.closeAll('loading'); }, 2000); //加载层-风格4 layer.msg('加载中', { icon: 16 ,shade: 0.01 }); //打酱油 layer.msg('尼玛,打个酱油', {icon: 4}); //tips层-上 layer.tips('上', '#id或者.class', { tips: [1, '#0FA6D8'] //还可配置颜色 }); //tips层-右 layer.tips('默认就是向右的', '#id或者.class'); //tips层-下 layer.tips('下', '#id或者.class', { tips: 3 }); //tips层-左 layer.tips('左边么么哒', '#id或者.class', { tips: [4, '#78BA32'] }); //tips层-不销毁之前的 layer.tips('不销毁之前的', '#id或者.class', { tipsMore: true }); //默认prompt layer.prompt(function(val, index){ layer.msg('得到了'+val); layer.close(index); }); //屏蔽浏览器滚动条 layer.open({ content: '浏览器滚动条已锁', scrollbar: false }); //弹出即全屏 var index = layer.open({ type: 2, content: 'http://layim.layui.com', area: ['320px', '195px'], maxmin: true }); layer.full(index); //正上方 layer.msg('灵活运用offset', { offset: 't', anim: 6 }); //更多例子 layer.msg('Hi');*/ var cuiLayerImpl = [function(require, module, exports) { module.exports = (function(window, undefined) { "use strict"; var isLayui = window.layui && layui.define, win, ready = { getPath: function() { var js = document.scripts, script = js[js.length - 1], jsPath = script.src; if(script.getAttribute('merge')) return; return jsPath.substring(0, jsPath.lastIndexOf("/") + 1); }(), config: {}, end: {}, minIndex: 0, minLeft: [], btn: ['确定', '取消'], //五种原始层模式 type: ['dialog', 'page', 'iframe', 'loading', 'tips'] }; //默认内置方法。 var layer = { v: '3.0.3', ie: function() { //ie版本 var agent = navigator.userAgent.toLowerCase(); return(!!window.ActiveXObject || "ActiveXObject" in window) ? ((agent.match(/msie\s(\d+)/) || [])[1] || '11' //由于ie11并没有msie的标识 ) : false; }(), index: (window.layer && window.layer.v) ? 100000 : 0, path: ready.getPath, config: function(options, fn) { options = options || {}; layer.cache = ready.config = $.extend({}, ready.config, options); layer.path = ready.config.path || layer.path; typeof options.extend === 'string' && (options.extend = [options.extend]); if(ready.config.path) layer.ready(); if(!options.extend) return this; isLayui ? layui.addcss('modules/layer/' + options.extend) : layer.link('skin/' + options.extend); return this; }, //载入CSS配件 link: function(href, fn, cssname) { //未设置路径,则不主动加载css if(!layer.path) return; var head = $('head')[0], link = document.createElement('link'); if(typeof fn === 'string') cssname = fn; var app = (cssname || href).replace(/\.|\//g, ''); var id = 'layuicss-' + app, timeout = 0; link.rel = 'stylesheet'; link.href = layer.path + href; link.id = id; if(!$('#' + id)[0]) { head.appendChild(link); } if(typeof fn !== 'function') return; //轮询css是否加载完毕 (function poll() { if(++timeout > 8 * 1000 / 100) { return window.console && console.error('layer.css: Invalid'); } parseInt($('#' + id).css('width')) === 1989 ? fn() : setTimeout(poll, 100); }()); }, ready: function(callback) { var cssname = 'skinlayercss', ver = '303'; isLayui ? layui.addcss('modules/layer/default/layer.css?v=' + layer.v + ver, callback, cssname) : layer.link('skin/default/layer.css?v=' + layer.v + ver, callback, cssname); return this; }, /** * 以弹窗方式显示错误 * @param content * @param yes */ alertError: function(content, yes) { if (content) { content = content.replace(/\\n/g, '
'); } dialog.alert(content, {icon: 11, btn: ['确定']}, yes) }, //各种快捷引用 alert: function(content, options, yes) { var type = typeof options === 'function'; if(type) yes = options; // add by clu on 2019-1-9 16:06:07 为dialog.alert添加统一的确定按钮 if (!options) { options = {btn: ['确定']}; } return layer.open($.extend({ content: content, yes: yes, autoClose: true }, type ? {} : options)); }, confirm: function(content, options, yes, cancel) { var type = typeof options === 'function'; if(type) { cancel = yes; yes = options; } return layer.open($.extend({ content: content, btn: ready.btn, yes: yes, btn2: cancel, autoClose: true }, type ? {} : options)); }, msg: function(content, options, end) { //最常用提示层 var type = typeof options === 'function', rskin = ready.config.skin; var skin = (rskin ? rskin + ' ' + rskin + '-msg' : '') || 'layui-layer-msg'; var anim = doms.anim.length - 1; if(type) end = options; return layer.open($.extend({ content: content, time: 3000, shade: false, skin: skin, title: false, closeBtn: false, btn: false, resize: false, end: end }, (type && !ready.config.skin) ? { skin: skin + ' layui-layer-hui', anim: anim } : function() { options = options || {}; if(options.icon === -1 || options.icon === undefined && !ready.config.skin) { options.skin = skin + ' ' + (options.skin || 'layui-layer-hui'); } return options; }())); }, load: function(icon, options) { return layer.open($.extend({ type: 3, icon: icon || 0, resize: false, shade: 0.01 }, options)); }, tips: function(content, follow, options) { return layer.open($.extend({ type: 4, content: [content, follow], closeBtn: false, time: 3000, shade: false, resize: false, fixed: false, maxWidth: 210 }, options)); } }; var LayerClass = function(setings) { var that = this; that.index = ++layer.index; that.config = $.extend({}, that.config, ready.config, setings); document.body ? that.createLayer() : setTimeout(function() { that.createLayer(); }, 30); }; LayerClass.pt = LayerClass.prototype; //缓存常用字符 var doms = ['layui-layer', '.layui-layer-title', '.layui-layer-main', '.layui-layer-dialog', 'layui-layer-iframe', 'layui-layer-content', 'layui-layer-btn', 'layui-layer-close']; doms.anim = ['layui-anim', 'layui-anim-01', 'layui-anim-02', 'layui-anim-03', 'layui-anim-04', 'layui-anim-05', 'layui-anim-06']; //默认配置,可以在LayerClass的构造方法中使用this.config访问 LayerClass.pt.config = { /** * 类型:Number,默认:0 layer提供了5种层类型。可传入的值有:0(信息框,默认)1(页面层)2(iframe层)3(加载层)4(tips层)。 若你采用layer.open({type: 1})方式调用,则type为必填项(信息框除外) */ type: 0, /** * 标题 * 类型:String/Array/Boolean,默认:'信息' title支持三种类型的值,若你传入的是普通的字符串,如title :'我是标题',那么只会改变标题文本;若你还需要自定义标题区域样式, 那么你可以title: ['文本', 'font-size:18px;'],数组第二项可以写任意css样式;如果你不想显示标题栏,你可以title: false */ title: '信息', /** * 类型:String/DOM/Array,默认:'' content可传入的值是灵活多变的,不仅可以传入普通的html内容,还可以指定DOM: type: 1, '传入任意的文本或html' //这里content是一个普通的String type: 1, $('#id') 这里content是一个DOM,注意:最好该元素要存放在body最外层,否则可能被其它的相对元素所影响 type: 2, 'http://sentsin.com' //这里content是一个URL,如果你不想让iframe出现滚动条,你还可以content: ['http://sentsin.com', 'no'] type: 4, content: ['内容', '#id'] //数组第二项即吸附元素选择器或者DOM */ content: '', /** * 样式类名 * 类型:String,默认:'' skin不仅允许你传入layer内置的样式class名,还可以传入您自定义的class名。这是一个很好的切入点, 意味着你可以借助skin轻松完成不同的风格定制。目前layer内置的skin有:layui-layer-lanlayui-layer-molv, 未来我们还会选择性地内置更多,但更推荐您自己来定义。以下是一个自定义风格的简单例子 //单个使用 layer.open({ skin: 'demo-class' }); //全局使用。即所有弹出层都默认采用,但是单个配置skin的优先级更高 layer.config({ skin: 'demo-class' }) //CSS body .demo-class .layui-layer-title{background:#c00; color:#fff; border: none;} body .demo-class .layui-layer-btn{border-top:1px solid #E9E7E7} body .demo-class .layui-layer-btn a{background:#333;} body .demo-class .layui-layer-btn .layui-layer-btn1{background:#999;} */ skin: '', /** * 坐标 类型:String/Array,默认:垂直水平居中 offset默认情况下不用设置。但如果你不想垂直水平居中,你还可以进行以下赋值: offset: 'auto' 默认坐标,即垂直水平居中 offset: '100px' 只定义top坐标,水平保持居中 offset: ['100px', '50px'] 同时定义top、left坐标 offset: 't' 快捷设置顶部坐标 offset: 'r' 快捷设置右边缘坐标 offset: 'b' 快捷设置底部坐标 offset: 'l' 快捷设置左边缘坐标 offset: 'lt' 快捷设置左上角 offset: 'lb' 快捷设置左下角 offset: 'rt' 快捷设置右上角 offset: 'rb' 快捷设置右下角 */ offset: 'auto', /** * 宽高 * 类型:String/Array,默认:'auto' 在默认状态下,layer是宽高都自适应的,但当你只想定义宽度时,你可以area: '500px',高度仍然是自适应的。当你宽高都要定义时,你可以area: ['500px', '300px'] */ area: 'auto', /** * 图标。信息框和加载层的私有参数 * 类型:Number,默认:-1(信息框)/0(加载层) 信息框默认不显示图标。当你想显示图标时,默认皮肤可以传入0-6如果是加载层,可以传入0-2。如: //eg1 layer.alert('酷毙了', {icon: 1}); //eg2 layer.msg('不开心。。', {icon: 5}); //eg3 layer.load(1); //风格1的加载 */ icon: -1, /** * 按钮 * 类型:String/Array,默认:undefined 信息框模式时,btn默认是一个确认按钮,其它层类型则默认不显示,加载层和tips层则无效。当您只想自定义一个按钮时, 你可以btn: '我知道了',当你要定义两个按钮时,你可以btn: ['yes', 'no']。 当然,你也可以定义更多按钮,比如:btn: ['按钮1', '按钮2', '按钮3', …],按钮1的回调是yes, 而从按钮2开始,则回调为btn2: function(){},以此类推。如: layer.open({ content: 'test' ,btn: ['按钮一', '按钮二', '按钮三'] ,yes: function(index, layero){ //按钮【按钮一】的回调 } ,btn2: function(index, layero){ //按钮【按钮二】的回调 //return false 开启该代码可禁止点击该按钮关闭 } ,btn3: function(index, layero){ //按钮【按钮三】的回调 //return false 开启该代码可禁止点击该按钮关闭 } ,cancel: function(){ //右上角关闭回调 //return false 开启该代码可禁止点击该按钮关闭 } }); */ btn: null, /** * 按钮排列 * 类型:String,默认:r 你可以快捷定义按钮的排列位置,btnAlign的默认值为r,即右对齐。该参数可支持的赋值如下: 值 备注 btnAlign: 'l' 按钮左对齐 btnAlign: 'c' 按钮居中对齐 btnAlign: 'r' 按钮右对齐。默认值,不用设置 */ btnAlign: 'r', /** * 关闭按钮 * 类型:String/Boolean,默认:1 layer提供了两种风格的关闭按钮,可通过配置1和2来展示,如果不显示,则closeBtn: 0 */ closeBtn: 1, /** * 遮罩 * 类型:String/Array/Boolean,默认:0.3 即弹层外区域。默认是0.3透明度的黑色背景('#000')。如果你想定义别的颜色,可以shade: [0.8, '#393D49'];如果你不想显示遮罩,可以shade: 0 */ shade: 0.3, /** * 是否点击遮罩关闭 * 类型:Boolean,默认:false 如果你的shade是存在的,那么你可以设定shadeClose来控制点击弹层外区域关闭。 */ shadeClose: false, /** * 自动关闭所需毫秒 * 类型:Number,默认:0 默认不会自动关闭。当你想自动关闭时,可以time: 5000,即代表5秒后自动关闭,注意单位是毫秒(1秒=1000毫秒) */ time: 0, /** * 用于控制弹层唯一标识 * 类型:String,默认:空字符 设置该值后,不管是什么类型的层,都只允许同时弹出一个。一般用于页面层和iframe层模式 */ id: '', /** * 弹出动画 * 类型:Number,默认:0 我们的出场动画全部采用CSS3。这意味着除了ie6-9,其它所有浏览器都是支持的。目前anim可支持的动画类型有0-6 如果不想显示动画,设置 anim: -1 即可。另外需要注意的是,3.0之前的版本用的是 shift 参数 anim: 0 平滑放大。默认 anim: 1 从上掉落 anim: 2 从最底部往上滑入 anim: 3 从左滑入 anim: 4 从左翻滚 anim: 5 渐显 anim: 6 抖动 */ anim: 0, /** * 关闭动画 (layer 3.0.3新增) * 类型:Boolean,默认:true 默认情况下,关闭层时会有一个过度动画。如果你不想开启,设置 isOutAnim: false 即可 */ isOutAnim: true, /** * 最大最小化 * 类型:Boolean,默认:false 该参数值对type:1和type:2有效。默认不显示最大小化按钮。需要显示配置maxmin: true即可 */ maxmin: false, /** * 固定 * 类型:Boolean,默认:true 即鼠标滚动时,层是否固定在可视区域。如果不想,设置fixed: false即可 */ fixed: true, moveType: 1, /** * 是否允许拉伸 * 类型:Boolean,默认:false 默认情况下,你可以在弹层右下角拖动来拉伸尺寸。如果对指定的弹层屏蔽该功能,设置 false即可。该参数对loading、tips层无效 */ resize: false, /** * 监听窗口拉伸动作 类型:Boolean,默认:true 默认情况下,你可以在弹层右下角拖动来拉伸尺寸。如果对指定的弹层屏蔽该功能,设置 false即可。该参数对loading、tips层无效 */ resizing: null, /** * 是否允许浏览器出现滚动条 类型:Boolean,默认:true 默认允许浏览器滚动,如果设定scrollbar: false,则屏蔽 */ scrollbar: true, /** * 最大宽度 类型:Number,默认:360 请注意:只有当area: 'auto'时,maxWidth的设定才有效。 */ maxWidth: 470, /** * 最大高度 类型:Number,默认:无 请注意:只有当高度自适应时,maxHeight的设定才有效。 */ maxHeight: null, zIndex: 19891014, /** * 触发拖动的元素 类型:String/DOM/Boolean,默认:'.layui-layer-title' 默认是触发标题区域拖拽。如果你想单独定义,指向元素的选择器或者DOM即可。如move: '.mine-move'。你还配置设定move: false来禁止拖拽 */ move: doms[1], /** * 是否允许拖拽到窗口外 类型:Boolean,默认:false 默认只能在窗口内拖拽,如果你想让拖到窗外,那么设定moveOut: true即可 */ moveOut: false, /** * 拖动完毕后的回调方法 类型:Function,默认:null 默认不会触发moveEnd,如果你需要,设定moveEnd: function(layero){}即可。其中layero为当前层的DOM对象 */ moveEnd: null, /** * tips方向和颜色 类型:Number/Array,默认:2 tips层的私有参数。支持上右下左四个方向,通过1-4进行方向设定。如tips: 3则表示在元素的下面出现。有时你还可能会定义一些颜色,可以设定tips: [1, '#c00'] */ tips: 2, /** * 是否允许多个tips 类型:Boolean,默认:false 允许多个意味着不会销毁之前的tips层。通过tipsMore: true开启 */ tipsMore: false, /** * 层弹出后的成功回调方法 类型:Function,默认:null 当你需要在层创建完毕时即执行一些语句,可以通过该回调。success会携带两个参数,分别是当前层DOM当前层索引。如: layer.open({ content: '测试回调', success: function(layero, index){ console.log(layero, index); } }); */ success: null, /** * 确定按钮回调方法 类型:Function,默认:null 该回调携带两个参数,分别为当前层索引、当前层DOM对象。如: layer.open({ content: '测试回调', yes: function(index, layero){ //do something layer.close(index); //如果设定了yes回调,需进行手工关闭 } }); */ yes: null, /** * 层销毁后触发的回调 类型:Function,默认:null 无论是确认还是取消,只要层被销毁了,end都会执行,不携带任何参数。 */ end: null, /** * full/min/restore -分别代表最大化、最小化、还原 后触发的回调 类型:Function,默认:null 携带一个参数,即当前层DOM */ full: null, min: null, restore: null }; //创建容器 LayerClass.pt.vessel = function(conType, callback) { var that = this, times = that.index, config = that.config; var zIndex = config.zIndex + times, titype = typeof config.title === 'object'; var ismax = config.maxmin && (config.type === 1 || config.type === 2); var titleHTML = (config.title ? '
' + (titype ? config.title[0] : config.title) + '
' : ''); config.zIndex = zIndex; callback([ //遮罩 config.shade ? ('
') : '', //主体 '
' + (conType && config.type != 2 ? '' : titleHTML) + '
' + (config.type == 0 && config.icon !== -1 ? '' : '') + (config.type == 1 && conType ? '' : (config.content || '')) + '
' + '' + function() { var closebtn = ismax ? '' : ''; config.closeBtn && (closebtn += ''); return closebtn; }() + '' + (config.btn ? function() { var button = ''; typeof config.btn === 'string' && (config.btn = [config.btn]); for(var i = 0, len = config.btn.length; i < len; i++) { button += '' + config.btn[i] + '' } return '
' + button + '
' }() : '') + (config.resize ? '' : '') + '
' ], titleHTML, $('
')); return that; }; //创建骨架,comment by clu on 2018年10月30日14:18:19 dialog组件实现的地方,dialog组件API LayerClass.pt.createLayer = function() { var that = this, config = that.config, times = that.index, nodeIndex, content = config.content, conType = typeof content === 'object', body = $('body'); if(config.id && $('#' + config.id)[0]) return; if(typeof config.area === 'string') { config.area = config.area === 'auto' ? ['', ''] : [config.area, '']; } //anim兼容旧版shift if(config.shift) { config.anim = config.shift; } if(layer.ie == 6) { config.fixed = false; } switch(config.type) { case 0: // 消息框 config.btn = ('btn' in config) ? config.btn : ready.btn[0]; layer.closeAll('dialog'); break; case 2: // iframe var content = config.content = conType ? config.content : [config.content, 'auto']; config.content = ''; break; case 3: // 加载层,可以是loading,也可以是 delete config.title; delete config.closeBtn; config.icon === -1 && (config.icon === 0); layer.closeAll('loading'); break; case 4: // tip提示 conType || (config.content = [config.content, 'body']); config.follow = config.content[1]; config.content = config.content[0] + ''; delete config.title; config.tips = typeof config.tips === 'object' ? config.tips : [config.tips, true]; config.tipsMore || layer.closeAll('tips'); break; } //建立容器 that.vessel(conType, function(html, titleHTML, moveElem) { body.append(html[0]); conType ? function() { (config.type == 2 || config.type == 4) ? function() { $('body').append(html[1]); }() : function() { if(!content.parents('.' + doms[0])[0]) { content.data('display', content.css('display')).show().addClass('layui-layer-wrap').wrap(html[1]); $('#' + doms[0] + times).find('.' + doms[5]).before(titleHTML); } }(); }() : body.append(html[1]); $('.layui-layer-move')[0] || body.append(ready.moveElem = moveElem); that.layero = $('#' + doms[0] + times); config.scrollbar || doms.html.css('overflow', 'hidden').attr('layer-full', times); }).auto(times); config.type == 2 && layer.ie == 6 && that.layero.find('iframe').attr('src', content[0]); //坐标自适应浏览器窗口尺寸 config.type == 4 ? that.tips() : that.offset(); if(config.fixed) { win.on('resize', function() { that.offset(); (/^\d+%$/.test(config.area[0]) || /^\d+%$/.test(config.area[1])) && that.auto(times); config.type == 4 && that.tips(); }); } config.time <= 0 || setTimeout(function() { layer.close(that.index) }, config.time); that.move().callback(); //为兼容jQuery3.0的css动画影响元素尺寸计算 if(doms.anim[config.anim]) { that.layero.addClass(doms.anim[config.anim]); } //记录关闭动画 if(config.isOutAnim) { that.layero.data('isOutAnim', true); } }; //自适应 LayerClass.pt.auto = function(index) { var that = this, config = that.config, layero = $('#' + doms[0] + index); if(config.area[0] === '' && config.maxWidth > 0) { //为了修复IE7下一个让人难以理解的bug if(layer.ie && layer.ie < 8 && config.btn) { layero.width(layero.innerWidth()); } if (config.type === 3) { // loading使用原始处理 layero.outerWidth() > config.maxWidth && layero.width(config.maxWidth); } else { // edit by clu on 2020-7-21 09:55:10 重新实现宽度自适应 // 如果是带icon的alert,要加款30px var deltaWidth = config.icon === -1 ? 0 : 30; var height = layero.outerHeight(), newWidth = Math.min(layero.outerWidth() + deltaWidth, config.maxWidth); // 过于方的弹窗按照比例加宽 if (newWidth / height < 1.7) { newWidth = height * 1.7; } layero.width(newWidth); } } var area = [layero.innerWidth(), layero.innerHeight()]; var titHeight = layero.find(doms[1]).outerHeight() || 0; var btnHeight = layero.find('.' + doms[6]).outerHeight() || 0; function setHeight(elem) { elem = layero.find(elem); elem.height(area[1] - titHeight - btnHeight - 2 * (parseFloat(elem.css('padding-top')) | 0)); } switch(config.type) { case 2: setHeight('iframe'); break; default: if(config.area[1] === '') { if(config.fixed && area[1] >= win.height()) { area[1] = win.height(); setHeight('.' + doms[5]); } } else { setHeight('.' + doms[5]); } break; } // add by clu on 2018年11月19日19:29:43 修复提示框的icon不能垂直居中的bug var container = layero; if (layero.find(".layui-layer-title").length > 0) { // 有标题栏,用layui-layer-content计算高度 container = layero.find(".layui-layer-content"); } var icon = container.find(".layui-layer-ico"); if (icon.length > 0) { icon.css('top', (container.outerHeight() - icon.outerHeight()) / 2 - 1); } return that; }; //计算坐标 LayerClass.pt.offset = function() { var that = this, config = that.config, layero = that.layero; var area = [layero.outerWidth(), layero.outerHeight()]; var type = typeof config.offset === 'object'; that.offsetTop = (win.height() - area[1]) / 2; that.offsetLeft = (win.width() - area[0]) / 2; if(type) { that.offsetTop = config.offset[0]; that.offsetLeft = config.offset[1] || that.offsetLeft; } else if(config.offset !== 'auto') { if(config.offset === 't') { //上 that.offsetTop = 0; } else if(config.offset === 'r') { //右 that.offsetLeft = win.width() - area[0]; } else if(config.offset === 'b') { //下 that.offsetTop = win.height() - area[1]; } else if(config.offset === 'l') { //左 that.offsetLeft = 0; } else if(config.offset === 'lt') { //左上角 that.offsetTop = 0; that.offsetLeft = 0; } else if(config.offset === 'lb') { //左下角 that.offsetTop = win.height() - area[1]; that.offsetLeft = 0; } else if(config.offset === 'rt') { //右上角 that.offsetTop = 0; that.offsetLeft = win.width() - area[0]; } else if(config.offset === 'rb') { //右下角 that.offsetTop = win.height() - area[1]; that.offsetLeft = win.width() - area[0]; } else { that.offsetTop = config.offset; } } if(!config.fixed) { that.offsetTop = /%$/.test(that.offsetTop) ? win.height() * parseFloat(that.offsetTop) / 100 : parseFloat(that.offsetTop); that.offsetLeft = /%$/.test(that.offsetLeft) ? win.width() * parseFloat(that.offsetLeft) / 100 : parseFloat(that.offsetLeft); that.offsetTop += win.scrollTop(); that.offsetLeft += win.scrollLeft(); } if(layero.attr('minLeft')) { that.offsetTop = win.height() - (layero.find(doms[1]).outerHeight() || 0); that.offsetLeft = layero.css('left'); } layero.css({ top: that.offsetTop, left: that.offsetLeft }); }; //Tips LayerClass.pt.tips = function() { var that = this, config = that.config, layero = that.layero; var layArea = [layero.outerWidth(), layero.outerHeight()], follow = $(config.follow); if(!follow[0]) follow = $('body'); var goal = { width: follow.outerWidth(), height: follow.outerHeight(), top: follow.offset().top, left: follow.offset().left }, tipsG = layero.find('.layui-layer-TipsG'); var guide = config.tips[0]; // config.tips[1] || tipsG.remove(); goal.autoLeft = function() { if(goal.left + layArea[0] - win.width() > 0) { goal.tipLeft = goal.left + goal.width - layArea[0]; tipsG.css({ right: 12, left: 'auto' }); } else { goal.tipLeft = goal.left; } }; //辨别tips的方位 goal.where = [function() { //上 goal.autoLeft(); goal.tipTop = goal.top - layArea[1] - 10; tipsG.removeClass('layui-layer-TipsB').addClass('layui-layer-TipsT').css('border-right-color', config.tips[1]); }, function() { //右 goal.tipLeft = goal.left + goal.width + 10; goal.tipTop = goal.top; tipsG.removeClass('layui-layer-TipsL').addClass('layui-layer-TipsR').css('border-bottom-color', config.tips[1]); }, function() { //下 goal.autoLeft(); goal.tipTop = goal.top + goal.height + 10; tipsG.removeClass('layui-layer-TipsT').addClass('layui-layer-TipsB').css('border-right-color', config.tips[1]); }, function() { //左 goal.tipLeft = goal.left - layArea[0] - 10; goal.tipTop = goal.top; tipsG.removeClass('layui-layer-TipsR').addClass('layui-layer-TipsL').css('border-bottom-color', config.tips[1]); }]; goal.where[guide - 1](); /* 8*2为小三角形占据的空间 */ if(guide === 1) { goal.top - (win.scrollTop() + layArea[1] + 8 * 2) < 0 && goal.where[2](); } else if(guide === 2) { win.width() - (goal.left + goal.width + layArea[0] + 8 * 2) > 0 || goal.where[3]() } else if(guide === 3) { (goal.top - win.scrollTop() + goal.height + layArea[1] + 8 * 2) - win.height() > 0 && goal.where[0](); } else if(guide === 4) { layArea[0] + 8 * 2 - goal.left > 0 && goal.where[1]() } layero.find('.' + doms[5]).css({ 'background-color': config.tips[1], 'padding-right': (config.closeBtn ? '30px' : '') }); layero.css({ left: goal.tipLeft - (config.fixed ? win.scrollLeft() : 0), top: goal.tipTop - (config.fixed ? win.scrollTop() : 0) }); } //拖拽层 LayerClass.pt.move = function() { var that = this, config = that.config, _DOC = $(document), layero = that.layero, moveElem = layero.find(config.move), resizeElem = layero.find('.layui-layer-resize'), dict = {}; if(config.move) { moveElem.css('cursor', 'move'); } moveElem.on('mousedown', function(e) { e.preventDefault(); if(config.move) { dict.moveStart = true; dict.offset = [e.clientX - parseFloat(layero.css('left')), e.clientY - parseFloat(layero.css('top'))]; ready.moveElem.css('cursor', 'move').show(); } }); resizeElem.on('mousedown', function(e) { e.preventDefault(); dict.resizeStart = true; dict.offset = [e.clientX, e.clientY]; dict.area = [layero.outerWidth(), layero.outerHeight()]; ready.moveElem.css('cursor', 'se-resize').show(); }); _DOC.on('mousemove', function(e) { //拖拽移动 if(dict.moveStart) { var X = e.clientX - dict.offset[0], Y = e.clientY - dict.offset[1], fixed = layero.css('position') === 'fixed'; e.preventDefault(); dict.stX = fixed ? 0 : win.scrollLeft(); dict.stY = fixed ? 0 : win.scrollTop(); //控制元素不被拖出窗口外 if(!config.moveOut) { var setRig = win.width() - layero.outerWidth() + dict.stX, setBot = win.height() - layero.outerHeight() + dict.stY; X < dict.stX && (X = dict.stX); X > setRig && (X = setRig); Y < dict.stY && (Y = dict.stY); Y > setBot && (Y = setBot); } layero.css({ left: X, top: Y }); } //Resize if(config.resize && dict.resizeStart) { var X = e.clientX - dict.offset[0], Y = e.clientY - dict.offset[1]; e.preventDefault(); layer.style(that.index, { width: dict.area[0] + X, height: dict.area[1] + Y }) dict.isResize = true; config.resizing && config.resizing(layero); } }).on('mouseup', function(e) { if(dict.moveStart) { delete dict.moveStart; ready.moveElem.hide(); config.moveEnd && config.moveEnd(layero); } if(dict.resizeStart) { delete dict.resizeStart; ready.moveElem.hide(); } }); return that; }; LayerClass.pt.callback = function() { var that = this, layero = that.layero, config = that.config; that.openLayer(); if(config.success) { if(config.type == 2) { layero.find('iframe').on('load', function() { config.success(layero, that.index); }); } else { config.success(layero, that.index); } } layer.ie == 6 && that.IE6(layero); //按钮 layero.find('.' + doms[6]).children('a').on('click', function() { var index = $(this).index(); if(index === 0) { // edit by clu on 2018-10-30 14:13:01 默认就可以关闭,比如弹出一个提示框,点击确定就可以关闭 var result = true; if(config.yes) { result = config.yes(that.index, layero) } else if(config['btn1']) { result = config['btn1'](that.index, layero) } // result === false可以阻止autoClose if (result === true || result !== false && config.autoClose === true) { // 确定不默认关闭,如果yes回调返回true,自动关闭,其它不关闭 layer.close(that.index); } } else { var close = config['btn' + (index + 1)] && config['btn' + (index + 1)](that.index, layero); close === false || layer.close(that.index); } }); //取消 function cancel() { var close = config.cancel && config.cancel(that.index, layero); close === false || layer.close(that.index); } //右上角关闭回调 layero.find('.' + doms[7]).on('click', cancel); //点遮罩关闭 if(config.shadeClose) { $('#layui-layer-shade' + that.index).on('click', function() { layer.close(that.index); }); } //最小化 layero.find('.layui-layer-min').on('click', function() { var min = config.min && config.min(layero); min === false || layer.min(that.index, config); }); //全屏/还原 layero.find('.layui-layer-max').on('click', function() { if($(this).hasClass('layui-layer-maxmin')) { layer.restore(that.index); config.restore && config.restore(layero); } else { layer.full(that.index, config); setTimeout(function() { config.full && config.full(layero); }, 100); } }); config.end && (ready.end[that.index] = config.end); }; //for ie6 恢复select ready.reselect = function() { $.each($('select'), function(index, value) { var sthis = $(this); if(!sthis.parents('.' + doms[0])[0]) { (sthis.attr('layer') == 1 && $('.' + doms[0]).length < 1) && sthis.removeAttr('layer').show(); } sthis = null; }); }; LayerClass.pt.IE6 = function(layero) { //隐藏select $('select').each(function(index, value) { var sthis = $(this); if(!sthis.parents('.' + doms[0])[0]) { sthis.css('display') === 'none' || sthis.attr({ 'layer': '1' }).hide(); } sthis = null; }); }; //需依赖原型的对外方法 LayerClass.pt.openLayer = function() { var that = this; //置顶当前窗口 layer.zIndex = that.config.zIndex; layer.setTop = function(layero) { var setZindex = function() { layer.zIndex++; layero.css('z-index', layer.zIndex + 1); }; layer.zIndex = parseInt(layero[0].style.zIndex); layero.on('mousedown', setZindex); return layer.zIndex; }; }; ready.record = function(layero) { var area = [layero.width(), layero.height(), layero.position().top, layero.position().left + parseFloat(layero.css('margin-left'))]; layero.find('.layui-layer-max').addClass('layui-layer-maxmin'); layero.attr({ area: area }); }; ready.rescollbar = function(index) { if(doms.html.attr('layer-full') == index) { if(doms.html[0].style.removeProperty) { doms.html[0].style.removeProperty('overflow'); } else { doms.html[0].style.removeAttribute('overflow'); } doms.html.removeAttr('layer-full'); } }; /** 内置成员 */ window.layer = layer; //获取子iframe的DOM layer.getChildFrame = function(selector, index) { index = index || $('.' + doms[4]).attr('times'); return $('#' + doms[0] + index).find('iframe').contents().find(selector); }; //得到当前iframe层的索引,子iframe时使用 layer.getFrameIndex = function(name) { return $('#' + name).parents('.' + doms[4]).attr('times'); }; //iframe层自适应宽高 layer.iframeAuto = function(index) { if(!index) return; var heg = layer.getChildFrame('html', index).outerHeight(); var layero = $('#' + doms[0] + index); var titHeight = layero.find(doms[1]).outerHeight() || 0; var btnHeight = layero.find('.' + doms[6]).outerHeight() || 0; layero.css({ height: heg + titHeight + btnHeight }); layero.find('iframe').css({ height: heg }); }; //重置iframe url layer.iframeSrc = function(index, url) { $('#' + doms[0] + index).find('iframe').attr('src', url); }; //设定层的样式 layer.style = function(index, options, limit) { var layero = $('#' + doms[0] + index), contElem = layero.find('.layui-layer-content'), type = layero.attr('type'), titHeight = layero.find(doms[1]).outerHeight() || 0, btnHeight = layero.find('.' + doms[6]).outerHeight() || 0, minLeft = layero.attr('minLeft'); if(type === ready.type[3] || type === ready.type[4]) { return; } if(!limit) { if(parseFloat(options.width) <= 260) { options.width = 260; }; if(parseFloat(options.height) - titHeight - btnHeight <= 64) { options.height = 64 + titHeight + btnHeight; }; } layero.css(options); btnHeight = layero.find('.' + doms[6]).outerHeight(); if(type === ready.type[2]) { layero.find('iframe').css({ height: parseFloat(options.height) - titHeight - btnHeight }); } else { // edit by clu on 2018-11-16 15:51:49 // 内容框的宽高,并不包含padding和border。这是标准盒模型的情况,但还存在另一种ie盒子模型, // ie盒子模型便是把padding与border包含在宽高内,即宽高包含了内容框的宽高加上padding与边框。 // 一般情况下,ie浏览器会使用ie盒子模型,其它如ff、chrome则使用标准盒子模型。如果要统一使用标准盒子模型, // 我们可以在网页中加入doctype申明使用w3c标准,这样所有浏览器都会使用标准盒子模型。 // css3里有一个属性box-sizing=content-box|border-box|inherit; // 来自http://www.w3school.com.cn的解释: // 值 描述 // content-box 这是由 CSS2.1 规定的宽度高度行为。宽度和高度分别应用到元素的内容框。在宽度和高度之外绘制元素的内边距和边框。 // border-box 为元素设定的宽度和高度决定了元素的边框盒。就是说,为元素指定的任何内边距和边框都将在已设定的宽度和高度内进行绘制。 // 通过从已设定的宽度和高度分别减去边框和内边距才能得到内容的宽度和高度。 // inherit 规定应从父元素继承 box-sizing 属性的值。 // cui全局使用了* {box-sizing: ''} // 由于.layui-layer-page .layui-layer-content在cui.css中设置了padding,因此不能减去padding,官方的.layui-layer-content // 的padding是0,因此没有问题 var paddingHeight = contElem.css('box-sizing') === 'border-box' ? 0 : parseFloat(contElem.css('padding-top')) + parseFloat(contElem.css('padding-bottom')); contElem.css({ height: parseFloat(options.height) - titHeight - btnHeight - paddingHeight }); } }; //最小化 layer.min = function(index, options) { var layero = $('#' + doms[0] + index), titHeight = layero.find(doms[1]).outerHeight() || 0, left = layero.attr('minLeft') || (181 * ready.minIndex) + 'px', position = layero.css('position'); ready.record(layero); if(ready.minLeft[0]) { left = ready.minLeft[0]; ready.minLeft.shift(); } layero.attr('position', position); layer.style(index, { width: 180, height: titHeight, left: left, top: win.height() - titHeight, position: 'fixed', overflow: 'hidden' }, true); layero.find('.layui-layer-min').hide(); layero.attr('type') === 'page' && layero.find(doms[4]).hide(); ready.rescollbar(index); if(!layero.attr('minLeft')) { ready.minIndex++; } layero.attr('minLeft', left); }; //还原 layer.restore = function(index) { var layero = $('#' + doms[0] + index), area = layero.attr('area').split(','); var type = layero.attr('type'); layer.style(index, { width: parseFloat(area[0]), height: parseFloat(area[1]), top: parseFloat(area[2]), left: parseFloat(area[3]), position: layero.attr('position'), overflow: 'visible' }, true); layero.find('.layui-layer-max').removeClass('layui-layer-maxmin'); layero.find('.layui-layer-min').show(); layero.attr('type') === 'page' && layero.find(doms[4]).show(); ready.rescollbar(index); }; //全屏 layer.full = function(index) { var layero = $('#' + doms[0] + index), timer; ready.record(layero); if(!doms.html.attr('layer-full')) { doms.html.css('overflow', 'hidden').attr('layer-full', index); } clearTimeout(timer); timer = setTimeout(function() { var isfix = layero.css('position') === 'fixed'; layer.style(index, { top: isfix ? 0 : win.scrollTop(), left: isfix ? 0 : win.scrollLeft(), width: win.width(), height: win.height() }, true); layero.find('.layui-layer-min').hide(); }, 100); }; //改变title layer.title = function(name, index) { var title = $('#' + doms[0] + (index || layer.index)).find(doms[1]); title.html(name); }; //关闭layer总方法 layer.close = function(index) { var layero = $('#' + doms[0] + index), type = layero.attr('type'), closeAnim = 'layer-anim-close'; if(!layero[0]) return; var WRAP = 'layui-layer-wrap', remove = function() { if(type === ready.type[1] && layero.attr('conType') === 'object') { layero.children(':not(.' + doms[5] + ')').remove(); var wrap = layero.find('.' + WRAP); for(var i = 0; i < 2; i++) { wrap.unwrap(); } wrap.css('display', wrap.data('display')).removeClass(WRAP); } else { //低版本IE 回收 iframe if(type === ready.type[2]) { try { var iframe = $('#' + doms[4] + index)[0]; iframe.contentWindow.document.write(''); iframe.contentWindow.close(); layero.find('.' + doms[5])[0].removeChild(iframe); } catch(e) {} } layero[0].innerHTML = ''; layero.remove(); } typeof ready.end[index] === 'function' && ready.end[index](); delete ready.end[index]; }; if(layero.data('isOutAnim')) { layero.addClass(closeAnim); } $('#layui-layer-moves, #layui-layer-shade' + index).remove(); layer.ie == 6 && ready.reselect(); ready.rescollbar(index); if(layero.attr('minLeft')) { ready.minIndex--; ready.minLeft.push(layero.attr('minLeft')); } if((layer.ie && layer.ie < 10) || !layero.data('isOutAnim')) { remove() } else { // setTimeout(function(){ // remove(); // }, 200); remove(); } }; //关闭所有层 layer.closeAll = function(type) { $.each($('.' + doms[0]), function() { var othis = $(this); var is = type ? (othis.attr('type') === type) : 1; is && layer.close(othis.attr('times')); is = null; }); }; /** 拓展模块,layui开始合并在一起 */ var cache = layer.cache || {}, skin = function(type) { return(cache.skin ? (' ' + cache.skin + ' ' + cache.skin + '-' + type) : ''); }; //仿系统prompt layer.prompt = function(options, yes) { var style = ''; options = options || {}; if(typeof options === 'function') yes = options; if(options.area) { var area = options.area; style = 'style="width: ' + area[0] + '; height: ' + area[1] + ';"'; delete options.area; } var prompt, content = options.formType == 2 ? '' : function() { return ''; }(); var success = options.success; delete options.success; return layer.open($.extend({ type: 1, btn: ['确定', '取消'], content: content, skin: 'layui-layer-prompt' + skin('prompt'), maxWidth: win.width(), success: function(layero) { prompt = layero.find('.layui-layer-input'); prompt.focus(); typeof success === 'function' && success(layero); }, resize: false, yes: function(index) { var value = prompt.val(); if(value === '') { prompt.focus(); } else if(value.length > (options.maxlength || 500)) { layer.tips('最多输入' + (options.maxlength || 500) + '个字数', prompt, { tips: 1 }); } else { yes && yes(value, index, prompt); } } }, options)); }; //tab层 layer.tab = function(options) { options = options || {}; var tab = options.tab || {}, success = options.success; delete options.success; return layer.open($.extend({ type: 1, skin: 'layui-layer-tab' + skin('tab'), resize: false, title: function() { var len = tab.length, ii = 1, str = ''; if(len > 0) { str = '' + tab[0].title + ''; for(; ii < len; ii++) { str += '' + tab[ii].title + ''; } } return str; }(), content: '', success: function(layero) { var btn = layero.find('.layui-layer-title').children(); var main = layero.find('.layui-layer-tabmain').children(); btn.on('mousedown', function(e) { e.stopPropagation ? e.stopPropagation() : e.cancelBubble = true; var othis = $(this), index = othis.index(); othis.addClass('layui-layer-tabnow').siblings().removeClass('layui-layer-tabnow'); main.eq(index).show().siblings().hide(); typeof options.change === 'function' && options.change(index); }); typeof success === 'function' && success(layero); } }, options)); }; //相册层 layer.photos = function(options, loop, key) { var dict = {}; options = options || {}; if(!options.photos) return; var type = options.photos.constructor === Object; var photos = type ? options.photos : {}, data = photos.data || []; var start = photos.start || 0; dict.imgIndex = (start | 0) + 1; options.img = options.img || 'img'; var success = options.success; delete options.success; if(!type) { //页面直接获取 var parent = $(options.photos), pushData = function() { data = []; parent.find(options.img).each(function(index) { var othis = $(this); othis.attr('layer-index', index); data.push({ alt: othis.attr('alt'), pid: othis.attr('layer-pid'), src: othis.attr('layer-src') || othis.attr('src'), thumb: othis.attr('src') }); }) }; pushData(); if(data.length === 0) return; loop || parent.on('click', options.img, function() { var othis = $(this), index = othis.attr('layer-index'); layer.photos($.extend(options, { photos: { start: index, data: data, tab: options.tab }, full: options.full }), true); pushData(); }) //不直接弹出 if(!loop) return; } else if(data.length === 0) { return layer.msg('没有图片'); } //上一张 dict.imgprev = function(key) { dict.imgIndex--; if(dict.imgIndex < 1) { dict.imgIndex = data.length; } dict.tabimg(key); }; //下一张 dict.imgnext = function(key, errorMsg) { dict.imgIndex++; if(dict.imgIndex > data.length) { dict.imgIndex = 1; if(errorMsg) { return; } } dict.tabimg(key) }; //方向键 dict.keyup = function(event) { if(!dict.end) { var code = event.keyCode; event.preventDefault(); if(code === 37) { dict.imgprev(true); } else if(code === 39) { dict.imgnext(true); } else if(code === 27) { layer.close(dict.index); } } }; //切换 dict.tabimg = function(key) { if(data.length <= 1) return; photos.start = dict.imgIndex - 1; layer.close(dict.index); setTimeout(function() { layer.photos(options, true, key); }, 200); return layer.photos(options, true, key); }; //一些动作 dict.event = function() { dict.bigimg.hover(function() { dict.imgsee.show(); }, function() { dict.imgsee.hide(); }); dict.bigimg.find('.layui-layer-imgprev').on('click', function(event) { event.preventDefault(); dict.imgprev(); }); dict.bigimg.find('.layui-layer-imgnext').on('click', function(event) { event.preventDefault(); dict.imgnext(); }); $(document).on('keyup', dict.keyup); }; //图片预加载 function loadImage(url, callback, error) { var img = new Image(); img.src = url; if(img.complete) { return callback(img); } img.onload = function() { img.onload = null; callback(img); }; img.onerror = function(e) { img.onerror = null; error(e); }; } dict.loadi = layer.load(1, { shade: 'shade' in options ? false : 0.9, scrollbar: false }); loadImage(data[start].src, function(img) { layer.close(dict.loadi); dict.index = layer.open($.extend({ type: 1, id: 'layui-layer-photos', area: function() { var imgarea = [img.width, img.height]; var winarea = [$(window).width() - 100, $(window).height() - 100]; //如果 实际图片的宽或者高比 屏幕大(那么进行缩放) if(!options.full && (imgarea[0] > winarea[0] || imgarea[1] > winarea[1])) { var wh = [imgarea[0] / winarea[0], imgarea[1] / winarea[1]]; //取宽度缩放比例、高度缩放比例 if(wh[0] > wh[1]) { //取缩放比例最大的进行缩放 imgarea[0] = imgarea[0] / wh[0]; imgarea[1] = imgarea[1] / wh[0]; } else if(wh[0] < wh[1]) { imgarea[0] = imgarea[0] / wh[1]; imgarea[1] = imgarea[1] / wh[1]; } } return [imgarea[0] + 'px', imgarea[1] + 'px']; }(), title: false, shade: 0.9, shadeClose: true, closeBtn: false, move: '.layui-layer-phimg img', moveType: 1, scrollbar: false, moveOut: true, //anim: Math.random()*5|0, isOutAnim: false, skin: 'layui-layer-photos' + skin('photos'), content: '
' + '' + (data[start].alt || '') + '' + '
' + (data.length > 1 ? '' : '') + '
' + (data[start].alt || '') + '' + dict.imgIndex + '/' + data.length + '
' + '
' + '
', success: function(layero, index) { dict.bigimg = layero.find('.layui-layer-phimg'); dict.imgsee = layero.find('.layui-layer-imguide,.layui-layer-imgbar'); dict.event(layero); options.tab && options.tab(data[start], layero); typeof success === 'function' && success(layero); }, end: function() { dict.end = true; $(document).off('keyup', dict.keyup); } }, options)); }, function() { layer.close(dict.loadi); layer.msg('当前图片地址异常
是否继续查看下一张?', { time: 30000, btn: ['下一张', '不看了'], yes: function() { data.length > 1 && dict.imgnext(true, true); } }); }); }; //主入口 ready.run = function(_$) { var $ = _$; win = $(window); doms.html = $('html'); // comment by clu on 2018-11-13 10:34:26 layer.open方法的主入口 layer.open = function(settings) { var o = new LayerClass(settings); // comment by clu on 2018-11-13 10:33:09 弹窗增加自动的日历控件渲染 var layer = $('#layui-layer' + o.index); // 日期组件自动渲染 var $Calendar = layer.find('[cuiCalendar]'); $Calendar.cuiCalendar({ container: layer }); return o.index; }; }; //加载方式 // window.layui && layui.define ? ( // layer.ready() // ,layui.define('jquery', function(exports){ //layui加载 // layer.path = layui.cache.dir; // ready.run(layui.jquery); // //暴露模块 // window.layer = layer; // exports('layer', layer); // }) // ) : ( // (typeof define === 'function' && define.amd) ? define(['jquery'], function(){ //requirejs加载 // ready.run(window.jQuery); // return layer; // }) : function(){ //普通script标签加载 // ready.run(window.jQuery); // layer.ready(); // }() // ); ready.run(window.jQuery); return layer; })(window); }, {}]; var cuiLodashImpl = [function(require, module, exports) { (function(global) { /** * @license * lodash 3.10.1 (Custom Build) lodash.com/license | Underscore.js 1.8.3 underscorejs.org/LICENSE * Build: `lodash modern -o ./lodash.js` */ ; (function() { function n(n, t) { if(n !== t) { var r = null === n, e = n === w, u = n === n, o = null === t, i = t === w, f = t === t; if(n > t && !o || !u || r && !i && f || e && f) return 1; if(n < t && !r || !f || o && !e && u || i && u) return -1 } return 0 } function t(n, t, r) { for(var e = n.length, u = r ? e : -1; r ? u-- : ++u < e;) if(t(n[u], u, n)) return u; return -1 } /** * findIndex * @param arr * @param item * @param startIndex * @param predicate * @return {*} */ function r(arr, item, startIndex, predicate) { predicate = predicate || function (o1, o2) { return o1 === o2; }; if(item !== item) return p(arr, startIndex); startIndex -= 1; for(var e = arr.length; ++startIndex < e;) // if(arr[startIndex] === item) if (predicate(arr[startIndex], item)) return startIndex; return -1 } function e(n) { return typeof n == "function" || false } function u(n) { return null == n ? "" : n + "" } function o(n, t) { for(var r = -1, e = n.length; ++r < e && -1 < t.indexOf(n.charAt(r));) ; return r } function i(n, t) { for(var r = n.length; r-- && -1 < t.indexOf(n.charAt(r));) ; return r } function f(t, r) { return n(t.a, r.a) || t.b - r.b } function a(n) { return Nn[n] } function c(n) { return Tn[n] } function l(n, t, r) { return t ? n = Bn[n] : r && (n = Dn[n]), "\\" + n } function s(n) { return "\\" + Dn[n] } function p(n, t, r) { var e = n.length; for(t += r ? 0 : -1; r ? t-- : ++t < e;) { var u = n[t]; if(u !== u) return t } return -1 } function h(n) { return !!n && typeof n == "object" } function _(n) { return 160 >= n && 9 <= n && 13 >= n || 32 == n || 160 == n || 5760 == n || 6158 == n || 8192 <= n && (8202 >= n || 8232 == n || 8233 == n || 8239 == n || 8287 == n || 12288 == n || 65279 == n); } function v(n, t) { for(var r = -1, e = n.length, u = -1, o = []; ++r < e;) n[r] === t && (n[r] = z, o[++u] = r); return o } function g(n) { for(var t = -1, r = n.length; ++t < r && _(n.charCodeAt(t));) ; return t } function y(n) { for(var t = n.length; t-- && _(n.charCodeAt(t));) ; return t } function d(n) { return Ln[n] } function m(_) { function Nn(n) { if(h(n) && !(Oo(n) || n instanceof zn)) { if(n instanceof Ln) return n; if(nu.call(n, "__chain__") && nu.call(n, "__wrapped__")) return Mr(n) } return new Ln(n) } function Tn() {} function Ln(n, t, r) { this.__wrapped__ = n, this.__actions__ = r || [], this.__chain__ = !!t } function zn(n) { this.__wrapped__ = n, this.__actions__ = [], this.__dir__ = 1, this.__filtered__ = false, this.__iteratees__ = [], this.__takeCount__ = Ru, this.__views__ = [] } function Bn() { this.__data__ = {} } function Dn(n) { var t = n ? n.length : 0; for(this.data = { hash: gu(null), set: new lu }; t--;) this.push(n[t]) } function Mn(n, t) { var r = n.data; return(typeof t == "string" || ge(t) ? r.set.has(t) : r.hash[t]) ? 0 : -1 } function qn(n, t) { var r = -1, e = n.length; for(t || (t = Be(e)); ++r < e;) t[r] = n[r]; return t } function Pn(n, t) { for(var r = -1, e = n.length; ++r < e && false !== t(n[r], r, n);) ; return n } function Kn(n, t) { for(var r = -1, e = n.length; ++r < e;) if(!t(n[r], r, n)) return false; return true } function Vn(n, t) { for(var r = -1, e = n.length, u = -1, o = []; ++r < e;) { var i = n[r]; t(i, r, n) && (o[++u] = i) } return o } function Gn(n, t) { for(var r = -1, e = n.length, u = Be(e); ++r < e;) u[r] = t(n[r], r, n); return u } function mergeArray(arr, arr2) { for(var index = -1, len2 = arr2.length, len1 = arr.length; ++index < len2;) arr[len1 + index] = arr2[index]; return arr } function Xn(n, t, r, e) { var u = -1, o = n.length; for(e && o && (r = n[++u]); ++u < o;) r = t(r, n[u], u, n); return r } function Hn(n, t) { for(var r = -1, e = n.length; ++r < e;) if(t(n[r], r, n)) return true; return false } function Qn(n, t, r, e) { return n !== w && nu.call(e, r) ? n : t } function nt(n, t, r) { for(var e = -1, u = zo(t), o = u.length; ++e < o;) { var i = u[e], f = n[i], a = r(f, t[i], i, n, t); (a === a ? a === f : f !== f) && (f !== w || i in n) || (n[i] = a) } return n } function tt(n, t) { return null == t ? n : et(t, zo(t), n) } function rt(n, t) { for(var r = -1, e = null == n, u = !e && isLengthAttrValid(n), o = u ? n.length : 0, i = t.length, f = Be(i); ++r < i;) { var a = t[r]; f[r] = u ? Cr(a, o) ? n[a] : w : e ? w : n[a] } return f } function et(n, t, r) { r || (r = {}); for(var e = -1, u = t.length; ++e < u;) { var o = t[e]; r[o] = n[o] } return r } function ut(n, t, r) { var e = typeof n; return "function" == e ? t === w ? n : Bt(n, t, r) : null == n ? Fe : "object" == e ? bt(n) : t === w ? ze(n) : xt(n, t) } function ot(n, t, r, e, u, o, i) { var f; if(r && (f = u ? r(n, e, u) : r(n)), f !== w) return f; if(!ge(n)) return n; if(e = Oo(n)) { if(f = kr(n), !t) return qn(n, f) } else { var a = ru.call(n), c = a == K; if(a != Z && a != B && (!c || u)) return Fn[a] ? Rr(n, a, t) : u ? n : {}; if(f = Ir(c ? {} : n), !t) return tt(f, n) } for(o || (o = []), i || (i = []), u = o.length; u--;) if(o[u] == n) return i[u]; return o.push(n), i.push(f), (e ? Pn : _t)(n, function(e, u) { f[u] = ot(e, t, r, u, n, o, i) }), f } function it(n, t, r) { if(typeof n != "function") throw new Ge(L); return su(function() { n.apply(w, r) }, t) } function subtract(arr, subWhatArr, predicate) { predicate = predicate || function (o1, o2) { return o1 === o2; }; var len = arr ? arr.length : 0, result = []; if(!len) return result; var index = -1, i = xr(), f = i === r, a = f && subWhatArr.length >= F && gu && lu ? new Dn(subWhatArr) : null, c = subWhatArr.length; a && (i = Mn, f = false, subWhatArr = a); n: for(; ++index < len;) if(a = arr[index], f && predicate(a, a)/*a === a*/) { for(var l = c; l--;) if(predicate(subWhatArr[l], a) /*predicate() === a*/) continue n; result.push(a) } else 0 > i(subWhatArr, a, 0, predicate) && result.push(a); return result } function at(n, t) { var r = true; return Su(n, function(n, e, u) { return r = !!t(n, e, u) }), r } function ct(n, t, r, e) { var u = e, o = u; return Su(n, function(n, i, f) { i = +t(n, i, f), (r(i, u) || i === e && i === o) && (u = i, o = n) }), o } function lt(n, t) { var r = []; return Su(n, function(n, e, u) { t(n, e, u) && r.push(n) }), r } function st(n, t, r, e) { var u; return r(n, function(n, r, o) { return t(n, r, o) ? (u = e ? r : n, false) : void 0 }), u } function pt(n, t, r, e) { e || (e = []); for(var u = -1, o = n.length; ++u < o;) { var i = n[u]; h(i) && isLengthAttrValid(i) && (r || Oo(i) || pe(i)) ? t ? pt(i, t, r, e) : mergeArray(e, i) : r || (e[e.length] = i) } return e } function ht(n, t) { Nu(n, t, Re) } function _t(n, t) { return Nu(n, t, zo) } function vt(n, t) { return Tu(n, t, zo) } function gt(n, t) { for(var r = -1, e = t.length, u = -1, o = []; ++r < e;) { var i = t[r]; ve(n[i]) && (o[++u] = i) } return o } function yt(n, t, r) { if(null != n) { r !== w && r in Br(n) && (t = [r]), r = 0; for(var e = t.length; null != n && r < e;) n = n[t[r++]]; return r && r == e ? n : w } } function dt(n, t, r, e, u, o) { if(n === t) n = true; else if(null == n || null == t || !ge(n) && !h(t)) n = n !== n && t !== t; else n: { var i = dt, f = Oo(n), a = Oo(t), c = D, l = D; f || (c = ru.call(n), c == B ? c = Z : c != Z && (f = xe(n))), a || (l = ru.call(t), l == B ? l = Z : l != Z && xe(t)); var s = c == Z, a = l == Z, l = c == l; if(!l || f || s) { if(!e && (c = s && nu.call(n, "__wrapped__"), a = a && nu.call(t, "__wrapped__"), c || a)) { n = i(c ? n.value() : n, a ? t.value() : t, r, e, u, o); break n } if(l) { for(u || (u = []), o || (o = []), c = u.length; c--;) if(u[c] == n) { n = o[c] == t; break n } u.push(n), o.push(t), n = (f ? yr : mr)(n, t, i, r, e, u, o), u.pop(), o.pop() } else n = false } else n = dr(n, t, c) } return n } function mt(n, t, r) { var e = t.length, u = e, o = !r; if(null == n) return !u; for(n = Br(n); e--;) { var i = t[e]; if(o && i[2] ? i[1] !== n[i[0]] : !(i[0] in n)) return false } for(; ++e < u;) { var i = t[e], f = i[0], a = n[f], c = i[1]; if(o && i[2]) { if(a === w && !(f in n)) return false } else if(i = r ? r(a, c, f) : w, i === w ? !dt(c, a, r, true) : !i) return false } return true } function wt(n, t) { var r = -1, e = isLengthAttrValid(n) ? Be(n.length) : []; return Su(n, function(n, u, o) { e[++r] = t(n, u, o) }), e } function bt(n) { var t = Ar(n); if(1 == t.length && t[0][2]) { var r = t[0][0], e = t[0][1]; return function(n) { return null == n ? false : n[r] === e && (e !== w || r in Br(n)) } } return function(n) { return mt(n, t) } } function xt(n, t) { var r = Oo(n), e = Wr(n) && t === t && !ge(t), u = n + ""; return n = Dr(n), function(o) { if(null == o) return false; var i = u; if(o = Br(o), !(!r && e || i in o)) { if(o = 1 == n.length ? o : yt(o, Et(n, 0, -1)), null == o) return false; i = Zr(n), o = Br(o) } return o[i] === t ? t !== w || i in o : dt(t, o[i], w, true) } } function At(n, t, r, e, u) { if(!ge(n)) return n; var o = isLengthAttrValid(t) && (Oo(t) || xe(t)), i = o ? w : zo(t); return Pn(i || t, function(f, a) { if(i && (a = f, f = t[a]), h(f)) { e || (e = []), u || (u = []); n: { for(var c = a, l = e, s = u, p = l.length, _ = t[c]; p--;) if(l[p] == _) { n[c] = s[p]; break n } var p = n[c], v = r ? r(p, _, c, n, t) : w, g = v === w; g && (v = _, isLengthAttrValid(_) && (Oo(_) || xe(_)) ? v = Oo(p) ? p : isLengthAttrValid(p) ? qn(p) : [] : me(_) || pe(_) ? v = pe(p) ? ke(p) : me(p) ? p : {} : g = false), l.push(_), s.push(v), g ? n[c] = At(v, _, r, l, s) : (v === v ? v !== p : p === p) && (n[c] = v) } } else c = n[a], l = r ? r(c, f, a, n, t) : w, (s = l === w) && (l = f), l === w && (!o || a in n) || !s && (l === l ? l === c : c !== c) || (n[a] = l); }), n } function attrGetter(n) { return function(t) { return null == t ? w : t[n] } } function kt(n) { var t = n + ""; return n = Dr(n), function(r) { return yt(r, n, t) } } function It(n, t) { for(var r = n ? t.length : 0; r--;) { var e = t[r]; if(e != u && Cr(e)) { var u = e; pu.call(n, e, 1) } } } function Rt(n, t) { return n + yu(ku() * (t - n + 1)) } function Ot(n, t, r, e, u) { return u(n, function(n, u, o) { r = e ? (e = false, n) : t(r, n, u, o) }), r } function Et(n, t, r) { var e = -1, u = n.length; for(t = null == t ? 0 : +t || 0, 0 > t && (t = -t > u ? 0 : u + t), r = r === w || r > u ? u : +r || 0, 0 > r && (r += u), u = t > r ? 0 : r - t >>> 0, t >>>= 0, r = Be(u); ++e < u;) r[e] = n[e + t]; return r } function Ct(n, t) { var r; return Su(n, function(n, e, u) { return r = t(n, e, u), !r }), !!r } function Ut(n, t) { var r = n.length; for(n.sort(t); r--;) n[r] = n[r].c; return n } function Wt(t, r, e) { var u = wr(), o = -1; return r = Gn(r, function(n) { return u(n) }), t = wt(t, function(n) { return { a: Gn(r, function(t) { return t(n) }), b: ++o, c: n } }), Ut(t, function(t, r) { var u; n: { for(var o = -1, i = t.a, f = r.a, a = i.length, c = e.length; ++o < a;) if(u = n(i[o], f[o])) { if(o >= c) break n; o = e[o], u *= "asc" === o || true === o ? 1 : -1; break n } u = t.b - r.b } return u }) } function $t(n, t) { var r = 0; return Su(n, function(n, e, u) { r += +t(n, e, u) || 0 }), r } function St(n, t) { var e = -1, u = xr(), o = n.length, i = u === r, f = i && o >= F, a = f && gu && lu ? new Dn(void 0) : null, c = []; a ? (u = Mn, i = false) : (f = false, a = t ? [] : c); n: for(; ++e < o;) { var l = n[e], s = t ? t(l, e, n) : l; if(i && l === l) { for(var p = a.length; p--;) if(a[p] === s) continue n; t && a.push(s), c.push(l) } else 0 > u(a, s, 0) && ((t || f) && a.push(s), c.push(l)) } return c } function Ft(n, t) { for(var r = -1, e = t.length, u = Be(e); ++r < e;) u[r] = n[t[r]]; return u } function Nt(n, t, r, e) { for(var u = n.length, o = e ? u : -1; (e ? o-- : ++o < u) && t(n[o], o, n);) ; return r ? Et(n, e ? 0 : o, e ? o + 1 : u) : Et(n, e ? o + 1 : 0, e ? u : o) } function Tt(n, t) { var r = n; r instanceof zn && (r = r.value()); for(var e = -1, u = t.length; ++e < u;) var o = t[e], r = o.func.apply(o.thisArg, mergeArray([r], o.args)); return r } function Lt(n, t, r) { var e = 0, u = n ? n.length : e; if(typeof t == "number" && t === t && u <= Eu) { for(; e < u;) { var o = e + u >>> 1, i = n[o]; (r ? i <= t : i < t) && null !== i ? e = o + 1 : u = o } return u } return zt(n, t, Fe, r) } function zt(n, t, r, e) { t = r(t); for(var u = 0, o = n ? n.length : 0, i = t !== t, f = null === t, a = t === w; u < o;) { var c = yu((u + o) / 2), l = r(n[c]), s = l !== w, p = l === l; (i ? p || e : f ? p && s && (e || null != l) : a ? p && (e || s) : null == l ? 0 : e ? l <= t : l < t) ? u = c + 1: o = c } return xu(o, Ou) } function Bt(n, t, r) { if(typeof n != "function") return Fe; if(t === w) return n; switch(r) { case 1: return function(r) { return n.call(t, r) }; case 3: return function(r, e, u) { return n.call(t, r, e, u) }; case 4: return function(r, e, u, o) { return n.call(t, r, e, u, o) }; case 5: return function(r, e, u, o, i) { return n.call(t, r, e, u, o, i) } } return function() { return n.apply(t, arguments) } } function Dt(n) { var t = new ou(n.byteLength); return new hu(t).set(new hu(n)), t } function Mt(n, t, r) { for(var e = r.length, u = -1, o = bu(n.length - e, 0), i = -1, f = t.length, a = Be(f + o); ++i < f;) a[i] = t[i]; for(; ++u < e;) a[r[u]] = n[u]; for(; o--;) a[i++] = n[u++]; return a } function qt(n, t, r) { for(var e = -1, u = r.length, o = -1, i = bu(n.length - u, 0), f = -1, a = t.length, c = Be(i + a); ++o < i;) c[o] = n[o]; for(i = o; ++f < a;) c[i + f] = t[f]; for(; ++e < u;) c[i + r[e]] = n[o++]; return c } function Pt(n, t) { return function(r, e, u) { var o = t ? t() : {}; if(e = wr(e, u, 3), Oo(r)) { u = -1; for(var i = r.length; ++u < i;) { var f = r[u]; n(o, f, e(f, u, r), r) } } else Su(r, function(t, r, u) { n(o, t, e(t, r, u), u) }); return o } } function Kt(n) { return le(function(t, r) { var e = -1, u = null == t ? 0 : r.length, o = 2 < u ? r[u - 2] : w, i = 2 < u ? r[2] : w, f = 1 < u ? r[u - 1] : w; for(typeof o == "function" ? (o = Bt(o, f, 5), u -= 2) : (o = typeof f == "function" ? f : w, u -= o ? 1 : 0), i && Ur(r[0], r[1], i) && (o = 3 > u ? w : o, u = 1); ++e < u;) (i = r[e]) && n(t, i, o); return t }) } function Vt(n, t) { return function(r, e) { var u = r ? lengthGetter(r) : 0; if(!isValidNumber(u)) return n(r, e); for(var o = t ? u : -1, i = Br(r); (t ? o-- : ++o < u) && false !== e(i[o], o, i);) ; return r } } function Zt(n) { return function(t, r, e) { var u = Br(t); e = e(t); for(var o = e.length, i = n ? o : -1; n ? i-- : ++i < o;) { var f = e[i]; if(false === r(u[f], f, u)) break } return t } } function Yt(n, t) { function r() { return(this && this !== Zn && this instanceof r ? e : n).apply(t, arguments) } var e = Jt(n); return r } function Gt(n) { return function(t) { var r = -1; t = $e(Ce(t)); for(var e = t.length, u = ""; ++r < e;) u = n(u, t[r], r); return u } } function Jt(n) { return function() { var t = arguments; switch(t.length) { case 0: return new n; case 1: return new n(t[0]); case 2: return new n(t[0], t[1]); case 3: return new n(t[0], t[1], t[2]); case 4: return new n(t[0], t[1], t[2], t[3]); case 5: return new n(t[0], t[1], t[2], t[3], t[4]); case 6: return new n(t[0], t[1], t[2], t[3], t[4], t[5]); case 7: return new n(t[0], t[1], t[2], t[3], t[4], t[5], t[6]) } var r = $u(n.prototype), t = n.apply(r, t); return ge(t) ? t : r } } function Xt(n) { function t(r, e, u) { return u && Ur(r, e, u) && (e = w), r = gr(r, n, w, w, w, w, w, e), r.placeholder = t.placeholder, r } return t } function Ht(n, t) { return le(function(r) { var e = r[0]; return null == e ? e : (r.push(t), n.apply(w, r)) }) } function Qt(n, t) { return function(r, e, u) { if(u && Ur(r, e, u) && (e = w), e = wr(e, u, 3), 1 == e.length) { u = r = Oo(r) ? r : zr(r); for(var o = e, i = -1, f = u.length, a = t, c = a; ++i < f;) { var l = u[i], s = +o(l); n(s, a) && (a = s, c = l) } if(u = c, !r.length || u !== t) return u } return ct(r, e, n, t) } } function nr(n, r) { return function(e, u, o) { return u = wr(u, o, 3), Oo(e) ? (u = t(e, u, r), -1 < u ? e[u] : w) : st(e, u, n) } } function tr(n) { return function(r, e, u) { return r && r.length ? (e = wr(e, u, 3), t(r, e, n)) : -1 } } function rr(n) { return function(t, r, e) { return r = wr(r, e, 3), st(t, r, n, true) } } function er(n) { return function() { for(var t, r = arguments.length, e = n ? r : -1, u = 0, o = Be(r); n ? e-- : ++e < r;) { var i = o[u++] = arguments[e]; if(typeof i != "function") throw new Ge(L); !t && Ln.prototype.thru && "wrapper" == br(i) && (t = new Ln([], true)) } for(e = t ? -1 : r; ++e < r;) { var i = o[e], u = br(i), f = "wrapper" == u ? zu(i) : w; t = f && $r(f[0]) && f[1] == (E | k | R | C) && !f[4].length && 1 == f[9] ? t[br(f[0])].apply(t, f[3]) : 1 == i.length && $r(i) ? t[u]() : t.thru(i) } return function() { var n = arguments, e = n[0]; if(t && 1 == n.length && Oo(e) && e.length >= F) return t.plant(e).value(); for(var u = 0, n = r ? o[u].apply(this, n) : e; ++u < r;) n = o[u].call(this, n); return n } } } function ur(n, t) { return function(r, e, u) { return typeof e == "function" && u === w && Oo(r) ? n(r, e) : t(r, Bt(e, u, 3)) } } function or(n) { return function(t, r, e) { return(typeof r != "function" || e !== w) && (r = Bt(r, e, 3)), n(t, r, Re) } } function ir(n) { return function(t, r, e) { return(typeof r != "function" || e !== w) && (r = Bt(r, e, 3)), n(t, r) } } function fr(n) { return function(t, r, e) { var u = {}; return r = wr(r, e, 3), _t(t, function(t, e, o) { o = r(t, e, o), e = n ? o : e, t = n ? t : o, u[e] = t }), u } } function ar(n) { return function(t, r, e) { return t = u(t), (n ? t : "") + pr(t, r, e) + (n ? "" : t) } } function cr(n) { var t = le(function(r, e) { var u = v(e, t.placeholder); return gr(r, n, w, e, u) }); return t } function lr(n, t) { return function(r, e, u, o) { var i = 3 > arguments.length; return typeof e == "function" && o === w && Oo(r) ? n(r, e, u, i) : Ot(r, wr(e, o, 4), u, i, t) } } function sr(n, t, r, e, u, o, i, f, a, c) { function l() { for(var m = arguments.length, b = m, j = Be(m); b--;) j[b] = arguments[b]; if(e && (j = Mt(j, e, u)), o && (j = qt(j, o, i)), _ || y) { var b = l.placeholder, k = v(j, b), m = m - k.length; if(m < c) { var I = f ? qn(f) : w, m = bu(c - m, 0), E = _ ? k : w, k = _ ? w : k, C = _ ? j : w, j = _ ? w : j; return t |= _ ? R : O, t &= ~(_ ? O : R), g || (t &= ~(x | A)), j = [n, t, r, C, E, j, k, I, a, m], I = sr.apply(w, j), $r(n) && Du(I, j), I.placeholder = b, I } } if(b = p ? r : this, I = h ? b[n] : n, f) for(m = j.length, E = xu(f.length, m), k = qn(j); E--;) C = f[E], j[E] = Cr(C, m) ? k[C] : w; return s && a < j.length && (j.length = a), this && this !== Zn && this instanceof l && (I = d || Jt(n)), I.apply(b, j) } var s = t & E, p = t & x, h = t & A, _ = t & k, g = t & j, y = t & I, d = h ? w : Jt(n); return l } function pr(n, t, r) { return n = n.length, t = +t, n < t && mu(t) ? (t -= n, r = null == r ? " " : r + "", Ue(r, vu(t / r.length)).slice(0, t)) : "" } function hr(n, t, r, e) { function u() { for(var t = -1, f = arguments.length, a = -1, c = e.length, l = Be(c + f); ++a < c;) l[a] = e[a]; for(; f--;) l[a++] = arguments[++t]; return(this && this !== Zn && this instanceof u ? i : n).apply(o ? r : this, l) } var o = t & x, i = Jt(n); return u } function _r(n) { var t = Pe[n]; return function(n, r) { return(r = r === w ? 0 : +r || 0) ? (r = au(10, r), t(n * r) / r) : t(n) } } function vr(n) { return function(t, r, e, u) { var o = wr(e); return null == e && o === ut ? Lt(t, r, n) : zt(t, r, o(e, u, 1), n) } } function gr(n, t, r, e, u, o, i, f) { var a = t & A; if(!a && typeof n != "function") throw new Ge(L); var c = e ? e.length : 0; if(c || (t &= ~(R | O), e = u = w), c -= u ? u.length : 0, t & O) { var l = e, s = u; e = u = w } var p = a ? w : zu(n); return r = [n, t, r, e, u, l, s, o, i, f], p && (e = r[1], t = p[1], f = e | t, u = t == E && e == k || t == E && e == C && r[7].length <= p[8] || t == (E | C) && e == k, (f < E || u) && (t & x && (r[2] = p[2], f |= e & x ? 0 : j), (e = p[3]) && (u = r[3], r[3] = u ? Mt(u, e, p[4]) : qn(e), r[4] = u ? v(r[3], z) : qn(p[4])), (e = p[5]) && (u = r[5], r[5] = u ? qt(u, e, p[6]) : qn(e), r[6] = u ? v(r[5], z) : qn(p[6])), (e = p[7]) && (r[7] = qn(e)), t & E && (r[8] = null == r[8] ? p[8] : xu(r[8], p[8])), null == r[9] && (r[9] = p[9]), r[0] = p[0], r[1] = f), t = r[1], f = r[9]), r[9] = null == f ? a ? 0 : n.length : bu(f - c, 0) || 0, (p ? Lu : Du)(t == x ? Yt(r[0], r[2]) : t != R && t != (x | R) || r[4].length ? sr.apply(w, r) : hr.apply(w, r), r); } function yr(n, t, r, e, u, o, i) { var f = -1, a = n.length, c = t.length; if(a != c && (!u || c <= a)) return false; for(; ++f < a;) { var l = n[f], c = t[f], s = e ? e(u ? c : l, u ? l : c, f) : w; if(s !== w) { if(s) continue; return false } if(u) { if(!Hn(t, function(n) { return l === n || r(l, n, e, u, o, i) })) return false } else if(l !== c && !r(l, c, e, u, o, i)) return false } return true } function dr(n, t, r) { switch(r) { case M: case q: return +n == +t; case P: return n.name == t.name && n.message == t.message; case V: return n != +n ? t != +t : n == +t; case Y: case G: return n == t + "" } return false } function mr(n, t, r, e, u, o, i) { var f = zo(n), a = f.length, c = zo(t).length; if(a != c && !u) return false; for(c = a; c--;) { var l = f[c]; if(!(u ? l in t : nu.call(t, l))) return false } for(var s = u; ++c < a;) { var l = f[c], p = n[l], h = t[l], _ = e ? e(u ? h : p, u ? p : h, l) : w; if(_ === w ? !r(p, h, e, u, o, i) : !_) return false; s || (s = "constructor" == l) } return s || (r = n.constructor, e = t.constructor, !(r != e && "constructor" in n && "constructor" in t) || typeof r == "function" && r instanceof r && typeof e == "function" && e instanceof e) ? true : false } function wr(n, t, r) { var e = Nn.callback || iterateeImpl, e = e === iterateeImpl ? ut : e; return r ? e(n, t, r) : e } function br(n) { for(var t = n.name + "", r = Wu[t], e = r ? r.length : 0; e--;) { var u = r[e], o = u.func; if(null == o || o == n) return u.name } return t } function xr(n, t, e) { var u = Nn.indexOf || Vr, u = u === Vr ? r : u; return n ? u(n, t, e) : u } function Ar(n) { n = Oe(n); for(var t = n.length; t--;) { var r = n[t][1]; n[t][2] = r === r && !ge(r) } return n } function jr(n, t) { var r = null == n ? w : n[t]; return ye(r) ? r : w } function kr(n) { var t = n.length, r = new n.constructor(t); return t && "string" == typeof n[0] && nu.call(n, "index") && (r.index = n.index, r.input = n.input), r } function Ir(n) { return n = n.constructor, typeof n == "function" && n instanceof n || (n = Ve), new n } function Rr(n, t, r) { var e = n.constructor; switch(t) { case J: return Dt(n); case M: case q: return new e(+n); case X: case H: case Q: case nn: case tn: case rn: case en: case un: case on: return t = n.buffer, new e(r ? Dt(t) : t, n.byteOffset, n.length); case V: case G: return new e(n); case Y: var u = new e(n.source, kn.exec(n)); u.lastIndex = n.lastIndex } return u } function Or(n, t, r) { return null == n || Wr(t, n) || (t = Dr(t), n = 1 == t.length ? n : yt(n, Et(t, 0, -1)), t = Zr(t)), t = null == n ? n : n[t], null == t ? w : t.apply(n, r) } function isLengthAttrValid(n) { return null != n && isValidNumber(lengthGetter(n)); } function Cr(n, t) { return n = typeof n == "number" || On.test(n) ? +n : -1, t = null == t ? Cu : t, -1 < n && 0 == n % 1 && n < t } function Ur(n, t, r) { if(!ge(r)) return false; var e = typeof t; return("number" == e ? isLengthAttrValid(r) && Cr(t, r.length) : "string" == e && t in r) ? (t = r[t], n === n ? n === t : t !== t) : false } function Wr(n, t) { var r = typeof n; return "string" == r && dn.test(n) || "number" == r ? true : Oo(n) ? false : !yn.test(n) || null != t && n in Br(t) } function $r(n) { var t = br(n), r = Nn[t]; return typeof r == "function" && t in zn.prototype ? n === r ? true : (t = zu(r), !!t && n === t[0]) : false } function isValidNumber(n) { return typeof n == "number" && -1 < n && 0 == n % 1 && n <= Cu; } function Fr(n, t) { return n === w ? t : Eo(n, t, Fr) } function Nr(n, t) { n = Br(n); for(var r = -1, e = t.length, u = {}; ++r < e;) { var o = t[r]; o in n && (u[o] = n[o]) } return u } function Tr(n, t) { var r = {}; return ht(n, function(n, e, u) { t(n, e, u) && (r[e] = n) }), r } function Lr(n) { for(var t = Re(n), r = t.length, e = r && n.length, u = !!e && isValidNumber(e) && (Oo(n) || pe(n)), o = -1, i = []; ++o < r;) { var f = t[o]; (u && Cr(f, e) || nu.call(n, f)) && i.push(f) } return i } function zr(n) { return null == n ? [] : isLengthAttrValid(n) ? ge(n) ? n : Ve(n) : Ee(n) } function Br(n) { return ge(n) ? n : Ve(n) } function Dr(n) { if(Oo(n)) return n; var t = []; return u(n).replace(mn, function(n, r, e, u) { t.push(e ? u.replace(An, "$1") : r || n) }), t } function Mr(n) { return n instanceof zn ? n.clone() : new Ln(n.__wrapped__, n.__chain__, qn(n.__actions__)) } function qr(n, t, r) { return n && n.length ? ((r ? Ur(n, t, r) : null == t) && (t = 1), Et(n, 0 > t ? 0 : t)) : [] } function Pr(n, t, r) { var e = n ? n.length : 0; return e ? ((r ? Ur(n, t, r) : null == t) && (t = 1), t = e - (+t || 0), Et(n, 0, 0 > t ? 0 : t)) : [] } function Kr(n) { return n ? n[0] : w } function Vr(n, t, e) { var u = n ? n.length : 0; if(!u) return -1; if(typeof e == "number") e = 0 > e ? bu(u + e, 0) : e; else if(e) return e = Lt(n, t), e < u && (t === t ? t === n[e] : n[e] !== n[e]) ? e : -1; return r(n, t, e || 0) } function Zr(n) { var t = n ? n.length : 0; return t ? n[t - 1] : w } function Yr(n) { return qr(n, 1) } function Gr(n, t, e, u) { if(!n || !n.length) return []; null != t && typeof t != "boolean" && (u = e, e = Ur(n, t, u) ? w : t, t = false); var o = wr(); if((null != e || o !== ut) && (e = o(e, u, 3)), t && xr() === r) { t = e; var i; e = -1, u = n.length; for(var o = -1, f = []; ++e < u;) { var a = n[e], c = t ? t(a, e, n) : a; e && i === c || (i = c, f[++o] = a) } n = f } else n = St(n, e); return n } function Jr(n) { if(!n || !n.length) return []; var t = -1, r = 0; n = Vn(n, function(n) { return isLengthAttrValid(n) ? (r = bu(n.length, r), true) : void 0 }); for(var e = Be(r); ++t < r;) e[t] = Gn(n, attrGetter(t)); return e } function Xr(n, t, r) { return n && n.length ? (n = Jr(n), null == t ? n : (t = Bt(t, r, 4), Gn(n, function(n) { return Xn(n, t, w, true) }))) : [] } function Hr(n, t) { var r = -1, e = n ? n.length : 0, u = {}; for(!e || t || Oo(n[0]) || (t = []); ++r < e;) { var o = n[r]; t ? u[o] = t[r] : o && (u[o[0]] = o[1]) } return u } function Qr(n) { return n = Nn(n), n.__chain__ = true, n } function ne(n, t, r) { return t.call(r, n) } function te(n, t, r) { var e = Oo(n) ? Kn : at; return r && Ur(n, t, r) && (t = w), (typeof t != "function" || r !== w) && (t = wr(t, r, 3)), e(n, t) } function re(n, t, r) { var e = Oo(n) ? Vn : lt; return t = wr(t, r, 3), e(n, t) } function ee(n, t, r, e) { var u = n ? lengthGetter(n) : 0; return isValidNumber(u) || (n = Ee(n), u = n.length), r = typeof r != "number" || e && Ur(t, r, e) ? 0 : 0 > r ? bu(u + r, 0) : r || 0, typeof n == "string" || !Oo(n) && be(n) ? r <= u && -1 < n.indexOf(t, r) : !!u && -1 < xr(n, t, r) } function ue(n, t, r) { var e = Oo(n) ? Gn : wt; return t = wr(t, r, 3), e(n, t) } function oe(n, t, r) { if(r ? Ur(n, t, r) : null == t) { n = zr(n); var e = n.length; return 0 < e ? n[Rt(0, e - 1)] : w } r = -1, n = je(n); var e = n.length, u = e - 1; for(t = xu(0 > t ? 0 : +t || 0, e); ++r < t;) { var e = Rt(r, u), o = n[e]; n[e] = n[r], n[r] = o } return n.length = t, n } function ie(n, t, r) { var e = Oo(n) ? Hn : Ct; return r && Ur(n, t, r) && (t = w), (typeof t != "function" || r !== w) && (t = wr(t, r, 3)), e(n, t) } function fe(n, t) { var r; if(typeof t != "function") { if(typeof n != "function") throw new Ge(L); var e = n; n = t, t = e } return function() { return 0 < --n && (r = t.apply(this, arguments)), 1 >= n && (t = w), r } } function ae(n, t, r) { function e(t, r) { r && iu(r), a = p = h = w, t && (_ = ho(), c = n.apply(s, f), p || a || (f = s = w)) } function u() { var n = t - (ho() - l); 0 >= n || n > t ? e(h, a) : p = su(u, n) } function o() { e(g, p); } function i() { if(f = arguments, l = ho(), s = this, h = g && (p || !y), false === v) var r = y && !p; else { a || y || (_ = l); var e = v - (l - _), i = 0 >= e || e > v; i ? (a && (a = iu(a)), _ = l, c = n.apply(s, f)) : a || (a = su(o, e)) } return i && p ? p = iu(p) : p || t === v || (p = su(u, t)), r && (i = true, c = n.apply(s, f)), !i || p || a || (f = s = w), c } var f, a, c, l, s, p, h, _ = 0, v = false, g = true; if(typeof n != "function") throw new Ge(L); if(t = 0 > t ? 0 : +t || 0, true === r) var y = true, g = false; else ge(r) && (y = !!r.leading, v = "maxWait" in r && bu(+r.maxWait || 0, t), g = "trailing" in r ? !!r.trailing : g); return i.cancel = function() { p && iu(p), a && iu(a), _ = 0, a = p = h = w }, i } function ce(n, t) { function r() { var e = arguments, u = t ? t.apply(this, e) : e[0], o = r.cache; return o.has(u) ? o.get(u) : (e = n.apply(this, e), r.cache = o.set(u, e), e) } if(typeof n != "function" || t && typeof t != "function") throw new Ge(L); return r.cache = new ce.Cache, r } function le(n, t) { if(typeof n != "function") throw new Ge(L); return t = bu(t === w ? n.length - 1 : +t || 0, 0), function() { for(var r = arguments, e = -1, u = bu(r.length - t, 0), o = Be(u); ++e < u;) o[e] = r[t + e]; switch(t) { case 0: return n.call(this, o); case 1: return n.call(this, r[0], o); case 2: return n.call(this, r[0], r[1], o) } for(u = Be(t + 1), e = -1; ++e < t;) u[e] = r[e]; return u[t] = o, n.apply(this, u) } } function se(n, t) { return n > t } function pe(n) { return h(n) && isLengthAttrValid(n) && nu.call(n, "callee") && !cu.call(n, "callee") } function he(n, t, r, e) { return e = (r = typeof r == "function" ? Bt(r, e, 3) : w) ? r(n, t) : w, e === w ? dt(n, t, r) : !!e } function _e(n) { return h(n) && typeof n.message == "string" && ru.call(n) == P } function ve(n) { return ge(n) && ru.call(n) == K } function ge(n) { var t = typeof n; return !!n && ("object" == t || "function" == t) } function ye(n) { return null == n ? false : ve(n) ? uu.test(Qe.call(n)) : h(n) && Rn.test(n) } function de(n) { return typeof n == "number" || h(n) && ru.call(n) == V } function me(n) { var t; if(!h(n) || ru.call(n) != Z || pe(n) || !(nu.call(n, "constructor") || (t = n.constructor, typeof t != "function" || t instanceof t))) return false; var r; return ht(n, function(n, t) { r = t }), r === w || nu.call(n, r) } function we(n) { return ge(n) && ru.call(n) == Y } function be(n) { return typeof n == "string" || h(n) && ru.call(n) == G } function xe(n) { return h(n) && isValidNumber(n.length) && !!Sn[ru.call(n)] } function Ae(n, t) { return n < t } function je(n) { var t = n ? lengthGetter(n) : 0; return isValidNumber(t) ? t ? qn(n) : [] : Ee(n) } function ke(n) { return et(n, Re(n)) } function Ie(n) { return gt(n, Re(n)) } function Re(n) { if(null == n) return []; ge(n) || (n = Ve(n)); for(var t = n.length, t = t && isValidNumber(t) && (Oo(n) || pe(n)) && t || 0, r = n.constructor, e = -1, r = typeof r == "function" && r.prototype === n, u = Be(t), o = 0 < t; ++e < t;) u[e] = e + ""; for(var i in n) o && Cr(i, t) || "constructor" == i && (r || !nu.call(n, i)) || u.push(i); return u } function Oe(n) { n = Br(n); for(var t = -1, r = zo(n), e = r.length, u = Be(e); ++t < e;) { var o = r[t]; u[t] = [o, n[o]] } return u } function Ee(n) { return Ft(n, zo(n)) } function Ce(n) { return(n = u(n)) && n.replace(En, a).replace(xn, "") } function Ue(n, t) { var r = ""; if(n = u(n), t = +t, 1 > t || !n || !mu(t)) return r; do t % 2 && (r += n), t = yu(t / 2), n += n; while (t); return r } function We(n, t, r) { var e = n; return(n = u(n)) ? (r ? Ur(e, t, r) : null == t) ? n.slice(g(n), y(n) + 1) : (t += "", n.slice(o(n, t), i(n, t) + 1)) : n } function $e(n, t, r) { return r && Ur(n, t, r) && (t = w), n = u(n), n.match(t || Wn) || [] } function iterateeImpl(n, t, r) { return r && Ur(n, t, r) && (t = w), h(n) ? Ne(n) : ut(n, t) } function Fe(n) { return n } function Ne(n) { return bt(ot(n, true)) } function Te(n, t, r) { if(null == r) { var e = ge(t), u = e ? zo(t) : w; ((u = u && u.length ? gt(t, u) : w) ? u.length : e) || (u = false, r = t, t = n, n = this) } u || (u = gt(t, zo(t))); var o = true, e = -1, i = ve(n), f = u.length; false === r ? o = false : ge(r) && "chain" in r && (o = r.chain); for(; ++e < f;) { r = u[e]; var a = t[r]; n[r] = a, i && (n.prototype[r] = function(t) { return function() { var r = this.__chain__; if(o || r) { var e = n(this.__wrapped__); return(e.__actions__ = qn(this.__actions__)).push({ func: t, args: arguments, thisArg: n }), e.__chain__ = r, e } return t.apply(n, mergeArray([this.value()], arguments)); } }(a)) } return n } function Le() {} function ze(n) { return Wr(n) ? attrGetter(n) : kt(n) } _ = _ ? Yn.defaults(Zn.Object(), _, Yn.pick(Zn, $n)) : Zn; var Be = _.Array, De = _.Date, Me = _.Error, qe = _.Function, Pe = _.Math, Ke = _.Number, Ve = _.Object, Ze = _.RegExp, Ye = _.String, Ge = _.TypeError, Je = Be.prototype, Xe = Ve.prototype, He = Ye.prototype, Qe = qe.prototype.toString, nu = Xe.hasOwnProperty, tu = 0, ru = Xe.toString, eu = Zn._, uu = Ze("^" + Qe.call(nu).replace(/[\\^$.*+?()[\]{}|]/g, "\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, "$1.*?") + "$"), ou = _.ArrayBuffer, iu = _.clearTimeout, fu = _.parseFloat, au = Pe.pow, cu = Xe.propertyIsEnumerable, lu = jr(_, "Set"), su = _.setTimeout, pu = Je.splice, hu = _.Uint8Array, _u = jr(_, "WeakMap"), vu = Pe.ceil, gu = jr(Ve, "create"), yu = Pe.floor, du = jr(Be, "isArray"), mu = _.isFinite, wu = jr(Ve, "keys"), bu = Pe.max, xu = Pe.min, Au = jr(De, "now"), ju = _.parseInt, ku = Pe.random, Iu = Ke.NEGATIVE_INFINITY, Ru = Ke.POSITIVE_INFINITY, Ou = 4294967294, Eu = 2147483647, Cu = 9007199254740991, Uu = _u && new _u, Wu = {}; Nn.support = {}, Nn.templateSettings = { escape: _n, evaluate: vn, interpolate: gn, variable: "", imports: { _: Nn } }; var $u = function() { function n() {} return function(t) { if(ge(t)) { n.prototype = t; var r = new n; n.prototype = w } return r || {} } }(), Su = Vt(_t), Fu = Vt(vt, true), Nu = Zt(), Tu = Zt(true), Lu = Uu ? function(n, t) { return Uu.set(n, t), n } : Fe, zu = Uu ? function(n) { return Uu.get(n) } : Le, lengthGetter = attrGetter("length"), Du = function() { var n = 0, t = 0; return function(r, e) { var u = ho(), o = S - (u - t); if(t = u, 0 < o) { if(++n >= $) return r } else n = 0; return Lu(r, e) } }(), Mu = le(function(n, t) { return h(n) && isLengthAttrValid(n) ? subtract(n, pt(t, false, true)) : [] }), qu = tr(), Pu = tr(true), Ku = le(function(n) { for(var t = n.length, e = t, u = Be(l), o = xr(), i = o === r, f = []; e--;) { var a = n[e] = isLengthAttrValid(a = n[e]) ? a : []; u[e] = i && 120 <= a.length && gu && lu ? new Dn(e && a) : null } var i = n[0], c = -1, l = i ? i.length : 0, s = u[0]; n: for(; ++c < l;) if(a = i[c], 0 > (s ? Mn(s, a) : o(f, a, 0))) { for(e = t; --e;) { var p = u[e]; if(0 > (p ? Mn(p, a) : o(n[e], a, 0))) continue n } s && s.push(a), f.push(a) } return f }), Vu = le(function(t, r) { r = pt(r); var e = rt(t, r); return It(t, r.sort(n)), e }), Zu = vr(), Yu = vr(true), Gu = le(function(n) { return St(pt(n, false, true)); }), Ju = le(function(n, t) { return isLengthAttrValid(n) ? subtract(n, t) : [] }), Xu = le(Jr), Hu = le(function(n) { var t = n.length, r = 2 < t ? n[t - 2] : w, e = 1 < t ? n[t - 1] : w; return 2 < t && typeof r == "function" ? t -= 2 : (r = 1 < t && typeof e == "function" ? (--t, e) : w, e = w), n.length = t, Xr(n, r, e) }), Qu = le(function(n) { return n = pt(n), this.thru(function(t) { t = Oo(t) ? t : [Br(t)]; for(var r = n, e = -1, u = t.length, o = -1, i = r.length, f = Be(u + i); ++e < u;) f[e] = t[e]; for(; ++o < i;) f[e++] = r[o]; return f }) }), no = le(function(n, t) { return rt(n, pt(t)) }), to = Pt(function(n, t, r) { nu.call(n, r) ? ++n[r] : n[r] = 1 }), ro = nr(Su), eo = nr(Fu, true), uo = ur(Pn, Su), oo = ur(function(n, t) { for(var r = n.length; r-- && false !== t(n[r], r, n);) ; return n }, Fu), io = Pt(function(n, t, r) { nu.call(n, r) ? n[r].push(t) : n[r] = [t] }), fo = Pt(function(n, t, r) { n[r] = t }), ao = le(function(n, t, r) { var e = -1, u = typeof t == "function", o = Wr(t), i = isLengthAttrValid(n) ? Be(n.length) : []; return Su(n, function(n) { var f = u ? t : o && null != n ? n[t] : w; i[++e] = f ? f.apply(n, r) : Or(n, t, r) }), i }), co = Pt(function(n, t, r) { n[r ? 0 : 1].push(t) }, function() { return [ [], [] ] }), lo = lr(Xn, Su), so = lr(function(n, t, r, e) { var u = n.length; for(e && u && (r = n[--u]); u--;) r = t(r, n[u], u, n); return r }, Fu), po = le(function(n, t) { if(null == n) return []; var r = t[2]; return r && Ur(t[0], t[1], r) && (t.length = 1), Wt(n, pt(t), []) }), ho = Au || function() { return(new De).getTime() }, _o = le(function(n, t, r) { var e = x; if(r.length) var u = v(r, _o.placeholder), e = e | R; return gr(n, e, t, r, u) }), vo = le(function(n, t) { t = t.length ? pt(t) : Ie(n); for(var r = -1, e = t.length; ++r < e;) { var u = t[r]; n[u] = gr(n[u], x, n) } return n }), go = le(function(n, t, r) { var e = x | A; if(r.length) var u = v(r, go.placeholder), e = e | R; return gr(t, e, n, r, u) }), yo = Xt(k), mo = Xt(I), wo = le(function(n, t) { return it(n, 1, t) }), bo = le(function(n, t, r) { return it(n, t, r) }), xo = er(), Ao = er(true), jo = le(function(n, t) { if(t = pt(t), typeof n != "function" || !Kn(t, e)) throw new Ge(L); var r = t.length; return le(function(e) { for(var u = xu(e.length, r); u--;) e[u] = t[u](e[u]); return n.apply(this, e) }) }), ko = cr(R), Io = cr(O), Ro = le(function(n, t) { return gr(n, C, w, w, w, pt(t)) }), Oo = du || function(n) { return h(n) && isValidNumber(n.length) && ru.call(n) == D }, Eo = Kt(At), Co = Kt(function(n, t, r) { return r ? nt(n, t, r) : tt(n, t) }), Uo = Ht(Co, function(n, t) { return n === w ? t : n }), Wo = Ht(Eo, Fr), $o = rr(_t), So = rr(vt), Fo = or(Nu), No = or(Tu), To = ir(_t), Lo = ir(vt), zo = wu ? function(n) { var t = null == n ? w : n.constructor; return typeof t == "function" && t.prototype === n || typeof n != "function" && isLengthAttrValid(n) ? Lr(n) : ge(n) ? wu(n) : [] } : Lr, Bo = fr(true), Do = fr(), Mo = le(function(n, t) { if(null == n) return {}; if("function" != typeof t[0]) return t = Gn(pt(t), Ye), Nr(n, subtract(Re(n), t)); var r = Bt(t[0], t[1], 3); return Tr(n, function(n, t, e) { return !r(n, t, e) }) }), qo = le(function(n, t) { return null == n ? {} : "function" == typeof t[0] ? Tr(n, Bt(t[0], t[1], 3)) : Nr(n, pt(t)) }), Po = Gt(function(n, t, r) { return t = t.toLowerCase(), n + (r ? t.charAt(0).toUpperCase() + t.slice(1) : t); }), Ko = Gt(function(n, t, r) { return n + (r ? "-" : "") + t.toLowerCase() }), Vo = ar(), Zo = ar(true), Yo = Gt(function(n, t, r) { return n + (r ? "_" : "") + t.toLowerCase() }), Go = Gt(function(n, t, r) { return n + (r ? " " : "") + (t.charAt(0).toUpperCase() + t.slice(1)) }), Jo = le(function(n, t) { try { return n.apply(w, t) } catch(r) { return _e(r) ? r : new Me(r) } }), Xo = le(function(n, t) { return function(r) { return Or(r, n, t) } }), Ho = le(function(n, t) { return function(r) { return Or(n, r, t) } }), Qo = _r("ceil"), ni = _r("floor"), ti = Qt(se, Iu), ri = Qt(Ae, Ru), ei = _r("round"); return Nn.prototype = Tn.prototype, Ln.prototype = $u(Tn.prototype), Ln.prototype.constructor = Ln, zn.prototype = $u(Tn.prototype), zn.prototype.constructor = zn, Bn.prototype["delete"] = function(n) { return this.has(n) && delete this.__data__[n] }, Bn.prototype.get = function(n) { return "__proto__" == n ? w : this.__data__[n] }, Bn.prototype.has = function(n) { return "__proto__" != n && nu.call(this.__data__, n) }, Bn.prototype.set = function(n, t) { return "__proto__" != n && (this.__data__[n] = t), this }, Dn.prototype.push = function(n) { var t = this.data; typeof n == "string" || ge(n) ? t.set.add(n) : t.hash[n] = true; }, ce.Cache = Bn, Nn.after = function(n, t) { if(typeof t != "function") { if(typeof n != "function") throw new Ge(L); var r = n; n = t, t = r } return n = mu(n = +n) ? n : 0, function() { return 1 > --n ? t.apply(this, arguments) : void 0 } }, Nn.ary = function(n, t, r) { return r && Ur(n, t, r) && (t = w), t = n && null == t ? n.length : bu(+t || 0, 0), gr(n, E, w, w, w, w, t) }, Nn.assign = Co, Nn.at = no, Nn.before = fe, Nn.bind = _o, Nn.bindAll = vo, Nn.bindKey = go, Nn.callback = iterateeImpl, Nn.chain = Qr, Nn.chunk = function(n, t, r) { t = (r ? Ur(n, t, r) : null == t) ? 1 : bu(yu(t) || 1, 1), r = 0; for(var e = n ? n.length : 0, u = -1, o = Be(vu(e / t)); r < e;) o[++u] = Et(n, r, r += t); return o }, Nn.compact = function(n) { for(var t = -1, r = n ? n.length : 0, e = -1, u = []; ++t < r;) { var o = n[t]; o && (u[++e] = o) } return u }, Nn.constant = function(n) { return function() { return n } }, Nn.countBy = to, Nn.create = function(n, t, r) { var e = $u(n); return r && Ur(n, t, r) && (t = w), t ? tt(e, t) : e }, Nn.curry = yo, Nn.curryRight = mo, Nn.debounce = ae, Nn.defaults = Uo, Nn.defaultsDeep = Wo, Nn.defer = wo, Nn.delay = bo, Nn.difference = Mu, Nn.drop = qr, Nn.dropRight = Pr, Nn.dropRightWhile = function(n, t, r) { return n && n.length ? Nt(n, wr(t, r, 3), true, true) : [] }, Nn.dropWhile = function(n, t, r) { return n && n.length ? Nt(n, wr(t, r, 3), true) : [] }, Nn.fill = function(n, t, r, e) { var u = n ? n.length : 0; if(!u) return []; for(r && typeof r != "number" && Ur(n, t, r) && (r = 0, e = u), u = n.length, r = null == r ? 0 : +r || 0, 0 > r && (r = -r > u ? 0 : u + r), e = e === w || e > u ? u : +e || 0, 0 > e && (e += u), u = r > e ? 0 : e >>> 0, r >>>= 0; r < u;) n[r++] = t; return n }, Nn.filter = re, Nn.flatten = function(n, t, r) { var e = n ? n.length : 0; return r && Ur(n, t, r) && (t = false), e ? pt(n, t) : [] }, Nn.flattenDeep = function(n) { return n && n.length ? pt(n, true) : [] }, Nn.flow = xo, Nn.flowRight = Ao, Nn.forEach = uo, Nn.forEachRight = oo, Nn.forIn = Fo, Nn.forInRight = No, Nn.forOwn = To, Nn.forOwnRight = Lo, Nn.functions = Ie, Nn.groupBy = io, Nn.indexBy = fo, Nn.initial = function(n) { return Pr(n, 1) }, Nn.intersection = Ku, Nn.invert = function(n, t, r) { r && Ur(n, t, r) && (t = w), r = -1; for(var e = zo(n), u = e.length, o = {}; ++r < u;) { var i = e[r], f = n[i]; t ? nu.call(o, f) ? o[f].push(i) : o[f] = [i] : o[f] = i } return o }, Nn.invoke = ao, Nn.keys = zo, Nn.keysIn = Re, Nn.map = ue, Nn.mapKeys = Bo, Nn.mapValues = Do, Nn.matches = Ne, Nn.matchesProperty = function(n, t) { return xt(n, ot(t, true)) }, Nn.memoize = ce, Nn.merge = Eo, Nn.method = Xo, Nn.methodOf = Ho, Nn.mixin = Te, Nn.modArgs = jo, Nn.negate = function(n) { if(typeof n != "function") throw new Ge(L); return function() { return !n.apply(this, arguments) } }, Nn.omit = Mo, Nn.once = function(n) { return fe(2, n) }, Nn.pairs = Oe, Nn.partial = ko, Nn.partialRight = Io, Nn.partition = co, Nn.pick = qo, Nn.pluck = function(n, t) { return ue(n, ze(t)) }, Nn.property = ze, Nn.propertyOf = function(n) { return function(t) { return yt(n, Dr(t), t + "") } }, Nn.pull = function() { var n = arguments, t = n[0]; if(!t || !t.length) return t; for(var r = 0, e = xr(), u = n.length; ++r < u;) for(var o = 0, i = n[r]; - 1 < (o = e(t, i, o));) pu.call(t, o, 1); return t }, Nn.pullAt = Vu, Nn.range = function(n, t, r) { r && Ur(n, t, r) && (t = r = w), n = +n || 0, r = null == r ? 1 : +r || 0, null == t ? (t = n, n = 0) : t = +t || 0; var e = -1; t = bu(vu((t - n) / (r || 1)), 0); for(var u = Be(t); ++e < t;) u[e] = n, n += r; return u }, Nn.rearg = Ro, Nn.reject = function(n, t, r) { var e = Oo(n) ? Vn : lt; return t = wr(t, r, 3), e(n, function(n, r, e) { return !t(n, r, e) }) }, Nn.remove = function(n, t, r) { var e = []; if(!n || !n.length) return e; var u = -1, o = [], i = n.length; for(t = wr(t, r, 3); ++u < i;) r = n[u], t(r, u, n) && (e.push(r), o.push(u)); return It(n, o), e }, Nn.rest = Yr, Nn.restParam = le, Nn.set = function(n, t, r) { if(null == n) return n; var e = t + ""; t = null != n[e] || Wr(t, n) ? [e] : Dr(t); for(var e = -1, u = t.length, o = u - 1, i = n; null != i && ++e < u;) { var f = t[e]; ge(i) && (e == o ? i[f] = r : null == i[f] && (i[f] = Cr(t[e + 1]) ? [] : {})), i = i[f] } return n }, Nn.shuffle = function(n) { return oe(n, Ru) }, Nn.slice = function(n, t, r) { var e = n ? n.length : 0; return e ? (r && typeof r != "number" && Ur(n, t, r) && (t = 0, r = e), Et(n, t, r)) : [] }, Nn.sortBy = function(n, t, r) { if(null == n) return []; r && Ur(n, t, r) && (t = w); var e = -1; return t = wr(t, r, 3), n = wt(n, function(n, r, u) { return { a: t(n, r, u), b: ++e, c: n } }), Ut(n, f) }, Nn.sortByAll = po, Nn.sortByOrder = function(n, t, r, e) { return null == n ? [] : (e && Ur(t, r, e) && (r = w), Oo(t) || (t = null == t ? [] : [t]), Oo(r) || (r = null == r ? [] : [r]), Wt(n, t, r)) }, Nn.spread = function(n) { if(typeof n != "function") throw new Ge(L); return function(t) { return n.apply(this, t) } }, Nn.take = function(n, t, r) { return n && n.length ? ((r ? Ur(n, t, r) : null == t) && (t = 1), Et(n, 0, 0 > t ? 0 : t)) : [] }, Nn.takeRight = function(n, t, r) { var e = n ? n.length : 0; return e ? ((r ? Ur(n, t, r) : null == t) && (t = 1), t = e - (+t || 0), Et(n, 0 > t ? 0 : t)) : [] }, Nn.takeRightWhile = function(n, t, r) { return n && n.length ? Nt(n, wr(t, r, 3), false, true) : [] }, Nn.takeWhile = function(n, t, r) { return n && n.length ? Nt(n, wr(t, r, 3)) : [] }, Nn.tap = function(n, t, r) { return t.call(r, n), n }, Nn.throttle = function(n, t, r) { var e = true, u = true; if(typeof n != "function") throw new Ge(L); return false === r ? e = false : ge(r) && (e = "leading" in r ? !!r.leading : e, u = "trailing" in r ? !!r.trailing : u), ae(n, t, { leading: e, maxWait: +t, trailing: u }) }, Nn.thru = ne, Nn.times = function(n, t, r) { if(n = yu(n), 1 > n || !mu(n)) return []; var e = -1, u = Be(xu(n, 4294967295)); for(t = Bt(t, r, 1); ++e < n;) 4294967295 > e ? u[e] = t(e) : t(e); return u }, Nn.toArray = je, Nn.toPlainObject = ke, Nn.transform = function(n, t, r, e) { var u = Oo(n) || xe(n); return t = wr(t, e, 4), null == r && (u || ge(n) ? (e = n.constructor, r = u ? Oo(n) ? new e : [] : $u(ve(e) ? e.prototype : w)) : r = {}), (u ? Pn : _t)(n, function(n, e, u) { return t(r, n, e, u) }), r }, Nn.union = Gu, Nn.uniq = Gr, Nn.unzip = Jr, Nn.unzipWith = Xr, Nn.values = Ee, Nn.valuesIn = function(n) { return Ft(n, Re(n)) }, Nn.where = function(n, t) { return re(n, bt(t)) }, Nn.without = Ju, Nn.wrap = function(n, t) { return t = null == t ? Fe : t, gr(t, R, w, [n], []) }, Nn.xor = function() { var predicate = null; var last = arguments[arguments.length - 1]; var type = typeof last; if (type === 'string') { predicate = function (o1, o2) { return o1 && o2 && o1[last] === o2[last]; }; } else if (type === 'function') { predicate = last; } if (predicate === null) { predicate = function (o1, o2) { return o1 === o2; }; } else { // 去除最后一个元素 delete arguments[arguments.length - 1]; arguments.length = arguments.length - 1; } var prevArr; for(var index = -1, length = arguments.length; ++index < length;) { var arr = arguments[index]; if(isLengthAttrValid(arr)) { if (prevArr) { prevArr = mergeArray(subtract(prevArr, arr, predicate), subtract(arr, prevArr, predicate)); } else { prevArr = arr; } } // var e = e ? Jn(ft(e, arr), ft(arr, e)) : arr } return prevArr ? St(prevArr) : [] }, Nn.subtract = subtract, Nn.zip = Xu, Nn.zipObject = Hr, Nn.zipWith = Hu, Nn.backflow = Ao, Nn.collect = ue, Nn.compose = Ao, Nn.each = uo, Nn.eachRight = oo, Nn.extend = Co, Nn.iteratee = iterateeImpl, Nn.methods = Ie, Nn.object = Hr, Nn.select = re, Nn.tail = Yr, Nn.unique = Gr, Te(Nn, Nn), Nn.add = function(n, t) { return(+n || 0) + (+t || 0) }, Nn.attempt = Jo, Nn.camelCase = Po, Nn.capitalize = function(n) { return(n = u(n)) && n.charAt(0).toUpperCase() + n.slice(1) }, Nn.ceil = Qo, Nn.clone = function(n, t, r, e) { return t && typeof t != "boolean" && Ur(n, t, r) ? t = false : typeof t == "function" && (e = r, r = t, t = false), typeof r == "function" ? ot(n, t, Bt(r, e, 3)) : ot(n, t) }, Nn.cloneDeep = function(n, t, r) { return typeof t == "function" ? ot(n, true, Bt(t, r, 3)) : ot(n, true) }, Nn.deburr = Ce, Nn.endsWith = function(n, t, r) { n = u(n), t += ""; var e = n.length; return r = r === w ? e : xu(0 > r ? 0 : +r || 0, e), r -= t.length, 0 <= r && n.indexOf(t, r) == r }, Nn.escape = function(n) { return(n = u(n)) && hn.test(n) ? n.replace(sn, c) : n }, Nn.escapeRegExp = function(n) { return(n = u(n)) && bn.test(n) ? n.replace(wn, l) : n || "(?:)" }, Nn.every = te, Nn.find = ro, Nn.findIndex = qu, Nn.findKey = $o, Nn.findLast = eo, Nn.findLastIndex = Pu, Nn.findLastKey = So, Nn.findWhere = function(n, t) { return ro(n, bt(t)) }, Nn.first = Kr, Nn.floor = ni, Nn.get = function(n, t, r) { return n = null == n ? w : yt(n, Dr(t), t + ""), n === w ? r : n }, Nn.gt = se, Nn.gte = function(n, t) { return n >= t }, Nn.has = function(n, t) { if(null == n) return false; var r = nu.call(n, t); if(!r && !Wr(t)) { if(t = Dr(t), n = 1 == t.length ? n : yt(n, Et(t, 0, -1)), null == n) return false; t = Zr(t), r = nu.call(n, t) } return r || isValidNumber(n.length) && Cr(t, n.length) && (Oo(n) || pe(n)) }, Nn.identity = Fe, Nn.includes = ee, Nn.indexOf = Vr, Nn.inRange = function(n, t, r) { return t = +t || 0, r === w ? (r = t, t = 0) : r = +r || 0, n >= xu(t, r) && n < bu(t, r) }, Nn.isArguments = pe, Nn.isArray = Oo, Nn.isBoolean = function(n) { return true === n || false === n || h(n) && ru.call(n) == M }, Nn.isDate = function(n) { return h(n) && ru.call(n) == q }, Nn.isElement = function(n) { return !!n && 1 === n.nodeType && h(n) && !me(n) }, Nn.isEmpty = function(n) { return null == n ? true : isLengthAttrValid(n) && (Oo(n) || be(n) || pe(n) || h(n) && ve(n.splice)) ? !n.length : !zo(n).length }, Nn.isEqual = he, Nn.isError = _e, Nn.isFinite = function(n) { return typeof n == "number" && mu(n) }, Nn.isFunction = ve, Nn.isMatch = function(n, t, r, e) { return r = typeof r == "function" ? Bt(r, e, 3) : w, mt(n, Ar(t), r) }, Nn.isNaN = function(n) { return de(n) && n != +n }, Nn.isNative = ye, Nn.isNull = function(n) { return null === n }, Nn.isNumber = de, Nn.isObject = ge, Nn.isPlainObject = me, Nn.isRegExp = we, Nn.isString = be, Nn.isTypedArray = xe, Nn.isUndefined = function(n) { return n === w }, Nn.kebabCase = Ko, Nn.last = Zr, Nn.lastIndexOf = function(n, t, r) { var e = n ? n.length : 0; if(!e) return -1; var u = e; if(typeof r == "number") u = (0 > r ? bu(e + r, 0) : xu(r || 0, e - 1)) + 1; else if(r) return u = Lt(n, t, true) - 1, n = n[u], (t === t ? t === n : n !== n) ? u : -1; if(t !== t) return p(n, u, true); for(; u--;) if(n[u] === t) return u; return -1 }, Nn.lt = Ae, Nn.lte = function(n, t) { return n <= t }, Nn.max = ti, Nn.min = ri, Nn.noConflict = function() { return Zn._ = eu, this }, Nn.noop = Le, Nn.now = ho, Nn.pad = function(n, t, r) { n = u(n), t = +t; var e = n.length; return e < t && mu(t) ? (e = (t - e) / 2, t = yu(e), e = vu(e), r = pr("", e, r), r.slice(0, t) + n + r) : n }, Nn.padLeft = Vo, Nn.padRight = Zo, Nn.parseInt = function(n, t, r) { return(r ? Ur(n, t, r) : null == t) ? t = 0 : t && (t = +t), n = We(n), ju(n, t || (In.test(n) ? 16 : 10)) }, Nn.random = function(n, t, r) { r && Ur(n, t, r) && (t = r = w); var e = null == n, u = null == t; return null == r && (u && typeof n == "boolean" ? (r = n, n = 1) : typeof t == "boolean" && (r = t, u = true)), e && u && (t = 1, u = false), n = +n || 0, u ? (t = n, n = 0) : t = +t || 0, r || n % 1 || t % 1 ? (r = ku(), xu(n + r * (t - n + fu("1e-" + ((r + "").length - 1))), t)) : Rt(n, t) }, Nn.reduce = lo, Nn.reduceRight = so, Nn.repeat = Ue, Nn.result = function(n, t, r) { var e = null == n ? w : n[t]; return e === w && (null == n || Wr(t, n) || (t = Dr(t), n = 1 == t.length ? n : yt(n, Et(t, 0, -1)), e = null == n ? w : n[Zr(t)]), e = e === w ? r : e), ve(e) ? e.call(n) : e }, Nn.round = ei, Nn.runInContext = m, Nn.size = function(n) { var t = n ? lengthGetter(n) : 0; return isValidNumber(t) ? t : zo(n).length }, Nn.snakeCase = Yo, Nn.some = ie, Nn.sortedIndex = Zu, Nn.sortedLastIndex = Yu, Nn.startCase = Go, Nn.startsWith = function(n, t, r) { return n = u(n), r = null == r ? 0 : xu(0 > r ? 0 : +r || 0, n.length), n.lastIndexOf(t, r) == r }, Nn.sum = function(n, t, r) { if(r && Ur(n, t, r) && (t = w), t = wr(t, r, 3), 1 == t.length) { n = Oo(n) ? n : zr(n), r = n.length; for(var e = 0; r--;) e += +t(n[r]) || 0; n = e } else n = $t(n, t); return n }, Nn.template = function(n, t, r) { var e = Nn.templateSettings; r && Ur(n, t, r) && (t = r = w), n = u(n), t = nt(tt({}, r || t), e, Qn), r = nt(tt({}, t.imports), e.imports, Qn); var o, i, f = zo(r), a = Ft(r, f), c = 0; r = t.interpolate || Cn; var l = "__p+='"; r = Ze((t.escape || Cn).source + "|" + r.source + "|" + (r === gn ? jn : Cn).source + "|" + (t.evaluate || Cn).source + "|$", "g"); var p = "sourceURL" in t ? "//# sourceURL=" + t.sourceURL + "\n" : ""; if(n.replace(r, function(t, r, e, u, f, a) { return e || (e = u), l += n.slice(c, a).replace(Un, s), r && (o = true, l += "'+__e(" + r + ")+'"), f && (i = true, l += "';" + f + ";\n__p+='"), e && (l += "'+((__t=(" + e + "))==null?'':__t)+'"), c = a + t.length, t }), l += "';", (t = t.variable) || (l = "with(obj){" + l + "}"), l = (i ? l.replace(fn, "") : l).replace(an, "$1").replace(cn, "$1;"), l = "function(" + (t || "obj") + "){" + (t ? "" : "obj||(obj={});") + "var __t,__p=''" + (o ? ",__e=_.escape" : "") + (i ? ",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}" : ";") + l + "return __p}", t = Jo(function() { return qe(f, p + "return " + l).apply(w, a) }), t.source = l, _e(t)) throw t; return t }, Nn.trim = We, Nn.trimLeft = function(n, t, r) { var e = n; return(n = u(n)) ? n.slice((r ? Ur(e, t, r) : null == t) ? g(n) : o(n, t + "")) : n }, Nn.trimRight = function(n, t, r) { var e = n; return(n = u(n)) ? (r ? Ur(e, t, r) : null == t) ? n.slice(0, y(n) + 1) : n.slice(0, i(n, t + "") + 1) : n; }, Nn.trunc = function(n, t, r) { r && Ur(n, t, r) && (t = w); var e = U; if(r = W, null != t) if(ge(t)) { var o = "separator" in t ? t.separator : o, e = "length" in t ? +t.length || 0 : e; r = "omission" in t ? u(t.omission) : r } else e = +t || 0; if(n = u(n), e >= n.length) return n; if(e -= r.length, 1 > e) return r; if(t = n.slice(0, e), null == o) return t + r; if(we(o)) { if(n.slice(e).search(o)) { var i, f = n.slice(0, e); for(o.global || (o = Ze(o.source, (kn.exec(o) || "") + "g")), o.lastIndex = 0; n = o.exec(f);) i = n.index; t = t.slice(0, null == i ? e : i) } } else n.indexOf(o, e) != e && (o = t.lastIndexOf(o), -1 < o && (t = t.slice(0, o))); return t + r }, Nn.unescape = function(n) { return(n = u(n)) && pn.test(n) ? n.replace(ln, d) : n }, Nn.uniqueId = function(n) { var t = ++tu; return u(n) + t }, Nn.words = $e, Nn.all = te, Nn.any = ie, Nn.contains = ee, Nn.eq = he, Nn.detect = ro, Nn.foldl = lo, Nn.foldr = so, Nn.head = Kr, Nn.include = ee, Nn.inject = lo, Te(Nn, function() { var n = {}; return _t(Nn, function(t, r) { Nn.prototype[r] || (n[r] = t) }), n }(), false), Nn.sample = oe, Nn.prototype.sample = function(n) { return this.__chain__ || null != n ? this.thru(function(t) { return oe(t, n) }) : oe(this.value()); }, Nn.VERSION = b, Pn("bind bindKey curry curryRight partial partialRight".split(" "), function(n) { Nn[n].placeholder = Nn }), Pn(["drop", "take"], function(n, t) { zn.prototype[n] = function(r) { var e = this.__filtered__; if(e && !t) return new zn(this); r = null == r ? 1 : bu(yu(r) || 0, 0); var u = this.clone(); return e ? u.__takeCount__ = xu(u.__takeCount__, r) : u.__views__.push({ size: r, type: n + (0 > u.__dir__ ? "Right" : "") }), u }, zn.prototype[n + "Right"] = function(t) { return this.reverse()[n](t).reverse() } }), Pn(["filter", "map", "takeWhile"], function(n, t) { var r = t + 1, e = r != T; zn.prototype[n] = function(n, t) { var u = this.clone(); return u.__iteratees__.push({ iteratee: wr(n, t, 1), type: r }), u.__filtered__ = u.__filtered__ || e, u } }), Pn(["first", "last"], function(n, t) { var r = "take" + (t ? "Right" : ""); zn.prototype[n] = function() { return this[r](1).value()[0] } }), Pn(["initial", "rest"], function(n, t) { var r = "drop" + (t ? "" : "Right"); zn.prototype[n] = function() { return this.__filtered__ ? new zn(this) : this[r](1) } }), Pn(["pluck", "where"], function(n, t) { var r = t ? "filter" : "map", e = t ? bt : ze; zn.prototype[n] = function(n) { return this[r](e(n)) } }), zn.prototype.compact = function() { return this.filter(Fe) }, zn.prototype.reject = function(n, t) { return n = wr(n, t, 1), this.filter(function(t) { return !n(t) }) }, zn.prototype.slice = function(n, t) { n = null == n ? 0 : +n || 0; var r = this; return r.__filtered__ && (0 < n || 0 > t) ? new zn(r) : (0 > n ? r = r.takeRight(-n) : n && (r = r.drop(n)), t !== w && (t = +t || 0, r = 0 > t ? r.dropRight(-t) : r.take(t - n)), r) }, zn.prototype.takeRightWhile = function(n, t) { return this.reverse().takeWhile(n, t).reverse() }, zn.prototype.toArray = function() { return this.take(Ru); }, _t(zn.prototype, function(n, t) { var r = /^(?:filter|map|reject)|While$/.test(t), e = /^(?:first|last)$/.test(t), u = Nn[e ? "take" + ("last" == t ? "Right" : "") : t]; u && (Nn.prototype[t] = function() { function t(n) { return e && i ? u(n, 1)[0] : u.apply(w, mergeArray([n], o)) } var o = e ? [1] : arguments, i = this.__chain__, f = this.__wrapped__, a = !!this.__actions__.length, c = f instanceof zn, l = o[0], s = c || Oo(f); return s && r && typeof l == "function" && 1 != l.length && (c = s = false), l = { func: ne, args: [t], thisArg: w }, a = c && !a, e && !i ? a ? (f = f.clone(), f.__actions__.push(l), n.call(f)) : u.call(w, this.value())[0] : !e && s ? (f = a ? f : new zn(this), f = n.apply(f, o), f.__actions__.push(l), new Ln(f, i)) : this.thru(t) }) }), Pn("join pop push replace shift sort splice split unshift".split(" "), function(n) { var t = (/^(?:replace|split)$/.test(n) ? He : Je)[n], r = /^(?:push|sort|unshift)$/.test(n) ? "tap" : "thru", e = /^(?:join|pop|replace|shift)$/.test(n); Nn.prototype[n] = function() { var n = arguments; return e && !this.__chain__ ? t.apply(this.value(), n) : this[r](function(r) { return t.apply(r, n) }) } }), _t(zn.prototype, function(n, t) { var r = Nn[t]; if(r) { var e = r.name + ""; (Wu[e] || (Wu[e] = [])).push({ name: t, func: r }) } }), Wu[sr(w, A).name] = [{ name: "wrapper", func: w }], zn.prototype.clone = function() { var n = new zn(this.__wrapped__); return n.__actions__ = qn(this.__actions__), n.__dir__ = this.__dir__, n.__filtered__ = this.__filtered__, n.__iteratees__ = qn(this.__iteratees__), n.__takeCount__ = this.__takeCount__, n.__views__ = qn(this.__views__), n }, zn.prototype.reverse = function() { if(this.__filtered__) { var n = new zn(this); n.__dir__ = -1, n.__filtered__ = true } else n = this.clone(), n.__dir__ *= -1; return n }, zn.prototype.value = function() { var n, t = this.__wrapped__.value(), r = this.__dir__, e = Oo(t), u = 0 > r, o = e ? t.length : 0; n = o; for(var i = this.__views__, f = 0, a = -1, c = i.length; ++a < c;) { var l = i[a], s = l.size; switch(l.type) { case "drop": f += s; break; case "dropRight": n -= s; break; case "take": n = xu(n, f + s); break; case "takeRight": f = bu(f, n - s) } } if(n = { start: f, end: n }, i = n.start, f = n.end, n = f - i, u = u ? f : i - 1, i = this.__iteratees__, f = i.length, a = 0, c = xu(n, this.__takeCount__), !e || o < F || o == n && c == n) return Tt(t, this.__actions__); e = []; n: for(; n-- && a < c;) { for(u += r, o = -1, l = t[u]; ++o < f;) { var p = i[o], s = p.type, p = p.iteratee(l); if(s == T) l = p; else if(!p) { if(s == N) continue n; break n } } e[a++] = l } return e }, Nn.prototype.chain = function() { return Qr(this) }, Nn.prototype.commit = function() { return new Ln(this.value(), this.__chain__) }, Nn.prototype.concat = Qu, Nn.prototype.plant = function(n) { for(var t, r = this; r instanceof Tn;) { var e = Mr(r); t ? u.__wrapped__ = e : t = e; var u = e, r = r.__wrapped__ } return u.__wrapped__ = n, t }, Nn.prototype.reverse = function() { function n(n) { return n.reverse() } var t = this.__wrapped__; return t instanceof zn ? (this.__actions__.length && (t = new zn(this)), t = t.reverse(), t.__actions__.push({ func: ne, args: [n], thisArg: w }), new Ln(t, this.__chain__)) : this.thru(n) }, Nn.prototype.toString = function() { return this.value() + "" }, Nn.prototype.run = Nn.prototype.toJSON = Nn.prototype.valueOf = Nn.prototype.value = function() { return Tt(this.__wrapped__, this.__actions__) }, Nn.prototype.collect = Nn.prototype.map, Nn.prototype.head = Nn.prototype.first, Nn.prototype.select = Nn.prototype.filter, Nn.prototype.tail = Nn.prototype.rest, Nn } var w, b = "3.10.1", x = 1, A = 2, j = 4, k = 8, I = 16, R = 32, O = 64, E = 128, C = 256, U = 30, W = "...", $ = 150, S = 16, F = 200, N = 1, T = 2, L = "Expected a function", z = "__lodash_placeholder__", B = "[object Arguments]", D = "[object Array]", M = "[object Boolean]", q = "[object Date]", P = "[object Error]", K = "[object Function]", V = "[object Number]", Z = "[object Object]", Y = "[object RegExp]", G = "[object String]", J = "[object ArrayBuffer]", X = "[object Float32Array]", H = "[object Float64Array]", Q = "[object Int8Array]", nn = "[object Int16Array]", tn = "[object Int32Array]", rn = "[object Uint8Array]", en = "[object Uint8ClampedArray]", un = "[object Uint16Array]", on = "[object Uint32Array]", fn = /\b__p\+='';/g, an = /\b(__p\+=)''\+/g, cn = /(__e\(.*?\)|\b__t\))\+'';/g, ln = /&(?:amp|lt|gt|quot|#39|#96);/g, sn = /[&<>"'`]/g, pn = RegExp(ln.source), hn = RegExp(sn.source), _n = /<%-([\s\S]+?)%>/g, vn = /<%([\s\S]+?)%>/g, gn = /<%=([\s\S]+?)%>/g, yn = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\n\\]|\\.)*?\1)\]/, dn = /^\w*$/, mn = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\n\\]|\\.)*?)\2)\]/g, wn = /^[:!,]|[\\^$.*+?()[\]{}|\/]|(^[0-9a-fA-Fnrtuvx])|([\n\r\u2028\u2029])/g, bn = RegExp(wn.source), xn = /[\u0300-\u036f\ufe20-\ufe23]/g, An = /\\(\\)?/g, jn = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g, kn = /\w*$/, In = /^0[xX]/, Rn = /^\[object .+?Constructor\]$/, On = /^\d+$/, En = /[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g, Cn = /($^)/, Un = /['\n\r\u2028\u2029\\]/g, Wn = RegExp("[A-Z\\xc0-\\xd6\\xd8-\\xde]+(?=[A-Z\\xc0-\\xd6\\xd8-\\xde][a-z\\xdf-\\xf6\\xf8-\\xff]+)|[A-Z\\xc0-\\xd6\\xd8-\\xde]?[a-z\\xdf-\\xf6\\xf8-\\xff]+|[A-Z\\xc0-\\xd6\\xd8-\\xde]+|[0-9]+", "g"), $n = "Array ArrayBuffer Date Error Float32Array Float64Array Function Int8Array Int16Array Int32Array Math Number Object RegExp Set String _ clearTimeout isFinite parseFloat parseInt setTimeout TypeError Uint8Array Uint8ClampedArray Uint16Array Uint32Array WeakMap".split(" "), Sn = {}; Sn[X] = Sn[H] = Sn[Q] = Sn[nn] = Sn[tn] = Sn[rn] = Sn[en] = Sn[un] = Sn[on] = true, Sn[B] = Sn[D] = Sn[J] = Sn[M] = Sn[q] = Sn[P] = Sn[K] = Sn["[object Map]"] = Sn[V] = Sn[Z] = Sn[Y] = Sn["[object Set]"] = Sn[G] = Sn["[object WeakMap]"] = false; var Fn = {}; Fn[B] = Fn[D] = Fn[J] = Fn[M] = Fn[q] = Fn[X] = Fn[H] = Fn[Q] = Fn[nn] = Fn[tn] = Fn[V] = Fn[Z] = Fn[Y] = Fn[G] = Fn[rn] = Fn[en] = Fn[un] = Fn[on] = true, Fn[P] = Fn[K] = Fn["[object Map]"] = Fn["[object Set]"] = Fn["[object WeakMap]"] = false; var Nn = { "\xc0": "A", "\xc1": "A", "\xc2": "A", "\xc3": "A", "\xc4": "A", "\xc5": "A", "\xe0": "a", "\xe1": "a", "\xe2": "a", "\xe3": "a", "\xe4": "a", "\xe5": "a", "\xc7": "C", "\xe7": "c", "\xd0": "D", "\xf0": "d", "\xc8": "E", "\xc9": "E", "\xca": "E", "\xcb": "E", "\xe8": "e", "\xe9": "e", "\xea": "e", "\xeb": "e", "\xcc": "I", "\xcd": "I", "\xce": "I", "\xcf": "I", "\xec": "i", "\xed": "i", "\xee": "i", "\xef": "i", "\xd1": "N", "\xf1": "n", "\xd2": "O", "\xd3": "O", "\xd4": "O", "\xd5": "O", "\xd6": "O", "\xd8": "O", "\xf2": "o", "\xf3": "o", "\xf4": "o", "\xf5": "o", "\xf6": "o", "\xf8": "o", "\xd9": "U", "\xda": "U", "\xdb": "U", "\xdc": "U", "\xf9": "u", "\xfa": "u", "\xfb": "u", "\xfc": "u", "\xdd": "Y", "\xfd": "y", "\xff": "y", "\xc6": "Ae", "\xe6": "ae", "\xde": "Th", "\xfe": "th", "\xdf": "ss" }, Tn = { "&": "&", "<": "<", ">": ">", '"': """, "'": "'", "`": "`" }, Ln = { "&": "&", "<": "<", ">": ">", """: '"', "'": "'", "`": "`" }, zn = { "function": true, object: true }, Bn = { 0: "x30", 1: "x31", 2: "x32", 3: "x33", 4: "x34", 5: "x35", 6: "x36", 7: "x37", 8: "x38", 9: "x39", A: "x41", B: "x42", C: "x43", D: "x44", E: "x45", F: "x46", a: "x61", b: "x62", c: "x63", d: "x64", e: "x65", f: "x66", n: "x6e", r: "x72", t: "x74", u: "x75", v: "x76", x: "x78" }, Dn = { "\\": "\\", "'": "'", "\n": "n", "\r": "r", "\u2028": "u2028", "\u2029": "u2029" }, Mn = zn[typeof exports] && exports && !exports.nodeType && exports, qn = zn[typeof module] && module && !module.nodeType && module, Pn = zn[typeof self] && self && self.Object && self, Kn = zn[typeof window] && window && window.Object && window, Vn = qn && qn.exports === Mn && Mn, Zn = Mn && qn && typeof global == "object" && global && global.Object && global || Kn !== (this && this.window) && Kn || Pn || this, Yn = m(); typeof define == "function" && typeof define.amd == "object" && define.amd ? (Zn._ = Yn, define(function() { return Yn })) : Mn && qn ? Vn ? (qn.exports = Yn)._ = Yn : Mn._ = Yn : Zn._ = Yn }).call(this); }).call(this, typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) }, {}]; var cuiMapImpl = [function(require, module, exports) { module.exports = function() { var cuiMap = { openMap: function(options) { var options = options || {}, width = options.width || '100%', height = options.height || '100%', path = window.cui_path || ''; dialog.open({ title: '地图', type: 2, html: true, maxmin: true, area: [width, height], content: path + '/cui/js/plugins/cui-map/map.html', success: function(dom) { var innerWindow = $(dom).find('iframe')[0].contentWindow; var innerDocument = innerWindow.document; $(innerDocument).ready(function() { var mapjs = innerDocument.createElement('script'); innerDocument.body.appendChild(mapjs); mapjs.src = options.gis + '?async=yes' || 'http://www.baidu.com/'; innerWindow.innerFunction(options); }) } }); } }; window.oasMap = cuiMap; return cuiMap; } }, {}]; var cuiNProgressImpl = [function(require, module, exports) { /* * @desc nprogress组件,依赖于开源组件nprogress */ var nprogress = require('../../../plugins/nprogress/nprogress'), nprogressCss = require('../../../plugins/nprogress/nprogress.css'); }, { "../../../plugins/nprogress/nprogress": 79, "../../../plugins/nprogress/nprogress.css": 78 }]; var cuiNProgressRealImpl= [function(require, module, exports) { /* NProgress, (c) 2013, 2014 Rico Sta. Cruz - http://ricostacruz.com/nprogress * @license MIT */ ; (function(root, factory) { if(typeof define === 'function' && define.amd) { define(factory); } else if(typeof exports === 'object') { module.exports = factory(); } else { root.NProgress = factory(); } })(this, function() { var NProgress = {}; NProgress.version = '0.2.0'; var Settings = NProgress.settings = { minimum: 0.08, easing: 'linear', positionUsing: '', speed: 350, trickle: true, trickleSpeed: 250, showSpinner: true, barSelector: '[role="bar"]', spinnerSelector: '[role="spinner"]', parent: 'body', template: '
' }; /** * Updates configuration. * * NProgress.configure({ * minimum: 0.1 * }); */ NProgress.configure = function(options) { var key, value; for(key in options) { value = options[key]; if(value !== undefined && options.hasOwnProperty(key)) Settings[key] = value; } return this; }; /** * Last number. */ NProgress.status = null; /** * Sets the progress bar status, where `n` is a number from `0.0` to `1.0`. * * NProgress.set(0.4); * NProgress.set(1.0); */ NProgress.set = function(n) { var started = NProgress.isStarted(); n = clamp(n, Settings.minimum, 1); NProgress.status = (n === 1 ? null : n); var progress = NProgress.render(!started), bar = progress.querySelector(Settings.barSelector), speed = Settings.speed, ease = Settings.easing; progress.offsetWidth; /* Repaint */ queue(function(next) { // Set positionUsing if it hasn't already been set if(Settings.positionUsing === '') Settings.positionUsing = NProgress.getPositioningCSS(); // Add transition css(bar, barPositionCSS(n, speed, ease)); if(n === 1) { // Fade out css(progress, { transition: 'none', opacity: 1 }); progress.offsetWidth; /* Repaint */ setTimeout(function() { css(progress, { transition: 'all ' + speed + 'ms linear', opacity: 0 }); setTimeout(function() { NProgress.remove(); next(); }, speed); }, speed); } else { setTimeout(next, speed); } }); return this; }; NProgress.isStarted = function() { return typeof NProgress.status === 'number'; }; /** * Shows the progress bar. * This is the same as setting the status to 0%, except that it doesn't go backwards. * * NProgress.start(); * */ NProgress.start = function() { if(!NProgress.status) NProgress.set(0); var work = function() { setTimeout(function() { if(!NProgress.status) return; NProgress.trickle(); work(); }, Settings.trickleSpeed); }; if(Settings.trickle) work(); return this; }; /** * Hides the progress bar. * This is the *sort of* the same as setting the status to 100%, with the * difference being `done()` makes some placebo effect of some realistic motion. * * NProgress.done(); * * If `true` is passed, it will show the progress bar even if its hidden. * * NProgress.done(true); */ NProgress.done = function(force) { if(!force && !NProgress.status) return this; return NProgress.inc(0.3 + 0.5 * Math.random()).set(1); }; /** * Increments by a random amount. */ NProgress.inc = function(amount) { var n = NProgress.status; if(!n) { return NProgress.start(); } else if(n > 1) { return; } else { if(typeof amount !== 'number') { if(n >= 0 && n < 0.25) { // Start out between 3 - 6% increments amount = (Math.random() * (5 - 3 + 1) + 3) / 100; } else if(n >= 0.25 && n < 0.65) { // increment between 0 - 3% amount = (Math.random() * 3) / 100; } else if(n >= 0.65 && n < 0.9) { // increment between 0 - 2% amount = (Math.random() * 2) / 100; } else if(n >= 0.9 && n < 0.99) { // finally, increment it .5 % amount = 0.005; } else { // after 99%, don't increment: amount = 0; } } n = clamp(n + amount, 0, 0.994); return NProgress.set(n); } }; NProgress.trickle = function() { return NProgress.inc(); }; /** * Waits for all supplied jQuery promises and * increases the progress as the promises resolve. * * @param $promise jQUery Promise */ (function() { var initial = 0, current = 0; NProgress.promise = function($promise) { if(!$promise || $promise.state() === "resolved") { return this; } if(current === 0) { NProgress.start(); } initial++; current++; $promise.always(function() { current--; if(current === 0) { initial = 0; NProgress.done(); } else { NProgress.set((initial - current) / initial); } }); return this; }; })(); /** * (Internal) renders the progress bar markup based on the `template` * setting. */ NProgress.render = function(fromStart) { if(NProgress.isRendered()) return document.getElementById('nprogress'); addClass(document.documentElement, 'nprogress-busy'); var progress = document.createElement('div'); progress.id = 'nprogress'; progress.innerHTML = Settings.template; var bar = progress.querySelector(Settings.barSelector), perc = fromStart ? '-100' : toBarPerc(NProgress.status || 0), parent = document.querySelector(Settings.parent), spinner; css(bar, { transition: 'all 0 linear', transform: 'translate3d(' + perc + '%,0,0)' }); if(!Settings.showSpinner) { spinner = progress.querySelector(Settings.spinnerSelector); spinner && removeElement(spinner); } if(parent != document.body) { addClass(parent, 'nprogress-custom-parent'); } parent.appendChild(progress); return progress; }; /** * Removes the element. Opposite of render(). */ NProgress.remove = function() { removeClass(document.documentElement, 'nprogress-busy'); removeClass(document.querySelector(Settings.parent), 'nprogress-custom-parent'); var progress = document.getElementById('nprogress'); progress && removeElement(progress); }; /** * Checks if the progress bar is rendered. */ NProgress.isRendered = function() { return !!document.getElementById('nprogress'); }; /** * Determine which positioning CSS rule to use. */ NProgress.getPositioningCSS = function() { // Sniff on document.body.style var bodyStyle = document.body.style; // Sniff prefixes var vendorPrefix = ('WebkitTransform' in bodyStyle) ? 'Webkit' : ('MozTransform' in bodyStyle) ? 'Moz' : ('msTransform' in bodyStyle) ? 'ms' : ('OTransform' in bodyStyle) ? 'O' : ''; if(vendorPrefix + 'Perspective' in bodyStyle) { // Modern browsers with 3D support, e.g. Webkit, IE10 return 'translate3d'; } else if(vendorPrefix + 'Transform' in bodyStyle) { // Browsers without 3D support, e.g. IE9 return 'translate'; } else { // Browsers without translate() support, e.g. IE7-8 return 'margin'; } }; /** * Helpers */ function clamp(n, min, max) { if(n < min) return min; if(n > max) return max; return n; } /** * (Internal) converts a percentage (`0..1`) to a bar translateX * percentage (`-100%..0%`). */ function toBarPerc(n) { return(-1 + n) * 100; } /** * (Internal) returns the correct CSS for changing the bar's * position given an n percentage, and speed and ease from Settings */ function barPositionCSS(n, speed, ease) { var barCSS; if(Settings.positionUsing === 'translate3d') { barCSS = { transform: 'translate3d(' + toBarPerc(n) + '%,0,0)' }; } else if(Settings.positionUsing === 'translate') { barCSS = { transform: 'translate(' + toBarPerc(n) + '%,0)' }; } else { barCSS = { 'margin-left': toBarPerc(n) + '%' }; } barCSS.transition = 'all ' + speed + 'ms ' + ease; return barCSS; } /** * (Internal) Queues a function to be executed. */ var queue = (function() { var pending = []; function next() { var fn = pending.shift(); if(fn) { fn(next); } } return function(fn) { pending.push(fn); if(pending.length == 1) next(); }; })(); /** * (Internal) Applies css properties to an element, similar to the jQuery * css method. * * While this helper does assist with vendor prefixed property names, it * does not perform any manipulation of values prior to setting styles. */ var css = (function() { var cssPrefixes = ['Webkit', 'O', 'Moz', 'ms'], cssProps = {}; function camelCase(string) { return string.replace(/^-ms-/, 'ms-').replace(/-([\da-z])/gi, function(match, letter) { return letter.toUpperCase(); }); } function getVendorProp(name) { var style = document.body.style; if(name in style) return name; var i = cssPrefixes.length, capName = name.charAt(0).toUpperCase() + name.slice(1), vendorName; while(i--) { vendorName = cssPrefixes[i] + capName; if(vendorName in style) return vendorName; } return name; } function getStyleProp(name) { name = camelCase(name); return cssProps[name] || (cssProps[name] = getVendorProp(name)); } function applyCss(element, prop, value) { prop = getStyleProp(prop); element.style[prop] = value; } return function(element, properties) { var args = arguments, prop, value; if(args.length == 2) { for(prop in properties) { value = properties[prop]; if(value !== undefined && properties.hasOwnProperty(prop)) applyCss(element, prop, value); } } else { applyCss(element, args[1], args[2]); } } })(); /** * (Internal) Determines if an element or space separated list of class names contains a class name. */ function hasClass(element, name) { var list = typeof element == 'string' ? element : classList(element); return list.indexOf(' ' + name + ' ') >= 0; } /** * (Internal) Adds a class to an element. */ function addClass(element, name) { var oldList = classList(element), newList = oldList + name; if(hasClass(oldList, name)) return; // Trim the opening space. element.className = newList.substring(1); } /** * (Internal) Removes a class from an element. */ function removeClass(element, name) { var oldList = classList(element), newList; if(!hasClass(element, name)) return; // Replace the class name. newList = oldList.replace(' ' + name + ' ', ' '); // Trim the opening and closing spaces. element.className = newList.substring(1, newList.length - 1); } /** * (Internal) Gets a space separated list of the class names on the element. * The list is wrapped with a single space on each end to facilitate finding * matches within the list. */ function classList(element) { return(' ' + (element && element.className || '') + ' ').replace(/\s+/gi, ' '); } /** * (Internal) Removes an element from the DOM. */ function removeElement(element) { element && element.parentNode && element.parentNode.removeChild(element); } return NProgress; }); }, {}]; var cuiNumberRollImpl = [function(require, module, exports) { /* * @desc numberRoll组件 * @anthor pwang * @Date 2016-04-29 */ var digitTpl = template.compile(require("./numroll_digit.tpl")), numberTpl = template.compile(require("./numroll_number.tpl")), pointTpl = template.compile(require("./numroll_point.tpl")), valueTpl = template.compile(require("./numroll_value.tpl")); module.exports = function() { $.cuiFactory("cuiNumberRoll", { options: { initNum: 0, comma: true, digit: false }, _create: function() { var toNum = this.options.initNum - 0; this.currentNum = toNum; this._createDom(); if(toNum !== 0) { this._moveTo(0, toNum); } }, _createDom: function() { var $el = this.$el, domTpl = valueTpl(), numberHtml = numberTpl({ type: "integer" }); $el.addClass("cui-number-roll"); $el.append(domTpl); $el.find(".cui-number-roll-val").before(numberHtml); //获取高度 this.numHeight = parseInt($el.find(".cui-number-content").css("font-size")) || $el.find(".cui-number-content").height(); }, _moveTo: function(start, end) { var digit = this.options.digit, end = digit ? end / (digit.unitNum) : end, end = digit.formatter ? digit.formatter(end) : end, $itgArr = [].reverse.call(this.$el.find(".cui-integer-number")), $flArr = this.$el.find(".cui-float-number"), compareObj = this._compare(start, end), itgChangeObj = compareObj.itgChangeObj, flChangeObj = compareObj.flChangeObj, len1 = Math.max($itgArr.length, itgChangeObj.length), len2 = Math.max($flArr.length, flChangeObj.length), i = 0, j = 0; //整数 for(; i < len1; i++) { (function(index, that) { var $itg = $itgArr.eq(index), changeObj = itgChangeObj[index]; if(changeObj.index == undefined) {} else if($itg.length == 0) { that._mvUnToNum.call(that, undefined, changeObj.to); } else if(!changeObj.to) { that._mvNumToUn.call(that, changeObj.from, undefined, $itgArr.eq(i)); } else { that._mvNumToNum.call(that, changeObj.from, changeObj.to, $itgArr.eq(i)); } })(i, this); } //小数部分 if(flChangeObj.length !== 0 && flChangeObj[0].to === undefined) { this._deleteAllFl(); } else if(flChangeObj.length !== 0 && $flArr.length === 0) { this._addFloatPoint(); } for(; j < len2; j++) { (function(index, that) { var $fl = $flArr.eq(index), changeObj = flChangeObj[index], boolA = changeObj.to == undefined ? "0" : "1", boolB = $fl.length === 0 ? "0" : "1", bool = boolA + boolB; switch(bool) { case "00": { break; }; case "01": { that._mvNumToUn.call(that, changeObj.from, undefined, $fl); break; }; case "10": { that._mvUnToNum.call(that, undefined, changeObj.to, "float"); break; }; case "11": { that._mvNumToNum.call(that, changeObj.from, changeObj.to, $fl); break; }; } })(j, this); } if(digit && this.$el.find(".cui-digit-number").length === 0) { this.$el.find(".cui-number-roll-val").after(digitTpl({ type: 'digit', name: digit.unit })) } this._setCurrentNum(end); }, //删除 _deleteAllFl: function() { this.$el.find(".cui-float-number").remove(); this.$el.find(".cui-fl-point-number").remove(); }, //增加小数点 _addFloatPoint: function() { var flPointTpl = pointTpl({ type: "fl-point" }); this.$el.find(".cui-number-roll-val").before(flPointTpl); }, _mvNumToNum: function(from, to, $dom) { var fromNum = from - 0, toNum = 0 - to, numHeight = this.numHeight; if(from === to) { $dom.find(".cui-number-content").removeClass("hide"); return; } $dom.find(".cui-other").removeClass("hide"); $dom.find(".cui-number-content").addClass("hide"); $dom.find(".cui-other").animate({ top: this.numHeight * toNum }, function() { $dom.find(".cui-number-content").text(-toNum); $dom.find(".cui-number-content").removeClass("hide"); $dom.find(".cui-other").addClass("hide"); }); }, _mvUnToNum: function(from, to, type) { var $el = this.$el, type = type || "integer", $numberTpl = $(numberTpl({ type: type })); if(type === "integer") { $el.find(".cui-number").eq(0).before($numberTpl); } else { $el.find(".cui-number-roll-val").before($numberTpl); } $el.find(".cui-other").removeClass("hide"); if(to !== ",") { var toNum = 0 - to; $numberTpl.find(".cui-other").animate({ top: this.numHeight * toNum }, function() { $numberTpl.find(".cui-number-content").text(-toNum || to); $numberTpl.find(".cui-number-content").removeClass("hide"); $el.find(".cui-other").addClass("hide"); }) } else { $numberTpl.addClass("cui-number-comma"); $numberTpl.find(".cui-other").css("top", -this.numHeight * 10); $numberTpl.find(".cui-number-content").text(-toNum || to); $numberTpl.find(".cui-number-content").removeClass("hide"); $el.find(".cui-other").addClass("hide"); } }, _mvNumToUn: function(from, to, $dom) { $dom.remove(); }, _compare: function(start, end) { var startObj = this._numberToObj(start), startObjFlArr = startObj.flArr, startObjItgArr = startObj.itgArr, endObj = this._numberToObj(end), endObjFlArr = endObj.flArr, endObjItgArr = endObj.itgArr, i = 0, j = 0, intChangeArr = [], flChangeArr = []; //比较整数部分和小数部分 var len1 = Math.max(startObjItgArr.length, endObjItgArr.length); var len2 = Math.max(startObjFlArr.length, endObjFlArr.length); var itgChangeObj = this._getCompareObj(startObjItgArr, endObjItgArr, len1); var flChangeObj = this._getCompareObj(startObjFlArr, endObjFlArr, len2); return { itgChangeObj: itgChangeObj, flChangeObj: flChangeObj } }, _getCompareObj: function(startObjArr, endObjArr, length) { var i = 0, changeArr = []; for(; i < length; i++) { if(i === startObjArr) { for(; i < endObjArr.lenth; i++) { changeArr.push({ index: i, from: undefined, to: endObjItgArr[i] }); } break; } if(i === endObjArr) { for(; i < startObjArr.lenth; i++) { changeArr.push({ index: i, from: startObjArr[i], to: undefined }); } break; } changeArr.push(this._computeChange(startObjArr[i], endObjArr[i], i)); } return changeArr; }, _numberToObj: function(num) { var numStr = String(num), numObj = numStr.split("."), flStr = numObj.length === 2 ? numObj[1] : "", itgStr = this._isNeedComma() ? this._addComma(numObj[0]) : this._reverseString(numObj[0]); return { flArr: this._stringToArr(flStr), itgArr: this._stringToArr(itgStr) } }, _reverseString: function(str) { return str.split("").reverse().join(""); }, _isNeedComma: function() { return this.options.comma; }, _addComma: function(intStr) { var intArrRev = this._stringToArr(intStr).reverse(), newIntStr = ""; for(var i = 0, len = intArrRev.length; i < len; i++) { if(i !== 0 && i % 3 == 0) { newIntStr += ","; } newIntStr += intArrRev[i]; } return newIntStr; }, _computeChange: function(start, end, i) { return { index: i, from: start, to: end } }, _stringToArr: function(str) { return str.split(""); }, _getCurrentNum: function() { return this.currentNum || 0; }, _setCurrentNum: function(currentNum) { this.currentNum = currentNum; this.$el.find(".cui-number-roll-val").val(currentNum); }, // 对外方法集 invoke: { setNumber: function(target) { this._moveTo(this.currentNum, target); }, getNumber: function() { return this._getCurrentNum(); } } }); } }, { "./numroll_digit.tpl": [function(require, module, exports) { module.exports = "
\n
\n
{{name}}
\n
\n
"; }, {}], "./numroll_number.tpl": [function(require, module, exports) { module.exports = "
\n
\n
0
\n
    \n
  • 0
  • \n
  • 1
  • \n
  • 2
  • \n
  • 3
  • \n
  • 4
  • \n
  • 5
  • \n
  • 6
  • \n
  • 7
  • \n
  • 8
  • \n
  • 9
  • \n
  • ,
  • \n
\n
\n
"; }, {}], "./numroll_point.tpl": [function(require, module, exports) { module.exports = "
\n
\n
.
\n
\n
"; }, {}], "./numroll_value.tpl": [function(require, module, exports) { module.exports = ""; }, {}] }]; var cuiOperateImpl = [function(require, module, exports) { var Position = require("../position/index"); panelTpl = template.compile(require("./panel.tpl")), module.exports = function() { $.cuiFactory("cuiOperate", { options: { // 操作板子集打开方式,可以选择click|hover,默认为click trigger: 'click', // 延时打开操作板子集(ms),当trigger为hover时生效 delay: 150, /**操作面板数据集合,如果操作项中有复制剪切板功能的多传一个字段copyContent,目前只支持一级剪切板:[{iconClass:"",text:"",id:"",pid:"",copyContent:"",disable:false},{iconClass:"",text:"",id:"",pid:""}]**/ data: [], //打开操作板的目标元素 target: '', // 操作面板位置偏移量,用于微调,默认值为[0,0] offset: [0, 0], //放在触发元素的哪一侧 placement: 'auto', //位置,绝对位置 position: null, //放置面板的父元素 content: null, //打开回调函数 // onOpen: function() {}, //关闭回调函数 // onClose: function() {}, //点击后的回调 // onSelected: function(option,target){}, //增加打开之前的回调 // beforeOpen: function(){} }, // 事件 events: { 'mouseover .expand-menu>li': function(self, evt) { if(this.options.trigger == "hover") { var index = $(self).attr("index"), id = this.mainList[index].id; $(self).siblings(".open").children(".second-menu").remove(); if($(self).hasClass("cui-disable")) { return; } $(self).addClass("open"); this.subOneList = this._createList(id); this.layoutRule.vertical = 'bottom'; this._createSubDom(this._preRenderData(this.subOneList, 1, self), self); } //return false; }, 'mouseleave .cui-operate': function(self, evt) { //return false; }, 'mouseover .first-menu>li': function(self, evt) { if(this.options.trigger == "hover") { $(self).parent().next().find("li.open").children(".second-menu").remove(); } //return false; }, 'mouseover .second-menu>li': function(self, evt) { if(this.options.trigger == "hover") { var index = $(self).attr("index"), id = this.subOneList[index].id; $(self).siblings(".open").children(".third-menu").remove(); if($(self).hasClass("cui-disable")) { return; } if(this.subOneList[index].hasChild) { $(self).addClass("open"); this.subTwoList = this._createList(id); this.layoutRule.vertical = 'bottom'; this._createSubDom(this._preRenderData(this.subTwoList, 2, self), self); } } //return false; }, 'click .expand-menu>li': function(self, evt) { if(this.options.trigger == "click") { var index = $(self).attr("index"), id = this.mainList[index].id; $(self).siblings(".open").children(".second-menu").remove(); if($(self).hasClass("cui-disable")) { return; } $(self).addClass("open"); this.subOneList = this._createList(id); this.layoutRule.vertical = 'bottom'; this._createSubDom(this._preRenderData(this.subOneList, 1, self), self); } return false; }, 'click .first-menu>li': function(self, evt) { var index = $(self).attr("index"); $(self).parent().next().find("li.open").children(".second-menu").remove(); if($(self).hasClass("cui-disable")) { return; } this._emit('selected', [this.mainList[index], this.$target]); this._iCall('close'); return false; }, 'click .second-menu>li': function(self, evt) { var index = $(self).attr("index"), id = this.subOneList[index].id; if(this.options.trigger == "click") { $(self).siblings(".open").children(".third-menu").remove(); if($(self).hasClass("cui-disable")) { return; } if(this.subOneList[index].hasChild) { $(self).addClass("open"); this.subTwoList = this._createList(id); this.layoutRule.vertical = 'bottom'; this._createSubDom(this._preRenderData(this.subTwoList, 2, self), self); } else { this._emit('selected', [this.subOneList[index], this.$target]); this._iCall('close'); } } else if(this.options.trigger == "hover") { if($(self).hasClass("cui-disable")) { return; } if(!this.subOneList[index].hasChild) { this._emit('selected', [this.subOneList[index], this.$target]); this._iCall('close'); } } return false; }, 'click .third-menu>li': function(self, evt) { if($(self).hasClass("cui-disable")) { return; } var index = $(self).attr("index"); this._emit('selected', [this.subTwoList[index], this.$target]); this._iCall('close'); return false; } }, //创建组件入口 _create: function() { this.$target = null; if(this.options.data != null && this.options.data.length > 0) { if(this.options.position) { this.openType = 0; this._initData(); this._openByPosition(); this._bindOuterClick(); } else { this.openType = 1; this._initData(); this._openOverLay(); this.$target = $(this.options.target); } } }, //如果是坐标初始化需绑定该事件 _bindOuterClick: function() { var self = this; $(document).on('click.cuiOperate', function(e) { if($(e.target).parents('.cui-operate').size() < 1 && !$(e.target).is('.cui-operate') && $(e.target).parents('.cui-operate').size() < 1 && !$(e.target).is('.cui-operate')) { self._iCall('close'); $(document).off('click.cuiOperate'); } }); }, //初始化数据 _initData: function() { //初始化全局变量 this._initParam(); //整合数据 this._tidyData(); }, //初始化全局变量 _initParam: function() { this.layoutRule = { horizontal: 'right', vertical: 'bottom' }; this.mainList = []; this.subOneList = []; this.subTwoList = []; }, //整合数据 _tidyData: function() { this.mainList = this._createList("0"); this._createDom(this._preRenderData(this.mainList, 0)); }, //创建数据 _createList: function(id) { var list = this.options.data, tempList = [], returnlist = [], num = 0, tempObj = null; for(var i = 0, len = list.length; i < len; i++) { if(list[i].pid == id) { tempList.push(list[i]); } } for(var i = 0, len = tempList.length; i < len; i++) { for(var j = 0, lens = list.length; j < lens; j++) { if(tempList[i].id == list[j].pid) { tempList[i].hasChild = true; break; } } if(tempList[i].hasChild) { returnlist.push(tempList[i]); } else { returnlist.unshift(tempList[i]); } } tempList = []; for(var i = 0; i < returnlist.length; i++) { if(!returnlist[i].hasChild) { tempList.push(returnlist[i]); num++; } }; tempList.reverse(); returnlist.splice(0, num); return tempList.concat(returnlist); }, //准备渲染的数据 _preRenderData: function(list, level, parentNode) { var options = this.options, hasChild = false, _renderData = {}; for(var i = 0, len = list.length; i < len; i++) { if(list[i].hasChild) { hasChild = true; break; }; }; if(parentNode) { this._judgeLayOut(parentNode, list); } return _renderData = { hasChild: hasChild, list: list, level: level, layout: this.layoutRule }; }, //创建dom节点 _createDom: function(_renderData) { var html = panelTpl(_renderData), outerContent = this.options.content; if(this.openType) { var $el = this.$el; $el.addClass('cui-operate').addClass("opt-panel"); $el.empty().append(html); if(outerContent) { outerContent.append($el); } else { $('body').append($el); } } else { this.$el.addClass('cui-operate').addClass("opt-panel").empty().append(html); if(outerContent) { outerContent.append($el); } else { $('body').append(this.$el); } } }, //创建子dom节点 _createSubDom: function(_renderData, parentNode) { var html = panelTpl(_renderData), $el = this.$el; if($(parentNode).has("ul").length == 0) { $(html).appendTo($(parentNode)); } }, //按照position方式打开 _openByPosition: function() { var position = this.options.position, $el = this.$el, thisLeft = position.left, //left值 thisTop = position.top, thisHeight = $el.outerHeight(), thisWidth = $el.outerWidth(), left = position.left, //left值 top = position.top, win = { height: $(window).height(), width: $(window).width(), scrollTop: $(window).scrollTop(), scrollLeft: $(window).scrollLeft() }; $el.find(".operate-arrow").removeClass("left-arrow right-arrow bottom-arrow opposite").addClass("left-arrow"); if(win.width + win.scrollLeft - thisLeft - thisWidth < 0) { $el.find(".operate-arrow").removeClass("left-arrow right-arrow bottom-arrow opposite").addClass("right-arrow"); left = thisLeft - thisWidth; } if(win.height + win.scrollTop - thisTop - thisHeight < 0) { $el.find(".operate-arrow").removeClass("left-arrow right-arrow bottom-arrow opposite").addClass("left-arrow"); top = thisTop - thisHeight; $el.find(".operate-arrow").addClass("opposite"); } if(win.height + win.scrollTop - thisTop - thisHeight < 0 && win.width + win.scrollLeft - thisLeft - thisWidth < 0) { $el.find(".operate-arrow").removeClass("left-arrow right-arrow bottom-arrow opposite").addClass("right-arrow"); left = thisLeft - thisWidth; top = thisTop - thisHeight; $el.find(".operate-arrow").addClass("opposite"); } $el.css("left", left); $el.css("top", top); }, //判断错位展示 _judgeLayOut: function(target, list) { var position = Position.location(target, "fixed"), result = {}, layoutRule = this.layoutRule; if(position.right - 191 >= 0) { result.right = true; } else { result.right = false; } if(position.left - 191 >= 0) { result.left = true; } else { result.left = false; } if(position.top - ((list.length - 1) * 30 + 6) >= 0) { result.top = true; } else { result.top = false; } if(position.bottom - ((list.length - 1) * 30 + 6) >= 0) { result.bottom = true; } else { result.bottom = false; } if(layoutRule.horizontal == "right") { if(result.right) { layoutRule.horizontal = "right"; } else { if(result.left) { layoutRule.horizontal = "left"; } else { layoutRule.horizontal = "right"; } } } if(layoutRule.horizontal == "left") { if(result.left) { layoutRule.horizontal = "left"; } else { if(result.right) { layoutRule.horizontal = "right"; } else { layoutRule.horizontal = "left"; } } } if(layoutRule.vertical == "bottom") { if(result.bottom) { layoutRule.vertical = "bottom"; } else { if(result.top) { layoutRule.vertical = "top"; } else { layoutRule.vertical = "bottom"; } } } if(layoutRule.vertical == "top") { if(result.top) { layoutRule.vertical = "top"; } else { if(result.bottom) { layoutRule.vertical = "bottom"; } else { layoutRule.vertical = "top"; } } } }, //用overlay打开 _openOverLay: function() { var options = this.options, thisEl = this.$el, self = this, elem = options.target, trig = options.trigger, delay = options.delay, placement = this.options.placement, thisHeight = this.$el.outerHeight(), //气泡高度 thisWidth = this.$el.outerWidth(), //气泡宽度 x = options.offset[0], //x轴偏移量 y = options.offset[1], //y轴偏移量 outerContent = options.content, win = { height: $(window).height(), width: $(window).width(), scrollTop: $(window).scrollTop(), scrollLeft: $(window).scrollLeft() }; thisEl.cuiOverlay({ target: $(elem), triggerType: trig, delay: delay, parentNode: outerContent, align: { // 基准定位元素,默认为当前的可视区域 baseElement: elem, // 基准定位元素的定位点,默认为左上角 baseXY: [0, 0], direction: 'v', alignType: -1, centerDist: 10, isSuitable: true } }).on('close.cuiOverlay', function() { self._iCall('close'); }).on('afterSetPosition.cuiOverlay', function(ev, $dom, afterAlign) { var direction, alignType; var directionType = { 'right': 'left', 'left': 'right', 'top': 'bottom', 'bottom': 'top' } if(afterAlign && afterAlign.direction && afterAlign.alignType) { direction = afterAlign.direction.toLowerCase(); alignType = afterAlign.alignType; thisEl.find(".operate-arrow").removeClass("left-arrow bottom-arrow opposite").addClass(directionType[direction] + "-arrow"); if(afterAlign.alignType === -1) { thisEl.find(".operate-arrow").addClass('opposite'); } } }).on('beforeOpen.cuiOverlay', function(ev, $dom, $el) { return; win = { height: $(window).height(), width: $(window).width(), scrollTop: $(window).scrollTop(), scrollLeft: $(window).scrollLeft() }; $('body').find(".cui-operate").hide(); //self._initData(); self._emit('beforeOpen', [this.$el]); var baseXY, left = 0, top = 0, splitNum = 10, thisTop = $($el.target).offset().top, //top值 thisLeft = $($el.target).offset().left, //left值 tgtWidth = $($el.target).outerWidth(), tgtHeight = $($el.target).outerHeight(); switch(placement) { case 'left': left = -thisWidth - 10 + x; top = -15 + y; thisEl.find(".operate-arrow").removeClass("left-arrow bottom-arrow opposite").addClass("right-arrow"); baseXY = [left, top]; if(win.height + win.scrollTop - thisTop - thisHeight - y < 0) { left = -thisWidth - 10 + x; top = -thisHeight + y + 35; baseXY = [left, top]; thisEl.find(".operate-arrow").addClass("opposite"); } break; case 'right': left = +$($el.target).outerWidth() + 10 + x; top = -13 + y; thisEl.find(".operate-arrow").removeClass("left-arrow bottom-arrow opposite").addClass("left-arrow"); baseXY = [left, top]; if(win.height + win.scrollTop - thisTop - thisHeight - y < 0) { left = $($el.target).outerWidth() + 10 + x; top = -thisHeight + y + 35; baseXY = [left, top]; thisEl.find(".operate-arrow").addClass("opposite"); } break; case 'top': left = +x; top = -thisHeight - 5 + y; thisEl.find(".operate-arrow").removeClass("left-arrow right-arrow opposite").addClass("bottom-arrow"); baseXY = [left, top]; if(win.width + win.scrollLeft - thisLeft - thisWidth - x < 0) { left = -thisWidth + 40 + x; top = -thisHeight - 5 + y; baseXY = [left, top]; thisEl.find(".operate-arrow").addClass("opposite"); } break; case 'bottom': left = +x; top = 25 + y; thisEl.find(".operate-arrow").removeClass("left-arrow right-arrow bottom-arrow opposite"); baseXY = [left, top]; if(win.width + win.scrollLeft - thisLeft - thisWidth - x < 0) { left = -thisWidth + 40 + x; top = 25 + y; baseXY = [left, top]; thisEl.find(".operate-arrow").addClass("opposite"); } break; default: left = +x; top = 25 + y; thisEl.find(".operate-arrow").removeClass("left-arrow right-arrow bottom-arrow opposite"); baseXY = [left, top]; if(win.width + win.scrollLeft - thisLeft - tgtWidth - splitNum - thisWidth - x < 0 && win.height + win.scrollTop - thisTop - tgtHeight - splitNum - thisHeight - y >= 0) { //在左侧展示 left = -thisWidth + 40 + x; top = 25 + y; baseXY = [left, top]; thisEl.find(".operate-arrow").removeClass("left-arrow right-arrow bottom-arrow opposite"); thisEl.find(".operate-arrow").addClass("opposite"); } if(win.width + win.scrollLeft - thisLeft - tgtWidth - splitNum - thisWidth - x < 0 && win.height + win.scrollTop - thisTop - tgtHeight - splitNum - thisHeight - y < 0) { left = -thisWidth + 40 + x; top = -thisHeight + y; baseXY = [left, top]; thisEl.find(".operate-arrow").removeClass("left-arrow right-arrow bottom-arrow opposite"); thisEl.find(".operate-arrow").addClass("bottom-arrow opposite"); } if(win.width + win.scrollLeft - thisLeft - tgtWidth - splitNum - thisWidth - x >= 0 && win.height + win.scrollTop - thisTop - tgtHeight - splitNum - thisHeight - y < 0) { left = +x; top = -thisHeight + y; baseXY = [left, top]; thisEl.find(".operate-arrow").removeClass("left-arrow right-arrow bottom-arrow opposite"); thisEl.find(".operate-arrow").addClass("bottom-arrow"); } if(win.width + win.scrollLeft - thisLeft - tgtWidth - splitNum - thisWidth - x >= 0 && win.height + win.scrollTop - thisTop - tgtHeight - splitNum - thisHeight - y >= 0) { left = +x; top = 25 + y; baseXY = [left, top]; thisEl.find(".operate-arrow").removeClass("left-arrow right-arrow bottom-arrow opposite"); } if(win.width + win.scrollLeft - thisLeft - tgtWidth - splitNum - thisWidth - x < 0 && win.height + win.scrollTop - thisTop - tgtHeight - splitNum - thisHeight - y >= 0 && thisLeft - thisWidth - splitNum + x < 0) { left = +x; top = 25 + y; baseXY = [left, top]; thisEl.find(".operate-arrow").removeClass("left-arrow right-arrow bottom-arrow opposite"); } if(win.width + win.scrollLeft - thisLeft - tgtWidth - splitNum - thisWidth - x < 0 && win.height + win.scrollTop - thisTop - tgtHeight - splitNum - thisHeight - y < 0 && thisLeft - thisWidth - splitNum + x < 0) { left = +x; top = -thisHeight + y; baseXY = [left, top]; thisEl.find(".operate-arrow").removeClass("left-arrow right-arrow bottom-arrow opposite"); thisEl.find(".operate-arrow").addClass("bottom-arrow"); } if(win.height + win.scrollTop - thisTop - tgtHeight - splitNum - thisHeight - y < 0 && win.width + win.scrollLeft - thisLeft - tgtWidth - splitNum - thisWidth - x < 0 && thisTop - thisHeight - splitNum + y < 0) { left = -thisWidth + 40 + x; top = 25 + y; baseXY = [left, top]; thisEl.find(".operate-arrow").removeClass("left-arrow right-arrow bottom-arrow opposite"); thisEl.find(".operate-arrow").addClass("opposite"); } if(win.height + win.scrollTop - thisTop - tgtHeight - splitNum - thisHeight - y < 0 && win.width + win.scrollLeft - thisLeft - tgtWidth - splitNum - thisWidth - x >= 0 && thisTop - thisHeight - splitNum + y < 0) { left = +x; top = 25 + y; baseXY = [left, top]; thisEl.find(".operate-arrow").removeClass("left-arrow right-arrow bottom-arrow opposite"); } if(win.height + win.scrollTop - thisTop - tgtHeight - splitNum - thisHeight - y < 0 && win.width + win.scrollLeft - thisLeft - tgtWidth - splitNum - thisWidth - x < 0 && thisTop - thisHeight - splitNum + y < 0 && thisLeft - thisWidth - splitNum + x < 0) { left = +x; top = 25 + y; baseXY = [left, top]; thisEl.find(".operate-arrow").removeClass("left-arrow right-arrow bottom-arrow opposite"); } } $dom.cuiOverlay('align', { baseXY: baseXY }); }); }, // 组件对外方法集 invoke: { //打开操作面板 open: function() { var self = this; var timeOut = setTimeout(function() { self._create(); self._emit('open'); self.$el.show(); }, 50); }, //关闭操作面板 close: function() { //this.$el.html(""); this._emit('close'); this.$el.find(".second-menu,.third-menu").remove(); this.$el.hide(); $('body').find('.cui-mask-opacity').hide(); }, /* * @param {ObjArray} dataList 操作面板数据集合 */ data: function(dataList) { this.options.data = dataList; this._create(); }, /* * @param {obj} position 位置,绝对位置 */ position: function(position) { if(this.options.position) { this.options.position = position; this._create(); } }, /* * @param {obj} 触发弹出操作板的目标元素 */ target: function(target) { if(target) { this.$target = target; } } } }); } }, { "../position/index": 53, "./panel.tpl": [function(require, module, exports) { module.exports = "{{if level == 0}}\n
\n{{/if}}\n\n{{if hasChild == true && level == 0}}\n\t\n{{/if}}"; }, {}] }]; var cuiOverlayImpl = [function(require, module, exports) { var Position = require("../position/index"); /** * 提供浮出层的基本功能,包括显示方式,位置定位,resize位置调整等。 * @ version 1.0.0 */ module.exports = function() { $.cuiFactory("cuiOverlay", { options: { // 触发类型,默认为hover,也可以为click triggerType: 'hover', // 触发类型为hover时的延时时间 delay: 150, // 触发的元素 target: null, // 定位参数 align: { // element 的定位点,默认为左上角 selfXY: [0, 0], // 基准定位元素,默认为当前的可视区域 baseElement: Position.VIEWPORT, // 基准定位元素的定位点,默认为左上角 baseXY: [0, 0], direction: '>', alignType: 1 }, // 父元素 parentNode: document.body, // 是否需要高级定位 advPin: false, // 是否需要点击其他地方消失 blurHide: true, //是否需要展示时的动画 isNeedAnimation: false, // onOpen: function() { // }, // beforeOpen: function() { // }, // onClose: function() { // } }, _create: function() { var self = this, options = this.options, $targetElement = $(options.target), delay = options.delay, triggerType = options.triggerType; this.target = $targetElement; cuiOverlay.allOverlays.push(this); this.$el.addClass('cui-overlay'); // 支持hover if(triggerType === 'hover' && $targetElement) { $targetElement.on('mouseenter.' + this.uiName, function(e) { if($(this).hasClass('disabled')) return; clearTimeout(self.hideTime); self.target = this; self.showTime = setTimeout(function() { self._iCall('show'); }, delay); }).on('mouseleave.' + this.uiName, function() { if($(this).hasClass('disabled')) return; clearTimeout(self.showTime); self.hideTime = setTimeout(function(e) { self._iCall('hide'); }, delay); }); this.$el.on('mouseenter.' + this.uiName, function() { clearTimeout(self.hideTime); }); this.$el.on('mouseleave.' + this.uiName, function() { self.hideTime = setTimeout(function() { self._iCall('hide'); }, delay); }); } else if(triggerType === 'click' && $targetElement) { $targetElement.context = $targetElement.context && $targetElement.context != undefined ? $targetElement.context : $targetElement.parent(); $targetElement.live('click.' + this.uiName, function() { if($(this).hasClass('disabled')) return; self.target = this; self._iCall('show'); }); } else if(triggerType === 'focus' && $targetElement) { $targetElement.on('focus.' + this.uiName, function() { if($(this).hasClass('disabled')) return; self.target = this; self._iCall('show'); }); // 联想下拉blur引发bug. // $targetElement.on('blur', function() { // if ($(this).hasClass('disabled')) return; // self.target = this; // //self._iCall('hide'); // }); } this._blurHide(); }, _setPosition: function(align) { var options = this.options, advPin = options.advPin; align || (align = options.align); if(!align) return; if(advPin) { return this._setAdvPosition(align, advPin); } else { return this._setNomalPosition(align); } }, /* * 普通定位 */ _setNomalPosition: function(align) { var $el = this.$el, isHidden = $el.css('display') === 'none', parentNode = this.options.parentNode, baseXY = align.baseXY, direction = align.direction, alignType = align.alignType, isSuitable = align.isSuitable, afterAlign, centerDist = align.centerDist, selfXY = align.selfXY; //在定位时,为避免元素高度不定,先显示出来 if(isHidden) { $el.css({ visible: 'hidden', display: 'block' }); } if(parentNode !== document.body && parentNode !== $(document.body)) { afterAlign = Position.pin({ element: $el, x: selfXY[0], y: selfXY[1] }, { element: this.target, x: baseXY[0], y: baseXY[1] }, parentNode, direction, alignType, centerDist, isSuitable); } else { afterAlign = Position.pin({ element: $el, x: selfXY[0], y: selfXY[1] }, { element: this.target, x: baseXY[0], y: baseXY[1] }, undefined, direction, alignType, centerDist, isSuitable); } // 定位后还原 if(isHidden) { $el.css({ visibility: '', display: 'none' }); } return afterAlign; }, // 高级定位 _setAdvPosition: function(align, advPin) { var $el = this.$el, isHidden = $el.css('display') === 'none'; //在定位时,为避免元素高度不定,先显示出来 if(isHidden) { $el.css({ visible: 'hidden', display: 'block' }); } Position.advPin($el, align.baseElement, { offset: align.baseXY, direction: advPin.direction }); // 定位完成后,还原 if(isHidden) { $el.css({ visibility: '', display: 'none' }); } }, // 除了element和relativeElements, 点击body后都会隐藏 element _blurHide: function(arr) { if(!arr) cuiOverlay.blurOverlays.push(this); arr = $.makeArray(arr); arr.push(this.options.target); this._relativeElements = arr; }, //判断overlay展示在目标元素的哪个方位 _judgeDirection: function() { var result = {}, isHidden = this.$el.css('display') === 'none'; //在定位时,为避免元素高度不定,先显示出来 if(isHidden) { this.$el.css({ visible: 'hidden', display: 'block' }); } var self = this.$el, target = $(this.target), selfPos = { top: this.$el.offset().top, left: this.$el.offset().left }, targetPos = { top: target.offset().top, left: target.offset().left }; if(this.options.parentNode !== document.body && this.options.parentNode !== $(document.body)) { selfPos = { top: this.$el.position().top, left: this.$el.position().left }, targetPos = { top: target.position().top, left: target.position().left }; } if(selfPos.top >= targetPos.top + target.outerHeight()) { result.direction = "bottom"; } else if(targetPos.top >= selfPos.top + self.outerHeight()) { result.direction = "top"; } else if(selfPos.left >= targetPos.left + target.outerWidth()) { result.direction = "right"; } else if(targetPos.left >= selfPos.left + self.outerWidth()) { result.direction = "left"; } result.selfPos = selfPos; // 定位后还原 if(isHidden) { this.$el.css({ visibility: '', display: 'none' }); } return result; }, // 对外方法集 invoke: { show: function() { /* * fixed bugs 2014/9/19 */ // 关闭所有其他的overlay // $.each(cuiOverlay.allOverlays, function(i, item) { // // 当实例为空或隐藏时,不处理 // if (!item || !item.visible) { // return; // } // item._iCall('hide'); // }); // this.options.beforeOpen.call(this.$el, this); this._emit('beforeOpen', [this.$el, this]); this.visible = true; var afterAlign = this._setPosition(); this._emit('afterSetPosition', [this.$el, afterAlign]); if(this.options.isNeedAnimation) { var result = this._judgeDirection(), $el = this.$el, isHidden = $el.css('display') === 'none'; if(result.direction == "bottom") { $el.css("top", result.selfPos.top + 15); if(!isHidden) { $el.hide(); } $el.animate({ top: result.selfPos.top, opacity: 'show' }, 300); } else if(result.direction == "top") { $el.css("top", result.selfPos.top - 15); if(!isHidden) { $el.hide(); } $el.animate({ top: result.selfPos.top, opacity: 'show' }, 300); } else if(result.direction == "left") { $el.css("left", result.selfPos.left - 15); if(!isHidden) { $el.hide(); } $el.animate({ left: result.selfPos.left, opacity: 'show' }, 300); } else if(result.direction == "right") { $el.css("left", result.selfPos.left + 15); if(!isHidden) { $el.hide(); } $el.animate({ left: result.selfPos.left, opacity: 'show' }, 300); } else { $el.show(); } } else { this.$el.show(); } if(this.options.hasOpacity) { $('body').find('.cui-mask-opacity').show(); } // this.options.onOpen.call(this.$el, this); this._emit('open', [this.$el, this]); }, hide: function() { this.visible = false; this.$el.hide(); if(this.options.hasOpacity) { $('body').find('.cui-mask-opacity').hide(); } // this.options.onClose.call(this.$el, this); this._emit('close', [this.$el, this]); }, /** * 只做展示 */ showSelf: function() { this.visible = true; this.$el.show(); this.options.onOpen.call(this.$el, this); }, /** * 修改对齐配置 */ align: function(_align) { if(_align) { this.options.align = $.extend({}, this.options.align, _align); this._setPosition(this.options.align); } }, blurHide: function(arr) { this._blurHide(arr); }, destroyOverlay: function() { var self = this, options = this.options, $targetElement = $(options.target), delay = options.delay, triggerType = options.triggerType; function erase(target, array) { for(var i = 0, arrLen = array.length; i < arrLen; i++) { if(target === array[i]) { array.splice(i, 1); return array; } }; } erase(cuiOverlay.allOverlays, this); this.$el.unbind('.' + this.uiName).removeData(this.uiName); if(triggerType === 'hover' && $targetElement) { $targetElement.off('mouseover.' + this.uiName).off('mouseleave.' + this.uiName); this.$el.off('mouseover.' + this.uiName); this.$el.off('mouseleave.' + this.uiName); } else if(triggerType === 'click' && $targetElement) { $targetElement.context = $targetElement.context && $targetElement.context != undefined ? $targetElement.context : $targetElement.parent(); $targetElement.die('click.' + this.uiName); } else if(triggerType === 'focus' && $targetElement) { $targetElement.off('focus.' + this.uiName); } //$(document).unbind('.' + this.uiName); } } }); window.cuiOverlay = {}; cuiOverlay.allOverlays = []; cuiOverlay.blurOverlays = []; $(document).off('.cuiOverlay'); $(document).on('click.cuiOverlay', function(e) { hideBlurOverlays(e); }); // 绑定resie重新定位事件 var timeout, winWidth = $(window).width(), winHeight = $(window).height(); $(window).resize(function() { timeout && clearTimeout(timeout); timeout = setTimeout(function() { var winNewWidth = $(window).width(); var winNewHeight = $(window).height(); if(winWidth !== winNewWidth || winHeight !== winNewHeight) { $.each(cuiOverlay.allOverlays, function(i, item) { // 当实例为空或隐藏时,不处理 if(!item || !item.visible) { return; } item._setPosition(); }); winWidth = winNewWidth; winHeight = winNewHeight; } }, 80); }); // 点击其他区域隐藏 function hideBlurOverlays(e) { $.each(cuiOverlay.blurOverlays, function(index, item) { // 当实例为空或隐藏时,不做处理 if(!item || !item.visible) { return; } if(!item.options.blurHide) { return; } // 遍历_relativeElements, 当点击的元素落在这些元素上时,不处理 for(var i = 0, itemLen = item._relativeElements.length; i < itemLen; i++) { if(!!item._relativeElements[i].size() && $.contains($("body")[0], $(item._relativeElements[i])[0])) { if(item._relativeElements[i].selector) { if(item._relativeElements[i].size() == $(item._relativeElements[i].selector).size()) { for(var j = 0, len = item._relativeElements[i].length; j < len; j++) { var el = $(item._relativeElements[i][j])[0]; if(el === e.target || $.contains(el, e.target)) { return; } } } else { var els = $(item._relativeElements[i].selector); if(!!els.size()) { for(var k = 0, lens = els.length; k < lens; k++) { var el = $(els[k])[0]; if(el === e.target || $.contains(el, e.target)) { return; } } } } } else { for(var j = 0, len = item._relativeElements[i].length; j < len; j++) { var el = $(item._relativeElements[i][j])[0]; if(el === e.target || $.contains(el, e.target)) { return; } } } } else { var el = $(item._relativeElements[i])[0]; if(el == undefined || el == null || !$.contains($("body")[0], el)) { var els = $(item._relativeElements[i].selector); if(!!els.size()) { for(var k = 0, lens = els.length; k < lens; k++) { var el = $(els[k])[0]; if(el === e.target || $.contains(el, e.target)) { return; } } } else { //throw new Error("target元素不存在或者相关元素不存在!"); } } else { if(el === e.target || $.contains(el, e.target)) { return; } } } }; if(($(e.target).is('.cui-overlay') || !!$(e.target).closest('.cui-overlay').size()) && $(e.target).closest('.cui-overlay').is(item.$el)) { return; } // 隐藏对应元素 item._iCall('hide'); }); } } }, { "../position/index": 53 }]; var cuiPaginImpl = [function(require, module, exports) { /* * @desc cuiPagin,依赖于cuiUf */ var cuiDropdown = require("../../components/dropdown/index"), util = require("../../base/util/index"), template = require("../../../lib/template/template"), paginTpl = template.compile(require("./pagin.tpl")); module.exports = function() { $.cuiFactory("cuiPagin", { VERSION: '1.0.0', options: { // 分页类型,normal为正常型,simple为简单型。 type: 'normal', // 分页的样式大小,normal为正常,sm为小模式,lg 为大模式。 size: 'normal', showMsg: true, // 当前页码 current: 1, // total,总条数 total: null, // pageItems 每页显示条数 pageItems: 10, // 自定义每页显示条数 customPageItems: [10, 20, 50, 100, 200, 500], // 是否需要快速跳转,只有在normal时生效。 skipto: true, // 是否需要设置每页显示条数操作,只有在normal时生效 setPageItems: true, //页码显示形式,当type为normal时生效。 displayStyle: [2, 3, 2], //设置分页条数的面板的展示位置:down默认的朝下,up朝上 customPagePos: "down" }, _create: function() { var options = this.options, self = this; this.$el.addClass('cui-pagin clearfix').addClass('pagination-' + options.size); this._preRenderData(); }, events: { // 快速跳转事件 'focus input': function(self, evt) { $(self).val(this.current); $(self).select(); }, 'blur input': function(self, evt) { if($(self).hasClass('cui-disabled')) return false; var page = parseInt(util.DBC2SBC($(self).val())); if(page != this.current && page > 0 && page <= this.totalPages) { this._setCurrentPagin(page); } else { $(self).val(''); } }, // 页码点击事件 'click .pagin-no': function(self, evt) { var current = parseInt($(self).text(), 10); this._setCurrentPagin(current); }, 'keypress input': function(self, evt) { if(evt.keyCode === 13) { $(self).trigger('blur'); } }, // 按钮点击事件 'click .pagin-btn': function(self, evt) { if($(self).hasClass('disabled')) return false; if($(self).hasClass('homepage')) { this._setCurrentPagin(1); } else if($(self).hasClass('prev')) { this._prevPagin(); } else if($(self).hasClass('next')) { this._nextPagin(); } }, // 选择每页显示多少条事件 'click .dropdown-menu>li': function(self, evt) { var pageItems = +$(self).attr('data-items'), that = this; setTimeout(function() { that._iCall('pageItems', [pageItems]); that._emit('pageItemsChange', [pageItems, that.current]); }, 0) } }, // 上一页 _prevPagin: function() { var self = this, current; if(this.current > 1) { current = parseInt(this.current, 10) - 1; setTimeout(function() { self._setCurrentPagin(current); }, 0); } }, // 下一页 _nextPagin: function() { var self = this, current; if(this.current < this.totalPages) { current = parseInt(this.current, 10) + 1; setTimeout(function() { self._setCurrentPagin(current); }, 0); } }, // 准备所有需要渲染的数据 _preRenderData: function() { if(this.options.total === null) return; var options = this.options, _renderData = {}, total = this.records !== undefined ? this.records : options.total, pageItems = this.options.pageItems || (this.options.pageItems = options.customPageItems[0]), totalPages = this.totalPages = Math.ceil(total / pageItems), current = this.current || (this.current = options.current), startItems = pageItems * (current - 1) + 1, endItems = pageItems * current, list = this._paginList(); if(+total === 0) { this.$el.hide(); return; } else { this.$el.show(); } this._renderData = _renderData = { total: total, pageItems: pageItems, totalPages: totalPages, current: current, startItems: startItems, endItems: endItems, setPageItems: options.setPageItems, skipto: options.skipto, list: list, showMsg: options.showMsg, type: options.type, customPageItems: options.customPageItems }; this._createDom(); }, _setCurrentPagin: function(current, needEmit) { if(this.current === current) { return; } this.current = current; this._preRenderData(); if(needEmit !== false) { this._emit('pageNoChange', [current, this.options.pageItems]); } }, _paginList: function() { var options = this.options, interval = this._getInterval(), displayStyle = options.displayStyle, list = []; if(interval[0] > 0 && displayStyle[2] > 0) { var end = Math.min(displayStyle[2], interval[0]); for(var i = 0; i < end; i++) { this._addToPaginList(list, i); } if(displayStyle[2] < interval[0]) { list.push('...'); } } // 中间的页码 for(var i = interval[0]; i < interval[1]; i++) { this._addToPaginList(list, i); } if(interval[1] < this.totalPages && displayStyle[2] > 0) { // 点点点字符串 if(this.totalPages - displayStyle[2] > interval[1]) { // 将点点点添加到容器 list.push('...'); } var begin = Math.max(this.totalPages - displayStyle[2], interval[1]); for(var i = begin; i < this.totalPages; i++) { this._addToPaginList(list, i); } } return list; }, //获取页码中间的起始值(当时type为normal时生效) _getInterval: function() { var current = this.current - 1, options = this.options, displayStyle = options.displayStyle; //··中间和末尾显示页面的个数 var ne_half = parseInt(displayStyle[1]) + parseInt(displayStyle[2]); //··总页数 var pages = this.totalPages; //··总页数 - 中间显示页数 var upper_limit = pages - displayStyle[1]; //··计算中间显示页码的开始 var start = current + 1 >= ne_half ? Math.max(Math.min(parseInt(current) + 2 - displayStyle[1], upper_limit), 0) : 0; //··计算中间显示页码的结束 var end = current + 1 >= ne_half ? Math.min(parseInt(current) + 2, pages) : Math.min(ne_half, pages); return [start, end]; }, /* * 将分页信息添加到List中 */ _addToPaginList: function(list, id) { id = (id < 0 ? 0 : (id < this.totalPages ? id : this.totalPages - 1)), id++; list.push(id); }, _createDom: function() { var html = paginTpl(this._renderData); // remove dropdown this.$el.find('[data-toggle="cuiDropdown"]').cuiDropdown('destroy'); this.$el.empty().html(html); // init dropdown this.$el.find('[data-toggle="cuiDropdown"]').cuiDropdown({ panelPos: this.options.customPagePos }); }, // 对外方法 invoke: { /* * 修改总数据条数 * @param _total 需要修改的总记录条数 */ total: function(_total) { // if(this.options.total !== _total){ // this.current = 1; // } this.options.total = this.records = _total; this._preRenderData(); }, /* * 修改每页显示的记录条数。 * @param _pageItems 需要修改的总记录条数 */ pageItems: function(_pageItems) { this.options.pageItems = _pageItems; this.totalPages = Math.ceil(this.records / _pageItems); if(this.current > this.totalPages && this.totalPages > 0) { this.current = this.totalPages; this._emit('pageNoChange', [this.current, this.options.pageItems]); } this._preRenderData(); }, /* * 获取或者修改当前分页组件的页码 */ current: function(current) { if(!!current && current <= this.totalPages) { //this.current = current; //this._preRenderData(); this._setCurrentPagin(current, false); } else { return this.current; } }, /* * 跳转的某一页。 */ jumpTo: function(current) { if(!!current && current <= this.totalPages) { this._setCurrentPagin(current); } else { return this.current; } } } }); } }, { "../../../lib/template/template": 2, "../../base/util/index": 12, "../../components/dropdown/index": 21, "./pagin.tpl": [function(require, module, exports) { module.exports = "\uFEFF{{if type == \"normal\"}}\n\n{{if showMsg}}\n
\n\t共 {{total}} 条记录,当前显示 {{startItems}}-{{if endItems > total}}{{total}}{{else}}{{endItems}}{{/if}} 条\n
\n{{/if}}\n{{if setPageItems === true}}\n
\n \n \n
\n{{/if}}\n{{else}}\n\n{{/if}}"; }, {}], }]; var cuiPlaceholderImpl = [function(require, module, exports) { /*! http://mths.be/placeholder v2.0.8 by @mathias */ module.exports = function() { // Opera Mini v7 doesn’t support placeholder although its DOM seems to indicate so var isOperaMini = Object.prototype.toString.call(window.operamini) == '[object OperaMini]'; var isInputSupported = 'placeholder' in document.createElement('input') && !isOperaMini; var isTextareaSupported = 'placeholder' in document.createElement('textarea') && !isOperaMini; var prototype = $.fn; var valHooks = $.valHooks; var propHooks = $.propHooks; var hooks; var placeholder; if(isInputSupported && isTextareaSupported) { placeholder = prototype.cuiInput = function() { return this; }; placeholder.input = placeholder.textarea = true; } else { placeholder = prototype.cuiInput = function() { var $this = this; if($this.data('placeholder-enabled')) return; // 防止多次初始化 $this.filter((isInputSupported ? 'textarea' : ':input') + '[placeholder]').not('.placeholder').bind({ 'focus.placeholder': clearPlaceholder, 'blur.placeholder': setPlaceholder }).data('placeholder-enabled', true).trigger('blur.placeholder'); return $this; }; placeholder.input = isInputSupported; placeholder.textarea = isTextareaSupported; hooks = { 'get': function(element) { var $element = $(element); var $passwordInput = $element.data('placeholder-password'); if($passwordInput) { return $passwordInput[0].value; } return $element.data('placeholder-enabled') && $element.hasClass('cui-placeholder') ? '' : element.value; }, 'set': function(element, value) { var $element = $(element); var $passwordInput = $element.data('placeholder-password'); if($passwordInput) { return $passwordInput[0].value = value; } if(!$element.data('placeholder-enabled')) { return element.value = value; } if(value == '') { element.value = value; // Issue #56: Setting the placeholder causes problems if the element continues to have focus. if(element != safeActiveElement()) { // We can't use `triggerHandler` here because of dummy text/password inputs :( setPlaceholder.call(element); } } else if($element.hasClass('cui-placeholder')) { clearPlaceholder.call(element, true, value) || (element.value = value); } else { element.value = value; } // `set` can not return `undefined`; see http://jsapi.info/jquery/1.7.1/val#L2363 return $element; } }; if(!isInputSupported) { valHooks.input = hooks; propHooks.value = hooks; } if(!isTextareaSupported) { valHooks.textarea = hooks; propHooks.value = hooks; } $(function() { // Look for forms $(document).delegate('form', 'submit.placeholder', function() { // Clear the placeholder values so they don't get submitted var $inputs = $('.cui-placeholder', this).each(clearPlaceholder); setTimeout(function() { $inputs.each(setPlaceholder); }, 10); }); }); // Clear placeholder values upon page reload $(window).bind('beforeunload.placeholder', function() { $('.cui-placeholder').each(function() { this.value = ''; }); }); } function args(elem) { // Return an object of element attributes var newAttrs = {}; var rinlinejQuery = /^jQuery\d+$/; $.each(elem.attributes, function(i, attr) { if(attr.specified && !rinlinejQuery.test(attr.name)) { newAttrs[attr.name] = attr.value; } }); return newAttrs; } function clearPlaceholder(event, value) { var input = this; var $input = $(input); if(input.value == $input.attr('placeholder') && $input.hasClass('cui-placeholder')) { if($input.data('placeholder-password')) { $input = $input.hide().next().show().attr('id', $input.removeAttr('id').data('placeholder-id')); // If `clearPlaceholder` was called from `$.valHooks.input.set` if(event === true) { return $input[0].value = value; } $input.focus(); } else { input.value = ''; $input.removeClass('cui-placeholder'); input == safeActiveElement() && input.select(); } } } function setPlaceholder() { var $replacement; var input = this; var $input = $(input); var id = this.id; if(input.value == '') { if(input.type == 'password') { if(!$input.data('placeholder-textinput')) { try { $replacement = $input.clone().attr({ 'type': 'text' }); } catch(e) { $replacement = $('').attr($.extend(args(this), { 'type': 'text' })); } $replacement.removeAttr('name').data({ 'placeholder-password': $input, 'placeholder-id': id }).bind('focus.placeholder', clearPlaceholder); $input.data({ 'placeholder-textinput': $replacement, 'placeholder-id': id }).before($replacement); } $input = $input.removeAttr('id').hide().prev().attr('id', id).show(); // Note: `$input[0] != input` now! } $input.addClass('cui-placeholder'); $input[0].value = $input.attr('placeholder'); } else { $input.removeClass('cui-placeholder'); } } function safeActiveElement() { // Avoid IE9 `document.activeElement` of death // https://github.com/mathiasbynens/jquery-placeholder/pull/99 try { return document.activeElement; } catch(exception) {} } $('input[placeholder], textarea[placeholder]').cuiInput(); } }, {}]; var cuiPopoverImpl = [function(require, module, exports) { /* * @desc popover组件 */ var _position = require("../../base/position/index"); module.exports = function() { var cuiPopoverArr = []; $.cuiFactory("cuiPopover", { VERSION: '1.0.0', options: { animation: true, html: false, placement: '', selector: false, trigger: 'click', focusoutClose: true, title: '', content: '', delay: 0, container: false, viewport: { selector: 'body', padding: 0 } }, _create: function() { var options = this.options, self = this; // 绑定事件 var triggers = options.trigger, focusoutClose = options.focusoutClose, triggerArr = triggers.split(' '); for(var i = 0, len = triggerArr.length; i < len; i++) { var trigger = triggerArr[i]; if(trigger === 'click') { //this.$el.on('click.' + this.uiName, this.$el, $.proxy(this._toggle, this)); this.$el.on('click.' + this.uiName, this.$el, function(e) { self._toggle.call(self, $(e.target)); }); if(focusoutClose) { cuiPopoverArr.push(this.$el); } } else if(trigger !== 'manual') { var eventIn = trigger === 'hover' ? 'mouseenter' : 'focusin'; var eventOut = trigger === 'hover' ? 'mouseleave' : 'focusout'; (trigger === "focus") && cuiPopoverArr.push(this.$el); this.$el.on(eventIn + '.' + this.uiName, this.$el, $.proxy(this._enter, this)); this.$el.on(eventOut + '.' + this.uiName, this.$el, $.proxy(this._leave, this)); } } }, _enter: function() { var options = this.options, status = this.$el.data('cuiPopover').status, direction = this.options.placement, content = this.options.content, title = this.options.title, animation = this.options.animation; if(!status) { this.status = true; this._openPopover(direction, title, content, animation); } }, _leave: function() { var options = this.options, status = this.$el.data('cuiPopover').status; if(status) { this.status = false; this._closePopover(); } }, /** * * place 2 param */ _Place2Param: function() { var place = this.options.placement; var placeObj = { 'top': 1, 'right': 2, 'bottom': 3, 'left': 4 } return placeObj[place]; }, _toggle: function($target) { var popoverStatus = this.$el.data('cuiPopover').status, direction = this.options.placement, content = this._getContent(), title = this._getTitle(), animation = this.options.animation; if(!popoverStatus) { this._openPopover(direction, title, content, animation); } else if($target.closest(".popover")[0] !== this.popoverItem[0]) { this._closePopover(); } }, _openPopover: function(direction, title, content, animation) { this.status = true; this._emit('beforeShow', [this.$el]); var options = this.options, that = this, delay = this.options.delay; delay = typeof delay === "object" ? delay.hide : delay, html = '
' + '
' + '

' + title + '

' + '
' + content + '
' + '
', $html = $(html); if(this.popoverItem) { this.popoverItem.remove(); } this.popoverItem = $html; $html.css("display", "block"); if(!title) { $html.find(".popover-title").css("display", "none"); } if(options.html) { $html.find(".popover-content").html(options.content); } else { $html.find(".popover-content").text(options.content); } this._emit('show', [this.$el]); this.closeTimeout && clearTimeout(this.closeTimeout); this.openTimeout = setTimeout(function() { that.options.container ? $html.appendTo(that.options.container) : $html.insertAfter(that.$el); that._setPosition(that.$el, $html, options.placement); setTimeout(function() { $html.addClass("in"); setTimeout(function() { that._emit("shown", [that.$el, that.popoverItem]); }, 150); }, 0) }, delay) }, /* * return title * if title is function, return the function apply reslut; */ _getTitle: function() { var options = this.options, title; title = typeof options.title === 'function' ? options.title.call(this.$el[0]) : options.title; return title; }, _getContent: function() { var options = this.options, content; content = typeof options.content === 'function' ? options.content.call(this.$el[0]) : options.content; return content; }, _closePopover: function() { this._emit('hide', [this.$el, this.$html]); var animation = this.options.animation, delay = this.options.delay, delay = typeof this.options.delay === "object" ? delay.hide : delay, that = this; this.openTimeout && clearTimeout(this.openTimeout); this.closeTimeout = setTimeout(function() { that.popoverItem && that.popoverItem.removeClass("in"); setTimeout(function() { that.popoverItem && that.popoverItem.remove(); that.status = false; that._emit("hidden", [that.$el, that.popoverItem]); }, 150); }, delay) }, _setPosition: function($el, $html, direction) { $html.offset(_position.getPosition($el, $html, direction)); }, // 对外方法 invoke: { hide: function() { var options = this.options, status = this.$el.data('cuiPopover').status; this._closePopover(); }, show: function() { var options = this.options, status = this.$el.data('cuiPopover').status, direction = this.options.placement, content = this._getContent(), title = this._getTitle(), animation = this.options.animation; this._openPopover(direction, title, content, animation); }, toggle: function() { this._toggle(); }, content: function(content) { var options = this.options, $html = this.popoverItem, $el = this.$el, direction = options.placement; options.content = content; // if(options.html) { // $html.find(".popover-content").html(content); // } else { // $html.find(".popover-content").text(content); // } // this._setPosition($el,$html,direction); }, setContent: function(content) { var options = this.options, $html = this.popoverItem, $el = this.$el, direction = options.placement; options.content = content; if(options.html) { $html.find(".popover-content").html(content); } else { $html.find(".popover-content").text(content); } } } }) $(document).on("click.cuiPopoverHide", function(e) { var $target = $(e.target), $popover = null, $triggerElement = null, excuteArr = []; for(var i = 0, len = cuiPopoverArr.length; i < len; i++) { $triggerElement = cuiPopoverArr[i]; if($triggerElement.data("cuiPopover")) { $popover = $triggerElement.data("cuiPopover").popoverItem; if(($target.closest($triggerElement).length === 0 && $target !== $triggerElement) && ($target.closest($popover).length === 0 && $target !== $popover)) { $popover && $popover.hasClass("in") && $triggerElement.cuiPopover('hide'); } } } }) } }, { "../../base/position/index": 10 }]; var cuiPositionImpl = [function(require, module, exports) { /** * 实现多种定位方式 * @ version 1.0.0 */ ; (function() { var Position = {}, VIEWPORT = { _id: 'VIEWPORT', nodeType: 1 }, isPinFixed = false, //用来标示目标元素是否为fixed定位 ua = (window.navigator.userAgent || "").toLowerCase(), isIE6 = ua.indexOf("msie 6") !== -1, alignFunc = function(pinLength, baseLength, alignType) { return alignType === 0 ? (baseLength - pinLength) / 2 : alignType === -1 ? baseLength - pinLength : 0; }, directionType = { '^': function(pinElement, baseElement, alignType) { var pinLength = pinElement.outerWidth(), baseLength = baseElement.outerWidth(); return { x: alignFunc(pinLength, baseLength, alignType), y: -pinElement.outerHeight() } }, 'v': function(pinElement, baseElement, alignType) { var pinLength = pinElement.outerWidth(), baseLength = baseElement.outerWidth(); return { x: alignFunc(pinLength, baseLength, alignType), y: baseElement.outerHeight() } }, '>': function(pinElement, baseElement, alignType) { var pinLength = pinElement.outerHeight(), baseLength = baseElement.outerHeight(); return { x: baseElement.outerWidth(), y: alignFunc(pinLength, baseLength, alignType) } }, '<': function(pinElement, baseElement, alignType) { var pinLength = pinElement.outerHeight(), baseLength = baseElement.outerHeight(); return { x: -pinElement.outerWidth(), y: alignFunc(pinLength, baseLength, alignType) } } } Position.isOutLeft = function(left, pinElement, parentNode) { var offsetLeft = parentNode ? parentNode.offset().left : 0, scrollLeft = parentNode ? parentNode.scrollLeft() : 0, width = parentNode ? parentNode.outerWidth() : $(window).width(); return left < offsetLeft; } Position.isOutRight = function(left, pinElement, parentNode) { var offsetLeft = parentNode ? parentNode.offset().left : 0, scrollLeft = parentNode ? parentNode.scrollLeft() : 0, width = parentNode ? parentNode.outerWidth() : $(window).width(); return((left - offsetLeft - scrollLeft + pinElement.outerWidth()) > width); } Position.isOutTop = function(top, pinElement, parentNode) { var offsetTop = parentNode ? parentNode.offset().top : 0, scrollTop = parentNode ? parentNode.scrollTop() : 0, height = parentNode ? parentNode.outerHeight() : $(window).height(); return top < offsetTop; } Position.isOutBottom = function(top, pinElement, parentNode) { var offsetTop = parentNode ? parentNode.offset().top : 0, scrollTop = parentNode ? parentNode.scrollTop() : 0, height = parentNode ? parentNode.outerHeight() : $(window).height(); return((top - offsetTop - scrollTop + pinElement.outerHeight()) > height); } /** * 将目标元素相对于基准元素进行定位。 * @param {Obj} 目标元素 * @param {obj} 基准元素 */ Position.pin = function(pinObject, baseObject, parentNode, direction, alignType, centerDist, isSuitable) { var d = { '>': 'Right', '<': 'Left', '^': 'Top', 'v': 'Bottom' } var opp = { '>': '<', '<': '>', 'v': '^', '^': 'v' } var other = { '>': ['Top', 'Bottom'], '<': ['Top', 'Bottom'], '^': ['Left', 'Right'], 'v': ['Left', 'Right'] } var offset = Position.getPinOffset(pinObject, baseObject, parentNode, direction, alignType, centerDist); var pinElement = $(pinObject.element); var len = (direction === '<' || direction === '>') ? offset.left : offset.top; var inD1 = Position['isOut' + d[direction]](len, pinElement, parentNode); var inD2 = Position['isOut' + d[opp[direction]]](len, pinElement, parentNode); if(direction && alignType !== undefined && isSuitable) { if(inD1 && !inD2) { direction = opp[direction]; offset = Position.getPinOffset(pinObject, baseObject, parentNode, direction, alignType, centerDist); } var len1 = (direction === '<' || direction === '>') ? offset.top : offset.left; var len2 = (direction === '<' || direction === '>') ? offset.top : offset.left; var inD3 = Position['isOut' + other[direction][0]](len1, pinElement, parentNode); var inD4 = Position['isOut' + other[direction][1]](len2, pinElement, parentNode); alignType = inD3 ? (inD4 ? alignType : 1) : (inD4 ? -1 : alignType); offset = Position.getPinOffset(pinObject, baseObject, parentNode, direction, alignType, centerDist); } // 定位目标元素 pinElement.css({ left: offset.left, top: offset.top }); return { direction: d[direction], alignType: alignType } } Position.getPinOffset = function(pinObject, baseObject, parentNode, direction, alignType, centerDist) { var centerDistLeft = 0, centerDistTop = 0; if(direction && centerDist) { centerDistLeft = (direction === '>' ? 1 : -1) * centerDist; centerDistTop = (direction === 'v' ? 1 : -1) * centerDist; } //将两个参数转化为标准定位对象 {element: a, x: 0, y: 0} pinObject = normalize(pinObject); baseObject = normalize(baseObject); // 设定目标元素的 position 为绝对定位 // 若元素的初始 position 不为 absolute,会影响元素的 display、宽高等属性 var pinElement = $(pinObject.element); var baseElement = $(baseObject.element); var directionObj; if(pinElement.css('position') !== 'fixed' || isIE6) { pinElement.css('position', 'absolute'); isPinFixed = false; } else { // 定位 fixed 元素的标志位,下面有特殊处理 isPinFixed = true; } // 将位置属性归一化为数值 // 注:必须放在上面这句 `css('position', 'absolute')` 之后, // 否则获取的宽高有可能不对 posConverter(pinObject); posConverter(baseObject); var parentOffset = getParentOffset(pinElement); var baseOffset = baseObject.offset(); // 先判断方向 if(direction && alignType !== undefined) { directionObj = directionType[direction](pinElement, baseElement, alignType); } // 计算目标元素的位置 var top = baseOffset.top + baseObject.y - pinObject.y - parentOffset.top + (directionObj ? directionObj.y : 0); var left = baseOffset.left + baseObject.x - pinObject.x - parentOffset.left + (directionObj ? directionObj.x : 0); if(parentNode) { top += parentNode.scrollTop(); left += parentNode.scrollLeft(); } return { left: left + centerDistLeft, top: top + centerDistTop } // 定位目标元素 // pinElement.css({ // left: left, // top: top // }); } // 将目标元素相对于基准元素进行居中定位 // 接受两个参数,分别为目标元素和定位的基准元素,都是 DOM 节点类型 Position.center = function(pinElement, baseElement) { Position.pin({ element: pinElement, x: '50%', y: '50%' }, { element: baseElement, x: '50%', y: '50%' }); }; /* 相对于基准元素四周定位 * @param {Object} pinElement 目标元素 * @param {Object} baseElement 基类元素 * @param {Object} options 定位配置箱 * options : { direction: 'h', // v offset: [0, 0] } */ Position.advPin = function(pinElement, baseElement, options) { pinElement = $(pinElement), baseElement = $(baseElement); // 准备坐标数据 var baseWidth = baseElement.outerWidth(), baseHeight = baseElement.outerHeight(), baseLeft = baseElement.offset().left, baseTop = baseElement.offset().top, pinWidth = pinElement.outerWidth(), pinHeight = pinElement.outerHeight(), pinLeft = pinElement.offset().left, pinTop = pinElement.offset().top, scrollTop = $(document).scrollTop(), scrollLeft = $(document).scrollLeft(), winHeight = $(window).height(), winWidth = $(window).width(), offset; if(arguments.length === 2) { options = { direction: 'v' } } else if(arguments.length === 3 && typeof options == 'string') { options = { direction: options } } if(pinElement.css('position') !== 'fixed') { pinElement.css('position', 'absolute'); } //计算偏移量 if(options.offset) { offset = options.offset; } if(options.direction == 'v') { // 垂直定位 var tempHeight = winHeight - (baseTop - scrollTop + baseHeight + pinHeight), tempTop, tempLeft; offset ? (tempTop = baseTop + offset[0], tempLeft = baseLeft + offset[1]) : (tempTop = baseTop, tempLeft = baseLeft); if(tempHeight > 0) { // 定位到基类元素底部 pinElement.css({ top: (tempTop + baseHeight), left: tempLeft }); } else { // 定位到基类元素上面 if((baseTop - scrollTop) < pinHeight) { pinElement.css({ top: (tempTop + baseHeight), left: tempLeft }); } else { pinElement.css({ top: (tempTop - pinHeight), left: tempLeft }); } } } else if(options.direction == 'h') { // 水平定位 var tempWidth = winWidth - (baseLeft - scrollLeft + baseWidth + pinWidth); offset ? (tempTop = baseTop + offset[0], tempLeft = baseLeft + offset[1]) : (tempTop = baseTop, tempLeft = baseLeft); if(tempWidth > 0) { // 定位到基类元素右边 pinElement.css({ left: (tempLeft + baseWidth), top: tempTop }); } else { // 定位到基类元素上面 if((baseLeft - scrollLeft) < pinWidth) { pinElement.css({ left: (tempLeft + baseWidth), top: tempTop }); } else { pinElement.css({ left: (tempLeft - pinWidth), top: tempTop }); } } } } /* * 获取一个元素的位置 * @param {String} pinElement 需要获取的元素 * @param {String} type 获取位置方式,支持"fixed",即获取元素相对于window的位置,默认是相对于document的位置 * return {top:0,right:0,bottom:0,left:0} */ Position.location = function(pinElement, type) { pinElement = $(pinElement); var pinWidth = pinElement.outerWidth(), pinHeight = pinElement.outerHeight(), pinLeft = pinElement.offset().left, pinTop = pinElement.offset().top, scrollTop = $(document).scrollTop(), scrollLeft = $(document).scrollLeft(), winHeight = $(window).height(), winWidth = $(window).width(), docHeight = $(document).height(), docWidth = $(document).width(); if(type == 'fixed') { return { top: (pinTop - scrollTop), right: (winWidth - (pinLeft - scrollLeft) - pinWidth), bottom: (winHeight - (pinTop - scrollTop) - pinHeight), left: (pinLeft - scrollLeft) }; } else { return { top: pinTop, right: (docWidth - pinLeft - pinWidth), bottom: (docHeight - pinTop - pinHeight), left: pinLeft }; } } /** * 计算两个元素重合的面积 */ Position.overlapArea = function(rElement, bElement) { var rOffset = rElement.offset(), rleft = rOffset.left, rtop = rOffset.top, rwidth = rElement.width(), rHeight = rElement.height(), bOffset = bElement.offset(), bleft = bOffset.left, btop = bOffset.top, bwidth = bElement.width(), bheight = bElement.height(); if((rleft + rwidth < bleft) || (bleft + bwidth < rleft) || (rtop + rHeight < btop) || (btop + bheight < rtop)) { return 0; } // 计算重叠的left,top var tempLeft = rleft - bleft, overlapLeft, tempTop = rtop - btop, overlapTop; overlapLeft = tempLeft < 0 ? rwidth - Math.abs(tempLeft) : bwidth - tempLeft; overlapTop = tempTop < 0 ? rHeight - Math.abs(tempTop) : bheight - tempTop; return [overlapLeft, overlapTop]; }; // 这是当前可视区域的伪 DOM 节点 // 需要相对于当前可视区域定位时,可传入此对象作为 element 参数 Position.VIEWPORT = VIEWPORT; // global.cui.Position = global.Position = Position; // Helpers // ------- // 将参数包装成标准的定位对象,形似 { element: a, x: 0, y: 0 } function normalize(posObject) { posObject = toElement(posObject) || {}; if(posObject.nodeType) { posObject = { element: posObject }; } var element = toElement(posObject.element) || VIEWPORT; if(element.nodeType !== 1) { throw new Error('posObject.element is invalid.'); } var result = { element: element, x: posObject.x || 0, y: posObject.y || 0 }; // config 的深度克隆会替换掉 Position.VIEWPORT, 导致直接比较为 false var isVIEWPORT = (element === VIEWPORT || element._id === 'VIEWPORT'); // 归一化 offset result.offset = function() { // 若定位 fixed 元素,则父元素的 offset 没有意义 if(isPinFixed) { return { left: 0, top: 0 }; } else if(isVIEWPORT) { return { left: $(document).scrollLeft(), top: $(document).scrollTop() }; } else { return getOffset($(element)[0]); } }; // 归一化 size, 含 padding 和 border result.size = function() { var el = isVIEWPORT ? $(window) : $(element); return { width: el.outerWidth(), height: el.outerHeight() }; }; return result; } // 对 x, y 两个参数为 left|center|right|%|px 时的处理,全部处理为纯数字 function posConverter(pinObject) { pinObject.x = xyConverter(pinObject.x, pinObject, 'width'); pinObject.y = xyConverter(pinObject.y, pinObject, 'height'); } // 处理 x, y 值,都转化为数字 function xyConverter(x, pinObject, type) { // 先转成字符串再说!好处理 x = x + ''; // 处理 px x = x.replace(/px/gi, ''); // 处理 alias if(/\D/.test(x)) { x = x.replace(/(?:top|left)/gi, '0%').replace(/center/gi, '50%').replace(/(?:bottom|right)/gi, '100%'); } // 将百分比转为像素值 if(x.indexOf('%') !== -1) { //支持小数 x = x.replace(/(\d+(?:\.\d+)?)%/gi, function(m, d) { return pinObject.size()[type] * (d / 100.0); }); } // 处理类似 100%+20px 的情况 if(/[+\-*\/]/.test(x)) { try { // eval 会影响压缩 // new Function 方法效率高于 for 循环拆字符串的方法 // 参照:http://jsperf.com/eval-newfunction-for x = (new Function('return ' + x))(); } catch(e) { throw new Error('Invalid position value: ' + x); } } // 转回为数字 return numberize(x); } // 获取 offsetParent 的位置 function getParentOffset(element) { var parent = element.offsetParent(); // IE7 下,body 子节点的 offsetParent 为 html 元素,其 offset 为 // { top: 2, left: 2 },会导致定位差 2 像素,所以这里将 parent // 转为 document.body if(parent[0] === document.documentElement) { parent = $(document.body); } // 修正 ie6 下 absolute 定位不准的 bug if(isIE6) { parent.css('zoom', 1); } // 获取 offsetParent 的 offset var offset; // 当 offsetParent 为 body, // 而且 body 的 position 是 static 时 // 元素并不按照 body 来定位,而是按 document 定位 // http://jsfiddle.net/afc163/hN9Tc/2/ // 因此这里的偏移值直接设为 0 0 if(parent[0] === document.body && parent.css('position') === 'static') { offset = { top: 0, left: 0 }; } else { offset = getOffset(parent[0]); } // 根据基准元素 offsetParent 的 border 宽度,来修正 offsetParent 的基准位置 offset.top += numberize(parent.css('border-top-width')); offset.left += numberize(parent.css('border-left-width')); return offset; } function numberize(s) { return parseFloat(s, 10) || 0; } function toElement(element) { return $(element)[0]; } // fix jQuery 1.7.2 offset // document.body 的 position 是 absolute 或 relative 时 // jQuery.offset 方法无法正确获取 body 的偏移值 // -> http://jsfiddle.net/afc163/gMAcp/ // jQuery 1.9.1 已经修正了这个问题 // -> http://jsfiddle.net/afc163/gMAcp/1/ // 这里先实现一份 // 参照 kissy 和 jquery 1.9.1 // -> https://github.com/kissyteam/kissy/blob/master/src/dom/sub-modules/base/src/base/offset.js#L366 // -> https://github.com/jquery/jquery/blob/1.9.1/src/offset.js#L28 function getOffset(element) { var box = element.getBoundingClientRect(), docElem = document.documentElement; // < ie8 不支持 win.pageXOffset, 则使用 docElem.scrollLeft return { left: box.left + (window.pageXOffset || docElem.scrollLeft) - (docElem.clientLeft || document.body.clientLeft || 0), top: box.top + (window.pageYOffset || docElem.scrollTop) - (docElem.clientTop || document.body.clientTop || 0) }; } module.exports = Position; })(); }, {}]; var cuiScrollspyImpl = [function(require, module, exports) { /* * @desc scrollspy组件 * @anthor eszhang * @Date 2016-03-31 */ module.exports = function() { 'use strict'; $.cuiFactory("cuiScrollspy", { VERSION: '1.0.0', options: { target: '', offset: 10, activeTarget: null }, _create: function() { this.$body = $(document.body); this.$scrollElement = this.$el.is(document.body) ? $(window) : this.$el; this.selector = (this.options.target || '') + ' .nav li > a'; this.offsets = []; this.targets = []; this.scrollHeight = 0; this.$scrollElement.on('scroll.cuiScrollspy', $.proxy(this._process, this)); this._refresh(); this._process(); }, _getScrollHeight: function() { return this.$scrollElement[0].scrollHeight || Math.max(this.$body[0].scrollHeight, document.documentElement.scrollHeight) }, _refresh: function() { var options = this.options, that = this, offsetMethod = 'offset', offsetBase = 0; this.offsets = []; this.targets = []; this.scrollHeight = this._getScrollHeight(); if(!$.isWindow(this.$scrollElement[0])) { offsetMethod = 'position' offsetBase = this.$scrollElement.scrollTop() } this.$body.find(this.selector).map(function() { var $el = $(this), href = $el.data('target') || $el.attr('href'), $href = /^#./.test(href) && $(href); return($href && $href.length && $href.is(':visible') && [ [$href[offsetMethod]().top + offsetBase, href] ]) || null; }).sort(function(a, b) { return a[0] - b[0] }).each(function() { that.offsets.push(this[0]); that.targets.push(this[1]); }); }, _process: function() { var scrollTop = this.$scrollElement.scrollTop() + this.options.offset, scrollHeight = this._getScrollHeight(), maxScroll = this.options.offset + scrollHeight - this.$scrollElement.height(), offsets = this.offsets, targets = this.targets, activeTarget = this.options.activeTarget, i; if(this.scrollHeight != scrollHeight) { this._refresh(); } if(scrollTop >= maxScroll) { return activeTarget != (i = targets[targets.length - 1]) && this._activate(i); } if(activeTarget && scrollTop < offsets[0]) { return this._clear(); } for(i = offsets.length; i--;) { activeTarget != targets[i] && scrollTop >= offsets[i] && (offsets[i + 1] === undefined || scrollTop < offsets[i + 1]) && this._activate(targets[i]) } }, _activate: function(target) { var options = this.options; this._clear(); //更新标志位 this.options.activeTarget = target; var selector = this.selector + '[data-target="' + target + '"],' + this.selector + '[href="' + target + '"]' var active = $(selector).parents('li').addClass('active') if(active.parent('.dropdown-menu').length) { active = active.closest('li.dropdown').addClass('active'); } active.trigger('activate.cuiScrollspy') }, _clear: function() { $(this.selector).parentsUntil(this.options.target, '.active').removeClass('active'); //重置标志位 this.options.activeTarget = null; }, // 对外方法 invoke: { //每当页面中从DOM中增加或删除页面元素时,都需要调用此方法 refresh: function() { this._refresh(); this._process(); }, //取消事件绑定 cancel: function() { this.$scrollElement.off('scroll.cuiScrollspy'); this._clear(); }, //恢复事件绑定 yes: function() { this.$scrollElement.on('scroll.cuiScrollspy', $.proxy(this._process, this)); this._iCall('refresh'); } } }); $('[cuiScrollspy]').cuiScrollspy({}); } }, {}]; var cuiSelectImpl = [function(require, module, exports) { var dropdown = require("../dropdown/index")(), selectTpl = template.compile(require("./select.tpl")); module.exports = function() { $.cuiFactory("cuiSelect", { VERSION: '1.0.0', options: { //select宽度 width: 200, //选项面板宽度 dropWidth: false, //选项面板高度 height: 181, //没有selected项的默认显示 placeholder: '请选择', //渲染的模板 render: null, //选项面板相对于select偏移的x, y offset: [0, 0], //面板对齐方式,默认为left align: 'left', //是否禁用select disabled: false, //初始化数据 data: [], //选项面板的父节点(需cuiDropdown支持) container: null }, _create: function() { //初始化select所需数据 this._preRenderData(); this._createDom(); }, events: { //指定绑定事件的元素 'target': function() { if(this.options.container) { return $(this.options.container).find('.' + this.randomClass); } else { return this.$select_el; } }, //select选中事件 'click .select-bd-li': function(self, evt) { if($(self).hasClass('disabled')) { return false; } var index = $(self).index(), //选中元素在当前上下级中的index //选中元素是否有group父元素,如有,获取父元素的text groupTxt = $(self).parents('.select-optgroup-li').size() ? $(self).parents('.select-optgroup-li').find('.group-value').text() : null; //设置选中项 this._select(index, groupTxt); //重置select this._reload(); }, //select hover状态 'mouseover .select-bd-li': function(self, evt) { if($(self).hasClass('disabled')) { return false; } //this.$select_el.find('.select-bd-li').removeClass('focus'); $(self).closest(".cui-select-bd").find('.select-bd-li').removeClass('focus'); $(self).addClass('focus'); }, 'mouseleave .select-bd-li': function (self, evt) { var $self = $(self); if ($self.hasClass('focus')) { $self.removeClass('focus'); } } }, _preRenderData: function() { var options = this.options; if(this.$el.is('select')) { this.type = 0; //整理元素初始化数据格式 this._initData = this._convertData(this.$el); } else { this.type = 1; //整合数据初始化数据 this._initData = { list: options.data, //选项面板数据 disabled: options.disabled, //是否禁用 placeholder: options.placeholder //默认显示 }; } //整合render、selected项数据 this._processData(this._initData); }, _processData: function(data) { var childrenSelect = null, that = this, list = null; if($.isArray(data)) { list = data; } else { this._renderData = $.extend(true, {}, that._initData); list = this._renderData.list; } //判断元素本身是否有render,没有再寻找options中是否有render _.forEach(list, function(n, key) { if(n.children) { _.forEach(n.children, function(n, key) { that._convertRenderDate(n); }); } else { that._convertRenderDate(n); } }); //选出已选项,提供给select默认渲染 childrenSelect = _.find(list, { children: [{ selected: true }] }); this._renderData.chosen = _.find(list, { selected: true }) || (childrenSelect ? _.find(childrenSelect.children, { selected: true }) : undefined); this._renderData.list = list; }, _convertRenderDate: function(n) { if(n.render) { n.renderData = n.render(n); } else if(this.options.render) { n.renderData = this.options.render(n); } }, _convertData: function(ele) { var options = ele[0].options, //所有的选项 l = options.length, i = 0, list = [], groupLabel = null, data = {}, item = {}, option = null; for(; i < l; i++) { option = options[i]; data = { value: option.value, text: option.text, selected: option.selected, disabled: option.disabled }; // add by clu on 2020-9-27 18:50:09 自定义属性也要 var attrNames = option.getAttributeNames(); for (var j = 0; j < attrNames.length; j++) { var name = attrNames[j]; if (!(name in data)) { data[name] = option.getAttribute(name); } } if(options[i].parentNode.getAttribute('label')) { if(groupLabel !== options[i].parentNode.getAttribute('label')) { groupLabel = options[i].parentNode.getAttribute('label'); item = {}; item.text = groupLabel; item.children = []; list.push(item); } item.children.push(data); } else { list.push(data) } } return { list: list, disabled: ele.prop('disabled'), placeholder: ele.attr('placeholder') || this.options.placeholder }; }, _createDom: function() { var options = this.options; if(this.type) { this.$el.addClass('cui-select dropdown').empty().html(selectTpl(this._renderData)); this.$select_el = this.$el; } else { this.$el.hide().after($('')); this.$select_el = this.$el.next('.cui-select'); } this.$select_el.css({ width: options.width }); //初始化选项面板 this._dropDown(); }, /* * 设置选中项 * @param: {selected} 选中项依据,只能为Number或者Object,Number为数据索引,Object如 {text: 'ly'} * {group} 分组的父元素text,如果有分组、selected为Number且无此参数,默认在第一个分组里面选择 */ _select: function(selected, group) { var args = arguments, list = this._renderData.list, childSelect = _.find(list, 'children'), chosen = null, chosenCopy = null; if(args[1]) { childSelect = _.find(list, { 'text': args[1] }); if(_.isObject(args[0])) { childSelect = _.where(list, { 'children': [] }) } } if(_.isNumber(args[0])) { chosen = childSelect ? _.at(childSelect.children, args[0])[0] : _.at(list, args[0])[0]; } else if(_.isObject(args[0])) { if(childSelect) { _.forEach(childSelect, function(n) { if(_.find(n.children, args[0])) { chosen = _.find(n.children, args[0]); } }); } else { chosen = _.find(list, args[0]); } } else { console.warn(this.uiName + '设置选择必须为json或者数字'); } if(chosen && chosen.disabled != true) { chosenCopy = $.extend(true, {}, chosen); if(this._renderData.chosen) { this._renderData.chosen.selected = false; } chosen.selected = true; this._renderData.chosen = {}; this._renderData.chosen = chosen; //选项变化事件 if(!chosenCopy.selected) { this._emit('change', [this.$select_el, chosen]); } this._emit('select', [this.$select_el, chosen]); if(this.$el.is('select')) { this.$el.val(chosen.value); // add by clu on 2020-7-15 14:57:42 触发原生的change事件,让cuiFormTip组件立即可以捕获到改动 this.$el.trigger('change'); } } //this.$el.val(chosen.value); }, //调用dropdown初始化select选项面板 _dropDown: function() { var that = this, align = this.options.align, headerH, dropStyle = {}; if(this._renderData.disabled) { this.$select_el.addClass('disabled'); return; } if(this.options.container) { this.randomClass = new Date().getTime() + ''; } this.$select_el.find('.select-hd').cuiDropdown({ isClickable: true, miss: true, container: this.options.container ? $(this.options.container) : null, randomClass: this.randomClass ? this.randomClass : '' }); headerH = this.$select_el.find('.select-hd').outerHeight(); dropStyle = { width: +this.options.dropWidth && this.options.dropWidth > 0 ? this.options.dropWidth : this.options.width, maxHeight: this.options.height, left: +this.options.offset[0] ? +this.options.offset[0] : 0, top: +this.options.offset[1] ? +this.options.offset[1] + headerH : headerH, /*// edit by clu on 2020-7-15 16:21:15 从absolute改为relative,因此top改为0 top: 0*/ } if(align == 'right') { dropStyle.left = 'inherit'; dropStyle.right = +this.options.offset[0] ? 0 - (+this.options.offset[0]) : 0; } if(this.options.container) { this.$select_bd = $(this.options.container).find('.' + this.randomClass).css(dropStyle); } else { this.$select_bd = this.$select_el.find('.cui-select-bd').css(dropStyle); } this.$select_el.find('.select-hd').on('show.cuiDropdown', function(ev, $el) { that._emit('open', [that.$select_el]); }); this.$select_el.find('.select-hd').on('hide.cuiDropdown', function(ev, $el) { that._emit('close', [that.$select_el]); }); }, //销毁选项面板 _destroyDropDown: function() { if(this.$select_el.find('.select-hd').data('cuiDropdown')) { this.$select_el.find('.select-hd').cuiDropdown('destroy'); } }, _reload: function() { //销毁选项面板 this._destroyDropDown(); //重置select this.$select_el.html(selectTpl(this._renderData)); //初始化新的选项面板 this._dropDown(); if(this.options.container) { this._bindUiEvents(); } }, invoke: { //重置select选项面板 reset: function() { var that = this; this._processData(this._initData); this._reload(); }, //select标签数据变化后刷新面板 reload: function() { if(this.$el.is('select')) { this._renderData = this._convertData(this.$el); } this._reload(); }, //打开select选项面板 open: function() { if(this.$select_el.find('.select-hd').data('cuiDropdown')) { this.$select_el.find('.select-hd').cuiDropdown('open'); } else { console.warn('disabled状态下不可操作面板'); } }, //关闭select选项面板 close: function() { if(this.$select_el.find('.select-hd').data('cuiDropdown')) { this.$select_el.find('.select-hd').cuiDropdown('close'); } else { console.warn('disabled状态下不可操作面板'); } }, //设置select选项面板数据 data: function(data) { var options = this.options; if(data) { if(_.isArray(data)) { this._processData(data); } else { console.warn(this.uiName + '("data")方法的参数不是一个数组'); } } else { return this._renderData.list; } this._reload(); }, //无参数时返回选中的select数据,有参数时设置参数数据为选中状态 select: function(select, group) { var chosen = {}; if(select || _.isNumber(select)) { this._select(select, group); this._reload(); } else { chosen = $.extend(true, {}, this._renderData.chosen) return chosen; } }, //设置select是否可用 disabled: function(disabled) { if(_.isBoolean(disabled)) { this._renderData.disabled = disabled; } else { this._renderData.disabled = true; } this._reload(); } } }); } }, { "../dropdown/index": 21, "./select.tpl": [function(require, module, exports) { module.exports = "
\n\t{{if chosen}}\n\t\t{{if chosen.renderData}}\n\t\t\t{{#chosen.renderData}}\n\t\t{{else}}\n\t\t\t{{chosen.text}}\n\t\t\t{{chosen.comment}}\n\t\t{{/if}}\n\t{{else}}\n\t\t{{placeholder}}\n\t{{/if}}\n\t\n
\n
\n\t\n
"; }, {}] }]; var cuiStickyImpl = [function(require, module, exports) { /* * @desc sticky组件 */ module.exports = function() { /** * 提供一个元素当滚动条滚动到该元素的高度时,该元素固定,以及达到某个高度是接触固定。 */ $.cuiFactory("cuiSticky", { options: { topSpacing: 0, bottomSpacing: 0, className: 'cui-issticky', wrapperClassName: 'cui-sticky-wrapper', center: false, getWidthFrom: '', responsiveWidth: false, bottomfixed: false, // stoptionsp 当滚动超过多少时不在固定 stoptionsp: null, /*2015-3-25增加 滚动容器和文档流*/ fixedContainer: window, fixedDocument: document, fixedWidth: false, }, _create: function() { var $el = this.$el, options = this.options, self = this; this.cuiSticked = [], this.$fixed_container = $(options.fixedContainer), this.$fixed_document = $(options.fixedDocument), this.windowHeight = this.$fixed_container.actual('outerHeight'); var stickyId = $el.attr('id'); var wrapperId = stickyId ? stickyId + '-' + options.wrapperClassName : options.wrapperClassName var wrapper = $('
').attr('id', stickyId + '-sticky-wrapper').addClass(options.wrapperClassName); $el.addClass('cui-sticky').wrapAll(wrapper); if(options.center) { $el.parent().css({ width: $el.actual('outerWidth'), marginLeft: "auto", marginRight: "auto" }); } if($el.css("float") == "right") { $el.css({ "float": "none" }).parent().css({ "float": "right" }); } var stickyWrapper = $el.parent(); // height = $el.height() === 0 ? $el.actualHeight() : $el.outerHeight(); stickyWrapper.css('height', $el.actual('outerHeight')); // 保存到所有的固定元素的对象中,便于统一管理。 this.cuiSticked.push({ topSpacing: options.topSpacing, bottomSpacing: options.bottomSpacing, stickyElement: $el, currentTop: null, stickyWrapper: stickyWrapper, className: options.className, getWidthFrom: options.getWidthFrom, responsiveWidth: options.responsiveWidth, stoptionsp: options.stoptionsp, bottomfixed: options.bottomfixed, that: this, fixedWidth: options.fixedWidth }); this.athchEvent(); self.scroller(); }, athchEvent: function() { var _fixed_container_width = this.$fixed_container.actual('outerWidth'), _fixed_container_height = this.$fixed_container.actual('outerHeight'), timeout, _self = this; this.$fixed_container.on("scroll", function() { _self.scroller(); }); $(window).on("resize", function() { timeout && clearTimeout(timeout); timeout = setTimeout(function() { var fix_container_width = _self.$fixed_container.actual('outerWidth'), fix_container_height = _self.$fixed_container.actual('outerHeight'); if(fix_container_width !== _fixed_container_width || fix_container_height !== _fixed_container_height) { _self.resizer(); _fixed_container_width = _self.$fixed_container.actual('outerWidth'); _fixed_container_height = _self.$fixed_container.actual('outerHeight'); } }, 80); }); }, scroller: function() { var fixed_container = this.$fixed_container, scrollTop = fixed_container.scrollTop(), documentHeight = this.$fixed_document.actual('outerHeight'), dwh = documentHeight - this.windowHeight, extra = (scrollTop > dwh) ? dwh - scrollTop : 0; for(var i = 0; i < this.cuiSticked.length; i++) { var s = this.cuiSticked[i], fixed_container_top = fixed_container.is($(window)) ? 0 : fixed_container.offset().top, elementTop = s.stickyWrapper.offset().top - fixed_container_top; elementTop = s.bottomfixed ? elementTop + s.stickyWrapper.actual('outerHeight') : elementTop; var etse = elementTop - s.topSpacing - extra; var flag = fixed_container.is($(window)) ? (scrollTop <= etse) : (etse > 0); if(flag) { if(s.currentTop !== null) { s.stickyElement.css('position', '').css('top', ''); s.stickyElement.parent().removeClass(s.className); s.that._emit('unFixed', [s.that.$el]); s.currentTop = null; } } else { var newTop = documentHeight - s.stickyElement.actual('outerHeight') - s.topSpacing - s.bottomSpacing - scrollTop - extra; if(newTop < 0) { newTop = newTop + s.topSpacing + fixed_container_top; } else { newTop = s.topSpacing + fixed_container_top; } if(typeof s.getWidthFrom !== 'undefined' && s.getWidthFrom !== '') { s.stickyElement.css('width', $(s.getWidthFrom).actual('outerWidth')); } else { //var width = $(s.stickyElement).width() === 0 ? $(s.stickyElement).actualWidth() : $(s.stickyElement).width(); s.stickyElement.css('width', $(s.stickyElement).actual('outerWidth')); } if(s.currentTop != newTop) { s.stickyElement.css('position', 'fixed').css('top', newTop); s.stickyElement.parent().addClass(s.className); s.that._emit('onFixed', [s.that.$el]); s.currentTop = newTop; } } // 如果超过了stoption则移除。 if(s.stoptionsp && s.stoptionsp < scrollTop) { s.stickyElement.css('position', '').css('top', ''); s.stickyElement.parent().removeClass(s.className); s.that._emit('unFixed', [s.that.$el]); s.currentTop = null; } } }, // window resize时对所有的固定元素宽度等进行重新计算 resizer: function() { // console.log('resizer函数z执行中~'); for(var i = 0; i < this.cuiSticked.length; i++) { var s = this.cuiSticked[i]; if(typeof s.getWidthFrom !== 'undefined' && s.responsiveWidth === true) { s.stickyElement.css('width', $(s.getWidthFrom).actual('outerWidth')); } else if(s.stickyElement.actual('outerWidth', { clone: true }) === 0 && s.stickyElement.actual('outerWidth') !== 0) { // 修复该bug.这边有性能问题,表格不需要这段代码,但是其他固定元素需要,所以暂时去掉。后面有时间补上这里逻辑。 s.stickyElement.css('width', "100%"); trueWidth = s.stickyElement.actual('outerWidth') - s.stickyElement.css('margin-left').slice(0, -2) - s.stickyElement.css('margin-right').slice(0, -2); s.stickyElement.outerWidth(trueWidth); } else { if(!s.fixedWidth) { s.stickyElement.css('width', s.stickyElement.parent().actual('outerWidth')) } } } }, // 对外方法集 invoke: { // update: this.scroller, /* * 解除当前元素的固定。 */ unstick: function() { var unstickyElement = this.$el; var removeIdx = -1; for(var i = 0; i < this.cuiSticked.length; i++) { if(this.cuiSticked[i].stickyElement.get(0) == unstickyElement.get(0)) { removeIdx = i; } } if(removeIdx != -1) { this.cuiSticked.splice(removeIdx, 1); unstickyElement.unwrap(); unstickyElement.removeClass("cui-sticky").removeAttr('style'); } }, /* * 设置关闭固定的高度。 * */ stoptionsp: function(top) { this.options.stoptionsp = top; for(var i = 0, len = this.cuiSticked.length; i < len; i++) { if(this.cuiSticked[i].that === this) { this.cuiSticked[i].stoptionsp = top; break; } } } } }); $.fn.extend({ actual: function(method, options) { // check if the jQuery method exist if(!this[method]) { throw '$.actual => The jQuery method "' + method + '" you called does not exist'; } var defaults = { absolute: false, clone: false, includeMargin: false }; var configs = $.extend(defaults, options); var $target = this.eq(0); var fix, restore; if(configs.clone === true) { fix = function() { var style = 'position: absolute !important; top: -1000 !important; '; // this is useful with css3pie $target = $target.clone().attr('style', style).appendTo('body'); }; restore = function() { // remove DOM element after getting the width $target.remove(); }; } else { var tmp = []; var style = ''; var $hidden; fix = function() { // get all hidden parents $hidden = $target.parents().addBack().filter(':hidden'); style += 'visibility: hidden !important; display: block !important; left: -9999px; top:-9999px;'; if(configs.absolute === true) style += 'position: absolute !important; '; // save the origin style props // set the hidden el css to be got the actual value later $hidden.each(function() { // Save original style. If no style was set, attr() returns undefined var $this = $(this); var thisStyle = $this.attr('style'); tmp.push(thisStyle); // Retain as much of the original style as possible, if there is one $this.attr('style', thisStyle ? thisStyle + ';' + style : style); }); }; restore = function() { // restore origin style values $hidden.each(function(i) { var $this = $(this); var _tmp = tmp[i]; if(_tmp === undefined) { $this.removeAttr('style'); } else { $this.attr('style', _tmp); } }); }; } fix(); // get the actual value with user specific methed // it can be 'width', 'height', 'outerWidth', 'innerWidth'... etc // configs.includeMargin only works for 'outerWidth' and 'outerHeight' var actual = /(outer)/.test(method) ? $target[method](configs.includeMargin) : $target[method](); restore(); // IMPORTANT, this plugin only return the value of the first element return actual; } }); $.fn.addBack = $.fn.addBack || $.fn.andSelf; $('[cuiSticky]').cuiSticky({}); } }, {}]; var cuiTabsCardImpl = [function(require, module, exports) { /* * @desc tabsCard组件 */ var _position = require("../../base/position/index"), tabsCardTpl = template.compile(require("./tabsCard.tpl")), tabsUnitTpl = template.compile(require("./tabsUnit.tpl")); module.exports = function() { $.cuiFactory("cuiTabsCard", { VERSION: '1.0.0', options: { width: 'auto', height: 'auto', tabsCardHead: { title: '', isCopyBtn: false, isCloseBtn: true }, tabsCardBody: { // tabs: null }, tabsCardFooter: { btns: [] }, trigger: 'click', direction: 'bottom', focusoutClose: true, hoverDelay: 2000, delay: 100, container: false, offset: [0, 0] }, _create: function() { var options = this.options, self = this; this._initEvent(); }, _initEvent: function() { // 绑定事件 var options = this.options, that = this, trigger = options.trigger, hoverDelay = this.options.hoverDelay; if(trigger) { if(trigger === 'click') { this.$el.on('click.' + this.uiName, this.$el, function(e) { that._toggle.call(that, $(e.target)); }); } else { this.$el.on('mouseenter.' + this.uiName, this.$el, function() { that._enter(); }); this.$el.on('mouseleave.' + this.uiName, this.$el, function() { that._leave(hoverDelay); }); } } }, _initRelativeEvent: function($relativeDom) { var that = this, index = 0, options = this.options, hoverDelay = options.hoverDelay, trigger = options.trigger, tabsCardFooter = options.tabsCardFooter, callback; $relativeDom.on('click.' + this.uiName, ".cui-tabsCard-title .delete-btn", function() { that._toggle(); }); $relativeDom.on('click.' + this.uiName, ".cui-tabsCard-title .copy-btn", function() { that._emit('copy', [that.$el, that.relativeDom]);; }); $relativeDom.on('click.' + this.uiName, ".cui-tabsCard-tabs .cui-tabs-hd li", function() { var index = $(this).index(); $(this).siblings().removeClass("current").end().addClass("current"); that._changeTab(index); that._emit("tabChange", [index, that.$el, that.relativeDom]); }); if(trigger == "hover") { $relativeDom.on('mouseenter.' + this.uiName, this.$el, function() { that._enter(); }); $relativeDom.on('mouseleave.' + this.uiName, this.$el, function() { that._leave(hoverDelay); }); } if(tabsCardFooter && tabsCardFooter.btns) { var btnIndex = 0; $relativeDom.on('click.' + this.uiName, "button:not('.disabled')", function() { btnIndex = $(this).index(); callback = tabsCardFooter.btns[btnIndex].callback || ''; _.isFunction(callback) && callback.apply(null, [that.$el, $relativeDom]); }); } index = that._getCurrentIndex(); $relativeDom.find("li").eq(index).trigger("click"); }, _toggle: function() { var options = this.options; this.status = this.status || false; if(this.status) { this._closeTabsCard(); } else { this._openTabsCard(); } }, _enter: function() { var that = this; that.hoverTimeoutId_End && clearTimeout(that.hoverTimeoutId_End); that.openTimeout && clearTimeout(that.openTimeout); that.closeTimeout && clearTimeout(that.closeTimeout); that.hoverTimeoutId_Start = setTimeout(function() { that.status ? 0 : that._openTabsCard(); }, 0) }, _leave: function(hoverDelay) { var that = this; that.hoverTimeoutId_Start && clearTimeout(that.hoverTimeoutId_Start); that.openTimeout && clearTimeout(that.openTimeout); that.closeTimeout && clearTimeout(that.closeTimeout); that.hoverTimeoutId_End = setTimeout(function() { that.status ? that._closeTabsCard() : 0; }, hoverDelay) }, _openTabsCard: function() { var that = this, options = this.options, delay = options.delay, direction = options.direction, $html = this.relativeDom = $("
"); $html.append(that._getRenderDom()); this._emit('show', [this.$el, this.relativeDom]); this.closeTimeout && clearTimeout(this.closeTimeout); this.openTimeout = setTimeout(function() { that.options.container ? $html.appendTo(that.options.container) : $html.insertAfter(that.$el); that._adjustBox($html); that._setPosition(that.$el, $html, options.direction); that._initRelativeEvent($html); that.status = true; this.relativeDom = $html; that._emit("shown", [that.$el, this.relativeDom]); }, delay); }, _closeTabsCard: function() { this._emit('hide', [this.$el, this.relativeDom]); var that = this, options = this.options, delay = this.options.delay; this.openTimeout && clearTimeout(that.openTimeout); this.closeTimeout = setTimeout(function() { that.relativeDom && that.relativeDom.remove(); that.status = false; that._emit("hidden", [that.$el, this.relativeDom]); that.relativeDom = null; }, delay) }, _adjustBox: function($html) { var options = this.options, width = $html.outerWidth(), _height = options.height, titleHeight = $html.find(".cui-tabsCard-title").outerHeight(), footHeight = $html.find(".cui-tabsCard-footer").outerHeight(); if(width < options.width) { $html.outerWidth(options.width); } //最小高度为50 _height = _height > (titleHeight + footHeight + 50) ? _height : titleHeight + footHeight + 50; if(options.height != 'auto') { $html.outerHeight(_height); $html.find(".cui-tabsCard-content").outerHeight(options.height - titleHeight - footHeight) } }, _getRenderDom: function() { var _title = this.$el.attr("data-card-title"); if(_title) { this.options.tabsCardHead.title = _title; } return $(tabsCardTpl({ data: this.options })); }, _getCurrentIndex: function() { var options = this.options, tabs = options.tabsCardBody && options.tabsCardBody.tabs, index; if(tabs) { $.each(tabs, function(i, data) { data.selected ? (index = i) : 0; }); } else { index = 0; } return index; }, /*切换tab卡*/ _changeTab: function(index) { var that = this, options = this.options, tabs = options.tabsCardBody.tabs, dataArray = tabs[index]; if(dataArray) { this.relativeDom.find(".cui-tabs-bd").html(tabsUnitTpl({ data: dataArray })); } }, _setPosition: function($el, $html, direction) { var offset = this.options.offset, offsetObj = _position.getPosition($el, $html, direction); var thisTop = offsetObj.top, //top值 thisLeft = offsetObj.left, elWidth = $el.outerWidth(), elHeight = $el.outerHeight(), elTop = $el.offset().top, elLeft = $el.offset().left, win = { height: $(window).height(), //窗口的宽高 width: $(window).width(), scrollTop: $(window).scrollTop(), //窗口的滚动条宽高 scrollLeft: $(window).scrollLeft() }, thisWidth = $html.outerWidth(), thisHeight = $html.outerHeight(); if(win.width + win.scrollLeft - thisLeft - thisWidth < 0) { if(thisLeft < thisWidth) {} else { switch(direction) { case 'bottom': offsetObj.left = thisLeft - thisWidth / 2 + elWidth / 2; break; case 'top': offsetObj.left = thisLeft - thisWidth / 2 + elWidth / 2; break; case 'right': offsetObj.left = thisLeft - thisWidth - elWidth - 20; break; } } } if(win.height + win.scrollTop - thisTop - thisHeight < 0) { if(thisTop < thisHeight) { // switch(direction){ // case 'top' : // offsetObj.top = thisTop; // break; // } } else { switch(direction) { case 'bottom': offsetObj.top = thisTop - thisHeight - elHeight - 20; break; case 'left': offsetObj.top = thisTop - thisHeight / 2 + elHeight / 2; break; case 'right': offsetObj.top = thisTop - thisHeight / 2 + elHeight / 2; break; } } } if(win.height + win.scrollTop - thisTop - thisHeight < 0 && win.width + win.scrollLeft - thisLeft - thisWidth < 0) { if(thisTop < thisHeight) {} else { switch(direction) { case 'bottom': offsetObj.top = thisTop - thisHeight - elHeight - 20; offsetObj.left = thisLeft - thisWidth / 2 + elWidth / 2; break; case 'left': offsetObj.top = thisTop - thisHeight / 2 + elHeight / 2; break; case 'right': offsetObj.top = thisTop - thisHeight / 2 + elHeight / 2; offsetObj.left = thisLeft - thisWidth - elWidth - 20; break; case 'top': offsetObj.top = thisTop - thisHeight / 2 + elHeight / 2; offsetObj.left = thisLeft - thisWidth / 2 + elWidth / 2; break; } } } if(elLeft < thisWidth) { switch(direction) { case 'left': offsetObj.left = elLeft + elWidth + 10; break; case 'bottom': offsetObj.left = elLeft; break; case 'top': offsetObj.left = elLeft; break; } if(elLeft > thisWidth / 2) { switch(direction) { case 'bottom': offsetObj.left = _position.getPosition($el, $html, direction).left; break; case 'top': offsetObj.left = _position.getPosition($el, $html, direction).left; break; } } } if(elTop < thisHeight) { switch(direction) { case 'top': offsetObj.top = elTop + elHeight + 10; break; case 'left': offsetObj.top = elTop; break; case 'right': offsetObj.top = elTop; break; } if(elTop > thisHeight / 2) { switch(direction) { case 'left': offsetObj.top = _position.getPosition($el, $html, direction).top; break; case 'right': offsetObj.top = _position.getPosition($el, $html, direction).top; break; } } } _.isNumber(parseInt(offset[0])) && (offsetObj.top += offset[0]); _.isNumber(parseInt(offset[1])) && (offsetObj.left += offset[1]); $html.offset(offsetObj); }, // 对外方法 invoke: { hide: function() { this._closeTabsCard(); }, show: function() { if(!this.relativeDom) { this._openTabsCard(); } }, content: function(tpl) { if(this.options.tabsCardBody) { this.options.tabsCardBody.content = tpl; this.relativeDom.find('.cui-tabsCard-content').html(tpl); } }, setBtnDisabled: function(index, isDisabled) { var $btnDom = this.relativeDom.find(".cui-tabsCard-footer button").eq(index); isDisabled ? $btnDom.addClass("disabled") : $btnDom.removeClass("disabled"); }, setCardTitle: function(title) { this.options.tabsCardHead.title = title; this.relativeDom.find('.cui-tabsCard-title h3').html(title); }, tabsCardBody: function(data) { // var _data = $.extend(true,this.options.tabsCardBody,data); this.options.tabsCardBody = data; this.relativeDom.html(tabsCardTpl({ data: this.options })); var index = this._getCurrentIndex(); //this._changeTab(index); this.relativeDom.find("li").eq(index).trigger("click"); this._adjustBox(this.relativeDom); this._setPosition(this.$el, this.relativeDom, this.options.direction); }, tabsCardFooter: function(data) { //var _data = $.extend(true,this.options.tabsCardFooter,data); this.options.tabsCardFooter = data; this.relativeDom.html(tabsCardTpl({ data: this.options })); var index = this._getCurrentIndex(); //this._changeTab(index); this.relativeDom.find("li").eq(index).trigger("click"); this._adjustBox(this.relativeDom); this._setPosition(this.$el, this.relativeDom, this.options.direction); } } }) } }, { "../../base/position/index": 10, "./tabsCard.tpl": [function(require, module, exports) { module.exports = "\n {{if data.tabsCardHead}}\n
\n {{if data.tabsCardHead.isCloseBtn}}{{/if}}\n {{if data.tabsCardHead.isCopyBtn}}{{/if}}\n

{{data.tabsCardHead.title}}

\n
\n {{/if}}\n
\n {{if data.tabsCardBody}}\n {{if data.tabsCardBody.content}}\n {{#data.tabsCardBody.content}}\n {{else if data.tabsCardBody.tabs}}\n
\n
\n \n
\n
\n \n
\n
\n {{/if}}\n {{else}}\n
\n {{/if}}\n
\n {{if data.tabsCardFooter}}\n
\n {{each data.tabsCardFooter.btns}}\n \n {{/each}}\n
\n {{/if}}"; }, {}], "./tabsUnit.tpl": [function(require, module, exports) { module.exports = "{{if data.label}}\n
\n \n {{if data.label.statusClass}}\n \n {{/if}}\n {{if data.label.text || data.label.subText }}\n \n {{/if}}\n
\n{{/if}}\n{{if data.content}}\n
{{#data.content}}
\n{{/if}}"; }, {}], }]; var cuiThinkInputImpl = [function(require, module, exports) { var _position = require("../../base/position/index"), tplA = template.compile(require("./bodyTplA.tpl")), tplB = template.compile(require("./bodyTplB.tpl")), tplC = template.compile(require("./bodyTplC.tpl")), tplMain = template.compile(require("./main.tpl")); module.exports = function() { $.cuiFactory("cuiThinkInput", { VERSION: '1.0.0', options: { /**联想输入面板数据集合:[{label:"",num:"",value:""},{label:"",num:"",value:""}]**/ data: [], //是否是分批取数据 isBatch: true, //父节点元素 parentEl: null, paginInfo: { type: 'little', current: 1, total: 0, pageItems: 8, pageNoChange: function(ev, current, pageItems) {} }, //当数据总条数为零时 blankDom: '', fillField: '', //无数据时的提示 nodataTip: "没有找到类似数据" }, // 事件 events: { //指定绑定事件的元素 'target': function() { return this.$think_el; }, 'click .associate-item': function(self, evt) { if(this.options.fillField) { this.triggerEle.val(this.currentList[this.hoverIndex][this.options.fillField]); } else { this.triggerEle.val(this.currentList[this.hoverIndex].label); } //this.triggerEle.val(this.$think_el.find('.associate-item[index="' + this.hoverIndex + '"]').text()); this.inputValue = this.triggerEle.val(); this._emit('onSelect', [this.currentList[this.hoverIndex]]); this.$think_el.hide(); this.isOpen = false; return false; }, 'mouseover .associate-item': function(self, evt) { this.$think_el.find(".associate-item").removeClass("current"); $(self).addClass("current"); this.hoverIndex = $(self).attr("index"); return false; }, 'mouseout .associate-item': function(self, evt) { this.$think_el.find(".associate-item").removeClass("current"); $(self).removeClass("current"); this.hoverIndex = -1; return false; } }, //调整面板 _adjustPanel: function() { var options = this.options, triggerEle = this.triggerEle, thisEl = this.$think_el, self = this, thisHeight = thisEl.outerHeight(), //联想面板高度 thisWidth = thisEl.outerWidth(), //联想面板宽度 win = { height: $(window).height(), width: $(window).width(), scrollTop: $(window).scrollTop(), scrollLeft: $(window).scrollLeft() }; thisEl.show(); }, _create: function() { var self = this; this.randomNum = new Date().getTime() + ""; this.triggerEle = this.$el; this.triggerEle.addClass("cuiThinkInput"); if(!this.triggerEle.attr('placeholder') && !this.options.isBatch) { this.triggerEle.attr('placeholder', '多项匹配以空格隔开'); } this.hoverIndex = -1; this.currentList = []; this.inputValue = ""; this.isShowFt = true; cuiThinkInput.allThinkInput.push(this); this.isOpen = false; if(!this.options.isBatch) { this.allData = this.options.data; this._dealData(); this._dataByIndex(parseInt(this.options.paginInfo.current, 10) - 1); this.options.paginInfo.pageNoChange = function(ev, current, pageItems) { self.options.paginInfo.current = parseInt(current); self._onPageNoChage(current - 1, pageItems); }; } else { this.currentList = this.options.data; var loop = this.options.paginInfo.pageItems - this.currentList.length; if(this.currentList.length < this.options.paginInfo.pageItems) { for(var i = 0; i < loop; i++) { this.currentList.push({ label: "", num: "", value: "" }); }; } } this._preRenderData(); this._createDom(); this._bindChange(); this._showAndHide(); this.triggerEle.live('click', function() { self._emit('onClick'); }); }, // 准备所有需要渲染的数据 _preRenderData: function(isfromTarget) { var options = this.options, isNoData = false, blankDom = options.blankDom, _renderData = {}; isNoData = (options.paginInfo.total == 0 || options.data.length == 0) ? true : false; this._tidyMatchLabel(); this._renderData = _renderData = { list: this.matchList, isNoData: isNoData, blankDom: blankDom, nodataTip: options.nodataTip }; this.isNoData = isNoData; this.isShowFt = !this.isNoData; }, _createDom: function(type) { var html; if(type == 1) { html = tplA(this._renderData); this.$think_el.append(html); this.$think_el.find(".associate-pagin").cuiPagin(this.options.paginInfo).on("pageNoChange.cuiPagin", this.options.paginInfo.pageNoChange); } else { html = tplMain(this._renderData); this.$think_el = $(html); if(this.options.parentEl) { $(this.options.parentEl).append(this.$think_el); } else { $("body").append(this.$think_el); } this.$think_el.find(".associate-pagin").cuiPagin(this.options.paginInfo).on("pageNoChange.cuiPagin", this.options.paginInfo.pageNoChange); } if(this.options.paginInfo.total == 0) { if(this.options.blankDom == "") { this.$think_el.find(".associate-bd").height(21); } } else { this.$think_el.find(".associate-bd").height(this.options.paginInfo.pageItems * 30); } if(this.options.paginInfo.total <= this.options.paginInfo.pageItems) { this.$think_el.find(".associate-ft").hide(); this.isShowFt = false; this.$think_el.find(".associate-bd").addClass("no-bottom"); } //调整宽度 var tempWidth = this.triggerEle.width() < 228 ? 228 : this.triggerEle.width(); this.$think_el.width(tempWidth); if(type == 1) { this._adjustPanel(); } }, //给input增加onchange事件 _bindChange: function() { var self = this, inputValue = ""; this.triggerEle.on("keyup.cuiThinkInput", function() { inputValue = $(this).val(); if(self.inputValue === inputValue) { return; } self.inputValue = inputValue; self._emit('onChange', [$(this).val()]); if(!self.options.isBatch) { var data = self.allData; var tempArray = []; for(var i = 0; i < data.length; i++) { //if(data[i].label.indexOf(inputValue)>= 0||data[i].label.toUpperCase().indexOf(inputValue.toUpperCase())>=0||data[i].value.indexOf(inputValue.toUpperCase())>= 0 ||(data[i].num && data[i].num.indexOf(inputValue)>=0)){ //tempArray.push(data[i]); //} if(self.matchInput(inputValue, data[i].label) || (data[i].num && self.matchInput(inputValue, data[i].num)) || (data[i].value && self.matchInput(inputValue, data[i].value))) { tempArray.push(data[i]); } } self._iCall("data", [tempArray, tempArray.length, true]); } }); }, _tidyMatchLabel: function() { var inputValue = this.triggerEle.val(); var list = this.currentList; var matchList = $.extend(true, [], list); /** var matchList = []; for (var i = 0; i < list.length; i++) { var obj = {}; for(var key in list[i]){ obj[key] = list[i][key]; } matchList.push(obj); } **/ var search = inputValue.split(' '); for(var i = 0; i < matchList.length; i++) { for(var j = 0; j < search.length; j++) { var index = matchList[i].label.toUpperCase().indexOf(search[j].toUpperCase()); if(index != -1) { matchList[i].label = matchList[i].label.substring(0, index) + "" + matchList[i].label.substring(index, index + search[j].length) + "" + matchList[i].label.substring(index + search[j].length, matchList[i].label.length); } }; } this.matchList = matchList; }, _setPosition: function($el, $html, direction) { var aPosition = _position.getPosition($el, $html, direction); aPosition.top -= 10; if(this.options.parentEl) { //$html.position(aPosition); var parentPos = $(this.options.parentEl).offset(); var triggerPos = this.triggerEle.offset(); var pos = {}; pos.top = triggerPos.top - parentPos.top + this.triggerEle.outerHeight(); pos.left = triggerPos.left - parentPos.left - ($html.outerWidth() - this.triggerEle.outerWidth()) / 2; $html.css(pos); } else { $html.offset(aPosition); } }, /**联想面板显隐**/ _showAndHide: function() { var options = this.options, triggerEle = this.triggerEle, thisEl = this.$think_el, direction = 'bottom', self = this, thisHeight = thisEl.outerHeight(), //联想面板高度 thisWidth = thisEl.outerWidth(), //联想面板宽度 win = { height: $(window).height(), width: $(window).width(), scrollTop: $(window).scrollTop(), scrollLeft: $(window).scrollLeft() }; triggerEle.on("click.cuiThinkInput", function() { thisEl.show(); self._setPosition(triggerEle, thisEl, direction); self.isOpen = true; }); //这样会导致页面有多少联想输入就会给document绑定多次,但是不需要维护一个变量,后面待优化 $(document).on("click.cuiThinkInput" + this.randomNum, function(e, triggerTarget) { var $target = triggerTarget ? triggerTarget : $(e.target); if($target.closest(".cui-associate-panel")[0] !== thisEl[0] && $target[0] !== triggerEle[0]) { thisEl.hide(); self.isOpen = false; } }); }, //内部翻页 _onPageNoChage: function(current, pageItems) { this._dataByIndex(current); //this._renderCurrentPage(); this._tidyMatchLabel(); var _renderData = { list: this.matchList }; var html = tplB(_renderData); this.$think_el.find(".associate-bd").html("").html(html); }, //数据一次性传入的整合 _dealData: function() { var data = this.options.data, total = data.length, pageItems = this.options.paginInfo.pageItems, pageNum = Math.ceil(total / pageItems), lastPageNum = total % pageItems, dataByIndex = {}; if(total > 0) { if(pageNum == 1) { dataByIndex["0"] = data; } else { for(var i = 0; i < pageNum - 1; i++) { var onePageData = []; for(var j = 0; j < pageItems; j++) { onePageData.push(data[i * pageItems + j]); } dataByIndex[i + ""] = onePageData; } var lastPageData = []; lastPageNum = lastPageNum == 0 ? pageItems : lastPageNum; for(var k = 0; k < lastPageNum; k++) { lastPageData.push(data[(pageNum - 1) * pageItems + k]); } dataByIndex[pageNum - 1 + ""] = lastPageData; } } else if(total == 0) { dataByIndex["0"] = []; } this.pageNum = pageNum; this.dataByIndex = dataByIndex; this.total = total; }, _dataByIndex: function(pageIndex) { this.currentList = this.dataByIndex[pageIndex + ""]; if(!this.currentList) { this.currentList = this.dataByIndex["0"]; } this.currentTrueLength = this.currentList.length; if(this.currentList.length < this.options.paginInfo.pageItems) { for(var i = 0; i < this.options.paginInfo.pageItems - this.currentList.length; i++) { this.currentList.push({ label: "", num: "", value: "" }); } } this.currentPage = pageIndex; }, //匹配 matchInput: function(input, data) { /**var tempt=0; input = input.replace(/\s/g, ''); for(i=0;i= 0||data[i].label.toUpperCase().indexOf(inputValue.toUpperCase())>=0||data[i].value.indexOf(inputValue.toUpperCase())>= 0 ||(data[i].num && data[i].num.indexOf(inputValue)>=0)){ //tempArray.push(data[i]); //} if(self.matchInput(inputValue, data[i].label) || (data[i].num && self.matchInput(inputValue, data[i].num)) || self.matchInput(inputValue, data[i].value)) { tempArray.push(data[i]); } } this._iCall("data", [tempArray, tempArray.length, true, true]); } }, //渲染某页数据 _renderCurrentPage: function() { var $el = this.$think_el; $el.find('.associate-item').text(""); $.each(this.currentList, function(index, obj) { $el.find('.associate-item[index=' + index + ']').text(obj.label); }); }, //键盘向上键操作 _liUp: function(e) { var self = this, currentIndex = self.hoverIndex, $el = this.$think_el; if(self.isOpen && currentIndex != -1 && currentIndex > 0) { e.preventDefault(); self.hoverIndex--; this.$think_el.find('.associate-item[index="' + self.hoverIndex + '"]').trigger('mouseover'); } return false; }, //键盘向下键操作 _liDown: function(e) { var self = this, currentIndex = self.hoverIndex, $el = this.$think_el; if(self.isOpen && currentIndex < self.currentTrueLength - 1) { e.preventDefault(); self.hoverIndex++; this.$think_el.find('.associate-item[index="' + self.hoverIndex + '"]').trigger('mouseover'); } return false; }, _click: function() { if(this.hoverIndex != -1) { this.triggerEle.blur(); this.$think_el.find('.associate-item[index="' + this.hoverIndex + '"]').trigger('click'); } }, // 组件对外方法集 invoke: { /* * 修改当前页数据 * @param dataList 新的数据集合 * @param total 总的数据条数 */ data: function(dataList, total, isInner, isfromTarget) { var self = this, $el = this.$think_el; this.options.data = dataList; if(total != undefined) { this.options.paginInfo.total = total; this.$think_el.find(".associate-pagin").cuiPagin('total', total); } if(this.options.isBatch) { this.hoverIndex = -1; this.currentList = this.options.data; if(this.isNoData && this.currentList.length > 0) { this.currentList = this.options.data; var loop = this.options.paginInfo.pageItems - this.currentList.length; if(this.currentList.length < this.options.paginInfo.pageItems) { for(var i = 0; i < loop; i++) { this.currentList.push({ label: "", num: "", value: "" }); }; } var _renderData = { list: this.currentList }; var html = tplB(_renderData); $el.find(".associate-bd").html("").html(html); $el.find(".associate-bd").removeClass("no-bottom"); $el.find(".associate-bd").height(this.options.paginInfo.pageItems * 30); } else if(!this.isNoData && this.currentList.length > 0) { $el.find('.associate-item').text(""); $.each(this.options.data, function(index, obj) { var item = $el.find('.associate-item[index=' + index + ']'); item.html(obj.label).attr('title', obj.title); }); } else if(this.currentList.length == 0) { var _renderData = { isNoData: true, blankDom: this.options.blankDom, nodataTip: this.options.nodataTip }; var html = bodyTplC(_renderData); $el.find(".associate-bd").html("").html(html); $el.find(".associate-bd").addClass("no-bottom"); if(this.options.blankDom == "") { $el.find(".associate-bd").height(21); } } if(this.options.paginInfo.total <= this.options.paginInfo.pageItems) { this.$think_el.find(".associate-ft").hide(); this.isShowFt = false; this.$think_el.find(".associate-bd").addClass("no-bottom"); } else { this.$think_el.find(".associate-ft").show(); this.isShowFt = true; this.$think_el.find(".associate-bd").removeClass("no-bottom"); } } else { if(!isInner) { this.allData = this.options.data; } this.$think_el.html(""); this.hoverIndex = -1; this.currentList = []; var tempPageNum = this.pageNum; this._dealData(); if(tempPageNum != this.pageNum) { this._dataByIndex(0); this.options.paginInfo.current = 1; } else { this._dataByIndex(parseInt(this.options.paginInfo.current, 10) - 1); } this._preRenderData(isfromTarget); this._createDom(1); if(!isInner) { //this.$el.cuiOverlay("showSelf"); } } this.isNoData = (this.options.paginInfo.total == 0 || this.options.data.length == 0) ? true : false; this.isShowFt = !this.isNoData; }, //设置联想输入当前页 current: function(num) { var current = parseInt(num, 10); this.options.paginInfo.current = current; this.$think_el.find(".associate-pagin").cuiPagin("current", current); }, //打开面板 open: function() { this._emit('onOpen'); this.$think_el.show(); }, //关闭面板 close: function() { this.isOpen = false; this._emit('onClose'); this.$think_el.hide(); }, //显示加载 showLoading: function() { this.$think_el.find(".associate-bd").hide(); this.$think_el.find(".associate-ft").hide(); this.$think_el.find(".associate-loading").show(); }, //关闭加载 hideLoading: function() { this.$think_el.find(".associate-bd").show(); if(this.isShowFt) { this.$think_el.find(".associate-ft").show(); } else { this.$think_el.find(".associate-ft").hide(); } this.$think_el.find(".associate-loading").hide(); }, destroy: function() { this.$el.unbind('.' + this.uiName).removeData(this.uiName); this.$think_el.remove(); this.triggerEle.off("click.cuiThinkInput"); this.triggerEle.off("keyup.cuiThinkInput"); $(document).off("click.cuiThinkInput" + this.randomNum); for(var i = 0, len = cuiThinkInput.allThinkInput.length; i < len; i++) { if(cuiThinkInput.allThinkInput[i] === this) { cuiThinkInput.allThinkInput.splice(i, 1); } } } } }); var cuiThinkInput = {}; cuiThinkInput.allThinkInput = []; $(document).off('keydown.cuiThinkInput'); $(document).on('keydown.cuiThinkInput', function(event) { switch(event.keyCode) { case 38: $.each(cuiThinkInput.allThinkInput, function(i, item) { if(item.isOpen) { item._liUp(event); } }); break; case 40: $.each(cuiThinkInput.allThinkInput, function(i, item) { if(item.isOpen) { item._liDown(event); } }); break; case 13: $.each(cuiThinkInput.allThinkInput, function(i, item) { if(item.isOpen) { item._click(event); } }); break; default: break; } }); } }, { "../../base/position/index": 10, "./bodyTplA.tpl": [function(require, module, exports) { module.exports = "
\n
\n
\n\t{{if isNoData == true}}\n\t\t{{if blankDom == \"\"}}\n\t\t\t
\n\t\t\t {{nodataTip}}\n
\n {{else}} \n \t
\n\t\t\t\t{{nodataTip}}\n
\n \t
\n\t\t\t\t{{#blankDom}}\n
\n {{/if}}\n\t{{else}}\n\t\t
\n\t\t\t
    \n\t\t\t\t{{each list}}\n\t\t\t\t\t
  • {{#$value.label}}
  • \n\t\t\t\t{{/each}}\n\t\t\t
\n\t\t
\n\t{{/if}}\n
\n
\n\t
\n\t
\n
\n
\n\t
\n\t \n\t 数据读取中....\n\t
\n
"; }, {}], "./bodyTplB.tpl": [function(require, module, exports) { module.exports = "
\n\t
    \n\t\t{{each list}}\n\t\t\t
  • {{#$value.label}}
  • \n\t\t{{/each}}\n\t
\n
"; }, {}], "./bodyTplC.tpl": [function(require, module, exports) { module.exports = "{{if blankDom == \"\"}}\n\t
\n\t\t{{nodataTip}}\n
\n{{else}} \n\t
\n\t\t{{nodataTip}}\n
\n\t
\n\t\t{{#blankDom}}\n
\n{{/if}}"; }, {}], "./main.tpl": [function(require, module, exports) { module.exports = "
\n\t\t
\n\t\t
\n\t
\n\t\t{{if isNoData == true}}\n\t\t\t{{if blankDom == \"\"}}\n\t\t\t\t
\n\t\t\t\t\t{{nodataTip}}\n\t
\n\t {{else}}\n\t \t
\n\t\t\t\t\t{{nodataTip}}\n\t
\n\t \t
\n\t\t\t\t\t{{#blankDom}}\n\t
\n\t {{/if}} \n\t\t{{else}}\n\t\t\t
\n\t\t\t\t
    \n\t\t\t\t\t{{each list}}\n\t\t\t\t\t\t
  • {{#$value.label}}
  • \n\t\t\t\t\t{{/each}}\n\t\t\t\t
\n\t\t\t
\n\t\t{{/if}}\n\t
\n\t
\n\t\t
\n\t\t
\n\t
\n\t
\n\t\t
\n\t\t \n\t\t 数据读取中....\n\t\t
\n\t
\n
"; }, {}] }]; var cuiToolTipImpl = [function(require, module, exports) { /* * @desc tooltips组件,依赖于cuiDialog */ module.exports = function() { $.cuiFactory("cuiToolTip", { VERSION: '1.0.0', options: { trigger: 'hover focus', title: '', placement: 'top', delay: 0, time: 2000 // if time > 0, and trigger is 'click', the tip will close auto after time }, _create: function() { var options = this.options, self = this; // 绑定事件 var triggers = options.trigger, triggerArr = triggers.split(' '); for(var i = 0, len = triggerArr.length; i < len; i++) { var trigger = triggerArr[i]; if(trigger === 'click') { this.$el.on('click.' + this.uiName, this.$el, $.proxy(this._toggle, this)); } else if(trigger !== 'manual') { var eventIn = trigger === 'hover' ? 'mouseenter' : 'focusin'; var eventOut = trigger === 'hover' ? 'mouseleave' : 'focusout'; this.$el.on(eventIn + '.' + this.uiName, this.$el, $.proxy(this._enter, this)); this.$el.on(eventOut + '.' + this.uiName, this.$el, $.proxy(this._leave, this)); } } }, _enter: function() { var options = this.options; var self = this; clearTimeout(this.timeout); this.hoverState = 'in'; if(!options.delay) return this._openTip(); // add the timeout this.timeout = setTimeout(function() { if(self.hoverState == 'in') self._openTip(); }, options.delay); }, _leave: function() { var options = this.options; var self = this; clearTimeout(this.timeout); this.hoverState = 'out'; if(!options.delay) return this._closeTip(); this.timeout = setTimeout(function() { if(self.hoverState == 'out') self._closeTip(); }, options.delay) }, /** * * place 2 param */ _Place2Param: function() { var place = this.options.placement; var placeObj = { 'top': 1, 'right': 2, 'bottom': 3, 'left': 4 } return placeObj[place]; }, _toggle: function() { var tip = this.$el.data('cuitip'); if(tip) { this._closeTip(); } else { this._openTip(); } }, _openTip: function() { var options = this.options, self = this, time = (options.trigger === 'click' && options.time > 0) ? options.time : 0; //2016-7-22 enzhang增(避免title为空的bug) if(!this._getTitle()) return; this._emit('show', [this.$el]); this.$el.data('cuitip', dialog.tips(this._getTitle(), this.$el, { tips: [this._Place2Param()], time: time, end: function() { self.$el.data('cuitip', null); self._emit('hide', [this.$el]); self._emit('hidden', [this.$el]); } })); this._emit('shown', [this.$el]); }, /* * return title * if title is function, return the function apply result; */ _getTitle: function() { var options = this.options, title; title = typeof options.title === 'function' ? options.title.call(this.$el[0]) : options.title; title = title ? title : this.$el.attr('title'); return title; }, _closeTip: function() { var tip = this.$el.data('cuitip'); if(!tip) return; var options = this.options; this._emit('hide', [this.$el]); dialog.close(tip); this.$el.data('cuitip', null); this._emit('hidden', [this.$el]); }, // 对外方法 invoke: { hide: function() { this._closeTip(); }, show: function() { this._openTip(); }, setContent: function(title) { if(!title || title === '') { console.warn('[OASTOOTIP]: title is invalid'); return; } this.options.title = title; } } }); $('[cuitooltip],[data-toggle="cuiToolTip"]').cuiToolTip({}); } }, {}]; var cuiTreeEnhanceImpl = [function(require, module, exports) { var treeTpl = template.compile(require("./tree.tpl")), treeRootTpl = template.compile(require("./tree_root.tpl")); treeRootRenderTpl = template.compile(require("./tree_root_render.tpl")); module.exports = function() { $.cuiFactory("cuiTreeEnhance", { VERSION: '1.0.0', options: { // 根节点 root: null, //树的数据集合:[{icon:"",label:"",id:"",pid:"",checked:false,selected:false,disabled:false,isAdd:false,isEdit:true,isDelete:true;hasChild:true;}] data: [], //树数据的数据形式,“array”为一维数组形式,“tree”树形形式; dataType: "array", //是否有checkbox:null、"checkbox"、"radio" checkType: null, //整个树disable disable: false, //所有被选中的节点id的集合 checkedIds: [], //部分勾选节点是否返回,true:返回,false:不返回 (是否返回所有上层父节点 该功能结合勾选的多种模式使用) returnPartChecked: false, //树有大小两种无数据样式0:小样式,1:大样式 noDataStyle: 0, //Y 属性定义 checkbox 被勾选后的情况; N 属性定义 checkbox 取消勾选后的情况; "p" 表示操作会影响父级节点; "s" 表示操作会影响子级节点。 checkboxEffect: { "Y": "ps", "N": "ps" }, //组件初始化展示方式:0:展示一级菜单其余全部收起;1:全部展开,显示所有节点;2:收起全部 showType: 1, //树组件的高度,默认“auto” 只能是数字形式 需要为容器添加overflow属性 height: "auto", //树组件的宽度,默认“auto” 只能是数字形式 需要为容器添加overflow属性 width: "auto", //是否可以增加节点 (只有这个属性开启并且节点有isAdd:true,才可以添加) addController: false, // 添加节点弹出的模板 该属性为null则代表,则不启用点击事件(用户可根据自己需求进行设置) // 若传入模板id 则调用模板进行处理 createTPLId: null, //是否可以删除节点 deleteController: false, //是否可以编辑 editController: false, // 添加节点弹出的模板 editTPLId: null, //初始化时是否全部折叠(大数据模式下该属性失效) isInitOpen: true, // 是否支持搜索 isSearch: false, //是否大数据 bigData: false, url: null, icon: $.noop(), // 是否启用分页 pageController: false, pageSize: 1000 }, // 节点默认字段 nodeField: { checkType: null, disabled: false, label: '', nlevel: 0, isEdit: false, isAdd: false, isDelete: false, checked: false, hasChild: false, isParent: false, icon: 'cuicon-details' }, _create: function() { this._definInitData(); this._initModel(); }, /** * 操作 */ // 初始化模型 _initModel: function() { // 获取加载模型 var loadModel = this._loaderController(); loadModel.apply(this); // 设置宽高 this._setTreeWH(); }, /** * [_dataLoad 直接传入data加载模式] * @DateTime 2017-06-29 * @copyright [copyright] * @license [license] * @version [version] * @return {[type]} [description] */ _dataLoad: function() { this._dataLoadInitData(); this._dealInitData(); this._createRootDom(this._renderData); this._createDom(this._renderData); }, /** * [_onceLoad url一次加载模式] * @DateTime 2017-07-01 * @copyright [copyright] * @license [license] * @version [version] * @param {[type]} $url [description] * @return {[type]} [description] */ _onceLoad: function($url) { this._onceLoadInitData(); var that = this, url = ''; if($url === undefined) { url = that.options.url; } else { url = $url; } that._model = cui.baseModel.extend({ statics: { baseUrl: url } }); that._model.list().then(function(res) { if(res.code === 0) { // 创建节点 that.options.data = res.data; that._dealInitData(); that._createRootDom(that._renderData); that._createDom(that._renderData); } }); }, /** * [_fenyeLoad 分页加载模式] * @DateTime 2017-07-01 * @copyright [copyright] * @license [license] * @version [version] * @param {[type]} $url [当重置时 url起作用] * @return {[type]} [description] */ _fenyeLoad: function($url) { this._fenyeLoadInitData(); // 初始化分页条件 var ps = this.options.pageSize, url = ''; if($url === undefined) { url = this.options.url; } else { url = $url; } this._model = cui.baseModel.extend({ statics: { baseUrl: url } }); this._model.condition = { page: 1, pagesize: ps, id: '-1' }; this._getFenyeData(); }, /** * [_getFenyeData 第一次分页获取数据第一次要对root节点进行处理] * @DateTime 2017-06-30 * @copyright [copyright] * @license [license] * @version [version] * @param {[type]} $ul [如果有对应dom 则追加到dom上] * @return {[type]} [description] */ _getFenyeData: function(obj) { var that = this; // 分页初始化 this._fenyeReset(); // 每一次分页查询需要初始化 this._eachfenyeReset(); that._model.list(this._model.condition).then(function(res) { if(res.code === 0) { //标识第一页 that.isFirstPage = true; that.isLastPage = false; // 识别是否为最后一页 if((that._model.condition.page * that._model.condition.pagesize) >= res.pagin.records) { that.isLastPage = true; } // 创建节点 that.options.data = res.data; that._dealInitData(); if(obj !== undefined && obj.nodeid !== undefined) { for(var i = 0; i < that.bakData.length; i++) { that.kvNodes[obj.nodeid].childList.push(that.bakData[i]); } } // 初次调用 需要记载用户定义根节点 if(that.firstInit === true) { that._createRootDom(that._renderData); that._createFenyeDom(that._renderData, obj); that.firstInit = false; } else { that._createFenyeDom(that._renderData, obj); } if((that._model.condition.page * that._model.condition.pagesize) < res.pagin.records) { // 下一页 that._model.condition.page += 1; that.getDataByPagin(obj); } } }); }, // 分页获取数据 getDataByPagin: function(obj) { var that = this; this._eachfenyeReset(); that._model.list(this._model.condition).then(function(res) { if(res.code === 0) { //标识第一页 that.isFirstPage = false; // 识别是否为最后一页 if((that._model.condition.page * that._model.condition.pagesize) >= res.pagin.records) { that.isLastPage = true; } that.options.data = res.data; that._dealInitData(); // 点击事件时添加childList if(obj !== undefined && obj.nodeid !== undefined) { for(var i = 0; i < that.bakData.length; i++) { that.kvNodes[obj.nodeid].childList.push(that.bakData[i]); } } that._createFenyeDom(that._renderData, obj); if((that._model.condition.page * that._model.condition.pagesize) < res.pagin.records) { // 下一页 that._model.condition.page += 1; that.getDataByPagin(obj); } } }); }, _createRootDom: function(data) { var $el = this.$el, // nodata: 是否有数据;verticalLine控制竖直线的样式;showHorizontalLine 控制水平线的样式 temp = { hasRoot: false, nodata: false, root: this.bakRoot, noDataStyle: this.options.noDataStyle, isSearch: this.options.isSearch, verticalLine: '', showHorizontalLine: false, }; // 如果有自己诶按显示数字线,若第一个子节点不包含子节点则显示长竖直线, // 如果第一个子节点是父节点且没有更节点只有一个子节点则显示横线 if(this.bakRoot != null && !$.isEmptyObject(this.bakRoot)) { temp.hasRoot = true; if(data.length > 0) { temp.verticalLine += 'show'; if(data[0].isParent === false) { temp.verticalLine += ' lg'; } if(data[0].isParent === false && data.length === 1) { temp.showHorizontalLine = true; } } } // 根节点渲染 if(data.length === 0) { temp.nodata = true; $el.empty().append(treeRootTpl(temp)).addClass("cui-tree"); return; } else { $el.empty().append(treeRootTpl(temp)).addClass("cui-tree"); } }, _renderRootDom: function(data) { var $el = this.$el, // nodata: 是否有数据;verticalLine控制竖直线的样式;showHorizontalLine 控制水平线的样式 temp = { hasRoot: false, nodata: false, root: this.bakRoot, noDataStyle: this.options.noDataStyle, isSearch: this.options.isSearch, verticalLine: '', showHorizontalLine: false, }; // 如果有自己诶按显示数字线,若第一个子节点不包含子节点则显示长竖直线, // 如果第一个子节点是父节点且没有更节点只有一个子节点则显示横线 if(this.bakRoot != null && !$.isEmptyObject(this.bakRoot)) { temp.hasRoot = true; if(data.length > 0) { temp.verticalLine += 'show'; if(data[0].isParent === false) { temp.verticalLine += ' lg'; } if(data[0].isParent === false && data.length === 1) { temp.showHorizontalLine = true; } } } // 根节点渲染 if(data.length === 0) { temp.nodata = true; $el.find('.treeContainer').empty().append(treeRootRenderTpl(temp)); return; } else { $el.find('.treeContainer').empty().append(treeRootRenderTpl(temp)); } }, //创建树子节点 _createDom: function(data) { var $el = this.$el; for(var i = 0; i < data.length; i++) { this._loopNodes(data[i], 0, this.bigData); } if(this.bigData) { this._appendHtml($el.find(".cuiTree-nodes"), this.nodesString); } else { $el.find(".cuiTree-nodes").append(this.nodesString.join('')); } }, //创建树子节点 _createFenyeDom: function(data, obj) { var $el = this.$el; for(var i = 0; i < data.length; i++) { this._fenyeLoopNodes(data[i], 0, this.bigData); } if(obj === undefined || obj.$ul === undefined) { $el.find(".cuiTree-nodes").append(this.nodesString.join('')); } else { // this.kvNodes[]; obj.$ul.append(this.nodesString.join('')); } }, // node节点数组转化为 _nodes2DomString: function(nodeArray) { var stringArray = []; for(var i = 0; i < nodeArray.length; i++) { var spanStatus = ''; i === nodeArray.length - 1 ? (spanStatus = 'bottom-docu') : (spanStatus = 'center-docu'); var iconClass = this._getIconClass(nodeArray[i]); stringArray.push(treeTpl({ $node: nodeArray[i], $spanStatus: spanStatus, $iconClass: iconClass })); } return stringArray; }, //递归树节点 _loopNodes: function(node, isSelf, isBigData) { if(!isSelf) { this.nodeLevel = 0; node.level = this.nodeLevel; } node.isOpen = !isBigData; var spanStatus = this._getSpanStatus(node); var iconClass = this._getIconClass(node); this.nodesString.push(treeTpl({ $node: node, $spanStatus: spanStatus, $iconClass: iconClass })); if(node.childList && node.childList.length > 0) { this.nodeLevel++; for(var i = 0; i < node.childList.length; i++) { node.childList[i].level = this.nodeLevel; node.childList[i].isFirstNode = (i == 0) ? true : false; node.childList[i].isLastNode = (i == node.childList.length - 1) ? true : false; } if(!isBigData) { for(var j = 0; j < node.childList.length; j++) { this._loopNodes(node.childList[j], 1); } } } this.nodesString.push(""); }, //递归树节点 _fenyeLoopNodes: function(node, isSelf, isBigData) { if(!isSelf) { this.nodeLevel = 0; node.level = this.nodeLevel; } // node.isOpen = !isBigData; var spanStatus = this._getFenyeSpanStatus(node); var iconClass = this._getIconClass(node); this.nodesString.push(treeTpl({ $node: node, $spanStatus: spanStatus, $iconClass: iconClass })); if(node.childList && node.childList.length > 0) { this.nodeLevel++; for(var i = 0; i < node.childList.length; i++) { node.childList[i].level = this.nodeLevel; node.childList[i].isFirstNode = (i == 0 && this.isFirstPage) ? true : false; node.childList[i].isLastNode = (i == node.childList.length - 1 && this.isLastPage) ? true : false; } for(var j = 0; j < node.childList.length; j++) { this._fenyeLoopNodes(node.childList[j], 1); } } this.nodesString.push(""); }, _setTreeWH: function() { var $el = this.$el; _.isNumber(this.options.width) ? $el.width(this.options.width) : undefined; _.isNumber(this.options.height) ? $el.height(this.options.height) : undefined; }, _appendHtml: function(container, html) { var start = 0, len = html.length, nowHtml, time = 0; while(time * 1000 < len) { nowHtml = html.slice(time * 1000, 1000 * ++time); (function(container, nowHtml) { setTimeout(function() { container.append(nowHtml); }, time * 100) })(container, nowHtml) } }, /** * 数据定义 */ _definInitData: function() { // 记录被select nodeId this.selectedNodeId = ""; // 记录被checked 所有节点 this.checkedNodes = []; // 存放树形 结构被转化成数组的数据 this.arrayTypeData = []; // 存放每个节点的html字符串 this.nodesString = []; // 用于记录 key value 格式 便于查找、操作 this.kvNodes = {}; // 放置用于渲染的数组 this._renderData = []; // node的层级标识 this.nodeLevel = 0; // 是否启用大数据加载模式 this.bigData = this.options.bigData; // 为了适应非分页情况 初始化页数 this.isFirstPage = true; this.isLastPage = true; // 第一次初始化标识 this.firstInit = true; this.triggerFlag = false; this.triggerValue = undefined; // 记录被checked的节点 this.onceCheckChangeNodes = []; }, _dealInitData: function() { this.bakRoot = $.extend(true, {}, this.options.root); this.bakData = $.extend(true, [], this.options.data); this._dealBakRoot(); this._dealBakData(); }, _dealBakRoot: function() { // 是否禁用 if(this.options.disable) { this.bakRoot.disabled = true; } }, _dealBakData: function() { //统一数据为数组形式 var dataConverter = this._dataTypeController(); dataConverter.apply(this); // 将node数组转化为标准形式 this._nodes2standard(this.bakData); // 处理禁用 this._dealDisabled(); // 处理是否打开 this._dealIsInitOpen(); // 为所有节点添加勾选状态 this._concatChecked(); // 记录被选中的节点到 checkedNodes this._dealCheckedNodes(); // 记录选中的节点 this._dealSelected(); // 记录节点类型 this._dealCheckType(); // 记录是否为父节点 this._dealIsParent(); // 记录初始化增删改的数据 this._dealAddDelEdit(); // 记录初始化icon this._dealInitIcon(); // 生成key value格式数据 this._generateKv(); // 准备渲染的数据 this._preRenderData(); // 添加区别第一还是最后一个Node的字段 this._addIsFirstOrlastNode(); }, _nodes2standard: function(array) { for(var i = 0; i < array.length; i++) { array[i] = this._node2standard(array[i]); } }, _node2standard: function(node) { var nodeRoot = $.extend(true, {}, node); for(key in this.nodeField) { if(key === 'checkType') { nodeRoot.checkType = nodeRoot[key] || this.options.checkType; } else if(key === 'disabled') { nodeRoot.disabled = nodeRoot[key] || this.options.disable; } else if(key === 'icon' && this.options.icon !== undefined) { nodeRoot.icon = nodeRoot[key] || this.options.icon(nodeRoot); } else { nodeRoot[key] = nodeRoot[key] || this.nodeField[key]; } } return nodeRoot; }, // 将转换后的数据封装到bakData _tidyData: function() { var data = this.bakData; this._tree2Array(data); //子节点已没有必要存在 _.forEach(this.arrayTypeData, function(node, i) { delete node.childList; }); this.bakData = this.arrayTypeData; }, //树形数据转换成数组 _tree2Array: function(data) { for(var i = 0; i < data.length; i++) { this.arrayTypeData.push(data[i]); if(data[i].childList && data[i].childList.length > 0) { this._tree2Array(data[i].childList); } } }, // 处理选checked _concatChecked: function() { var that = this; _.forEach(that.bakData, function(node, i) { _.forEach(that.options.checkedIds, function(checkedNodeId, j) { if(node.id === checkedNodeId) { node.checked = true; return false; } }) }) }, // 处理禁用 _dealDisabled: function() { if(this.options.disable) { _.forEach(this.bakData, function(node, i) { node.disabled = true; }) } }, // 记录初始化打开 _dealIsInitOpen: function() { if(this.options.isInitOpen) { _.forEach(this.bakData, function(node, i) { node.isInitOpen = true; }) } }, // 记录selected _dealSelected: function() { var that = this; _.forEach(this.bakData, function(node, i) { if(node.selected && that.selectedNodeId === "") { that.selectedNodeId = "" + node.id; } }) }, // 记录checkType _dealCheckType: function() { var that = this; _.forEach(this.bakData, function(node, i) { node.checkType = that.options.checkType; }) }, // 记录是否父节点 _dealIsParent: function() { _.forEach(this.bakData, function(node, i) { node.isParent = false; node.hasChild === true ? (node.isParent = true) : (node.isParent = false); }) }, // 处理增删改 _dealAddDelEdit: function() { var that = this; _.forEach(this.bakData, function(node, i) { node.isAdd = that.options.addController && node.isAdd; node.isEdit = that.options.editController && node.isEdit; node.isDelete = that.options.deleteController && node.isDelete; }) }, // 记录初始化icon _dealInitIcon: function() { var that = this; _.forEach(this.bakData, function(node, i) { if(that.options.icon !== undefined) { node.icon = that.options.icon(node); } else if(node.icon === undefined) { node.icon = ""; } }) }, // 保存checkedNodes _dealCheckedNodes: function() { var that = this; _.forEach(this.bakData, function(node, i) { if(node.checked) { _.remove(that.checkedNodes, { id: node.id }); that.checkedNodes.push(node); } }) }, _dataLoadInitData: function() { // 每次单次加载都要清空前一次的数据 this.nodesString = []; // 若为树结构需要初始化 this.arrayTypeData = []; }, // 单词加载初始化数据 _onceLoadInitData: function() { // url单次加载 必须是array this.options.dataType = "array"; // 每次单次加载都要清空前一次的数据 this.nodesString = []; }, // 分页加载初始化数据 _fenyeLoadInitData: function() { // 分页加载 必须是array this.options.dataType = "array"; this.options.bigData = false; this.bigData = false; }, // 为分一次分页查询 重置必要数据 _eachfenyeReset: function() { // 清空nodeString this.nodesString = []; }, _fenyeReset: function() { this._model.condition.page = 1; }, // 生成key value形式 _generateKv: function() { var that = this; _.forEach(this.bakData, function(node, i) { node.childList === undefined ? (node.childList = []) : undefined; that.kvNodes['' + node.id] = node; }) }, _preRenderData: function() { this._renderData = this._transformTozTreeFormat(); }, // 为第一个 和最后一个元素添加标识 _addIsFirstOrlastNode: function() { for(var i = 0; i < this._renderData.length; i++) { this._renderData[i].isFirstNode = (i == 0 && this.isFirstPage) ? true : false; this._renderData[i].isLastNode = (i == this._renderData.length - 1 && this.isLastPage) ? true : false; } }, // 处理树的核心方法 _transformTozTreeFormat: function() { var sNodes = this.bakData; var i, l; var r = []; var tmpMap = []; for(i = 0, l = sNodes.length; i < l; i++) { tmpMap[sNodes[i]["id"]] = sNodes[i]; } for(i = 0, l = sNodes.length; i < l; i++) { // 是否有子节点 if(tmpMap[sNodes[i]["pid"]] && sNodes[i]["id"] != sNodes[i]["pid"]) { tmpMap[sNodes[i]["pid"]].isParent = true; if(!tmpMap[sNodes[i]["pid"]]["childList"]) { tmpMap[sNodes[i]["pid"]]["childList"] = []; } tmpMap[sNodes[i]["pid"]]["childList"].push(sNodes[i]); } else { r.push(sNodes[i]); } } return r; }, // 获取展开关闭那边的样式 _getSpanStatus: function(node) { var spanStatus = ''; if(node.isParent) { if(node.level == 0 && node.isFirstNode) { if(this._renderData.length > 1) { spanStatus = (node.isOpen && node.isInitOpen) === true ? 'roots-open' : 'roots-close'; } else { spanStatus = (node.isOpen && node.isInitOpen) === true ? 'root-open' : 'root-close'; } } else { if(node.isLastNode === true) { spanStatus = (node.isOpen && node.isInitOpen) === true ? 'bottom-open' : 'bottom-close'; } else { spanStatus = (node.isOpen && node.isInitOpen) === true ? 'center-open' : 'center-close'; } } } else { if(node.isLastNode === true) { spanStatus = (node.isFirstNode && node.level == 0) ? 'root-docu' : 'bottom-docu'; } else if(node.isFirstNode && node.level == 0) { spanStatus = 'roots-docu'; } else { spanStatus = 'center-docu'; } } return spanStatus; }, // 分页情况下获取展开关闭那边的样式 _getFenyeSpanStatus: function(node) { var spanStatus = ''; if(node.hasChild) { // 第一层 第一个节点具有根节点样式 if(node.level == 0 && node.isFirstNode && this.firstInit === true) { spanStatus = (this._renderData.length > 1) ? 'roots-close' : 'root-close'; } else { spanStatus = (node.isLastNode === true) ? 'bottom-close' : 'center-close'; } } else { if(node.isLastNode === true) { spanStatus = (node.isFirstNode && node.level == 0) ? 'root-docu' : 'bottom-docu'; } else if(node.isFirstNode && node.level == 0) { spanStatus = 'roots-docu'; } else { spanStatus = 'center-docu'; } } return spanStatus; }, // 获取图片样式 _getIconClass: function(node) { var iconClass = ''; node.level == 0 ? iconClass += ' node-top ' : 0; if(node.isParent === true) { iconClass += ' bigger '; (!!node.icon === true && node.icon.length > 0) ? iconClass += (' cuicon ' + node.icon): iconClass += ' cuicon cuicon-folder'; } else { (!!node.icon === true && node.icon.length > 0) ? iconClass += (' cuicon ' + node.icon): iconClass += ' cuicon cuicon-details'; } return iconClass; }, // 获取父节点 _getParentNode: function(id) { return this.kvNodes['' + this.kvNodes['' + id].pid]; }, _appendNodes: function(container, nodeList) { var start = 0, len = nodeList.length, list, time = 0; that = this; while(time * 1000 < len) { list = nodeList.slice(time * 1000, 1000 * ++time); (function(container, list) { setTimeout(function() { var htmlNow = []; list.forEach(function(node) { var spanStatus = that._getSpanStatus(node); var iconClass = that._getIconClass(node); htmlNow.push(treeTpl({ $node: node, $spanStatus: spanStatus, $iconClass: iconClass })); htmlNow.push(''); }) container.append(htmlNow.join('')); }, time * 100) })(container, list); } }, _judgeParentNode: function(pid) { var pNode = this.kvNodes['' + pid]; if(!pNode || !pNode.childList || pNode.childList.length === 0) { return; } var childrenNotDisabled = []; var childrenCheckeds = 0; _.forEach(pNode.childList, function(node, i) { if(!node.disabled) { childrenNotDisabled.push(node); node.checked ? childrenCheckeds++ : undefined; } }) if(childrenCheckeds === childrenNotDisabled.length) { pNode.checked = true; if(!_.find(this.checkedNodes, { id: pid })) { this.onceCheckChangeNodes.push(pNode); } _.remove(this.checkedNodes, { id: pid }); this.checkedNodes.push(pNode); this.$el.find('li[nodeid="' + pid + '"]>input[type=checkbox]').prop("checked", true); this._judgeParentNode(pNode.pid); } else if(childrenCheckeds < childrenNotDisabled.length) { if(pNode.checked) { pNode.checked = false; _.remove(this.checkedNodes, { id: pid }); this.onceCheckChangeNodes.push(pNode); this.$el.find('li[nodeid="' + pid + '"]>input[type=checkbox]').prop("checked", false); this._judgeParentNode(pNode.pid); } } }, _judgeParentNodeByZ: function(pid) { var pNode = this.kvNodes['' + pid]; if(!pNode || !pNode.childList || pNode.childList.length === 0) { return; } // 可用节点数 var childrenNotDisabled = []; // 勾选节点数 var childrenCheckeds = 0; _.forEach(pNode.childList, function(node, i) { if(!node.disabled) { childrenNotDisabled.push(node); node.checked ? childrenCheckeds++ : undefined; } }) if(childrenCheckeds === 0) { if(pNode.checked) { pNode.checked = false; _.remove(this.checkedNodes, { id: pid }); this.onceCheckChangeNodes.push(pNode); this.$el.find('li[nodeid="' + pid + '"]>input[type=checkbox]').prop("checked", false); this._judgeParentNodeByZ(pNode.pid); } } else { pNode.checked = true; if(!_.find(this.checkedNodes, { id: pid })) { this.onceCheckChangeNodes.push(pNode); } _.remove(this.checkedNodes, { id: pid }); this.checkedNodes.push(pNode); this.$el.find('li[nodeid="' + pid + '"]>input[type=checkbox]').prop("checked", true); this._judgeParentNodeByZ(pNode.pid); } }, _makeChildrenDone: function(pNode, status) { var that = this; // nodeid = xxx 下面的所有checkbox this.$el.find('li[nodeid="' + pNode.id + '"] input[type=checkbox]').prop('checked', status); _.forEach(pNode.childList, function(node, i) { if(!node.disabled) { if(node.checked !== status) { that.onceCheckChangeNodes.push(node); if(status) { that.checkedNodes.push(node) } else { _.remove(that.checkedNodes, { id: node.id }) } } node.checked = status; if(node.isParent && node.childList && node.childList.length > 0) { that._makeChildrenDone(node, status); } else { // 如果没有子节点了 则在此处改变当前节点的状态 that.$el.find('li[nodeid="' + node.id + '"] input[type=checkbox]').prop('checked', status); } } }); }, // 准备好 options.data对树进行加载 _onceLoadByData: function() { this._onceLoadInitData(); this._dealInitData(); this._createRootDom(this._renderData); this._createDom(this._renderData); }, _findGrandSons: function(searchInfo) { var showIds = this._iCall('searchShowIds', [searchInfo]), grandSon = []; // 找出最后面的节点,即该节点的所有孙子节点都不在需要展示的集合 for(var k = 0; k < showIds.length; k++) { var cIds = this._iCall('searchAllCidsById', [showIds[k]]); if(!cui.util.hasSameElement(cIds, showIds)) { grandSon.push(showIds[k]); } } return grandSon; }, /** * [setHighLightLabel 高亮匹配到的文字] * @DateTime 2017-07-14 * @copyright [copyright] * @license [license] * @version [version] * @param {[type]} searchInfo [需要高亮的文字] * @param {[type]} nodeids [需要文字高亮的节点id的集合] * @return {[type]} [description] */ setHighLightLabel: function(searchInfo, nodeIds) { var $el = this.$el, highLabel = '' + searchInfo + ''; for(var i = 0; i < nodeIds.length; i++) { var newLabel = ''; var nodeLabel = $el.find('li[nodeid="' + nodeIds[i] + '"] >a >.nodeLabel').html(); var array = nodeLabel.split(searchInfo); for(var j = 0; j < array.length; j++) { newLabel += array[j]; j === (array.length - 1) ? newLabel += highLabel : undefined; } $el.find('li[nodeid="' + nodeIds[i] + '"] >a >.nodeLabel').html(newLabel); } }, /** * 控制器 */ /** * [_loaderController 加载模式选择器] * @DateTime 2017-06-29 * @copyright [copyright] * @license [license] * @version [version] * @return {[type]} [description] */ _loaderController: function() { // 加载模式选择器 if(!!this.options.url === false) { return this._dataLoad; } else { if(this.options.pageController === false) { return this._onceLoad; } else { return this._fenyeLoad; } } }, /** * [dataType 数据类型控制器] * @DateTime 2017-06-29 * @copyright [copyright] * @license [license] * @version [version] * @return {[type]} [description] */ _dataTypeController: function() { if(this.options.dataType === "tree") { return this._tidyData; } else { return function() {}; } }, events: { //指定绑定事件的元素 'target': function() { return this.$el; }, // 展开关闭按钮 'click li>span': function(self, evt) { var className = $(self)[0].className; if(className.indexOf("docu") != -1) { return false; } if(className.indexOf("open") != -1) { $(self).removeClass(className).addClass(className.split("-")[0] + "-close"); // 分页模式 删除子节点 ; 非分页,隐藏子节点 $(self).closest('li').find('>ul').hide(); } if(className.indexOf("close") != -1) { $(self).removeClass(className).addClass(className.split("-")[0] + "-open"); $(self).closest('li').find('>ul').show(); // 大数据情况 第一次进来获取,以后隐藏 if(this.bigData) { var data = this.kvNodes, $li = $(self).closest('li'), pid = $li.attr('nodeid'), node = data[pid], $ul = $li.find('ul'), html = []; node.childList.forEach(function(one, i, list) { one.isFirstNode = (i == 0) ? true : false; one.isLastNode = (i == list.length - 1) ? true : false; }) if(node && !$li.data('hasRendered')) { this._appendNodes($ul, node.childList); $li.data('hasRendered', true); } } // 分页模式处理 if(this.options.pageController === true) { var $li = $(self).closest('li'), pid = $li.attr('nodeid'), $ul = $li.find('ul'); if(!$li.data('hasRendered')) { var obj = {}; var nodeid = $(self).parents('li').attr('nodeid'); this._model.condition.id = nodeid; obj.$ul = $ul; obj.nodeid = nodeid; this._getFenyeData(obj); // for(var i=0 ; ia': function(self, evt) { if($(self).closest("li").hasClass("node-disabled")) { return; } this.$el.find("a").removeClass("current"); $(self).addClass("current"); this.selectedNodeId = $(self).closest("li").attr("nodeid"); this._emit('select', [this._iCall("getSelectedNode")]); }, 'click .cuiTree-root>a': function(self, evt) { if($(self).closest(".cuiTree-root").hasClass("node-disabled")) { return; } this.$el.find("a").removeClass("current"); $(self).addClass("current"); this.selectedNodeId = ""; this._emit('select', [this.bakRoot]); }, 'dblclick .cuiTree-root>a': function(self, evt) { if(this._renderData.length === 0) { return; } this.$el.find(".cuiTree-nodes").toggle(); this.$el.find(".cuiTree-root>span").toggleClass("show"); }, 'click li>input[type=checkbox]': function(self, evt) { var node = this.kvNodes[$(self).closest("li").attr("nodeid")]; var status = $(self).prop("checked"); if(this.triggerFlag) { status = this.triggerValue; } this.onceCheckChangeNodes = []; // 选中 if(status) { node.checked = true; if(!_.find(this.checkedNodes, { id: node.id })) { this.onceCheckChangeNodes.push(node); } _.remove(this.checkedNodes, { id: node.id }); this.checkedNodes.push(node); if(this.options.checkboxEffect.Y.indexOf("p") > -1) { this._judgeParentNode(node.pid); } if(this.options.checkboxEffect.Y.indexOf("z") > -1) { this._judgeParentNodeByZ(node.pid); } if(this.options.checkboxEffect.Y.indexOf("s") > -1) { node.isParent ? this._makeChildrenDone(node, status) : undefined; } } else { node.checked = false; _.remove(this.checkedNodes, { id: node.id }); this.onceCheckChangeNodes.push(node); if(this.options.checkboxEffect.N.indexOf("p") > -1) { this._judgeParentNode(node.pid); } if(this.options.checkboxEffect.N.indexOf("z") > -1) { this._judgeParentNodeByZ(node.pid); } if(this.options.checkboxEffect.N.indexOf("s") > -1) { node.isParent ? this._makeChildrenDone(node, status) : undefined; } } this._emit('checkChange', [this._iCall("getCheckedNodes"), status, this.onceCheckChangeNodes]); this.triggerFlag = false; this.triggerValue = undefined; }, 'click li>input[type=radio]': function(self, evt) { var node = this.kvNodes[$(self).closest("li").attr("nodeid")]; var status = $(self).prop("checked"); if(this.checkedNodes.length === 1) { if(this.checkedNodes[0].id !== node.id) { _.remove(this.checkedNodes, { id: this.checkedNodes[0].id }); this.checkedNodes.push(node); this._emit('checkChange', [this._iCall("getCheckedNodes")]); } } else { this.checkedNodes.length = 0; this.checkedNodes.push(node); this._emit('checkChange', [this._iCall("getCheckedNodes")]); } }, //新增子节点 'click li a>i.cuicon-add': function(self, evt) { if(this.options.createTPLId !== null && !!this.options.url === true) { evt.stopPropagation(); var that = this; var nodeid = $(self).closest("li").attr("nodeid"); var html = template.compile($('#' + that.options.createTPLId).html())(); var d = dialog.open({ title: '添加节点', btn: ['确定', '取消'], content: html, yes: function(index) { // 把节点自身id处理成对外方法需要的数组形式 // 其中字段id为添加子节点的父元素的id var obj = { id: '', label: '', isAdd: false, isEdit: false, isDelete: false, checkType: that.options.checkType }; var label = $('.layui-layer-content [name="nodeName"]').val(); obj.label = label; obj.id = nodeid; obj.isAdd = $('.layui-layer-content [name="isAdd"]').val() == '0' ? true : false; obj.isEdit = $('.layui-layer-content [name="isEdit"]').val() == '0' ? true : false; obj.isDelete = $('.layui-layer-content [name="isDelete"]').val() == '0' ? true : false; that.invoke.addNode.call(that, obj); that._emit('addNode', obj); dialog.close(d); } }); } else { console.log("请设置createTPLId属性或自定义点击事件"); } }, //编辑节点 'click li a>i.cuicon-edit': function(self, evt) { if(this.options.editTPLId !== null && !!this.options.url === true) { evt.stopPropagation(); var that = this; var nodeid = $(self).closest("li").attr("nodeid"); var label = $(self).closest("li").find('>a span').html(); var html = template.compile($('#' + that.options.editTPLId).html())(); var d = dialog.open({ title: '添加节点', btn: ['确定', '取消'], content: html, success: function(index) { // 把节点自身id处理成对外方法需要的数组形式 // $('.layui-layer-content [name="nodeID"]').val(nodeid); $('.layui-layer-content [name="nodeName"]').val(label); }, yes: function(index) { // 把节点自身id处理成对外方法需要的数组形式 var node = that.kvNodes[nodeid]; var label = $('.layui-layer-content [name="nodeName"]').val(); node.label = label; that.invoke.editNode.call(that, node); that._emit('editNode', node); dialog.close(d); } }); } else { console.log("请设置editTPLId属性或自定义点击事件"); } }, //删除节点 'click li a>i.cuicon-delete': function(self, evt) { if(!!this.options.url === true) { evt.stopPropagation(); var nodeid = $(self).closest("li").attr("nodeid"); this.invoke.deleteNode.call(this, this.kvNodes[nodeid]); this._emit('deleteNode', [nodeid]); } }, 'keyup .searchInput': function(self, evt) { var label = $(self).val(); var showIds = this._iCall('search', [label]); this._emit('search', [showIds]); } }, invoke: { //重置树节点数据 data的结构{data:xxx,url:xxx} data: function(data) { if(this.options.pageController === true) { $('.cuiTree-nodes li').remove(); this._fenyeLoad(data.url); } else if(!!data.url === true) { $('.cuiTree-nodes li').remove(); this._onceLoad(data.url); } else { this.options.data = data; this._dataLoad(); } }, //不改变options.data情况下的重绘树 用于类似 搜索之类的 dataBybakData: function(data) { this._dataLoadInitData(); $('.cuiTree-nodes li').remove(); this.bakRoot = $.extend(true, {}, this.options.root); this.bakData = $.extend(true, [], data); this._dealBakRoot(); this._dealBakData(); this._renderRootDom(this._renderData); this._createDom(this._renderData); }, //增加子节点 save返回被添加节点的相关信息{} addNode: function(node) { var $el = this.$el, that = this, parentId = node.id; if(this.options.pageController === true) { //分页 this._model.save(node).then(function(res) { //返回新添加的节点 if(res.code === 0) { var newData = []; newData.push(res.data); var nodeStringArray = that._nodes2DomString(newData); // 样式控制 if($el.find(".cuiTree-nodes li[nodeid='" + parentId + "']").find('>span').attr('class').indexOf("open") != -1) { // 有子节点且打开 // 为之前的最后一个元素修改样式 var newClass = 'center-' + $el.find(".cuiTree-nodes li[nodeid='" + parentId + "']").find('>ul >li:last').find('>span').attr('class').split('-')[1]; $el.find(".cuiTree-nodes li[nodeid='" + parentId + "']").find('>ul >li:last').find('>span').attr('class', newClass); // 追加新的元素 $el.find(".cuiTree-nodes li[nodeid='" + parentId + "']").find('>ul').append(nodeStringArray.join('')); } else if($el.find(".cuiTree-nodes li[nodeid='" + parentId + "']").find('>span').attr('class').indexOf("docu") != -1) { // 无子节点改变点击标识样式为+ var cls = $el.find(".cuiTree-nodes li[nodeid='" + parentId + "']").find('>span').attr('class'); $el.find(".cuiTree-nodes li[nodeid='" + parentId + "']").find('>span').attr('class', cls.split('-')[0] + '-close'); // 若为根节点 if($el.find(".cuiTree-nodes li[nodeid='" + parentId + "']").get(0) === $('.cuiTree-nodes >li:first').get(0)) { // 删除更节点的下面的样式span $el.find('.cuiTree-root >span').html(''); } } else { // 有子节点 关闭啥也不做 console.log("notodo"); } dialog.msg(res.msg, { icon: 1 }); // 存入kvNodes that.kvNodes['' + res.data.id] = that._node2standard(res.data); that.kvNodes[parentId].childList.push(that.kvNodes['' + res.data.id]); } else { dialog.msg(res.msg, { icon: 2 }); } }); } else { if(!!this.options.url === true) { this._model.save(node).then(function(res) { if(res.code === 0) { var node = that.kvNodes['' + parentId]; node.isParent = true; that.options.data = res.data; dialog.msg(res.msg, { icon: 1 }); that._onceLoadByData(); } else { dialog.msg(res.msg, { icon: 2 }); } }); } else { var newData = this.options.data; var nodeObj = that._node2standard(node); newData.push(nodeObj); this.options.data = newData; this._dataLoad(); } } }, //批量增加子节点[{},{}] addNodes: function(objs) { var $el = this.$el, that = this; if(this.options.pageController === true) { //分页 console.log('分页暂时不提供批量增加'); } else { var newData = this.options.data; objs.forEach(function(v, i) { var nodeObj = that._node2standard(v); newData.push(nodeObj); }); this.options.data = newData; if(!!this.options.url === true) { //一次加载数据 this._onceLoadByData(); } else { //直接传数据 this._dataLoad(); } } }, //删除节点 deleteNode: function(obj) { var $el = this.$el, that = this, node = {}; node.id = obj.id; if(this.options.pageController === true) { //分页 this._model.delete(node).then(function(res) { if(res.code === 0) { $el.find(".cuiTree-nodes li[nodeid='" + node.id + "']").remove(); dialog.msg(res.msg, { icon: 1 }); } else { dialog.msg(res.msg, { icon: 2 }); } }) } else { var newData = that.options.data; console.log(newData); newData.forEach(function(v, i) { if(v.id == node.id) { _.remove(newData, v); } }); ! function getNeedDeleteNodes(id) { var currentId, delArr = []; newData.forEach(function(v, i) { if(v.pid == id) { delArr.push(v) } }); delArr.forEach(function(v) { _.remove(newData, v); getNeedDeleteNodes(v.id); }); }(node.id); this.options.data = newData; if(!!this.options.url === true) { //一次加载数据 this._model.delete(node).then(function(res) { if(res.code === 0) { that.options.data = res.data; that._onceLoadByData(); dialog.msg(res.msg, { icon: 1 }); } else { dialog.msg(res.msg, { icon: 2 }); } }); } else { //直接传数据 this._dataLoad(); } } }, //编辑节点 editNode: function(node) { var $el = this.$el, that = this; if(this.options.pageController === true) { //分页 this._model.update(node).then(function(res) { if(res.code === 0) { $el.find(".cuiTree-nodes li[nodeid='" + res.data.id + "']").find(">a >span").html(res.data.label); dialog.msg(res.msg, { icon: 1 }); } else { dialog.msg(res.msg, { icon: 2 }); } }) } else { //一次加载数据 if(!!this.options.url === true) { var data = { id: node.id, isAdd: node.isAdd, isDelete: node.isDelete, isEdit: node.isEdit, label: node.label }; this._model.update(data).then(function(res) { if(res.code === 0) { that.options.data = res.data; that._onceLoadByData(); dialog.msg(res.msg, { icon: 1 }); } else { dialog.msg(res.msg, { icon: 2 }); } }); } else { //直接传数据 var newData = this.options.data; newData.forEach(function(v, i) { if(v.id == node.id) { v.label = node.label; } }); this.options.data = newData; this._dataLoad(); } } }, //获取树中被选中的节点 getSelectedNode: function() { if(this.options.root && this.$el.find('.cuiTree-root>a').hasClass("current")) { return this.options.root; } else { return this.kvNodes['' + this.selectedNodeId] ? this.kvNodes['' + this.selectedNodeId] : null; } }, //获取树中被勾选的节点集合 getCheckedNodes: function() { var that = this; if(this.options.returnPartChecked) { var partChecked = $.extend(true, [], this.checkedNodes); var getRelatedParents = function(node) { var parentNode = that._getParentNode(node.id); if(parentNode) { // _.remove(partChecked,{id:parentNode.id}); partChecked.push(parentNode); getRelatedParents(parentNode); } } _.forEach(this.checkedNodes, function(node, i) { getRelatedParents(node); }); return _.uniq(partChecked, 'id'); } else { return this.checkedNodes; } }, //选中树的某个节点,如果想选中根节点请传"root" selectNode: function(id) { if(id === "" || id === null || id === undefined) { return; } if(this.selectedNodeId !== "") { this.$el.find('li[nodeid="' + this.selectedNodeId + '"]>a').removeClass("current"); } if(id === "root" && this.options.root) { this.selectedNodeId = ""; this.$el.find('.cuiTree-root>a').addClass("current"); this._emit('select', [this.options.root]); } else { this.selectedNodeId = id + ""; this.$el.find('li[nodeid="' + id + '"]>a').addClass("current"); this._emit('select', [this._iCall("getSelectedNode")]); } }, //改变某个节点的checked状态 changeCheckedStatus: function(id, status) { if(id === "" || id === null || id === undefined || that.kvNodes['' + id].disabled === true) { return; } var node_input = this.$el.find('li[nodeid="' + id + '"]>input'); var currStatus = node_input.prop("checked"); if(currStatus !== status) { if(this.options.checkType === "checkbox") { // this.triggerFlag = true; // this.triggerValue = status; // node_input.trigger("click"); node_input.attr('checked', status); status === true ? this.checkedNodes.push(this.kvNodes['' + id]) : _.remove(this.checkedNodes, { id: id }); } else if(this.options.checkType === "radio") { node_input.prop("checked", status); this.checkedNodes.length = 0; if(status) { this.checkedNodes.push(this.kvNodes['' + id]); } this._emit('checkChange', [this._iCall("getCheckedNodes")]); } node_input.attr('checked', status); } }, checkedByIds: function(array, status) { for(var i = 0; i < array.length; i++) { this.invoke.changeCheckedStatus.call(this, array[i], status); } }, checkedAll: function(status) { var array = _.keys(this.kvNodes); for(var i = 0; i < array.length; i++) { this.invoke.changeCheckedStatus.call(this, array[i], status); } }, //使整棵树禁用或不禁用 disable: function(status) { if(this.options.pageController === true) { //分页 var $el = this.$el; this.options.disable = status; $el.html(); this._create(); } else { this.options.disable = status; if(!!this.options.url === true) { //一次加载数据 this._onceLoadByData(); } else { //直接传数据 this._dataLoad(); } } }, //返回渲染后的树节点集合(只有根节点其中childList中包含子节点) getAllTreeNodes: function() { return this._renderData; }, //返回渲染后的树节点集合 getAllTreeNode: function() { var array = []; _.forEach(this.kvNodes, function(node, i) { array.push(node); }); return array; }, //根据id返回树节点 getNodeById: function(id) { if(this.options.pageController === true) { //分页 return this.kvNodes['' + id] ? this.kvNodes['' + id] : null; } else { return this.kvNodes['' + id] ? this.kvNodes['' + id] : null; } }, // 获取父节点与子节点的映射 getPid2ChildList: function() { var data = $.extend(true, {}, this.kvNodes); //子节点已没有必要存在 _.forEach(data, function(node, i) { delete node.childList; }); data = _.values(data); var groupedByparents = _.groupBy(data, 'pid'); var catsById = _.indexBy(data, 'id'); _.each(_.omit(groupedByparents, ''), function(childList, parentId) { if(parentId !== '-1') { catsById['' + parentId].childList = childList; } }) _.each(catsById, function(cat) { cat.isParent = !_.isEmpty(cat.childList); }); return groupedByparents; }, getChildListById: function(id) { var pid2childList = this._iCall('getPid2ChildList'); return pid2childList[id] ? pid2childList[id] : null; }, // 查找所有上级节点id searchAllPidsById: function(id) { // 所有父节点id var that = this, allpid = [], kvNodes = $.extend(true, {}, this.kvNodes); function loopAddpid(id) { if(id !== '-1') { allpid.push(id); loopAddpid(that.kvNodes['' + id].pid); } } loopAddpid(id); // 删除第一个id,次id为用于搜索的id allpid = _.drop(allpid); return allpid; }, // 返回节点对应的所有上级父节点 searchAllparentsById: function(id) { var kvNodes = $.extend(true, {}, this.kvNodes), // 所有父节点id allParentsNode = []; var allpid = this._iCall('searchAllPidsById', [id]); for(var i = 0; i < allpid.length; i++) { allParentsNode.push(kvNodes[allpid[i]]); } return allParentsNode; }, // 子节点id到父节点集合(含父节点的节点) getId2ParentList: function() { var kvNodes = $.extend(true, {}, this.kvNodes), id2PListObj = {}; for(key in kvNodes) { var pNodeArray = this._iCall('searchAllparentsById', [key]); id2PListObj['' + key] = pNodeArray; } return id2PListObj; }, // 查找所有上级节点id searchAllCidsById: function(id) { // 所有父节点id var that = this, allCids = [], kvNodes = $.extend(true, {}, this.kvNodes); function loopAddcid(id) { for(var i = 0; i < that.kvNodes['' + id].childList.length; i++) { allCids.push(that.kvNodes['' + id].childList[i].id); if(that.kvNodes['' + id] && that.kvNodes['' + id].childList && that.kvNodes['' + id].childList.length > 0) { loopAddcid(that.kvNodes['' + id].childList[i].id); } } } loopAddcid(id); return allCids; }, // 返回节点对应的所有上级父节点 searchAllchildsById: function(id) { var kvNodes = $.extend(true, {}, this.kvNodes), // 所有父节点id allchildsNode = []; var allCids = this._iCall('searchAllCidsById', [id]); for(var i = 0; i < allCids.length; i++) { allchildsNode.push(kvNodes[allCids[i]]); } return allchildsNode; }, // 查找所有下级子节点(含子节点的子节点) getId2ChildsList: function() { var kvNodes = $.extend(true, {}, this.kvNodes), id2CListObj = {}; for(key in kvNodes) { var cNodeArray = this._iCall('searchAllchildsById', [key]); id2CListObj['' + key] = cNodeArray; } return id2CListObj; }, // 根据搜索的label 查找所有需要展示的节点id searchShowIds: function(searchInfo) { var kvNodes = $.extend(true, {}, this.kvNodes), labelIds = [], showIds = []; //在labelIds中存放所有的含有value值的节点的id _.forIn(kvNodes, function(value, key) { var label = value.label; if(label.indexOf(searchInfo) !== -1) { labelIds.push(key); } }); for(var i = 0; i < labelIds.length; i++) { var pIds = this._iCall('searchAllPidsById', [labelIds[i]]); showIds = _.union(showIds, labelIds, pIds); } return showIds; }, setNodeClosedById: function(id) { var $el = this.$el, $self = $el.find('li[nodeid="' + id + '"] >span'), className = $self[0].className; if(className.indexOf("docu") != -1) { return false; } $self.removeClass(className).addClass(className.split("-")[0] + "-close"); // 分页模式 删除子节点 ; 非分页,隐藏子节点 $self.closest('li').find('>ul').hide(); }, search: function(searchInfo) { var renderData = $.extend(true, {}, this._renderData), data = $.extend(true, [], this.options.data), // 需要展示的节点(不包含收起的节点) showIds = this._iCall('searchShowIds', [searchInfo]), grandSons = this._findGrandSons(searchInfo), delIds = []; // needIds需要展示的节点(包含收起的节点) var needIds = showIds; for(var i = 0; i < grandSons.length; i++) { cids = this._iCall('searchAllCidsById', [grandSons[i]]) needIds = _.union(needIds, cids); } // 此处此处删除过程中data的length会减少所以 先缓存后删除 for(var j = 0; j < data.length; j++) { var obj = {}; if(needIds.indexOf(data[j].id) === -1) { obj.id = data[j].id; delIds.push(obj); } } // 删除data中不需要展示的节点 for(k = 0; k < delIds.length; k++) { _.remove(data, { id: delIds[k].id }); } // 刷新需要的模板 this._iCall('dataBybakData', [data]); // 闭合根节点 for(var l = 0; l < grandSons.length; l++) { this._iCall('setNodeClosedById', [grandSons[l]]); } // 为匹配到的设置高亮 this.setHighLightLabel(searchInfo, showIds); return showIds; } } }) } }, { "./tree.tpl": [function(require, module, exports) { module.exports = "
  • \n \n \n \n \n {{$node.label}}\n {{if $node.isAdd === true}}{{/if}}\n {{if $node.isEdit === true}} {{/if}}\n {{if $node.isDelete === true}} {{/if}}\n \n
      \n\n\n"; }, {}], "./tree_root.tpl": [function(require, module, exports) { module.exports = "{{if $data.isSearch}}\n\n{{/if}}\n
      \n {{if $data.hasRoot && !$data.nodata}}\n \n {{/if}}\n {{if $data.nodata}}\n
      对不起,暂无数据
      \n {{else}}\n
        \n {{/if}}\n"; }, {}], "./tree_root_render.tpl": [function(require, module, exports) { module.exports = "{{if $data.hasRoot && !$data.nodata}}\n\n{{/if}}\n{{if $data.nodata}}\n
        对不起,暂无数据
        \n{{else}}\n
          \n{{/if}}\n"; }, {}], }]; var cuiTreeImpl = [function(require, module, exports) { var treeTpl = template.compile(require("./tree.tpl")), treeRootTpl = template.compile(require("./tree_root.tpl")); module.exports = function() { $.cuiFactory("cuiTree", { VERSION: '1.0.0', options: { //根节点数据:{icon:"",label:"",selected:false,disabled:false} root: null, //树的数据集合:[{icon:"",label:"",id:"",pid:"",checked:false,selected:false,disabled:false}] data: [], //树数据的数据形式,“array”为一维数组形式,“tree”树形形式 dataType: "array", //是否有checkbox:null、"checkbox"、"radio" checkType: null, //整个树disable disable: false, //所有被选中的节点id的集合 checkedIds: [], //部分勾选节点是否返回,true:返回,false:不返回 returnPartChecked: false, //树有大小两种无数据样式0:小样式,1:大样式 noDataStyle: 0, //Y 属性定义 checkbox 被勾选后的情况; N 属性定义 checkbox 取消勾选后的情况; //"p" 表示操作会影响父级节点; "s" 表示操作会影响子级节点 "z"表示勾选单个子节点父节点勾选。 checkboxEffect: { "Y": "ps", "N": "ps" }, //组件初始化展示方式:0:展示一级菜单其余全部收起;1:全部展开,显示所有节点;2:收起全部 showType: 1, //树组件的高度,默认“auto” height: "auto", //树组件的宽度,默认“auto” width: "auto", //是否可以增加节点 isAdd: false, //是否可以删除节点 isDelete: false, //是否可以编辑 isEdit: false, //初始化时是否全部折叠 isInitOpen: true, //是否大数据 bigData: false, url: null, icon: $.noop() }, _create: function() { this._renderTree(); if(!!this.options.url) { this._initModel(); } }, // 实际初始化和渲染树的方法 _renderTree: function() { this.bakData = $.extend(true, [], this.options.data); this.bakRoot = $.extend(true, {}, this.options.root) this.triggerFlag = false; this.triggerValue = undefined; this.selectedNodeId = ""; this.nodesString = []; this.onceCheckChangeNodes = []; this.checkedNodes = []; this.arrayTypeData = []; this._tidyData(); this._concatChecked(); this._generateKv(); this._preRenderData(); this._createDom(this._renderData); this._generateKv(); }, // 初始化数据渲染(当通过url传递数据时) _initModel: function() { var that = this; if(!that.options.url) return; that._model = cui.baseModel.extend({ statics: { baseUrl: that.options.url } }); that._model.list().then(function(res) { if(res.code === 0) { that._iCall('data', [res.data]); that._emit('afterRender', [res.data]); } }); }, //判断传过来的数据是树形结构还是数组结构 _tidyData: function() { var data = this.bakData; if(this.options.dataType === "tree") { this._tree2Array(data); this.bakData = this.arrayTypeData; } }, //树形数据转换成数组 _tree2Array: function(data) { for(var i = 0; i < data.length; i++) { this.arrayTypeData.push(data[i]); if(data[i].childList && data[i].childList.length > 0) { this._tree2Array(data[i].childList); } }; }, //合并checked数据 _concatChecked: function() { var data = this.bakData; var checkedArr = this.options.checkedIds; var that = this; _.forEach(data, function(node, i) { //为了减少循环次数把这块逻辑加进来 if(that.options.dataType === "tree" && node.childList) { delete node.childList; } //把全局disable加进来 if(that.options.disable) { node.disabled = true; } _.forEach(checkedArr, function(checkedNodeId, j) { if(node.id === checkedNodeId) { node.checked = true; return false; } }) }) }, events: { //指定绑定事件的元素 'target': function() { return this.$el; }, 'click li>span': function(self, evt) { // 展开收起 var className = $(self)[0].className; if(className.indexOf("docu") != -1) { return false; } if(className.indexOf("open") != -1) { $(self).removeClass(className).addClass(className.split("-")[0] + "-close"); $(self).closest('li').find('>ul').hide(); } if(className.indexOf("close") != -1) { $(self).removeClass(className).addClass(className.split("-")[0] + "-open"); $(self).closest('li').find('>ul').show(); if(this.bigData) { // to do var data = this.kvNodes; var $li = $(self).closest('li'); var pid = $li.attr('nodeid'); var node = data[pid]; var $ul = $li.find('ul'); var html = []; node.childList.forEach(function(one, i, list) { one.isFirstNode = (i == 0) ? true : false; one.isLastNode = (i == list.length - 1) ? true : false; }) if(node && !$li.data('hasRendered')) { this._appendNodes($ul, node.childList); $li.data('hasRendered', true); } } } }, 'click li>a': function(self, evt) { if($(self).closest("li").hasClass("node-disabled")) { return; } this.$el.find("a").removeClass("current"); $(self).addClass("current"); this.selectedNodeId = $(self).closest("li").attr("nodeid"); this._emit('select', [this._iCall("getSelectedNode")]); // add by clu on 2018-11-22 15:20:24 点击a,触发自动选中checkbox var radioOrCheckbox = $(self).prev('input[type=checkbox],input[type=radio]'); if (radioOrCheckbox.length === 1) { this.triggerFlag = true; this.triggerValue = !radioOrCheckbox.prop('checked'); radioOrCheckbox.trigger('click'); } }, 'click .cuiTree-root>a': function(self, evt) { if($(self).closest(".cuiTree-root").hasClass("node-disabled")) { return; } this.$el.find("a").removeClass("current"); $(self).addClass("current"); this.selectedNodeId = ""; this._emit('select', [this.bakRoot]); }, 'dblclick .cuiTree-root>a': function(self, evt) { if(this._renderData.length === 0) { return; } this.$el.find(".cuiTree-nodes").toggle(); this.$el.find(".cuiTree-root>span").toggleClass("show"); }, 'click li>input[type=checkbox]': function(self, evt) { var status = $(self).prop("checked"); var node = this.kvNodes[$(self).closest("li").attr("nodeid")]; if(this.triggerFlag) { status = this.triggerValue; } this.onceCheckChangeNodes = []; if(status) { node.checked = true; if(!_.find(this.checkedNodes, { id: node.id })) { this.onceCheckChangeNodes.push(node); } _.remove(this.checkedNodes, { id: node.id }); this.checkedNodes.push(node); if(this.options.checkboxEffect.Y.indexOf("p") > -1) { this._judgeParentNode(node.pid); } if(this.options.checkboxEffect.Y.indexOf("z") > -1) { this._judgeParentNodeByZ(node.pid); } if(this.options.checkboxEffect.Y.indexOf("s") > -1) { node.isParent ? this._makeChildrenDone(node, status) : undefined; } } else { node.checked = false; _.remove(this.checkedNodes, { id: node.id }); this.onceCheckChangeNodes.push(node); if(this.options.checkboxEffect.N.indexOf("p") > -1) { this._judgeParentNode(node.pid); } if(this.options.checkboxEffect.N.indexOf("z") > -1) { this._judgeParentNodeByZ(node.pid); } if(this.options.checkboxEffect.N.indexOf("s") > -1) { node.isParent ? this._makeChildrenDone(node, status) : undefined; } } this._emit('checkChange', [this._iCall("getCheckedNodes"), status, this.onceCheckChangeNodes]); this.triggerFlag = false; this.triggerValue = undefined; //console.log(this.checkedNodes.length) }, 'click li>input[type=radio]': function(self, evt) { var node = this.kvNodes[$(self).closest("li").attr("nodeid")]; var status = $(self).prop("checked"); if(this.checkedNodes.length === 1) { if(this.checkedNodes[0].id !== node.id) { _.remove(this.checkedNodes, { id: this.checkedNodes[0].id }); this.checkedNodes.push(node); this._emit('checkChange', [this._iCall("getCheckedNodes")]); } } else { this.checkedNodes.length = 0; this.checkedNodes.push(node); this._emit('checkChange', [this._iCall("getCheckedNodes")]); } //console.log(this.checkedNodes[0].id) }, //新增子节点 'click li a>i.cuicon-add': function(self, evt) { evt.stopPropagation(); var nodeid = $(self).closest("li").attr("nodeid"); var labelContent = $(self).siblings('span').text(); this._emit('addNode', [nodeid, labelContent]); }, //编辑节点 'click li a>i.cuicon-edit': function(self, evt) { evt.stopPropagation(); var nodeid = $(self).closest("li").attr("nodeid"); var labelContent = $(self).siblings('span').text(); this._emit('editNode', [nodeid, labelContent]); }, //删除节点 'click li a>i.cuicon-delete': function(self, evt) { evt.stopPropagation(); var nodeid = $(self).closest("li").attr("nodeid"); this._emit('deleteNode', [nodeid]); } }, _judgeParentNode: function(pid) { var pNode = this.kvNodes['' + pid]; if(!pNode || !pNode.childList || pNode.childList.length === 0) { return; } var childrenNotDisabled = []; var childrenCheckeds = 0; _.forEach(pNode.childList, function(node, i) { if(!node.disabled) { childrenNotDisabled.push(node); node.checked ? childrenCheckeds++ : undefined; } }) if(childrenCheckeds === childrenNotDisabled.length) { pNode.checked = true; if(!_.find(this.checkedNodes, { id: pid })) { this.onceCheckChangeNodes.push(pNode); } _.remove(this.checkedNodes, { id: pid }); this.checkedNodes.push(pNode); this.$el.find('li[nodeid="' + pid + '"]>input[type=checkbox]').prop("checked", true); this._judgeParentNode(pNode.pid); } else if(childrenCheckeds < childrenNotDisabled.length) { if(pNode.checked) { pNode.checked = false; _.remove(this.checkedNodes, { id: pid }); this.onceCheckChangeNodes.push(pNode); this.$el.find('li[nodeid="' + pid + '"]>input[type=checkbox]').prop("checked", false); this._judgeParentNode(pNode.pid); } } }, _judgeParentNodeByZ: function(pid) { var pNode = this.kvNodes['' + pid]; if(!pNode || !pNode.childList || pNode.childList.length === 0) { return; } // 可用节点数 var childrenNotDisabled = []; // 勾选节点数 var childrenCheckeds = 0; _.forEach(pNode.childList, function(node, i) { if(!node.disabled) { childrenNotDisabled.push(node); node.checked ? childrenCheckeds++ : undefined; } }) if(childrenCheckeds === 0) { if(pNode.checked) { pNode.checked = false; _.remove(this.checkedNodes, { id: pid }); this.onceCheckChangeNodes.push(pNode); this.$el.find('li[nodeid="' + pid + '"]>input[type=checkbox]').prop("checked", false); this._judgeParentNodeByZ(pNode.pid); } } else { pNode.checked = true; if(!_.find(this.checkedNodes, { id: pid })) { this.onceCheckChangeNodes.push(pNode); } _.remove(this.checkedNodes, { id: pid }); this.checkedNodes.push(pNode); this.$el.find('li[nodeid="' + pid + '"]>input[type=checkbox]').prop("checked", true); this._judgeParentNodeByZ(pNode.pid); } }, _makeChildrenDone: function(pNode, status) { var that = this; this.$el.find('li[nodeid="' + pNode.id + '"] >input[type=checkbox]').prop('checked', status); _.forEach(pNode.childList, function(node, i) { if(!node.disabled) { if(node.checked !== status) { that.onceCheckChangeNodes.push(node); if(status) { that.checkedNodes.push(node) } else { _.remove(that.checkedNodes, { id: node.id }) } } node.checked = status; if(node.isParent && node.childList && node.childList.length > 0) { that._makeChildrenDone(node, status); } else { // 如果没有子节点了 则在此处改变当前节点的状态 that.$el.find('li[nodeid="' + node.id + '"] >input[type=checkbox]').prop('checked', status); } } }); }, //创建数据 _convert: function() { var data = this.bakData, result = []; for(var i = 0; i < data.length; i++) { var ri = data[i]; data[i].checkType = this.options.checkType; for(var j = 0; j < data.length; j++) { data[j].isParent = false; for(var k = 0; k < data.length; k++) { if(data[k].pid == data[j].id) { data[j].isParent = true; break; } } } if(ri.pid != null && ri.pid != 'null' && ri.pid != -1) { for(var j = 0; j < data.length; j++) { var rj = data[j]; if(rj.id == ri.pid) { rj.childList = !rj.childList ? [] : rj.childList; rj.childList.push(ri); break; } } } if(ri.pid == undefined || ri.pid == null || ri.pid == 'null' || ri.pid == -1 || this.kvNodes['' + ri.pid] === undefined) { result.push(ri); } } return result; }, _transformTozTreeFormat: function() { var sNodes = this.bakData; var i, l; var r = []; var tmpMap = []; for(i = 0, l = sNodes.length; i < l; i++) { sNodes[i].checkType = this.options.checkType; sNodes[i].isParent = false; tmpMap[sNodes[i]["id"]] = sNodes[i]; } for(i = 0, l = sNodes.length; i < l; i++) { if(tmpMap[sNodes[i]["pid"]] && sNodes[i]["id"] != sNodes[i]["pid"]) { tmpMap[sNodes[i]["pid"]].isParent = true; if(!tmpMap[sNodes[i]["pid"]]["childList"]) tmpMap[sNodes[i]["pid"]]["childList"] = []; tmpMap[sNodes[i]["pid"]]["childList"].push(sNodes[i]); } else { r.push(sNodes[i]); } } return r; }, _appendNodes: function(container, nodeList) { var start = 0, len = nodeList.length, list, time = 0; that = this; while(time * 1000 < len) { list = nodeList.slice(time * 1000, 1000 * ++time); (function(container, list) { setTimeout(function() { var htmlNow = []; list.forEach(function(node) { if(node.icon !== '' && node.icon !== null && node.icon !== undefined || that.options.icon === undefined) { htmlNow.push(treeTpl({ $node: node })); } else { var iconClass = that.options.icon(); htmlNow.push(treeTpl({ $node: node, iconClass: iconClass })); } htmlNow.push('
        '); }) container.append(htmlNow.join('')); }, time * 100) })(container, list); } }, _appendHtml: function(container, html) { var start = 0, len = html.length, nowHtml, time = 0; while(time * 1000 < len) { nowHtml = html.slice(time * 1000, 1000 * ++time); (function(container, nowHtml) { setTimeout(function() { container.append(nowHtml); }, time * 100) })(container, nowHtml) } }, //整合成kv数据,方便查找 _generateKv: function() { var data = this.bakData; var that = this; this.kvNodes = {}; _.forEach(data, function(node, i) { if(node.selected && that.selectedNodeId === "") { that.selectedNodeId = "" + node.id; } if(node.checked) { _.remove(that.checkedNodes, { id: node.id }); that.checkedNodes.push(node); } node.isInitOpen = that.options.isInitOpen; that.kvNodes['' + node.id] = node; }); }, _getParentNode: function(id) { return this.kvNodes['' + this.kvNodes['' + id].pid]; }, //创建树子节点 _createDom: function(data) { var $el = this.$el; var temp = {}; temp.hasRoot = false; temp.nodata = false; if(this.bakRoot != null && !$.isEmptyObject(this.bakRoot)) { temp.hasRoot = true; temp.root = this.bakRoot; if(this.options.disable) { temp.root.disabled = true; } data.length === 0 ? temp.showLine = false : temp.showLine = true; if(data.length > 0) { data[0].isParent ? temp.lg = false : temp.lg = true; data.length === 1 ? temp.multiTop = false : temp.multiTop = true; } } if(data.length === 0) { temp.nodata = true; temp.noDataStyle = this.options.noDataStyle; $el.empty().append(treeRootTpl(temp)).addClass("cui-tree"); return; } else { $el.empty().append(treeRootTpl(temp)).addClass("cui-tree"); } this.nodeLevel = 0; data.length > 1 ? data[0].mutiTop = true : data[0].mutiTop = false; this.bigData = !!this.options.bigData for(var i = 0; i < data.length; i++) { data[i].isFirstNode = (i == 0) ? true : false; data[i].isLastNode = (i == data.length - 1) ? true : false; this._loopNodes(data[i], 0, this.bigData); } if(this.bigData) { this._appendHtml($el.find(".cuiTree-nodes"), this.nodesString); } else { $el.find(".cuiTree-nodes").append(this.nodesString.join('')); } _.isNumber(this.options.width) ? $el.width(this.options.width) : undefined; _.isNumber(this.options.height) ? $el.height(this.options.height) : undefined; }, //递归树节点 _loopNodes: function(node, isSelf, isBigData) { if(!isSelf) { this.nodeLevel = 0; node.level = this.nodeLevel; } //传入是否增加,编辑,删除的布尔值 node.isAdd = this.options.isAdd; node.isEdit = this.options.isEdit; node.isDelete = this.options.isDelete; node.isOpen = !isBigData; if(node.icon !== '' && node.icon !== null && node.icon !== undefined || this.options.icon === undefined) { this.nodesString.push(treeTpl({ $node: node })); } else { var iconClass = this.options.icon(); this.nodesString.push(treeTpl({ $node: node, iconClass: iconClass })); } if(node.childList && node.childList.length > 0) { this.nodeLevel++; for(var i = 0; i < node.childList.length; i++) { node.childList[i].level = this.nodeLevel; node.childList[i].isFirstNode = (i == 0) ? true : false; node.childList[i].isLastNode = (i == node.childList.length - 1) ? true : false; } if(!isBigData) { for(var j = 0; j < node.childList.length; j++) { this._loopNodes(node.childList[j], 1); } } } this.nodesString.push("
      • "); }, _preRenderData: function() { this._renderData = this._transformTozTreeFormat(); }, invoke: { //重置树节点数据 data: function(data) { this.options.data = data; this._renderTree(); }, //增加子节点 addNode: function(parentId, childIds, labelText, nlevel, edit) { var that = this; var newData = that.options.data; childIds.forEach(function(v, i) { newData.push({ 'id': v, 'label': labelText[i], 'pid': parentId, 'nlevel': nlevel, 'edit': edit }); }); that.options.data = newData; that._create(); // var $parentEL=this.$el.find('li[nodeid="'+parentId+'"]>ul'); // $parentEL.removeClass('ul-hide') }, //删除节点 deleteNode: function(id) { var that = this; var newData = that.options.data; console.log(newData); newData.forEach(function(v, i) { if(v.id == id) { _.remove(newData, v); } }); ! function getNeedDeleteNodes(id) { var currentId, delArr = []; newData.forEach(function(v, i) { if(v.pid == id) { delArr.push(v) } }); delArr.forEach(function(v) { _.remove(newData, v); getNeedDeleteNodes(v.id); }); }(id); that.options.data = newData; that._create(); }, //编辑节点 editNode: function(id, labelText) { var that = this; var newData = that.options.data; newData.forEach(function(v, i) { if(v.id == id) { v.label = labelText; } }); that.options.data = newData; that._create(); }, //获取树中被勾选的节点集合 getCheckedNodes: function() { var that = this; if(that.options.returnPartChecked) { var partChecked = $.extend(true, [], that.checkedNodes); var getRelatedParents = function(node) { var parentNode = that._getParentNode(node.id); if(parentNode) { // _.remove(partChecked,{id:parentNode.id}); partChecked.push(parentNode); getRelatedParents(parentNode); } } _.forEach(that.checkedNodes, function(node, i) { getRelatedParents(node); }); return _.uniq(partChecked, 'id'); } else { return that.checkedNodes; } }, //获取树中被选中的节点 getSelectedNode: function() { var that = this; if(that.options.root && that.$el.find('.cuiTree-root>a').hasClass("current")) { return that.options.root; } else { return that.kvNodes['' + that.selectedNodeId] ? that.kvNodes['' + that.selectedNodeId] : null; } }, //选中树的某个节点,如果想选中根节点请传"root" selectNode: function(id) { var that = this; if(id === "" || id === null || id === undefined) { return; } if(that.selectedNodeId !== "") { that.$el.find('li[nodeid="' + that.selectedNodeId + '"]>a').removeClass("current"); } if(id === "root" && that.options.root) { that.selectedNodeId = ""; that.$el.find('.cuiTree-root>a').addClass("current"); that._emit('select', [that.options.root]); } else { that.selectedNodeId = id + ""; that.$el.find('li[nodeid="' + id + '"]>a').addClass("current"); that._emit('select', [that._iCall("getSelectedNode")]); } }, //改变某个节点的checked状态 changeCheckedStatus: function(id, status) { var that = this; // fix by clu on 2020-7-8 11:00:12 增加对kvNodes[id]是否存在的校验 if(id === "" || id === null || id === undefined || !that.kvNodes['' + id] || that.kvNodes['' + id].disabled === true) { return; } var node_input = that.$el.find('li[nodeid="' + id + '"]>input'); if(node_input.length === 0) return; var currStatus = node_input.prop("checked"); if(currStatus !== status) { if(that.options.checkType === "checkbox") { // that.triggerFlag = true; // that.triggerValue = status; // node_input.trigger("click"); // node_input.attr('checked',status); node_input.prop("checked", status); status === true ? that.checkedNodes.push(that.kvNodes['' + id]) : _.remove(that.checkedNodes, { id: id }); } else if(that.options.checkType === "radio") { node_input.prop("checked", status); that.checkedNodes.length = 0; if(status) { that.checkedNodes.push(that.kvNodes['' + id]); } that._emit('checkChange', [that._iCall("getCheckedNodes")]); } } }, checkedByIds: function(array, status) { //批量对节点状态修改 var that = this; for(var i = 0; i < array.length; i++) { that.invoke.changeCheckedStatus.call(that, array[i], status); } }, checkedAll: function(status) { var that = this; var array = _.keys(that.kvNodes); for(var i = 0; i < array.length; i++) { that.invoke.changeCheckedStatus.call(that, array[i], status); } }, //使整棵树禁用或不禁用 disable: function(status) { var that = this; that.options.disable = status; that._create(); }, //返回渲染后的树节点集合(只有根节点其中childList中包含子节点) getAllTreeNodes: function() { return this._renderData; }, //返回渲染后的树节点集合 getAllTreeNode: function() { var that = this; // return this._renderData; var array = []; _.forEach(that.kvNodes, function(node, i) { array.push(node); }); return array; }, //根据id返回树节点 getNodeById: function(id) { var that = this; return that.kvNodes['' + id] ? that.kvNodes['' + id] : null; } } }); } }, { "./tree.tpl": [function(require, module, exports) { module.exports = "
      • \n \n \n \n 0}}{{$node.icon}}{{else}}cuicon cuicon-folder{{/if}}{{else}}{{if $node.icon && $node.icon.length >0}}{{$node.icon}}{{else}}cuicon cuicon-details{{/if}}{{/if}}{{if $node.level == 0}} node-top{{/if}}{{if $node.isParent}} bigger{{/if}} \n {{else}}\n {{iconClass}}\n {{/if}} \n \n \">\n {{$node.label}}\n {{if $node.isAdd&&$node.nlevel==1}}{{/if}}\n {{if $node.isEdit&&$node.edit==1}} {{/if}}\n {{if $node.isDelete&&!$node.hasOwnProperty(\"delete\")}} {{/if}}\n \n
          \n\n"; }, {}], "./tree_root.tpl": [function(require, module, exports) { module.exports = "{{if $data.hasRoot && !$data.nodata}}\n\n{{/if}}\n{{if $data.nodata}}\n
          对不起,暂无数据
          \n{{else}}\n
            \n{{/if}}\n"; }, {}] }]; (function(startup) { if(typeof exports === "object" && typeof module !== "undefined") { module.exports = startup() } else if(typeof define === "function" && define.amd) { define([], startup) } else { var g; if(typeof window !== "undefined") { g = window } else if(typeof global !== "undefined") { g = global } else if(typeof self !== "undefined") { g = self } else { g = this } g.derequire = startup() } })(function() { var define, module, exports; return(function startup(mappings, moduleObjects, autoLoadModules) { function loadModule(index, moduleMapping, u) { if(!moduleObjects[index]) { moduleMapping = moduleMapping || {}; if(!(mappings[index] || moduleMapping[index])) { var requireFun = typeof require === "function" && require; if(!u && requireFun) return requireFun(index, !0); if(i) return i(index, !0); var f = new Error("Cannot find module '" + index + "'"); throw f.code = "MODULE_NOT_FOUND", f } var module = moduleObjects[index] = { exports: {} }; var moduleFunction = (mappings[index] || moduleMapping[index])[0]; moduleFunction.call(module.exports, function(moduleToRequire) { var moduleMapping = mappings[index][1]; var moduleIndex = moduleMapping[moduleToRequire]; // 如果moduleToRequire = "./simpleTable.tpl", 则 moduleIndex则变成了./simpleTable.tpl对应的module(数组) if ($.isArray(moduleIndex)) { // 构建一个假的mapping moduleMapping = {}; moduleMapping[index + "_" + moduleToRequire] = moduleIndex; moduleIndex = index + "_" + moduleToRequire; } return loadModule(moduleIndex || moduleToRequire, moduleMapping) }, module, module.exports, startup, mappings, moduleObjects, autoLoadModules) } return moduleObjects[index].exports } var i = typeof require === "function" && require; for(var o = 0; o < autoLoadModules.length; o++) loadModule(autoLoadModules[o]); return loadModule; })({ 1: cuiBrowserifyCss, 2: cuiArtTemplateImpl, 3: cuiStartup, 4: cuiFormUtils, 5: cuiClass, 6: cuiCore, 7: cuiEventAction, 8: cuiForm, 9: cuiGlobal, 10: cuiPositionUtils, 11: cuiFactory, 12: cuiUtils, 17: cuiCalendarImpl, 18: cuiCollapseImpl, 19: cuiBootstrapTransitionImpl, 20: cuiDialogImpl, 21: cuiDropdownImpl, 25: cuiFilterImpl, 26: cuiFormTipImpl, 29: cuiGridTreeImpl, 30: cuiGridImpl, 39: cuiGuideImpl, 40: cuiNProgressImpl, 41: cuiNumberRollImpl, 46: cuiOperateImpl, 48: cuiOverlayImpl, 49: cuiPaginImpl, 51: cuiPlaceholderImpl, 52: cuiPopoverImpl, 53: cuiPositionImpl, 54: cuiScrollspyImpl, 55: cuiSelectImpl, 57: cuiStickyImpl, 58: cuiTabsCardImpl, 64: cuiThinkInputImpl, 66: cuiToolTipImpl, 67: cuiTreeEnhanceImpl, 71: cuiTreeImpl, 74: cuiJQueryCookieImpl, 75: cuiJQueryValidateImpl, 76: cuiLayerImpl, 77: cuiLodashImpl, 78: [function(require, module, exports) { var css = "/* Make clicks pass-through */\n#nprogress {\n pointer-events: none;\n}\n#nprogress .bar {\n background: #29d;\n position: fixed;\n z-index: 1031;\n top: 0;\n left: 0;\n width: 100%;\n height: 2px;\n}\n/* Fancy blur effect */\n#nprogress .peg {\n display: block;\n position: absolute;\n right: 0px;\n width: 100px;\n height: 100%;\n box-shadow: 0 0 10px #29d, 0 0 5px #29d;\n opacity: 1.0;\n -webkit-transform: rotate(3deg) translate(0px, -4px);\n -ms-transform: rotate(3deg) translate(0px, -4px);\n transform: rotate(3deg) translate(0px, -4px);\n}\n/* Remove these to get rid of the spinner */\n#nprogress .spinner {\n display: block;\n position: fixed;\n z-index: 1031;\n top: 15px;\n right: 15px;\n}\n#nprogress .spinner-icon {\n width: 18px;\n height: 18px;\n box-sizing: border-box;\n border: solid 2px transparent;\n border-top-color: #29d;\n border-left-color: #29d;\n border-radius: 50%;\n -webkit-animation: nprogress-spinner 400ms linear infinite;\n animation: nprogress-spinner 400ms linear infinite;\n}\n.nprogress-custom-parent {\n overflow: hidden;\n position: relative;\n}\n.nprogress-custom-parent #nprogress .spinner,\n.nprogress-custom-parent #nprogress .bar {\n position: absolute;\n}\n@-webkit-keyframes nprogress-spinner {\n 0% {\n -webkit-transform: rotate(0deg);\n }\n\n 100% {\n -webkit-transform: rotate(360deg);\n }\n}\n@keyframes nprogress-spinner {\n 0% {\n transform: rotate(0deg);\n }\n\n 100% {\n transform: rotate(360deg);\n }\n}\n"; (require("browserify-css").createStyle(css, { "href": "src\\js\\plugins\\nprogress\\nprogress.css" }, { "insertAt": "bottom" })); module.exports = css; }, { "browserify-css": 1 }], 79: cuiNProgressRealImpl, 80: cuiMapImpl }, {}, [3])(3) });