From 8b7926641fb0b4a6bcc9d8b21b71824489f344eb Mon Sep 17 00:00:00 2001 From: guy Date: Thu, 18 May 2017 09:28:38 +0800 Subject: [PATCH 01/10] enable --- bi/base.js | 9 +- bi/core.js | 253 ++++++++++++------------- docs/base.js | 9 +- docs/core.js | 253 ++++++++++++------------- src/base/single/button/button.basic.js | 9 +- src/core/alias.js | 249 ++++++++++++------------ src/core/proto/date.js | 3 +- 7 files changed, 389 insertions(+), 396 deletions(-) diff --git a/bi/base.js b/bi/base.js index a7fe770ab7..9c789c2538 100644 --- a/bi/base.js +++ b/bi/base.js @@ -881,9 +881,14 @@ BI.BasicButton = BI.inherit(BI.Single, { return this.options.text; }, - _setEnable: function (b) { + _setEnable: function (enable) { BI.BasicButton.superclass._setEnable.apply(this, arguments); - if (!b) { + if (enable === true) { + this.element.removeClass("base-disabled disabled"); + } else if (enable === false) { + this.element.addClass("base-disabled disabled"); + } + if (!enable) { if (this.options.shadow) { this.$mask && this.$mask.setVisible(false); } diff --git a/bi/core.js b/bi/core.js index f311b8aeb5..5d1435197c 100644 --- a/bi/core.js +++ b/bi/core.js @@ -3042,6 +3042,9 @@ if (!window.BI) { } }); })(jQuery);;(function () { + if (!window.BI) { + window.BI = {}; + } function isEmpty(value) { // 判断是否为空值 var result = value === "" || value === null || value === undefined; @@ -3102,124 +3105,6 @@ if (!window.BI) { return text; } - /** - * 把日期对象按照指定格式转化成字符串 - * - * @example - * var date = new Date('Thu Dec 12 2013 00:00:00 GMT+0800'); - * var result = BI.date2Str(date, 'yyyy-MM-dd');//2013-12-12 - * - * @class BI.date2Str - * @param date 日期 - * @param format 日期格式 - * @returns {String} - */ - function date2Str(date, format) { - if (!date) { - return ''; - } - // O(len(format)) - var len = format.length, result = ''; - if (len > 0) { - var flagch = format.charAt(0), start = 0, str = flagch; - for (var i = 1; i < len; i++) { - var ch = format.charAt(i); - if (flagch !== ch) { - result += compileJFmt({ - 'char': flagch, - 'str': str, - 'len': i - start - }, date); - flagch = ch; - start = i; - str = flagch; - } else { - str += ch; - } - } - result += compileJFmt({ - 'char': flagch, - 'str': str, - 'len': len - start - }, date); - } - return result; - - function compileJFmt(jfmt, date) { - var str = jfmt.str, len = jfmt.len, ch = jfmt['char']; - switch (ch) { - case 'E': //星期 - str = Date._DN[date.getDay()]; - break; - case 'y': //年 - if (len <= 3) { - str = (date.getFullYear() + '').slice(2, 4); - } else { - str = date.getFullYear(); - } - break; - case 'M': //月 - if (len > 2) { - str = Date._MN[date.getMonth()]; - } else if (len < 2) { - str = date.getMonth() + 1; - } else { - str = String.leftPad(date.getMonth() + 1 + '', 2, '0'); - } - break; - case 'd': //日 - if (len > 1) { - str = String.leftPad(date.getDate() + '', 2, '0'); - } else { - str = date.getDate(); - } - break; - case 'h': //时(12) - var hour = date.getHours() % 12; - if (hour === 0) { - hour = 12; - } - if (len > 1) { - str = String.leftPad(hour + '', 2, '0'); - } else { - str = hour; - } - break; - case 'H': //时(24) - if (len > 1) { - str = String.leftPad(date.getHours() + '', 2, '0'); - } else { - str = date.getHours(); - } - break; - case 'm': - if (len > 1) { - str = String.leftPad(date.getMinutes() + '', 2, '0'); - } else { - str = date.getMinutes(); - } - break; - case 's': - if (len > 1) { - str = String.leftPad(date.getSeconds() + '', 2, '0'); - } else { - str = date.getSeconds(); - } - break; - case 'a': - str = date.getHours() < 12 ? 'am' : 'pm'; - break; - case 'z': - str = date.getTimezone(); - break; - default: - str = jfmt.str; - break; - } - return str; - } - }; - /** * 数字格式 */ @@ -3262,7 +3147,8 @@ if (!window.BI) { } else { return left + '.' + right; } - }; + } + /** * 处理小数点右边小数部分 * @param tright 右边内容 @@ -3306,7 +3192,7 @@ if (!window.BI) { if (newnum.length > orilen) { newnum = newnum.substr(1); } else { - newnum = BI.leftPad(newnum, orilen, '0'); + newnum = String.leftPad(newnum, orilen, '0'); result.leftPlus = false; } right = right.replace(/^[0-9]+/, newnum); @@ -3567,7 +3453,7 @@ if (!window.BI) { return o; })(jo); - } + }; BI.contentFormat = function (cv, fmt) { if (isEmpty(cv)) { @@ -3609,15 +3495,122 @@ if (!window.BI) { return text; }; - BI.leftPad = function (val, size, ch) { - var result = String(val); - if (!ch) { - ch = " "; + /** + * 把日期对象按照指定格式转化成字符串 + * + * @example + * var date = new Date('Thu Dec 12 2013 00:00:00 GMT+0800'); + * var result = BI.date2Str(date, 'yyyy-MM-dd');//2013-12-12 + * + * @class BI.date2Str + * @param date 日期 + * @param format 日期格式 + * @returns {String} + */ + BI.date2Str = function (date, format) { + if (!date) { + return ''; } - while (result.length < size) { - result = ch + result; + // O(len(format)) + var len = format.length, result = ''; + if (len > 0) { + var flagch = format.charAt(0), start = 0, str = flagch; + for (var i = 1; i < len; i++) { + var ch = format.charAt(i); + if (flagch !== ch) { + result += compileJFmt({ + 'char': flagch, + 'str': str, + 'len': i - start + }, date); + flagch = ch; + start = i; + str = flagch; + } else { + str += ch; + } + } + result += compileJFmt({ + 'char': flagch, + 'str': str, + 'len': len - start + }, date); + } + return result; + + function compileJFmt(jfmt, date) { + var str = jfmt.str, len = jfmt.len, ch = jfmt['char']; + switch (ch) { + case 'E': //星期 + str = Date._DN[date.getDay()]; + break; + case 'y': //年 + if (len <= 3) { + str = (date.getFullYear() + '').slice(2, 4); + } else { + str = date.getFullYear(); + } + break; + case 'M': //月 + if (len > 2) { + str = Date._MN[date.getMonth()]; + } else if (len < 2) { + str = date.getMonth() + 1; + } else { + str = String.leftPad(date.getMonth() + 1 + '', 2, '0'); + } + break; + case 'd': //日 + if (len > 1) { + str = String.leftPad(date.getDate() + '', 2, '0'); + } else { + str = date.getDate(); + } + break; + case 'h': //时(12) + var hour = date.getHours() % 12; + if (hour === 0) { + hour = 12; + } + if (len > 1) { + str = String.leftPad(hour + '', 2, '0'); + } else { + str = hour; + } + break; + case 'H': //时(24) + if (len > 1) { + str = String.leftPad(date.getHours() + '', 2, '0'); + } else { + str = date.getHours(); + } + break; + case 'm': + if (len > 1) { + str = String.leftPad(date.getMinutes() + '', 2, '0'); + } else { + str = date.getMinutes(); + } + break; + case 's': + if (len > 1) { + str = String.leftPad(date.getSeconds() + '', 2, '0'); + } else { + str = date.getSeconds(); + } + break; + case 'a': + str = date.getHours() < 12 ? 'am' : 'pm'; + break; + case 'z': + str = date.getTimezone(); + break; + default: + str = jfmt.str; + break; + } + return str; } - return result.toString(); }; BI.object2Number = function (value) { @@ -6026,7 +6019,6 @@ Date._QN = ["", BI.i18nText("BI-Quarter_1"), BI.i18nText("BI-Quarter_3"), BI.i18nText("BI-Quarter_4")]; - /** Adds the number of days array to the Date object. */ Date._MD = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; @@ -6500,7 +6492,8 @@ Date.parseDateTime = function (str, fmt) { return new Date(y, m, d, hr, min, sec); } return today; -};/* +}; +/* * 给jQuery.Event对象添加的工具方法 */ $.extend($.Event.prototype, { diff --git a/docs/base.js b/docs/base.js index a7fe770ab7..9c789c2538 100644 --- a/docs/base.js +++ b/docs/base.js @@ -881,9 +881,14 @@ BI.BasicButton = BI.inherit(BI.Single, { return this.options.text; }, - _setEnable: function (b) { + _setEnable: function (enable) { BI.BasicButton.superclass._setEnable.apply(this, arguments); - if (!b) { + if (enable === true) { + this.element.removeClass("base-disabled disabled"); + } else if (enable === false) { + this.element.addClass("base-disabled disabled"); + } + if (!enable) { if (this.options.shadow) { this.$mask && this.$mask.setVisible(false); } diff --git a/docs/core.js b/docs/core.js index 1715d0032b..ede23ef0b3 100644 --- a/docs/core.js +++ b/docs/core.js @@ -19906,6 +19906,9 @@ BI.PopoverSection = BI.inherit(BI.Widget, { } }); BI.PopoverSection.EVENT_CLOSE = "EVENT_CLOSE";;(function () { + if (!window.BI) { + window.BI = {}; + } function isEmpty(value) { // 判断是否为空值 var result = value === "" || value === null || value === undefined; @@ -19966,124 +19969,6 @@ BI.PopoverSection.EVENT_CLOSE = "EVENT_CLOSE";;(function () { return text; } - /** - * 把日期对象按照指定格式转化成字符串 - * - * @example - * var date = new Date('Thu Dec 12 2013 00:00:00 GMT+0800'); - * var result = BI.date2Str(date, 'yyyy-MM-dd');//2013-12-12 - * - * @class BI.date2Str - * @param date 日期 - * @param format 日期格式 - * @returns {String} - */ - function date2Str(date, format) { - if (!date) { - return ''; - } - // O(len(format)) - var len = format.length, result = ''; - if (len > 0) { - var flagch = format.charAt(0), start = 0, str = flagch; - for (var i = 1; i < len; i++) { - var ch = format.charAt(i); - if (flagch !== ch) { - result += compileJFmt({ - 'char': flagch, - 'str': str, - 'len': i - start - }, date); - flagch = ch; - start = i; - str = flagch; - } else { - str += ch; - } - } - result += compileJFmt({ - 'char': flagch, - 'str': str, - 'len': len - start - }, date); - } - return result; - - function compileJFmt(jfmt, date) { - var str = jfmt.str, len = jfmt.len, ch = jfmt['char']; - switch (ch) { - case 'E': //星期 - str = Date._DN[date.getDay()]; - break; - case 'y': //年 - if (len <= 3) { - str = (date.getFullYear() + '').slice(2, 4); - } else { - str = date.getFullYear(); - } - break; - case 'M': //月 - if (len > 2) { - str = Date._MN[date.getMonth()]; - } else if (len < 2) { - str = date.getMonth() + 1; - } else { - str = String.leftPad(date.getMonth() + 1 + '', 2, '0'); - } - break; - case 'd': //日 - if (len > 1) { - str = String.leftPad(date.getDate() + '', 2, '0'); - } else { - str = date.getDate(); - } - break; - case 'h': //时(12) - var hour = date.getHours() % 12; - if (hour === 0) { - hour = 12; - } - if (len > 1) { - str = String.leftPad(hour + '', 2, '0'); - } else { - str = hour; - } - break; - case 'H': //时(24) - if (len > 1) { - str = String.leftPad(date.getHours() + '', 2, '0'); - } else { - str = date.getHours(); - } - break; - case 'm': - if (len > 1) { - str = String.leftPad(date.getMinutes() + '', 2, '0'); - } else { - str = date.getMinutes(); - } - break; - case 's': - if (len > 1) { - str = String.leftPad(date.getSeconds() + '', 2, '0'); - } else { - str = date.getSeconds(); - } - break; - case 'a': - str = date.getHours() < 12 ? 'am' : 'pm'; - break; - case 'z': - str = date.getTimezone(); - break; - default: - str = jfmt.str; - break; - } - return str; - } - }; - /** * 数字格式 */ @@ -20126,7 +20011,8 @@ BI.PopoverSection.EVENT_CLOSE = "EVENT_CLOSE";;(function () { } else { return left + '.' + right; } - }; + } + /** * 处理小数点右边小数部分 * @param tright 右边内容 @@ -20170,7 +20056,7 @@ BI.PopoverSection.EVENT_CLOSE = "EVENT_CLOSE";;(function () { if (newnum.length > orilen) { newnum = newnum.substr(1); } else { - newnum = BI.leftPad(newnum, orilen, '0'); + newnum = String.leftPad(newnum, orilen, '0'); result.leftPlus = false; } right = right.replace(/^[0-9]+/, newnum); @@ -20431,7 +20317,7 @@ BI.PopoverSection.EVENT_CLOSE = "EVENT_CLOSE";;(function () { return o; })(jo); - } + }; BI.contentFormat = function (cv, fmt) { if (isEmpty(cv)) { @@ -20473,15 +20359,122 @@ BI.PopoverSection.EVENT_CLOSE = "EVENT_CLOSE";;(function () { return text; }; - BI.leftPad = function (val, size, ch) { - var result = String(val); - if (!ch) { - ch = " "; + /** + * 把日期对象按照指定格式转化成字符串 + * + * @example + * var date = new Date('Thu Dec 12 2013 00:00:00 GMT+0800'); + * var result = BI.date2Str(date, 'yyyy-MM-dd');//2013-12-12 + * + * @class BI.date2Str + * @param date 日期 + * @param format 日期格式 + * @returns {String} + */ + BI.date2Str = function (date, format) { + if (!date) { + return ''; } - while (result.length < size) { - result = ch + result; + // O(len(format)) + var len = format.length, result = ''; + if (len > 0) { + var flagch = format.charAt(0), start = 0, str = flagch; + for (var i = 1; i < len; i++) { + var ch = format.charAt(i); + if (flagch !== ch) { + result += compileJFmt({ + 'char': flagch, + 'str': str, + 'len': i - start + }, date); + flagch = ch; + start = i; + str = flagch; + } else { + str += ch; + } + } + result += compileJFmt({ + 'char': flagch, + 'str': str, + 'len': len - start + }, date); + } + return result; + + function compileJFmt(jfmt, date) { + var str = jfmt.str, len = jfmt.len, ch = jfmt['char']; + switch (ch) { + case 'E': //星期 + str = Date._DN[date.getDay()]; + break; + case 'y': //年 + if (len <= 3) { + str = (date.getFullYear() + '').slice(2, 4); + } else { + str = date.getFullYear(); + } + break; + case 'M': //月 + if (len > 2) { + str = Date._MN[date.getMonth()]; + } else if (len < 2) { + str = date.getMonth() + 1; + } else { + str = String.leftPad(date.getMonth() + 1 + '', 2, '0'); + } + break; + case 'd': //日 + if (len > 1) { + str = String.leftPad(date.getDate() + '', 2, '0'); + } else { + str = date.getDate(); + } + break; + case 'h': //时(12) + var hour = date.getHours() % 12; + if (hour === 0) { + hour = 12; + } + if (len > 1) { + str = String.leftPad(hour + '', 2, '0'); + } else { + str = hour; + } + break; + case 'H': //时(24) + if (len > 1) { + str = String.leftPad(date.getHours() + '', 2, '0'); + } else { + str = date.getHours(); + } + break; + case 'm': + if (len > 1) { + str = String.leftPad(date.getMinutes() + '', 2, '0'); + } else { + str = date.getMinutes(); + } + break; + case 's': + if (len > 1) { + str = String.leftPad(date.getSeconds() + '', 2, '0'); + } else { + str = date.getSeconds(); + } + break; + case 'a': + str = date.getHours() < 12 ? 'am' : 'pm'; + break; + case 'z': + str = date.getTimezone(); + break; + default: + str = jfmt.str; + break; + } + return str; } - return result.toString(); }; BI.object2Number = function (value) { @@ -23528,7 +23521,6 @@ Date._QN = ["", BI.i18nText("BI-Quarter_1"), BI.i18nText("BI-Quarter_3"), BI.i18nText("BI-Quarter_4")]; - /** Adds the number of days array to the Date object. */ Date._MD = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; @@ -24002,7 +23994,8 @@ Date.parseDateTime = function (str, fmt) { return new Date(y, m, d, hr, min, sec); } return today; -};/* +}; +/* * 给jQuery.Event对象添加的工具方法 */ $.extend($.Event.prototype, { diff --git a/src/base/single/button/button.basic.js b/src/base/single/button/button.basic.js index c35cbb5f7b..80b513862d 100644 --- a/src/base/single/button/button.basic.js +++ b/src/base/single/button/button.basic.js @@ -298,9 +298,14 @@ BI.BasicButton = BI.inherit(BI.Single, { return this.options.text; }, - _setEnable: function (b) { + _setEnable: function (enable) { BI.BasicButton.superclass._setEnable.apply(this, arguments); - if (!b) { + if (enable === true) { + this.element.removeClass("base-disabled disabled"); + } else if (enable === false) { + this.element.addClass("base-disabled disabled"); + } + if (!enable) { if (this.options.shadow) { this.$mask && this.$mask.setVisible(false); } diff --git a/src/core/alias.js b/src/core/alias.js index 0abe30e403..59f7c55422 100644 --- a/src/core/alias.js +++ b/src/core/alias.js @@ -1,4 +1,7 @@ ;(function () { + if (!window.BI) { + window.BI = {}; + } function isEmpty(value) { // 判断是否为空值 var result = value === "" || value === null || value === undefined; @@ -59,124 +62,6 @@ return text; } - /** - * 把日期对象按照指定格式转化成字符串 - * - * @example - * var date = new Date('Thu Dec 12 2013 00:00:00 GMT+0800'); - * var result = BI.date2Str(date, 'yyyy-MM-dd');//2013-12-12 - * - * @class BI.date2Str - * @param date 日期 - * @param format 日期格式 - * @returns {String} - */ - function date2Str(date, format) { - if (!date) { - return ''; - } - // O(len(format)) - var len = format.length, result = ''; - if (len > 0) { - var flagch = format.charAt(0), start = 0, str = flagch; - for (var i = 1; i < len; i++) { - var ch = format.charAt(i); - if (flagch !== ch) { - result += compileJFmt({ - 'char': flagch, - 'str': str, - 'len': i - start - }, date); - flagch = ch; - start = i; - str = flagch; - } else { - str += ch; - } - } - result += compileJFmt({ - 'char': flagch, - 'str': str, - 'len': len - start - }, date); - } - return result; - - function compileJFmt(jfmt, date) { - var str = jfmt.str, len = jfmt.len, ch = jfmt['char']; - switch (ch) { - case 'E': //星期 - str = Date._DN[date.getDay()]; - break; - case 'y': //年 - if (len <= 3) { - str = (date.getFullYear() + '').slice(2, 4); - } else { - str = date.getFullYear(); - } - break; - case 'M': //月 - if (len > 2) { - str = Date._MN[date.getMonth()]; - } else if (len < 2) { - str = date.getMonth() + 1; - } else { - str = String.leftPad(date.getMonth() + 1 + '', 2, '0'); - } - break; - case 'd': //日 - if (len > 1) { - str = String.leftPad(date.getDate() + '', 2, '0'); - } else { - str = date.getDate(); - } - break; - case 'h': //时(12) - var hour = date.getHours() % 12; - if (hour === 0) { - hour = 12; - } - if (len > 1) { - str = String.leftPad(hour + '', 2, '0'); - } else { - str = hour; - } - break; - case 'H': //时(24) - if (len > 1) { - str = String.leftPad(date.getHours() + '', 2, '0'); - } else { - str = date.getHours(); - } - break; - case 'm': - if (len > 1) { - str = String.leftPad(date.getMinutes() + '', 2, '0'); - } else { - str = date.getMinutes(); - } - break; - case 's': - if (len > 1) { - str = String.leftPad(date.getSeconds() + '', 2, '0'); - } else { - str = date.getSeconds(); - } - break; - case 'a': - str = date.getHours() < 12 ? 'am' : 'pm'; - break; - case 'z': - str = date.getTimezone(); - break; - default: - str = jfmt.str; - break; - } - return str; - } - }; - /** * 数字格式 */ @@ -219,7 +104,8 @@ } else { return left + '.' + right; } - }; + } + /** * 处理小数点右边小数部分 * @param tright 右边内容 @@ -263,7 +149,7 @@ if (newnum.length > orilen) { newnum = newnum.substr(1); } else { - newnum = BI.leftPad(newnum, orilen, '0'); + newnum = String.leftPad(newnum, orilen, '0'); result.leftPlus = false; } right = right.replace(/^[0-9]+/, newnum); @@ -524,7 +410,7 @@ return o; })(jo); - } + }; BI.contentFormat = function (cv, fmt) { if (isEmpty(cv)) { @@ -566,15 +452,122 @@ return text; }; - BI.leftPad = function (val, size, ch) { - var result = String(val); - if (!ch) { - ch = " "; + /** + * 把日期对象按照指定格式转化成字符串 + * + * @example + * var date = new Date('Thu Dec 12 2013 00:00:00 GMT+0800'); + * var result = BI.date2Str(date, 'yyyy-MM-dd');//2013-12-12 + * + * @class BI.date2Str + * @param date 日期 + * @param format 日期格式 + * @returns {String} + */ + BI.date2Str = function (date, format) { + if (!date) { + return ''; } - while (result.length < size) { - result = ch + result; + // O(len(format)) + var len = format.length, result = ''; + if (len > 0) { + var flagch = format.charAt(0), start = 0, str = flagch; + for (var i = 1; i < len; i++) { + var ch = format.charAt(i); + if (flagch !== ch) { + result += compileJFmt({ + 'char': flagch, + 'str': str, + 'len': i - start + }, date); + flagch = ch; + start = i; + str = flagch; + } else { + str += ch; + } + } + result += compileJFmt({ + 'char': flagch, + 'str': str, + 'len': len - start + }, date); + } + return result; + + function compileJFmt(jfmt, date) { + var str = jfmt.str, len = jfmt.len, ch = jfmt['char']; + switch (ch) { + case 'E': //星期 + str = Date._DN[date.getDay()]; + break; + case 'y': //年 + if (len <= 3) { + str = (date.getFullYear() + '').slice(2, 4); + } else { + str = date.getFullYear(); + } + break; + case 'M': //月 + if (len > 2) { + str = Date._MN[date.getMonth()]; + } else if (len < 2) { + str = date.getMonth() + 1; + } else { + str = String.leftPad(date.getMonth() + 1 + '', 2, '0'); + } + break; + case 'd': //日 + if (len > 1) { + str = String.leftPad(date.getDate() + '', 2, '0'); + } else { + str = date.getDate(); + } + break; + case 'h': //时(12) + var hour = date.getHours() % 12; + if (hour === 0) { + hour = 12; + } + if (len > 1) { + str = String.leftPad(hour + '', 2, '0'); + } else { + str = hour; + } + break; + case 'H': //时(24) + if (len > 1) { + str = String.leftPad(date.getHours() + '', 2, '0'); + } else { + str = date.getHours(); + } + break; + case 'm': + if (len > 1) { + str = String.leftPad(date.getMinutes() + '', 2, '0'); + } else { + str = date.getMinutes(); + } + break; + case 's': + if (len > 1) { + str = String.leftPad(date.getSeconds() + '', 2, '0'); + } else { + str = date.getSeconds(); + } + break; + case 'a': + str = date.getHours() < 12 ? 'am' : 'pm'; + break; + case 'z': + str = date.getTimezone(); + break; + default: + str = jfmt.str; + break; + } + return str; } - return result.toString(); }; BI.object2Number = function (value) { diff --git a/src/core/proto/date.js b/src/core/proto/date.js index c8292a94dc..ed5eeb3d0b 100644 --- a/src/core/proto/date.js +++ b/src/core/proto/date.js @@ -55,7 +55,6 @@ Date._QN = ["", BI.i18nText("BI-Quarter_1"), BI.i18nText("BI-Quarter_3"), BI.i18nText("BI-Quarter_4")]; - /** Adds the number of days array to the Date object. */ Date._MD = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; @@ -529,4 +528,4 @@ Date.parseDateTime = function (str, fmt) { return new Date(y, m, d, hr, min, sec); } return today; -}; \ No newline at end of file +}; From 54797eaef9c22a1e743a2cfaa69a2b28379ae609 Mon Sep 17 00:00:00 2001 From: guy Date: Thu, 18 May 2017 10:16:49 +0800 Subject: [PATCH 02/10] add --- bi/core.js | 2 +- docs/core.js | 2 +- src/core/view.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bi/core.js b/bi/core.js index 5d1435197c..3d3ab264a0 100644 --- a/bi/core.js +++ b/bi/core.js @@ -5370,7 +5370,7 @@ BI.View = BI.inherit(BI.V, { BI.each(cardNames, function (i, name) { delete self._cards[name]; }); - this._cardLayouts[key] && this._cardLayouts[key].destroy(); + this._cardLayouts[key] && this._cardLayouts[key]._destroy(); return this; }, diff --git a/docs/core.js b/docs/core.js index ede23ef0b3..acd8075bc6 100644 --- a/docs/core.js +++ b/docs/core.js @@ -15372,7 +15372,7 @@ BI.View = BI.inherit(BI.V, { BI.each(cardNames, function (i, name) { delete self._cards[name]; }); - this._cardLayouts[key] && this._cardLayouts[key].destroy(); + this._cardLayouts[key] && this._cardLayouts[key]._destroy(); return this; }, diff --git a/src/core/view.js b/src/core/view.js index cfeaa5a53d..f5e5f23115 100644 --- a/src/core/view.js +++ b/src/core/view.js @@ -168,7 +168,7 @@ BI.View = BI.inherit(BI.V, { BI.each(cardNames, function (i, name) { delete self._cards[name]; }); - this._cardLayouts[key] && this._cardLayouts[key].destroy(); + this._cardLayouts[key] && this._cardLayouts[key]._destroy(); return this; }, From 867ca5907835e2451395754a849850d7f2502a06 Mon Sep 17 00:00:00 2001 From: young Date: Thu, 18 May 2017 11:55:56 +0800 Subject: [PATCH 03/10] function --- src/core/func/function.js | 495 +++++++++++++++++++------------------- 1 file changed, 246 insertions(+), 249 deletions(-) diff --git a/src/core/func/function.js b/src/core/func/function.js index d212ba5f4a..78a005ec44 100644 --- a/src/core/func/function.js +++ b/src/core/func/function.js @@ -2,281 +2,278 @@ * 基本的函数 * Created by GUY on 2015/6/24. */ -$(function () { - BI.Func = {}; - var formulas = {}; - BI.extend(BI.Func, { - - /** - * 获取搜索结果 - * @param items - * @param keyword - * @param param 搜索哪个属性 - */ - getSearchResult: function (items, keyword, param) { - var isArray = BI.isArray(items); - items = isArray ? BI.flatten(items) : items; - param || (param = "text"); - if (!BI.isKey(keyword)) { - return { - finded: BI.deepClone(items), - matched: isArray ? [] : {} - }; - } - var t, text, py; - keyword = BI.toUpperCase(keyword); - var matched = isArray ? [] : {}, finded = isArray ? [] : {}; - BI.each(items, function (i, item) { - item = BI.deepClone(item); - t = BI.stripEL(item); - text = t[param] || t.text || t.value || t.name || t; - py = BI.makeFirstPY(text); - text = BI.toUpperCase(text); - py = BI.toUpperCase(py); - var pidx; - if (text.indexOf(keyword) > -1) { - if (text === keyword) { - isArray ? matched.push(item) : (matched[i] = item); - } else { - isArray ? finded.push(item) : (finded[i] = item); - } - } else if (pidx = py.indexOf(keyword), (pidx > -1 && Math.floor(pidx / text.length) === Math.floor((pidx + keyword.length - 1) / text.length))) { - if (text === keyword || keyword.length === text.length) { - isArray ? matched.push(item) : (matched[i] = item); - } else { - isArray ? finded.push(item) : (finded[i] = item); - } - } - }); - return { - matched: matched, - finded: finded - } - }, - }); +BI.Func = {}; +BI.extend(BI.Func, { /** - * 对DOM操作的通用函数 - * @type {{}} + * 获取搜索结果 + * @param items + * @param keyword + * @param param 搜索哪个属性 */ - BI.DOM = {}; - BI.extend(BI.DOM, { - - /** - * 把dom数组或元素悬挂起来,使其不对html产生影响 - * @param dom - */ - hang: function (doms) { - if (BI.isEmpty(doms)) { - return; - } - var frag = document.createDocumentFragment(); - BI.each(doms, function (i, dom) { - dom instanceof BI.Widget && (dom = dom.element); - dom instanceof $ && dom[0] && frag.appendChild(dom[0]); - }); - return frag; - }, - - isExist: function (obj) { - return $("body").find(obj.element).length > 0; - }, - - //预加载图片 - preloadImages: function (srcArray, onload) { - var count = 0, images = []; - - function complete() { - count++; - if (count >= srcArray.length) { - onload(); + getSearchResult: function (items, keyword, param) { + var isArray = BI.isArray(items); + items = isArray ? BI.flatten(items) : items; + param || (param = "text"); + if (!BI.isKey(keyword)) { + return { + finded: BI.deepClone(items), + matched: isArray ? [] : {} + }; + } + var t, text, py; + keyword = BI.toUpperCase(keyword); + var matched = isArray ? [] : {}, finded = isArray ? [] : {}; + BI.each(items, function (i, item) { + item = BI.deepClone(item); + t = BI.stripEL(item); + text = t[param] || t.text || t.value || t.name || t; + py = BI.makeFirstPY(text); + text = BI.toUpperCase(text); + py = BI.toUpperCase(py); + var pidx; + if (text.indexOf(keyword) > -1) { + if (text === keyword) { + isArray ? matched.push(item) : (matched[i] = item); + } else { + isArray ? finded.push(item) : (finded[i] = item); + } + } else if (pidx = py.indexOf(keyword), (pidx > -1 && Math.floor(pidx / text.length) === Math.floor((pidx + keyword.length - 1) / text.length))) { + if (text === keyword || keyword.length === text.length) { + isArray ? matched.push(item) : (matched[i] = item); + } else { + isArray ? finded.push(item) : (finded[i] = item); } } + }); + return { + matched: matched, + finded: finded + } + }, +}); - BI.each(srcArray, function (i, src) { - images[i] = new Image(); - images[i].src = src; - images[i].onload = function () { - complete() - }; - images[i].onerror = function () { - complete() - }; - }); - }, - - isColor: function (color) { - return this.isRGBColor(color) || this.isHexColor(color); - }, - - isRGBColor: function (color) { - if (!color) { - return false; - } - return color.substr(0, 3) === "rgb"; - }, +/** + * 对DOM操作的通用函数 + * @type {{}} + */ +BI.DOM = {}; +BI.extend(BI.DOM, { - isHexColor: function (color) { - if (!color) { - return false; + /** + * 把dom数组或元素悬挂起来,使其不对html产生影响 + * @param dom + */ + hang: function (doms) { + if (BI.isEmpty(doms)) { + return; + } + var frag = document.createDocumentFragment(); + BI.each(doms, function (i, dom) { + dom instanceof BI.Widget && (dom = dom.element); + dom instanceof $ && dom[0] && frag.appendChild(dom[0]); + }); + return frag; + }, + + isExist: function (obj) { + return $("body").find(obj.element).length > 0; + }, + + //预加载图片 + preloadImages: function (srcArray, onload) { + var count = 0, images = []; + + function complete() { + count++; + if (count >= srcArray.length) { + onload(); } - return color[0] === "#" && color.length === 7; - }, + } - isDarkColor: function (hex) { - if (!hex) { - return false; - } - var rgb = this.rgb2json(this.hex2rgb(hex)); - var grayLevel = Math.round(rgb.r * 0.299 + rgb.g * 0.587 + rgb.b * 0.114); - if (grayLevel < 140) { - return true; - } + BI.each(srcArray, function (i, src) { + images[i] = new Image(); + images[i].src = src; + images[i].onload = function () { + complete() + }; + images[i].onerror = function () { + complete() + }; + }); + }, + + isColor: function (color) { + return this.isRGBColor(color) || this.isHexColor(color); + }, + + isRGBColor: function (color) { + if (!color) { return false; - }, + } + return color.substr(0, 3) === "rgb"; + }, - //获取对比颜色 - getContrastColor: function (color) { - if (!color) { - return ""; - } - if (this.isDarkColor(color)) { - return "#ffffff"; - } - return "#1a1a1a"; - }, + isHexColor: function (color) { + if (!color) { + return false; + } + return color[0] === "#" && color.length === 7; + }, - rgb2hex: function (rgbColour) { - if (!rgbColour || rgbColour.substr(0, 3) != "rgb") { - return ""; - } - var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); - var red = BI.parseInt(rgbValues[0]); - var green = BI.parseInt(rgbValues[1]); - var blue = BI.parseInt(rgbValues[2]); + isDarkColor: function (hex) { + if (!hex) { + return false; + } + var rgb = this.rgb2json(this.hex2rgb(hex)); + var grayLevel = Math.round(rgb.r * 0.299 + rgb.g * 0.587 + rgb.b * 0.114); + if (grayLevel < 140) { + return true; + } + return false; + }, - var hexColour = "#" + this.int2hex(red) + this.int2hex(green) + this.int2hex(blue); + //获取对比颜色 + getContrastColor: function (color) { + if (!color) { + return ""; + } + if (this.isDarkColor(color)) { + return "#ffffff"; + } + return "#1a1a1a"; + }, - return hexColour; - }, + rgb2hex: function (rgbColour) { + if (!rgbColour || rgbColour.substr(0, 3) != "rgb") { + return ""; + } + var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); + var red = BI.parseInt(rgbValues[0]); + var green = BI.parseInt(rgbValues[1]); + var blue = BI.parseInt(rgbValues[2]); - rgb2json: function (rgbColour) { - if (!rgbColour) { - return {}; - } - var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); - return { - r: BI.parseInt(rgbValues[0]), - g: BI.parseInt(rgbValues[1]), - b: BI.parseInt(rgbValues[2]) - }; - }, + var hexColour = "#" + this.int2hex(red) + this.int2hex(green) + this.int2hex(blue); - rgba2json: function (rgbColour) { - if (!rgbColour) { - return {}; - } - var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); - return { - r: BI.parseInt(rgbValues[0]), - g: BI.parseInt(rgbValues[1]), - b: BI.parseInt(rgbValues[2]), - a: BI.parseFloat(rgbValues[3]) - }; - }, + return hexColour; + }, - json2rgb: function (rgb) { - if (!BI.isKey(rgb.r) || !BI.isKey(rgb.g) || !BI.isKey(rgb.b)) { - return ""; - } - return "rgb(" + rgb.r + "," + rgb.g + "," + rgb.b + ")"; - }, + rgb2json: function (rgbColour) { + if (!rgbColour) { + return {}; + } + var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); + return { + r: BI.parseInt(rgbValues[0]), + g: BI.parseInt(rgbValues[1]), + b: BI.parseInt(rgbValues[2]) + }; + }, + + rgba2json: function (rgbColour) { + if (!rgbColour) { + return {}; + } + var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); + return { + r: BI.parseInt(rgbValues[0]), + g: BI.parseInt(rgbValues[1]), + b: BI.parseInt(rgbValues[2]), + a: BI.parseFloat(rgbValues[3]) + }; + }, + + json2rgb: function (rgb) { + if (!BI.isKey(rgb.r) || !BI.isKey(rgb.g) || !BI.isKey(rgb.b)) { + return ""; + } + return "rgb(" + rgb.r + "," + rgb.g + "," + rgb.b + ")"; + }, - json2rgba: function (rgba) { - if (!BI.isKey(rgba.r) || !BI.isKey(rgba.g) || !BI.isKey(rgba.b)) { - return ""; - } - return "rgba(" + rgba.r + "," + rgba.g + "," + rgba.b + "," + rgba.a + ")"; - }, + json2rgba: function (rgba) { + if (!BI.isKey(rgba.r) || !BI.isKey(rgba.g) || !BI.isKey(rgba.b)) { + return ""; + } + return "rgba(" + rgba.r + "," + rgba.g + "," + rgba.b + "," + rgba.a + ")"; + }, - int2hex: function (strNum) { - var hexdig = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']; + int2hex: function (strNum) { + var hexdig = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']; - return hexdig[strNum >>> 4] + '' + hexdig[strNum & 15]; - }, + return hexdig[strNum >>> 4] + '' + hexdig[strNum & 15]; + }, - hex2rgb: function (color) { - if (!color) { - return ""; - } - var tempValue = "rgb(", colorArray; + hex2rgb: function (color) { + if (!color) { + return ""; + } + var tempValue = "rgb(", colorArray; - if (color.length === 7) { - colorArray = [BI.parseInt('0x' + color.substring(1, 3)), - BI.parseInt('0x' + color.substring(3, 5)), - BI.parseInt('0x' + color.substring(5, 7))]; - } - else if (color.length === 4) { - colorArray = [BI.parseInt('0x' + color.substring(1, 2)), - BI.parseInt('0x' + color.substring(2, 3)), - BI.parseInt('0x' + color.substring(3, 4))]; - } - tempValue += colorArray[0] + ","; - tempValue += colorArray[1] + ","; - tempValue += colorArray[2] + ")"; + if (color.length === 7) { + colorArray = [BI.parseInt('0x' + color.substring(1, 3)), + BI.parseInt('0x' + color.substring(3, 5)), + BI.parseInt('0x' + color.substring(5, 7))]; + } + else if (color.length === 4) { + colorArray = [BI.parseInt('0x' + color.substring(1, 2)), + BI.parseInt('0x' + color.substring(2, 3)), + BI.parseInt('0x' + color.substring(3, 4))]; + } + tempValue += colorArray[0] + ","; + tempValue += colorArray[1] + ","; + tempValue += colorArray[2] + ")"; - return tempValue; - }, + return tempValue; + }, - rgba2rgb: function (rgbColour, BGcolor) { - if (BI.isNull(BGcolor)) { - BGcolor = 1; - } - if (rgbColour.substr(0, 4) != "rgba") { - return ""; - } - var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); - if (rgbValues.length < 4) { - return ""; - } - var R = BI.parseFloat(rgbValues[0]); - var G = BI.parseFloat(rgbValues[1]); - var B = BI.parseFloat(rgbValues[2]); - var A = BI.parseFloat(rgbValues[3]); + rgba2rgb: function (rgbColour, BGcolor) { + if (BI.isNull(BGcolor)) { + BGcolor = 1; + } + if (rgbColour.substr(0, 4) != "rgba") { + return ""; + } + var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); + if (rgbValues.length < 4) { + return ""; + } + var R = BI.parseFloat(rgbValues[0]); + var G = BI.parseFloat(rgbValues[1]); + var B = BI.parseFloat(rgbValues[2]); + var A = BI.parseFloat(rgbValues[3]); - return "rgb(" + Math.floor(255 * (BGcolor * (1 - A )) + R * A) + "," + - Math.floor(255 * (BGcolor * (1 - A )) + G * A) + "," + - Math.floor(255 * (BGcolor * (1 - A )) + B * A) + ")"; - }, + return "rgb(" + Math.floor(255 * (BGcolor * (1 - A )) + R * A) + "," + + Math.floor(255 * (BGcolor * (1 - A )) + G * A) + "," + + Math.floor(255 * (BGcolor * (1 - A )) + B * A) + ")"; + }, - getTextSizeWidth: function (text, fontSize) { - var span = $("").addClass("text-width-span").appendTo($("body")); + getTextSizeWidth: function (text, fontSize) { + var span = $("").addClass("text-width-span").appendTo($("body")); - if (fontSize == null) { - fontSize = 12; - } - fontSize = fontSize + "px"; - - span.css("font-size", fontSize).text(text); - - var width = span.width(); - span.remove(); - - return width; - }, - - //获取滚动条的宽度 - getScrollWidth: function () { - if (this._scrollWidth == null) { - var ul = $("
").width(50).height(50).css({ - position: "absolute", - top: "-9999px", - overflow: "scroll" - }).appendTo($("body")); - this._scrollWidth = ul[0].offsetWidth - ul[0].clientWidth; - ul.destroy(); - } - return this._scrollWidth; + if (fontSize == null) { + fontSize = 12; + } + fontSize = fontSize + "px"; + + span.css("font-size", fontSize).text(text); + + var width = span.width(); + span.remove(); + + return width; + }, + + //获取滚动条的宽度 + getScrollWidth: function () { + if (this._scrollWidth == null) { + var ul = $("
").width(50).height(50).css({ + position: "absolute", + top: "-9999px", + overflow: "scroll" + }).appendTo($("body")); + this._scrollWidth = ul[0].offsetWidth - ul[0].clientWidth; + ul.destroy(); } - }); + return this._scrollWidth; + } }); \ No newline at end of file From 6ca6a6d559c7ff7c190918320ac0b09f6f39924c Mon Sep 17 00:00:00 2001 From: young Date: Thu, 18 May 2017 12:12:01 +0800 Subject: [PATCH 04/10] function --- bi/core.js | 476 +++++++++++++++++++++++++-------------------------- docs/core.js | 476 +++++++++++++++++++++++++-------------------------- 2 files changed, 472 insertions(+), 480 deletions(-) diff --git a/bi/core.js b/bi/core.js index 3d3ab264a0..b980688e63 100644 --- a/bi/core.js +++ b/bi/core.js @@ -16608,284 +16608,280 @@ BI.extend(jQuery, { * 基本的函数 * Created by GUY on 2015/6/24. */ -$(function () { - BI.Func = {}; - var formulas = {}; - BI.extend(BI.Func, { +BI.Func = {}; +BI.extend(BI.Func, { - /** - * 获取搜索结果 - * @param items - * @param keyword - * @param param 搜索哪个属性 - */ - getSearchResult: function (items, keyword, param) { - var isArray = BI.isArray(items); - items = isArray ? BI.flatten(items) : items; - param || (param = "text"); - if (!BI.isKey(keyword)) { - return { - finded: BI.deepClone(items), - matched: isArray ? [] : {} - }; - } - var t, text, py; - keyword = keyword + ""; - keyword = BI.toUpperCase(keyword); - var matched = isArray ? [] : {}, finded = isArray ? [] : {}; - BI.each(items, function (i, item) { - item = BI.deepClone(item); - t = BI.stripEL(item); - text = t[param] || t.text || t.value || t.name || t; - py = BI.makeFirstPY(text); - text = BI.toUpperCase(text); - py = BI.toUpperCase(py); - var pidx; - if (text.indexOf(keyword) > -1) { - if (text === keyword) { - isArray ? matched.push(item) : (matched[i] = item); - } else { - isArray ? finded.push(item) : (finded[i] = item); - } - } else if (pidx = py.indexOf(keyword), (pidx > -1 && Math.floor(pidx / text.length) === Math.floor((pidx + keyword.length - 1) / text.length))) { - if (text === keyword || keyword.length === text.length) { - isArray ? matched.push(item) : (matched[i] = item); - } else { - isArray ? finded.push(item) : (finded[i] = item); - } - } - }); + /** + * 获取搜索结果 + * @param items + * @param keyword + * @param param 搜索哪个属性 + */ + getSearchResult: function (items, keyword, param) { + var isArray = BI.isArray(items); + items = isArray ? BI.flatten(items) : items; + param || (param = "text"); + if (!BI.isKey(keyword)) { return { - matched: matched, - finded: finded + finded: BI.deepClone(items), + matched: isArray ? [] : {} + }; + } + var t, text, py; + keyword = BI.toUpperCase(keyword); + var matched = isArray ? [] : {}, finded = isArray ? [] : {}; + BI.each(items, function (i, item) { + item = BI.deepClone(item); + t = BI.stripEL(item); + text = t[param] || t.text || t.value || t.name || t; + py = BI.makeFirstPY(text); + text = BI.toUpperCase(text); + py = BI.toUpperCase(py); + var pidx; + if (text.indexOf(keyword) > -1) { + if (text === keyword) { + isArray ? matched.push(item) : (matched[i] = item); + } else { + isArray ? finded.push(item) : (finded[i] = item); + } + } else if (pidx = py.indexOf(keyword), (pidx > -1 && Math.floor(pidx / text.length) === Math.floor((pidx + keyword.length - 1) / text.length))) { + if (text === keyword || keyword.length === text.length) { + isArray ? matched.push(item) : (matched[i] = item); + } else { + isArray ? finded.push(item) : (finded[i] = item); + } } - }, - }); + }); + return { + matched: matched, + finded: finded + } + }, +}); + +/** + * 对DOM操作的通用函数 + * @type {{}} + */ +BI.DOM = {}; +BI.extend(BI.DOM, { /** - * 对DOM操作的通用函数 - * @type {{}} + * 把dom数组或元素悬挂起来,使其不对html产生影响 + * @param dom */ - BI.DOM = {}; - BI.extend(BI.DOM, { - - /** - * 把dom数组或元素悬挂起来,使其不对html产生影响 - * @param dom - */ - hang: function (doms) { - if (BI.isEmpty(doms)) { - return; - } - var frag = document.createDocumentFragment(); - BI.each(doms, function (i, dom) { - dom instanceof BI.Widget && (dom = dom.element); - dom instanceof $ && dom[0] && frag.appendChild(dom[0]); - }); - return frag; - }, + hang: function (doms) { + if (BI.isEmpty(doms)) { + return; + } + var frag = document.createDocumentFragment(); + BI.each(doms, function (i, dom) { + dom instanceof BI.Widget && (dom = dom.element); + dom instanceof $ && dom[0] && frag.appendChild(dom[0]); + }); + return frag; + }, - isExist: function (obj) { - return $("body").find(obj.element).length > 0; - }, + isExist: function (obj) { + return $("body").find(obj.element).length > 0; + }, - //预加载图片 - preloadImages: function (srcArray, onload) { - var count = 0, images = []; + //预加载图片 + preloadImages: function (srcArray, onload) { + var count = 0, images = []; - function complete() { - count++; - if (count >= srcArray.length) { - onload(); - } + function complete() { + count++; + if (count >= srcArray.length) { + onload(); } + } - BI.each(srcArray, function (i, src) { - images[i] = new Image(); - images[i].src = src; - images[i].onload = function () { - complete() - }; - images[i].onerror = function () { - complete() - }; - }); - }, + BI.each(srcArray, function (i, src) { + images[i] = new Image(); + images[i].src = src; + images[i].onload = function () { + complete() + }; + images[i].onerror = function () { + complete() + }; + }); + }, - isColor: function (color) { - return this.isRGBColor(color) || this.isHexColor(color); - }, + isColor: function (color) { + return this.isRGBColor(color) || this.isHexColor(color); + }, - isRGBColor: function (color) { - if (!color) { - return false; - } - return color.substr(0, 3) === "rgb"; - }, + isRGBColor: function (color) { + if (!color) { + return false; + } + return color.substr(0, 3) === "rgb"; + }, - isHexColor: function (color) { - if (!color) { - return false; - } - return color[0] === "#" && color.length === 7; - }, + isHexColor: function (color) { + if (!color) { + return false; + } + return color[0] === "#" && color.length === 7; + }, - isDarkColor: function (hex) { - if (!hex) { - return false; - } - var rgb = this.rgb2json(this.hex2rgb(hex)); - var grayLevel = Math.round(rgb.r * 0.299 + rgb.g * 0.587 + rgb.b * 0.114); - if (grayLevel < 140) { - return true; - } + isDarkColor: function (hex) { + if (!hex) { return false; - }, + } + var rgb = this.rgb2json(this.hex2rgb(hex)); + var grayLevel = Math.round(rgb.r * 0.299 + rgb.g * 0.587 + rgb.b * 0.114); + if (grayLevel < 140) { + return true; + } + return false; + }, - //获取对比颜色 - getContrastColor: function (color) { - if (!color) { - return ""; - } - if (this.isDarkColor(color)) { - return "#ffffff"; - } - return "#1a1a1a"; - }, + //获取对比颜色 + getContrastColor: function (color) { + if (!color) { + return ""; + } + if (this.isDarkColor(color)) { + return "#ffffff"; + } + return "#1a1a1a"; + }, - rgb2hex: function (rgbColour) { - if (!rgbColour || rgbColour.substr(0, 3) != "rgb") { - return ""; - } - var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); - var red = BI.parseInt(rgbValues[0]); - var green = BI.parseInt(rgbValues[1]); - var blue = BI.parseInt(rgbValues[2]); + rgb2hex: function (rgbColour) { + if (!rgbColour || rgbColour.substr(0, 3) != "rgb") { + return ""; + } + var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); + var red = BI.parseInt(rgbValues[0]); + var green = BI.parseInt(rgbValues[1]); + var blue = BI.parseInt(rgbValues[2]); - var hexColour = "#" + this.int2hex(red) + this.int2hex(green) + this.int2hex(blue); + var hexColour = "#" + this.int2hex(red) + this.int2hex(green) + this.int2hex(blue); - return hexColour; - }, + return hexColour; + }, - rgb2json: function (rgbColour) { - if (!rgbColour) { - return {}; - } - var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); - return { - r: BI.parseInt(rgbValues[0]), - g: BI.parseInt(rgbValues[1]), - b: BI.parseInt(rgbValues[2]) - }; - }, + rgb2json: function (rgbColour) { + if (!rgbColour) { + return {}; + } + var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); + return { + r: BI.parseInt(rgbValues[0]), + g: BI.parseInt(rgbValues[1]), + b: BI.parseInt(rgbValues[2]) + }; + }, - rgba2json: function (rgbColour) { - if (!rgbColour) { - return {}; - } - var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); - return { - r: BI.parseInt(rgbValues[0]), - g: BI.parseInt(rgbValues[1]), - b: BI.parseInt(rgbValues[2]), - a: BI.parseFloat(rgbValues[3]) - }; - }, + rgba2json: function (rgbColour) { + if (!rgbColour) { + return {}; + } + var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); + return { + r: BI.parseInt(rgbValues[0]), + g: BI.parseInt(rgbValues[1]), + b: BI.parseInt(rgbValues[2]), + a: BI.parseFloat(rgbValues[3]) + }; + }, - json2rgb: function (rgb) { - if (!BI.isKey(rgb.r) || !BI.isKey(rgb.g) || !BI.isKey(rgb.b)) { - return ""; - } - return "rgb(" + rgb.r + "," + rgb.g + "," + rgb.b + ")"; - }, + json2rgb: function (rgb) { + if (!BI.isKey(rgb.r) || !BI.isKey(rgb.g) || !BI.isKey(rgb.b)) { + return ""; + } + return "rgb(" + rgb.r + "," + rgb.g + "," + rgb.b + ")"; + }, - json2rgba: function (rgba) { - if (!BI.isKey(rgba.r) || !BI.isKey(rgba.g) || !BI.isKey(rgba.b)) { - return ""; - } - return "rgba(" + rgba.r + "," + rgba.g + "," + rgba.b + "," + rgba.a + ")"; - }, + json2rgba: function (rgba) { + if (!BI.isKey(rgba.r) || !BI.isKey(rgba.g) || !BI.isKey(rgba.b)) { + return ""; + } + return "rgba(" + rgba.r + "," + rgba.g + "," + rgba.b + "," + rgba.a + ")"; + }, - int2hex: function (strNum) { - var hexdig = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']; + int2hex: function (strNum) { + var hexdig = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']; - return hexdig[strNum >>> 4] + '' + hexdig[strNum & 15]; - }, + return hexdig[strNum >>> 4] + '' + hexdig[strNum & 15]; + }, - hex2rgb: function (color) { - if (!color) { - return ""; - } - var tempValue = "rgb(", colorArray; + hex2rgb: function (color) { + if (!color) { + return ""; + } + var tempValue = "rgb(", colorArray; - if (color.length === 7) { - colorArray = [BI.parseInt('0x' + color.substring(1, 3)), - BI.parseInt('0x' + color.substring(3, 5)), - BI.parseInt('0x' + color.substring(5, 7))]; - } - else if (color.length === 4) { - colorArray = [BI.parseInt('0x' + color.substring(1, 2)), - BI.parseInt('0x' + color.substring(2, 3)), - BI.parseInt('0x' + color.substring(3, 4))]; - } - tempValue += colorArray[0] + ","; - tempValue += colorArray[1] + ","; - tempValue += colorArray[2] + ")"; + if (color.length === 7) { + colorArray = [BI.parseInt('0x' + color.substring(1, 3)), + BI.parseInt('0x' + color.substring(3, 5)), + BI.parseInt('0x' + color.substring(5, 7))]; + } + else if (color.length === 4) { + colorArray = [BI.parseInt('0x' + color.substring(1, 2)), + BI.parseInt('0x' + color.substring(2, 3)), + BI.parseInt('0x' + color.substring(3, 4))]; + } + tempValue += colorArray[0] + ","; + tempValue += colorArray[1] + ","; + tempValue += colorArray[2] + ")"; - return tempValue; - }, + return tempValue; + }, - rgba2rgb: function (rgbColour, BGcolor) { - if (BI.isNull(BGcolor)) { - BGcolor = 1; - } - if (rgbColour.substr(0, 4) != "rgba") { - return ""; - } - var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); - if (rgbValues.length < 4) { - return ""; - } - var R = BI.parseFloat(rgbValues[0]); - var G = BI.parseFloat(rgbValues[1]); - var B = BI.parseFloat(rgbValues[2]); - var A = BI.parseFloat(rgbValues[3]); + rgba2rgb: function (rgbColour, BGcolor) { + if (BI.isNull(BGcolor)) { + BGcolor = 1; + } + if (rgbColour.substr(0, 4) != "rgba") { + return ""; + } + var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); + if (rgbValues.length < 4) { + return ""; + } + var R = BI.parseFloat(rgbValues[0]); + var G = BI.parseFloat(rgbValues[1]); + var B = BI.parseFloat(rgbValues[2]); + var A = BI.parseFloat(rgbValues[3]); - return "rgb(" + Math.floor(255 * (BGcolor * (1 - A )) + R * A) + "," + - Math.floor(255 * (BGcolor * (1 - A )) + G * A) + "," + - Math.floor(255 * (BGcolor * (1 - A )) + B * A) + ")"; - }, + return "rgb(" + Math.floor(255 * (BGcolor * (1 - A )) + R * A) + "," + + Math.floor(255 * (BGcolor * (1 - A )) + G * A) + "," + + Math.floor(255 * (BGcolor * (1 - A )) + B * A) + ")"; + }, - getTextSizeWidth: function (text, fontSize) { - var span = $("").addClass("text-width-span").appendTo($("body")); + getTextSizeWidth: function (text, fontSize) { + var span = $("").addClass("text-width-span").appendTo($("body")); - if (fontSize == null) { - fontSize = 12; - } - fontSize = fontSize + "px"; + if (fontSize == null) { + fontSize = 12; + } + fontSize = fontSize + "px"; - span.css("font-size", fontSize).text(text); + span.css("font-size", fontSize).text(text); - var width = span.width(); - span.remove(); + var width = span.width(); + span.remove(); - return width; - }, + return width; + }, - //获取滚动条的宽度 - getScrollWidth: function () { - if (this._scrollWidth == null) { - var ul = $("
").width(50).height(50).css({ - position: "absolute", - top: "-9999px", - overflow: "scroll" - }).appendTo($("body")); - this._scrollWidth = ul[0].offsetWidth - ul[0].clientWidth; - ul.destroy(); - } - return this._scrollWidth; + //获取滚动条的宽度 + getScrollWidth: function () { + if (this._scrollWidth == null) { + var ul = $("
").width(50).height(50).css({ + position: "absolute", + top: "-9999px", + overflow: "scroll" + }).appendTo($("body")); + this._scrollWidth = ul[0].offsetWidth - ul[0].clientWidth; + ul.destroy(); } - }); + return this._scrollWidth; + } });/** * guy * 检测某个Widget的EventChange事件然后去show某个card diff --git a/docs/core.js b/docs/core.js index acd8075bc6..205c182a1a 100644 --- a/docs/core.js +++ b/docs/core.js @@ -22631,284 +22631,280 @@ BI.extend(jQuery, { * 基本的函数 * Created by GUY on 2015/6/24. */ -$(function () { - BI.Func = {}; - var formulas = {}; - BI.extend(BI.Func, { +BI.Func = {}; +BI.extend(BI.Func, { - /** - * 获取搜索结果 - * @param items - * @param keyword - * @param param 搜索哪个属性 - */ - getSearchResult: function (items, keyword, param) { - var isArray = BI.isArray(items); - items = isArray ? BI.flatten(items) : items; - param || (param = "text"); - if (!BI.isKey(keyword)) { - return { - finded: BI.deepClone(items), - matched: isArray ? [] : {} - }; - } - var t, text, py; - keyword = keyword + ""; - keyword = BI.toUpperCase(keyword); - var matched = isArray ? [] : {}, finded = isArray ? [] : {}; - BI.each(items, function (i, item) { - item = BI.deepClone(item); - t = BI.stripEL(item); - text = t[param] || t.text || t.value || t.name || t; - py = BI.makeFirstPY(text); - text = BI.toUpperCase(text); - py = BI.toUpperCase(py); - var pidx; - if (text.indexOf(keyword) > -1) { - if (text === keyword) { - isArray ? matched.push(item) : (matched[i] = item); - } else { - isArray ? finded.push(item) : (finded[i] = item); - } - } else if (pidx = py.indexOf(keyword), (pidx > -1 && Math.floor(pidx / text.length) === Math.floor((pidx + keyword.length - 1) / text.length))) { - if (text === keyword || keyword.length === text.length) { - isArray ? matched.push(item) : (matched[i] = item); - } else { - isArray ? finded.push(item) : (finded[i] = item); - } - } - }); + /** + * 获取搜索结果 + * @param items + * @param keyword + * @param param 搜索哪个属性 + */ + getSearchResult: function (items, keyword, param) { + var isArray = BI.isArray(items); + items = isArray ? BI.flatten(items) : items; + param || (param = "text"); + if (!BI.isKey(keyword)) { return { - matched: matched, - finded: finded + finded: BI.deepClone(items), + matched: isArray ? [] : {} + }; + } + var t, text, py; + keyword = BI.toUpperCase(keyword); + var matched = isArray ? [] : {}, finded = isArray ? [] : {}; + BI.each(items, function (i, item) { + item = BI.deepClone(item); + t = BI.stripEL(item); + text = t[param] || t.text || t.value || t.name || t; + py = BI.makeFirstPY(text); + text = BI.toUpperCase(text); + py = BI.toUpperCase(py); + var pidx; + if (text.indexOf(keyword) > -1) { + if (text === keyword) { + isArray ? matched.push(item) : (matched[i] = item); + } else { + isArray ? finded.push(item) : (finded[i] = item); + } + } else if (pidx = py.indexOf(keyword), (pidx > -1 && Math.floor(pidx / text.length) === Math.floor((pidx + keyword.length - 1) / text.length))) { + if (text === keyword || keyword.length === text.length) { + isArray ? matched.push(item) : (matched[i] = item); + } else { + isArray ? finded.push(item) : (finded[i] = item); + } } - }, - }); + }); + return { + matched: matched, + finded: finded + } + }, +}); + +/** + * 对DOM操作的通用函数 + * @type {{}} + */ +BI.DOM = {}; +BI.extend(BI.DOM, { /** - * 对DOM操作的通用函数 - * @type {{}} + * 把dom数组或元素悬挂起来,使其不对html产生影响 + * @param dom */ - BI.DOM = {}; - BI.extend(BI.DOM, { - - /** - * 把dom数组或元素悬挂起来,使其不对html产生影响 - * @param dom - */ - hang: function (doms) { - if (BI.isEmpty(doms)) { - return; - } - var frag = document.createDocumentFragment(); - BI.each(doms, function (i, dom) { - dom instanceof BI.Widget && (dom = dom.element); - dom instanceof $ && dom[0] && frag.appendChild(dom[0]); - }); - return frag; - }, + hang: function (doms) { + if (BI.isEmpty(doms)) { + return; + } + var frag = document.createDocumentFragment(); + BI.each(doms, function (i, dom) { + dom instanceof BI.Widget && (dom = dom.element); + dom instanceof $ && dom[0] && frag.appendChild(dom[0]); + }); + return frag; + }, - isExist: function (obj) { - return $("body").find(obj.element).length > 0; - }, + isExist: function (obj) { + return $("body").find(obj.element).length > 0; + }, - //预加载图片 - preloadImages: function (srcArray, onload) { - var count = 0, images = []; + //预加载图片 + preloadImages: function (srcArray, onload) { + var count = 0, images = []; - function complete() { - count++; - if (count >= srcArray.length) { - onload(); - } + function complete() { + count++; + if (count >= srcArray.length) { + onload(); } + } - BI.each(srcArray, function (i, src) { - images[i] = new Image(); - images[i].src = src; - images[i].onload = function () { - complete() - }; - images[i].onerror = function () { - complete() - }; - }); - }, + BI.each(srcArray, function (i, src) { + images[i] = new Image(); + images[i].src = src; + images[i].onload = function () { + complete() + }; + images[i].onerror = function () { + complete() + }; + }); + }, - isColor: function (color) { - return this.isRGBColor(color) || this.isHexColor(color); - }, + isColor: function (color) { + return this.isRGBColor(color) || this.isHexColor(color); + }, - isRGBColor: function (color) { - if (!color) { - return false; - } - return color.substr(0, 3) === "rgb"; - }, + isRGBColor: function (color) { + if (!color) { + return false; + } + return color.substr(0, 3) === "rgb"; + }, - isHexColor: function (color) { - if (!color) { - return false; - } - return color[0] === "#" && color.length === 7; - }, + isHexColor: function (color) { + if (!color) { + return false; + } + return color[0] === "#" && color.length === 7; + }, - isDarkColor: function (hex) { - if (!hex) { - return false; - } - var rgb = this.rgb2json(this.hex2rgb(hex)); - var grayLevel = Math.round(rgb.r * 0.299 + rgb.g * 0.587 + rgb.b * 0.114); - if (grayLevel < 140) { - return true; - } + isDarkColor: function (hex) { + if (!hex) { return false; - }, + } + var rgb = this.rgb2json(this.hex2rgb(hex)); + var grayLevel = Math.round(rgb.r * 0.299 + rgb.g * 0.587 + rgb.b * 0.114); + if (grayLevel < 140) { + return true; + } + return false; + }, - //获取对比颜色 - getContrastColor: function (color) { - if (!color) { - return ""; - } - if (this.isDarkColor(color)) { - return "#ffffff"; - } - return "#1a1a1a"; - }, + //获取对比颜色 + getContrastColor: function (color) { + if (!color) { + return ""; + } + if (this.isDarkColor(color)) { + return "#ffffff"; + } + return "#1a1a1a"; + }, - rgb2hex: function (rgbColour) { - if (!rgbColour || rgbColour.substr(0, 3) != "rgb") { - return ""; - } - var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); - var red = BI.parseInt(rgbValues[0]); - var green = BI.parseInt(rgbValues[1]); - var blue = BI.parseInt(rgbValues[2]); + rgb2hex: function (rgbColour) { + if (!rgbColour || rgbColour.substr(0, 3) != "rgb") { + return ""; + } + var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); + var red = BI.parseInt(rgbValues[0]); + var green = BI.parseInt(rgbValues[1]); + var blue = BI.parseInt(rgbValues[2]); - var hexColour = "#" + this.int2hex(red) + this.int2hex(green) + this.int2hex(blue); + var hexColour = "#" + this.int2hex(red) + this.int2hex(green) + this.int2hex(blue); - return hexColour; - }, + return hexColour; + }, - rgb2json: function (rgbColour) { - if (!rgbColour) { - return {}; - } - var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); - return { - r: BI.parseInt(rgbValues[0]), - g: BI.parseInt(rgbValues[1]), - b: BI.parseInt(rgbValues[2]) - }; - }, + rgb2json: function (rgbColour) { + if (!rgbColour) { + return {}; + } + var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); + return { + r: BI.parseInt(rgbValues[0]), + g: BI.parseInt(rgbValues[1]), + b: BI.parseInt(rgbValues[2]) + }; + }, - rgba2json: function (rgbColour) { - if (!rgbColour) { - return {}; - } - var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); - return { - r: BI.parseInt(rgbValues[0]), - g: BI.parseInt(rgbValues[1]), - b: BI.parseInt(rgbValues[2]), - a: BI.parseFloat(rgbValues[3]) - }; - }, + rgba2json: function (rgbColour) { + if (!rgbColour) { + return {}; + } + var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); + return { + r: BI.parseInt(rgbValues[0]), + g: BI.parseInt(rgbValues[1]), + b: BI.parseInt(rgbValues[2]), + a: BI.parseFloat(rgbValues[3]) + }; + }, - json2rgb: function (rgb) { - if (!BI.isKey(rgb.r) || !BI.isKey(rgb.g) || !BI.isKey(rgb.b)) { - return ""; - } - return "rgb(" + rgb.r + "," + rgb.g + "," + rgb.b + ")"; - }, + json2rgb: function (rgb) { + if (!BI.isKey(rgb.r) || !BI.isKey(rgb.g) || !BI.isKey(rgb.b)) { + return ""; + } + return "rgb(" + rgb.r + "," + rgb.g + "," + rgb.b + ")"; + }, - json2rgba: function (rgba) { - if (!BI.isKey(rgba.r) || !BI.isKey(rgba.g) || !BI.isKey(rgba.b)) { - return ""; - } - return "rgba(" + rgba.r + "," + rgba.g + "," + rgba.b + "," + rgba.a + ")"; - }, + json2rgba: function (rgba) { + if (!BI.isKey(rgba.r) || !BI.isKey(rgba.g) || !BI.isKey(rgba.b)) { + return ""; + } + return "rgba(" + rgba.r + "," + rgba.g + "," + rgba.b + "," + rgba.a + ")"; + }, - int2hex: function (strNum) { - var hexdig = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']; + int2hex: function (strNum) { + var hexdig = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']; - return hexdig[strNum >>> 4] + '' + hexdig[strNum & 15]; - }, + return hexdig[strNum >>> 4] + '' + hexdig[strNum & 15]; + }, - hex2rgb: function (color) { - if (!color) { - return ""; - } - var tempValue = "rgb(", colorArray; + hex2rgb: function (color) { + if (!color) { + return ""; + } + var tempValue = "rgb(", colorArray; - if (color.length === 7) { - colorArray = [BI.parseInt('0x' + color.substring(1, 3)), - BI.parseInt('0x' + color.substring(3, 5)), - BI.parseInt('0x' + color.substring(5, 7))]; - } - else if (color.length === 4) { - colorArray = [BI.parseInt('0x' + color.substring(1, 2)), - BI.parseInt('0x' + color.substring(2, 3)), - BI.parseInt('0x' + color.substring(3, 4))]; - } - tempValue += colorArray[0] + ","; - tempValue += colorArray[1] + ","; - tempValue += colorArray[2] + ")"; + if (color.length === 7) { + colorArray = [BI.parseInt('0x' + color.substring(1, 3)), + BI.parseInt('0x' + color.substring(3, 5)), + BI.parseInt('0x' + color.substring(5, 7))]; + } + else if (color.length === 4) { + colorArray = [BI.parseInt('0x' + color.substring(1, 2)), + BI.parseInt('0x' + color.substring(2, 3)), + BI.parseInt('0x' + color.substring(3, 4))]; + } + tempValue += colorArray[0] + ","; + tempValue += colorArray[1] + ","; + tempValue += colorArray[2] + ")"; - return tempValue; - }, + return tempValue; + }, - rgba2rgb: function (rgbColour, BGcolor) { - if (BI.isNull(BGcolor)) { - BGcolor = 1; - } - if (rgbColour.substr(0, 4) != "rgba") { - return ""; - } - var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); - if (rgbValues.length < 4) { - return ""; - } - var R = BI.parseFloat(rgbValues[0]); - var G = BI.parseFloat(rgbValues[1]); - var B = BI.parseFloat(rgbValues[2]); - var A = BI.parseFloat(rgbValues[3]); + rgba2rgb: function (rgbColour, BGcolor) { + if (BI.isNull(BGcolor)) { + BGcolor = 1; + } + if (rgbColour.substr(0, 4) != "rgba") { + return ""; + } + var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); + if (rgbValues.length < 4) { + return ""; + } + var R = BI.parseFloat(rgbValues[0]); + var G = BI.parseFloat(rgbValues[1]); + var B = BI.parseFloat(rgbValues[2]); + var A = BI.parseFloat(rgbValues[3]); - return "rgb(" + Math.floor(255 * (BGcolor * (1 - A )) + R * A) + "," + - Math.floor(255 * (BGcolor * (1 - A )) + G * A) + "," + - Math.floor(255 * (BGcolor * (1 - A )) + B * A) + ")"; - }, + return "rgb(" + Math.floor(255 * (BGcolor * (1 - A )) + R * A) + "," + + Math.floor(255 * (BGcolor * (1 - A )) + G * A) + "," + + Math.floor(255 * (BGcolor * (1 - A )) + B * A) + ")"; + }, - getTextSizeWidth: function (text, fontSize) { - var span = $("").addClass("text-width-span").appendTo($("body")); + getTextSizeWidth: function (text, fontSize) { + var span = $("").addClass("text-width-span").appendTo($("body")); - if (fontSize == null) { - fontSize = 12; - } - fontSize = fontSize + "px"; + if (fontSize == null) { + fontSize = 12; + } + fontSize = fontSize + "px"; - span.css("font-size", fontSize).text(text); + span.css("font-size", fontSize).text(text); - var width = span.width(); - span.remove(); + var width = span.width(); + span.remove(); - return width; - }, + return width; + }, - //获取滚动条的宽度 - getScrollWidth: function () { - if (this._scrollWidth == null) { - var ul = $("
").width(50).height(50).css({ - position: "absolute", - top: "-9999px", - overflow: "scroll" - }).appendTo($("body")); - this._scrollWidth = ul[0].offsetWidth - ul[0].clientWidth; - ul.destroy(); - } - return this._scrollWidth; + //获取滚动条的宽度 + getScrollWidth: function () { + if (this._scrollWidth == null) { + var ul = $("
").width(50).height(50).css({ + position: "absolute", + top: "-9999px", + overflow: "scroll" + }).appendTo($("body")); + this._scrollWidth = ul[0].offsetWidth - ul[0].clientWidth; + ul.destroy(); } - }); + return this._scrollWidth; + } });/** * guy * 检测某个Widget的EventChange事件然后去show某个card From 34c9c128704dc71dc6f6ee042f86fa7508514cf9 Mon Sep 17 00:00:00 2001 From: guy Date: Thu, 18 May 2017 14:05:12 +0800 Subject: [PATCH 05/10] add --- bi/base.js | 2 +- bi/core.js | 490 +++++++++++++++++++++--------------------- docs/base.js | 2 +- docs/core.js | 490 +++++++++++++++++++++--------------------- src/base/grid/grid.js | 2 +- src/core/widget.js | 14 ++ 6 files changed, 517 insertions(+), 483 deletions(-) diff --git a/bi/base.js b/bi/base.js index 9c789c2538..89aeb00e72 100644 --- a/bi/base.js +++ b/bi/base.js @@ -14807,7 +14807,7 @@ BI.GridView = BI.inherit(BI.Widget, { minY = Math.min(minY, rowDatum.offset + verticalOffsetAdjustment); maxY = Math.max(maxY, rowDatum.offset + verticalOffsetAdjustment + rowDatum.size); renderedKeys.push(key); - renderedWidgets[i] = child; + renderedWidgets[rowIndex] = child; } } //已存在的, 需要添加的和需要删除的 diff --git a/bi/core.js b/bi/core.js index 3d3ab264a0..56eb536657 100644 --- a/bi/core.js +++ b/bi/core.js @@ -4485,6 +4485,7 @@ BI.Widget = BI.inherit(BI.OB, { this._mountChildren && this._mountChildren(); BI.each(this._children, function (i, widget) { !self.isEnabled() && widget._setEnable(false); + !self.isValid() && widget._setValid(false); widget._mount && widget._mount(); }); this.mounted && this.mounted(); @@ -4518,6 +4519,18 @@ BI.Widget = BI.inherit(BI.OB, { }); }, + _setValid: function (valid) { + if (valid === true) { + this.options.invalid = false; + } else if (valid === false) { + this.options.invalid = true; + } + //递归将所有子组件使有效 + BI.each(this._children, function (i, child) { + child._setValid && child._setValid(valid); + }); + }, + setEnable: function (enable) { this._setEnable(enable); if (enable === true) { @@ -4542,6 +4555,7 @@ BI.Widget = BI.inherit(BI.OB, { setValid: function (valid) { this.options.invalid = !valid; + this._setValid(valid); if (valid === true) { this.element.removeClass("base-invalid invalid"); } else if (valid === false) { @@ -16608,284 +16622,280 @@ BI.extend(jQuery, { * 基本的函数 * Created by GUY on 2015/6/24. */ -$(function () { - BI.Func = {}; - var formulas = {}; - BI.extend(BI.Func, { +BI.Func = {}; +BI.extend(BI.Func, { - /** - * 获取搜索结果 - * @param items - * @param keyword - * @param param 搜索哪个属性 - */ - getSearchResult: function (items, keyword, param) { - var isArray = BI.isArray(items); - items = isArray ? BI.flatten(items) : items; - param || (param = "text"); - if (!BI.isKey(keyword)) { - return { - finded: BI.deepClone(items), - matched: isArray ? [] : {} - }; - } - var t, text, py; - keyword = keyword + ""; - keyword = BI.toUpperCase(keyword); - var matched = isArray ? [] : {}, finded = isArray ? [] : {}; - BI.each(items, function (i, item) { - item = BI.deepClone(item); - t = BI.stripEL(item); - text = t[param] || t.text || t.value || t.name || t; - py = BI.makeFirstPY(text); - text = BI.toUpperCase(text); - py = BI.toUpperCase(py); - var pidx; - if (text.indexOf(keyword) > -1) { - if (text === keyword) { - isArray ? matched.push(item) : (matched[i] = item); - } else { - isArray ? finded.push(item) : (finded[i] = item); - } - } else if (pidx = py.indexOf(keyword), (pidx > -1 && Math.floor(pidx / text.length) === Math.floor((pidx + keyword.length - 1) / text.length))) { - if (text === keyword || keyword.length === text.length) { - isArray ? matched.push(item) : (matched[i] = item); - } else { - isArray ? finded.push(item) : (finded[i] = item); - } - } - }); + /** + * 获取搜索结果 + * @param items + * @param keyword + * @param param 搜索哪个属性 + */ + getSearchResult: function (items, keyword, param) { + var isArray = BI.isArray(items); + items = isArray ? BI.flatten(items) : items; + param || (param = "text"); + if (!BI.isKey(keyword)) { return { - matched: matched, - finded: finded + finded: BI.deepClone(items), + matched: isArray ? [] : {} + }; + } + var t, text, py; + keyword = BI.toUpperCase(keyword); + var matched = isArray ? [] : {}, finded = isArray ? [] : {}; + BI.each(items, function (i, item) { + item = BI.deepClone(item); + t = BI.stripEL(item); + text = t[param] || t.text || t.value || t.name || t; + py = BI.makeFirstPY(text); + text = BI.toUpperCase(text); + py = BI.toUpperCase(py); + var pidx; + if (text.indexOf(keyword) > -1) { + if (text === keyword) { + isArray ? matched.push(item) : (matched[i] = item); + } else { + isArray ? finded.push(item) : (finded[i] = item); + } + } else if (pidx = py.indexOf(keyword), (pidx > -1 && Math.floor(pidx / text.length) === Math.floor((pidx + keyword.length - 1) / text.length))) { + if (text === keyword || keyword.length === text.length) { + isArray ? matched.push(item) : (matched[i] = item); + } else { + isArray ? finded.push(item) : (finded[i] = item); + } } - }, - }); + }); + return { + matched: matched, + finded: finded + } + }, +}); + +/** + * 对DOM操作的通用函数 + * @type {{}} + */ +BI.DOM = {}; +BI.extend(BI.DOM, { /** - * 对DOM操作的通用函数 - * @type {{}} + * 把dom数组或元素悬挂起来,使其不对html产生影响 + * @param dom */ - BI.DOM = {}; - BI.extend(BI.DOM, { - - /** - * 把dom数组或元素悬挂起来,使其不对html产生影响 - * @param dom - */ - hang: function (doms) { - if (BI.isEmpty(doms)) { - return; - } - var frag = document.createDocumentFragment(); - BI.each(doms, function (i, dom) { - dom instanceof BI.Widget && (dom = dom.element); - dom instanceof $ && dom[0] && frag.appendChild(dom[0]); - }); - return frag; - }, + hang: function (doms) { + if (BI.isEmpty(doms)) { + return; + } + var frag = document.createDocumentFragment(); + BI.each(doms, function (i, dom) { + dom instanceof BI.Widget && (dom = dom.element); + dom instanceof $ && dom[0] && frag.appendChild(dom[0]); + }); + return frag; + }, - isExist: function (obj) { - return $("body").find(obj.element).length > 0; - }, + isExist: function (obj) { + return $("body").find(obj.element).length > 0; + }, - //预加载图片 - preloadImages: function (srcArray, onload) { - var count = 0, images = []; + //预加载图片 + preloadImages: function (srcArray, onload) { + var count = 0, images = []; - function complete() { - count++; - if (count >= srcArray.length) { - onload(); - } + function complete() { + count++; + if (count >= srcArray.length) { + onload(); } + } - BI.each(srcArray, function (i, src) { - images[i] = new Image(); - images[i].src = src; - images[i].onload = function () { - complete() - }; - images[i].onerror = function () { - complete() - }; - }); - }, + BI.each(srcArray, function (i, src) { + images[i] = new Image(); + images[i].src = src; + images[i].onload = function () { + complete() + }; + images[i].onerror = function () { + complete() + }; + }); + }, - isColor: function (color) { - return this.isRGBColor(color) || this.isHexColor(color); - }, + isColor: function (color) { + return this.isRGBColor(color) || this.isHexColor(color); + }, - isRGBColor: function (color) { - if (!color) { - return false; - } - return color.substr(0, 3) === "rgb"; - }, + isRGBColor: function (color) { + if (!color) { + return false; + } + return color.substr(0, 3) === "rgb"; + }, - isHexColor: function (color) { - if (!color) { - return false; - } - return color[0] === "#" && color.length === 7; - }, + isHexColor: function (color) { + if (!color) { + return false; + } + return color[0] === "#" && color.length === 7; + }, - isDarkColor: function (hex) { - if (!hex) { - return false; - } - var rgb = this.rgb2json(this.hex2rgb(hex)); - var grayLevel = Math.round(rgb.r * 0.299 + rgb.g * 0.587 + rgb.b * 0.114); - if (grayLevel < 140) { - return true; - } + isDarkColor: function (hex) { + if (!hex) { return false; - }, + } + var rgb = this.rgb2json(this.hex2rgb(hex)); + var grayLevel = Math.round(rgb.r * 0.299 + rgb.g * 0.587 + rgb.b * 0.114); + if (grayLevel < 140) { + return true; + } + return false; + }, - //获取对比颜色 - getContrastColor: function (color) { - if (!color) { - return ""; - } - if (this.isDarkColor(color)) { - return "#ffffff"; - } - return "#1a1a1a"; - }, + //获取对比颜色 + getContrastColor: function (color) { + if (!color) { + return ""; + } + if (this.isDarkColor(color)) { + return "#ffffff"; + } + return "#1a1a1a"; + }, - rgb2hex: function (rgbColour) { - if (!rgbColour || rgbColour.substr(0, 3) != "rgb") { - return ""; - } - var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); - var red = BI.parseInt(rgbValues[0]); - var green = BI.parseInt(rgbValues[1]); - var blue = BI.parseInt(rgbValues[2]); + rgb2hex: function (rgbColour) { + if (!rgbColour || rgbColour.substr(0, 3) != "rgb") { + return ""; + } + var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); + var red = BI.parseInt(rgbValues[0]); + var green = BI.parseInt(rgbValues[1]); + var blue = BI.parseInt(rgbValues[2]); - var hexColour = "#" + this.int2hex(red) + this.int2hex(green) + this.int2hex(blue); + var hexColour = "#" + this.int2hex(red) + this.int2hex(green) + this.int2hex(blue); - return hexColour; - }, + return hexColour; + }, - rgb2json: function (rgbColour) { - if (!rgbColour) { - return {}; - } - var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); - return { - r: BI.parseInt(rgbValues[0]), - g: BI.parseInt(rgbValues[1]), - b: BI.parseInt(rgbValues[2]) - }; - }, + rgb2json: function (rgbColour) { + if (!rgbColour) { + return {}; + } + var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); + return { + r: BI.parseInt(rgbValues[0]), + g: BI.parseInt(rgbValues[1]), + b: BI.parseInt(rgbValues[2]) + }; + }, - rgba2json: function (rgbColour) { - if (!rgbColour) { - return {}; - } - var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); - return { - r: BI.parseInt(rgbValues[0]), - g: BI.parseInt(rgbValues[1]), - b: BI.parseInt(rgbValues[2]), - a: BI.parseFloat(rgbValues[3]) - }; - }, + rgba2json: function (rgbColour) { + if (!rgbColour) { + return {}; + } + var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); + return { + r: BI.parseInt(rgbValues[0]), + g: BI.parseInt(rgbValues[1]), + b: BI.parseInt(rgbValues[2]), + a: BI.parseFloat(rgbValues[3]) + }; + }, - json2rgb: function (rgb) { - if (!BI.isKey(rgb.r) || !BI.isKey(rgb.g) || !BI.isKey(rgb.b)) { - return ""; - } - return "rgb(" + rgb.r + "," + rgb.g + "," + rgb.b + ")"; - }, + json2rgb: function (rgb) { + if (!BI.isKey(rgb.r) || !BI.isKey(rgb.g) || !BI.isKey(rgb.b)) { + return ""; + } + return "rgb(" + rgb.r + "," + rgb.g + "," + rgb.b + ")"; + }, - json2rgba: function (rgba) { - if (!BI.isKey(rgba.r) || !BI.isKey(rgba.g) || !BI.isKey(rgba.b)) { - return ""; - } - return "rgba(" + rgba.r + "," + rgba.g + "," + rgba.b + "," + rgba.a + ")"; - }, + json2rgba: function (rgba) { + if (!BI.isKey(rgba.r) || !BI.isKey(rgba.g) || !BI.isKey(rgba.b)) { + return ""; + } + return "rgba(" + rgba.r + "," + rgba.g + "," + rgba.b + "," + rgba.a + ")"; + }, - int2hex: function (strNum) { - var hexdig = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']; + int2hex: function (strNum) { + var hexdig = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']; - return hexdig[strNum >>> 4] + '' + hexdig[strNum & 15]; - }, + return hexdig[strNum >>> 4] + '' + hexdig[strNum & 15]; + }, - hex2rgb: function (color) { - if (!color) { - return ""; - } - var tempValue = "rgb(", colorArray; + hex2rgb: function (color) { + if (!color) { + return ""; + } + var tempValue = "rgb(", colorArray; - if (color.length === 7) { - colorArray = [BI.parseInt('0x' + color.substring(1, 3)), - BI.parseInt('0x' + color.substring(3, 5)), - BI.parseInt('0x' + color.substring(5, 7))]; - } - else if (color.length === 4) { - colorArray = [BI.parseInt('0x' + color.substring(1, 2)), - BI.parseInt('0x' + color.substring(2, 3)), - BI.parseInt('0x' + color.substring(3, 4))]; - } - tempValue += colorArray[0] + ","; - tempValue += colorArray[1] + ","; - tempValue += colorArray[2] + ")"; + if (color.length === 7) { + colorArray = [BI.parseInt('0x' + color.substring(1, 3)), + BI.parseInt('0x' + color.substring(3, 5)), + BI.parseInt('0x' + color.substring(5, 7))]; + } + else if (color.length === 4) { + colorArray = [BI.parseInt('0x' + color.substring(1, 2)), + BI.parseInt('0x' + color.substring(2, 3)), + BI.parseInt('0x' + color.substring(3, 4))]; + } + tempValue += colorArray[0] + ","; + tempValue += colorArray[1] + ","; + tempValue += colorArray[2] + ")"; - return tempValue; - }, + return tempValue; + }, - rgba2rgb: function (rgbColour, BGcolor) { - if (BI.isNull(BGcolor)) { - BGcolor = 1; - } - if (rgbColour.substr(0, 4) != "rgba") { - return ""; - } - var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); - if (rgbValues.length < 4) { - return ""; - } - var R = BI.parseFloat(rgbValues[0]); - var G = BI.parseFloat(rgbValues[1]); - var B = BI.parseFloat(rgbValues[2]); - var A = BI.parseFloat(rgbValues[3]); + rgba2rgb: function (rgbColour, BGcolor) { + if (BI.isNull(BGcolor)) { + BGcolor = 1; + } + if (rgbColour.substr(0, 4) != "rgba") { + return ""; + } + var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); + if (rgbValues.length < 4) { + return ""; + } + var R = BI.parseFloat(rgbValues[0]); + var G = BI.parseFloat(rgbValues[1]); + var B = BI.parseFloat(rgbValues[2]); + var A = BI.parseFloat(rgbValues[3]); - return "rgb(" + Math.floor(255 * (BGcolor * (1 - A )) + R * A) + "," + - Math.floor(255 * (BGcolor * (1 - A )) + G * A) + "," + - Math.floor(255 * (BGcolor * (1 - A )) + B * A) + ")"; - }, + return "rgb(" + Math.floor(255 * (BGcolor * (1 - A )) + R * A) + "," + + Math.floor(255 * (BGcolor * (1 - A )) + G * A) + "," + + Math.floor(255 * (BGcolor * (1 - A )) + B * A) + ")"; + }, - getTextSizeWidth: function (text, fontSize) { - var span = $("").addClass("text-width-span").appendTo($("body")); + getTextSizeWidth: function (text, fontSize) { + var span = $("").addClass("text-width-span").appendTo($("body")); - if (fontSize == null) { - fontSize = 12; - } - fontSize = fontSize + "px"; + if (fontSize == null) { + fontSize = 12; + } + fontSize = fontSize + "px"; - span.css("font-size", fontSize).text(text); + span.css("font-size", fontSize).text(text); - var width = span.width(); - span.remove(); + var width = span.width(); + span.remove(); - return width; - }, + return width; + }, - //获取滚动条的宽度 - getScrollWidth: function () { - if (this._scrollWidth == null) { - var ul = $("
").width(50).height(50).css({ - position: "absolute", - top: "-9999px", - overflow: "scroll" - }).appendTo($("body")); - this._scrollWidth = ul[0].offsetWidth - ul[0].clientWidth; - ul.destroy(); - } - return this._scrollWidth; + //获取滚动条的宽度 + getScrollWidth: function () { + if (this._scrollWidth == null) { + var ul = $("
").width(50).height(50).css({ + position: "absolute", + top: "-9999px", + overflow: "scroll" + }).appendTo($("body")); + this._scrollWidth = ul[0].offsetWidth - ul[0].clientWidth; + ul.destroy(); } - }); + return this._scrollWidth; + } });/** * guy * 检测某个Widget的EventChange事件然后去show某个card diff --git a/docs/base.js b/docs/base.js index 9c789c2538..89aeb00e72 100644 --- a/docs/base.js +++ b/docs/base.js @@ -14807,7 +14807,7 @@ BI.GridView = BI.inherit(BI.Widget, { minY = Math.min(minY, rowDatum.offset + verticalOffsetAdjustment); maxY = Math.max(maxY, rowDatum.offset + verticalOffsetAdjustment + rowDatum.size); renderedKeys.push(key); - renderedWidgets[i] = child; + renderedWidgets[rowIndex] = child; } } //已存在的, 需要添加的和需要删除的 diff --git a/docs/core.js b/docs/core.js index acd8075bc6..0867958c94 100644 --- a/docs/core.js +++ b/docs/core.js @@ -14487,6 +14487,7 @@ BI.Widget = BI.inherit(BI.OB, { this._mountChildren && this._mountChildren(); BI.each(this._children, function (i, widget) { !self.isEnabled() && widget._setEnable(false); + !self.isValid() && widget._setValid(false); widget._mount && widget._mount(); }); this.mounted && this.mounted(); @@ -14520,6 +14521,18 @@ BI.Widget = BI.inherit(BI.OB, { }); }, + _setValid: function (valid) { + if (valid === true) { + this.options.invalid = false; + } else if (valid === false) { + this.options.invalid = true; + } + //递归将所有子组件使有效 + BI.each(this._children, function (i, child) { + child._setValid && child._setValid(valid); + }); + }, + setEnable: function (enable) { this._setEnable(enable); if (enable === true) { @@ -14544,6 +14557,7 @@ BI.Widget = BI.inherit(BI.OB, { setValid: function (valid) { this.options.invalid = !valid; + this._setValid(valid); if (valid === true) { this.element.removeClass("base-invalid invalid"); } else if (valid === false) { @@ -22631,284 +22645,280 @@ BI.extend(jQuery, { * 基本的函数 * Created by GUY on 2015/6/24. */ -$(function () { - BI.Func = {}; - var formulas = {}; - BI.extend(BI.Func, { +BI.Func = {}; +BI.extend(BI.Func, { - /** - * 获取搜索结果 - * @param items - * @param keyword - * @param param 搜索哪个属性 - */ - getSearchResult: function (items, keyword, param) { - var isArray = BI.isArray(items); - items = isArray ? BI.flatten(items) : items; - param || (param = "text"); - if (!BI.isKey(keyword)) { - return { - finded: BI.deepClone(items), - matched: isArray ? [] : {} - }; - } - var t, text, py; - keyword = keyword + ""; - keyword = BI.toUpperCase(keyword); - var matched = isArray ? [] : {}, finded = isArray ? [] : {}; - BI.each(items, function (i, item) { - item = BI.deepClone(item); - t = BI.stripEL(item); - text = t[param] || t.text || t.value || t.name || t; - py = BI.makeFirstPY(text); - text = BI.toUpperCase(text); - py = BI.toUpperCase(py); - var pidx; - if (text.indexOf(keyword) > -1) { - if (text === keyword) { - isArray ? matched.push(item) : (matched[i] = item); - } else { - isArray ? finded.push(item) : (finded[i] = item); - } - } else if (pidx = py.indexOf(keyword), (pidx > -1 && Math.floor(pidx / text.length) === Math.floor((pidx + keyword.length - 1) / text.length))) { - if (text === keyword || keyword.length === text.length) { - isArray ? matched.push(item) : (matched[i] = item); - } else { - isArray ? finded.push(item) : (finded[i] = item); - } - } - }); + /** + * 获取搜索结果 + * @param items + * @param keyword + * @param param 搜索哪个属性 + */ + getSearchResult: function (items, keyword, param) { + var isArray = BI.isArray(items); + items = isArray ? BI.flatten(items) : items; + param || (param = "text"); + if (!BI.isKey(keyword)) { return { - matched: matched, - finded: finded + finded: BI.deepClone(items), + matched: isArray ? [] : {} + }; + } + var t, text, py; + keyword = BI.toUpperCase(keyword); + var matched = isArray ? [] : {}, finded = isArray ? [] : {}; + BI.each(items, function (i, item) { + item = BI.deepClone(item); + t = BI.stripEL(item); + text = t[param] || t.text || t.value || t.name || t; + py = BI.makeFirstPY(text); + text = BI.toUpperCase(text); + py = BI.toUpperCase(py); + var pidx; + if (text.indexOf(keyword) > -1) { + if (text === keyword) { + isArray ? matched.push(item) : (matched[i] = item); + } else { + isArray ? finded.push(item) : (finded[i] = item); + } + } else if (pidx = py.indexOf(keyword), (pidx > -1 && Math.floor(pidx / text.length) === Math.floor((pidx + keyword.length - 1) / text.length))) { + if (text === keyword || keyword.length === text.length) { + isArray ? matched.push(item) : (matched[i] = item); + } else { + isArray ? finded.push(item) : (finded[i] = item); + } } - }, - }); + }); + return { + matched: matched, + finded: finded + } + }, +}); + +/** + * 对DOM操作的通用函数 + * @type {{}} + */ +BI.DOM = {}; +BI.extend(BI.DOM, { /** - * 对DOM操作的通用函数 - * @type {{}} + * 把dom数组或元素悬挂起来,使其不对html产生影响 + * @param dom */ - BI.DOM = {}; - BI.extend(BI.DOM, { - - /** - * 把dom数组或元素悬挂起来,使其不对html产生影响 - * @param dom - */ - hang: function (doms) { - if (BI.isEmpty(doms)) { - return; - } - var frag = document.createDocumentFragment(); - BI.each(doms, function (i, dom) { - dom instanceof BI.Widget && (dom = dom.element); - dom instanceof $ && dom[0] && frag.appendChild(dom[0]); - }); - return frag; - }, + hang: function (doms) { + if (BI.isEmpty(doms)) { + return; + } + var frag = document.createDocumentFragment(); + BI.each(doms, function (i, dom) { + dom instanceof BI.Widget && (dom = dom.element); + dom instanceof $ && dom[0] && frag.appendChild(dom[0]); + }); + return frag; + }, - isExist: function (obj) { - return $("body").find(obj.element).length > 0; - }, + isExist: function (obj) { + return $("body").find(obj.element).length > 0; + }, - //预加载图片 - preloadImages: function (srcArray, onload) { - var count = 0, images = []; + //预加载图片 + preloadImages: function (srcArray, onload) { + var count = 0, images = []; - function complete() { - count++; - if (count >= srcArray.length) { - onload(); - } + function complete() { + count++; + if (count >= srcArray.length) { + onload(); } + } - BI.each(srcArray, function (i, src) { - images[i] = new Image(); - images[i].src = src; - images[i].onload = function () { - complete() - }; - images[i].onerror = function () { - complete() - }; - }); - }, + BI.each(srcArray, function (i, src) { + images[i] = new Image(); + images[i].src = src; + images[i].onload = function () { + complete() + }; + images[i].onerror = function () { + complete() + }; + }); + }, - isColor: function (color) { - return this.isRGBColor(color) || this.isHexColor(color); - }, + isColor: function (color) { + return this.isRGBColor(color) || this.isHexColor(color); + }, - isRGBColor: function (color) { - if (!color) { - return false; - } - return color.substr(0, 3) === "rgb"; - }, + isRGBColor: function (color) { + if (!color) { + return false; + } + return color.substr(0, 3) === "rgb"; + }, - isHexColor: function (color) { - if (!color) { - return false; - } - return color[0] === "#" && color.length === 7; - }, + isHexColor: function (color) { + if (!color) { + return false; + } + return color[0] === "#" && color.length === 7; + }, - isDarkColor: function (hex) { - if (!hex) { - return false; - } - var rgb = this.rgb2json(this.hex2rgb(hex)); - var grayLevel = Math.round(rgb.r * 0.299 + rgb.g * 0.587 + rgb.b * 0.114); - if (grayLevel < 140) { - return true; - } + isDarkColor: function (hex) { + if (!hex) { return false; - }, + } + var rgb = this.rgb2json(this.hex2rgb(hex)); + var grayLevel = Math.round(rgb.r * 0.299 + rgb.g * 0.587 + rgb.b * 0.114); + if (grayLevel < 140) { + return true; + } + return false; + }, - //获取对比颜色 - getContrastColor: function (color) { - if (!color) { - return ""; - } - if (this.isDarkColor(color)) { - return "#ffffff"; - } - return "#1a1a1a"; - }, + //获取对比颜色 + getContrastColor: function (color) { + if (!color) { + return ""; + } + if (this.isDarkColor(color)) { + return "#ffffff"; + } + return "#1a1a1a"; + }, - rgb2hex: function (rgbColour) { - if (!rgbColour || rgbColour.substr(0, 3) != "rgb") { - return ""; - } - var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); - var red = BI.parseInt(rgbValues[0]); - var green = BI.parseInt(rgbValues[1]); - var blue = BI.parseInt(rgbValues[2]); + rgb2hex: function (rgbColour) { + if (!rgbColour || rgbColour.substr(0, 3) != "rgb") { + return ""; + } + var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); + var red = BI.parseInt(rgbValues[0]); + var green = BI.parseInt(rgbValues[1]); + var blue = BI.parseInt(rgbValues[2]); - var hexColour = "#" + this.int2hex(red) + this.int2hex(green) + this.int2hex(blue); + var hexColour = "#" + this.int2hex(red) + this.int2hex(green) + this.int2hex(blue); - return hexColour; - }, + return hexColour; + }, - rgb2json: function (rgbColour) { - if (!rgbColour) { - return {}; - } - var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); - return { - r: BI.parseInt(rgbValues[0]), - g: BI.parseInt(rgbValues[1]), - b: BI.parseInt(rgbValues[2]) - }; - }, + rgb2json: function (rgbColour) { + if (!rgbColour) { + return {}; + } + var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); + return { + r: BI.parseInt(rgbValues[0]), + g: BI.parseInt(rgbValues[1]), + b: BI.parseInt(rgbValues[2]) + }; + }, - rgba2json: function (rgbColour) { - if (!rgbColour) { - return {}; - } - var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); - return { - r: BI.parseInt(rgbValues[0]), - g: BI.parseInt(rgbValues[1]), - b: BI.parseInt(rgbValues[2]), - a: BI.parseFloat(rgbValues[3]) - }; - }, + rgba2json: function (rgbColour) { + if (!rgbColour) { + return {}; + } + var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); + return { + r: BI.parseInt(rgbValues[0]), + g: BI.parseInt(rgbValues[1]), + b: BI.parseInt(rgbValues[2]), + a: BI.parseFloat(rgbValues[3]) + }; + }, - json2rgb: function (rgb) { - if (!BI.isKey(rgb.r) || !BI.isKey(rgb.g) || !BI.isKey(rgb.b)) { - return ""; - } - return "rgb(" + rgb.r + "," + rgb.g + "," + rgb.b + ")"; - }, + json2rgb: function (rgb) { + if (!BI.isKey(rgb.r) || !BI.isKey(rgb.g) || !BI.isKey(rgb.b)) { + return ""; + } + return "rgb(" + rgb.r + "," + rgb.g + "," + rgb.b + ")"; + }, - json2rgba: function (rgba) { - if (!BI.isKey(rgba.r) || !BI.isKey(rgba.g) || !BI.isKey(rgba.b)) { - return ""; - } - return "rgba(" + rgba.r + "," + rgba.g + "," + rgba.b + "," + rgba.a + ")"; - }, + json2rgba: function (rgba) { + if (!BI.isKey(rgba.r) || !BI.isKey(rgba.g) || !BI.isKey(rgba.b)) { + return ""; + } + return "rgba(" + rgba.r + "," + rgba.g + "," + rgba.b + "," + rgba.a + ")"; + }, - int2hex: function (strNum) { - var hexdig = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']; + int2hex: function (strNum) { + var hexdig = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']; - return hexdig[strNum >>> 4] + '' + hexdig[strNum & 15]; - }, + return hexdig[strNum >>> 4] + '' + hexdig[strNum & 15]; + }, - hex2rgb: function (color) { - if (!color) { - return ""; - } - var tempValue = "rgb(", colorArray; + hex2rgb: function (color) { + if (!color) { + return ""; + } + var tempValue = "rgb(", colorArray; - if (color.length === 7) { - colorArray = [BI.parseInt('0x' + color.substring(1, 3)), - BI.parseInt('0x' + color.substring(3, 5)), - BI.parseInt('0x' + color.substring(5, 7))]; - } - else if (color.length === 4) { - colorArray = [BI.parseInt('0x' + color.substring(1, 2)), - BI.parseInt('0x' + color.substring(2, 3)), - BI.parseInt('0x' + color.substring(3, 4))]; - } - tempValue += colorArray[0] + ","; - tempValue += colorArray[1] + ","; - tempValue += colorArray[2] + ")"; + if (color.length === 7) { + colorArray = [BI.parseInt('0x' + color.substring(1, 3)), + BI.parseInt('0x' + color.substring(3, 5)), + BI.parseInt('0x' + color.substring(5, 7))]; + } + else if (color.length === 4) { + colorArray = [BI.parseInt('0x' + color.substring(1, 2)), + BI.parseInt('0x' + color.substring(2, 3)), + BI.parseInt('0x' + color.substring(3, 4))]; + } + tempValue += colorArray[0] + ","; + tempValue += colorArray[1] + ","; + tempValue += colorArray[2] + ")"; - return tempValue; - }, + return tempValue; + }, - rgba2rgb: function (rgbColour, BGcolor) { - if (BI.isNull(BGcolor)) { - BGcolor = 1; - } - if (rgbColour.substr(0, 4) != "rgba") { - return ""; - } - var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); - if (rgbValues.length < 4) { - return ""; - } - var R = BI.parseFloat(rgbValues[0]); - var G = BI.parseFloat(rgbValues[1]); - var B = BI.parseFloat(rgbValues[2]); - var A = BI.parseFloat(rgbValues[3]); + rgba2rgb: function (rgbColour, BGcolor) { + if (BI.isNull(BGcolor)) { + BGcolor = 1; + } + if (rgbColour.substr(0, 4) != "rgba") { + return ""; + } + var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); + if (rgbValues.length < 4) { + return ""; + } + var R = BI.parseFloat(rgbValues[0]); + var G = BI.parseFloat(rgbValues[1]); + var B = BI.parseFloat(rgbValues[2]); + var A = BI.parseFloat(rgbValues[3]); - return "rgb(" + Math.floor(255 * (BGcolor * (1 - A )) + R * A) + "," + - Math.floor(255 * (BGcolor * (1 - A )) + G * A) + "," + - Math.floor(255 * (BGcolor * (1 - A )) + B * A) + ")"; - }, + return "rgb(" + Math.floor(255 * (BGcolor * (1 - A )) + R * A) + "," + + Math.floor(255 * (BGcolor * (1 - A )) + G * A) + "," + + Math.floor(255 * (BGcolor * (1 - A )) + B * A) + ")"; + }, - getTextSizeWidth: function (text, fontSize) { - var span = $("").addClass("text-width-span").appendTo($("body")); + getTextSizeWidth: function (text, fontSize) { + var span = $("").addClass("text-width-span").appendTo($("body")); - if (fontSize == null) { - fontSize = 12; - } - fontSize = fontSize + "px"; + if (fontSize == null) { + fontSize = 12; + } + fontSize = fontSize + "px"; - span.css("font-size", fontSize).text(text); + span.css("font-size", fontSize).text(text); - var width = span.width(); - span.remove(); + var width = span.width(); + span.remove(); - return width; - }, + return width; + }, - //获取滚动条的宽度 - getScrollWidth: function () { - if (this._scrollWidth == null) { - var ul = $("
").width(50).height(50).css({ - position: "absolute", - top: "-9999px", - overflow: "scroll" - }).appendTo($("body")); - this._scrollWidth = ul[0].offsetWidth - ul[0].clientWidth; - ul.destroy(); - } - return this._scrollWidth; + //获取滚动条的宽度 + getScrollWidth: function () { + if (this._scrollWidth == null) { + var ul = $("
").width(50).height(50).css({ + position: "absolute", + top: "-9999px", + overflow: "scroll" + }).appendTo($("body")); + this._scrollWidth = ul[0].offsetWidth - ul[0].clientWidth; + ul.destroy(); } - }); + return this._scrollWidth; + } });/** * guy * 检测某个Widget的EventChange事件然后去show某个card diff --git a/src/base/grid/grid.js b/src/base/grid/grid.js index 82e00bad64..35ccab50ca 100644 --- a/src/base/grid/grid.js +++ b/src/base/grid/grid.js @@ -172,7 +172,7 @@ BI.GridView = BI.inherit(BI.Widget, { minY = Math.min(minY, rowDatum.offset + verticalOffsetAdjustment); maxY = Math.max(maxY, rowDatum.offset + verticalOffsetAdjustment + rowDatum.size); renderedKeys.push(key); - renderedWidgets[i] = child; + renderedWidgets[rowIndex] = child; } } //已存在的, 需要添加的和需要删除的 diff --git a/src/core/widget.js b/src/core/widget.js index 83e63c84dc..3e217a5c3f 100644 --- a/src/core/widget.js +++ b/src/core/widget.js @@ -165,6 +165,7 @@ BI.Widget = BI.inherit(BI.OB, { this._mountChildren && this._mountChildren(); BI.each(this._children, function (i, widget) { !self.isEnabled() && widget._setEnable(false); + !self.isValid() && widget._setValid(false); widget._mount && widget._mount(); }); this.mounted && this.mounted(); @@ -198,6 +199,18 @@ BI.Widget = BI.inherit(BI.OB, { }); }, + _setValid: function (valid) { + if (valid === true) { + this.options.invalid = false; + } else if (valid === false) { + this.options.invalid = true; + } + //递归将所有子组件使有效 + BI.each(this._children, function (i, child) { + child._setValid && child._setValid(valid); + }); + }, + setEnable: function (enable) { this._setEnable(enable); if (enable === true) { @@ -222,6 +235,7 @@ BI.Widget = BI.inherit(BI.OB, { setValid: function (valid) { this.options.invalid = !valid; + this._setValid(valid); if (valid === true) { this.element.removeClass("base-invalid invalid"); } else if (valid === false) { From 03bbac1322b37b716b93bbd5ed421486f47a0a62 Mon Sep 17 00:00:00 2001 From: guy Date: Thu, 18 May 2017 14:18:41 +0800 Subject: [PATCH 06/10] bug --- bi/base.js | 10 ++++++---- docs/base.js | 10 ++++++---- src/base/collection/collection.js | 5 +++-- src/base/grid/grid.js | 5 +++-- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/bi/base.js b/bi/base.js index 89aeb00e72..cc94118cc6 100644 --- a/bi/base.js +++ b/bi/base.js @@ -2666,6 +2666,7 @@ BI.CollectionView = BI.inherit(BI.Widget, { for (var i = 0, len = childrenToDisplay.length; i < len; i++) { var datum = childrenToDisplay[i]; var index = BI.deepIndexOf(this.renderedKeys, datum.index); + var child; if (index > -1) { if (datum.width !== this.renderedCells[index]._width) { this.renderedCells[index]._width = datum.width; @@ -2681,9 +2682,9 @@ BI.CollectionView = BI.inherit(BI.Widget, { if (this.renderedCells[index].top !== datum.y) { this.renderedCells[index].el.element.css("top", datum.y + "px"); } - renderedCells.push(this.renderedCells[index]); + renderedCells.push(child = this.renderedCells[index]); } else { - var child = BI.createWidget(BI.extend({ + child = BI.createWidget(BI.extend({ type: "bi.label", width: datum.width, height: datum.height @@ -14766,6 +14767,7 @@ BI.GridView = BI.inherit(BI.Widget, { var columnDatum = this._columnSizeAndPositionManager.getSizeAndPositionOfCell(columnIndex); var index = BI.deepIndexOf(this.renderedKeys, key); + var child; if (index > -1) { if (columnDatum.size !== this.renderedCells[index]._width) { this.renderedCells[index]._width = columnDatum.size; @@ -14781,9 +14783,9 @@ BI.GridView = BI.inherit(BI.Widget, { if (this.renderedCells[index].top !== rowDatum.offset + verticalOffsetAdjustment) { this.renderedCells[index].el.element.css("top", (rowDatum.offset + verticalOffsetAdjustment) + "px"); } - renderedCells.push(this.renderedCells[index]); + renderedCells.push(child = this.renderedCells[index]); } else { - var child = BI.createWidget(BI.extend({ + child = BI.createWidget(BI.extend({ type: "bi.label", width: columnDatum.size, height: rowDatum.size diff --git a/docs/base.js b/docs/base.js index 89aeb00e72..cc94118cc6 100644 --- a/docs/base.js +++ b/docs/base.js @@ -2666,6 +2666,7 @@ BI.CollectionView = BI.inherit(BI.Widget, { for (var i = 0, len = childrenToDisplay.length; i < len; i++) { var datum = childrenToDisplay[i]; var index = BI.deepIndexOf(this.renderedKeys, datum.index); + var child; if (index > -1) { if (datum.width !== this.renderedCells[index]._width) { this.renderedCells[index]._width = datum.width; @@ -2681,9 +2682,9 @@ BI.CollectionView = BI.inherit(BI.Widget, { if (this.renderedCells[index].top !== datum.y) { this.renderedCells[index].el.element.css("top", datum.y + "px"); } - renderedCells.push(this.renderedCells[index]); + renderedCells.push(child = this.renderedCells[index]); } else { - var child = BI.createWidget(BI.extend({ + child = BI.createWidget(BI.extend({ type: "bi.label", width: datum.width, height: datum.height @@ -14766,6 +14767,7 @@ BI.GridView = BI.inherit(BI.Widget, { var columnDatum = this._columnSizeAndPositionManager.getSizeAndPositionOfCell(columnIndex); var index = BI.deepIndexOf(this.renderedKeys, key); + var child; if (index > -1) { if (columnDatum.size !== this.renderedCells[index]._width) { this.renderedCells[index]._width = columnDatum.size; @@ -14781,9 +14783,9 @@ BI.GridView = BI.inherit(BI.Widget, { if (this.renderedCells[index].top !== rowDatum.offset + verticalOffsetAdjustment) { this.renderedCells[index].el.element.css("top", (rowDatum.offset + verticalOffsetAdjustment) + "px"); } - renderedCells.push(this.renderedCells[index]); + renderedCells.push(child = this.renderedCells[index]); } else { - var child = BI.createWidget(BI.extend({ + child = BI.createWidget(BI.extend({ type: "bi.label", width: columnDatum.size, height: rowDatum.size diff --git a/src/base/collection/collection.js b/src/base/collection/collection.js index 111c833e88..864a791026 100644 --- a/src/base/collection/collection.js +++ b/src/base/collection/collection.js @@ -156,6 +156,7 @@ BI.CollectionView = BI.inherit(BI.Widget, { for (var i = 0, len = childrenToDisplay.length; i < len; i++) { var datum = childrenToDisplay[i]; var index = BI.deepIndexOf(this.renderedKeys, datum.index); + var child; if (index > -1) { if (datum.width !== this.renderedCells[index]._width) { this.renderedCells[index]._width = datum.width; @@ -171,9 +172,9 @@ BI.CollectionView = BI.inherit(BI.Widget, { if (this.renderedCells[index].top !== datum.y) { this.renderedCells[index].el.element.css("top", datum.y + "px"); } - renderedCells.push(this.renderedCells[index]); + renderedCells.push(child = this.renderedCells[index]); } else { - var child = BI.createWidget(BI.extend({ + child = BI.createWidget(BI.extend({ type: "bi.label", width: datum.width, height: datum.height diff --git a/src/base/grid/grid.js b/src/base/grid/grid.js index 35ccab50ca..56b65d42be 100644 --- a/src/base/grid/grid.js +++ b/src/base/grid/grid.js @@ -131,6 +131,7 @@ BI.GridView = BI.inherit(BI.Widget, { var columnDatum = this._columnSizeAndPositionManager.getSizeAndPositionOfCell(columnIndex); var index = BI.deepIndexOf(this.renderedKeys, key); + var child; if (index > -1) { if (columnDatum.size !== this.renderedCells[index]._width) { this.renderedCells[index]._width = columnDatum.size; @@ -146,9 +147,9 @@ BI.GridView = BI.inherit(BI.Widget, { if (this.renderedCells[index].top !== rowDatum.offset + verticalOffsetAdjustment) { this.renderedCells[index].el.element.css("top", (rowDatum.offset + verticalOffsetAdjustment) + "px"); } - renderedCells.push(this.renderedCells[index]); + renderedCells.push(child = this.renderedCells[index]); } else { - var child = BI.createWidget(BI.extend({ + child = BI.createWidget(BI.extend({ type: "bi.label", width: columnDatum.size, height: rowDatum.size From a49a249ffb59b296dcc61c95c3cae126e128d666 Mon Sep 17 00:00:00 2001 From: guy Date: Thu, 18 May 2017 15:07:00 +0800 Subject: [PATCH 07/10] add --- bi/base.js | 52 ++++++++++++++++++++++++++---- docs/base.js | 52 ++++++++++++++++++++++++++---- src/base/collection/collection.js | 5 +++ src/base/grid/grid.js | 9 ++++-- src/base/table/table.collection.js | 17 ++++++++-- src/base/table/table.grid.js | 15 +++++++++ src/base/table/table.resizable.js | 6 ++-- 7 files changed, 135 insertions(+), 21 deletions(-) diff --git a/bi/base.js b/bi/base.js index cc94118cc6..ba2bebf1ce 100644 --- a/bi/base.js +++ b/bi/base.js @@ -2845,6 +2845,11 @@ BI.CollectionView = BI.inherit(BI.Widget, { return this._getMaxScrollTop(); }, + //重新计算children + reRange: function () { + this.renderRange = {}; + }, + restore: function () { BI.each(this.renderedCells, function (i, cell) { cell.el.destroy(); @@ -14759,6 +14764,7 @@ BI.GridView = BI.inherit(BI.Widget, { var renderedCells = [], renderedKeys = [], renderedWidgets = {}; var minX = this._getMaxScrollLeft(), minY = this._getMaxScrollTop(), maxX = 0, maxY = 0; + var count = 0; for (var rowIndex = rowStartIndex; rowIndex <= rowStopIndex; rowIndex++) { var rowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowIndex); @@ -14809,7 +14815,7 @@ BI.GridView = BI.inherit(BI.Widget, { minY = Math.min(minY, rowDatum.offset + verticalOffsetAdjustment); maxY = Math.max(maxY, rowDatum.offset + verticalOffsetAdjustment + rowDatum.size); renderedKeys.push(key); - renderedWidgets[rowIndex] = child; + renderedWidgets[count++] = child; } } //已存在的, 需要添加的和需要删除的 @@ -14942,6 +14948,11 @@ BI.GridView = BI.inherit(BI.Widget, { this.options.estimatedRowSize = height; }, + //重新计算children + reRange: function () { + this.renderRange = {}; + }, + restore: function () { BI.each(this.renderedCells, function (i, cell) { cell.el.destroy(); @@ -14955,7 +14966,6 @@ BI.GridView = BI.inherit(BI.Widget, { populate: function (items) { if (items && items !== this.options.items) { this.options.items = items; - this.restore(); } this._populate(); } @@ -28711,7 +28721,8 @@ BI.CollectionTable = BI.inherit(BI.Widget, { _populateScrollbar: function () { var o = this.options; - var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0, summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize; + var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0, + summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize; var freezeColLength = this._getFreezeColLength(); BI.each(o.columnSize, function (i, size) { if (o.isNeedFreeze === true && o.freezeCols.contains(i)) { @@ -28752,7 +28763,8 @@ BI.CollectionTable = BI.inherit(BI.Widget, { _populateTable: function () { var self = this, o = this.options; - var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0, summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize; + var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0, + summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize; var freezeColLength = this._getFreezeColLength(); BI.each(o.columnSize, function (i, size) { if (o.isNeedFreeze === true && o.freezeCols.contains(i)) { @@ -28783,7 +28795,7 @@ BI.CollectionTable = BI.inherit(BI.Widget, { var trh = otrh + this._scrollBarSize; var blw = oblw + this._scrollBarSize; var blh = oblh + this._scrollBarSize; - var brw = obrw+ this._scrollBarSize; + var brw = obrw + this._scrollBarSize; var brh = obrh + this._scrollBarSize; var digest = function (el) { @@ -28963,8 +28975,10 @@ BI.CollectionTable = BI.inherit(BI.Widget, { return; } if (this._isNeedDigest === true) { + this._reRange(); this._digest(); } + this._isNeedDigest = false; this._populateTable(); this._populateScrollbar(); }, @@ -29059,6 +29073,13 @@ BI.CollectionTable = BI.inherit(BI.Widget, { this.bottomRightCollection.restore(); }, + _reRange: function () { + this.topLeftCollection.reRange(); + this.topRightCollection.reRange(); + this.bottomLeftCollection.reRange(); + this.bottomRightCollection.reRange(); + }, + restore: function () { this._restore(); } @@ -29671,6 +29692,10 @@ BI.GridTable = BI.inherit(BI.Widget, { if (this._width <= 0 || this._height <= 0) { return; } + if (this._isNeedDigest === true) { + this._reRange(); + this._isNeedDigest = false; + } this._populateTable(); this._populateScrollbar(); }, @@ -29728,10 +29753,12 @@ BI.GridTable = BI.inherit(BI.Widget, { setColumnSize: function (columnSize) { this.options.columnSize = columnSize; + this._isNeedDigest = true; }, setRegionColumnSize: function (regionColumnSize) { this.options.regionColumnSize = regionColumnSize; + this._isNeedDigest = true; }, getColumnSize: function () { @@ -29744,11 +29771,13 @@ BI.GridTable = BI.inherit(BI.Widget, { populate: function (items, header) { if (items && this.options.items !== items) { + this._isNeedDigest = true; this.options.items = items; this.items = this._getItems(); this._restore(); } if (header && this.options.header !== header) { + this._isNeedDigest = true; this.options.header = header; this.header = this._getHeader(); this._restore(); @@ -29763,6 +29792,13 @@ BI.GridTable = BI.inherit(BI.Widget, { this.bottomRightGrid.restore(); }, + _reRange: function () { + this.topLeftGrid.reRange(); + this.topRightGrid.reRange(); + this.bottomLeftGrid.reRange(); + this.bottomRightGrid.reRange(); + }, + restore: function () { this._restore(); } @@ -32356,8 +32392,10 @@ BI.ResizableTable = BI.inherit(BI.Widget, { }; var stop = function (j, size) { self.resizer.setVisible(false); - o.columnSize[j] = size; - self.table.setColumnSize(o.columnSize); + var columnSize = o.columnSize.slice(); + columnSize[j] = size; + o.columnSize = columnSize; + self.table.setColumnSize(columnSize); self.table.populate(); self._populate(); self.fireEvent(BI.Table.EVENT_TABLE_AFTER_COLUMN_RESIZE); diff --git a/docs/base.js b/docs/base.js index cc94118cc6..ba2bebf1ce 100644 --- a/docs/base.js +++ b/docs/base.js @@ -2845,6 +2845,11 @@ BI.CollectionView = BI.inherit(BI.Widget, { return this._getMaxScrollTop(); }, + //重新计算children + reRange: function () { + this.renderRange = {}; + }, + restore: function () { BI.each(this.renderedCells, function (i, cell) { cell.el.destroy(); @@ -14759,6 +14764,7 @@ BI.GridView = BI.inherit(BI.Widget, { var renderedCells = [], renderedKeys = [], renderedWidgets = {}; var minX = this._getMaxScrollLeft(), minY = this._getMaxScrollTop(), maxX = 0, maxY = 0; + var count = 0; for (var rowIndex = rowStartIndex; rowIndex <= rowStopIndex; rowIndex++) { var rowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowIndex); @@ -14809,7 +14815,7 @@ BI.GridView = BI.inherit(BI.Widget, { minY = Math.min(minY, rowDatum.offset + verticalOffsetAdjustment); maxY = Math.max(maxY, rowDatum.offset + verticalOffsetAdjustment + rowDatum.size); renderedKeys.push(key); - renderedWidgets[rowIndex] = child; + renderedWidgets[count++] = child; } } //已存在的, 需要添加的和需要删除的 @@ -14942,6 +14948,11 @@ BI.GridView = BI.inherit(BI.Widget, { this.options.estimatedRowSize = height; }, + //重新计算children + reRange: function () { + this.renderRange = {}; + }, + restore: function () { BI.each(this.renderedCells, function (i, cell) { cell.el.destroy(); @@ -14955,7 +14966,6 @@ BI.GridView = BI.inherit(BI.Widget, { populate: function (items) { if (items && items !== this.options.items) { this.options.items = items; - this.restore(); } this._populate(); } @@ -28711,7 +28721,8 @@ BI.CollectionTable = BI.inherit(BI.Widget, { _populateScrollbar: function () { var o = this.options; - var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0, summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize; + var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0, + summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize; var freezeColLength = this._getFreezeColLength(); BI.each(o.columnSize, function (i, size) { if (o.isNeedFreeze === true && o.freezeCols.contains(i)) { @@ -28752,7 +28763,8 @@ BI.CollectionTable = BI.inherit(BI.Widget, { _populateTable: function () { var self = this, o = this.options; - var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0, summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize; + var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0, + summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize; var freezeColLength = this._getFreezeColLength(); BI.each(o.columnSize, function (i, size) { if (o.isNeedFreeze === true && o.freezeCols.contains(i)) { @@ -28783,7 +28795,7 @@ BI.CollectionTable = BI.inherit(BI.Widget, { var trh = otrh + this._scrollBarSize; var blw = oblw + this._scrollBarSize; var blh = oblh + this._scrollBarSize; - var brw = obrw+ this._scrollBarSize; + var brw = obrw + this._scrollBarSize; var brh = obrh + this._scrollBarSize; var digest = function (el) { @@ -28963,8 +28975,10 @@ BI.CollectionTable = BI.inherit(BI.Widget, { return; } if (this._isNeedDigest === true) { + this._reRange(); this._digest(); } + this._isNeedDigest = false; this._populateTable(); this._populateScrollbar(); }, @@ -29059,6 +29073,13 @@ BI.CollectionTable = BI.inherit(BI.Widget, { this.bottomRightCollection.restore(); }, + _reRange: function () { + this.topLeftCollection.reRange(); + this.topRightCollection.reRange(); + this.bottomLeftCollection.reRange(); + this.bottomRightCollection.reRange(); + }, + restore: function () { this._restore(); } @@ -29671,6 +29692,10 @@ BI.GridTable = BI.inherit(BI.Widget, { if (this._width <= 0 || this._height <= 0) { return; } + if (this._isNeedDigest === true) { + this._reRange(); + this._isNeedDigest = false; + } this._populateTable(); this._populateScrollbar(); }, @@ -29728,10 +29753,12 @@ BI.GridTable = BI.inherit(BI.Widget, { setColumnSize: function (columnSize) { this.options.columnSize = columnSize; + this._isNeedDigest = true; }, setRegionColumnSize: function (regionColumnSize) { this.options.regionColumnSize = regionColumnSize; + this._isNeedDigest = true; }, getColumnSize: function () { @@ -29744,11 +29771,13 @@ BI.GridTable = BI.inherit(BI.Widget, { populate: function (items, header) { if (items && this.options.items !== items) { + this._isNeedDigest = true; this.options.items = items; this.items = this._getItems(); this._restore(); } if (header && this.options.header !== header) { + this._isNeedDigest = true; this.options.header = header; this.header = this._getHeader(); this._restore(); @@ -29763,6 +29792,13 @@ BI.GridTable = BI.inherit(BI.Widget, { this.bottomRightGrid.restore(); }, + _reRange: function () { + this.topLeftGrid.reRange(); + this.topRightGrid.reRange(); + this.bottomLeftGrid.reRange(); + this.bottomRightGrid.reRange(); + }, + restore: function () { this._restore(); } @@ -32356,8 +32392,10 @@ BI.ResizableTable = BI.inherit(BI.Widget, { }; var stop = function (j, size) { self.resizer.setVisible(false); - o.columnSize[j] = size; - self.table.setColumnSize(o.columnSize); + var columnSize = o.columnSize.slice(); + columnSize[j] = size; + o.columnSize = columnSize; + self.table.setColumnSize(columnSize); self.table.populate(); self._populate(); self.fireEvent(BI.Table.EVENT_TABLE_AFTER_COLUMN_RESIZE); diff --git a/src/base/collection/collection.js b/src/base/collection/collection.js index 864a791026..a4ee2e3d35 100644 --- a/src/base/collection/collection.js +++ b/src/base/collection/collection.js @@ -335,6 +335,11 @@ BI.CollectionView = BI.inherit(BI.Widget, { return this._getMaxScrollTop(); }, + //重新计算children + reRange: function () { + this.renderRange = {}; + }, + restore: function () { BI.each(this.renderedCells, function (i, cell) { cell.el.destroy(); diff --git a/src/base/grid/grid.js b/src/base/grid/grid.js index 56b65d42be..98bd8d3b27 100644 --- a/src/base/grid/grid.js +++ b/src/base/grid/grid.js @@ -123,6 +123,7 @@ BI.GridView = BI.inherit(BI.Widget, { var renderedCells = [], renderedKeys = [], renderedWidgets = {}; var minX = this._getMaxScrollLeft(), minY = this._getMaxScrollTop(), maxX = 0, maxY = 0; + var count = 0; for (var rowIndex = rowStartIndex; rowIndex <= rowStopIndex; rowIndex++) { var rowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowIndex); @@ -173,7 +174,7 @@ BI.GridView = BI.inherit(BI.Widget, { minY = Math.min(minY, rowDatum.offset + verticalOffsetAdjustment); maxY = Math.max(maxY, rowDatum.offset + verticalOffsetAdjustment + rowDatum.size); renderedKeys.push(key); - renderedWidgets[rowIndex] = child; + renderedWidgets[count++] = child; } } //已存在的, 需要添加的和需要删除的 @@ -306,6 +307,11 @@ BI.GridView = BI.inherit(BI.Widget, { this.options.estimatedRowSize = height; }, + //重新计算children + reRange: function () { + this.renderRange = {}; + }, + restore: function () { BI.each(this.renderedCells, function (i, cell) { cell.el.destroy(); @@ -319,7 +325,6 @@ BI.GridView = BI.inherit(BI.Widget, { populate: function (items) { if (items && items !== this.options.items) { this.options.items = items; - this.restore(); } this._populate(); } diff --git a/src/base/table/table.collection.js b/src/base/table/table.collection.js index 535b3e1aeb..e599bf5c92 100644 --- a/src/base/table/table.collection.js +++ b/src/base/table/table.collection.js @@ -175,7 +175,8 @@ BI.CollectionTable = BI.inherit(BI.Widget, { _populateScrollbar: function () { var o = this.options; - var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0, summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize; + var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0, + summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize; var freezeColLength = this._getFreezeColLength(); BI.each(o.columnSize, function (i, size) { if (o.isNeedFreeze === true && o.freezeCols.contains(i)) { @@ -216,7 +217,8 @@ BI.CollectionTable = BI.inherit(BI.Widget, { _populateTable: function () { var self = this, o = this.options; - var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0, summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize; + var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0, + summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize; var freezeColLength = this._getFreezeColLength(); BI.each(o.columnSize, function (i, size) { if (o.isNeedFreeze === true && o.freezeCols.contains(i)) { @@ -247,7 +249,7 @@ BI.CollectionTable = BI.inherit(BI.Widget, { var trh = otrh + this._scrollBarSize; var blw = oblw + this._scrollBarSize; var blh = oblh + this._scrollBarSize; - var brw = obrw+ this._scrollBarSize; + var brw = obrw + this._scrollBarSize; var brh = obrh + this._scrollBarSize; var digest = function (el) { @@ -427,8 +429,10 @@ BI.CollectionTable = BI.inherit(BI.Widget, { return; } if (this._isNeedDigest === true) { + this._reRange(); this._digest(); } + this._isNeedDigest = false; this._populateTable(); this._populateScrollbar(); }, @@ -523,6 +527,13 @@ BI.CollectionTable = BI.inherit(BI.Widget, { this.bottomRightCollection.restore(); }, + _reRange: function () { + this.topLeftCollection.reRange(); + this.topRightCollection.reRange(); + this.bottomLeftCollection.reRange(); + this.bottomRightCollection.reRange(); + }, + restore: function () { this._restore(); } diff --git a/src/base/table/table.grid.js b/src/base/table/table.grid.js index 873a581b83..7c745644af 100644 --- a/src/base/table/table.grid.js +++ b/src/base/table/table.grid.js @@ -357,6 +357,10 @@ BI.GridTable = BI.inherit(BI.Widget, { if (this._width <= 0 || this._height <= 0) { return; } + if (this._isNeedDigest === true) { + this._reRange(); + this._isNeedDigest = false; + } this._populateTable(); this._populateScrollbar(); }, @@ -414,10 +418,12 @@ BI.GridTable = BI.inherit(BI.Widget, { setColumnSize: function (columnSize) { this.options.columnSize = columnSize; + this._isNeedDigest = true; }, setRegionColumnSize: function (regionColumnSize) { this.options.regionColumnSize = regionColumnSize; + this._isNeedDigest = true; }, getColumnSize: function () { @@ -430,11 +436,13 @@ BI.GridTable = BI.inherit(BI.Widget, { populate: function (items, header) { if (items && this.options.items !== items) { + this._isNeedDigest = true; this.options.items = items; this.items = this._getItems(); this._restore(); } if (header && this.options.header !== header) { + this._isNeedDigest = true; this.options.header = header; this.header = this._getHeader(); this._restore(); @@ -449,6 +457,13 @@ BI.GridTable = BI.inherit(BI.Widget, { this.bottomRightGrid.restore(); }, + _reRange: function () { + this.topLeftGrid.reRange(); + this.topRightGrid.reRange(); + this.bottomLeftGrid.reRange(); + this.bottomRightGrid.reRange(); + }, + restore: function () { this._restore(); } diff --git a/src/base/table/table.resizable.js b/src/base/table/table.resizable.js index cdc990e02c..1055ef37a7 100644 --- a/src/base/table/table.resizable.js +++ b/src/base/table/table.resizable.js @@ -219,8 +219,10 @@ BI.ResizableTable = BI.inherit(BI.Widget, { }; var stop = function (j, size) { self.resizer.setVisible(false); - o.columnSize[j] = size; - self.table.setColumnSize(o.columnSize); + var columnSize = o.columnSize.slice(); + columnSize[j] = size; + o.columnSize = columnSize; + self.table.setColumnSize(columnSize); self.table.populate(); self._populate(); self.fireEvent(BI.Table.EVENT_TABLE_AFTER_COLUMN_RESIZE); From 34ae74ec2519284dc181a49a27b0a56a4840483a Mon Sep 17 00:00:00 2001 From: guy Date: Thu, 18 May 2017 15:29:35 +0800 Subject: [PATCH 08/10] update --- bi/base.js | 18 ++++++++++++++++-- docs/base.js | 18 ++++++++++++++++-- src/base/collection/collection.js | 9 ++++++++- src/base/grid/grid.js | 9 ++++++++- 4 files changed, 48 insertions(+), 6 deletions(-) diff --git a/bi/base.js b/bi/base.js index ba2bebf1ce..e8dcccdbe4 100644 --- a/bi/base.js +++ b/bi/base.js @@ -2850,10 +2850,16 @@ BI.CollectionView = BI.inherit(BI.Widget, { this.renderRange = {}; }, + _clearChildren: function () { + this.container._children = {}; + this.container.attr("items", []); + }, + restore: function () { BI.each(this.renderedCells, function (i, cell) { - cell.el.destroy(); + cell.el._destroy(); }); + this._clearChildren(); this.renderedCells = []; this.renderedKeys = []; this.renderRange = {}; @@ -2864,6 +2870,7 @@ BI.CollectionView = BI.inherit(BI.Widget, { if (items && items !== this.options.items) { this.options.items = items; this._calculateSizeAndPositionData(); + this.restore(); } this._populate(); } @@ -14953,10 +14960,16 @@ BI.GridView = BI.inherit(BI.Widget, { this.renderRange = {}; }, + _clearChildren: function () { + this.container._children = {}; + this.container.attr("items", []); + }, + restore: function () { BI.each(this.renderedCells, function (i, cell) { - cell.el.destroy(); + cell.el._destroy(); }); + this._clearChildren(); this.renderedCells = []; this.renderedKeys = []; this.renderRange = {}; @@ -14966,6 +14979,7 @@ BI.GridView = BI.inherit(BI.Widget, { populate: function (items) { if (items && items !== this.options.items) { this.options.items = items; + this.restore(); } this._populate(); } diff --git a/docs/base.js b/docs/base.js index ba2bebf1ce..e8dcccdbe4 100644 --- a/docs/base.js +++ b/docs/base.js @@ -2850,10 +2850,16 @@ BI.CollectionView = BI.inherit(BI.Widget, { this.renderRange = {}; }, + _clearChildren: function () { + this.container._children = {}; + this.container.attr("items", []); + }, + restore: function () { BI.each(this.renderedCells, function (i, cell) { - cell.el.destroy(); + cell.el._destroy(); }); + this._clearChildren(); this.renderedCells = []; this.renderedKeys = []; this.renderRange = {}; @@ -2864,6 +2870,7 @@ BI.CollectionView = BI.inherit(BI.Widget, { if (items && items !== this.options.items) { this.options.items = items; this._calculateSizeAndPositionData(); + this.restore(); } this._populate(); } @@ -14953,10 +14960,16 @@ BI.GridView = BI.inherit(BI.Widget, { this.renderRange = {}; }, + _clearChildren: function () { + this.container._children = {}; + this.container.attr("items", []); + }, + restore: function () { BI.each(this.renderedCells, function (i, cell) { - cell.el.destroy(); + cell.el._destroy(); }); + this._clearChildren(); this.renderedCells = []; this.renderedKeys = []; this.renderRange = {}; @@ -14966,6 +14979,7 @@ BI.GridView = BI.inherit(BI.Widget, { populate: function (items) { if (items && items !== this.options.items) { this.options.items = items; + this.restore(); } this._populate(); } diff --git a/src/base/collection/collection.js b/src/base/collection/collection.js index a4ee2e3d35..52acf14348 100644 --- a/src/base/collection/collection.js +++ b/src/base/collection/collection.js @@ -340,10 +340,16 @@ BI.CollectionView = BI.inherit(BI.Widget, { this.renderRange = {}; }, + _clearChildren: function () { + this.container._children = {}; + this.container.attr("items", []); + }, + restore: function () { BI.each(this.renderedCells, function (i, cell) { - cell.el.destroy(); + cell.el._destroy(); }); + this._clearChildren(); this.renderedCells = []; this.renderedKeys = []; this.renderRange = {}; @@ -354,6 +360,7 @@ BI.CollectionView = BI.inherit(BI.Widget, { if (items && items !== this.options.items) { this.options.items = items; this._calculateSizeAndPositionData(); + this.restore(); } this._populate(); } diff --git a/src/base/grid/grid.js b/src/base/grid/grid.js index 98bd8d3b27..4d79401c8a 100644 --- a/src/base/grid/grid.js +++ b/src/base/grid/grid.js @@ -312,10 +312,16 @@ BI.GridView = BI.inherit(BI.Widget, { this.renderRange = {}; }, + _clearChildren: function () { + this.container._children = {}; + this.container.attr("items", []); + }, + restore: function () { BI.each(this.renderedCells, function (i, cell) { - cell.el.destroy(); + cell.el._destroy(); }); + this._clearChildren(); this.renderedCells = []; this.renderedKeys = []; this.renderRange = {}; @@ -325,6 +331,7 @@ BI.GridView = BI.inherit(BI.Widget, { populate: function (items) { if (items && items !== this.options.items) { this.options.items = items; + this.restore(); } this._populate(); } From 407dba164506ebdc009691e10b88e1027df7b24f Mon Sep 17 00:00:00 2001 From: guy Date: Thu, 18 May 2017 16:02:00 +0800 Subject: [PATCH 09/10] =?UTF-8?q?=E6=80=A7=E8=83=BD=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bi/base.js | 34 +++++++++++++++++------------- bi/case.js | 2 +- docs/base.js | 34 +++++++++++++++++------------- docs/case.js | 2 +- src/base/collection/collection.js | 10 +++++---- src/base/grid/grid.js | 8 ++++--- src/base/table/table.collection.js | 8 +++---- src/base/table/table.grid.js | 8 +++---- src/case/table/table.adaptive.js | 2 +- 9 files changed, 60 insertions(+), 48 deletions(-) diff --git a/bi/base.js b/bi/base.js index e8dcccdbe4..005c9fea96 100644 --- a/bi/base.js +++ b/bi/base.js @@ -2775,8 +2775,12 @@ BI.CollectionView = BI.inherit(BI.Widget, { return Math.max(0, this._height - this.options.height + (this.options.overflowY ? BI.DOM.getScrollWidth() : 0)); }, - _populate: function () { + _populate: function (items) { var o = this.options; + if (items && items !== this.options.items) { + this.options.items = items; + this._calculateSizeAndPositionData(); + } if (o.items.length > 0) { this.container.setWidth(this._width); this.container.setHeight(this._height); @@ -2868,11 +2872,9 @@ BI.CollectionView = BI.inherit(BI.Widget, { populate: function (items) { if (items && items !== this.options.items) { - this.options.items = items; - this._calculateSizeAndPositionData(); this.restore(); } - this._populate(); + this._populate(items); } }); BI.CollectionView.EVENT_SCROLL = "EVENT_SCROLL"; @@ -14869,8 +14871,11 @@ BI.GridView = BI.inherit(BI.Widget, { return Math.max(0, this._rowSizeAndPositionManager.getTotalSize() - this.options.height + (this.options.overflowY ? BI.DOM.getScrollWidth() : 0)); }, - _populate: function () { + _populate: function (items) { var self = this, o = this.options; + if (items && items !== this.options.items) { + this.options.items = items; + } if (o.items.length > 0) { this.columnCount = o.items[0].length; this.rowCount = o.items.length; @@ -14978,10 +14983,9 @@ BI.GridView = BI.inherit(BI.Widget, { populate: function (items) { if (items && items !== this.options.items) { - this.options.items = items; this.restore(); } - this._populate(); + this._populate(items); } }); BI.GridView.EVENT_SCROLL = "EVENT_SCROLL"; @@ -28866,10 +28870,10 @@ BI.CollectionTable = BI.inherit(BI.Widget, { run(this.bottomLeftItems, o.items, leftItems); run(this.bottomRightItems, o.items, rightItems); - this.topLeftCollection.populate(leftHeader); - this.topRightCollection.populate(rightHeader); - this.bottomLeftCollection.populate(leftItems); - this.bottomRightCollection.populate(rightItems); + this.topLeftCollection._populate(leftHeader); + this.topRightCollection._populate(rightHeader); + this.bottomLeftCollection._populate(leftItems); + this.bottomRightCollection._populate(rightItems); }, _digest: function () { @@ -29696,10 +29700,10 @@ BI.GridTable = BI.inherit(BI.Widget, { this.contextLayout.attr("items", items); this.contextLayout.resize(); - this.topLeftGrid.populate(this.header[0]); - this.topRightGrid.populate(this.header[1]); - this.bottomLeftGrid.populate(this.items[0]); - this.bottomRightGrid.populate(this.items[1]); + this.topLeftGrid._populate(this.header[0]); + this.topRightGrid._populate(this.header[1]); + this.bottomLeftGrid._populate(this.items[0]); + this.bottomRightGrid._populate(this.items[1]); }, _populate: function () { diff --git a/bi/case.js b/bi/case.js index 697267ae70..2fcf3869ee 100644 --- a/bi/case.js +++ b/bi/case.js @@ -8762,7 +8762,7 @@ BI.AdaptiveTable = BI.inherit(BI.Widget, { freezeCols = []; } if (!BI.isNumber(columnSize[0])) { - columnSize = o.minColumnSize; + columnSize = o.minColumnSize.slice(); } var summaryFreezeColumnSize = 0, summaryColumnSize = 0; BI.each(columnSize, function (i, size) { diff --git a/docs/base.js b/docs/base.js index e8dcccdbe4..005c9fea96 100644 --- a/docs/base.js +++ b/docs/base.js @@ -2775,8 +2775,12 @@ BI.CollectionView = BI.inherit(BI.Widget, { return Math.max(0, this._height - this.options.height + (this.options.overflowY ? BI.DOM.getScrollWidth() : 0)); }, - _populate: function () { + _populate: function (items) { var o = this.options; + if (items && items !== this.options.items) { + this.options.items = items; + this._calculateSizeAndPositionData(); + } if (o.items.length > 0) { this.container.setWidth(this._width); this.container.setHeight(this._height); @@ -2868,11 +2872,9 @@ BI.CollectionView = BI.inherit(BI.Widget, { populate: function (items) { if (items && items !== this.options.items) { - this.options.items = items; - this._calculateSizeAndPositionData(); this.restore(); } - this._populate(); + this._populate(items); } }); BI.CollectionView.EVENT_SCROLL = "EVENT_SCROLL"; @@ -14869,8 +14871,11 @@ BI.GridView = BI.inherit(BI.Widget, { return Math.max(0, this._rowSizeAndPositionManager.getTotalSize() - this.options.height + (this.options.overflowY ? BI.DOM.getScrollWidth() : 0)); }, - _populate: function () { + _populate: function (items) { var self = this, o = this.options; + if (items && items !== this.options.items) { + this.options.items = items; + } if (o.items.length > 0) { this.columnCount = o.items[0].length; this.rowCount = o.items.length; @@ -14978,10 +14983,9 @@ BI.GridView = BI.inherit(BI.Widget, { populate: function (items) { if (items && items !== this.options.items) { - this.options.items = items; this.restore(); } - this._populate(); + this._populate(items); } }); BI.GridView.EVENT_SCROLL = "EVENT_SCROLL"; @@ -28866,10 +28870,10 @@ BI.CollectionTable = BI.inherit(BI.Widget, { run(this.bottomLeftItems, o.items, leftItems); run(this.bottomRightItems, o.items, rightItems); - this.topLeftCollection.populate(leftHeader); - this.topRightCollection.populate(rightHeader); - this.bottomLeftCollection.populate(leftItems); - this.bottomRightCollection.populate(rightItems); + this.topLeftCollection._populate(leftHeader); + this.topRightCollection._populate(rightHeader); + this.bottomLeftCollection._populate(leftItems); + this.bottomRightCollection._populate(rightItems); }, _digest: function () { @@ -29696,10 +29700,10 @@ BI.GridTable = BI.inherit(BI.Widget, { this.contextLayout.attr("items", items); this.contextLayout.resize(); - this.topLeftGrid.populate(this.header[0]); - this.topRightGrid.populate(this.header[1]); - this.bottomLeftGrid.populate(this.items[0]); - this.bottomRightGrid.populate(this.items[1]); + this.topLeftGrid._populate(this.header[0]); + this.topRightGrid._populate(this.header[1]); + this.bottomLeftGrid._populate(this.items[0]); + this.bottomRightGrid._populate(this.items[1]); }, _populate: function () { diff --git a/docs/case.js b/docs/case.js index 697267ae70..2fcf3869ee 100644 --- a/docs/case.js +++ b/docs/case.js @@ -8762,7 +8762,7 @@ BI.AdaptiveTable = BI.inherit(BI.Widget, { freezeCols = []; } if (!BI.isNumber(columnSize[0])) { - columnSize = o.minColumnSize; + columnSize = o.minColumnSize.slice(); } var summaryFreezeColumnSize = 0, summaryColumnSize = 0; BI.each(columnSize, function (i, size) { diff --git a/src/base/collection/collection.js b/src/base/collection/collection.js index 52acf14348..1b03201872 100644 --- a/src/base/collection/collection.js +++ b/src/base/collection/collection.js @@ -265,8 +265,12 @@ BI.CollectionView = BI.inherit(BI.Widget, { return Math.max(0, this._height - this.options.height + (this.options.overflowY ? BI.DOM.getScrollWidth() : 0)); }, - _populate: function () { + _populate: function (items) { var o = this.options; + if (items && items !== this.options.items) { + this.options.items = items; + this._calculateSizeAndPositionData(); + } if (o.items.length > 0) { this.container.setWidth(this._width); this.container.setHeight(this._height); @@ -358,11 +362,9 @@ BI.CollectionView = BI.inherit(BI.Widget, { populate: function (items) { if (items && items !== this.options.items) { - this.options.items = items; - this._calculateSizeAndPositionData(); this.restore(); } - this._populate(); + this._populate(items); } }); BI.CollectionView.EVENT_SCROLL = "EVENT_SCROLL"; diff --git a/src/base/grid/grid.js b/src/base/grid/grid.js index 4d79401c8a..92798e55b8 100644 --- a/src/base/grid/grid.js +++ b/src/base/grid/grid.js @@ -221,8 +221,11 @@ BI.GridView = BI.inherit(BI.Widget, { return Math.max(0, this._rowSizeAndPositionManager.getTotalSize() - this.options.height + (this.options.overflowY ? BI.DOM.getScrollWidth() : 0)); }, - _populate: function () { + _populate: function (items) { var self = this, o = this.options; + if (items && items !== this.options.items) { + this.options.items = items; + } if (o.items.length > 0) { this.columnCount = o.items[0].length; this.rowCount = o.items.length; @@ -330,10 +333,9 @@ BI.GridView = BI.inherit(BI.Widget, { populate: function (items) { if (items && items !== this.options.items) { - this.options.items = items; this.restore(); } - this._populate(); + this._populate(items); } }); BI.GridView.EVENT_SCROLL = "EVENT_SCROLL"; diff --git a/src/base/table/table.collection.js b/src/base/table/table.collection.js index e599bf5c92..dd31c1cc05 100644 --- a/src/base/table/table.collection.js +++ b/src/base/table/table.collection.js @@ -306,10 +306,10 @@ BI.CollectionTable = BI.inherit(BI.Widget, { run(this.bottomLeftItems, o.items, leftItems); run(this.bottomRightItems, o.items, rightItems); - this.topLeftCollection.populate(leftHeader); - this.topRightCollection.populate(rightHeader); - this.bottomLeftCollection.populate(leftItems); - this.bottomRightCollection.populate(rightItems); + this.topLeftCollection._populate(leftHeader); + this.topRightCollection._populate(rightHeader); + this.bottomLeftCollection._populate(leftItems); + this.bottomRightCollection._populate(rightItems); }, _digest: function () { diff --git a/src/base/table/table.grid.js b/src/base/table/table.grid.js index 7c745644af..0746479242 100644 --- a/src/base/table/table.grid.js +++ b/src/base/table/table.grid.js @@ -347,10 +347,10 @@ BI.GridTable = BI.inherit(BI.Widget, { this.contextLayout.attr("items", items); this.contextLayout.resize(); - this.topLeftGrid.populate(this.header[0]); - this.topRightGrid.populate(this.header[1]); - this.bottomLeftGrid.populate(this.items[0]); - this.bottomRightGrid.populate(this.items[1]); + this.topLeftGrid._populate(this.header[0]); + this.topRightGrid._populate(this.header[1]); + this.bottomLeftGrid._populate(this.items[0]); + this.bottomRightGrid._populate(this.items[1]); }, _populate: function () { diff --git a/src/case/table/table.adaptive.js b/src/case/table/table.adaptive.js index 88017193e4..7146b83a76 100644 --- a/src/case/table/table.adaptive.js +++ b/src/case/table/table.adaptive.js @@ -115,7 +115,7 @@ BI.AdaptiveTable = BI.inherit(BI.Widget, { freezeCols = []; } if (!BI.isNumber(columnSize[0])) { - columnSize = o.minColumnSize; + columnSize = o.minColumnSize.slice(); } var summaryFreezeColumnSize = 0, summaryColumnSize = 0; BI.each(columnSize, function (i, size) { From e93655a1c1fc9c7d29b398b039ff3d9c106fd261 Mon Sep 17 00:00:00 2001 From: guy Date: Thu, 18 May 2017 17:12:09 +0800 Subject: [PATCH 10/10] add --- bi/widget.js | 462 +++++++++--------- docs/widget.js | 462 +++++++++--------- src/widget/multistringlist/multistringlist.js | 228 +++++---- src/widget/multitreelist/multitreelist.js | 214 ++++---- .../multitreelist/multitreelist.popup.js | 20 +- 5 files changed, 714 insertions(+), 672 deletions(-) diff --git a/bi/widget.js b/bi/widget.js index 9ec134e1a4..903504541b 100644 --- a/bi/widget.js +++ b/bi/widget.js @@ -10955,7 +10955,7 @@ BI.MultiSelectCheckSelectedSwitcher = BI.inherit(BI.Widget, { BI.MultiSelectCheckSelectedSwitcher.EVENT_TRIGGER_CHANGE = "MultiSelectCheckSelectedSwitcher.EVENT_TRIGGER_CHANGE"; BI.MultiSelectCheckSelectedSwitcher.EVENT_BEFORE_POPUPVIEW = "MultiSelectCheckSelectedSwitcher.EVENT_BEFORE_POPUPVIEW"; BI.shortcut('bi.multi_select_check_selected_switcher', BI.MultiSelectCheckSelectedSwitcher);/** - * Created by zcf on 2016/12/14. + * Created by zcf_1 on 2017/5/2. */ BI.MultiStringList = BI.inherit(BI.Widget, { _defaultConfig: function () { @@ -10963,33 +10963,30 @@ BI.MultiStringList = BI.inherit(BI.Widget, { baseCls: 'bi-multi-string-list', itemsCreator: BI.emptyFn, valueFormatter: BI.emptyFn, - height: 25 + el: {} }) }, _init: function () { BI.MultiStringList.superclass._init.apply(this, arguments); var self = this, o = this.options; + this.storeValue = {}; var assertShowValue = function () { BI.isKey(self._startValue) && self.storeValue.value[self.storeValue.type === BI.Selection.All ? "remove" : "pushDistinct"](self._startValue); - self.trigger.getSearcher().setState(self.storeValue); - self.trigger.getCounter().setButtonChecked(self.storeValue); }; - this.storeValue = {}; - - this.popup = BI.createWidget({ + this.adapter = BI.createWidget({ type: "bi.multi_select_loader", cls: "popup-multi-string-list bi-border-left bi-border-right bi-border-bottom", itemsCreator: o.itemsCreator, valueFormatter: o.valueFormatter, - onLoaded: o.onLoaded, + // onLoaded: o.onLoaded, el: { height: "" } }); - this.popup.on(BI.MultiSelectLoader.EVENT_CHANGE, function () { + this.adapter.on(BI.MultiSelectLoader.EVENT_CHANGE, function () { self.storeValue = this.getValue(); self._adjust(function () { assertShowValue(); @@ -10997,90 +10994,105 @@ BI.MultiStringList = BI.inherit(BI.Widget, { }); }); - this.trigger = BI.createWidget({ - type: "bi.multi_select_trigger", - height: o.height, - adapter: this.popup, - masker: { - offset: { - left: 1, - top: 0, - right: 2, - bottom: 1 - } - }, + this.searcherPane = BI.createWidget({ + type: "bi.multi_select_search_pane", + cls: "bi-border-left bi-border-right bi-border-bottom", valueFormatter: o.valueFormatter, + keywordGetter: function () { + return self.trigger.getKeyword(); + }, itemsCreator: function (op, callback) { - o.itemsCreator(op, function (res) { - if (op.times === 1 && BI.isNotNull(op.keyword)) { - self.trigger.setValue(self.getValue()); - } - callback.apply(self, arguments); - }); + op.keyword = self.trigger.getKeyword(); + this.setKeyword(op.keyword); + o.itemsCreator(op, callback); } }); + this.searcherPane.setVisible(false); - this.trigger.on(BI.MultiSelectTrigger.EVENT_START, function () { - self._setStartValue(""); - this.getSearcher().setValue(self.storeValue); - }); - this.trigger.on(BI.MultiSelectTrigger.EVENT_STOP, function () { - self._setStartValue(""); - }); - this.trigger.on(BI.MultiSelectTrigger.EVENT_PAUSE, function () { - if (this.getSearcher().hasMatched()) { - var keyword = this.getSearcher().getKeyword(); - self._join({ - type: BI.Selection.Multi, - value: [keyword] - }, function () { - self.trigger.setValue(self.storeValue); - self.popup.setValue(self.storeValue); - self._setStartValue(keyword); - assertShowValue(); - self.populate(); + this.trigger = BI.createWidget({ + type: "bi.searcher", + isAutoSearch: false, + isAutoSync: false, + onSearch: function (op, callback) { + callback(); + }, + adapter: this.adapter, + popup: this.searcherPane, + height: 200, + masker: false, + listeners: [{ + eventName: BI.Searcher.EVENT_START, + action: function () { + self._showSearcherPane(); self._setStartValue(""); - self.fireEvent(BI.MultiStringList.EVENT_CHANGE); - }) - } - }); - this.trigger.on(BI.MultiSelectTrigger.EVENT_SEARCHING, function (keywords) { - var last = BI.last(keywords); - keywords = BI.initial(keywords || []); - if (keywords.length > 0) { - self._joinKeywords(keywords, function () { - if (BI.isEndWithBlank(last)) { - self.trigger.setValue(self.storeValue); - self.popup.setValue(self.storeValue); - assertShowValue(); - self.popup.populate(); - self._setStartValue(""); + this.setValue(self.storeValue); + } + }, { + eventName: BI.Searcher.EVENT_STOP, + action: function () { + self._showAdapter(); + self._setStartValue(""); + self.adapter.setValue(self.storeValue); + } + }, { + eventName: BI.Searcher.EVENT_PAUSE, + action: function () { + if (this.hasMatched()) { + var keyword = this.getKeyword(); + self._join({ + type: BI.Selection.Multi, + value: [keyword] + }, function () { + self._showAdapter(); + self.trigger.setValue(self.storeValue); + self.adapter.setValue(self.storeValue); + self._setStartValue(keyword); + assertShowValue(); + self._setStartValue(""); + self.fireEvent(BI.MultiStringList.EVENT_CHANGE); + }) } else { - self.trigger.setValue(self.storeValue); - self.popup.setValue(self.storeValue); - assertShowValue(); + self._showAdapter(); } - }); - } + } + }, { + eventName: BI.Searcher.EVENT_SEARCHING, + action: function () { + var keywords = this.getKeyword(); + var last = BI.last(keywords); + keywords = BI.initial(keywords || []); + if (keywords.length > 0) { + self._joinKeywords(keywords, function () { + if (BI.isEndWithBlank(last)) { + self.trigger.setValue(self.storeValue); + self.adapter.setValue(self.storeValue); + assertShowValue(); + self.adapter.populate(); + self._setStartValue(""); + } else { + self.trigger.setValue(self.storeValue); + self.adapter.setValue(self.storeValue); + assertShowValue(); + } + }); + } + } + }, { + eventName: BI.Searcher.EVENT_CHANGE, + action: function (value, obj) { + if (obj instanceof BI.MultiSelectBar) { + self._joinAll(this.getValue(), function () { + assertShowValue(); + }); + } else { + self._join(this.getValue(), function () {//安徽省 北京 + assertShowValue(); + }); + } + } + }] }); - this.trigger.on(BI.MultiSelectTrigger.EVENT_CHANGE, function (value, obj) { - if (obj instanceof BI.MultiSelectBar) { - self._joinAll(this.getValue(), function () { - assertShowValue(); - }); - } else { - self._join(this.getValue(), function () {//安徽省 北京 - assertShowValue(); - }); - } - }); - this.trigger.on(BI.MultiSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW, function () { - this.getCounter().setValue(self.storeValue); - }); - var div = BI.createWidget({ - type: "bi.layout" - }); BI.createWidget({ type: "bi.vtape", element: this, @@ -11088,16 +11100,37 @@ BI.MultiStringList = BI.inherit(BI.Widget, { width: "100%", items: [{ el: this.trigger, - height: 25 - }, { - el: div, - height: 2 + height: 30 }, { - el: this.popup, + el: this.adapter, height: "fill" }] }); + BI.createWidget({ + type: "bi.absolute", + element: this, + height: "100%", + width: "100%", + items: [{ + el: this.searcherPane, + top: 30, + bottom: 0, + left: 0, + right: 0 + }] + }) + }, + + _showAdapter: function () { + this.adapter.setVisible(true); + this.searcherPane.setVisible(false); }, + + _showSearcherPane: function () { + this.searcherPane.setVisible(true); + this.adapter.setVisible(false); + }, + _defaultState: function () { this.trigger.stopEditing(); }, @@ -11142,7 +11175,7 @@ BI.MultiStringList = BI.inherit(BI.Widget, { this._assertValue(res); o.itemsCreator({ type: BI.MultiStringList.REQ_GET_ALL_DATA, - keyword: this.trigger.getKey() + keyword: self.trigger.getKeyword() }, function (ob) { var items = BI.pluck(ob.items, "value"); if (self.storeValue.type === res.type) { @@ -11231,22 +11264,21 @@ BI.MultiStringList = BI.inherit(BI.Widget, { _setStartValue: function (value) { this._startValue = value; - this.popup.setStartValue(value); + this.adapter.setStartValue(value); }, - // isAllSelected: function () { - // return this.popup.isAllSelected(); - // }, + isAllSelected: function () { + return this.adapter.isAllSelected(); + }, resize: function () { - this.trigger.getCounter().adjustView(); - this.trigger.getSearcher().adjustView(); + // this.trigger.getCounter().adjustView(); + // this.trigger.adjustView(); }, - setValue: function (v) { this.storeValue = v || {}; this._assertValue(this.storeValue); - this.popup.setValue(this.storeValue); + this.adapter.setValue(this.storeValue); this.trigger.setValue(this.storeValue); }, @@ -11257,7 +11289,7 @@ BI.MultiStringList = BI.inherit(BI.Widget, { populate: function () { this._count = null; this._allData = null; - this.popup.populate.apply(this.popup, arguments); + this.adapter.populate.apply(this.adapter, arguments); this.trigger.populate.apply(this.trigger, arguments); } }); @@ -12008,130 +12040,96 @@ BI.MultiTreeSearcher.EVENT_START = "EVENT_START"; BI.MultiTreeSearcher.EVENT_STOP = "EVENT_STOP"; BI.MultiTreeSearcher.EVENT_PAUSE = "EVENT_PAUSE"; BI.shortcut('bi.multi_tree_searcher', BI.MultiTreeSearcher);/** - * Created by zcf on 2016/12/20. + * Created by zcf_1 on 2017/5/11. */ -BI.MultiTreeList = BI.inherit(BI.Widget, { - constants: { - offset: { - left: 1, - top: 0, - right: 2, - bottom: 1 - } - }, - +BI.MultiSelectTree = BI.inherit(BI.Widget, { _defaultConfig: function () { - return BI.extend(BI.MultiTreeList.superclass._defaultConfig.apply(this, arguments), { + return BI.extend(BI.MultiSelectTree.superclass._defaultConfig.apply(this, arguments), { baseCls: 'bi-multi-tree-combo', itemsCreator: BI.emptyFn, height: 25 - }); + }) }, _init: function () { - BI.MultiTreeList.superclass._init.apply(this, arguments); - + BI.MultiSelectTree.superclass._init.apply(this, arguments); var self = this, o = this.options; + this.storeValue = {value: {}}; - var isInit = false; - var want2showCounter = false; - - this.popup = BI.createWidget({ - type: "bi.multi_tree_list_popup", + this.adapter = BI.createWidget({ + type: "bi.multi_select_tree_popup", itemsCreator: o.itemsCreator }); - - this.popup.on(BI.MultiStringListPopup.EVENT_AFTER_INIT, function () { - self.trigger.getCounter().adjustView(); - isInit = true; - if (want2showCounter === true) { - showCounter(); + this.adapter.on(BI.MultiSelectTreePopup.EVENT_CHANGE, function () { + if (self.trigger.isSearching()) { + self.storeValue = {value: self.searcherPane.getValue()}; + } else { + self.storeValue = {value: self.adapter.getValue()}; } + self.fireEvent(BI.MultiSelectTree.EVENT_CHANGE); }); - this.trigger = BI.createWidget({ - type: "bi.multi_select_trigger", - height: o.height, - adapter: this.popup, - masker: { - offset: this.constants.offset + this.searcherPane = BI.createWidget({//搜索中的时候用的是parttree,同adapter中的synctree不一样 + type: "bi.multi_tree_search_pane", + cls: "bi-border-left bi-border-right bi-border-bottom", + keywordGetter: function () { + return self.trigger.getKeyword(); }, - searcher: { - type: "bi.multi_tree_searcher", - itemsCreator: o.itemsCreator - }, - switcher: { - el: { - type: "bi.multi_tree_check_selected_button" - }, - popup: { - type: "bi.multi_tree_check_pane", - itemsCreator: o.itemsCreator - } - } - }); - - this.storeValue = {value: {}}; - - var isSearching = function () { - return self.trigger.getSearcher().isSearching(); - }; - - this.trigger.on(BI.MultiSelectTrigger.EVENT_START, function () { - self.storeValue = {value: self.popup.getValue()}; - this.setValue(self.storeValue); - }); - this.trigger.on(BI.MultiSelectTrigger.EVENT_STOP, function () { - self.storeValue = {value: this.getValue()}; - self.trigger.setValue(self.storeValue); - self.popup.setValue(self.storeValue); - BI.nextTick(function () { - self.trigger.populate(); - self.popup.populate(); - }); - }); - function showCounter() { - if (isSearching()) { - self.storeValue = {value: self.trigger.getValue()}; - } else { - self.storeValue = {value: self.popup.getValue()}; - } - self.trigger.setValue(self.storeValue); - } - - this.trigger.on(BI.MultiSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW, function () { - if (want2showCounter === false) { - want2showCounter = true; - } - if (isInit === true) { - want2showCounter = null; - showCounter(); + itemsCreator: function (op, callback) { + op.keyword = self.trigger.getKeyword(); + o.itemsCreator(op, callback); } }); + this.searcherPane.setVisible(false); - this.trigger.on(BI.MultiSelectTrigger.EVENT_CHANGE, function () { - var val = { - type: BI.Selection.Multi, - value: this.getSearcher().hasChecked() ? {1: 1} : {} - }; - this.getSearcher().setState(val); - this.getCounter().setButtonChecked(val); - }); - - this.popup.on(BI.MultiStringListPopup.EVENT_CHANGE, function () { - showCounter(); - var val = { - type: BI.Selection.Multi, - value: this.hasChecked() ? {1: 1} : {} - }; - self.trigger.getSearcher().setState(val); - self.trigger.getCounter().setButtonChecked(val); - self.fireEvent(BI.MultiTreeList.EVENT_CHANGE); + this.trigger = BI.createWidget({ + type: "bi.searcher", + isAutoSearch: false, + isAutoSync: false, + onSearch: function (op, callback) { + callback({ + keyword: self.trigger.getKeyword() + }); + }, + adapter: this.adapter, + popup: this.searcherPane, + height: 200, + masker: false, + listeners: [{ + eventName: BI.Searcher.EVENT_START, + action: function () { + self._showSearcherPane(); + self.storeValue = {value: self.adapter.getValue()}; + self.searcherPane.setValue(self.storeValue); + } + }, { + eventName: BI.Searcher.EVENT_STOP, + action: function () { + self._showAdapter(); + // self.storeValue = {value: self.searcherPane.getValue()}; + self.adapter.setValue(self.storeValue); + BI.nextTick(function () { + self.adapter.populate(); + }); + } + }, { + eventName: BI.Searcher.EVENT_CHANGE, + action: function () { + if (self.trigger.isSearching()) { + self.storeValue = {value: self.searcherPane.getValue()}; + } else { + self.storeValue = {value: self.adapter.getValue()}; + } + self.fireEvent(BI.MultiSelectTree.EVENT_CHANGE); + } + }, { + eventName: BI.Searcher.EVENT_PAUSE, + action: function () { + self._showAdapter(); + } + }] }); - var div = BI.createWidget({ - type: "bi.layout" - }); BI.createWidget({ type: "bi.vtape", element: this, @@ -12139,29 +12137,45 @@ BI.MultiTreeList = BI.inherit(BI.Widget, { width: "100%", items: [{ el: this.trigger, - height: 25 - }, { - el: div, - height: 2 + height: 30 }, { - el: this.popup, + el: this.adapter, height: "fill" }] + }); + BI.createWidget({ + type: "bi.absolute", + element: this, + height: "100%", + width: "100%", + items: [{ + el: this.searcherPane, + top: 30, + bottom: 0, + left: 0, + right: 0 + }] }) + }, - _defaultState: function () { - this.trigger.stopEditing(); + _showAdapter: function () { + this.adapter.setVisible(true); + this.searcherPane.setVisible(false); + }, + + _showSearcherPane: function () { + this.searcherPane.setVisible(true); + this.adapter.setVisible(false); }, resize: function () { - this.trigger.getCounter().adjustView(); - this.trigger.getSearcher().adjustView(); + }, setValue: function (v) { this.storeValue.value = v || {}; - this.popup.setValue({ + this.adapter.setValue({ value: v || {} }); this.trigger.setValue({ @@ -12175,22 +12189,22 @@ BI.MultiTreeList = BI.inherit(BI.Widget, { populate: function () { this.trigger.populate.apply(this.trigger, arguments); - this.popup.populate.apply(this.popup, arguments); + this.adapter.populate.apply(this.adapter, arguments); } }); -BI.MultiTreeList.EVENT_CHANGE = "MultiTreeList.EVENT_CHANGE"; -BI.shortcut('bi.multi_tree_list', BI.MultiTreeList);/** +BI.MultiSelectTree.EVENT_CHANGE = "BI.MultiSelectTree.EVENT_CHANGE"; +BI.shortcut("bi.multi_select_tree", BI.MultiSelectTree);/** * Created by zcf on 2016/12/21. */ -BI.MultiStringListPopup=BI.inherit(BI.Widget,{ - _defaultConfig:function () { - return BI.extend(BI.MultiStringListPopup.superclass._defaultConfig.apply(this, arguments), { +BI.MultiSelectTreePopup = BI.inherit(BI.Widget, { + _defaultConfig: function () { + return BI.extend(BI.MultiSelectTreePopup.superclass._defaultConfig.apply(this, arguments), { baseCls: "bi-tree-list-popup bi-border-left bi-border-right bi-border-bottom", itemsCreator: BI.emptyFn }); }, - _init:function () { - BI.MultiStringListPopup.superclass._init.apply(this, arguments); + _init: function () { + BI.MultiSelectTreePopup.superclass._init.apply(this, arguments); var self = this, o = this.options; this.popup = BI.createWidget({ type: "bi.sync_tree", @@ -12199,10 +12213,10 @@ BI.MultiStringListPopup=BI.inherit(BI.Widget,{ itemsCreator: o.itemsCreator }); this.popup.on(BI.TreeView.EVENT_AFTERINIT, function () { - self.fireEvent(BI.MultiStringListPopup.EVENT_AFTER_INIT) + self.fireEvent(BI.MultiSelectTreePopup.EVENT_AFTER_INIT) }); this.popup.on(BI.TreeView.EVENT_CHANGE, function () { - self.fireEvent(BI.MultiStringListPopup.EVENT_CHANGE) + self.fireEvent(BI.MultiSelectTreePopup.EVENT_CHANGE) }); }, @@ -12224,9 +12238,9 @@ BI.MultiStringListPopup=BI.inherit(BI.Widget,{ } }); -BI.MultiStringListPopup.EVENT_AFTER_INIT="BI.MultiStringListPopup.EVENT_AFTER_INIT"; -BI.MultiStringListPopup.EVENT_CHANGE="BI.MultiStringListPopup.EVENT_CHANGE"; -BI.shortcut("bi.multi_tree_list_popup",BI.MultiStringListPopup);//小于号的值为:0,小于等于号的值为:1 +BI.MultiSelectTreePopup.EVENT_AFTER_INIT = "BI.MultiSelectTreePopup.EVENT_AFTER_INIT"; +BI.MultiSelectTreePopup.EVENT_CHANGE = "BI.MultiSelectTreePopup.EVENT_CHANGE"; +BI.shortcut("bi.multi_select_tree_popup", BI.MultiSelectTreePopup);//小于号的值为:0,小于等于号的值为:1 //closeMIn:最小值的符号,closeMax:最大值的符号 /** * Created by roy on 15/9/17. diff --git a/docs/widget.js b/docs/widget.js index 9ec134e1a4..903504541b 100644 --- a/docs/widget.js +++ b/docs/widget.js @@ -10955,7 +10955,7 @@ BI.MultiSelectCheckSelectedSwitcher = BI.inherit(BI.Widget, { BI.MultiSelectCheckSelectedSwitcher.EVENT_TRIGGER_CHANGE = "MultiSelectCheckSelectedSwitcher.EVENT_TRIGGER_CHANGE"; BI.MultiSelectCheckSelectedSwitcher.EVENT_BEFORE_POPUPVIEW = "MultiSelectCheckSelectedSwitcher.EVENT_BEFORE_POPUPVIEW"; BI.shortcut('bi.multi_select_check_selected_switcher', BI.MultiSelectCheckSelectedSwitcher);/** - * Created by zcf on 2016/12/14. + * Created by zcf_1 on 2017/5/2. */ BI.MultiStringList = BI.inherit(BI.Widget, { _defaultConfig: function () { @@ -10963,33 +10963,30 @@ BI.MultiStringList = BI.inherit(BI.Widget, { baseCls: 'bi-multi-string-list', itemsCreator: BI.emptyFn, valueFormatter: BI.emptyFn, - height: 25 + el: {} }) }, _init: function () { BI.MultiStringList.superclass._init.apply(this, arguments); var self = this, o = this.options; + this.storeValue = {}; var assertShowValue = function () { BI.isKey(self._startValue) && self.storeValue.value[self.storeValue.type === BI.Selection.All ? "remove" : "pushDistinct"](self._startValue); - self.trigger.getSearcher().setState(self.storeValue); - self.trigger.getCounter().setButtonChecked(self.storeValue); }; - this.storeValue = {}; - - this.popup = BI.createWidget({ + this.adapter = BI.createWidget({ type: "bi.multi_select_loader", cls: "popup-multi-string-list bi-border-left bi-border-right bi-border-bottom", itemsCreator: o.itemsCreator, valueFormatter: o.valueFormatter, - onLoaded: o.onLoaded, + // onLoaded: o.onLoaded, el: { height: "" } }); - this.popup.on(BI.MultiSelectLoader.EVENT_CHANGE, function () { + this.adapter.on(BI.MultiSelectLoader.EVENT_CHANGE, function () { self.storeValue = this.getValue(); self._adjust(function () { assertShowValue(); @@ -10997,90 +10994,105 @@ BI.MultiStringList = BI.inherit(BI.Widget, { }); }); - this.trigger = BI.createWidget({ - type: "bi.multi_select_trigger", - height: o.height, - adapter: this.popup, - masker: { - offset: { - left: 1, - top: 0, - right: 2, - bottom: 1 - } - }, + this.searcherPane = BI.createWidget({ + type: "bi.multi_select_search_pane", + cls: "bi-border-left bi-border-right bi-border-bottom", valueFormatter: o.valueFormatter, + keywordGetter: function () { + return self.trigger.getKeyword(); + }, itemsCreator: function (op, callback) { - o.itemsCreator(op, function (res) { - if (op.times === 1 && BI.isNotNull(op.keyword)) { - self.trigger.setValue(self.getValue()); - } - callback.apply(self, arguments); - }); + op.keyword = self.trigger.getKeyword(); + this.setKeyword(op.keyword); + o.itemsCreator(op, callback); } }); + this.searcherPane.setVisible(false); - this.trigger.on(BI.MultiSelectTrigger.EVENT_START, function () { - self._setStartValue(""); - this.getSearcher().setValue(self.storeValue); - }); - this.trigger.on(BI.MultiSelectTrigger.EVENT_STOP, function () { - self._setStartValue(""); - }); - this.trigger.on(BI.MultiSelectTrigger.EVENT_PAUSE, function () { - if (this.getSearcher().hasMatched()) { - var keyword = this.getSearcher().getKeyword(); - self._join({ - type: BI.Selection.Multi, - value: [keyword] - }, function () { - self.trigger.setValue(self.storeValue); - self.popup.setValue(self.storeValue); - self._setStartValue(keyword); - assertShowValue(); - self.populate(); + this.trigger = BI.createWidget({ + type: "bi.searcher", + isAutoSearch: false, + isAutoSync: false, + onSearch: function (op, callback) { + callback(); + }, + adapter: this.adapter, + popup: this.searcherPane, + height: 200, + masker: false, + listeners: [{ + eventName: BI.Searcher.EVENT_START, + action: function () { + self._showSearcherPane(); self._setStartValue(""); - self.fireEvent(BI.MultiStringList.EVENT_CHANGE); - }) - } - }); - this.trigger.on(BI.MultiSelectTrigger.EVENT_SEARCHING, function (keywords) { - var last = BI.last(keywords); - keywords = BI.initial(keywords || []); - if (keywords.length > 0) { - self._joinKeywords(keywords, function () { - if (BI.isEndWithBlank(last)) { - self.trigger.setValue(self.storeValue); - self.popup.setValue(self.storeValue); - assertShowValue(); - self.popup.populate(); - self._setStartValue(""); + this.setValue(self.storeValue); + } + }, { + eventName: BI.Searcher.EVENT_STOP, + action: function () { + self._showAdapter(); + self._setStartValue(""); + self.adapter.setValue(self.storeValue); + } + }, { + eventName: BI.Searcher.EVENT_PAUSE, + action: function () { + if (this.hasMatched()) { + var keyword = this.getKeyword(); + self._join({ + type: BI.Selection.Multi, + value: [keyword] + }, function () { + self._showAdapter(); + self.trigger.setValue(self.storeValue); + self.adapter.setValue(self.storeValue); + self._setStartValue(keyword); + assertShowValue(); + self._setStartValue(""); + self.fireEvent(BI.MultiStringList.EVENT_CHANGE); + }) } else { - self.trigger.setValue(self.storeValue); - self.popup.setValue(self.storeValue); - assertShowValue(); + self._showAdapter(); } - }); - } + } + }, { + eventName: BI.Searcher.EVENT_SEARCHING, + action: function () { + var keywords = this.getKeyword(); + var last = BI.last(keywords); + keywords = BI.initial(keywords || []); + if (keywords.length > 0) { + self._joinKeywords(keywords, function () { + if (BI.isEndWithBlank(last)) { + self.trigger.setValue(self.storeValue); + self.adapter.setValue(self.storeValue); + assertShowValue(); + self.adapter.populate(); + self._setStartValue(""); + } else { + self.trigger.setValue(self.storeValue); + self.adapter.setValue(self.storeValue); + assertShowValue(); + } + }); + } + } + }, { + eventName: BI.Searcher.EVENT_CHANGE, + action: function (value, obj) { + if (obj instanceof BI.MultiSelectBar) { + self._joinAll(this.getValue(), function () { + assertShowValue(); + }); + } else { + self._join(this.getValue(), function () {//安徽省 北京 + assertShowValue(); + }); + } + } + }] }); - this.trigger.on(BI.MultiSelectTrigger.EVENT_CHANGE, function (value, obj) { - if (obj instanceof BI.MultiSelectBar) { - self._joinAll(this.getValue(), function () { - assertShowValue(); - }); - } else { - self._join(this.getValue(), function () {//安徽省 北京 - assertShowValue(); - }); - } - }); - this.trigger.on(BI.MultiSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW, function () { - this.getCounter().setValue(self.storeValue); - }); - var div = BI.createWidget({ - type: "bi.layout" - }); BI.createWidget({ type: "bi.vtape", element: this, @@ -11088,16 +11100,37 @@ BI.MultiStringList = BI.inherit(BI.Widget, { width: "100%", items: [{ el: this.trigger, - height: 25 - }, { - el: div, - height: 2 + height: 30 }, { - el: this.popup, + el: this.adapter, height: "fill" }] }); + BI.createWidget({ + type: "bi.absolute", + element: this, + height: "100%", + width: "100%", + items: [{ + el: this.searcherPane, + top: 30, + bottom: 0, + left: 0, + right: 0 + }] + }) + }, + + _showAdapter: function () { + this.adapter.setVisible(true); + this.searcherPane.setVisible(false); }, + + _showSearcherPane: function () { + this.searcherPane.setVisible(true); + this.adapter.setVisible(false); + }, + _defaultState: function () { this.trigger.stopEditing(); }, @@ -11142,7 +11175,7 @@ BI.MultiStringList = BI.inherit(BI.Widget, { this._assertValue(res); o.itemsCreator({ type: BI.MultiStringList.REQ_GET_ALL_DATA, - keyword: this.trigger.getKey() + keyword: self.trigger.getKeyword() }, function (ob) { var items = BI.pluck(ob.items, "value"); if (self.storeValue.type === res.type) { @@ -11231,22 +11264,21 @@ BI.MultiStringList = BI.inherit(BI.Widget, { _setStartValue: function (value) { this._startValue = value; - this.popup.setStartValue(value); + this.adapter.setStartValue(value); }, - // isAllSelected: function () { - // return this.popup.isAllSelected(); - // }, + isAllSelected: function () { + return this.adapter.isAllSelected(); + }, resize: function () { - this.trigger.getCounter().adjustView(); - this.trigger.getSearcher().adjustView(); + // this.trigger.getCounter().adjustView(); + // this.trigger.adjustView(); }, - setValue: function (v) { this.storeValue = v || {}; this._assertValue(this.storeValue); - this.popup.setValue(this.storeValue); + this.adapter.setValue(this.storeValue); this.trigger.setValue(this.storeValue); }, @@ -11257,7 +11289,7 @@ BI.MultiStringList = BI.inherit(BI.Widget, { populate: function () { this._count = null; this._allData = null; - this.popup.populate.apply(this.popup, arguments); + this.adapter.populate.apply(this.adapter, arguments); this.trigger.populate.apply(this.trigger, arguments); } }); @@ -12008,130 +12040,96 @@ BI.MultiTreeSearcher.EVENT_START = "EVENT_START"; BI.MultiTreeSearcher.EVENT_STOP = "EVENT_STOP"; BI.MultiTreeSearcher.EVENT_PAUSE = "EVENT_PAUSE"; BI.shortcut('bi.multi_tree_searcher', BI.MultiTreeSearcher);/** - * Created by zcf on 2016/12/20. + * Created by zcf_1 on 2017/5/11. */ -BI.MultiTreeList = BI.inherit(BI.Widget, { - constants: { - offset: { - left: 1, - top: 0, - right: 2, - bottom: 1 - } - }, - +BI.MultiSelectTree = BI.inherit(BI.Widget, { _defaultConfig: function () { - return BI.extend(BI.MultiTreeList.superclass._defaultConfig.apply(this, arguments), { + return BI.extend(BI.MultiSelectTree.superclass._defaultConfig.apply(this, arguments), { baseCls: 'bi-multi-tree-combo', itemsCreator: BI.emptyFn, height: 25 - }); + }) }, _init: function () { - BI.MultiTreeList.superclass._init.apply(this, arguments); - + BI.MultiSelectTree.superclass._init.apply(this, arguments); var self = this, o = this.options; + this.storeValue = {value: {}}; - var isInit = false; - var want2showCounter = false; - - this.popup = BI.createWidget({ - type: "bi.multi_tree_list_popup", + this.adapter = BI.createWidget({ + type: "bi.multi_select_tree_popup", itemsCreator: o.itemsCreator }); - - this.popup.on(BI.MultiStringListPopup.EVENT_AFTER_INIT, function () { - self.trigger.getCounter().adjustView(); - isInit = true; - if (want2showCounter === true) { - showCounter(); + this.adapter.on(BI.MultiSelectTreePopup.EVENT_CHANGE, function () { + if (self.trigger.isSearching()) { + self.storeValue = {value: self.searcherPane.getValue()}; + } else { + self.storeValue = {value: self.adapter.getValue()}; } + self.fireEvent(BI.MultiSelectTree.EVENT_CHANGE); }); - this.trigger = BI.createWidget({ - type: "bi.multi_select_trigger", - height: o.height, - adapter: this.popup, - masker: { - offset: this.constants.offset + this.searcherPane = BI.createWidget({//搜索中的时候用的是parttree,同adapter中的synctree不一样 + type: "bi.multi_tree_search_pane", + cls: "bi-border-left bi-border-right bi-border-bottom", + keywordGetter: function () { + return self.trigger.getKeyword(); }, - searcher: { - type: "bi.multi_tree_searcher", - itemsCreator: o.itemsCreator - }, - switcher: { - el: { - type: "bi.multi_tree_check_selected_button" - }, - popup: { - type: "bi.multi_tree_check_pane", - itemsCreator: o.itemsCreator - } - } - }); - - this.storeValue = {value: {}}; - - var isSearching = function () { - return self.trigger.getSearcher().isSearching(); - }; - - this.trigger.on(BI.MultiSelectTrigger.EVENT_START, function () { - self.storeValue = {value: self.popup.getValue()}; - this.setValue(self.storeValue); - }); - this.trigger.on(BI.MultiSelectTrigger.EVENT_STOP, function () { - self.storeValue = {value: this.getValue()}; - self.trigger.setValue(self.storeValue); - self.popup.setValue(self.storeValue); - BI.nextTick(function () { - self.trigger.populate(); - self.popup.populate(); - }); - }); - function showCounter() { - if (isSearching()) { - self.storeValue = {value: self.trigger.getValue()}; - } else { - self.storeValue = {value: self.popup.getValue()}; - } - self.trigger.setValue(self.storeValue); - } - - this.trigger.on(BI.MultiSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW, function () { - if (want2showCounter === false) { - want2showCounter = true; - } - if (isInit === true) { - want2showCounter = null; - showCounter(); + itemsCreator: function (op, callback) { + op.keyword = self.trigger.getKeyword(); + o.itemsCreator(op, callback); } }); + this.searcherPane.setVisible(false); - this.trigger.on(BI.MultiSelectTrigger.EVENT_CHANGE, function () { - var val = { - type: BI.Selection.Multi, - value: this.getSearcher().hasChecked() ? {1: 1} : {} - }; - this.getSearcher().setState(val); - this.getCounter().setButtonChecked(val); - }); - - this.popup.on(BI.MultiStringListPopup.EVENT_CHANGE, function () { - showCounter(); - var val = { - type: BI.Selection.Multi, - value: this.hasChecked() ? {1: 1} : {} - }; - self.trigger.getSearcher().setState(val); - self.trigger.getCounter().setButtonChecked(val); - self.fireEvent(BI.MultiTreeList.EVENT_CHANGE); + this.trigger = BI.createWidget({ + type: "bi.searcher", + isAutoSearch: false, + isAutoSync: false, + onSearch: function (op, callback) { + callback({ + keyword: self.trigger.getKeyword() + }); + }, + adapter: this.adapter, + popup: this.searcherPane, + height: 200, + masker: false, + listeners: [{ + eventName: BI.Searcher.EVENT_START, + action: function () { + self._showSearcherPane(); + self.storeValue = {value: self.adapter.getValue()}; + self.searcherPane.setValue(self.storeValue); + } + }, { + eventName: BI.Searcher.EVENT_STOP, + action: function () { + self._showAdapter(); + // self.storeValue = {value: self.searcherPane.getValue()}; + self.adapter.setValue(self.storeValue); + BI.nextTick(function () { + self.adapter.populate(); + }); + } + }, { + eventName: BI.Searcher.EVENT_CHANGE, + action: function () { + if (self.trigger.isSearching()) { + self.storeValue = {value: self.searcherPane.getValue()}; + } else { + self.storeValue = {value: self.adapter.getValue()}; + } + self.fireEvent(BI.MultiSelectTree.EVENT_CHANGE); + } + }, { + eventName: BI.Searcher.EVENT_PAUSE, + action: function () { + self._showAdapter(); + } + }] }); - var div = BI.createWidget({ - type: "bi.layout" - }); BI.createWidget({ type: "bi.vtape", element: this, @@ -12139,29 +12137,45 @@ BI.MultiTreeList = BI.inherit(BI.Widget, { width: "100%", items: [{ el: this.trigger, - height: 25 - }, { - el: div, - height: 2 + height: 30 }, { - el: this.popup, + el: this.adapter, height: "fill" }] + }); + BI.createWidget({ + type: "bi.absolute", + element: this, + height: "100%", + width: "100%", + items: [{ + el: this.searcherPane, + top: 30, + bottom: 0, + left: 0, + right: 0 + }] }) + }, - _defaultState: function () { - this.trigger.stopEditing(); + _showAdapter: function () { + this.adapter.setVisible(true); + this.searcherPane.setVisible(false); + }, + + _showSearcherPane: function () { + this.searcherPane.setVisible(true); + this.adapter.setVisible(false); }, resize: function () { - this.trigger.getCounter().adjustView(); - this.trigger.getSearcher().adjustView(); + }, setValue: function (v) { this.storeValue.value = v || {}; - this.popup.setValue({ + this.adapter.setValue({ value: v || {} }); this.trigger.setValue({ @@ -12175,22 +12189,22 @@ BI.MultiTreeList = BI.inherit(BI.Widget, { populate: function () { this.trigger.populate.apply(this.trigger, arguments); - this.popup.populate.apply(this.popup, arguments); + this.adapter.populate.apply(this.adapter, arguments); } }); -BI.MultiTreeList.EVENT_CHANGE = "MultiTreeList.EVENT_CHANGE"; -BI.shortcut('bi.multi_tree_list', BI.MultiTreeList);/** +BI.MultiSelectTree.EVENT_CHANGE = "BI.MultiSelectTree.EVENT_CHANGE"; +BI.shortcut("bi.multi_select_tree", BI.MultiSelectTree);/** * Created by zcf on 2016/12/21. */ -BI.MultiStringListPopup=BI.inherit(BI.Widget,{ - _defaultConfig:function () { - return BI.extend(BI.MultiStringListPopup.superclass._defaultConfig.apply(this, arguments), { +BI.MultiSelectTreePopup = BI.inherit(BI.Widget, { + _defaultConfig: function () { + return BI.extend(BI.MultiSelectTreePopup.superclass._defaultConfig.apply(this, arguments), { baseCls: "bi-tree-list-popup bi-border-left bi-border-right bi-border-bottom", itemsCreator: BI.emptyFn }); }, - _init:function () { - BI.MultiStringListPopup.superclass._init.apply(this, arguments); + _init: function () { + BI.MultiSelectTreePopup.superclass._init.apply(this, arguments); var self = this, o = this.options; this.popup = BI.createWidget({ type: "bi.sync_tree", @@ -12199,10 +12213,10 @@ BI.MultiStringListPopup=BI.inherit(BI.Widget,{ itemsCreator: o.itemsCreator }); this.popup.on(BI.TreeView.EVENT_AFTERINIT, function () { - self.fireEvent(BI.MultiStringListPopup.EVENT_AFTER_INIT) + self.fireEvent(BI.MultiSelectTreePopup.EVENT_AFTER_INIT) }); this.popup.on(BI.TreeView.EVENT_CHANGE, function () { - self.fireEvent(BI.MultiStringListPopup.EVENT_CHANGE) + self.fireEvent(BI.MultiSelectTreePopup.EVENT_CHANGE) }); }, @@ -12224,9 +12238,9 @@ BI.MultiStringListPopup=BI.inherit(BI.Widget,{ } }); -BI.MultiStringListPopup.EVENT_AFTER_INIT="BI.MultiStringListPopup.EVENT_AFTER_INIT"; -BI.MultiStringListPopup.EVENT_CHANGE="BI.MultiStringListPopup.EVENT_CHANGE"; -BI.shortcut("bi.multi_tree_list_popup",BI.MultiStringListPopup);//小于号的值为:0,小于等于号的值为:1 +BI.MultiSelectTreePopup.EVENT_AFTER_INIT = "BI.MultiSelectTreePopup.EVENT_AFTER_INIT"; +BI.MultiSelectTreePopup.EVENT_CHANGE = "BI.MultiSelectTreePopup.EVENT_CHANGE"; +BI.shortcut("bi.multi_select_tree_popup", BI.MultiSelectTreePopup);//小于号的值为:0,小于等于号的值为:1 //closeMIn:最小值的符号,closeMax:最大值的符号 /** * Created by roy on 15/9/17. diff --git a/src/widget/multistringlist/multistringlist.js b/src/widget/multistringlist/multistringlist.js index 5ca2696795..f1783428da 100644 --- a/src/widget/multistringlist/multistringlist.js +++ b/src/widget/multistringlist/multistringlist.js @@ -1,5 +1,5 @@ /** - * Created by zcf on 2016/12/14. + * Created by zcf_1 on 2017/5/2. */ BI.MultiStringList = BI.inherit(BI.Widget, { _defaultConfig: function () { @@ -7,33 +7,30 @@ BI.MultiStringList = BI.inherit(BI.Widget, { baseCls: 'bi-multi-string-list', itemsCreator: BI.emptyFn, valueFormatter: BI.emptyFn, - height: 25 + el: {} }) }, _init: function () { BI.MultiStringList.superclass._init.apply(this, arguments); var self = this, o = this.options; + this.storeValue = {}; var assertShowValue = function () { BI.isKey(self._startValue) && self.storeValue.value[self.storeValue.type === BI.Selection.All ? "remove" : "pushDistinct"](self._startValue); - self.trigger.getSearcher().setState(self.storeValue); - self.trigger.getCounter().setButtonChecked(self.storeValue); }; - this.storeValue = {}; - - this.popup = BI.createWidget({ + this.adapter = BI.createWidget({ type: "bi.multi_select_loader", cls: "popup-multi-string-list bi-border-left bi-border-right bi-border-bottom", itemsCreator: o.itemsCreator, valueFormatter: o.valueFormatter, - onLoaded: o.onLoaded, + // onLoaded: o.onLoaded, el: { height: "" } }); - this.popup.on(BI.MultiSelectLoader.EVENT_CHANGE, function () { + this.adapter.on(BI.MultiSelectLoader.EVENT_CHANGE, function () { self.storeValue = this.getValue(); self._adjust(function () { assertShowValue(); @@ -41,90 +38,105 @@ BI.MultiStringList = BI.inherit(BI.Widget, { }); }); - this.trigger = BI.createWidget({ - type: "bi.multi_select_trigger", - height: o.height, - adapter: this.popup, - masker: { - offset: { - left: 1, - top: 0, - right: 2, - bottom: 1 - } - }, + this.searcherPane = BI.createWidget({ + type: "bi.multi_select_search_pane", + cls: "bi-border-left bi-border-right bi-border-bottom", valueFormatter: o.valueFormatter, + keywordGetter: function () { + return self.trigger.getKeyword(); + }, itemsCreator: function (op, callback) { - o.itemsCreator(op, function (res) { - if (op.times === 1 && BI.isNotNull(op.keyword)) { - self.trigger.setValue(self.getValue()); - } - callback.apply(self, arguments); - }); + op.keyword = self.trigger.getKeyword(); + this.setKeyword(op.keyword); + o.itemsCreator(op, callback); } }); + this.searcherPane.setVisible(false); - this.trigger.on(BI.MultiSelectTrigger.EVENT_START, function () { - self._setStartValue(""); - this.getSearcher().setValue(self.storeValue); - }); - this.trigger.on(BI.MultiSelectTrigger.EVENT_STOP, function () { - self._setStartValue(""); - }); - this.trigger.on(BI.MultiSelectTrigger.EVENT_PAUSE, function () { - if (this.getSearcher().hasMatched()) { - var keyword = this.getSearcher().getKeyword(); - self._join({ - type: BI.Selection.Multi, - value: [keyword] - }, function () { - self.trigger.setValue(self.storeValue); - self.popup.setValue(self.storeValue); - self._setStartValue(keyword); - assertShowValue(); - self.populate(); + this.trigger = BI.createWidget({ + type: "bi.searcher", + isAutoSearch: false, + isAutoSync: false, + onSearch: function (op, callback) { + callback(); + }, + adapter: this.adapter, + popup: this.searcherPane, + height: 200, + masker: false, + listeners: [{ + eventName: BI.Searcher.EVENT_START, + action: function () { + self._showSearcherPane(); self._setStartValue(""); - self.fireEvent(BI.MultiStringList.EVENT_CHANGE); - }) - } - }); - this.trigger.on(BI.MultiSelectTrigger.EVENT_SEARCHING, function (keywords) { - var last = BI.last(keywords); - keywords = BI.initial(keywords || []); - if (keywords.length > 0) { - self._joinKeywords(keywords, function () { - if (BI.isEndWithBlank(last)) { - self.trigger.setValue(self.storeValue); - self.popup.setValue(self.storeValue); - assertShowValue(); - self.popup.populate(); - self._setStartValue(""); + this.setValue(self.storeValue); + } + }, { + eventName: BI.Searcher.EVENT_STOP, + action: function () { + self._showAdapter(); + self._setStartValue(""); + self.adapter.setValue(self.storeValue); + } + }, { + eventName: BI.Searcher.EVENT_PAUSE, + action: function () { + if (this.hasMatched()) { + var keyword = this.getKeyword(); + self._join({ + type: BI.Selection.Multi, + value: [keyword] + }, function () { + self._showAdapter(); + self.trigger.setValue(self.storeValue); + self.adapter.setValue(self.storeValue); + self._setStartValue(keyword); + assertShowValue(); + self._setStartValue(""); + self.fireEvent(BI.MultiStringList.EVENT_CHANGE); + }) } else { - self.trigger.setValue(self.storeValue); - self.popup.setValue(self.storeValue); - assertShowValue(); + self._showAdapter(); } - }); - } + } + }, { + eventName: BI.Searcher.EVENT_SEARCHING, + action: function () { + var keywords = this.getKeyword(); + var last = BI.last(keywords); + keywords = BI.initial(keywords || []); + if (keywords.length > 0) { + self._joinKeywords(keywords, function () { + if (BI.isEndWithBlank(last)) { + self.trigger.setValue(self.storeValue); + self.adapter.setValue(self.storeValue); + assertShowValue(); + self.adapter.populate(); + self._setStartValue(""); + } else { + self.trigger.setValue(self.storeValue); + self.adapter.setValue(self.storeValue); + assertShowValue(); + } + }); + } + } + }, { + eventName: BI.Searcher.EVENT_CHANGE, + action: function (value, obj) { + if (obj instanceof BI.MultiSelectBar) { + self._joinAll(this.getValue(), function () { + assertShowValue(); + }); + } else { + self._join(this.getValue(), function () {//安徽省 北京 + assertShowValue(); + }); + } + } + }] }); - this.trigger.on(BI.MultiSelectTrigger.EVENT_CHANGE, function (value, obj) { - if (obj instanceof BI.MultiSelectBar) { - self._joinAll(this.getValue(), function () { - assertShowValue(); - }); - } else { - self._join(this.getValue(), function () {//安徽省 北京 - assertShowValue(); - }); - } - }); - this.trigger.on(BI.MultiSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW, function () { - this.getCounter().setValue(self.storeValue); - }); - var div = BI.createWidget({ - type: "bi.layout" - }); BI.createWidget({ type: "bi.vtape", element: this, @@ -132,16 +144,37 @@ BI.MultiStringList = BI.inherit(BI.Widget, { width: "100%", items: [{ el: this.trigger, - height: 25 - }, { - el: div, - height: 2 + height: 30 }, { - el: this.popup, + el: this.adapter, height: "fill" }] }); + BI.createWidget({ + type: "bi.absolute", + element: this, + height: "100%", + width: "100%", + items: [{ + el: this.searcherPane, + top: 30, + bottom: 0, + left: 0, + right: 0 + }] + }) }, + + _showAdapter: function () { + this.adapter.setVisible(true); + this.searcherPane.setVisible(false); + }, + + _showSearcherPane: function () { + this.searcherPane.setVisible(true); + this.adapter.setVisible(false); + }, + _defaultState: function () { this.trigger.stopEditing(); }, @@ -186,7 +219,7 @@ BI.MultiStringList = BI.inherit(BI.Widget, { this._assertValue(res); o.itemsCreator({ type: BI.MultiStringList.REQ_GET_ALL_DATA, - keyword: this.trigger.getKey() + keyword: self.trigger.getKeyword() }, function (ob) { var items = BI.pluck(ob.items, "value"); if (self.storeValue.type === res.type) { @@ -275,22 +308,21 @@ BI.MultiStringList = BI.inherit(BI.Widget, { _setStartValue: function (value) { this._startValue = value; - this.popup.setStartValue(value); + this.adapter.setStartValue(value); }, - // isAllSelected: function () { - // return this.popup.isAllSelected(); - // }, + isAllSelected: function () { + return this.adapter.isAllSelected(); + }, resize: function () { - this.trigger.getCounter().adjustView(); - this.trigger.getSearcher().adjustView(); + // this.trigger.getCounter().adjustView(); + // this.trigger.adjustView(); }, - setValue: function (v) { this.storeValue = v || {}; this._assertValue(this.storeValue); - this.popup.setValue(this.storeValue); + this.adapter.setValue(this.storeValue); this.trigger.setValue(this.storeValue); }, @@ -301,7 +333,7 @@ BI.MultiStringList = BI.inherit(BI.Widget, { populate: function () { this._count = null; this._allData = null; - this.popup.populate.apply(this.popup, arguments); + this.adapter.populate.apply(this.adapter, arguments); this.trigger.populate.apply(this.trigger, arguments); } }); diff --git a/src/widget/multitreelist/multitreelist.js b/src/widget/multitreelist/multitreelist.js index 52182c0dce..2403eac14a 100644 --- a/src/widget/multitreelist/multitreelist.js +++ b/src/widget/multitreelist/multitreelist.js @@ -1,128 +1,94 @@ /** - * Created by zcf on 2016/12/20. + * Created by zcf_1 on 2017/5/11. */ -BI.MultiTreeList = BI.inherit(BI.Widget, { - constants: { - offset: { - left: 1, - top: 0, - right: 2, - bottom: 1 - } - }, - +BI.MultiSelectTree = BI.inherit(BI.Widget, { _defaultConfig: function () { - return BI.extend(BI.MultiTreeList.superclass._defaultConfig.apply(this, arguments), { + return BI.extend(BI.MultiSelectTree.superclass._defaultConfig.apply(this, arguments), { baseCls: 'bi-multi-tree-combo', itemsCreator: BI.emptyFn, height: 25 - }); + }) }, _init: function () { - BI.MultiTreeList.superclass._init.apply(this, arguments); - + BI.MultiSelectTree.superclass._init.apply(this, arguments); var self = this, o = this.options; + this.storeValue = {value: {}}; - var isInit = false; - var want2showCounter = false; - - this.popup = BI.createWidget({ - type: "bi.multi_tree_list_popup", + this.adapter = BI.createWidget({ + type: "bi.multi_select_tree_popup", itemsCreator: o.itemsCreator }); - - this.popup.on(BI.MultiStringListPopup.EVENT_AFTER_INIT, function () { - self.trigger.getCounter().adjustView(); - isInit = true; - if (want2showCounter === true) { - showCounter(); + this.adapter.on(BI.MultiSelectTreePopup.EVENT_CHANGE, function () { + if (self.trigger.isSearching()) { + self.storeValue = {value: self.searcherPane.getValue()}; + } else { + self.storeValue = {value: self.adapter.getValue()}; } + self.fireEvent(BI.MultiSelectTree.EVENT_CHANGE); }); - this.trigger = BI.createWidget({ - type: "bi.multi_select_trigger", - height: o.height, - adapter: this.popup, - masker: { - offset: this.constants.offset + this.searcherPane = BI.createWidget({//搜索中的时候用的是parttree,同adapter中的synctree不一样 + type: "bi.multi_tree_search_pane", + cls: "bi-border-left bi-border-right bi-border-bottom", + keywordGetter: function () { + return self.trigger.getKeyword(); }, - searcher: { - type: "bi.multi_tree_searcher", - itemsCreator: o.itemsCreator - }, - switcher: { - el: { - type: "bi.multi_tree_check_selected_button" - }, - popup: { - type: "bi.multi_tree_check_pane", - itemsCreator: o.itemsCreator - } + itemsCreator: function (op, callback) { + op.keyword = self.trigger.getKeyword(); + o.itemsCreator(op, callback); } }); + this.searcherPane.setVisible(false); - this.storeValue = {value: {}}; - - var isSearching = function () { - return self.trigger.getSearcher().isSearching(); - }; - - this.trigger.on(BI.MultiSelectTrigger.EVENT_START, function () { - self.storeValue = {value: self.popup.getValue()}; - this.setValue(self.storeValue); - }); - this.trigger.on(BI.MultiSelectTrigger.EVENT_STOP, function () { - self.storeValue = {value: this.getValue()}; - self.trigger.setValue(self.storeValue); - self.popup.setValue(self.storeValue); - BI.nextTick(function () { - self.trigger.populate(); - self.popup.populate(); - }); - }); - function showCounter() { - if (isSearching()) { - self.storeValue = {value: self.trigger.getValue()}; - } else { - self.storeValue = {value: self.popup.getValue()}; - } - self.trigger.setValue(self.storeValue); - } - - this.trigger.on(BI.MultiSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW, function () { - if (want2showCounter === false) { - want2showCounter = true; - } - if (isInit === true) { - want2showCounter = null; - showCounter(); - } - }); - - this.trigger.on(BI.MultiSelectTrigger.EVENT_CHANGE, function () { - var val = { - type: BI.Selection.Multi, - value: this.getSearcher().hasChecked() ? {1: 1} : {} - }; - this.getSearcher().setState(val); - this.getCounter().setButtonChecked(val); - }); - - this.popup.on(BI.MultiStringListPopup.EVENT_CHANGE, function () { - showCounter(); - var val = { - type: BI.Selection.Multi, - value: this.hasChecked() ? {1: 1} : {} - }; - self.trigger.getSearcher().setState(val); - self.trigger.getCounter().setButtonChecked(val); - self.fireEvent(BI.MultiTreeList.EVENT_CHANGE); + this.trigger = BI.createWidget({ + type: "bi.searcher", + isAutoSearch: false, + isAutoSync: false, + onSearch: function (op, callback) { + callback({ + keyword: self.trigger.getKeyword() + }); + }, + adapter: this.adapter, + popup: this.searcherPane, + height: 200, + masker: false, + listeners: [{ + eventName: BI.Searcher.EVENT_START, + action: function () { + self._showSearcherPane(); + self.storeValue = {value: self.adapter.getValue()}; + self.searcherPane.setValue(self.storeValue); + } + }, { + eventName: BI.Searcher.EVENT_STOP, + action: function () { + self._showAdapter(); + // self.storeValue = {value: self.searcherPane.getValue()}; + self.adapter.setValue(self.storeValue); + BI.nextTick(function () { + self.adapter.populate(); + }); + } + }, { + eventName: BI.Searcher.EVENT_CHANGE, + action: function () { + if (self.trigger.isSearching()) { + self.storeValue = {value: self.searcherPane.getValue()}; + } else { + self.storeValue = {value: self.adapter.getValue()}; + } + self.fireEvent(BI.MultiSelectTree.EVENT_CHANGE); + } + }, { + eventName: BI.Searcher.EVENT_PAUSE, + action: function () { + self._showAdapter(); + } + }] }); - var div = BI.createWidget({ - type: "bi.layout" - }); BI.createWidget({ type: "bi.vtape", element: this, @@ -130,29 +96,45 @@ BI.MultiTreeList = BI.inherit(BI.Widget, { width: "100%", items: [{ el: this.trigger, - height: 25 + height: 30 }, { - el: div, - height: 2 - }, { - el: this.popup, + el: this.adapter, height: "fill" }] + }); + BI.createWidget({ + type: "bi.absolute", + element: this, + height: "100%", + width: "100%", + items: [{ + el: this.searcherPane, + top: 30, + bottom: 0, + left: 0, + right: 0 + }] }) + }, - _defaultState: function () { - this.trigger.stopEditing(); + _showAdapter: function () { + this.adapter.setVisible(true); + this.searcherPane.setVisible(false); + }, + + _showSearcherPane: function () { + this.searcherPane.setVisible(true); + this.adapter.setVisible(false); }, resize: function () { - this.trigger.getCounter().adjustView(); - this.trigger.getSearcher().adjustView(); + }, setValue: function (v) { this.storeValue.value = v || {}; - this.popup.setValue({ + this.adapter.setValue({ value: v || {} }); this.trigger.setValue({ @@ -166,8 +148,8 @@ BI.MultiTreeList = BI.inherit(BI.Widget, { populate: function () { this.trigger.populate.apply(this.trigger, arguments); - this.popup.populate.apply(this.popup, arguments); + this.adapter.populate.apply(this.adapter, arguments); } }); -BI.MultiTreeList.EVENT_CHANGE = "MultiTreeList.EVENT_CHANGE"; -BI.shortcut('bi.multi_tree_list', BI.MultiTreeList); \ No newline at end of file +BI.MultiSelectTree.EVENT_CHANGE = "BI.MultiSelectTree.EVENT_CHANGE"; +BI.shortcut("bi.multi_select_tree", BI.MultiSelectTree); \ No newline at end of file diff --git a/src/widget/multitreelist/multitreelist.popup.js b/src/widget/multitreelist/multitreelist.popup.js index 549c471d0f..864137a9c6 100644 --- a/src/widget/multitreelist/multitreelist.popup.js +++ b/src/widget/multitreelist/multitreelist.popup.js @@ -1,15 +1,15 @@ /** * Created by zcf on 2016/12/21. */ -BI.MultiStringListPopup=BI.inherit(BI.Widget,{ - _defaultConfig:function () { - return BI.extend(BI.MultiStringListPopup.superclass._defaultConfig.apply(this, arguments), { +BI.MultiSelectTreePopup = BI.inherit(BI.Widget, { + _defaultConfig: function () { + return BI.extend(BI.MultiSelectTreePopup.superclass._defaultConfig.apply(this, arguments), { baseCls: "bi-tree-list-popup bi-border-left bi-border-right bi-border-bottom", itemsCreator: BI.emptyFn }); }, - _init:function () { - BI.MultiStringListPopup.superclass._init.apply(this, arguments); + _init: function () { + BI.MultiSelectTreePopup.superclass._init.apply(this, arguments); var self = this, o = this.options; this.popup = BI.createWidget({ type: "bi.sync_tree", @@ -18,10 +18,10 @@ BI.MultiStringListPopup=BI.inherit(BI.Widget,{ itemsCreator: o.itemsCreator }); this.popup.on(BI.TreeView.EVENT_AFTERINIT, function () { - self.fireEvent(BI.MultiStringListPopup.EVENT_AFTER_INIT) + self.fireEvent(BI.MultiSelectTreePopup.EVENT_AFTER_INIT) }); this.popup.on(BI.TreeView.EVENT_CHANGE, function () { - self.fireEvent(BI.MultiStringListPopup.EVENT_CHANGE) + self.fireEvent(BI.MultiSelectTreePopup.EVENT_CHANGE) }); }, @@ -43,6 +43,6 @@ BI.MultiStringListPopup=BI.inherit(BI.Widget,{ } }); -BI.MultiStringListPopup.EVENT_AFTER_INIT="BI.MultiStringListPopup.EVENT_AFTER_INIT"; -BI.MultiStringListPopup.EVENT_CHANGE="BI.MultiStringListPopup.EVENT_CHANGE"; -BI.shortcut("bi.multi_tree_list_popup",BI.MultiStringListPopup); \ No newline at end of file +BI.MultiSelectTreePopup.EVENT_AFTER_INIT = "BI.MultiSelectTreePopup.EVENT_AFTER_INIT"; +BI.MultiSelectTreePopup.EVENT_CHANGE = "BI.MultiSelectTreePopup.EVENT_CHANGE"; +BI.shortcut("bi.multi_select_tree_popup", BI.MultiSelectTreePopup); \ No newline at end of file