|
|
|
@ -1,7 +1,26 @@
|
|
|
|
|
import { shortcut, Widget, isNotNull, extend, isNotEmptyString, array2String, map, count, string2Array, filter, isArray, Cache, Queue } from "@/core"; |
|
|
|
|
import { Combo } from "@/base"; |
|
|
|
|
import { |
|
|
|
|
VerticalLayout, |
|
|
|
|
Layout, |
|
|
|
|
AbsoluteLayout, |
|
|
|
|
shortcut, |
|
|
|
|
Widget, |
|
|
|
|
isNotNull, |
|
|
|
|
extend, |
|
|
|
|
isNotEmptyString, |
|
|
|
|
array2String, |
|
|
|
|
map, |
|
|
|
|
count, |
|
|
|
|
string2Array, |
|
|
|
|
filter, |
|
|
|
|
isArray, |
|
|
|
|
Cache, |
|
|
|
|
Queue |
|
|
|
|
} from "@/core"; |
|
|
|
|
import { Label, Combo, TextItem } from "@/base"; |
|
|
|
|
import { PopupPanel } from "../layer"; |
|
|
|
|
import { CustomColorChooser } from "./colorchooser.custom"; |
|
|
|
|
import { ColorChooserPopup } from "./colorchooser.popup"; |
|
|
|
|
import { ColorPickerEditor, ColorPicker } from "./colorpicker"; |
|
|
|
|
import { ColorPickerEditor, ColorPicker, HexColorPicker } from "./colorpicker"; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @author windy |
|
|
|
@ -20,203 +39,244 @@ export class HexColorChooserPopup extends Widget {
|
|
|
|
|
width: 300, |
|
|
|
|
recommendColorsGetter: BI.emptyFn, // 推荐色获取接口
|
|
|
|
|
simple: false, // 简单模式, popup中没有自动和透明
|
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
render() { |
|
|
|
|
const o = this.options; |
|
|
|
|
const hasRecommendColors = isNotNull(o.recommendColorsGetter()); |
|
|
|
|
|
|
|
|
|
return [{ |
|
|
|
|
type: "bi.vertical", |
|
|
|
|
items: [{ |
|
|
|
|
el: { |
|
|
|
|
type: "bi.vertical", |
|
|
|
|
hgap: 15, |
|
|
|
|
items: [extend({ |
|
|
|
|
type: o.simple ? "bi.simple_hex_color_picker_editor" : "bi.hex_color_picker_editor", |
|
|
|
|
value: o.value, |
|
|
|
|
height: o.simple ? 36 : 70, |
|
|
|
|
listeners: [{ |
|
|
|
|
eventName: ColorPickerEditor.EVENT_CHANGE, |
|
|
|
|
action: (...args) => { |
|
|
|
|
this.setValue(this.colorEditor.getValue()); |
|
|
|
|
this._dealStoreColors(); |
|
|
|
|
this.fireEvent(ColorChooserPopup.EVENT_VALUE_CHANGE, ...args); |
|
|
|
|
}, |
|
|
|
|
}], |
|
|
|
|
ref: _ref => { |
|
|
|
|
this.colorEditor = _ref; |
|
|
|
|
}, |
|
|
|
|
}, o.editor), { |
|
|
|
|
|
|
|
|
|
return [ |
|
|
|
|
{ |
|
|
|
|
type: VerticalLayout.xtype, |
|
|
|
|
items: [ |
|
|
|
|
{ |
|
|
|
|
el: { |
|
|
|
|
type: "bi.hex_color_picker", |
|
|
|
|
cls: "bi-border-bottom bi-border-right", |
|
|
|
|
items: [this._digestStoreColors(this._getStoreColors())], |
|
|
|
|
height: 22, |
|
|
|
|
value: o.value, |
|
|
|
|
listeners: [{ |
|
|
|
|
eventName: ColorPicker.EVENT_CHANGE, |
|
|
|
|
action: (...args) => { |
|
|
|
|
this.setValue(this.storeColors.getValue()[0]); |
|
|
|
|
this._dealStoreColors(); |
|
|
|
|
this.fireEvent(ColorChooserPopup.EVENT_CHANGE, ...args); |
|
|
|
|
type: VerticalLayout.xtype, |
|
|
|
|
hgap: 15, |
|
|
|
|
items: [ |
|
|
|
|
extend( |
|
|
|
|
{ |
|
|
|
|
type: o.simple |
|
|
|
|
? "bi.simple_hex_color_picker_editor" |
|
|
|
|
: "bi.hex_color_picker_editor", |
|
|
|
|
value: o.value, |
|
|
|
|
height: o.simple ? 36 : 70, |
|
|
|
|
listeners: [ |
|
|
|
|
{ |
|
|
|
|
eventName: ColorPickerEditor.EVENT_CHANGE, |
|
|
|
|
action: (...args) => { |
|
|
|
|
this.setValue(this.colorEditor.getValue()); |
|
|
|
|
this._dealStoreColors(); |
|
|
|
|
this.fireEvent(ColorChooserPopup.EVENT_VALUE_CHANGE, ...args); |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
], |
|
|
|
|
ref: _ref => { |
|
|
|
|
this.colorEditor = _ref; |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
o.editor |
|
|
|
|
), |
|
|
|
|
{ |
|
|
|
|
el: { |
|
|
|
|
type: HexColorPicker.xtype, |
|
|
|
|
cls: "bi-border-bottom bi-border-right", |
|
|
|
|
items: [this._digestStoreColors(this._getStoreColors())], |
|
|
|
|
height: 22, |
|
|
|
|
value: o.value, |
|
|
|
|
listeners: [ |
|
|
|
|
{ |
|
|
|
|
eventName: ColorPicker.EVENT_CHANGE, |
|
|
|
|
action: (...args) => { |
|
|
|
|
this.setValue(this.storeColors.getValue()[0]); |
|
|
|
|
this._dealStoreColors(); |
|
|
|
|
this.fireEvent(ColorChooserPopup.EVENT_CHANGE, ...args); |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
], |
|
|
|
|
ref: _ref => { |
|
|
|
|
this.storeColors = _ref; |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
tgap: 10, |
|
|
|
|
height: 22, |
|
|
|
|
}, |
|
|
|
|
}], |
|
|
|
|
ref: _ref => { |
|
|
|
|
this.storeColors = _ref; |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
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", |
|
|
|
|
cls: "bi-border-bottom bi-border-right", |
|
|
|
|
items: [this._digestStoreColors(o.recommendColorsGetter())], |
|
|
|
|
height: 22, |
|
|
|
|
value: o.value, |
|
|
|
|
listeners: [{ |
|
|
|
|
eventName: ColorPicker.EVENT_CHANGE, |
|
|
|
|
action: (...args) => { |
|
|
|
|
this.setValue(this.recommendColors.getValue()[0]); |
|
|
|
|
this._dealStoreColors(); |
|
|
|
|
this.fireEvent(ColorChooserPopup.EVENT_CHANGE, ...args); |
|
|
|
|
{ |
|
|
|
|
el: hasRecommendColors |
|
|
|
|
? { |
|
|
|
|
type: VerticalLayout.xtype, |
|
|
|
|
items: [ |
|
|
|
|
{ |
|
|
|
|
type: Label.xtype, |
|
|
|
|
text: BI.i18nText("BI-Basic_Recommend_Color"), |
|
|
|
|
textAlign: "left", |
|
|
|
|
height: 24, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
type: HexColorPicker.xtype, |
|
|
|
|
cls: "bi-border-bottom bi-border-right", |
|
|
|
|
items: [this._digestStoreColors(o.recommendColorsGetter())], |
|
|
|
|
height: 22, |
|
|
|
|
value: o.value, |
|
|
|
|
listeners: [ |
|
|
|
|
{ |
|
|
|
|
eventName: ColorPicker.EVENT_CHANGE, |
|
|
|
|
action: (...args) => { |
|
|
|
|
this.setValue(this.recommendColors.getValue()[0]); |
|
|
|
|
this._dealStoreColors(); |
|
|
|
|
this.fireEvent( |
|
|
|
|
ColorChooserPopup.EVENT_CHANGE, |
|
|
|
|
...args |
|
|
|
|
); |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
], |
|
|
|
|
ref: _ref => { |
|
|
|
|
this.recommendColors = _ref; |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
], |
|
|
|
|
} |
|
|
|
|
: { type: Layout.xtype }, |
|
|
|
|
tgap: hasRecommendColors ? 10 : 0, |
|
|
|
|
height: hasRecommendColors ? 47 : 0, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
el: { |
|
|
|
|
type: Layout.xtype, |
|
|
|
|
cls: "bi-border-top", |
|
|
|
|
}, |
|
|
|
|
}], |
|
|
|
|
ref: _ref => { |
|
|
|
|
this.recommendColors = _ref; |
|
|
|
|
vgap: 10, |
|
|
|
|
height: 1, |
|
|
|
|
}, |
|
|
|
|
}], |
|
|
|
|
} : { type: "bi.layout" }, |
|
|
|
|
tgap: hasRecommendColors ? 10 : 0, |
|
|
|
|
height: hasRecommendColors ? 47 : 0, |
|
|
|
|
}, { |
|
|
|
|
{ |
|
|
|
|
type: AbsoluteLayout.xtype, |
|
|
|
|
items: [ |
|
|
|
|
{ |
|
|
|
|
el: { |
|
|
|
|
type: HexColorPicker.xtype, |
|
|
|
|
space: true, |
|
|
|
|
value: o.value, |
|
|
|
|
listeners: [ |
|
|
|
|
{ |
|
|
|
|
eventName: ColorPicker.EVENT_CHANGE, |
|
|
|
|
action: (...args) => { |
|
|
|
|
this.setValue(this.colorPicker.getValue()[0]); |
|
|
|
|
this._dealStoreColors(); |
|
|
|
|
this.fireEvent(ColorChooserPopup.EVENT_CHANGE, ...args); |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
], |
|
|
|
|
ref: _ref => { |
|
|
|
|
this.colorPicker = _ref; |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
top: 0, |
|
|
|
|
left: 0, |
|
|
|
|
right: 0, |
|
|
|
|
bottom: 1, |
|
|
|
|
} |
|
|
|
|
], |
|
|
|
|
height: 80, |
|
|
|
|
} |
|
|
|
|
], |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
el: { |
|
|
|
|
type: "bi.layout", |
|
|
|
|
type: Combo.xtype, |
|
|
|
|
cls: "bi-border-top", |
|
|
|
|
}, |
|
|
|
|
vgap: 10, |
|
|
|
|
height: 1, |
|
|
|
|
}, { |
|
|
|
|
type: "bi.absolute", |
|
|
|
|
items: [{ |
|
|
|
|
container: null, |
|
|
|
|
direction: "right,top", |
|
|
|
|
isNeedAdjustHeight: false, |
|
|
|
|
el: { |
|
|
|
|
type: "bi.hex_color_picker", |
|
|
|
|
space: true, |
|
|
|
|
value: o.value, |
|
|
|
|
listeners: [{ |
|
|
|
|
eventName: ColorPicker.EVENT_CHANGE, |
|
|
|
|
action: (...args) => { |
|
|
|
|
this.setValue(this.colorPicker.getValue()[0]); |
|
|
|
|
this._dealStoreColors(); |
|
|
|
|
this.fireEvent(ColorChooserPopup.EVENT_CHANGE, ...args); |
|
|
|
|
type: TextItem.xtype, |
|
|
|
|
cls: "color-chooser-popup-more bi-list-item", |
|
|
|
|
textAlign: "center", |
|
|
|
|
height: 24, |
|
|
|
|
textLgap: 10, |
|
|
|
|
text: `${BI.i18nText("BI-Basic_More")}...`, |
|
|
|
|
}, |
|
|
|
|
popup: { |
|
|
|
|
type: PopupPanel.xtype, |
|
|
|
|
buttons: [BI.i18nText("BI-Basic_Cancel"), BI.i18nText("BI-Basic_Save")], |
|
|
|
|
title: BI.i18nText("BI-Custom_Color"), |
|
|
|
|
el: { |
|
|
|
|
type: CustomColorChooser.xtype, |
|
|
|
|
value: o.value, |
|
|
|
|
editor: o.editor, |
|
|
|
|
ref: _ref => { |
|
|
|
|
this.customColorChooser = _ref; |
|
|
|
|
}, |
|
|
|
|
}], |
|
|
|
|
ref: _ref => { |
|
|
|
|
this.colorPicker = _ref; |
|
|
|
|
}, |
|
|
|
|
stopPropagation: false, |
|
|
|
|
bgap: -1, |
|
|
|
|
rgap: 1, |
|
|
|
|
lgap: 1, |
|
|
|
|
minWidth: 227, |
|
|
|
|
listeners: [ |
|
|
|
|
{ |
|
|
|
|
eventName: BI.PopupPanel.EVENT_CLICK_TOOLBAR_BUTTON, |
|
|
|
|
action: (index, ...args) => { |
|
|
|
|
switch (index) { |
|
|
|
|
case 0: |
|
|
|
|
this.more.hideView(); |
|
|
|
|
break; |
|
|
|
|
case 1: { |
|
|
|
|
const color = this.customColorChooser.getValue(); |
|
|
|
|
// farbtastic选择器没有透明和自动选项,点击保存不应该设置透明
|
|
|
|
|
if (isNotEmptyString(color)) { |
|
|
|
|
this.setValue(color); |
|
|
|
|
this._dealStoreColors(); |
|
|
|
|
} |
|
|
|
|
this.more.hideView(); |
|
|
|
|
this.fireEvent(ColorChooserPopup.EVENT_CHANGE, index, ...args); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
default: |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
], |
|
|
|
|
}, |
|
|
|
|
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: { |
|
|
|
|
type: "bi.text_item", |
|
|
|
|
cls: "color-chooser-popup-more bi-list-item", |
|
|
|
|
textAlign: "center", |
|
|
|
|
height: 24, |
|
|
|
|
textLgap: 10, |
|
|
|
|
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", |
|
|
|
|
value: o.value, |
|
|
|
|
editor: o.editor, |
|
|
|
|
listeners: [ |
|
|
|
|
{ |
|
|
|
|
eventName: Combo.EVENT_AFTER_POPUPVIEW, |
|
|
|
|
action: () => { |
|
|
|
|
this.customColorChooser.setValue(this.getValue()); |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
], |
|
|
|
|
ref: _ref => { |
|
|
|
|
this.customColorChooser = _ref; |
|
|
|
|
this.more = _ref; |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
stopPropagation: false, |
|
|
|
|
bgap: -1, |
|
|
|
|
rgap: 1, |
|
|
|
|
lgap: 1, |
|
|
|
|
minWidth: 227, |
|
|
|
|
listeners: [{ |
|
|
|
|
eventName: BI.PopupPanel.EVENT_CLICK_TOOLBAR_BUTTON, |
|
|
|
|
action: (index, ...args) => { |
|
|
|
|
switch (index) { |
|
|
|
|
case 0: |
|
|
|
|
this.more.hideView(); |
|
|
|
|
break; |
|
|
|
|
case 1: { |
|
|
|
|
const color = this.customColorChooser.getValue(); |
|
|
|
|
// farbtastic选择器没有透明和自动选项,点击保存不应该设置透明
|
|
|
|
|
if (isNotEmptyString(color)) { |
|
|
|
|
this.setValue(color); |
|
|
|
|
this._dealStoreColors(); |
|
|
|
|
} |
|
|
|
|
this.more.hideView(); |
|
|
|
|
this.fireEvent(ColorChooserPopup.EVENT_CHANGE, index, ...args); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
default: |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
tgap: 10, |
|
|
|
|
height: 24, |
|
|
|
|
} |
|
|
|
|
], |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
type: AbsoluteLayout.xtype, |
|
|
|
|
items: [ |
|
|
|
|
{ |
|
|
|
|
el: { |
|
|
|
|
type: Layout.xtype, |
|
|
|
|
cls: "disable-mask", |
|
|
|
|
invisible: !o.disabled, |
|
|
|
|
ref: () => { |
|
|
|
|
this.mask = this; |
|
|
|
|
}, |
|
|
|
|
}], |
|
|
|
|
}, |
|
|
|
|
listeners: [{ |
|
|
|
|
eventName: Combo.EVENT_AFTER_POPUPVIEW, |
|
|
|
|
action: () => { |
|
|
|
|
this.customColorChooser.setValue(this.getValue()); |
|
|
|
|
}, |
|
|
|
|
}], |
|
|
|
|
ref: _ref => { |
|
|
|
|
this.more = _ref; |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
tgap: 10, |
|
|
|
|
height: 24, |
|
|
|
|
}], |
|
|
|
|
}, { |
|
|
|
|
type: "bi.absolute", |
|
|
|
|
items: [{ |
|
|
|
|
el: { |
|
|
|
|
type: "bi.layout", |
|
|
|
|
cls: "disable-mask", |
|
|
|
|
invisible: !o.disabled, |
|
|
|
|
ref: () => { |
|
|
|
|
this.mask = this; |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
left: 0, |
|
|
|
|
right: 0, |
|
|
|
|
top: 0, |
|
|
|
|
bottom: 0, |
|
|
|
|
}], |
|
|
|
|
}]; |
|
|
|
|
left: 0, |
|
|
|
|
right: 0, |
|
|
|
|
top: 0, |
|
|
|
|
bottom: 0, |
|
|
|
|
} |
|
|
|
|
], |
|
|
|
|
} |
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 这里就实现的不好了,setValue里面有个editor,editor的setValue会检测错误然后出bubble提示
|
|
|
|
@ -256,15 +316,15 @@ export class HexColorChooserPopup extends Widget {
|
|
|
|
|
disabled: true, |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return items; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_getStoreColors() { |
|
|
|
|
const o = this.options; |
|
|
|
|
const colorsArray = string2Array(Cache.getItem("colors") || ""); |
|
|
|
|
|
|
|
|
|
return filter(colorsArray, (idx, color) => o.simple ? this._isRGBColor(color) : true); |
|
|
|
|
|
|
|
|
|
return filter(colorsArray, (idx, color) => (o.simple ? this._isRGBColor(color) : true)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_isRGBColor(color) { |
|
|
|
|