From 3db612aa389ee5386bcc7c05d8e7ff029ef7d337 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joker=2EWang-=E7=8E=8B=E9=A1=BA?= Date: Thu, 29 Dec 2022 15:03:57 +0800 Subject: [PATCH] =?UTF-8?q?KERNEL-13841=20refactor:base=E6=96=87=E4=BB=B6e?= =?UTF-8?q?s6=E5=8C=96=E7=AE=AD=E5=A4=B4=E5=87=BD=E6=95=B0=E5=92=8Cthis?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/base/grid/grid.js | 24 ++++++++++++------------ src/base/layer/layer.drawer.js | 12 ++++++------ src/base/layer/layer.popover.js | 16 ++++++++-------- src/base/layer/layer.popup.js | 4 ++-- src/base/layer/layer.searcher.js | 16 ++++++++-------- src/base/list/listview.js | 14 +++++++------- src/base/list/virtualgrouplist.js | 24 ++++++++++++------------ src/base/list/virtuallist.js | 24 ++++++++++++------------ src/base/pager/pager.js | 10 +++++----- src/base/single/tip/tip.toast.js | 2 +- src/base/single/tip/tip.tooltip.js | 2 +- 11 files changed, 74 insertions(+), 74 deletions(-) diff --git a/src/base/grid/grid.js b/src/base/grid/grid.js index 4ee6e6332..3798a8e46 100644 --- a/src/base/grid/grid.js +++ b/src/base/grid/grid.js @@ -30,7 +30,7 @@ export default class GridView extends Widget { scrollLeft: 0, scrollTop: 0, items: [], - itemFormatter: (item, row, col)=> { + itemFormatter: (item, row, col) => { return item; }, }); @@ -46,13 +46,13 @@ export default class GridView extends Widget { this.renderedKeys = []; this.renderRange = {}; this._scrollLock = false; - this._debounceRelease = BI.debounce(()=> { + this._debounceRelease = BI.debounce(() => { this._scrollLock = false; }, 1000 / 60); this.container = BI._lazyCreateWidget({ type: "bi.absolute", }); - this.element.scroll(()=> { + this.element.scroll(() => { if (this._scrollLock === true) { return; } @@ -85,7 +85,7 @@ export default class GridView extends Widget { scrollx: scrollx, items: [this.container], }); - o.items = BI.isFunction(o.items) ? this.__watch(o.items, (context, newValue)=> { + o.items = BI.isFunction(o.items) ? this.__watch(o.items, (context, newValue) => { this.populate(newValue); }) : o.items; if (o.items.length > 0) { @@ -104,7 +104,7 @@ export default class GridView extends Widget { } destroyed() { - BI.each(this.renderedCells, (i, cell)=> { + BI.each(this.renderedCells, (i, cell) => { cell.el._destroy(); }) } @@ -235,14 +235,14 @@ export default class GridView extends Widget { } // 已存在的, 需要添加的和需要删除的 const existSet = {}, addSet = {}, deleteArray = []; - BI.each(renderedKeys, (i, key)=> { + BI.each(renderedKeys, (i, key) => { if (this.renderedKeys[i]) { existSet[i] = key; } else { addSet[i] = key; } }); - BI.each(this.renderedKeys, function (i, key) { + BI.each(this.renderedKeys, (i, key) => { if (existSet[i]) { return; } @@ -251,12 +251,12 @@ export default class GridView extends Widget { } deleteArray.push(key[2]); }); - BI.each(deleteArray, (i, index)=> { + BI.each(deleteArray, (i, index) => { // 性能优化,不调用destroy方法防止触发destroy事件 this.renderedCells[index].el._destroy(); }); const addedItems = []; - BI.each(addSet, function (index, key) { + BI.each(addSet, (index, key) => { addedItems.push(renderedCells[key[2]]); }); // 与listview一样, 给上下文 @@ -370,7 +370,7 @@ export default class GridView extends Widget { setOverflowX(b) { if (this.options.overflowX !== !!b) { this.options.overflowX = !!b; - BI.nextTick(()=> { + BI.nextTick(() => { this.element.css({ overflowX: b ? "auto" : "hidden" }); }); } @@ -379,7 +379,7 @@ export default class GridView extends Widget { setOverflowY(b) { if (this.options.overflowY !== !!b) { this.options.overflowY = !!b; - BI.nextTick(()=> { + BI.nextTick(() => { this.element.css({ overflowY: b ? "auto" : "hidden" }); }); } @@ -418,7 +418,7 @@ export default class GridView extends Widget { } restore() { - BI.each(this.renderedCells, (i, cell)=> { + BI.each(this.renderedCells, (i, cell) => { cell.el._destroy(); }); this._clearChildren(); diff --git a/src/base/layer/layer.drawer.js b/src/base/layer/layer.drawer.js index 5f0efd278..890981d0e 100644 --- a/src/base/layer/layer.drawer.js +++ b/src/base/layer/layer.drawer.js @@ -82,7 +82,7 @@ export default class Drawer extends Widget { type: "bi.icon_button", cls: "bi-message-close close-font", height: headerHeight, - handler: ()=> { + handler: () => { this.close(); }, } : { @@ -98,7 +98,7 @@ export default class Drawer extends Widget { type: "bi.vertical", scrolly: true, cls: "drawer-body", - ref: (_ref)=> { + ref: (_ref) => { this.body = _ref; }, items: [{ @@ -153,7 +153,7 @@ export default class Drawer extends Widget { show(callback) { const { placement } = this.options; - requestAnimationFrame(()=> { + requestAnimationFrame(() => { const size = this._getSuitableSize(); switch (placement) { case "right": @@ -185,7 +185,7 @@ export default class Drawer extends Widget { hide(callback) { const { placement } = this.options; - requestAnimationFrame(()=> { + requestAnimationFrame(() => { switch (placement) { case "right": this.element.css({ @@ -215,13 +215,13 @@ export default class Drawer extends Widget { } open() { - this.show(()=> { + this.show(() => { this.fireEvent(Drawer.EVENT_OPEN); }); } close() { - this.hide(()=> { + this.hide(() => { this.fireEvent(Drawer.EVENT_CLOSE); }); } diff --git a/src/base/layer/layer.popover.js b/src/base/layer/layer.popover.js index 64f457d0b..cd91db05e 100644 --- a/src/base/layer/layer.popover.js +++ b/src/base/layer/layer.popover.js @@ -47,7 +47,7 @@ export class Popover extends Widget { this.startX = 0; this.startY = 0; const size = this._calculateSize(); - this.tracker = new BI.MouseMoveTracker(function (deltaX, deltaY) { + this.tracker = new BI.MouseMoveTracker((deltaX, deltaY) => { const W = BI.Widget._renderEngine.createElement("body").width(); const H = BI.Widget._renderEngine.createElement("body").height(); this.startX += deltaX; @@ -60,7 +60,7 @@ export class Popover extends Widget { BI.Resizers._resize({ target: this.element[0], }); - }, ()=> { + }, () => { this.tracker.releaseMouseMoves(); }, _global); const items = [{ @@ -70,7 +70,7 @@ export class Popover extends Widget { items: [{ el: { type: "bi.absolute", - ref: (_ref)=> { + ref: (_ref) => { this.dragger = _ref; }, items: [{ @@ -95,7 +95,7 @@ export class Popover extends Widget { type: "bi.icon_button", cls: "bi-message-close close-font", height: headerHeight, - handler: ()=> { + handler: () => { this.close(); }, }, @@ -109,7 +109,7 @@ export class Popover extends Widget { type: "bi.vertical", scrolly: true, cls: "popover-body", - ref: (_ref)=> { + ref: (_ref) => { this.body = _ref; }, css: { @@ -164,7 +164,7 @@ export class Popover extends Widget { } // mounted之后绑定事件 mounted() { - this.dragger.element.mousedown(function (e) { + this.dragger.element.mousedown((e) => { if (this.options.draggable !== false) { this.startX = this.element[0].offsetLeft; this.startY = this.element[0].offsetTop; @@ -258,7 +258,7 @@ export class BarPopover extends Popover { text: this.options.btns[1], value: 1, level: "ignore", - handler: (v)=> { + handler: (v) => { this.fireEvent(Popover.EVENT_CANCEL, v); this.close(v); }, @@ -267,7 +267,7 @@ export class BarPopover extends Popover { text: this.options.btns[0], warningTitle: warningTitle, value: 0, - handler: (v)=> { + handler: (v) => { this.fireEvent(Popover.EVENT_CONFIRM, v); this.close(v); }, diff --git a/src/base/layer/layer.popup.js b/src/base/layer/layer.popup.js index 93d7bee37..ea4a35196 100644 --- a/src/base/layer/layer.popup.js +++ b/src/base/layer/layer.popup.js @@ -80,8 +80,8 @@ export default class PopupView extends Widget { this.view = this._createView(); this.toolbar = this._createToolBar(); - this.view.on(BI.Controller.EVENT_CHANGE, (type, ...args)=> { - this.fireEvent.apply(this, [BI.Controller.EVENT_CHANGE, type, args]); + this.view.on(BI.Controller.EVENT_CHANGE, (type, ...args) => { + this.fireEvent.apply(this, [BI.Controller.EVENT_CHANGE, type, ...args]); if (type === BI.Events.CLICK) { this.fireEvent(PopupView.EVENT_CHANGE); } diff --git a/src/base/layer/layer.searcher.js b/src/base/layer/layer.searcher.js index 8b8d037f7..f76aa7a17 100644 --- a/src/base/layer/layer.searcher.js +++ b/src/base/layer/layer.searcher.js @@ -26,7 +26,7 @@ export default class SearcherView extends Pane { matcher: { // 完全匹配的构造器 type: "bi.button_group", behaviors: { - redmark: ()=> { + redmark: () => { return true; }, }, @@ -38,7 +38,7 @@ export default class SearcherView extends Pane { searcher: { type: "bi.button_group", behaviors: { - redmark: function () { + redmark: () => { return true; }, }, @@ -56,7 +56,7 @@ export default class SearcherView extends Pane { type: "bi.button_group", chooseType, behaviors: { - redmark: ()=> { + redmark: () => { return true; }, }, @@ -65,8 +65,8 @@ export default class SearcherView extends Pane { }], value, }); - this.matcher.on(BI.Controller.EVENT_CHANGE, (type, val, ob)=> { - this.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + this.matcher.on(BI.Controller.EVENT_CHANGE, (type, val, ob, ...args) => { + this.fireEvent.apply(this, [BI.Controller.EVENT_CHANGE, type, val, ob, ...args]); if (type === BI.Events.CLICK) { this.fireEvent(SearcherView.EVENT_CHANGE, val, ob); } @@ -85,7 +85,7 @@ export default class SearcherView extends Pane { type: "bi.button_group", chooseType, behaviors: { - redmark: ()=> { + redmark: () => { return true; }, }, @@ -94,8 +94,8 @@ export default class SearcherView extends Pane { }], value, }); - this.searcher.on(BI.Controller.EVENT_CHANGE, (type, val, ob)=> { - this.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + this.searcher.on(BI.Controller.EVENT_CHANGE, (type, val, ob, ...args) => { + this.fireEvent.apply(this, [BI.Controller.EVENT_CHANGE, type, val, ob, ...args]); if (type === BI.Events.CLICK) { this.fireEvent(BI.SearcherView.EVENT_CHANGE, val, ob); } diff --git a/src/base/list/listview.js b/src/base/list/listview.js index 03da49d3b..3ec9dc162 100644 --- a/src/base/list/listview.js +++ b/src/base/list/listview.js @@ -16,7 +16,7 @@ export default class ListView extends Widget { scrollTop: 0, el: {}, items: [], - itemFormatter: (item, index)=> { + itemFormatter: (item, index) => { return item; }, }; @@ -37,7 +37,7 @@ export default class ListView extends Widget { items: [BI.extend({ type: "bi.vertical", scrolly: false, - ref: (_ref)=> { + ref: (_ref) => { this.container = _ref; }, }, el)], @@ -49,17 +49,17 @@ export default class ListView extends Widget { mounted() { const o = this.options; // 这里无法进行结构,因为存在赋值操作,如果使用结构则this.options的值不会跟随变化 - o.items = BI.isFunction(o.items) ? this.__watch(o.items, (context, newValue)=> { + o.items = BI.isFunction(o.items) ? this.__watch(o.items, (context, newValue) => { this.populate(newValue); }) : o.items; this._populate(); - this.element.scroll((e)=> { + this.element.scroll((e) => { o.scrollTop = this.element.scrollTop(); this._calculateBlocksToRender(); }); let lastWidth = this.element.width(), lastHeight = this.element.height(); - BI.ResizeDetector.addResizeListener(this, ()=> { + BI.ResizeDetector.addResizeListener(this, () => { if (!this.element.is(":visible")) { return; } @@ -81,14 +81,14 @@ export default class ListView extends Widget { let cnt = this.renderedIndex + 1; let lastHeight; - const getElementHeight = ()=> { + const getElementHeight = () => { return this.container.element.height(); } lastHeight = getElementHeight(); while ((lastHeight) < minContentHeight && index < items.length) { const itemsArr = items.slice(index, index + blockSize); - this.container.addItems(itemsArr.map((item, i)=> { + this.container.addItems(itemsArr.map((item, i) => { return itemFormatter(item, index + i); }), this); const addedHeight = getElementHeight() - lastHeight; diff --git a/src/base/list/virtualgrouplist.js b/src/base/list/virtualgrouplist.js index a9b113833..be9845cc1 100644 --- a/src/base/list/virtualgrouplist.js +++ b/src/base/list/virtualgrouplist.js @@ -18,7 +18,7 @@ export default class VirtualGroupList extends Widget { rowHeight: "auto", items: [], el: {}, - itemFormatter: (item, index)=> { + itemFormatter: (item, index) => { return item; }, }; @@ -37,13 +37,13 @@ export default class VirtualGroupList extends Widget { type: "bi.vertical", items: [{ type: "bi.layout", - ref: ()=> { + ref: () => { this.topBlank = this; }, }, { type: "bi.virtual_group", height: rowHeight * items.length, - ref: ()=> { + ref: () => { this.container = this; }, layouts: [BI.extend({ @@ -52,7 +52,7 @@ export default class VirtualGroupList extends Widget { }, el)], }, { type: "bi.layout", - ref: ()=> { + ref: () => { this.bottomBlank = this; }, }], @@ -63,22 +63,22 @@ export default class VirtualGroupList extends Widget { mounted() { // 这里无法进行结构,因为存在赋值操作,如果使用结构则this.options的值不会跟随变化 const o = this.options; - o.items = BI.isFunction(o.items) ? this.__watch(o.items, (context, newValue)=> { + o.items = BI.isFunction(o.items) ? this.__watch(o.items, (context, newValue) => { this.populate(newValue); }) : o.items; this._populate(); this.ticking = false; - this.element.scroll(()=> { + this.element.scroll(() => { o.scrollTop = this.element.scrollTop(); if (!this.ticking) { - requestAnimationFrame(function () { + requestAnimationFrame(() => { this._calculateBlocksToRender(); this.ticking = false; }); this.ticking = true; } }); - BI.ResizeDetector.addResizeListener(this, ()=> { + BI.ResizeDetector.addResizeListener(this, () => { if (this.element.is(":visible")) { this._calculateBlocksToRender(); } @@ -95,13 +95,13 @@ export default class VirtualGroupList extends Widget { const minContentHeight = scrollTop + height + overscanHeight; let index = (this.renderedIndex + 1) * blockSize, cnt = this.renderedIndex + 1; let lastHeight; - const getElementHeight = ()=> { + const getElementHeight = () => { return this.container.element.height() + this.topBlank.element.height() + this.bottomBlank.element.height(); } lastHeight = this.renderedIndex === -1 ? 0 : getElementHeight(); while (lastHeight < minContentHeight && index < items.length) { const itemsArr = items.slice(index, index + blockSize); - this.container[this.renderedIndex === -1 ? "populate" : "addItems"](itemsArr.map((item, i)=> { + this.container[this.renderedIndex === -1 ? "populate" : "addItems"](itemsArr.map((item, i) => { return itemFormatter(item, index + i); }), this); const elementHeight = getElementHeight(); @@ -138,7 +138,7 @@ export default class VirtualGroupList extends Widget { } } this.bottomBlank.setHeight(this.tree.sumTo(this.renderedIndex) - this.tree.sumTo(Math.min(end, this.renderedIndex)) + "px"); - this.container.populate(itemsArr.map((item, i)=> { + this.container.populate(itemsArr.map((item, i) => { return itemFormatter(item, (start < 0 ? 0 : start) * blockSize + i); })); } else { @@ -149,7 +149,7 @@ export default class VirtualGroupList extends Widget { } } this.container.element.height(rowHeight * items.length - topHeight); - this.container.populate(itemsArr.map((item, i)=> { + this.container.populate(itemsArr.map((item, i) => { return itemFormatter(item, (start < 0 ? 0 : start) * blockSize + i); })); } diff --git a/src/base/list/virtuallist.js b/src/base/list/virtuallist.js index bf4cca217..ed788acdd 100644 --- a/src/base/list/virtuallist.js +++ b/src/base/list/virtuallist.js @@ -16,7 +16,7 @@ export default class VirtualList extends Widget { blockSize: 10, scrollTop: 0, items: [], - itemFormatter: (item, index)=> { + itemFormatter: (item, index) => { return item; }, }; @@ -34,18 +34,18 @@ export default class VirtualList extends Widget { type: "bi.vertical", items: [{ type: "bi.layout", - ref: (_ref)=> { + ref: (_ref) => { this.topBlank = _ref; }, }, { type: "bi.vertical", scrolly: false, - ref: (_ref)=> { + ref: (_ref) => { this.container = _ref; }, }, { type: "bi.layout", - ref: (_ref)=> { + ref: (_ref) => { this.bottomBlank = _ref; }, }], @@ -55,15 +55,15 @@ export default class VirtualList extends Widget { mounted() { // 这里无法进行结构,因为存在赋值操作,如果使用结构则this.options的值不会跟随变化 const o = this.options; - o.items = BI.isFunction(o.items) ? this.__watch(o.items, (context, newValue)=> { + o.items = BI.isFunction(o.items) ? this.__watch(o.items, (context, newValue) => { this.populate(newValue); }) : o.items; this._populate(); - this.element.scroll((e)=> { + this.element.scroll((e) => { o.scrollTop = this.element.scrollTop(); this._calculateBlocksToRender(); }); - BI.ResizeDetector.addResizeListener(this, ()=> { + BI.ResizeDetector.addResizeListener(this, () => { if (this.element.is(":visible")) { this._calculateBlocksToRender(); } @@ -76,13 +76,13 @@ export default class VirtualList extends Widget { const minContentHeight = scrollTop + height + overscanHeight; let index = (this.renderedIndex + 1) * blockSize, cnt = this.renderedIndex + 1; let lastHeight; - const getElementHeight = ()=> { + const getElementHeight = () => { return this.container.element.height() + this.topBlank.element.height() + this.bottomBlank.element.height(); } lastHeight = getElementHeight(); while (lastHeight < minContentHeight && index < items.length) { const itemsArr = items.slice(index, index + blockSize); - this.container.addItems(itemsArr.map((item, i)=> { + this.container.addItems(itemsArr.map((item, i) => { return itemFormatter(item, index + i); }), this); const addedHeight = getElementHeight() - lastHeight; @@ -158,10 +158,10 @@ export default class VirtualList extends Widget { this.container.element.append(lastFragment); this.topBlank.setHeight(this.tree.sumTo(Math.max(-1, start - 1)) + "px"); this.bottomBlank.setHeight(this.tree.sumTo(this.renderedIndex) - this.tree.sumTo(Math.min(end, this.renderedIndex)) + "px"); - BI.each(needMount, (i, child)=> { + BI.each(needMount, (i, child) => { child && child._mount(); }); - BI.each(needDestroyed, (i, child)=> { + BI.each(needDestroyed, (i, child) => { child && child._destroy(); }); } @@ -180,7 +180,7 @@ export default class VirtualList extends Widget { } _clearChildren() { - BI.each(this.container._children, (i, cell)=> { + BI.each(this.container._children, (i, cell) => { cell && cell._destroy(); }); this.container._children = {}; diff --git a/src/base/pager/pager.js b/src/base/pager/pager.js index a8b2d9418..4eba409e6 100644 --- a/src/base/pager/pager.js +++ b/src/base/pager/pager.js @@ -23,7 +23,7 @@ export default class Pager extends Widget { dynamicShowFirstLast: false, // 是否动态显示首页、尾页 dynamicShowPrevNext: false, // 是否动态显示上一页、下一页 pages: false, // 总页数 - curr: function () { + curr: () => { return 1; }, // 初始化当前页 groups: 0, // 连续显示分页数 @@ -34,7 +34,7 @@ export default class Pager extends Widget { next: "下一页", firstPage: 1, - lastPage: ()=> { // 在万不得已时才会调用这个函数获取最后一页的页码, 主要作用于setValue方法 + lastPage: () => { // 在万不得已时才会调用这个函数获取最后一页的页码, 主要作用于setValue方法 return 1; }, hasPrev: BI.emptyFn, // pages不可用时有效 @@ -185,7 +185,7 @@ export default class Pager extends Widget { this.button_group = BI.createWidget({ type: "bi.button_group", element: this, - items: BI.map(view, (idx, v)=> { + items: BI.map(view, (idx, v) => { v = BI.extend({ cls: "bi-list-item-select bi-border-radius", height: 23, @@ -198,7 +198,7 @@ export default class Pager extends Widget { behaviors, layouts, }); - this.button_group.on(BI.Controller.EVENT_CHANGE, (type, value, obj, ...args)=> { + this.button_group.on(BI.Controller.EVENT_CHANGE, (type, value, obj, ...args) => { // if (self._lock === true) { // return; // } @@ -230,7 +230,7 @@ export default class Pager extends Widget { this._populate(); this.fireEvent(Pager.EVENT_CHANGE, obj); } - this.fireEvent.apply(this, [BI.Controller.EVENT_CHANGE, type, value, obj, args]); + this.fireEvent.apply(this, [BI.Controller.EVENT_CHANGE, type, value, obj, ...args]); }); this.fireEvent(Pager.EVENT_AFTER_POPULATE); } diff --git a/src/base/single/tip/tip.toast.js b/src/base/single/tip/tip.toast.js index 1fa33187a..e93b3627a 100644 --- a/src/base/single/tip/tip.toast.js +++ b/src/base/single/tip/tip.toast.js @@ -100,7 +100,7 @@ export default class Toast extends Tip { items.push({ type: "bi.icon_button", cls: "close-font toast-icon", - handler: ()=> { + handler: () => { this.destroy(); }, height: textHeight, diff --git a/src/base/single/tip/tip.tooltip.js b/src/base/single/tip/tip.tooltip.js index ab95c113a..d50a52c19 100644 --- a/src/base/single/tip/tip.tooltip.js +++ b/src/base/single/tip/tip.tooltip.js @@ -51,7 +51,7 @@ export default class Tooltip extends Tip { element: this, hgap: this._const.hgap, innerVgap: this._const.vgap, - items: BI.map(texts, function (i, text) { + items: BI.map(texts, (i, text) => { return { type: "bi.label", textAlign: textAlign,