From 9b23bee3da4b01bf4c4655e178382dee33f816a5 Mon Sep 17 00:00:00 2001 From: Young Date: Mon, 9 Jul 2018 18:31:19 +0800 Subject: [PATCH] =?UTF-8?q?BI-26291=20=E9=99=A4=E6=B3=95=E4=B8=A2=E7=B2=BE?= =?UTF-8?q?=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/bundle.js | 87 +++++++++++++++++++++++++++++----------- dist/case.js | 17 +++++--- dist/core.js | 70 +++++++++++++++++++++++--------- dist/fineui.js | 87 +++++++++++++++++++++++++++++----------- src/core/proto/number.js | 70 +++++++++++++++++++++++--------- utils/utils.js | 70 +++++++++++++++++++++++--------- 6 files changed, 296 insertions(+), 105 deletions(-) diff --git a/dist/bundle.js b/dist/bundle.js index 75589a6ac3..0c7fb0335e 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -29973,32 +29973,66 @@ function accMul (arg1, arg2) { Number.prototype.mul = function (arg) { return accMul(arg, this); }; + /** - ** 除法函数,用来得到精确的除法结果 - ** 说明:javascript的除法结果会有误差,在两个浮点数相除的时候会比较明显。这个函数返回较为精确的除法结果。 - ** 调用:accDiv(arg1,arg2) - ** 返回值:arg1除以arg2的精确结果 - **/ -function accDiv (arg1, arg2) { - var t1 = 0, t2 = 0, r1, r2; - try { - t1 = arg1.toString().split(".")[1].length; - } catch (e) { + * Return digits length of a number + * @param {*number} num Input number + */ +function digitLength (num) { + // Get digit length of e + var eSplit = num.toString().split(/[eE]/); + var len = (eSplit[0].split(".")[1] || "").length - (+(eSplit[1] || 0)); + return len > 0 ? len : 0; +} +/** + * 把小数转成整数,支持科学计数法。如果是小数则放大成整数 + * @param {*number} num 输入数 + */ +function float2Fixed (num) { + if (num.toString().indexOf("e") === -1) { + return Number(num.toString().replace(".", "")); } - try { - t2 = arg2.toString().split(".")[1].length; - } catch (e) { + var dLen = digitLength(num); + return dLen > 0 ? num * Math.pow(10, dLen) : num; +} + +/** + * 精确乘法 + */ +function times (num1, num2) { + var others = []; + for (var _i = 2; _i < arguments.length; _i++) { + others[_i - 2] = arguments[_i]; + } + if (others.length > 0) { + return times.apply(void 0, [times(num1, num2), others[0]].concat(others.slice(1))); + } + var num1Changed = float2Fixed(num1); + var num2Changed = float2Fixed(num2); + var baseNum = digitLength(num1) + digitLength(num2); + var leftValue = num1Changed * num2Changed; + return leftValue / Math.pow(10, baseNum); +} + +/** + * 精确除法 + */ +function accDivide (num1, num2) { + var others = []; + for (var _i = 2; _i < arguments.length; _i++) { + others[_i - 2] = arguments[_i]; } - with (Math) { - r1 = Number(arg1.toString().replace(".", "")); - r2 = Number(arg2.toString().replace(".", "")); - return (t2 > t1) ? (r1 / r2) * pow(10, t2 - t1) : (r1 / r2) / pow(10, t1 - t2); + if (others.length > 0) { + return accDivide.apply(void 0, [accDivide(num1, num2), others[0]].concat(others.slice(1))); } + var num1Changed = float2Fixed(num1); + var num2Changed = float2Fixed(num2); + return times((num1Changed / num2Changed), Math.pow(10, digitLength(num2) - digitLength(num1))); } // 给Number类型增加一个div方法,调用起来更加方便。 Number.prototype.div = function (arg) { - return accDiv(this, arg); + return accDivide(this, arg); };/** * 对字符串对象的扩展 * @class String @@ -83174,11 +83208,6 @@ BI.RichEditorTextToolbar = BI.inherit(BI.Widget, { editor: o.editor }); })); - this.element.mousedown(function (e) { - BI.each(buttons, function (i, btn) { - btn.hideIf(e); - }); - }); BI.createWidget({ type: "bi.left", element: this, @@ -83300,6 +83329,10 @@ BI.shortcut("bi.rich_editor_text_toolbar", BI.RichEditorTextToolbar);/** return this.instance.getContent(); }, + getContentHeight: function () { + return this.instance.getContentHeight(); + }, + getInstance: function () { return this.instance; }, @@ -83509,6 +83542,10 @@ BI.shortcut("bi.rich_editor_text_toolbar", BI.RichEditorTextToolbar);/** return this.content; }, + getContentHeight: function () { + return this.elm.element.height(); + }, + setContent: function (e) { this.content = e; this.ne.fireEvent("set"); @@ -84274,6 +84311,10 @@ BI.RichEditor = BI.inherit(BI.Widget, { getValue: function () { return this.editor.getValue(); + }, + + getContentHeight: function () { + return this.editor.getContentHeight(); } }); BI.RichEditor.EVENT_AFTER_HIDEVIEW = "EVENT_AFTER_HIDEVIEW"; diff --git a/dist/case.js b/dist/case.js index 4f0941b3b0..4b97705504 100644 --- a/dist/case.js +++ b/dist/case.js @@ -10673,11 +10673,6 @@ BI.RichEditorTextToolbar = BI.inherit(BI.Widget, { editor: o.editor }); })); - this.element.mousedown(function (e) { - BI.each(buttons, function (i, btn) { - btn.hideIf(e); - }); - }); BI.createWidget({ type: "bi.left", element: this, @@ -10799,6 +10794,10 @@ BI.shortcut("bi.rich_editor_text_toolbar", BI.RichEditorTextToolbar);/** return this.instance.getContent(); }, + getContentHeight: function () { + return this.instance.getContentHeight(); + }, + getInstance: function () { return this.instance; }, @@ -11008,6 +11007,10 @@ BI.shortcut("bi.rich_editor_text_toolbar", BI.RichEditorTextToolbar);/** return this.content; }, + getContentHeight: function () { + return this.elm.element.height(); + }, + setContent: function (e) { this.content = e; this.ne.fireEvent("set"); @@ -11773,6 +11776,10 @@ BI.RichEditor = BI.inherit(BI.Widget, { getValue: function () { return this.editor.getValue(); + }, + + getContentHeight: function () { + return this.editor.getContentHeight(); } }); BI.RichEditor.EVENT_AFTER_HIDEVIEW = "EVENT_AFTER_HIDEVIEW"; diff --git a/dist/core.js b/dist/core.js index 0a8e8ae41f..345ee03e37 100644 --- a/dist/core.js +++ b/dist/core.js @@ -29973,32 +29973,66 @@ function accMul (arg1, arg2) { Number.prototype.mul = function (arg) { return accMul(arg, this); }; + /** - ** 除法函数,用来得到精确的除法结果 - ** 说明:javascript的除法结果会有误差,在两个浮点数相除的时候会比较明显。这个函数返回较为精确的除法结果。 - ** 调用:accDiv(arg1,arg2) - ** 返回值:arg1除以arg2的精确结果 - **/ -function accDiv (arg1, arg2) { - var t1 = 0, t2 = 0, r1, r2; - try { - t1 = arg1.toString().split(".")[1].length; - } catch (e) { + * Return digits length of a number + * @param {*number} num Input number + */ +function digitLength (num) { + // Get digit length of e + var eSplit = num.toString().split(/[eE]/); + var len = (eSplit[0].split(".")[1] || "").length - (+(eSplit[1] || 0)); + return len > 0 ? len : 0; +} +/** + * 把小数转成整数,支持科学计数法。如果是小数则放大成整数 + * @param {*number} num 输入数 + */ +function float2Fixed (num) { + if (num.toString().indexOf("e") === -1) { + return Number(num.toString().replace(".", "")); } - try { - t2 = arg2.toString().split(".")[1].length; - } catch (e) { + var dLen = digitLength(num); + return dLen > 0 ? num * Math.pow(10, dLen) : num; +} + +/** + * 精确乘法 + */ +function times (num1, num2) { + var others = []; + for (var _i = 2; _i < arguments.length; _i++) { + others[_i - 2] = arguments[_i]; + } + if (others.length > 0) { + return times.apply(void 0, [times(num1, num2), others[0]].concat(others.slice(1))); + } + var num1Changed = float2Fixed(num1); + var num2Changed = float2Fixed(num2); + var baseNum = digitLength(num1) + digitLength(num2); + var leftValue = num1Changed * num2Changed; + return leftValue / Math.pow(10, baseNum); +} + +/** + * 精确除法 + */ +function accDivide (num1, num2) { + var others = []; + for (var _i = 2; _i < arguments.length; _i++) { + others[_i - 2] = arguments[_i]; } - with (Math) { - r1 = Number(arg1.toString().replace(".", "")); - r2 = Number(arg2.toString().replace(".", "")); - return (t2 > t1) ? (r1 / r2) * pow(10, t2 - t1) : (r1 / r2) / pow(10, t1 - t2); + if (others.length > 0) { + return accDivide.apply(void 0, [accDivide(num1, num2), others[0]].concat(others.slice(1))); } + var num1Changed = float2Fixed(num1); + var num2Changed = float2Fixed(num2); + return times((num1Changed / num2Changed), Math.pow(10, digitLength(num2) - digitLength(num1))); } // 给Number类型增加一个div方法,调用起来更加方便。 Number.prototype.div = function (arg) { - return accDiv(this, arg); + return accDivide(this, arg); };/** * 对字符串对象的扩展 * @class String diff --git a/dist/fineui.js b/dist/fineui.js index ce7ab807c8..b358fbaeaa 100644 --- a/dist/fineui.js +++ b/dist/fineui.js @@ -30222,32 +30222,66 @@ function accMul (arg1, arg2) { Number.prototype.mul = function (arg) { return accMul(arg, this); }; + /** - ** 除法函数,用来得到精确的除法结果 - ** 说明:javascript的除法结果会有误差,在两个浮点数相除的时候会比较明显。这个函数返回较为精确的除法结果。 - ** 调用:accDiv(arg1,arg2) - ** 返回值:arg1除以arg2的精确结果 - **/ -function accDiv (arg1, arg2) { - var t1 = 0, t2 = 0, r1, r2; - try { - t1 = arg1.toString().split(".")[1].length; - } catch (e) { + * Return digits length of a number + * @param {*number} num Input number + */ +function digitLength (num) { + // Get digit length of e + var eSplit = num.toString().split(/[eE]/); + var len = (eSplit[0].split(".")[1] || "").length - (+(eSplit[1] || 0)); + return len > 0 ? len : 0; +} +/** + * 把小数转成整数,支持科学计数法。如果是小数则放大成整数 + * @param {*number} num 输入数 + */ +function float2Fixed (num) { + if (num.toString().indexOf("e") === -1) { + return Number(num.toString().replace(".", "")); } - try { - t2 = arg2.toString().split(".")[1].length; - } catch (e) { + var dLen = digitLength(num); + return dLen > 0 ? num * Math.pow(10, dLen) : num; +} + +/** + * 精确乘法 + */ +function times (num1, num2) { + var others = []; + for (var _i = 2; _i < arguments.length; _i++) { + others[_i - 2] = arguments[_i]; + } + if (others.length > 0) { + return times.apply(void 0, [times(num1, num2), others[0]].concat(others.slice(1))); + } + var num1Changed = float2Fixed(num1); + var num2Changed = float2Fixed(num2); + var baseNum = digitLength(num1) + digitLength(num2); + var leftValue = num1Changed * num2Changed; + return leftValue / Math.pow(10, baseNum); +} + +/** + * 精确除法 + */ +function accDivide (num1, num2) { + var others = []; + for (var _i = 2; _i < arguments.length; _i++) { + others[_i - 2] = arguments[_i]; } - with (Math) { - r1 = Number(arg1.toString().replace(".", "")); - r2 = Number(arg2.toString().replace(".", "")); - return (t2 > t1) ? (r1 / r2) * pow(10, t2 - t1) : (r1 / r2) / pow(10, t1 - t2); + if (others.length > 0) { + return accDivide.apply(void 0, [accDivide(num1, num2), others[0]].concat(others.slice(1))); } + var num1Changed = float2Fixed(num1); + var num2Changed = float2Fixed(num2); + return times((num1Changed / num2Changed), Math.pow(10, digitLength(num2) - digitLength(num1))); } // 给Number类型增加一个div方法,调用起来更加方便。 Number.prototype.div = function (arg) { - return accDiv(this, arg); + return accDivide(this, arg); };/** * 对字符串对象的扩展 * @class String @@ -83423,11 +83457,6 @@ BI.RichEditorTextToolbar = BI.inherit(BI.Widget, { editor: o.editor }); })); - this.element.mousedown(function (e) { - BI.each(buttons, function (i, btn) { - btn.hideIf(e); - }); - }); BI.createWidget({ type: "bi.left", element: this, @@ -83549,6 +83578,10 @@ BI.shortcut("bi.rich_editor_text_toolbar", BI.RichEditorTextToolbar);/** return this.instance.getContent(); }, + getContentHeight: function () { + return this.instance.getContentHeight(); + }, + getInstance: function () { return this.instance; }, @@ -83758,6 +83791,10 @@ BI.shortcut("bi.rich_editor_text_toolbar", BI.RichEditorTextToolbar);/** return this.content; }, + getContentHeight: function () { + return this.elm.element.height(); + }, + setContent: function (e) { this.content = e; this.ne.fireEvent("set"); @@ -84523,6 +84560,10 @@ BI.RichEditor = BI.inherit(BI.Widget, { getValue: function () { return this.editor.getValue(); + }, + + getContentHeight: function () { + return this.editor.getContentHeight(); } }); BI.RichEditor.EVENT_AFTER_HIDEVIEW = "EVENT_AFTER_HIDEVIEW"; diff --git a/src/core/proto/number.js b/src/core/proto/number.js index 17f747b69a..accfa46362 100644 --- a/src/core/proto/number.js +++ b/src/core/proto/number.js @@ -232,30 +232,64 @@ function accMul (arg1, arg2) { Number.prototype.mul = function (arg) { return accMul(arg, this); }; + /** - ** 除法函数,用来得到精确的除法结果 - ** 说明:javascript的除法结果会有误差,在两个浮点数相除的时候会比较明显。这个函数返回较为精确的除法结果。 - ** 调用:accDiv(arg1,arg2) - ** 返回值:arg1除以arg2的精确结果 - **/ -function accDiv (arg1, arg2) { - var t1 = 0, t2 = 0, r1, r2; - try { - t1 = arg1.toString().split(".")[1].length; - } catch (e) { + * Return digits length of a number + * @param {*number} num Input number + */ +function digitLength (num) { + // Get digit length of e + var eSplit = num.toString().split(/[eE]/); + var len = (eSplit[0].split(".")[1] || "").length - (+(eSplit[1] || 0)); + return len > 0 ? len : 0; +} +/** + * 把小数转成整数,支持科学计数法。如果是小数则放大成整数 + * @param {*number} num 输入数 + */ +function float2Fixed (num) { + if (num.toString().indexOf("e") === -1) { + return Number(num.toString().replace(".", "")); } - try { - t2 = arg2.toString().split(".")[1].length; - } catch (e) { + var dLen = digitLength(num); + return dLen > 0 ? num * Math.pow(10, dLen) : num; +} + +/** + * 精确乘法 + */ +function times (num1, num2) { + var others = []; + for (var _i = 2; _i < arguments.length; _i++) { + others[_i - 2] = arguments[_i]; + } + if (others.length > 0) { + return times.apply(void 0, [times(num1, num2), others[0]].concat(others.slice(1))); + } + var num1Changed = float2Fixed(num1); + var num2Changed = float2Fixed(num2); + var baseNum = digitLength(num1) + digitLength(num2); + var leftValue = num1Changed * num2Changed; + return leftValue / Math.pow(10, baseNum); +} + +/** + * 精确除法 + */ +function accDivide (num1, num2) { + var others = []; + for (var _i = 2; _i < arguments.length; _i++) { + others[_i - 2] = arguments[_i]; } - with (Math) { - r1 = Number(arg1.toString().replace(".", "")); - r2 = Number(arg2.toString().replace(".", "")); - return (t2 > t1) ? (r1 / r2) * pow(10, t2 - t1) : (r1 / r2) / pow(10, t1 - t2); + if (others.length > 0) { + return accDivide.apply(void 0, [accDivide(num1, num2), others[0]].concat(others.slice(1))); } + var num1Changed = float2Fixed(num1); + var num2Changed = float2Fixed(num2); + return times((num1Changed / num2Changed), Math.pow(10, digitLength(num2) - digitLength(num1))); } // 给Number类型增加一个div方法,调用起来更加方便。 Number.prototype.div = function (arg) { - return accDiv(this, arg); + return accDivide(this, arg); }; \ No newline at end of file diff --git a/utils/utils.js b/utils/utils.js index 980ffcd351..e7a0480165 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -10416,32 +10416,66 @@ function accMul (arg1, arg2) { Number.prototype.mul = function (arg) { return accMul(arg, this); }; + /** - ** 除法函数,用来得到精确的除法结果 - ** 说明:javascript的除法结果会有误差,在两个浮点数相除的时候会比较明显。这个函数返回较为精确的除法结果。 - ** 调用:accDiv(arg1,arg2) - ** 返回值:arg1除以arg2的精确结果 - **/ -function accDiv (arg1, arg2) { - var t1 = 0, t2 = 0, r1, r2; - try { - t1 = arg1.toString().split(".")[1].length; - } catch (e) { + * Return digits length of a number + * @param {*number} num Input number + */ +function digitLength (num) { + // Get digit length of e + var eSplit = num.toString().split(/[eE]/); + var len = (eSplit[0].split(".")[1] || "").length - (+(eSplit[1] || 0)); + return len > 0 ? len : 0; +} +/** + * 把小数转成整数,支持科学计数法。如果是小数则放大成整数 + * @param {*number} num 输入数 + */ +function float2Fixed (num) { + if (num.toString().indexOf("e") === -1) { + return Number(num.toString().replace(".", "")); } - try { - t2 = arg2.toString().split(".")[1].length; - } catch (e) { + var dLen = digitLength(num); + return dLen > 0 ? num * Math.pow(10, dLen) : num; +} + +/** + * 精确乘法 + */ +function times (num1, num2) { + var others = []; + for (var _i = 2; _i < arguments.length; _i++) { + others[_i - 2] = arguments[_i]; + } + if (others.length > 0) { + return times.apply(void 0, [times(num1, num2), others[0]].concat(others.slice(1))); + } + var num1Changed = float2Fixed(num1); + var num2Changed = float2Fixed(num2); + var baseNum = digitLength(num1) + digitLength(num2); + var leftValue = num1Changed * num2Changed; + return leftValue / Math.pow(10, baseNum); +} + +/** + * 精确除法 + */ +function accDivide (num1, num2) { + var others = []; + for (var _i = 2; _i < arguments.length; _i++) { + others[_i - 2] = arguments[_i]; } - with (Math) { - r1 = Number(arg1.toString().replace(".", "")); - r2 = Number(arg2.toString().replace(".", "")); - return (t2 > t1) ? (r1 / r2) * pow(10, t2 - t1) : (r1 / r2) / pow(10, t1 - t2); + if (others.length > 0) { + return accDivide.apply(void 0, [accDivide(num1, num2), others[0]].concat(others.slice(1))); } + var num1Changed = float2Fixed(num1); + var num2Changed = float2Fixed(num2); + return times((num1Changed / num2Changed), Math.pow(10, digitLength(num2) - digitLength(num1))); } // 给Number类型增加一个div方法,调用起来更加方便。 Number.prototype.div = function (arg) { - return accDiv(this, arg); + return accDivide(this, arg); };/** * 对字符串对象的扩展 * @class String