forked from fanruan/fineui
Browse Source
Merge in VISUAL/fineui from ~ZHENFEI.LI/fineui:es6 to es6 * commit '4eed1de4829ac8eb7bfee671db3a95acf93eb453': KERNEL-14093 refactor: widget/editor、numbereditor、numberinterval KERNEL-14092 refactor: widget/timeinterval 无JIRA任务 fix: this指向错误的bug 无JIRA任务 fix: 使用脚本漏掉的常量es6
Zhenfei.Li-李振飞
2 years ago
23 changed files with 1177 additions and 1077 deletions
@ -1,20 +1,20 @@
|
||||
/** |
||||
* 小号搜索框 |
||||
* Created by GUY on 2015/9/29. |
||||
* @class BI.SmallSearchEditor |
||||
* @extends BI.SearchEditor |
||||
*/ |
||||
BI.SmallSearchEditor = BI.inherit(BI.SearchEditor, { |
||||
_defaultConfig: function () { |
||||
var conf = BI.SmallSearchEditor.superclass._defaultConfig.apply(this, arguments); |
||||
return BI.extend(conf, { |
||||
baseCls: (conf.baseCls || "") + " bi-small-search-editor", |
||||
height: 20 |
||||
import { shortcut, extend } from "@/core"; |
||||
import { SearchEditor } from "./editor.search"; |
||||
|
||||
@shortcut() |
||||
export class SmallSearchEditor extends SearchEditor { |
||||
static xtype = "bi.small_search_editor" |
||||
|
||||
_defaultConfig() { |
||||
const conf = super._defaultConfig(...arguments); |
||||
|
||||
return extend(conf, { |
||||
baseCls: `${conf.baseCls || ""} bi-small-search-editor`, |
||||
height: 20, |
||||
}); |
||||
}, |
||||
} |
||||
|
||||
_init: function () { |
||||
BI.SmallSearchEditor.superclass._init.apply(this, arguments); |
||||
_init() { |
||||
super._init(...arguments); |
||||
} |
||||
}); |
||||
BI.shortcut("bi.small_search_editor", BI.SmallSearchEditor); |
||||
} |
||||
|
@ -1,20 +1,20 @@
|
||||
/** |
||||
* 小号搜索框 |
||||
* Created by GUY on 2015/9/29. |
||||
* @class BI.SmallTextEditor |
||||
* @extends BI.SearchEditor |
||||
*/ |
||||
BI.SmallTextEditor = BI.inherit(BI.TextEditor, { |
||||
_defaultConfig: function () { |
||||
var conf = BI.SmallTextEditor.superclass._defaultConfig.apply(this, arguments); |
||||
return BI.extend(conf, { |
||||
baseCls: (conf.baseCls || "") + " bi-small-text-editor", |
||||
height: 20 |
||||
import { shortcut, extend } from "@/core"; |
||||
import { TextEditor } from "./editor.text"; |
||||
|
||||
@shortcut() |
||||
export class SmallTextEditor extends TextEditor { |
||||
static xtype = "bi.small_text_editor" |
||||
|
||||
_defaultConfig() { |
||||
const conf = super._defaultConfig(...arguments); |
||||
|
||||
return extend(conf, { |
||||
baseCls: `${conf.baseCls || ""} bi-small-text-editor`, |
||||
height: 20, |
||||
}); |
||||
}, |
||||
} |
||||
|
||||
_init: function () { |
||||
BI.SmallTextEditor.superclass._init.apply(this, arguments); |
||||
_init() { |
||||
super._init(...arguments); |
||||
} |
||||
}); |
||||
BI.shortcut("bi.small_text_editor", BI.SmallTextEditor); |
||||
} |
||||
|
@ -0,0 +1,4 @@
|
||||
export { SearchEditor } from "./editor.search"; |
||||
export { SmallSearchEditor } from "./editor.search.small"; |
||||
export { TextEditor } from "./editor.text"; |
||||
export { SmallTextEditor } from "./editor.text.small"; |
@ -1,202 +1,204 @@
|
||||
/** |
||||
* Created by windy on 2017/3/13. |
||||
* 数值微调器 |
||||
*/ |
||||
BI.NumberEditor = BI.inherit(BI.Widget, { |
||||
_defaultConfig: function (conf) { |
||||
return BI.extend(BI.NumberEditor.superclass._defaultConfig.apply(this, arguments), { |
||||
baseCls: "bi-number-editor bi-focus-shadow " + (conf.simple ? "bi-border-bottom" : "bi-border bi-border-radius"), |
||||
validationChecker: BI.emptyFn, |
||||
valueFormatter: function (v) { |
||||
import { shortcut, Widget, extend, emptyFn, createWidget, toPix, parseFloat, HTapeLayout, GridLayout, isNumeric, clamp, MIN, MAX, KeyCode, add } from "@/core"; |
||||
import { SignEditor } from "@/case"; |
||||
import { TextEditor } from "../editor"; |
||||
import { IconButton } from "@/base"; |
||||
|
||||
@shortcut() |
||||
export class NumberEditor extends Widget { |
||||
static xtype = "bi.number_editor" |
||||
|
||||
static EVENT_CONFIRM = "EVENT_CONFIRM" |
||||
static EVENT_CHANGE = "EVENT_CHANGE" |
||||
|
||||
_defaultConfig(conf) { |
||||
return extend(super._defaultConfig(...arguments), { |
||||
baseCls: `bi-number-editor bi-focus-shadow ${conf.simple ? "bi-border-bottom" : "bi-border bi-border-radius"}`, |
||||
validationChecker: emptyFn, |
||||
valueFormatter (v) { |
||||
return v; |
||||
}, |
||||
valueParser: function (v) { |
||||
valueParser (v) { |
||||
return v; |
||||
}, |
||||
value: 0, |
||||
allowBlank: false, |
||||
errorText: "", |
||||
step: 1, |
||||
min: BI.MIN, |
||||
max: BI.MAX, |
||||
min: MIN, |
||||
max: MAX, |
||||
watermark: "", |
||||
}); |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.NumberEditor.superclass._init.apply(this, arguments); |
||||
var self = this, o = this.options; |
||||
this.editor = BI.createWidget({ |
||||
type: "bi.sign_editor", |
||||
height: BI.toPix(o.height, 2), |
||||
} |
||||
|
||||
_init() { |
||||
super._init(...arguments); |
||||
const o = this.options; |
||||
this.editor = createWidget({ |
||||
type: SignEditor.xtype, |
||||
height: toPix(o.height, 2), |
||||
simple: o.simple, |
||||
allowBlank: o.allowBlank, |
||||
watermark: o.watermark, |
||||
value: o.valueFormatter(o.value), |
||||
validationChecker: function (v) { |
||||
validationChecker: v => { |
||||
// 不设置validationChecker就自动检测
|
||||
var parsedValue = o.valueParser(v); |
||||
if (o.validationChecker === BI.emptyFn && !self._checkValueInRange(parsedValue)) { |
||||
const parsedValue = o.valueParser(v); |
||||
if (o.validationChecker === emptyFn && !this._checkValueInRange(parsedValue)) { |
||||
return false; |
||||
} |
||||
|
||||
return o.validationChecker(parsedValue); |
||||
}, |
||||
errorText: o.errorText, |
||||
listeners: [ |
||||
{ |
||||
eventName: BI.SignEditor.EVENT_QUICK_DOWN, |
||||
action: e => { |
||||
if ([BI.KeyCode.UP, BI.KeyCode.DOWN].includes(e.keyCode)) { |
||||
e.preventDefault(); |
||||
} |
||||
}, |
||||
listeners: [{ |
||||
eventName: SignEditor.EVENT_QUICK_DOWN, |
||||
action: e => { |
||||
if ([KeyCode.UP, KeyCode.DOWN].includes(e.keyCode)) { |
||||
e.preventDefault(); |
||||
} |
||||
}, |
||||
{ |
||||
eventName: BI.SignEditor.EVENT_KEY_DOWN, |
||||
action: (keycode) => { |
||||
if (keycode === BI.KeyCode.UP) { |
||||
this._finetuning(o.step); |
||||
|
||||
return; |
||||
} |
||||
if (keycode === BI.KeyCode.DOWN) { |
||||
this._finetuning(-o.step); |
||||
} |
||||
}, |
||||
} |
||||
}, |
||||
{ |
||||
eventName: SignEditor.EVENT_KEY_DOWN, |
||||
action: keycode => { |
||||
if (keycode === KeyCode.UP) { |
||||
this._finetuning(o.step); |
||||
|
||||
return; |
||||
} |
||||
if (keycode === KeyCode.DOWN) { |
||||
this._finetuning(-o.step); |
||||
} |
||||
}, |
||||
} |
||||
], |
||||
}); |
||||
this.editor.on(BI.TextEditor.EVENT_CHANGE, function () { |
||||
this.editor.on(TextEditor.EVENT_CHANGE, () => { |
||||
// 大多数时候valueFormatter往往需要配合valueParser一起使用
|
||||
var value = this.getValue(); |
||||
var parsedValue = o.valueParser(value); |
||||
this.setValue(o.valueFormatter(parsedValue)); |
||||
self.fireEvent(BI.NumberEditor.EVENT_CHANGE); |
||||
const value = this.editor.getValue(); |
||||
const parsedValue = o.valueParser(value); |
||||
this.editor.setValue(o.valueFormatter(parsedValue)); |
||||
this.fireEvent(NumberEditor.EVENT_CHANGE); |
||||
}); |
||||
this.editor.on(BI.TextEditor.EVENT_ERROR, function () { |
||||
o.value = BI.parseFloat(this.getLastValidValue()); |
||||
self._checkAdjustDisabled(o.value); |
||||
self.element.addClass("error"); |
||||
this.editor.on(TextEditor.EVENT_ERROR, () => { |
||||
o.value = parseFloat(this.editor.getLastValidValue()); |
||||
this._checkAdjustDisabled(o.value); |
||||
this.element.addClass("error"); |
||||
}); |
||||
this.editor.on(BI.TextEditor.EVENT_VALID, function () { |
||||
o.value = BI.parseFloat(this.getValue()); |
||||
self._checkAdjustDisabled(o.value); |
||||
self.element.removeClass("error"); |
||||
this.editor.on(TextEditor.EVENT_VALID, () => { |
||||
o.value = parseFloat(this.editor.getValue()); |
||||
this._checkAdjustDisabled(o.value); |
||||
this.element.removeClass("error"); |
||||
}); |
||||
this.editor.on(BI.TextEditor.EVENT_CONFIRM, function () { |
||||
self.fireEvent(BI.NumberEditor.EVENT_CONFIRM); |
||||
this.editor.on(TextEditor.EVENT_CONFIRM, () => { |
||||
this.fireEvent(NumberEditor.EVENT_CONFIRM); |
||||
}); |
||||
this.topBtn = BI.createWidget({ |
||||
type: "bi.icon_button", |
||||
this.topBtn = createWidget({ |
||||
type: IconButton.xtype, |
||||
forceNotSelected: true, |
||||
trigger: "lclick,", |
||||
debounce: false, |
||||
cls: (o.simple ? "solid-triangle-top-font " : "add-up-font bi-border-left ") + "top-button bi-list-item-active2 icon-size-12", |
||||
cls: `${o.simple ? "solid-triangle-top-font " : "add-up-font bi-border-left "}top-button bi-list-item-active2 icon-size-12`, |
||||
}); |
||||
this.topBtn.on(BI.IconButton.EVENT_CHANGE, function () { |
||||
self._finetuning(o.step); |
||||
self.fireEvent(BI.NumberEditor.EVENT_CHANGE); |
||||
self.fireEvent(BI.NumberEditor.EVENT_CONFIRM); |
||||
this.topBtn.on(IconButton.EVENT_CHANGE, () => { |
||||
this._finetuning(o.step); |
||||
this.fireEvent(NumberEditor.EVENT_CHANGE); |
||||
this.fireEvent(NumberEditor.EVENT_CONFIRM); |
||||
}); |
||||
this.bottomBtn = BI.createWidget({ |
||||
type: "bi.icon_button", |
||||
this.bottomBtn = createWidget({ |
||||
type: IconButton.xtype, |
||||
trigger: "lclick,", |
||||
forceNotSelected: true, |
||||
debounce: false, |
||||
cls: (o.simple ? "solid-triangle-bottom-font " : "minus-down-font bi-border-left ") + "bottom-button bi-list-item-active2 icon-size-12", |
||||
cls: `${o.simple ? "solid-triangle-bottom-font " : "minus-down-font bi-border-left "}bottom-button bi-list-item-active2 icon-size-12`, |
||||
}); |
||||
this.bottomBtn.on(BI.IconButton.EVENT_CHANGE, function () { |
||||
self._finetuning(-o.step); |
||||
self.fireEvent(BI.NumberEditor.EVENT_CHANGE); |
||||
self.fireEvent(BI.NumberEditor.EVENT_CONFIRM); |
||||
this.bottomBtn.on(IconButton.EVENT_CHANGE, () => { |
||||
this._finetuning(-o.step); |
||||
this.fireEvent(NumberEditor.EVENT_CHANGE); |
||||
this.fireEvent(NumberEditor.EVENT_CONFIRM); |
||||
}); |
||||
BI.createWidget({ |
||||
type: "bi.htape", |
||||
height: BI.toPix(o.height, 2), |
||||
createWidget({ |
||||
type: HTapeLayout.xtype, |
||||
height: toPix(o.height, 2), |
||||
element: this, |
||||
items: [ |
||||
this.editor, { |
||||
el: { |
||||
type: "bi.grid", |
||||
type: GridLayout.xtype, |
||||
columns: 1, |
||||
rows: 2, |
||||
items: [ |
||||
{ |
||||
column: 0, |
||||
row: 0, |
||||
el: this.topBtn, |
||||
}, { |
||||
column: 0, |
||||
row: 1, |
||||
el: this.bottomBtn, |
||||
} |
||||
], |
||||
items: [{ |
||||
column: 0, |
||||
row: 0, |
||||
el: this.topBtn, |
||||
}, { |
||||
column: 0, |
||||
row: 1, |
||||
el: this.bottomBtn, |
||||
}], |
||||
}, |
||||
width: 23, |
||||
} |
||||
], |
||||
}); |
||||
}, |
||||
} |
||||
|
||||
focus: function () { |
||||
focus() { |
||||
this.editor.focus(); |
||||
}, |
||||
} |
||||
|
||||
isEditing: function () { |
||||
isEditing() { |
||||
return this.editor.isEditing(); |
||||
}, |
||||
} |
||||
|
||||
_checkValueInRange: function (v) { |
||||
var o = this.options; |
||||
_checkValueInRange(v) { |
||||
const o = this.options; |
||||
|
||||
return !!(BI.isNumeric(v) && BI.parseFloat(v) >= o.min && BI.parseFloat(v) <= o.max); |
||||
}, |
||||
return !!(isNumeric(v) && parseFloat(v) >= o.min && parseFloat(v) <= o.max); |
||||
} |
||||
|
||||
_checkAdjustDisabled: function (v) { |
||||
if (this.options.validationChecker === BI.emptyFn) { |
||||
this.bottomBtn.setEnable(BI.parseFloat(v) > this.options.min); |
||||
this.topBtn.setEnable(BI.parseFloat(v) < this.options.max); |
||||
_checkAdjustDisabled(v) { |
||||
if (this.options.validationChecker === emptyFn) { |
||||
this.bottomBtn.setEnable(parseFloat(v) > this.options.min); |
||||
this.topBtn.setEnable(parseFloat(v) < this.options.max); |
||||
} |
||||
}, |
||||
|
||||
// 微调
|
||||
_finetuning: function (add) { |
||||
const { max, min } = this.options; |
||||
let v = BI.parseFloat(this.getValue()); |
||||
v = BI.add(v, add); |
||||
v = BI.clamp(v, min, max); |
||||
} |
||||
|
||||
_finetuning(addValue) { |
||||
const { |
||||
max, |
||||
min, |
||||
} = this.options; |
||||
let v = parseFloat(this.getValue()); |
||||
v = add(v, addValue); |
||||
v = clamp(v, min, max); |
||||
this.setValue(v); |
||||
}, |
||||
} |
||||
|
||||
setUpEnable: function (v) { |
||||
setUpEnable(v) { |
||||
this.topBtn.setEnable(!!v); |
||||
}, |
||||
} |
||||
|
||||
setDownEnable: function (v) { |
||||
setDownEnable(v) { |
||||
this.bottomBtn.setEnable(!!v); |
||||
}, |
||||
} |
||||
|
||||
getLastValidValue: function () { |
||||
getLastValidValue() { |
||||
return this.editor.getLastValidValue(); |
||||
}, |
||||
} |
||||
|
||||
getLastChangedValue: function () { |
||||
getLastChangedValue() { |
||||
return this.editor.getLastChangedValue(); |
||||
}, |
||||
} |
||||
|
||||
getValue: function () { |
||||
getValue() { |
||||
return this.options.value; |
||||
}, |
||||
} |
||||
|
||||
setValue: function (v) { |
||||
var o = this.options; |
||||
setValue(v) { |
||||
const o = this.options; |
||||
o.value = v; |
||||
this.editor.setValue(o.valueFormatter(v)); |
||||
this._checkAdjustDisabled(o.value); |
||||
}, |
||||
|
||||
}); |
||||
BI.NumberEditor.EVENT_CONFIRM = "EVENT_CONFIRM"; |
||||
BI.NumberEditor.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
BI.shortcut("bi.number_editor", BI.NumberEditor); |
||||
} |
||||
} |
||||
|
@ -0,0 +1,3 @@
|
||||
export { DateInterval } from "./dateinterval"; |
||||
export { TimeInterval } from "./timeinterval"; |
||||
export { TimePeriods } from "./timeperiods"; |
@ -1,92 +1,90 @@
|
||||
/** |
||||
* 时间区间 |
||||
* qcc |
||||
* 2019/2/28 |
||||
*/ |
||||
import { shortcut, extend } from "@/core"; |
||||
import { Single, Label } from "@/base"; |
||||
import { TimeCombo } from "../time"; |
||||
|
||||
@shortcut() |
||||
export class TimePeriods extends Single { |
||||
static xtype = "bi.time_periods" |
||||
|
||||
props = { |
||||
extraCls: "bi-time-interval", |
||||
value: {}, |
||||
}; |
||||
|
||||
static EVENT_CONFIRM = "EVENT_CONFIRM" |
||||
static EVENT_CHANGE = "EVENT_CHANGE" |
||||
|
||||
!(function () { |
||||
BI.TimePeriods = BI.inherit(BI.Single, { |
||||
constants: { |
||||
height: 24, |
||||
width: 24, |
||||
hgap: 15, |
||||
offset: -15 |
||||
}, |
||||
props: { |
||||
extraCls: "bi-time-interval", |
||||
value: {} |
||||
}, |
||||
|
||||
render: function () { |
||||
var self = this, o = this.options; |
||||
|
||||
return { |
||||
type: "bi.horizontal_fill", |
||||
columnSize: ["fill", "", "fill"], |
||||
items: [{ |
||||
el: BI.extend({ |
||||
ref: function (_ref) { |
||||
self.left = _ref; |
||||
} |
||||
}, this._createCombo(o.value.start, o.watermark?.start)) |
||||
}, { |
||||
el: { |
||||
type: "bi.label", |
||||
height: o.height, |
||||
hgap: 5, |
||||
text: "-", |
||||
ref: function (_ref) { |
||||
self.label = _ref; |
||||
} |
||||
} |
||||
}, { |
||||
el: BI.extend({ |
||||
ref: function (_ref) { |
||||
self.right = _ref; |
||||
} |
||||
}, this._createCombo(o.value.end, o.watermark?.end)) |
||||
}] |
||||
}; |
||||
}, |
||||
render() { |
||||
const o = this.options; |
||||
|
||||
return { |
||||
type: "bi.horizontal_fill", |
||||
columnSize: ["fill", "", "fill"], |
||||
items: [{ |
||||
el: extend({ |
||||
ref: _ref => { |
||||
this.left = _ref; |
||||
}, |
||||
}, this._createCombo(o.value.start, o.watermark?.start)), |
||||
}, { |
||||
el: { |
||||
type: Label.xtype, |
||||
height: o.height, |
||||
hgap: 5, |
||||
text: "-", |
||||
ref: _ref => { |
||||
this.label = _ref; |
||||
}, |
||||
}, |
||||
}, { |
||||
el: extend({ |
||||
ref: _ref => { |
||||
this.right = _ref; |
||||
}, |
||||
}, this._createCombo(o.value.end, o.watermark?.end)), |
||||
}], |
||||
}; |
||||
} |
||||
|
||||
_createCombo(v, watermark) { |
||||
const o = this.options; |
||||
|
||||
return { |
||||
type: TimeCombo.xtype, |
||||
value: v, |
||||
height: o.height, |
||||
watermark, |
||||
listeners: [{ |
||||
eventName: TimeCombo.EVENT_BEFORE_POPUPVIEW, |
||||
action: () => { |
||||
this.left.hidePopupView(); |
||||
this.right.hidePopupView(); |
||||
}, |
||||
}, { |
||||
eventName: TimeCombo.EVENT_CHANGE, |
||||
action: () => { |
||||
this.fireEvent(TimePeriods.EVENT_CHANGE); |
||||
}, |
||||
}, { |
||||
eventName: TimeCombo.EVENT_CONFIRM, |
||||
action: () => { |
||||
this.fireEvent(TimePeriods.EVENT_CONFIRM); |
||||
}, |
||||
}], |
||||
}; |
||||
} |
||||
|
||||
_createCombo: function (v, watermark) { |
||||
var self = this; |
||||
var o = this.options; |
||||
return { |
||||
type: "bi.time_combo", |
||||
value: v, |
||||
height: o.height, |
||||
watermark: watermark, |
||||
listeners: [{ |
||||
eventName: BI.TimeCombo.EVENT_BEFORE_POPUPVIEW, |
||||
action: function () { |
||||
self.left.hidePopupView(); |
||||
self.right.hidePopupView(); |
||||
} |
||||
}, { |
||||
eventName: BI.TimeCombo.EVENT_CHANGE, |
||||
action: function () { |
||||
self.fireEvent(BI.TimePeriods.EVENT_CHANGE); |
||||
} |
||||
}, { |
||||
eventName: BI.TimeCombo.EVENT_CONFIRM, |
||||
action: function () { |
||||
self.fireEvent(BI.TimePeriods.EVENT_CONFIRM); |
||||
} |
||||
}] |
||||
}; |
||||
}, |
||||
setValue(date) { |
||||
date = date || {}; |
||||
this.left.setValue(date.start); |
||||
this.right.setValue(date.end); |
||||
} |
||||
|
||||
setValue: function (date) { |
||||
date = date || {}; |
||||
this.left.setValue(date.start); |
||||
this.right.setValue(date.end); |
||||
}, |
||||
getValue: function () { |
||||
return {start: this.left.getValue(), end: this.right.getValue()}; |
||||
} |
||||
}); |
||||
BI.TimePeriods.EVENT_CONFIRM = "EVENT_CONFIRM"; |
||||
BI.TimePeriods.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
BI.shortcut("bi.time_periods", BI.TimePeriods); |
||||
})(); |
||||
getValue() { |
||||
return { |
||||
start: this.left.getValue(), |
||||
end: this.right.getValue(), |
||||
}; |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue