Browse Source

Pull request #2363: 无JIRA任务 chore: 优化代码

Merge in VISUAL/fineui from ~GUY/fineui:master to master

* commit 'fabde0b58c3b9fc19b3214ea8b3087ad3aa283f2':
  chore: 优化代码
es6
guy 3 years ago
parent
commit
3fb343c759
  1. 283
      src/case/colorchooser/colorchooser.popup.hex.js
  2. 4
      src/case/colorchooser/colorpicker/colorpicker.hex.js
  3. 4
      src/case/colorchooser/colorpicker/editor.colorpicker.hex.js

283
src/case/colorchooser/colorchooser.popup.hex.js

@ -16,32 +16,59 @@ BI.HexColorChooserPopup = BI.inherit(BI.Widget, {
var self = this, o = this.options; var self = this, o = this.options;
var hasRecommendColors = BI.isNotNull(o.recommendColorsGetter()); var hasRecommendColors = BI.isNotNull(o.recommendColorsGetter());
return [{ return [{
el: { type: "bi.vertical",
type: 'bi.vertical', items: [{
items: [{ el: {
el: { type: "bi.vertical",
type: "bi.vertical", hgap: 15,
hgap: 15, items: [BI.extend({
items: [BI.extend({ type: o.simple ? "bi.simple_hex_color_picker_editor" : "bi.hex_color_picker_editor",
type: o.simple ? "bi.simple_hex_color_picker_editor" : "bi.hex_color_picker_editor", value: o.value,
height: o.simple ? 36 : 70,
listeners: [{
eventName: BI.ColorPickerEditor.EVENT_CHANGE,
action: function () {
self.setValue(this.getValue());
self._dealStoreColors();
self.fireEvent(BI.ColorChooserPopup.EVENT_VALUE_CHANGE, arguments);
}
}],
ref: function (_ref) {
self.colorEditor = _ref;
}
}, o.editor), {
el: {
type: "bi.hex_color_picker",
cls: "bi-border-bottom bi-border-right",
items: [this._digestStoreColors(this._getStoreColors())],
height: 22,
value: o.value, value: o.value,
height: o.simple ? 36 : 70,
listeners: [{ listeners: [{
eventName: BI.ColorPickerEditor.EVENT_CHANGE, eventName: BI.ColorPicker.EVENT_CHANGE,
action: function () { action: function () {
self.setValue(this.getValue()); self.setValue(this.getValue()[0]);
self._dealStoreColors(); self._dealStoreColors();
self.fireEvent(BI.ColorChooserPopup.EVENT_VALUE_CHANGE, arguments); self.fireEvent(BI.ColorChooserPopup.EVENT_CHANGE, arguments);
} }
}], }],
ref: function (_ref) { ref: function (_ref) {
self.colorEditor = _ref; self.storeColors = _ref;
} }
}, o.editor), { },
el: { tgap: 10,
height: 22
}, {
el: hasRecommendColors ? {
type: "bi.vertical",
items: [{
type: "bi.label",
text: BI.i18nText("BI-Basic_Recommend_Color"),
textAlign: "left",
height: 24
}, {
type: "bi.hex_color_picker", type: "bi.hex_color_picker",
cls: "bi-border-bottom bi-border-right", cls: "bi-border-bottom bi-border-right",
items: [this._digestStoreColors(this._getStoreColors())], items: [this._digestStoreColors(o.recommendColorsGetter())],
height: 22, height: 22,
value: o.value, value: o.value,
listeners: [{ listeners: [{
@ -53,144 +80,111 @@ BI.HexColorChooserPopup = BI.inherit(BI.Widget, {
} }
}], }],
ref: function (_ref) { ref: function (_ref) {
self.storeColors = _ref; self.recommendColors = _ref;
} }
}, }]
tgap: 10, } : {type: "bi.layout"},
height: 22 tgap: hasRecommendColors ? 10 : 0,
}, { height: hasRecommendColors ? 47 : 0
el: hasRecommendColors ? { }, {
type: 'bi.vertical',
items: [{
type: 'bi.label',
text: BI.i18nText('BI-Basic_Recommend_Color'),
textAlign: 'left',
height: 24,
}, {
type: "bi.hex_color_picker",
cls: "bi-border-bottom bi-border-right",
items: [this._digestStoreColors(o.recommendColorsGetter())],
height: 22,
value: o.value,
listeners: [{
eventName: BI.ColorPicker.EVENT_CHANGE,
action: function () {
self.setValue(this.getValue()[0]);
self._dealStoreColors();
self.fireEvent(BI.ColorChooserPopup.EVENT_CHANGE, arguments);
}
}],
ref: function (_ref) {
self.recommendColors = _ref;
}
}]
} : { type: 'bi.layout' },
tgap: hasRecommendColors ? 10 : 0,
height: hasRecommendColors ? 47 : 0
}, {
el: {
type: 'bi.layout',
cls: 'bi-border-top',
},
vgap: 10,
height: 1
}, {
type: 'bi.absolute',
items: [{
el: {
type: "bi.hex_color_picker",
space: true,
value: o.value,
listeners: [{
eventName: BI.ColorPicker.EVENT_CHANGE,
action: function () {
self.setValue(this.getValue()[0]);
self._dealStoreColors();
self.fireEvent(BI.ColorChooserPopup.EVENT_CHANGE, arguments);
}
}],
ref: function (_ref) {
self.colorPicker = _ref;
},
},
top: 0,
left: 0,
right: 0,
bottom: 1,
}],
height: 80,
}]
}
}, {
el: {
type: "bi.combo",
cls: "bi-border-top",
container: null,
direction: "right,top",
isNeedAdjustHeight: false,
el: { el: {
type: "bi.text_item", type: "bi.layout",
cls: "color-chooser-popup-more bi-list-item", cls: "bi-border-top"
textAlign: "center",
height: 24,
textLgap: 10,
text: BI.i18nText("BI-Basic_More") + "..."
}, },
popup: { vgap: 10,
type: "bi.popup_panel", height: 1
buttons: [BI.i18nText("BI-Basic_Cancel"), BI.i18nText("BI-Basic_Save")], }, {
title: BI.i18nText("BI-Custom_Color"), type: "bi.absolute",
items: [{
el: { el: {
type: "bi.custom_color_chooser", type: "bi.hex_color_picker",
editor: o.editor, space: true,
value: o.value,
listeners: [{
eventName: BI.ColorPicker.EVENT_CHANGE,
action: function () {
self.setValue(this.getValue()[0]);
self._dealStoreColors();
self.fireEvent(BI.ColorChooserPopup.EVENT_CHANGE, arguments);
}
}],
ref: function (_ref) { ref: function (_ref) {
self.customColorChooser = _ref; self.colorPicker = _ref;
} }
}, },
stopPropagation: false, top: 0,
bgap: -1, left: 0,
rgap: 1, right: 0,
lgap: 1, bottom: 1
minWidth: 227, }],
listeners: [{ height: 80
eventName: BI.PopupPanel.EVENT_CLICK_TOOLBAR_BUTTON, }]
action: function (index) { }
switch (index) { }, {
case 0: el: {
self.more.hideView(); type: "bi.combo",
break; cls: "bi-border-top",
case 1: container: null,
var color = self.customColorChooser.getValue(); direction: "right,top",
// farbtastic选择器没有透明和自动选项,点击保存不应该设置透明 isNeedAdjustHeight: false,
if (BI.isNotEmptyString(color)) { el: {
self.setValue(color); type: "bi.text_item",
self._dealStoreColors(); cls: "color-chooser-popup-more bi-list-item",
} textAlign: "center",
self.more.hideView(); height: 24,
self.fireEvent(BI.ColorChooserPopup.EVENT_CHANGE, arguments); textLgap: 10,
break; text: BI.i18nText("BI-Basic_More") + "..."
} },
} popup: {
}] type: "bi.popup_panel",
buttons: [BI.i18nText("BI-Basic_Cancel"), BI.i18nText("BI-Basic_Save")],
title: BI.i18nText("BI-Custom_Color"),
el: {
type: "bi.custom_color_chooser",
editor: o.editor,
ref: function (_ref) {
self.customColorChooser = _ref;
}
}, },
stopPropagation: false,
bgap: -1,
rgap: 1,
lgap: 1,
minWidth: 227,
listeners: [{ listeners: [{
eventName: BI.Combo.EVENT_AFTER_POPUPVIEW, eventName: BI.PopupPanel.EVENT_CLICK_TOOLBAR_BUTTON,
action: function () { action: function (index) {
self.customColorChooser.setValue(self.getValue()); switch (index) {
case 0:
self.more.hideView();
break;
case 1:
var color = self.customColorChooser.getValue();
// farbtastic选择器没有透明和自动选项,点击保存不应该设置透明
if (BI.isNotEmptyString(color)) {
self.setValue(color);
self._dealStoreColors();
}
self.more.hideView();
self.fireEvent(BI.ColorChooserPopup.EVENT_CHANGE, arguments);
break;
}
} }
}], }]
ref: function (_ref) {
self.more = _ref;
}
}, },
tgap: 10, listeners: [{
height: 24 eventName: BI.Combo.EVENT_AFTER_POPUPVIEW,
}] action: function () {
}, self.customColorChooser.setValue(self.getValue());
left: 0, }
right: 0, }],
top: 0, ref: function (_ref) {
bottom: 0 self.more = _ref;
}
},
tgap: 10,
height: 24
}]
}, { }, {
type: "bi.absolute", type: "bi.absolute",
items: [{ items: [{
@ -212,7 +206,6 @@ BI.HexColorChooserPopup = BI.inherit(BI.Widget, {
// 这里就实现的不好了,setValue里面有个editor,editor的setValue会检测错误然后出bubble提示 // 这里就实现的不好了,setValue里面有个editor,editor的setValue会检测错误然后出bubble提示
mounted: function () { mounted: function () {
var self = this;
var o = this.options; var o = this.options;
if (BI.isNotNull(o.value)) { if (BI.isNotNull(o.value)) {
this.setValue(o.value); this.setValue(o.value);
@ -251,7 +244,7 @@ BI.HexColorChooserPopup = BI.inherit(BI.Widget, {
return items; return items;
}, },
_getStoreColors: function() { _getStoreColors: function () {
var self = this, o = this.options; var self = this, o = this.options;
var colorsArray = BI.string2Array(BI.Cache.getItem("colors") || ""); var colorsArray = BI.string2Array(BI.Cache.getItem("colors") || "");
return BI.filter(colorsArray, function (idx, color) { return BI.filter(colorsArray, function (idx, color) {

4
src/case/colorchooser/colorpicker/colorpicker.hex.js

@ -110,8 +110,6 @@ BI.HexColorPicker = BI.inherit(BI.Widget, {
render: function () { render: function () {
var self = this, o = this.options; var self = this, o = this.options;
this.colors = BI.createWidget();
return { return {
type: "bi.button_group", type: "bi.button_group",
items: this._digest(o.items || this._items), items: this._digest(o.items || this._items),
@ -167,4 +165,4 @@ BI.HexColorPicker = BI.inherit(BI.Widget, {
} }
}); });
BI.HexColorPicker.EVENT_CHANGE = "EVENT_CHANGE"; BI.HexColorPicker.EVENT_CHANGE = "EVENT_CHANGE";
BI.shortcut("bi.hex_color_picker", BI.HexColorPicker); BI.shortcut("bi.hex_color_picker", BI.HexColorPicker);

4
src/case/colorchooser/colorpicker/editor.colorpicker.hex.js

@ -61,7 +61,7 @@ BI.HexColorPickerEditor = BI.inherit(BI.Widget, {
tgap: 10, tgap: 10,
items: [{ items: [{
type: 'bi.vertical_adapt', type: 'bi.vertical_adapt',
columnSize: [0.5, 'fill'], columnSize: ["fill", 'fill'],
height: 24, height: 24,
items: [{ items: [{
type: "bi.color_picker_show_button", type: "bi.color_picker_show_button",
@ -284,4 +284,4 @@ BI.HexColorPickerEditor = BI.inherit(BI.Widget, {
} }
}); });
BI.HexColorPickerEditor.EVENT_CHANGE = "EVENT_CHANGE"; BI.HexColorPickerEditor.EVENT_CHANGE = "EVENT_CHANGE";
BI.shortcut("bi.hex_color_picker_editor", BI.HexColorPickerEditor); BI.shortcut("bi.hex_color_picker_editor", BI.HexColorPickerEditor);

Loading…
Cancel
Save