From 648c8a3d336814274cec8660ba2d56d102c846c1 Mon Sep 17 00:00:00 2001 From: guy Date: Fri, 12 May 2017 15:23:41 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E5=91=A8=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bi/core.js | 18 ++++++++++++------ docs/core.js | 18 ++++++++++++------ src/core/proto/date.js | 18 ++++++++++++------ 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/bi/core.js b/bi/core.js index 8d24e0f0e..494b9d052 100644 --- a/bi/core.js +++ b/bi/core.js @@ -6249,7 +6249,6 @@ Date._QN = ["", BI.i18nText("BI-Quarter_1"), 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]; @@ -6284,12 +6283,19 @@ Date.prototype.getDayOfYear = function () { /** Returns the number of the week in year, as defined in ISO 8601. */ Date.prototype.getWeekNumber = function () { var d = new Date(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0); - var DoW = d.getDay(); - d.setDate(d.getDate() - (DoW + 6) % 7 + 3); // Nearest Thu + var week = d.getDay(); + if (this.getMonth() === 0 && this.getDate() <= week) { + return 1; + } + d.setDate(this.getDate() - week); var ms = d.valueOf(); // GMT d.setMonth(0); - d.setDate(4); // Thu in Week 1 - return Math.round((ms - d.valueOf()) / (7 * 864e5)) + 1; + d.setDate(1); + var offset = Math.floor((ms - d.valueOf()) / (7 * 864e5)) + 1; + if (d.getDay() > 0) { + offset++; + } + return offset; }; //离当前时间多少天的时间 @@ -6381,7 +6387,7 @@ Date.prototype.getOffsetMonth = function (n) { var dt = new Date(this.getTime()); var day = dt.getDate(); var monthDay = new Date(dt.getFullYear(), dt.getMonth() + parseInt(n), 1).getMonthDays(); - if(day > monthDay){ + if (day > monthDay) { day = monthDay; } dt.setDate(day); diff --git a/docs/core.js b/docs/core.js index 3c3a69807..0bd912d24 100644 --- a/docs/core.js +++ b/docs/core.js @@ -23732,7 +23732,6 @@ Date._QN = ["", BI.i18nText("BI-Quarter_1"), 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]; @@ -23767,12 +23766,19 @@ Date.prototype.getDayOfYear = function () { /** Returns the number of the week in year, as defined in ISO 8601. */ Date.prototype.getWeekNumber = function () { var d = new Date(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0); - var DoW = d.getDay(); - d.setDate(d.getDate() - (DoW + 6) % 7 + 3); // Nearest Thu + var week = d.getDay(); + if (this.getMonth() === 0 && this.getDate() <= week) { + return 1; + } + d.setDate(this.getDate() - week); var ms = d.valueOf(); // GMT d.setMonth(0); - d.setDate(4); // Thu in Week 1 - return Math.round((ms - d.valueOf()) / (7 * 864e5)) + 1; + d.setDate(1); + var offset = Math.floor((ms - d.valueOf()) / (7 * 864e5)) + 1; + if (d.getDay() > 0) { + offset++; + } + return offset; }; //离当前时间多少天的时间 @@ -23864,7 +23870,7 @@ Date.prototype.getOffsetMonth = function (n) { var dt = new Date(this.getTime()); var day = dt.getDate(); var monthDay = new Date(dt.getFullYear(), dt.getMonth() + parseInt(n), 1).getMonthDays(); - if(day > monthDay){ + if (day > monthDay) { day = monthDay; } dt.setDate(day); diff --git a/src/core/proto/date.js b/src/core/proto/date.js index b25c92d15..36197df93 100644 --- a/src/core/proto/date.js +++ b/src/core/proto/date.js @@ -56,7 +56,6 @@ Date._QN = ["", BI.i18nText("BI-Quarter_1"), 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]; @@ -91,12 +90,19 @@ Date.prototype.getDayOfYear = function () { /** Returns the number of the week in year, as defined in ISO 8601. */ Date.prototype.getWeekNumber = function () { var d = new Date(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0); - var DoW = d.getDay(); - d.setDate(d.getDate() - (DoW + 6) % 7 + 3); // Nearest Thu + var week = d.getDay(); + if (this.getMonth() === 0 && this.getDate() <= week) { + return 1; + } + d.setDate(this.getDate() - week); var ms = d.valueOf(); // GMT d.setMonth(0); - d.setDate(4); // Thu in Week 1 - return Math.round((ms - d.valueOf()) / (7 * 864e5)) + 1; + d.setDate(1); + var offset = Math.floor((ms - d.valueOf()) / (7 * 864e5)) + 1; + if (d.getDay() > 0) { + offset++; + } + return offset; }; //离当前时间多少天的时间 @@ -188,7 +194,7 @@ Date.prototype.getOffsetMonth = function (n) { var dt = new Date(this.getTime()); var day = dt.getDate(); var monthDay = new Date(dt.getFullYear(), dt.getMonth() + parseInt(n), 1).getMonthDays(); - if(day > monthDay){ + if (day > monthDay) { day = monthDay; } dt.setDate(day); From 70762c4ec08ec85934e5a32afbe55fc5d4265800 Mon Sep 17 00:00:00 2001 From: guy Date: Fri, 12 May 2017 16:09:12 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E6=BB=9A=E5=8A=A8=E5=B8=A7=E9=A2=91?= =?UTF-8?q?=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bi/base.js | 4 ++-- docs/base.js | 4 ++-- src/base/collection/collection.js | 2 +- src/base/grid/grid.js | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bi/base.js b/bi/base.js index 888d21cba..8c75b6e8e 100644 --- a/bi/base.js +++ b/bi/base.js @@ -2542,7 +2542,7 @@ BI.Collection = BI.inherit(BI.Widget, { this._scrollLock = false; this._debounceRelease = BI.debounce(function () { self._scrollLock = false; - }, 150); + }, 1000 / 60); this.container = BI.createWidget({ type: "bi.absolute" }); @@ -14616,7 +14616,7 @@ BI.Grid = BI.inherit(BI.Widget, { this._scrollLock = false; this._debounceRelease = BI.debounce(function () { self._scrollLock = false; - }, 150); + }, 1000 / 60); this.container = BI.createWidget({ type: "bi.absolute" }); diff --git a/docs/base.js b/docs/base.js index 888d21cba..8c75b6e8e 100644 --- a/docs/base.js +++ b/docs/base.js @@ -2542,7 +2542,7 @@ BI.Collection = BI.inherit(BI.Widget, { this._scrollLock = false; this._debounceRelease = BI.debounce(function () { self._scrollLock = false; - }, 150); + }, 1000 / 60); this.container = BI.createWidget({ type: "bi.absolute" }); @@ -14616,7 +14616,7 @@ BI.Grid = BI.inherit(BI.Widget, { this._scrollLock = false; this._debounceRelease = BI.debounce(function () { self._scrollLock = false; - }, 150); + }, 1000 / 60); this.container = BI.createWidget({ type: "bi.absolute" }); diff --git a/src/base/collection/collection.js b/src/base/collection/collection.js index 62481e0f0..b9e358175 100644 --- a/src/base/collection/collection.js +++ b/src/base/collection/collection.js @@ -30,7 +30,7 @@ BI.Collection = BI.inherit(BI.Widget, { this._scrollLock = false; this._debounceRelease = BI.debounce(function () { self._scrollLock = false; - }, 150); + }, 1000 / 60); this.container = BI.createWidget({ type: "bi.absolute" }); diff --git a/src/base/grid/grid.js b/src/base/grid/grid.js index fdce627c3..e138e6622 100644 --- a/src/base/grid/grid.js +++ b/src/base/grid/grid.js @@ -33,7 +33,7 @@ BI.Grid = BI.inherit(BI.Widget, { this._scrollLock = false; this._debounceRelease = BI.debounce(function () { self._scrollLock = false; - }, 150); + }, 1000 / 60); this.container = BI.createWidget({ type: "bi.absolute" }); From f7b703a9433960da0b182fbbd1d1c1e0e1c3b6d3 Mon Sep 17 00:00:00 2001 From: guy Date: Fri, 12 May 2017 16:54:13 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E5=9B=BE=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bi/case.js | 18 +++++++++--------- bi/chart.js | 4 +++- docs/case.js | 18 +++++++++--------- docs/chart.js | 4 +++- src/addons/chart/chart.js | 4 +++- 5 files changed, 27 insertions(+), 21 deletions(-) diff --git a/bi/case.js b/bi/case.js index 7b4c962e3..163ac141d 100644 --- a/bi/case.js +++ b/bi/case.js @@ -9118,18 +9118,18 @@ BI.DynamicSummaryLayerTreeTable = BI.inherit(BI.Widget, { var vDeep = this._getVDeep(); var header = this._createHeader(vDeep); var data = this._formatItems(o.items, header, deep); - // var columnSize = o.columnSize.slice(); - // var minColumnSize = o.minColumnSize.slice(); - // var maxColumnSize = o.maxColumnSize.slice(); - // BI.removeAt(columnSize, data.deletedCols); - // BI.removeAt(minColumnSize, data.deletedCols); - // BI.removeAt(maxColumnSize, data.deletedCols); + var columnSize = o.columnSize.slice(); + var minColumnSize = o.minColumnSize.slice(); + var maxColumnSize = o.maxColumnSize.slice(); + BI.removeAt(columnSize, data.deletedCols); + BI.removeAt(minColumnSize, data.deletedCols); + BI.removeAt(maxColumnSize, data.deletedCols); return { header: data.header, items: data.items, - columnSize: this._formatColumnSize(o.columnSize, deep), - minColumnSize: this._formatColumns(o.minColumnSize, deep), - maxColumnSize: this._formatColumns(o.maxColumnSize, deep), + columnSize: this._formatColumnSize(columnSize, deep), + minColumnSize: this._formatColumns(minColumnSize, deep), + maxColumnSize: this._formatColumns(maxColumnSize, deep), freezeCols: this._formatFreezeCols() } }, diff --git a/bi/chart.js b/bi/chart.js index 4130d7a7a..b095fe2bb 100644 --- a/bi/chart.js +++ b/bi/chart.js @@ -19,7 +19,9 @@ BI.Chart = BI.inherit(BI.Pane, { this.vanCharts = VanCharts.init(self.element[0]); this._resizer = BI.debounce(function () { - self.vanCharts.resize(); + if (self.element.width() > 0 && self.element.height() > 0) { + self.vanCharts.resize(); + } }, 30); BI.ResizeDetector.addResizeListener(this, function (e) { self._resizer(); diff --git a/docs/case.js b/docs/case.js index 7b4c962e3..163ac141d 100644 --- a/docs/case.js +++ b/docs/case.js @@ -9118,18 +9118,18 @@ BI.DynamicSummaryLayerTreeTable = BI.inherit(BI.Widget, { var vDeep = this._getVDeep(); var header = this._createHeader(vDeep); var data = this._formatItems(o.items, header, deep); - // var columnSize = o.columnSize.slice(); - // var minColumnSize = o.minColumnSize.slice(); - // var maxColumnSize = o.maxColumnSize.slice(); - // BI.removeAt(columnSize, data.deletedCols); - // BI.removeAt(minColumnSize, data.deletedCols); - // BI.removeAt(maxColumnSize, data.deletedCols); + var columnSize = o.columnSize.slice(); + var minColumnSize = o.minColumnSize.slice(); + var maxColumnSize = o.maxColumnSize.slice(); + BI.removeAt(columnSize, data.deletedCols); + BI.removeAt(minColumnSize, data.deletedCols); + BI.removeAt(maxColumnSize, data.deletedCols); return { header: data.header, items: data.items, - columnSize: this._formatColumnSize(o.columnSize, deep), - minColumnSize: this._formatColumns(o.minColumnSize, deep), - maxColumnSize: this._formatColumns(o.maxColumnSize, deep), + columnSize: this._formatColumnSize(columnSize, deep), + minColumnSize: this._formatColumns(minColumnSize, deep), + maxColumnSize: this._formatColumns(maxColumnSize, deep), freezeCols: this._formatFreezeCols() } }, diff --git a/docs/chart.js b/docs/chart.js index 4130d7a7a..b095fe2bb 100644 --- a/docs/chart.js +++ b/docs/chart.js @@ -19,7 +19,9 @@ BI.Chart = BI.inherit(BI.Pane, { this.vanCharts = VanCharts.init(self.element[0]); this._resizer = BI.debounce(function () { - self.vanCharts.resize(); + if (self.element.width() > 0 && self.element.height() > 0) { + self.vanCharts.resize(); + } }, 30); BI.ResizeDetector.addResizeListener(this, function (e) { self._resizer(); diff --git a/src/addons/chart/chart.js b/src/addons/chart/chart.js index 7cb475339..cadcca0bc 100644 --- a/src/addons/chart/chart.js +++ b/src/addons/chart/chart.js @@ -19,7 +19,9 @@ BI.Chart = BI.inherit(BI.Pane, { this.vanCharts = VanCharts.init(self.element[0]); this._resizer = BI.debounce(function () { - self.vanCharts.resize(); + if (self.element.width() > 0 && self.element.height() > 0) { + self.vanCharts.resize(); + } }, 30); BI.ResizeDetector.addResizeListener(this, function (e) { self._resizer(); From f638558b0727cb72dfeb0b580743990af0a70c72 Mon Sep 17 00:00:00 2001 From: guy <141592Wc> Date: Sat, 13 May 2017 13:41:03 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E8=A1=A8=E6=A0=BC=E5=8A=A0=E5=85=A5?= =?UTF-8?q?=E6=A8=AA=E5=90=91=E6=BB=9A=E5=8A=A8=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bi/base.js | 139 +++++++++++++++++++---- docs/base.js | 139 +++++++++++++++++++---- src/base/table/table.collection.quick.js | 71 ++++++++++-- src/base/table/table.grid.quick.js | 68 +++++++++-- 4 files changed, 348 insertions(+), 69 deletions(-) diff --git a/bi/base.js b/bi/base.js index 8c75b6e8e..39be28e36 100644 --- a/bi/base.js +++ b/bi/base.js @@ -29036,26 +29036,54 @@ BI.QuickCollectionTable = BI.inherit(BI.CollectionTable, { mounted: function () { BI.QuickCollectionTable.superclass.mounted.apply(this, arguments); var self = this; - this._leftWheelHandler = new BI.WheelHandler( - BI.bind(this._onWheelY, this), - BI.bind(this._shouldHandleX, this), + this._topLeftWheelHandler = new BI.WheelHandler( + BI.bind(this._onWheelLeft, this), + BI.bind(this._shouldHandleLeftX, this), BI.bind(this._shouldHandleY, this) ); - this._rightWheelHandler = new BI.WheelHandler( - BI.bind(this._onWheelY, this), - BI.bind(this._shouldHandleX, this), + this._topRightWheelHandler = new BI.WheelHandler( + BI.bind(this._onWheelRight, this), + BI.bind(this._shouldHandleRightX, this), + BI.bind(this._shouldHandleY, this) + ); + this._bottomLeftWheelHandler = new BI.WheelHandler( + BI.bind(this._onWheelLeft, this), + BI.bind(this._shouldHandleLeftX, this), BI.bind(this._shouldHandleY, this) ); + this._bottomRightWheelHandler = new BI.WheelHandler( + BI.bind(this._onWheelRight, this), + BI.bind(this._shouldHandleRightX, this), + BI.bind(this._shouldHandleY, this) + ); + this.topLeftCollection.element.mousewheel(function (e) { + self._topLeftWheelHandler.onWheel(e.originalEvent); + }); + this.topRightCollection.element.mousewheel(function (e) { + self._topRightWheelHandler.onWheel(e.originalEvent); + }); this.bottomLeftCollection.element.mousewheel(function (e) { - self._leftWheelHandler.onWheel(e.originalEvent); + self._bottomLeftWheelHandler.onWheel(e.originalEvent); }); this.bottomRightCollection.element.mousewheel(function (e) { - self._rightWheelHandler.onWheel(e.originalEvent); + self._bottomRightWheelHandler.onWheel(e.originalEvent); }); }, - _shouldHandleX: function (delta) { - return false; + _shouldHandleLeftX: function (delta) { + if (delta > 0) { + return this.bottomLeftCollection.getScrollLeft() < this.bottomLeftCollection.getMaxScrollLeft(); + } else { + return this.bottomLeftCollection.getScrollLeft() > 0; + } + }, + + _shouldHandleRightX: function (delta) { + if (delta > 0) { + return this.bottomRightCollection.getScrollLeft() < this.bottomRightCollection.getMaxScrollLeft(); + } else { + return this.bottomRightCollection.getScrollLeft() > 0; + } }, _shouldHandleY: function (delta) { @@ -29066,19 +29094,38 @@ BI.QuickCollectionTable = BI.inherit(BI.CollectionTable, { } }, - _onWheelY: function (deltaX, deltaY) { + _onWheelLeft: function (deltaX, deltaY) { + var self = this; + var scrollTop = this.bottomLeftCollection.getScrollTop(); + var scrollLeft = this.bottomLeftCollection.getScrollLeft(); + scrollTop += deltaY; + scrollLeft += deltaX; + this.bottomLeftCollection.setScrollTop(scrollTop); + this.bottomRightCollection.setScrollTop(scrollTop); + this.topLeftCollection.setScrollLeft(scrollLeft); + this.bottomLeftCollection.setScrollLeft(scrollLeft); + self._populateScrollbar(); + this.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); + }, + + _onWheelRight: function (deltaX, deltaY) { var self = this; var scrollTop = this.bottomRightCollection.getScrollTop(); + var scrollLeft = this.bottomRightCollection.getScrollLeft(); scrollTop += deltaY; + scrollLeft += deltaX; this.bottomLeftCollection.setScrollTop(scrollTop); this.bottomRightCollection.setScrollTop(scrollTop); + this.topRightCollection.setScrollLeft(scrollLeft); + this.bottomRightCollection.setScrollLeft(scrollLeft); self._populateScrollbar(); this.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); }, _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)) { @@ -29691,26 +29738,54 @@ BI.QuickGridTable = BI.inherit(BI.GridTable, { mounted: function () { BI.QuickGridTable.superclass.mounted.apply(this, arguments); var self = this; - this._leftWheelHandler = new BI.WheelHandler( - BI.bind(this._onWheelY, this), - BI.bind(this._shouldHandleX, this), + this._topLeftWheelHandler = new BI.WheelHandler( + BI.bind(this._onWheelLeft, this), + BI.bind(this._shouldHandleLeftX, this), BI.bind(this._shouldHandleY, this) ); - this._rightWheelHandler = new BI.WheelHandler( - BI.bind(this._onWheelY, this), - BI.bind(this._shouldHandleX, this), + this._topRightWheelHandler = new BI.WheelHandler( + BI.bind(this._onWheelRight, this), + BI.bind(this._shouldHandleRightX, this), + BI.bind(this._shouldHandleY, this) + ); + this._bottomLeftWheelHandler = new BI.WheelHandler( + BI.bind(this._onWheelLeft, this), + BI.bind(this._shouldHandleLeftX, this), BI.bind(this._shouldHandleY, this) ); + this._bottomRightWheelHandler = new BI.WheelHandler( + BI.bind(this._onWheelRight, this), + BI.bind(this._shouldHandleRightX, this), + BI.bind(this._shouldHandleY, this) + ); + this.topLeftGrid.element.mousewheel(function (e) { + self._topLeftWheelHandler.onWheel(e.originalEvent); + }); + this.topRightGrid.element.mousewheel(function (e) { + self._topRightWheelHandler.onWheel(e.originalEvent); + }); this.bottomLeftGrid.element.mousewheel(function (e) { - self._leftWheelHandler.onWheel(e.originalEvent); + self._bottomLeftWheelHandler.onWheel(e.originalEvent); }); this.bottomRightGrid.element.mousewheel(function (e) { - self._rightWheelHandler.onWheel(e.originalEvent); + self._bottomRightWheelHandler.onWheel(e.originalEvent); }); }, - _shouldHandleX: function (delta) { - return false; + _shouldHandleLeftX: function (delta) { + if (delta > 0) { + return this.bottomLeftGrid.getScrollLeft() < this.bottomLeftGrid.getMaxScrollLeft(); + } else { + return this.bottomLeftGrid.getScrollLeft() > 0; + } + }, + + _shouldHandleRightX: function (delta) { + if (delta > 0) { + return this.bottomRightGrid.getScrollLeft() < this.bottomRightGrid.getMaxScrollLeft(); + } else { + return this.bottomRightGrid.getScrollLeft() > 0; + } }, _shouldHandleY: function (delta) { @@ -29721,12 +29796,30 @@ BI.QuickGridTable = BI.inherit(BI.GridTable, { } }, - _onWheelY: function (deltaX, deltaY) { + _onWheelLeft: function (deltaX, deltaY) { + var self = this; + var scrollTop = this.bottomLeftGrid.getScrollTop(); + var scrollLeft = this.bottomLeftGrid.getScrollLeft(); + scrollTop += deltaY; + scrollLeft += deltaX; + this.bottomLeftGrid.setScrollTop(scrollTop); + this.bottomRightGrid.setScrollTop(scrollTop); + this.topLeftGrid.setScrollLeft(scrollLeft); + this.bottomLeftGrid.setScrollLeft(scrollLeft); + self._populateScrollbar(); + this.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); + }, + + _onWheelRight: function (deltaX, deltaY) { var self = this; var scrollTop = this.bottomRightGrid.getScrollTop(); + var scrollLeft = this.bottomRightGrid.getScrollLeft(); scrollTop += deltaY; + scrollLeft += deltaX; this.bottomLeftGrid.setScrollTop(scrollTop); this.bottomRightGrid.setScrollTop(scrollTop); + this.topRightGrid.setScrollLeft(scrollLeft); + this.bottomRightGrid.setScrollLeft(scrollLeft); self._populateScrollbar(); this.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); }, diff --git a/docs/base.js b/docs/base.js index 8c75b6e8e..39be28e36 100644 --- a/docs/base.js +++ b/docs/base.js @@ -29036,26 +29036,54 @@ BI.QuickCollectionTable = BI.inherit(BI.CollectionTable, { mounted: function () { BI.QuickCollectionTable.superclass.mounted.apply(this, arguments); var self = this; - this._leftWheelHandler = new BI.WheelHandler( - BI.bind(this._onWheelY, this), - BI.bind(this._shouldHandleX, this), + this._topLeftWheelHandler = new BI.WheelHandler( + BI.bind(this._onWheelLeft, this), + BI.bind(this._shouldHandleLeftX, this), BI.bind(this._shouldHandleY, this) ); - this._rightWheelHandler = new BI.WheelHandler( - BI.bind(this._onWheelY, this), - BI.bind(this._shouldHandleX, this), + this._topRightWheelHandler = new BI.WheelHandler( + BI.bind(this._onWheelRight, this), + BI.bind(this._shouldHandleRightX, this), + BI.bind(this._shouldHandleY, this) + ); + this._bottomLeftWheelHandler = new BI.WheelHandler( + BI.bind(this._onWheelLeft, this), + BI.bind(this._shouldHandleLeftX, this), BI.bind(this._shouldHandleY, this) ); + this._bottomRightWheelHandler = new BI.WheelHandler( + BI.bind(this._onWheelRight, this), + BI.bind(this._shouldHandleRightX, this), + BI.bind(this._shouldHandleY, this) + ); + this.topLeftCollection.element.mousewheel(function (e) { + self._topLeftWheelHandler.onWheel(e.originalEvent); + }); + this.topRightCollection.element.mousewheel(function (e) { + self._topRightWheelHandler.onWheel(e.originalEvent); + }); this.bottomLeftCollection.element.mousewheel(function (e) { - self._leftWheelHandler.onWheel(e.originalEvent); + self._bottomLeftWheelHandler.onWheel(e.originalEvent); }); this.bottomRightCollection.element.mousewheel(function (e) { - self._rightWheelHandler.onWheel(e.originalEvent); + self._bottomRightWheelHandler.onWheel(e.originalEvent); }); }, - _shouldHandleX: function (delta) { - return false; + _shouldHandleLeftX: function (delta) { + if (delta > 0) { + return this.bottomLeftCollection.getScrollLeft() < this.bottomLeftCollection.getMaxScrollLeft(); + } else { + return this.bottomLeftCollection.getScrollLeft() > 0; + } + }, + + _shouldHandleRightX: function (delta) { + if (delta > 0) { + return this.bottomRightCollection.getScrollLeft() < this.bottomRightCollection.getMaxScrollLeft(); + } else { + return this.bottomRightCollection.getScrollLeft() > 0; + } }, _shouldHandleY: function (delta) { @@ -29066,19 +29094,38 @@ BI.QuickCollectionTable = BI.inherit(BI.CollectionTable, { } }, - _onWheelY: function (deltaX, deltaY) { + _onWheelLeft: function (deltaX, deltaY) { + var self = this; + var scrollTop = this.bottomLeftCollection.getScrollTop(); + var scrollLeft = this.bottomLeftCollection.getScrollLeft(); + scrollTop += deltaY; + scrollLeft += deltaX; + this.bottomLeftCollection.setScrollTop(scrollTop); + this.bottomRightCollection.setScrollTop(scrollTop); + this.topLeftCollection.setScrollLeft(scrollLeft); + this.bottomLeftCollection.setScrollLeft(scrollLeft); + self._populateScrollbar(); + this.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); + }, + + _onWheelRight: function (deltaX, deltaY) { var self = this; var scrollTop = this.bottomRightCollection.getScrollTop(); + var scrollLeft = this.bottomRightCollection.getScrollLeft(); scrollTop += deltaY; + scrollLeft += deltaX; this.bottomLeftCollection.setScrollTop(scrollTop); this.bottomRightCollection.setScrollTop(scrollTop); + this.topRightCollection.setScrollLeft(scrollLeft); + this.bottomRightCollection.setScrollLeft(scrollLeft); self._populateScrollbar(); this.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); }, _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)) { @@ -29691,26 +29738,54 @@ BI.QuickGridTable = BI.inherit(BI.GridTable, { mounted: function () { BI.QuickGridTable.superclass.mounted.apply(this, arguments); var self = this; - this._leftWheelHandler = new BI.WheelHandler( - BI.bind(this._onWheelY, this), - BI.bind(this._shouldHandleX, this), + this._topLeftWheelHandler = new BI.WheelHandler( + BI.bind(this._onWheelLeft, this), + BI.bind(this._shouldHandleLeftX, this), BI.bind(this._shouldHandleY, this) ); - this._rightWheelHandler = new BI.WheelHandler( - BI.bind(this._onWheelY, this), - BI.bind(this._shouldHandleX, this), + this._topRightWheelHandler = new BI.WheelHandler( + BI.bind(this._onWheelRight, this), + BI.bind(this._shouldHandleRightX, this), + BI.bind(this._shouldHandleY, this) + ); + this._bottomLeftWheelHandler = new BI.WheelHandler( + BI.bind(this._onWheelLeft, this), + BI.bind(this._shouldHandleLeftX, this), BI.bind(this._shouldHandleY, this) ); + this._bottomRightWheelHandler = new BI.WheelHandler( + BI.bind(this._onWheelRight, this), + BI.bind(this._shouldHandleRightX, this), + BI.bind(this._shouldHandleY, this) + ); + this.topLeftGrid.element.mousewheel(function (e) { + self._topLeftWheelHandler.onWheel(e.originalEvent); + }); + this.topRightGrid.element.mousewheel(function (e) { + self._topRightWheelHandler.onWheel(e.originalEvent); + }); this.bottomLeftGrid.element.mousewheel(function (e) { - self._leftWheelHandler.onWheel(e.originalEvent); + self._bottomLeftWheelHandler.onWheel(e.originalEvent); }); this.bottomRightGrid.element.mousewheel(function (e) { - self._rightWheelHandler.onWheel(e.originalEvent); + self._bottomRightWheelHandler.onWheel(e.originalEvent); }); }, - _shouldHandleX: function (delta) { - return false; + _shouldHandleLeftX: function (delta) { + if (delta > 0) { + return this.bottomLeftGrid.getScrollLeft() < this.bottomLeftGrid.getMaxScrollLeft(); + } else { + return this.bottomLeftGrid.getScrollLeft() > 0; + } + }, + + _shouldHandleRightX: function (delta) { + if (delta > 0) { + return this.bottomRightGrid.getScrollLeft() < this.bottomRightGrid.getMaxScrollLeft(); + } else { + return this.bottomRightGrid.getScrollLeft() > 0; + } }, _shouldHandleY: function (delta) { @@ -29721,12 +29796,30 @@ BI.QuickGridTable = BI.inherit(BI.GridTable, { } }, - _onWheelY: function (deltaX, deltaY) { + _onWheelLeft: function (deltaX, deltaY) { + var self = this; + var scrollTop = this.bottomLeftGrid.getScrollTop(); + var scrollLeft = this.bottomLeftGrid.getScrollLeft(); + scrollTop += deltaY; + scrollLeft += deltaX; + this.bottomLeftGrid.setScrollTop(scrollTop); + this.bottomRightGrid.setScrollTop(scrollTop); + this.topLeftGrid.setScrollLeft(scrollLeft); + this.bottomLeftGrid.setScrollLeft(scrollLeft); + self._populateScrollbar(); + this.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); + }, + + _onWheelRight: function (deltaX, deltaY) { var self = this; var scrollTop = this.bottomRightGrid.getScrollTop(); + var scrollLeft = this.bottomRightGrid.getScrollLeft(); scrollTop += deltaY; + scrollLeft += deltaX; this.bottomLeftGrid.setScrollTop(scrollTop); this.bottomRightGrid.setScrollTop(scrollTop); + this.topRightGrid.setScrollLeft(scrollLeft); + this.bottomRightGrid.setScrollLeft(scrollLeft); self._populateScrollbar(); this.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); }, diff --git a/src/base/table/table.collection.quick.js b/src/base/table/table.collection.quick.js index ab1cd926f..1e9565860 100644 --- a/src/base/table/table.collection.quick.js +++ b/src/base/table/table.collection.quick.js @@ -28,26 +28,54 @@ BI.QuickCollectionTable = BI.inherit(BI.CollectionTable, { mounted: function () { BI.QuickCollectionTable.superclass.mounted.apply(this, arguments); var self = this; - this._leftWheelHandler = new BI.WheelHandler( - BI.bind(this._onWheelY, this), - BI.bind(this._shouldHandleX, this), + this._topLeftWheelHandler = new BI.WheelHandler( + BI.bind(this._onWheelLeft, this), + BI.bind(this._shouldHandleLeftX, this), BI.bind(this._shouldHandleY, this) ); - this._rightWheelHandler = new BI.WheelHandler( - BI.bind(this._onWheelY, this), - BI.bind(this._shouldHandleX, this), + this._topRightWheelHandler = new BI.WheelHandler( + BI.bind(this._onWheelRight, this), + BI.bind(this._shouldHandleRightX, this), BI.bind(this._shouldHandleY, this) ); + this._bottomLeftWheelHandler = new BI.WheelHandler( + BI.bind(this._onWheelLeft, this), + BI.bind(this._shouldHandleLeftX, this), + BI.bind(this._shouldHandleY, this) + ); + this._bottomRightWheelHandler = new BI.WheelHandler( + BI.bind(this._onWheelRight, this), + BI.bind(this._shouldHandleRightX, this), + BI.bind(this._shouldHandleY, this) + ); + this.topLeftCollection.element.mousewheel(function (e) { + self._topLeftWheelHandler.onWheel(e.originalEvent); + }); + this.topRightCollection.element.mousewheel(function (e) { + self._topRightWheelHandler.onWheel(e.originalEvent); + }); this.bottomLeftCollection.element.mousewheel(function (e) { - self._leftWheelHandler.onWheel(e.originalEvent); + self._bottomLeftWheelHandler.onWheel(e.originalEvent); }); this.bottomRightCollection.element.mousewheel(function (e) { - self._rightWheelHandler.onWheel(e.originalEvent); + self._bottomRightWheelHandler.onWheel(e.originalEvent); }); }, - _shouldHandleX: function (delta) { - return false; + _shouldHandleLeftX: function (delta) { + if (delta > 0) { + return this.bottomLeftCollection.getScrollLeft() < this.bottomLeftCollection.getMaxScrollLeft(); + } else { + return this.bottomLeftCollection.getScrollLeft() > 0; + } + }, + + _shouldHandleRightX: function (delta) { + if (delta > 0) { + return this.bottomRightCollection.getScrollLeft() < this.bottomRightCollection.getMaxScrollLeft(); + } else { + return this.bottomRightCollection.getScrollLeft() > 0; + } }, _shouldHandleY: function (delta) { @@ -58,19 +86,38 @@ BI.QuickCollectionTable = BI.inherit(BI.CollectionTable, { } }, - _onWheelY: function (deltaX, deltaY) { + _onWheelLeft: function (deltaX, deltaY) { + var self = this; + var scrollTop = this.bottomLeftCollection.getScrollTop(); + var scrollLeft = this.bottomLeftCollection.getScrollLeft(); + scrollTop += deltaY; + scrollLeft += deltaX; + this.bottomLeftCollection.setScrollTop(scrollTop); + this.bottomRightCollection.setScrollTop(scrollTop); + this.topLeftCollection.setScrollLeft(scrollLeft); + this.bottomLeftCollection.setScrollLeft(scrollLeft); + self._populateScrollbar(); + this.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); + }, + + _onWheelRight: function (deltaX, deltaY) { var self = this; var scrollTop = this.bottomRightCollection.getScrollTop(); + var scrollLeft = this.bottomRightCollection.getScrollLeft(); scrollTop += deltaY; + scrollLeft += deltaX; this.bottomLeftCollection.setScrollTop(scrollTop); this.bottomRightCollection.setScrollTop(scrollTop); + this.topRightCollection.setScrollLeft(scrollLeft); + this.bottomRightCollection.setScrollLeft(scrollLeft); self._populateScrollbar(); this.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); }, _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)) { diff --git a/src/base/table/table.grid.quick.js b/src/base/table/table.grid.quick.js index 62e4a4a7e..8bd73149d 100644 --- a/src/base/table/table.grid.quick.js +++ b/src/base/table/table.grid.quick.js @@ -28,26 +28,54 @@ BI.QuickGridTable = BI.inherit(BI.GridTable, { mounted: function () { BI.QuickGridTable.superclass.mounted.apply(this, arguments); var self = this; - this._leftWheelHandler = new BI.WheelHandler( - BI.bind(this._onWheelY, this), - BI.bind(this._shouldHandleX, this), + this._topLeftWheelHandler = new BI.WheelHandler( + BI.bind(this._onWheelLeft, this), + BI.bind(this._shouldHandleLeftX, this), BI.bind(this._shouldHandleY, this) ); - this._rightWheelHandler = new BI.WheelHandler( - BI.bind(this._onWheelY, this), - BI.bind(this._shouldHandleX, this), + this._topRightWheelHandler = new BI.WheelHandler( + BI.bind(this._onWheelRight, this), + BI.bind(this._shouldHandleRightX, this), BI.bind(this._shouldHandleY, this) ); + this._bottomLeftWheelHandler = new BI.WheelHandler( + BI.bind(this._onWheelLeft, this), + BI.bind(this._shouldHandleLeftX, this), + BI.bind(this._shouldHandleY, this) + ); + this._bottomRightWheelHandler = new BI.WheelHandler( + BI.bind(this._onWheelRight, this), + BI.bind(this._shouldHandleRightX, this), + BI.bind(this._shouldHandleY, this) + ); + this.topLeftGrid.element.mousewheel(function (e) { + self._topLeftWheelHandler.onWheel(e.originalEvent); + }); + this.topRightGrid.element.mousewheel(function (e) { + self._topRightWheelHandler.onWheel(e.originalEvent); + }); this.bottomLeftGrid.element.mousewheel(function (e) { - self._leftWheelHandler.onWheel(e.originalEvent); + self._bottomLeftWheelHandler.onWheel(e.originalEvent); }); this.bottomRightGrid.element.mousewheel(function (e) { - self._rightWheelHandler.onWheel(e.originalEvent); + self._bottomRightWheelHandler.onWheel(e.originalEvent); }); }, - _shouldHandleX: function (delta) { - return false; + _shouldHandleLeftX: function (delta) { + if (delta > 0) { + return this.bottomLeftGrid.getScrollLeft() < this.bottomLeftGrid.getMaxScrollLeft(); + } else { + return this.bottomLeftGrid.getScrollLeft() > 0; + } + }, + + _shouldHandleRightX: function (delta) { + if (delta > 0) { + return this.bottomRightGrid.getScrollLeft() < this.bottomRightGrid.getMaxScrollLeft(); + } else { + return this.bottomRightGrid.getScrollLeft() > 0; + } }, _shouldHandleY: function (delta) { @@ -58,12 +86,30 @@ BI.QuickGridTable = BI.inherit(BI.GridTable, { } }, - _onWheelY: function (deltaX, deltaY) { + _onWheelLeft: function (deltaX, deltaY) { + var self = this; + var scrollTop = this.bottomLeftGrid.getScrollTop(); + var scrollLeft = this.bottomLeftGrid.getScrollLeft(); + scrollTop += deltaY; + scrollLeft += deltaX; + this.bottomLeftGrid.setScrollTop(scrollTop); + this.bottomRightGrid.setScrollTop(scrollTop); + this.topLeftGrid.setScrollLeft(scrollLeft); + this.bottomLeftGrid.setScrollLeft(scrollLeft); + self._populateScrollbar(); + this.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); + }, + + _onWheelRight: function (deltaX, deltaY) { var self = this; var scrollTop = this.bottomRightGrid.getScrollTop(); + var scrollLeft = this.bottomRightGrid.getScrollLeft(); scrollTop += deltaY; + scrollLeft += deltaX; this.bottomLeftGrid.setScrollTop(scrollTop); this.bottomRightGrid.setScrollTop(scrollTop); + this.topRightGrid.setScrollLeft(scrollLeft); + this.bottomRightGrid.setScrollLeft(scrollLeft); self._populateScrollbar(); this.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); }, From 3c9175eb659991d0af98d82f55ab2b7c18fb16ed Mon Sep 17 00:00:00 2001 From: guy Date: Sat, 13 May 2017 19:43:53 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E8=A1=A8=E6=A0=BC=E6=BB=9A=E5=8A=A8?= =?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 | 221 ++++++++++++++++++++---------- bi/core.js | 23 ++++ docs/base.js | 221 ++++++++++++++++++++---------- docs/core.js | 23 ++++ src/base/collection/collection.js | 193 +++++++++++++++++--------- src/base/grid/grid.js | 28 +++- src/core/base.js | 23 ++++ 7 files changed, 525 insertions(+), 207 deletions(-) diff --git a/bi/base.js b/bi/base.js index 39be28e36..ebf369c81 100644 --- a/bi/base.js +++ b/bi/base.js @@ -2539,6 +2539,7 @@ BI.Collection = BI.inherit(BI.Widget, { var self = this, o = this.options; this.renderedCells = []; this.renderedKeys = []; + this.renderRange = {}; this._scrollLock = false; this._debounceRelease = BI.debounce(function () { self._scrollLock = false; @@ -2588,12 +2589,10 @@ BI.Collection = BI.inherit(BI.Widget, { for (var index = 0, len = o.items.length; index < len; index++) { var cellMetadatum = o.cellSizeAndPositionGetter(index); - if ( - cellMetadatum.height == null || isNaN(cellMetadatum.height) || + if (cellMetadatum.height == null || isNaN(cellMetadatum.height) || cellMetadatum.width == null || isNaN(cellMetadatum.width) || cellMetadatum.x == null || isNaN(cellMetadatum.x) || - cellMetadatum.y == null || isNaN(cellMetadatum.y) - ) { + cellMetadatum.y == null || isNaN(cellMetadatum.y)) { throw Error(); } @@ -2634,75 +2633,134 @@ BI.Collection = BI.inherit(BI.Widget, { var top = Math.max(0, scrollTop - o.verticalOverscanSize); var right = Math.min(this._width, scrollLeft + o.width + o.horizontalOverscanSize); var bottom = Math.min(this._height, scrollTop + o.height + o.verticalOverscanSize); - var childrenToDisplay = this._cellRenderers(bottom - top, right - left, left, top); - var renderedCells = [], renderedKeys = []; - for (var i = 0, len = childrenToDisplay.length; i < len; i++) { - var datum = childrenToDisplay[i]; - var index = BI.deepIndexOf(this.renderedKeys, datum.index); - if (index > -1) { - if (datum.width !== this.renderedCells[index]._width) { - this.renderedCells[index]._width = datum.width; - this.renderedCells[index].el.setWidth(datum.width); + if (right > 0 && bottom > 0) { + //如果滚动的区间并没有超出渲染的范围 + if (top >= this.renderRange.minY && bottom <= this.renderRange.maxY && left >= this.renderRange.minX && right <= this.renderRange.maxX) { + return; + } + var childrenToDisplay = this._cellRenderers(bottom - top, right - left, left, top); + var renderedCells = [], renderedKeys = []; + //存储所有的left和top + var lefts = {}, tops = {}; + for (var i = 0, len = childrenToDisplay.length; i < len; i++) { + var datum = childrenToDisplay[i]; + lefts[datum.x] = datum.x; + lefts[datum.x + datum.width] = datum.x + datum.width; + tops[datum.y] = datum.y; + tops[datum.y + datum.height] = datum.y + datum.height; + } + lefts = BI.toArray(lefts); + tops = BI.toArray(tops); + var leftMap = BI.invert(lefts); + var topMap = BI.invert(tops); + //存储上下左右四个边界 + var leftBorder = {}, rightBorder = {}, topBorder = {}, bottomBorder = {}; + var assertMinBorder = function (border, offset) { + if (border[offset] == null) { + border[offset] = Number.MAX_VALUE; + } + }; + var assertMaxBorder = function (border, offset) { + if (border[offset] == null) { + border[offset] = 0; } - if (datum.height !== this.renderedCells[index]._height) { - this.renderedCells[index]._height = datum.height; - this.renderedCells[index].el.setHeight(datum.height); + }; + for (var i = 0, len = childrenToDisplay.length; i < len; i++) { + var datum = childrenToDisplay[i]; + var index = BI.deepIndexOf(this.renderedKeys, datum.index); + if (index > -1) { + if (datum.width !== this.renderedCells[index]._width) { + this.renderedCells[index]._width = datum.width; + this.renderedCells[index].el.setWidth(datum.width); + } + if (datum.height !== this.renderedCells[index]._height) { + this.renderedCells[index]._height = datum.height; + this.renderedCells[index].el.setHeight(datum.height); + } + if (this.renderedCells[index].left !== datum.x) { + this.renderedCells[index].el.element.css("left", datum.x + "px"); + } + if (this.renderedCells[index].top !== datum.y) { + this.renderedCells[index].el.element.css("top", datum.y + "px"); + } + renderedCells.push(this.renderedCells[index]); + } else { + var child = BI.createWidget(BI.extend({ + type: "bi.label", + width: datum.width, + height: datum.height + }, o.items[datum.index], { + cls: (o.items[datum.index].cls || "") + " container-cell" + (datum.y === 0 ? " first-row" : "") + (datum.x === 0 ? " first-col" : ""), + _left: datum.x, + _top: datum.y + })); + renderedCells.push({ + el: child, + left: datum.x, + top: datum.y, + _width: datum.width, + _height: datum.height + }); } - if (this.renderedCells[index].left !== datum.x) { - this.renderedCells[index].el.element.css("left", datum.x + "px"); + var startTopIndex = topMap[datum.y] | 0; + var endTopIndex = topMap[datum.y + datum.height] | 0; + for (var k = startTopIndex; k <= endTopIndex; k++) { + var t = tops[k]; + assertMinBorder(leftBorder, t); + assertMaxBorder(rightBorder, t); + leftBorder[t] = Math.min(leftBorder[t], datum.x); + rightBorder[t] = Math.max(rightBorder[t], datum.x + datum.width); } - if (this.renderedCells[index].top !== datum.y) { - this.renderedCells[index].el.element.css("top", datum.y + "px"); + var startLeftIndex = leftMap[datum.x] | 0; + var endLeftIndex = leftMap[datum.x + datum.width] | 0; + for (var k = startLeftIndex; k <= endLeftIndex; k++) { + var l = lefts[k]; + assertMinBorder(topBorder, l); + assertMaxBorder(bottomBorder, l); + topBorder[l] = Math.min(topBorder[l], datum.y); + bottomBorder[l] = Math.max(bottomBorder[l], datum.y + datum.height); } - renderedCells.push(this.renderedCells[index]); - } else { - var child = BI.createWidget(BI.extend({ - type: "bi.label", - width: datum.width, - height: datum.height - }, o.items[datum.index], { - cls: (o.items[datum.index].cls || "") + " container-cell" + (datum.y === 0 ? " first-row" : "") + (datum.x === 0 ? " first-col" : ""), - _left: datum.x, - _top: datum.y - })); - renderedCells.push({ - el: child, - left: datum.x, - top: datum.y, - _width: datum.width, - _height: datum.height - }); + + renderedKeys.push(datum.index); } - renderedKeys.push(datum.index); + //已存在的, 需要添加的和需要删除的 + var existSet = {}, addSet = {}, deleteArray = []; + BI.each(renderedKeys, function (i, key) { + if (BI.deepContains(self.renderedKeys, key)) { + existSet[i] = key; + } else { + addSet[i] = key; + } + }); + BI.each(this.renderedKeys, function (i, key) { + if (BI.deepContains(existSet, key)) { + return; + } + if (BI.deepContains(addSet, key)) { + return; + } + deleteArray.push(i); + }); + BI.each(deleteArray, function (i, index) { + self.renderedCells[index].el.destroy(); + }); + var addedItems = []; + BI.each(addSet, function (index) { + addedItems.push(renderedCells[index]) + }); + this.container.addItems(addedItems); + this.renderedCells = renderedCells; + this.renderedKeys = renderedKeys; + + //Todo 左右比较特殊 + var minX = BI.min(leftBorder); + var maxX = BI.max(rightBorder); + + var minY = BI.max(topBorder); + var maxY = BI.min(bottomBorder); + + this.renderRange = {minX: minX, minY: minY, maxX: maxX, maxY: maxY}; } - //已存在的, 需要添加的和需要删除的 - var existSet = {}, addSet = {}, deleteArray = []; - BI.each(renderedKeys, function (i, key) { - if (BI.deepContains(self.renderedKeys, key)) { - existSet[i] = key; - } else { - addSet[i] = key; - } - }); - BI.each(this.renderedKeys, function (i, key) { - if (BI.deepContains(existSet, key)) { - return; - } - if (BI.deepContains(addSet, key)) { - return; - } - deleteArray.push(i); - }); - BI.each(deleteArray, function (i, index) { - self.renderedCells[index].el.destroy(); - }); - var addedItems = []; - BI.each(addSet, function (index) { - addedItems.push(renderedCells[index]) - }); - this.container.addItems(addedItems); - this.renderedCells = renderedCells; - this.renderedKeys = renderedKeys; }, _getMaxScrollLeft: function () { @@ -2789,6 +2847,7 @@ BI.Collection = BI.inherit(BI.Widget, { }); this.renderedCells = []; this.renderedKeys = []; + this.renderRange = {}; this._scrollLock = false; }, @@ -14613,6 +14672,7 @@ BI.Grid = BI.inherit(BI.Widget, { var self = this, o = this.options; this.renderedCells = []; this.renderedKeys = []; + this.renderRange = {}; this._scrollLock = false; this._debounceRelease = BI.debounce(function () { self._scrollLock = false; @@ -14661,13 +14721,17 @@ BI.Grid = BI.inherit(BI.Widget, { _calculateChildrenToRender: function () { var self = this, o = this.options; - var width = o.width, height = o.height, scrollLeft = BI.clamp(o.scrollLeft, 0, this._getMaxScrollLeft()), scrollTop = BI.clamp(o.scrollTop, 0, this._getMaxScrollTop()), + var width = o.width, height = o.height, scrollLeft = BI.clamp(o.scrollLeft, 0, this._getMaxScrollLeft()), + scrollTop = BI.clamp(o.scrollTop, 0, this._getMaxScrollTop()), overscanColumnCount = o.overscanColumnCount, overscanRowCount = o.overscanRowCount; if (height > 0 && width > 0) { var visibleColumnIndices = this._columnSizeAndPositionManager.getVisibleCellRange(width, scrollLeft); var visibleRowIndices = this._rowSizeAndPositionManager.getVisibleCellRange(height, scrollTop); + if (BI.isEmpty(visibleColumnIndices) || BI.isEmpty(visibleRowIndices)) { + return; + } var horizontalOffsetAdjustment = this._columnSizeAndPositionManager.getOffsetAdjustment(width, scrollLeft); var verticalOffsetAdjustment = this._rowSizeAndPositionManager.getOffsetAdjustment(height, scrollTop); @@ -14685,8 +14749,22 @@ BI.Grid = BI.inherit(BI.Widget, { var rowStartIndex = overscanRowIndices.overscanStartIndex; var rowStopIndex = overscanRowIndices.overscanStopIndex; - var renderedCells = [], renderedKeys = []; + //算区间size + var minRowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowStartIndex); + var minColumnDatum = this._columnSizeAndPositionManager.getSizeAndPositionOfCell(columnStartIndex); + var maxRowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowStopIndex); + var maxColumnDatum = this._columnSizeAndPositionManager.getSizeAndPositionOfCell(columnStopIndex); + var top = minRowDatum.offset + verticalOffsetAdjustment; + var left = minColumnDatum.offset + horizontalOffsetAdjustment; + var bottom = maxRowDatum.offset + verticalOffsetAdjustment + maxRowDatum.size; + var right = maxColumnDatum.offset + horizontalOffsetAdjustment + maxColumnDatum.size; + //如果滚动的区间并没有超出渲染的范围 + if (top >= this.renderRange.minY && bottom <= this.renderRange.maxY && left >= this.renderRange.minX && right <= this.renderRange.maxX) { + return; + } + var renderedCells = [], renderedKeys = []; + var minX = this._getMaxScrollLeft(), minY = this._getMaxScrollTop(), maxX = 0, maxY = 0; for (var rowIndex = rowStartIndex; rowIndex <= rowStopIndex; rowIndex++) { var rowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowIndex); @@ -14731,6 +14809,10 @@ BI.Grid = BI.inherit(BI.Widget, { _height: rowDatum.size }); } + minX = Math.min(minX, columnDatum.offset + horizontalOffsetAdjustment); + maxX = Math.max(maxX, columnDatum.offset + horizontalOffsetAdjustment + columnDatum.size); + minY = Math.min(minY, rowDatum.offset + verticalOffsetAdjustment); + maxY = Math.max(maxY, rowDatum.offset + verticalOffsetAdjustment + rowDatum.size); renderedKeys.push(key); } } @@ -14762,6 +14844,7 @@ BI.Grid = BI.inherit(BI.Widget, { this.container.addItems(addedItems); this.renderedCells = renderedCells; this.renderedKeys = renderedKeys; + this.renderRange = {minX: minX, minY: minY, maxX: maxX, maxY: maxY}; } }, diff --git a/bi/core.js b/bi/core.js index 494b9d052..5de694e03 100644 --- a/bi/core.js +++ b/bi/core.js @@ -2163,6 +2163,29 @@ if (!window.BI) { return true; }, + backFindKey: function (obj, predicate, context) { + predicate = BI.iteratee(predicate, context); + var keys = _.keys(obj), key; + for (var i = keys.length - 1; i >= 0; i--) { + key = keys[i]; + if (predicate(obj[key], key, obj)) { + return key; + } + } + }, + + backFind: function (obj, predicate, context) { + var key; + if (BI.isArray(obj)) { + key = BI.findLastIndex(obj, predicate, context); + } else { + key = BI.backFindKey(obj, predicate, context); + } + if (key !== void 0 && key !== -1) { + return obj[key]; + } + }, + remove: function (obj, target, context) { var isFunction = BI.isFunction(target); target = isFunction || BI.isArray(target) ? target : [target]; diff --git a/docs/base.js b/docs/base.js index 39be28e36..ebf369c81 100644 --- a/docs/base.js +++ b/docs/base.js @@ -2539,6 +2539,7 @@ BI.Collection = BI.inherit(BI.Widget, { var self = this, o = this.options; this.renderedCells = []; this.renderedKeys = []; + this.renderRange = {}; this._scrollLock = false; this._debounceRelease = BI.debounce(function () { self._scrollLock = false; @@ -2588,12 +2589,10 @@ BI.Collection = BI.inherit(BI.Widget, { for (var index = 0, len = o.items.length; index < len; index++) { var cellMetadatum = o.cellSizeAndPositionGetter(index); - if ( - cellMetadatum.height == null || isNaN(cellMetadatum.height) || + if (cellMetadatum.height == null || isNaN(cellMetadatum.height) || cellMetadatum.width == null || isNaN(cellMetadatum.width) || cellMetadatum.x == null || isNaN(cellMetadatum.x) || - cellMetadatum.y == null || isNaN(cellMetadatum.y) - ) { + cellMetadatum.y == null || isNaN(cellMetadatum.y)) { throw Error(); } @@ -2634,75 +2633,134 @@ BI.Collection = BI.inherit(BI.Widget, { var top = Math.max(0, scrollTop - o.verticalOverscanSize); var right = Math.min(this._width, scrollLeft + o.width + o.horizontalOverscanSize); var bottom = Math.min(this._height, scrollTop + o.height + o.verticalOverscanSize); - var childrenToDisplay = this._cellRenderers(bottom - top, right - left, left, top); - var renderedCells = [], renderedKeys = []; - for (var i = 0, len = childrenToDisplay.length; i < len; i++) { - var datum = childrenToDisplay[i]; - var index = BI.deepIndexOf(this.renderedKeys, datum.index); - if (index > -1) { - if (datum.width !== this.renderedCells[index]._width) { - this.renderedCells[index]._width = datum.width; - this.renderedCells[index].el.setWidth(datum.width); + if (right > 0 && bottom > 0) { + //如果滚动的区间并没有超出渲染的范围 + if (top >= this.renderRange.minY && bottom <= this.renderRange.maxY && left >= this.renderRange.minX && right <= this.renderRange.maxX) { + return; + } + var childrenToDisplay = this._cellRenderers(bottom - top, right - left, left, top); + var renderedCells = [], renderedKeys = []; + //存储所有的left和top + var lefts = {}, tops = {}; + for (var i = 0, len = childrenToDisplay.length; i < len; i++) { + var datum = childrenToDisplay[i]; + lefts[datum.x] = datum.x; + lefts[datum.x + datum.width] = datum.x + datum.width; + tops[datum.y] = datum.y; + tops[datum.y + datum.height] = datum.y + datum.height; + } + lefts = BI.toArray(lefts); + tops = BI.toArray(tops); + var leftMap = BI.invert(lefts); + var topMap = BI.invert(tops); + //存储上下左右四个边界 + var leftBorder = {}, rightBorder = {}, topBorder = {}, bottomBorder = {}; + var assertMinBorder = function (border, offset) { + if (border[offset] == null) { + border[offset] = Number.MAX_VALUE; + } + }; + var assertMaxBorder = function (border, offset) { + if (border[offset] == null) { + border[offset] = 0; } - if (datum.height !== this.renderedCells[index]._height) { - this.renderedCells[index]._height = datum.height; - this.renderedCells[index].el.setHeight(datum.height); + }; + for (var i = 0, len = childrenToDisplay.length; i < len; i++) { + var datum = childrenToDisplay[i]; + var index = BI.deepIndexOf(this.renderedKeys, datum.index); + if (index > -1) { + if (datum.width !== this.renderedCells[index]._width) { + this.renderedCells[index]._width = datum.width; + this.renderedCells[index].el.setWidth(datum.width); + } + if (datum.height !== this.renderedCells[index]._height) { + this.renderedCells[index]._height = datum.height; + this.renderedCells[index].el.setHeight(datum.height); + } + if (this.renderedCells[index].left !== datum.x) { + this.renderedCells[index].el.element.css("left", datum.x + "px"); + } + if (this.renderedCells[index].top !== datum.y) { + this.renderedCells[index].el.element.css("top", datum.y + "px"); + } + renderedCells.push(this.renderedCells[index]); + } else { + var child = BI.createWidget(BI.extend({ + type: "bi.label", + width: datum.width, + height: datum.height + }, o.items[datum.index], { + cls: (o.items[datum.index].cls || "") + " container-cell" + (datum.y === 0 ? " first-row" : "") + (datum.x === 0 ? " first-col" : ""), + _left: datum.x, + _top: datum.y + })); + renderedCells.push({ + el: child, + left: datum.x, + top: datum.y, + _width: datum.width, + _height: datum.height + }); } - if (this.renderedCells[index].left !== datum.x) { - this.renderedCells[index].el.element.css("left", datum.x + "px"); + var startTopIndex = topMap[datum.y] | 0; + var endTopIndex = topMap[datum.y + datum.height] | 0; + for (var k = startTopIndex; k <= endTopIndex; k++) { + var t = tops[k]; + assertMinBorder(leftBorder, t); + assertMaxBorder(rightBorder, t); + leftBorder[t] = Math.min(leftBorder[t], datum.x); + rightBorder[t] = Math.max(rightBorder[t], datum.x + datum.width); } - if (this.renderedCells[index].top !== datum.y) { - this.renderedCells[index].el.element.css("top", datum.y + "px"); + var startLeftIndex = leftMap[datum.x] | 0; + var endLeftIndex = leftMap[datum.x + datum.width] | 0; + for (var k = startLeftIndex; k <= endLeftIndex; k++) { + var l = lefts[k]; + assertMinBorder(topBorder, l); + assertMaxBorder(bottomBorder, l); + topBorder[l] = Math.min(topBorder[l], datum.y); + bottomBorder[l] = Math.max(bottomBorder[l], datum.y + datum.height); } - renderedCells.push(this.renderedCells[index]); - } else { - var child = BI.createWidget(BI.extend({ - type: "bi.label", - width: datum.width, - height: datum.height - }, o.items[datum.index], { - cls: (o.items[datum.index].cls || "") + " container-cell" + (datum.y === 0 ? " first-row" : "") + (datum.x === 0 ? " first-col" : ""), - _left: datum.x, - _top: datum.y - })); - renderedCells.push({ - el: child, - left: datum.x, - top: datum.y, - _width: datum.width, - _height: datum.height - }); + + renderedKeys.push(datum.index); } - renderedKeys.push(datum.index); + //已存在的, 需要添加的和需要删除的 + var existSet = {}, addSet = {}, deleteArray = []; + BI.each(renderedKeys, function (i, key) { + if (BI.deepContains(self.renderedKeys, key)) { + existSet[i] = key; + } else { + addSet[i] = key; + } + }); + BI.each(this.renderedKeys, function (i, key) { + if (BI.deepContains(existSet, key)) { + return; + } + if (BI.deepContains(addSet, key)) { + return; + } + deleteArray.push(i); + }); + BI.each(deleteArray, function (i, index) { + self.renderedCells[index].el.destroy(); + }); + var addedItems = []; + BI.each(addSet, function (index) { + addedItems.push(renderedCells[index]) + }); + this.container.addItems(addedItems); + this.renderedCells = renderedCells; + this.renderedKeys = renderedKeys; + + //Todo 左右比较特殊 + var minX = BI.min(leftBorder); + var maxX = BI.max(rightBorder); + + var minY = BI.max(topBorder); + var maxY = BI.min(bottomBorder); + + this.renderRange = {minX: minX, minY: minY, maxX: maxX, maxY: maxY}; } - //已存在的, 需要添加的和需要删除的 - var existSet = {}, addSet = {}, deleteArray = []; - BI.each(renderedKeys, function (i, key) { - if (BI.deepContains(self.renderedKeys, key)) { - existSet[i] = key; - } else { - addSet[i] = key; - } - }); - BI.each(this.renderedKeys, function (i, key) { - if (BI.deepContains(existSet, key)) { - return; - } - if (BI.deepContains(addSet, key)) { - return; - } - deleteArray.push(i); - }); - BI.each(deleteArray, function (i, index) { - self.renderedCells[index].el.destroy(); - }); - var addedItems = []; - BI.each(addSet, function (index) { - addedItems.push(renderedCells[index]) - }); - this.container.addItems(addedItems); - this.renderedCells = renderedCells; - this.renderedKeys = renderedKeys; }, _getMaxScrollLeft: function () { @@ -2789,6 +2847,7 @@ BI.Collection = BI.inherit(BI.Widget, { }); this.renderedCells = []; this.renderedKeys = []; + this.renderRange = {}; this._scrollLock = false; }, @@ -14613,6 +14672,7 @@ BI.Grid = BI.inherit(BI.Widget, { var self = this, o = this.options; this.renderedCells = []; this.renderedKeys = []; + this.renderRange = {}; this._scrollLock = false; this._debounceRelease = BI.debounce(function () { self._scrollLock = false; @@ -14661,13 +14721,17 @@ BI.Grid = BI.inherit(BI.Widget, { _calculateChildrenToRender: function () { var self = this, o = this.options; - var width = o.width, height = o.height, scrollLeft = BI.clamp(o.scrollLeft, 0, this._getMaxScrollLeft()), scrollTop = BI.clamp(o.scrollTop, 0, this._getMaxScrollTop()), + var width = o.width, height = o.height, scrollLeft = BI.clamp(o.scrollLeft, 0, this._getMaxScrollLeft()), + scrollTop = BI.clamp(o.scrollTop, 0, this._getMaxScrollTop()), overscanColumnCount = o.overscanColumnCount, overscanRowCount = o.overscanRowCount; if (height > 0 && width > 0) { var visibleColumnIndices = this._columnSizeAndPositionManager.getVisibleCellRange(width, scrollLeft); var visibleRowIndices = this._rowSizeAndPositionManager.getVisibleCellRange(height, scrollTop); + if (BI.isEmpty(visibleColumnIndices) || BI.isEmpty(visibleRowIndices)) { + return; + } var horizontalOffsetAdjustment = this._columnSizeAndPositionManager.getOffsetAdjustment(width, scrollLeft); var verticalOffsetAdjustment = this._rowSizeAndPositionManager.getOffsetAdjustment(height, scrollTop); @@ -14685,8 +14749,22 @@ BI.Grid = BI.inherit(BI.Widget, { var rowStartIndex = overscanRowIndices.overscanStartIndex; var rowStopIndex = overscanRowIndices.overscanStopIndex; - var renderedCells = [], renderedKeys = []; + //算区间size + var minRowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowStartIndex); + var minColumnDatum = this._columnSizeAndPositionManager.getSizeAndPositionOfCell(columnStartIndex); + var maxRowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowStopIndex); + var maxColumnDatum = this._columnSizeAndPositionManager.getSizeAndPositionOfCell(columnStopIndex); + var top = minRowDatum.offset + verticalOffsetAdjustment; + var left = minColumnDatum.offset + horizontalOffsetAdjustment; + var bottom = maxRowDatum.offset + verticalOffsetAdjustment + maxRowDatum.size; + var right = maxColumnDatum.offset + horizontalOffsetAdjustment + maxColumnDatum.size; + //如果滚动的区间并没有超出渲染的范围 + if (top >= this.renderRange.minY && bottom <= this.renderRange.maxY && left >= this.renderRange.minX && right <= this.renderRange.maxX) { + return; + } + var renderedCells = [], renderedKeys = []; + var minX = this._getMaxScrollLeft(), minY = this._getMaxScrollTop(), maxX = 0, maxY = 0; for (var rowIndex = rowStartIndex; rowIndex <= rowStopIndex; rowIndex++) { var rowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowIndex); @@ -14731,6 +14809,10 @@ BI.Grid = BI.inherit(BI.Widget, { _height: rowDatum.size }); } + minX = Math.min(minX, columnDatum.offset + horizontalOffsetAdjustment); + maxX = Math.max(maxX, columnDatum.offset + horizontalOffsetAdjustment + columnDatum.size); + minY = Math.min(minY, rowDatum.offset + verticalOffsetAdjustment); + maxY = Math.max(maxY, rowDatum.offset + verticalOffsetAdjustment + rowDatum.size); renderedKeys.push(key); } } @@ -14762,6 +14844,7 @@ BI.Grid = BI.inherit(BI.Widget, { this.container.addItems(addedItems); this.renderedCells = renderedCells; this.renderedKeys = renderedKeys; + this.renderRange = {minX: minX, minY: minY, maxX: maxX, maxY: maxY}; } }, diff --git a/docs/core.js b/docs/core.js index 0bd912d24..49809986e 100644 --- a/docs/core.js +++ b/docs/core.js @@ -13305,6 +13305,29 @@ if (!window.BI) { return true; }, + backFindKey: function (obj, predicate, context) { + predicate = BI.iteratee(predicate, context); + var keys = _.keys(obj), key; + for (var i = keys.length - 1; i >= 0; i--) { + key = keys[i]; + if (predicate(obj[key], key, obj)) { + return key; + } + } + }, + + backFind: function (obj, predicate, context) { + var key; + if (BI.isArray(obj)) { + key = BI.findLastIndex(obj, predicate, context); + } else { + key = BI.backFindKey(obj, predicate, context); + } + if (key !== void 0 && key !== -1) { + return obj[key]; + } + }, + remove: function (obj, target, context) { var isFunction = BI.isFunction(target); target = isFunction || BI.isArray(target) ? target : [target]; diff --git a/src/base/collection/collection.js b/src/base/collection/collection.js index b9e358175..f830cb050 100644 --- a/src/base/collection/collection.js +++ b/src/base/collection/collection.js @@ -27,6 +27,7 @@ BI.Collection = BI.inherit(BI.Widget, { var self = this, o = this.options; this.renderedCells = []; this.renderedKeys = []; + this.renderRange = {}; this._scrollLock = false; this._debounceRelease = BI.debounce(function () { self._scrollLock = false; @@ -76,12 +77,10 @@ BI.Collection = BI.inherit(BI.Widget, { for (var index = 0, len = o.items.length; index < len; index++) { var cellMetadatum = o.cellSizeAndPositionGetter(index); - if ( - cellMetadatum.height == null || isNaN(cellMetadatum.height) || + if (cellMetadatum.height == null || isNaN(cellMetadatum.height) || cellMetadatum.width == null || isNaN(cellMetadatum.width) || cellMetadatum.x == null || isNaN(cellMetadatum.x) || - cellMetadatum.y == null || isNaN(cellMetadatum.y) - ) { + cellMetadatum.y == null || isNaN(cellMetadatum.y)) { throw Error(); } @@ -122,75 +121,134 @@ BI.Collection = BI.inherit(BI.Widget, { var top = Math.max(0, scrollTop - o.verticalOverscanSize); var right = Math.min(this._width, scrollLeft + o.width + o.horizontalOverscanSize); var bottom = Math.min(this._height, scrollTop + o.height + o.verticalOverscanSize); - var childrenToDisplay = this._cellRenderers(bottom - top, right - left, left, top); - var renderedCells = [], renderedKeys = []; - for (var i = 0, len = childrenToDisplay.length; i < len; i++) { - var datum = childrenToDisplay[i]; - var index = BI.deepIndexOf(this.renderedKeys, datum.index); - if (index > -1) { - if (datum.width !== this.renderedCells[index]._width) { - this.renderedCells[index]._width = datum.width; - this.renderedCells[index].el.setWidth(datum.width); + if (right > 0 && bottom > 0) { + //如果滚动的区间并没有超出渲染的范围 + if (top >= this.renderRange.minY && bottom <= this.renderRange.maxY && left >= this.renderRange.minX && right <= this.renderRange.maxX) { + return; + } + var childrenToDisplay = this._cellRenderers(bottom - top, right - left, left, top); + var renderedCells = [], renderedKeys = []; + //存储所有的left和top + var lefts = {}, tops = {}; + for (var i = 0, len = childrenToDisplay.length; i < len; i++) { + var datum = childrenToDisplay[i]; + lefts[datum.x] = datum.x; + lefts[datum.x + datum.width] = datum.x + datum.width; + tops[datum.y] = datum.y; + tops[datum.y + datum.height] = datum.y + datum.height; + } + lefts = BI.toArray(lefts); + tops = BI.toArray(tops); + var leftMap = BI.invert(lefts); + var topMap = BI.invert(tops); + //存储上下左右四个边界 + var leftBorder = {}, rightBorder = {}, topBorder = {}, bottomBorder = {}; + var assertMinBorder = function (border, offset) { + if (border[offset] == null) { + border[offset] = Number.MAX_VALUE; } - if (datum.height !== this.renderedCells[index]._height) { - this.renderedCells[index]._height = datum.height; - this.renderedCells[index].el.setHeight(datum.height); + }; + var assertMaxBorder = function (border, offset) { + if (border[offset] == null) { + border[offset] = 0; } - if (this.renderedCells[index].left !== datum.x) { - this.renderedCells[index].el.element.css("left", datum.x + "px"); + }; + for (var i = 0, len = childrenToDisplay.length; i < len; i++) { + var datum = childrenToDisplay[i]; + var index = BI.deepIndexOf(this.renderedKeys, datum.index); + if (index > -1) { + if (datum.width !== this.renderedCells[index]._width) { + this.renderedCells[index]._width = datum.width; + this.renderedCells[index].el.setWidth(datum.width); + } + if (datum.height !== this.renderedCells[index]._height) { + this.renderedCells[index]._height = datum.height; + this.renderedCells[index].el.setHeight(datum.height); + } + if (this.renderedCells[index].left !== datum.x) { + this.renderedCells[index].el.element.css("left", datum.x + "px"); + } + if (this.renderedCells[index].top !== datum.y) { + this.renderedCells[index].el.element.css("top", datum.y + "px"); + } + renderedCells.push(this.renderedCells[index]); + } else { + var child = BI.createWidget(BI.extend({ + type: "bi.label", + width: datum.width, + height: datum.height + }, o.items[datum.index], { + cls: (o.items[datum.index].cls || "") + " container-cell" + (datum.y === 0 ? " first-row" : "") + (datum.x === 0 ? " first-col" : ""), + _left: datum.x, + _top: datum.y + })); + renderedCells.push({ + el: child, + left: datum.x, + top: datum.y, + _width: datum.width, + _height: datum.height + }); } - if (this.renderedCells[index].top !== datum.y) { - this.renderedCells[index].el.element.css("top", datum.y + "px"); + var startTopIndex = topMap[datum.y] | 0; + var endTopIndex = topMap[datum.y + datum.height] | 0; + for (var k = startTopIndex; k <= endTopIndex; k++) { + var t = tops[k]; + assertMinBorder(leftBorder, t); + assertMaxBorder(rightBorder, t); + leftBorder[t] = Math.min(leftBorder[t], datum.x); + rightBorder[t] = Math.max(rightBorder[t], datum.x + datum.width); } - renderedCells.push(this.renderedCells[index]); - } else { - var child = BI.createWidget(BI.extend({ - type: "bi.label", - width: datum.width, - height: datum.height - }, o.items[datum.index], { - cls: (o.items[datum.index].cls || "") + " container-cell" + (datum.y === 0 ? " first-row" : "") + (datum.x === 0 ? " first-col" : ""), - _left: datum.x, - _top: datum.y - })); - renderedCells.push({ - el: child, - left: datum.x, - top: datum.y, - _width: datum.width, - _height: datum.height - }); + var startLeftIndex = leftMap[datum.x] | 0; + var endLeftIndex = leftMap[datum.x + datum.width] | 0; + for (var k = startLeftIndex; k <= endLeftIndex; k++) { + var l = lefts[k]; + assertMinBorder(topBorder, l); + assertMaxBorder(bottomBorder, l); + topBorder[l] = Math.min(topBorder[l], datum.y); + bottomBorder[l] = Math.max(bottomBorder[l], datum.y + datum.height); + } + + renderedKeys.push(datum.index); } - renderedKeys.push(datum.index); + //已存在的, 需要添加的和需要删除的 + var existSet = {}, addSet = {}, deleteArray = []; + BI.each(renderedKeys, function (i, key) { + if (BI.deepContains(self.renderedKeys, key)) { + existSet[i] = key; + } else { + addSet[i] = key; + } + }); + BI.each(this.renderedKeys, function (i, key) { + if (BI.deepContains(existSet, key)) { + return; + } + if (BI.deepContains(addSet, key)) { + return; + } + deleteArray.push(i); + }); + BI.each(deleteArray, function (i, index) { + self.renderedCells[index].el.destroy(); + }); + var addedItems = []; + BI.each(addSet, function (index) { + addedItems.push(renderedCells[index]) + }); + this.container.addItems(addedItems); + this.renderedCells = renderedCells; + this.renderedKeys = renderedKeys; + + //Todo 左右比较特殊 + var minX = BI.min(leftBorder); + var maxX = BI.max(rightBorder); + + var minY = BI.max(topBorder); + var maxY = BI.min(bottomBorder); + + this.renderRange = {minX: minX, minY: minY, maxX: maxX, maxY: maxY}; } - //已存在的, 需要添加的和需要删除的 - var existSet = {}, addSet = {}, deleteArray = []; - BI.each(renderedKeys, function (i, key) { - if (BI.deepContains(self.renderedKeys, key)) { - existSet[i] = key; - } else { - addSet[i] = key; - } - }); - BI.each(this.renderedKeys, function (i, key) { - if (BI.deepContains(existSet, key)) { - return; - } - if (BI.deepContains(addSet, key)) { - return; - } - deleteArray.push(i); - }); - BI.each(deleteArray, function (i, index) { - self.renderedCells[index].el.destroy(); - }); - var addedItems = []; - BI.each(addSet, function (index) { - addedItems.push(renderedCells[index]) - }); - this.container.addItems(addedItems); - this.renderedCells = renderedCells; - this.renderedKeys = renderedKeys; }, _getMaxScrollLeft: function () { @@ -277,6 +335,7 @@ BI.Collection = BI.inherit(BI.Widget, { }); this.renderedCells = []; this.renderedKeys = []; + this.renderRange = {}; this._scrollLock = false; }, diff --git a/src/base/grid/grid.js b/src/base/grid/grid.js index e138e6622..ce9d7c1ae 100644 --- a/src/base/grid/grid.js +++ b/src/base/grid/grid.js @@ -30,6 +30,7 @@ BI.Grid = BI.inherit(BI.Widget, { var self = this, o = this.options; this.renderedCells = []; this.renderedKeys = []; + this.renderRange = {}; this._scrollLock = false; this._debounceRelease = BI.debounce(function () { self._scrollLock = false; @@ -78,13 +79,17 @@ BI.Grid = BI.inherit(BI.Widget, { _calculateChildrenToRender: function () { var self = this, o = this.options; - var width = o.width, height = o.height, scrollLeft = BI.clamp(o.scrollLeft, 0, this._getMaxScrollLeft()), scrollTop = BI.clamp(o.scrollTop, 0, this._getMaxScrollTop()), + var width = o.width, height = o.height, scrollLeft = BI.clamp(o.scrollLeft, 0, this._getMaxScrollLeft()), + scrollTop = BI.clamp(o.scrollTop, 0, this._getMaxScrollTop()), overscanColumnCount = o.overscanColumnCount, overscanRowCount = o.overscanRowCount; if (height > 0 && width > 0) { var visibleColumnIndices = this._columnSizeAndPositionManager.getVisibleCellRange(width, scrollLeft); var visibleRowIndices = this._rowSizeAndPositionManager.getVisibleCellRange(height, scrollTop); + if (BI.isEmpty(visibleColumnIndices) || BI.isEmpty(visibleRowIndices)) { + return; + } var horizontalOffsetAdjustment = this._columnSizeAndPositionManager.getOffsetAdjustment(width, scrollLeft); var verticalOffsetAdjustment = this._rowSizeAndPositionManager.getOffsetAdjustment(height, scrollTop); @@ -102,8 +107,22 @@ BI.Grid = BI.inherit(BI.Widget, { var rowStartIndex = overscanRowIndices.overscanStartIndex; var rowStopIndex = overscanRowIndices.overscanStopIndex; - var renderedCells = [], renderedKeys = []; + //算区间size + var minRowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowStartIndex); + var minColumnDatum = this._columnSizeAndPositionManager.getSizeAndPositionOfCell(columnStartIndex); + var maxRowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowStopIndex); + var maxColumnDatum = this._columnSizeAndPositionManager.getSizeAndPositionOfCell(columnStopIndex); + var top = minRowDatum.offset + verticalOffsetAdjustment; + var left = minColumnDatum.offset + horizontalOffsetAdjustment; + var bottom = maxRowDatum.offset + verticalOffsetAdjustment + maxRowDatum.size; + var right = maxColumnDatum.offset + horizontalOffsetAdjustment + maxColumnDatum.size; + //如果滚动的区间并没有超出渲染的范围 + if (top >= this.renderRange.minY && bottom <= this.renderRange.maxY && left >= this.renderRange.minX && right <= this.renderRange.maxX) { + return; + } + var renderedCells = [], renderedKeys = []; + var minX = this._getMaxScrollLeft(), minY = this._getMaxScrollTop(), maxX = 0, maxY = 0; for (var rowIndex = rowStartIndex; rowIndex <= rowStopIndex; rowIndex++) { var rowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowIndex); @@ -148,6 +167,10 @@ BI.Grid = BI.inherit(BI.Widget, { _height: rowDatum.size }); } + minX = Math.min(minX, columnDatum.offset + horizontalOffsetAdjustment); + maxX = Math.max(maxX, columnDatum.offset + horizontalOffsetAdjustment + columnDatum.size); + minY = Math.min(minY, rowDatum.offset + verticalOffsetAdjustment); + maxY = Math.max(maxY, rowDatum.offset + verticalOffsetAdjustment + rowDatum.size); renderedKeys.push(key); } } @@ -179,6 +202,7 @@ BI.Grid = BI.inherit(BI.Widget, { this.container.addItems(addedItems); this.renderedCells = renderedCells; this.renderedKeys = renderedKeys; + this.renderRange = {minX: minX, minY: minY, maxX: maxX, maxY: maxY}; } }, diff --git a/src/core/base.js b/src/core/base.js index d291ca5c7..96438a27e 100644 --- a/src/core/base.js +++ b/src/core/base.js @@ -268,6 +268,29 @@ if (!window.BI) { return true; }, + backFindKey: function (obj, predicate, context) { + predicate = BI.iteratee(predicate, context); + var keys = _.keys(obj), key; + for (var i = keys.length - 1; i >= 0; i--) { + key = keys[i]; + if (predicate(obj[key], key, obj)) { + return key; + } + } + }, + + backFind: function (obj, predicate, context) { + var key; + if (BI.isArray(obj)) { + key = BI.findLastIndex(obj, predicate, context); + } else { + key = BI.backFindKey(obj, predicate, context); + } + if (key !== void 0 && key !== -1) { + return obj[key]; + } + }, + remove: function (obj, target, context) { var isFunction = BI.isFunction(target); target = isFunction || BI.isArray(target) ? target : [target]; From cffb24d4c372a65e0d530da238ed7e9371a168f9 Mon Sep 17 00:00:00 2001 From: guy Date: Sun, 14 May 2017 02:31:23 +0800 Subject: [PATCH 6/8] add --- bi/base.js | 1 + docs/base.js | 1 + src/base/grid/grid.js | 1 + 3 files changed, 3 insertions(+) diff --git a/bi/base.js b/bi/base.js index ebf369c81..9476b3d85 100644 --- a/bi/base.js +++ b/bi/base.js @@ -14948,6 +14948,7 @@ BI.Grid = BI.inherit(BI.Widget, { }); this.renderedCells = []; this.renderedKeys = []; + this.renderRange = {}; this._scrollLock = false; }, diff --git a/docs/base.js b/docs/base.js index ebf369c81..9476b3d85 100644 --- a/docs/base.js +++ b/docs/base.js @@ -14948,6 +14948,7 @@ BI.Grid = BI.inherit(BI.Widget, { }); this.renderedCells = []; this.renderedKeys = []; + this.renderRange = {}; this._scrollLock = false; }, diff --git a/src/base/grid/grid.js b/src/base/grid/grid.js index ce9d7c1ae..43fa51746 100644 --- a/src/base/grid/grid.js +++ b/src/base/grid/grid.js @@ -306,6 +306,7 @@ BI.Grid = BI.inherit(BI.Widget, { }); this.renderedCells = []; this.renderedKeys = []; + this.renderRange = {}; this._scrollLock = false; }, From 118f155445ca32d891773763e3a7e31feb084d86 Mon Sep 17 00:00:00 2001 From: git Date: Sun, 14 May 2017 02:36:44 +0800 Subject: [PATCH 7/8] update --- demo.html | 34 ---------------------------------- server.js | 2 +- 2 files changed, 1 insertion(+), 35 deletions(-) delete mode 100644 demo.html diff --git a/demo.html b/demo.html deleted file mode 100644 index dcbb03ef1..000000000 --- a/demo.html +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - \ No newline at end of file diff --git a/server.js b/server.js index 8bce8676a..dd4840982 100644 --- a/server.js +++ b/server.js @@ -9,5 +9,5 @@ const port = 3000; app.use(express.static("./")); app.listen(port, function() { console.log("server start"); - open('http://localhost:' + port + '/demo.html'); + open('http://localhost:' + port + '/docs/index.html'); }); From ad3cef619563b263e12b96e39b565859d71a1b17 Mon Sep 17 00:00:00 2001 From: guy Date: Sun, 14 May 2017 11:46:17 +0800 Subject: [PATCH 8/8] =?UTF-8?q?polyfill=E7=A7=BB=E5=87=BA=E6=9D=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gruntfile.js | 43 +-- bi/core.js | 322 +----------------- docs/core.js | 322 +----------------- docs/index.html | 1 + src/core/proto/array.js | 259 +------------- src/core/proto/cache.js | 20 -- src/polyfill/array.js | 31 ++ src/polyfill/console.js | 12 + src/polyfill/localStorage.js | 21 ++ .../proto/special.js => polyfill/sort.js} | 14 - 10 files changed, 95 insertions(+), 950 deletions(-) create mode 100644 src/polyfill/array.js create mode 100644 src/polyfill/console.js create mode 100644 src/polyfill/localStorage.js rename src/{core/proto/special.js => polyfill/sort.js} (75%) diff --git a/Gruntfile.js b/Gruntfile.js index 664716e7a..ce4ad486c 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -7,6 +7,10 @@ module.exports = function (grunt) { options: { separator: '' }, + polyfillJs: { + src: ['src/polyfill/**/*.js'], + dest: 'docs/polyfill.js' + }, coreJs: { src: [ 'src/core/jquery.js', @@ -30,41 +34,7 @@ module.exports = function (grunt) { ], dest: 'docs/core.js' }, - biCoreJs: { - src: [ - 'src/core/underscore.js', - 'src/core/foundation.js', - 'src/core/mvc/**/*.js', - 'src/core/base.js', - 'src/core/alias.js', - 'src/core/events.js', - 'src/core/var.js', - 'src/core/ob.js', - 'src/core/widget.js', - 'src/core/model.js', - 'src/core/view.js', - 'src/core/shortcut.js', - 'src/core/plugin.js', - 'src/core/controller.js', - 'src/core/proto/**/*.js', - 'src/core/utils/**/*.js', - 'src/core/behavior/behavior.js', - 'src/core/wrapper/layout.js', - 'src/core/action/**/*.js', - 'src/core/adapter/**/*.js', - 'src/core/controller/**/*.js', - 'src/core/event/**/*.js', - 'src/core/func/**/*.js', - 'src/core/listener/**/*.js', - 'src/core/loader/**/*.js', - 'src/core/logic/**/*.js', - 'src/data/data.js', - 'src/data/**/*.js', - 'src/config.js' - ], - dest: 'bi/core.js' - }, //最基础的控件 baseJs: { src: [ @@ -137,6 +107,11 @@ module.exports = function (grunt) { dest: 'docs/demo.css' }, + bi_polyfillJs: { + src: ['src/polyfill/**/*.js'], + dest: 'bi/polyfill.js' + }, + bi_coreJs: { src: [ 'src/core/foundation.js', diff --git a/bi/core.js b/bi/core.js index 5de694e03..95228d4cf 100644 --- a/bi/core.js +++ b/bi/core.js @@ -5843,34 +5843,6 @@ $.extend(Array.prototype, { contains: function (o) { return this.indexOf(o) > -1; }, - /** - * 检查指定的值是否在数组中 - * @param {Object} o 要检查的值 - * @return {Number} o在数组中的索引(如果不在数组中则返回-1) - */ - indexOf: function (o) { - for (var i = 0, len = this.length; i < len; i++) { - if (_.isEqual(o, this[i])) { - return i; - } - } - return -1; - }, - - /** - * 检查指定的值是否在数组中 - * ie67不支持数组的这个方法 - * @param {Object} o 要检查的值 - * @return {Number} o在数组中的索引(如果不在数组中则返回-1) - */ - lastIndexOf: function (o) { - for (var len = this.length, i = len - 1; i >= 0; i--) { - if (_.isEqual(o, this[i])) { - return i; - } - } - return -1; - }, /** * 从数组中移除指定的值,如果值不在数组中,则不产生任何效果 @@ -5879,265 +5851,29 @@ $.extend(Array.prototype, { */ remove: function (o) { var index = this.indexOf(o); - if (index != -1) { + if (index !== -1) { this.splice(index, 1); } return this; }, - /** - * 移除数组中的所有元素 - */ - clear: function () { - while (this.length > 0) { - this.pop(); - } - } -}); -/** - * Array原型拓展 - * Created by wang on 15/6/23. - */ -!function () { - Array.prototype.pushArray = function (array) { + pushArray: function (array) { for (var i = 0; i < array.length; i++) { this.push(array[i]); } - }; - Array.prototype.pushDistinct = function (obj) { + }, + pushDistinct: function (obj) { if (!this.contains(obj)) { this.push(obj); } - }; - Array.prototype.pushDistinctArray = function (array) { + }, + pushDistinctArray: function (array) { for (var i = 0, len = array.length; i < len; i++) { this.pushDistinct(array[i]); } - }; -}(); - -/** - * 规定bi的数组分为两种,其中,value和type值为key值 - * 1、[{"text":1,"value":2,"children":[]}] - * 2、[{"name":1,"type":2,"children":[]}] - * guy - * 对数组的操作 - * @type {{}} - */ -ArrayUtils = {}; - -$.extend(ArrayUtils, { - /** - * 遍历方法 - * @param array - * @param back - */ - traversal: function (array, back) { - if (BI.isNull(array)) { - return; - } - var self = this; - BI.each(array, function (i, item) { - if (back(i, item) === BI.Status.END) { - return false; - } - self.traversal(item.children, back); - }) - }, - - getAllChildNames: function (array) { - var names = []; - this.traversal(array, function (i, item) { - if (BI.isNotEmptyArray(item.children)) { - return BI.Status.RUNNING; - } - names.push(item.text || item.name); - }); - return names; - }, - - /** - * 获取第一个子节点 - * @param array - */ - getFirstChild: function (array) { - var first = {}; - this.traversal(array, function (i, item) { - if (BI.isNotEmptyArray(item.children)) { - return; - } - first = item; - return BI.Status.END; - }) - return first; - }, - - /** - * 获取最后一个子节点 - * @param array - */ - getLastChild: function (array) { - var first = {}; - this.traversal(array, function (i, item) { - if (item.children && item.children.length > 0) { - return; - } - first = item; - }) - return first; - }, - - getTextByValue: function (array, value) { - if (!array) { - return value; - } - var text = ""; - this.traversal(array, function (i, item) { - if (BI.isEqual(item.value, value)) { - text = item.text; - return BI.Status.END; - } - }); - return text; - }, - - getNameByType: function (array, type) { - if (!array) { - return type; - } - var name = ""; - this.traversal(array, function (i, item) { - if (BI.isEqual(item.type, type)) { - name = item.name; - return BI.Status.END; - } - }); - return name; - }, - - getItemByText: function (array, text) { - var res = void 0; - this.traversal(array, function (i, item) { - if (BI.isCapitalEqual(item.text, text)) { - res = item; - return BI.Status.END; - } - }); - return res; - }, - - getIndexByText: function (array, text) { - var res = -1; - this.traversal(array, function (i, item) { - if (BI.isCapitalEqual(item.text, text)) { - res = i; - return BI.Status.END; - } - }); - return res; - }, - - getItemByValue: function (array, value) { - var res = void 0; - this.traversal(array, function (i, item) { - if (BI.isEqual(item.value, value)) { - res = item; - return BI.Status.END; - } - }); - return res; - }, - - getIndexByValue: function (array, value) { - var res = -1; - this.traversal(array, function (i, item) { - if (BI.isEqual(item.value, value)) { - res = i; - return BI.Status.END; - } - }); - return res; - }, - - getItemByName: function (array, name) { - var res = void 0; - this.traversal(array, function (i, item) { - if (BI.isCapitalEqual(item.name, name)) { - res = item; - return BI.Status.END; - } - }); - return res; - }, - - getIndexByName: function (array, name) { - var res = -1; - this.traversal(array, function (i, item) { - if (BI.isCapitalEqual(item.name, name)) { - res = i; - return BI.Status.END; - } - }); - return res; - }, - - getItemByType: function (array, type) { - var res = void 0; - this.traversal(array, function (i, item) { - if (BI.isEqual(item.type, type)) { - res = item; - return BI.Status.END; - } - }); - return res; - }, - - getIndexByType: function (array, type) { - var res = -1; - this.traversal(array, function (i, item) { - if (BI.isEqual(item.type, type)) { - res = i; - return BI.Status.END; - } - }); - return res; - }, - - deleteItemByType: function (array, type) { - var item = this.getItemByType(array, type); - array.remove(item); - }, - - deleteItemByName: function (array, name) { - var item = this.getItemByName(array, name); - array.remove(item); - }, - - deleteItemByValue: function (array, value) { - var item = this.getItemByValue(array, value); - array.remove(item); - } -});/* - * 前端缓存 - */ -window.localStorage || (window.localStorage = { - items: {}, - setItem: function (k, v) { - BI.Cache.addCookie(k, v); - }, - getItem: function (k) { - return BI.Cache.getCookie(k); - }, - removeItem: function (k) { - BI.Cache.deleteCookie(k); - }, - key: function () { - - }, - clear: function () { - this.items = {}; } }); + BI.Cache = { _prefix: "bi", setUsername: function (username) { @@ -7094,50 +6830,6 @@ function accDiv(arg1, arg2) { Number.prototype.div = function (arg) { return accDiv(this, arg); };/** - * 特殊情况 - * Created by wang on 15/6/23. - */ -//解决console未定义问题 guy -window.console = window.console || (function () { - var c = {}; - c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile - = c.clear = c.exception = c.trace = c.assert = function () { - }; - return c; - })(); - - -//修复ie9下sort方法的bug -!function (window) { - var ua = window.navigator.userAgent.toLowerCase(), - reg = /msie|applewebkit.+safari/; - if (reg.test(ua)) { - var _sort = Array.prototype.sort; - Array.prototype.sort = function (fn) { - if (!!fn && typeof fn === 'function') { - if (this.length < 2) { - return this; - } - var i = 0, j = i + 1, l = this.length, tmp, r = false, t = 0; - for (; i < l; i++) { - for (j = i + 1; j < l; j++) { - t = fn.call(this, this[i], this[j]); - r = (typeof t === 'number' ? t : - !!t ? 1 : 0) > 0; - if (r === true) { - tmp = this[i]; - this[i] = this[j]; - this[j] = tmp; - } - } - } - return this; - } else { - return _sort.call(this); - } - }; - } -}(window);/** * 对字符串对象的扩展 * @class String */ diff --git a/docs/core.js b/docs/core.js index 49809986e..39cd1299f 100644 --- a/docs/core.js +++ b/docs/core.js @@ -23326,34 +23326,6 @@ $.extend(Array.prototype, { contains: function (o) { return this.indexOf(o) > -1; }, - /** - * 检查指定的值是否在数组中 - * @param {Object} o 要检查的值 - * @return {Number} o在数组中的索引(如果不在数组中则返回-1) - */ - indexOf: function (o) { - for (var i = 0, len = this.length; i < len; i++) { - if (_.isEqual(o, this[i])) { - return i; - } - } - return -1; - }, - - /** - * 检查指定的值是否在数组中 - * ie67不支持数组的这个方法 - * @param {Object} o 要检查的值 - * @return {Number} o在数组中的索引(如果不在数组中则返回-1) - */ - lastIndexOf: function (o) { - for (var len = this.length, i = len - 1; i >= 0; i--) { - if (_.isEqual(o, this[i])) { - return i; - } - } - return -1; - }, /** * 从数组中移除指定的值,如果值不在数组中,则不产生任何效果 @@ -23362,265 +23334,29 @@ $.extend(Array.prototype, { */ remove: function (o) { var index = this.indexOf(o); - if (index != -1) { + if (index !== -1) { this.splice(index, 1); } return this; }, - /** - * 移除数组中的所有元素 - */ - clear: function () { - while (this.length > 0) { - this.pop(); - } - } -}); -/** - * Array原型拓展 - * Created by wang on 15/6/23. - */ -!function () { - Array.prototype.pushArray = function (array) { + pushArray: function (array) { for (var i = 0; i < array.length; i++) { this.push(array[i]); } - }; - Array.prototype.pushDistinct = function (obj) { + }, + pushDistinct: function (obj) { if (!this.contains(obj)) { this.push(obj); } - }; - Array.prototype.pushDistinctArray = function (array) { + }, + pushDistinctArray: function (array) { for (var i = 0, len = array.length; i < len; i++) { this.pushDistinct(array[i]); } - }; -}(); - -/** - * 规定bi的数组分为两种,其中,value和type值为key值 - * 1、[{"text":1,"value":2,"children":[]}] - * 2、[{"name":1,"type":2,"children":[]}] - * guy - * 对数组的操作 - * @type {{}} - */ -ArrayUtils = {}; - -$.extend(ArrayUtils, { - /** - * 遍历方法 - * @param array - * @param back - */ - traversal: function (array, back) { - if (BI.isNull(array)) { - return; - } - var self = this; - BI.each(array, function (i, item) { - if (back(i, item) === BI.Status.END) { - return false; - } - self.traversal(item.children, back); - }) - }, - - getAllChildNames: function (array) { - var names = []; - this.traversal(array, function (i, item) { - if (BI.isNotEmptyArray(item.children)) { - return BI.Status.RUNNING; - } - names.push(item.text || item.name); - }); - return names; - }, - - /** - * 获取第一个子节点 - * @param array - */ - getFirstChild: function (array) { - var first = {}; - this.traversal(array, function (i, item) { - if (BI.isNotEmptyArray(item.children)) { - return; - } - first = item; - return BI.Status.END; - }) - return first; - }, - - /** - * 获取最后一个子节点 - * @param array - */ - getLastChild: function (array) { - var first = {}; - this.traversal(array, function (i, item) { - if (item.children && item.children.length > 0) { - return; - } - first = item; - }) - return first; - }, - - getTextByValue: function (array, value) { - if (!array) { - return value; - } - var text = ""; - this.traversal(array, function (i, item) { - if (BI.isEqual(item.value, value)) { - text = item.text; - return BI.Status.END; - } - }); - return text; - }, - - getNameByType: function (array, type) { - if (!array) { - return type; - } - var name = ""; - this.traversal(array, function (i, item) { - if (BI.isEqual(item.type, type)) { - name = item.name; - return BI.Status.END; - } - }); - return name; - }, - - getItemByText: function (array, text) { - var res = void 0; - this.traversal(array, function (i, item) { - if (BI.isCapitalEqual(item.text, text)) { - res = item; - return BI.Status.END; - } - }); - return res; - }, - - getIndexByText: function (array, text) { - var res = -1; - this.traversal(array, function (i, item) { - if (BI.isCapitalEqual(item.text, text)) { - res = i; - return BI.Status.END; - } - }); - return res; - }, - - getItemByValue: function (array, value) { - var res = void 0; - this.traversal(array, function (i, item) { - if (BI.isEqual(item.value, value)) { - res = item; - return BI.Status.END; - } - }); - return res; - }, - - getIndexByValue: function (array, value) { - var res = -1; - this.traversal(array, function (i, item) { - if (BI.isEqual(item.value, value)) { - res = i; - return BI.Status.END; - } - }); - return res; - }, - - getItemByName: function (array, name) { - var res = void 0; - this.traversal(array, function (i, item) { - if (BI.isCapitalEqual(item.name, name)) { - res = item; - return BI.Status.END; - } - }); - return res; - }, - - getIndexByName: function (array, name) { - var res = -1; - this.traversal(array, function (i, item) { - if (BI.isCapitalEqual(item.name, name)) { - res = i; - return BI.Status.END; - } - }); - return res; - }, - - getItemByType: function (array, type) { - var res = void 0; - this.traversal(array, function (i, item) { - if (BI.isEqual(item.type, type)) { - res = item; - return BI.Status.END; - } - }); - return res; - }, - - getIndexByType: function (array, type) { - var res = -1; - this.traversal(array, function (i, item) { - if (BI.isEqual(item.type, type)) { - res = i; - return BI.Status.END; - } - }); - return res; - }, - - deleteItemByType: function (array, type) { - var item = this.getItemByType(array, type); - array.remove(item); - }, - - deleteItemByName: function (array, name) { - var item = this.getItemByName(array, name); - array.remove(item); - }, - - deleteItemByValue: function (array, value) { - var item = this.getItemByValue(array, value); - array.remove(item); - } -});/* - * 前端缓存 - */ -window.localStorage || (window.localStorage = { - items: {}, - setItem: function (k, v) { - BI.Cache.addCookie(k, v); - }, - getItem: function (k) { - return BI.Cache.getCookie(k); - }, - removeItem: function (k) { - BI.Cache.deleteCookie(k); - }, - key: function () { - - }, - clear: function () { - this.items = {}; } }); + BI.Cache = { _prefix: "bi", setUsername: function (username) { @@ -24577,50 +24313,6 @@ function accDiv(arg1, arg2) { Number.prototype.div = function (arg) { return accDiv(this, arg); };/** - * 特殊情况 - * Created by wang on 15/6/23. - */ -//解决console未定义问题 guy -window.console = window.console || (function () { - var c = {}; - c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile - = c.clear = c.exception = c.trace = c.assert = function () { - }; - return c; - })(); - - -//修复ie9下sort方法的bug -!function (window) { - var ua = window.navigator.userAgent.toLowerCase(), - reg = /msie|applewebkit.+safari/; - if (reg.test(ua)) { - var _sort = Array.prototype.sort; - Array.prototype.sort = function (fn) { - if (!!fn && typeof fn === 'function') { - if (this.length < 2) { - return this; - } - var i = 0, j = i + 1, l = this.length, tmp, r = false, t = 0; - for (; i < l; i++) { - for (j = i + 1; j < l; j++) { - t = fn.call(this, this[i], this[j]); - r = (typeof t === 'number' ? t : - !!t ? 1 : 0) > 0; - if (r === true) { - tmp = this[i]; - this[i] = this[j]; - this[j] = tmp; - } - } - } - return this; - } else { - return _sort.call(this); - } - }; - } -}(window);/** * 对字符串对象的扩展 * @class String */ diff --git a/docs/index.html b/docs/index.html index c9c8367f8..0db30acc5 100644 --- a/docs/index.html +++ b/docs/index.html @@ -15,6 +15,7 @@ + diff --git a/src/core/proto/array.js b/src/core/proto/array.js index fc1c3b977..5bf8cc3c3 100644 --- a/src/core/proto/array.js +++ b/src/core/proto/array.js @@ -6,34 +6,6 @@ $.extend(Array.prototype, { contains: function (o) { return this.indexOf(o) > -1; }, - /** - * 检查指定的值是否在数组中 - * @param {Object} o 要检查的值 - * @return {Number} o在数组中的索引(如果不在数组中则返回-1) - */ - indexOf: function (o) { - for (var i = 0, len = this.length; i < len; i++) { - if (_.isEqual(o, this[i])) { - return i; - } - } - return -1; - }, - - /** - * 检查指定的值是否在数组中 - * ie67不支持数组的这个方法 - * @param {Object} o 要检查的值 - * @return {Number} o在数组中的索引(如果不在数组中则返回-1) - */ - lastIndexOf: function (o) { - for (var len = this.length, i = len - 1; i >= 0; i--) { - if (_.isEqual(o, this[i])) { - return i; - } - } - return -1; - }, /** * 从数组中移除指定的值,如果值不在数组中,则不产生任何效果 @@ -42,242 +14,25 @@ $.extend(Array.prototype, { */ remove: function (o) { var index = this.indexOf(o); - if (index != -1) { + if (index !== -1) { this.splice(index, 1); } return this; }, - /** - * 移除数组中的所有元素 - */ - clear: function () { - while (this.length > 0) { - this.pop(); - } - } -}); -/** - * Array原型拓展 - * Created by wang on 15/6/23. - */ -!function () { - Array.prototype.pushArray = function (array) { + pushArray: function (array) { for (var i = 0; i < array.length; i++) { this.push(array[i]); } - }; - Array.prototype.pushDistinct = function (obj) { + }, + pushDistinct: function (obj) { if (!this.contains(obj)) { this.push(obj); } - }; - Array.prototype.pushDistinctArray = function (array) { + }, + pushDistinctArray: function (array) { for (var i = 0, len = array.length; i < len; i++) { this.pushDistinct(array[i]); } - }; -}(); - -/** - * 规定bi的数组分为两种,其中,value和type值为key值 - * 1、[{"text":1,"value":2,"children":[]}] - * 2、[{"name":1,"type":2,"children":[]}] - * guy - * 对数组的操作 - * @type {{}} - */ -ArrayUtils = {}; - -$.extend(ArrayUtils, { - /** - * 遍历方法 - * @param array - * @param back - */ - traversal: function (array, back) { - if (BI.isNull(array)) { - return; - } - var self = this; - BI.each(array, function (i, item) { - if (back(i, item) === BI.Status.END) { - return false; - } - self.traversal(item.children, back); - }) - }, - - getAllChildNames: function (array) { - var names = []; - this.traversal(array, function (i, item) { - if (BI.isNotEmptyArray(item.children)) { - return BI.Status.RUNNING; - } - names.push(item.text || item.name); - }); - return names; - }, - - /** - * 获取第一个子节点 - * @param array - */ - getFirstChild: function (array) { - var first = {}; - this.traversal(array, function (i, item) { - if (BI.isNotEmptyArray(item.children)) { - return; - } - first = item; - return BI.Status.END; - }) - return first; - }, - - /** - * 获取最后一个子节点 - * @param array - */ - getLastChild: function (array) { - var first = {}; - this.traversal(array, function (i, item) { - if (item.children && item.children.length > 0) { - return; - } - first = item; - }) - return first; - }, - - getTextByValue: function (array, value) { - if (!array) { - return value; - } - var text = ""; - this.traversal(array, function (i, item) { - if (BI.isEqual(item.value, value)) { - text = item.text; - return BI.Status.END; - } - }); - return text; - }, - - getNameByType: function (array, type) { - if (!array) { - return type; - } - var name = ""; - this.traversal(array, function (i, item) { - if (BI.isEqual(item.type, type)) { - name = item.name; - return BI.Status.END; - } - }); - return name; - }, - - getItemByText: function (array, text) { - var res = void 0; - this.traversal(array, function (i, item) { - if (BI.isCapitalEqual(item.text, text)) { - res = item; - return BI.Status.END; - } - }); - return res; - }, - - getIndexByText: function (array, text) { - var res = -1; - this.traversal(array, function (i, item) { - if (BI.isCapitalEqual(item.text, text)) { - res = i; - return BI.Status.END; - } - }); - return res; - }, - - getItemByValue: function (array, value) { - var res = void 0; - this.traversal(array, function (i, item) { - if (BI.isEqual(item.value, value)) { - res = item; - return BI.Status.END; - } - }); - return res; - }, - - getIndexByValue: function (array, value) { - var res = -1; - this.traversal(array, function (i, item) { - if (BI.isEqual(item.value, value)) { - res = i; - return BI.Status.END; - } - }); - return res; - }, - - getItemByName: function (array, name) { - var res = void 0; - this.traversal(array, function (i, item) { - if (BI.isCapitalEqual(item.name, name)) { - res = item; - return BI.Status.END; - } - }); - return res; - }, - - getIndexByName: function (array, name) { - var res = -1; - this.traversal(array, function (i, item) { - if (BI.isCapitalEqual(item.name, name)) { - res = i; - return BI.Status.END; - } - }); - return res; - }, - - getItemByType: function (array, type) { - var res = void 0; - this.traversal(array, function (i, item) { - if (BI.isEqual(item.type, type)) { - res = item; - return BI.Status.END; - } - }); - return res; - }, - - getIndexByType: function (array, type) { - var res = -1; - this.traversal(array, function (i, item) { - if (BI.isEqual(item.type, type)) { - res = i; - return BI.Status.END; - } - }); - return res; - }, - - deleteItemByType: function (array, type) { - var item = this.getItemByType(array, type); - array.remove(item); - }, - - deleteItemByName: function (array, name) { - var item = this.getItemByName(array, name); - array.remove(item); - }, - - deleteItemByValue: function (array, value) { - var item = this.getItemByValue(array, value); - array.remove(item); } -}); \ No newline at end of file +}); diff --git a/src/core/proto/cache.js b/src/core/proto/cache.js index b529bfeee..5e0668138 100644 --- a/src/core/proto/cache.js +++ b/src/core/proto/cache.js @@ -1,24 +1,4 @@ -/* - * 前端缓存 - */ -window.localStorage || (window.localStorage = { - items: {}, - setItem: function (k, v) { - BI.Cache.addCookie(k, v); - }, - getItem: function (k) { - return BI.Cache.getCookie(k); - }, - removeItem: function (k) { - BI.Cache.deleteCookie(k); - }, - key: function () { - }, - clear: function () { - this.items = {}; - } -}); BI.Cache = { _prefix: "bi", setUsername: function (username) { diff --git a/src/polyfill/array.js b/src/polyfill/array.js new file mode 100644 index 000000000..65f018588 --- /dev/null +++ b/src/polyfill/array.js @@ -0,0 +1,31 @@ +if(![].indexOf){ + /** + * 检查指定的值是否在数组中 + * @param {Object} o 要检查的值 + * @return {Number} o在数组中的索引(如果不在数组中则返回-1) + */ + [].indexOf = function (o) { + for (var i = 0, len = this.length; i < len; i++) { + if (_.isEqual(o, this[i])) { + return i; + } + } + return -1; + } +} +if(![].lastIndexOf){ + /** + * 检查指定的值是否在数组中 + * ie67不支持数组的这个方法 + * @param {Object} o 要检查的值 + * @return {Number} o在数组中的索引(如果不在数组中则返回-1) + */ + [].lastIndexOf = function (o) { + for (var len = this.length, i = len - 1; i >= 0; i--) { + if (_.isEqual(o, this[i])) { + return i; + } + } + return -1; + } +} \ No newline at end of file diff --git a/src/polyfill/console.js b/src/polyfill/console.js new file mode 100644 index 000000000..a1c017c06 --- /dev/null +++ b/src/polyfill/console.js @@ -0,0 +1,12 @@ +/** + * 特殊情况 + * Created by wang on 15/6/23. + */ +//解决console未定义问题 guy +window.console = window.console || (function () { + var c = {}; + c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile + = c.clear = c.exception = c.trace = c.assert = function () { + }; + return c; + })(); diff --git a/src/polyfill/localStorage.js b/src/polyfill/localStorage.js new file mode 100644 index 000000000..12036d743 --- /dev/null +++ b/src/polyfill/localStorage.js @@ -0,0 +1,21 @@ +/* + * 前端缓存 + */ +window.localStorage || (window.localStorage = { + items: {}, + setItem: function (k, v) { + BI.Cache.addCookie(k, v); + }, + getItem: function (k) { + return BI.Cache.getCookie(k); + }, + removeItem: function (k) { + BI.Cache.deleteCookie(k); + }, + key: function () { + + }, + clear: function () { + this.items = {}; + } +}); \ No newline at end of file diff --git a/src/core/proto/special.js b/src/polyfill/sort.js similarity index 75% rename from src/core/proto/special.js rename to src/polyfill/sort.js index 2ea79ffb8..6ad73ba9c 100644 --- a/src/core/proto/special.js +++ b/src/polyfill/sort.js @@ -1,17 +1,3 @@ -/** - * 特殊情况 - * Created by wang on 15/6/23. - */ -//解决console未定义问题 guy -window.console = window.console || (function () { - var c = {}; - c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile - = c.clear = c.exception = c.trace = c.assert = function () { - }; - return c; - })(); - - //修复ie9下sort方法的bug !function (window) { var ua = window.navigator.userAgent.toLowerCase(),