Browse Source

KERNEL-13843 refactor: core未完成es6化时不阻塞普通组件的es6化的一个示例

es6
Zhenfei.Li 2 years ago
parent
commit
691dde05dc
  1. 86
      src/base/1.pane.js
  2. 8
      src/core/decorator.js
  3. 3
      tsconfig.json

86
src/base/1.pane.js

@ -6,41 +6,44 @@
* @extends BI.Widget * @extends BI.Widget
* @abstract * @abstract
*/ */
BI.Pane = BI.inherit(BI.Widget, { import { shortcut } from "../core/decorator";
_defaultConfig: function () { @shortcut()
return BI.extend(BI.Pane.superclass._defaultConfig.apply(this, arguments), { export class Pane extends BI.Widget {
static xtype = "bi.pane";
static EVENT_LOADED = "EVENT_LOADED";
static EVENT_LOADING = "EVENT_LOADING";
props = {
_baseCls: "bi-pane", _baseCls: "bi-pane",
tipText: BI.i18nText("BI-No_Selected_Item"), tipText: BI.i18nText("BI-No_Selected_Item"),
loadingText: "", loadingText: "",
loadingSize: "small", loadingSize: "small",
overlap: true, overlap: true,
onLoaded: BI.emptyFn, onLoaded: BI.emptyFn,
}); }
},
_assertTip: function () { _assertTip() {
var self = this, o = this.options;
if (!this._tipText) { if (!this._tipText) {
BI.createWidget({ BI.createWidget({
type: "bi.absolute_center_adapt", type: "bi.absolute_center_adapt",
element: this, element: this,
items: [{ items: [{
type: "bi.label", type: "bi.label",
ref: function (_ref) { ref: (_ref) => {
self._tipText = _ref; this._tipText = _ref;
}, },
cls: "bi-tips", cls: "bi-tips",
text: o.tipText, text: this.options.tipText,
height: 25, height: 25,
}], }],
}); });
} }
}, }
loading: function () { loading() {
var self = this, o = this.options; const o = this.options;
var loadingAnimation = BI.createWidget(BI.Providers.getProvider("bi.provider.system").getLoading({ const loadingAnimation = BI.createWidget(BI.Providers.getProvider("bi.provider.system").getLoading({
loadingSize: o.loadingSize, loadingSize: o.loadingSize,
context: this, context: this,
})); }));
@ -56,7 +59,7 @@ BI.Pane = BI.inherit(BI.Widget, {
element: BI.Layers.make(this.getName() + "-loading", this), element: BI.Layers.make(this.getName() + "-loading", this),
}); });
} }
BI.Layers.show(self.getName() + "-loading"); BI.Layers.show(this.getName() + "-loading");
} else if (BI.isNull(this._loading)) { } else if (BI.isNull(this._loading)) {
loadingAnimation.element.css("zIndex", 1); loadingAnimation.element.css("zIndex", 1);
BI.createWidget({ BI.createWidget({
@ -66,17 +69,17 @@ BI.Pane = BI.inherit(BI.Widget, {
items: this._getLoadingTipItems(loadingAnimation), items: this._getLoadingTipItems(loadingAnimation),
}); });
} }
self.fireEvent(BI.Pane.EVENT_LOADING); this.fireEvent(Pane.EVENT_LOADING);
this.element.addClass("loading-status"); this.element.addClass("loading-status");
}, }
_getSize: function (v) { _getSize(v) {
return Math.ceil(v / (this.options.loadingSize === "small" ? 2 : 1)); return Math.ceil(v / (this.options.loadingSize === "small" ? 2 : 1));
}, }
_getLoadingTipItems: function (loadingTip) { _getLoadingTipItems(loadingTip) {
var self = this, o = this.options; const o = this.options;
var loadingTipItems = [{ const loadingTipItems = [{
type: "bi.horizontal_adapt", type: "bi.horizontal_adapt",
items: [loadingTip], items: [loadingTip],
}]; }];
@ -88,46 +91,43 @@ BI.Pane = BI.inherit(BI.Widget, {
return [{ return [{
type: "bi.vertical", type: "bi.vertical",
ref: function (_ref) { ref: (_ref) => {
self._loading = _ref; this._loading = _ref;
}, },
items: loadingTipItems, items: loadingTipItems,
}]; }];
}, }
loaded: function () { loaded() {
var self = this, o = this.options; BI.Layers.remove(this.getName() + "-loading");
BI.Layers.remove(self.getName() + "-loading");
this._loading && this._loading.destroy(); this._loading && this._loading.destroy();
o.onLoaded(); this.options.onLoaded();
self.fireEvent(BI.Pane.EVENT_LOADED); this.fireEvent(Pane.EVENT_LOADED);
this.element.removeClass("loading-status"); this.element.removeClass("loading-status");
}, }
check: function () { check() {
this.setTipVisible(BI.isEmpty(this.options.items)); this.setTipVisible(BI.isEmpty(this.options.items));
}, }
setTipVisible: function (b) { setTipVisible(b) {
if (b === true) { if (b === true) {
this._assertTip(); this._assertTip();
this._tipText && this._tipText.setVisible(true); this._tipText && this._tipText.setVisible(true);
} else { } else {
this._tipText && this._tipText.setVisible(false); this._tipText && this._tipText.setVisible(false);
} }
}, }
setTipText: function (text) { setTipText(text) {
this._assertTip(); this._assertTip();
this._tipText.setText(text); this._tipText.setText(text);
}, }
populate: function (items) { populate(items) {
this.options.items = items || []; this.options.items = items || [];
this.check(); this.check();
}, }
}); }
BI.Pane.EVENT_LOADED = "EVENT_LOADED";
BI.Pane.EVENT_LOADING = "EVENT_LOADING";
BI.shortcut("bi.pane", BI.Pane); BI.extend(BI, { Pane });

8
src/core/decorator.js

@ -0,0 +1,8 @@
/**
* 注册widget
*/
export function shortcut() {
return function decorator(Target) {
BI.shortcut(Target.xtype, Target);
};
}

3
tsconfig.json

@ -20,7 +20,8 @@
"noUnusedParameters": true, "noUnusedParameters": true,
"noImplicitReturns": true, "noImplicitReturns": true,
"noFallthroughCasesInSwitch": true, "noFallthroughCasesInSwitch": true,
"emitDeclarationOnly": true "emitDeclarationOnly": true,
"allowJs": true,
}, },
"include": [ "include": [
"typescript/*.ts", "typescript/*.ts",

Loading…
Cancel
Save