forked from fanruan/fineui
Browse Source
Merge in VISUAL/fineui from ~IMPACT/fine-ui:es6 to es6 * commit 'd2f320307cf4d09a5e67e02cf4cd47e336373ef7': KERNEL-14107 refactor: widget/searchmultitextvaluecombo、textvaluedownlistcombo ES6化es6
Impact-吴家豪
2 years ago
14 changed files with 263 additions and 240 deletions
@ -1,99 +1,116 @@ |
|||||||
/** |
import { |
||||||
* @class BI.TextValueDownListCombo |
shortcut, |
||||||
* @extend BI.Widget |
Widget, |
||||||
*/ |
extend, |
||||||
BI.TextValueDownListCombo = BI.inherit(BI.Widget, { |
isNotNull, |
||||||
_defaultConfig: function (config) { |
createWidget, |
||||||
return BI.extend(BI.TextValueDownListCombo.superclass._defaultConfig.apply(this, arguments), { |
Selection, |
||||||
baseCls: "bi-text-value-down-list-combo bi-border-radius " + (config.simple ? "bi-border-bottom" : "bi-border"), |
toPix, |
||||||
|
isNull, |
||||||
|
deepClone, |
||||||
|
each, |
||||||
|
flatten, |
||||||
|
has |
||||||
|
} from "@/core"; |
||||||
|
import { DownListCombo } from "../downlist"; |
||||||
|
|
||||||
|
@shortcut() |
||||||
|
export class TextValueDownListCombo extends Widget { |
||||||
|
static xtype = "bi.text_value_down_list_combo"; |
||||||
|
|
||||||
|
static EVENT_CHANGE = "EVENT_CHANGE"; |
||||||
|
|
||||||
|
_defaultConfig(config) { |
||||||
|
return extend(super._defaultConfig(...arguments), { |
||||||
|
baseCls: |
||||||
|
`bi-text-value-down-list-combo bi-border-radius ${config.simple ? "bi-border-bottom" : "bi-border"}`, |
||||||
height: 24, |
height: 24, |
||||||
}); |
}); |
||||||
}, |
} |
||||||
|
|
||||||
_init: function () { |
_init() { |
||||||
var self = this, o = this.options; |
const o = this.options; |
||||||
BI.TextValueDownListCombo.superclass._init.apply(this, arguments); |
super._init(...arguments); |
||||||
this._createValueMap(); |
this._createValueMap(); |
||||||
|
|
||||||
var value; |
let value; |
||||||
if(BI.isNotNull(o.value)) { |
if (isNotNull(o.value)) { |
||||||
value = this._digest(o.value); |
value = this._digest(o.value); |
||||||
} |
} |
||||||
|
|
||||||
this.combo = BI.createWidget({ |
this.combo = createWidget({ |
||||||
type: "bi.down_list_combo", |
type: DownListCombo.xtype, |
||||||
element: this, |
element: this, |
||||||
chooseType: BI.Selection.Single, |
chooseType: Selection.Single, |
||||||
adjustLength: 2, |
adjustLength: 2, |
||||||
width: BI.toPix(o.width, 2), |
width: toPix(o.width, 2), |
||||||
height: BI.toPix(o.height, 2), |
height: toPix(o.height, 2), |
||||||
el: { |
el: { |
||||||
type: "bi.down_list_select_text_trigger", |
type: "bi.down_list_select_text_trigger", |
||||||
ref: function (_ref) { |
ref: _ref => { |
||||||
self.trigger = _ref; |
this.trigger = _ref; |
||||||
}, |
}, |
||||||
cls: "text-value-down-list-trigger", |
cls: "text-value-down-list-trigger", |
||||||
height: BI.toPix(o.height, 2), |
height: toPix(o.height, 2), |
||||||
items: o.items, |
items: o.items, |
||||||
text: o.text, |
text: o.text, |
||||||
value: value |
value, |
||||||
}, |
}, |
||||||
value: BI.isNull(value) ? [] : [value], |
value: isNull(value) ? [] : [value], |
||||||
items: BI.deepClone(o.items) |
items: deepClone(o.items), |
||||||
}); |
}); |
||||||
|
|
||||||
this.combo.on(BI.DownListCombo.EVENT_CHANGE, function () { |
this.combo.on(DownListCombo.EVENT_CHANGE, () => { |
||||||
var currentVal = self.combo.getValue()[0].value; |
const currentVal = this.combo.getValue()[0].value; |
||||||
if (currentVal !== self.value) { |
if (currentVal !== this.value) { |
||||||
self.setValue(currentVal); |
this.setValue(currentVal); |
||||||
self.fireEvent(BI.TextValueDownListCombo.EVENT_CHANGE); |
this.fireEvent(TextValueDownListCombo.EVENT_CHANGE); |
||||||
} |
} |
||||||
}); |
}); |
||||||
|
|
||||||
this.combo.on(BI.DownListCombo.EVENT_SON_VALUE_CHANGE, function () { |
this.combo.on(DownListCombo.EVENT_SON_VALUE_CHANGE, () => { |
||||||
var currentVal = self.combo.getValue()[0].childValue; |
const currentVal = this.combo.getValue()[0].childValue; |
||||||
if (currentVal !== self.value) { |
if (currentVal !== this.value) { |
||||||
self.setValue(currentVal); |
this.setValue(currentVal); |
||||||
self.fireEvent(BI.TextValueDownListCombo.EVENT_CHANGE); |
this.fireEvent(TextValueDownListCombo.EVENT_CHANGE); |
||||||
} |
} |
||||||
}); |
}); |
||||||
}, |
} |
||||||
|
|
||||||
_createValueMap: function () { |
_createValueMap() { |
||||||
var self = this; |
|
||||||
this.valueMap = {}; |
this.valueMap = {}; |
||||||
BI.each(BI.flatten(this.options.items), function (idx, item) { |
each(flatten(this.options.items), (idx, item) => { |
||||||
if (BI.has(item, "el")) { |
if (has(item, "el")) { |
||||||
BI.each(item.children, function (id, it) { |
each(item.children, (id, it) => { |
||||||
self.valueMap[it.value] = {value: item.el.value, childValue: it.value}; |
this.valueMap[it.value] = { value: item.el.value, childValue: it.value }; |
||||||
}); |
}); |
||||||
} else { |
} else { |
||||||
self.valueMap[item.value] = {value: item.value}; |
this.valueMap[item.value] = { value: item.value }; |
||||||
} |
} |
||||||
}); |
}); |
||||||
}, |
} |
||||||
|
|
||||||
_digest: function (v) { |
_digest(v) { |
||||||
this.value = v; |
this.value = v; |
||||||
|
|
||||||
return this.valueMap[v]; |
return this.valueMap[v]; |
||||||
}, |
} |
||||||
|
|
||||||
setValue: function (v) { |
setValue(v) { |
||||||
v = this._digest(v); |
v = this._digest(v); |
||||||
this.combo.setValue([v]); |
this.combo.setValue([v]); |
||||||
this.trigger?.setValue(v); |
this.trigger?.setValue(v); |
||||||
}, |
} |
||||||
|
|
||||||
getValue: function () { |
getValue() { |
||||||
var v = this.combo.getValue()[0]; |
const v = this.combo.getValue()[0]; |
||||||
|
|
||||||
return [v.childValue || v.value]; |
return [v.childValue || v.value]; |
||||||
}, |
} |
||||||
|
|
||||||
populate: function (items) { |
populate(items) { |
||||||
this.options.items = BI.flatten(items); |
this.options.items = flatten(items); |
||||||
this.combo.populate(items); |
this.combo.populate(items); |
||||||
this._createValueMap(); |
this._createValueMap(); |
||||||
} |
} |
||||||
}); |
} |
||||||
BI.TextValueDownListCombo.EVENT_CHANGE = "EVENT_CHANGE"; |
|
||||||
BI.shortcut("bi.text_value_down_list_combo", BI.TextValueDownListCombo); |
|
||||||
|
@ -0,0 +1,2 @@ |
|||||||
|
export { TextValueDownListCombo } from "./combo.textvaluedownlist"; |
||||||
|
export { DownListSelectTextTrigger } from "./trigger.textvaluedownlist"; |
@ -1,55 +1,54 @@ |
|||||||
/** |
import { shortcut, extend, createWidget, isNull, flatten, deepClone, each, has, concat } from "@/core"; |
||||||
* 选择字段trigger, downlist专用 |
import { Trigger } from "@/base"; |
||||||
* 显示形式为 父亲值(儿子值) |
import { SelectTextTrigger } from "@/case"; |
||||||
* |
|
||||||
* @class BI.DownListSelectTextTrigger |
|
||||||
* @extends BI.Trigger |
|
||||||
*/ |
|
||||||
BI.DownListSelectTextTrigger = BI.inherit(BI.Trigger, { |
|
||||||
|
|
||||||
_defaultConfig: function () { |
@shortcut() |
||||||
return BI.extend(BI.DownListSelectTextTrigger.superclass._defaultConfig.apply(this, arguments), { |
export class DownListSelectTextTrigger extends Trigger { |
||||||
|
static xtype = "bi.down_list_select_text_trigger"; |
||||||
|
|
||||||
|
_defaultConfig() { |
||||||
|
return extend(super._defaultConfig(...arguments), { |
||||||
baseCls: "bi-down-list-select-text-trigger", |
baseCls: "bi-down-list-select-text-trigger", |
||||||
height: 24, |
height: 24, |
||||||
text: "" |
text: "", |
||||||
}); |
}); |
||||||
}, |
} |
||||||
|
|
||||||
_init: function () { |
_init() { |
||||||
BI.DownListSelectTextTrigger.superclass._init.apply(this, arguments); |
super._init(...arguments); |
||||||
var o = this.options; |
const o = this.options; |
||||||
this.trigger = BI.createWidget({ |
this.trigger = createWidget({ |
||||||
type: "bi.select_text_trigger", |
type: SelectTextTrigger.xtype, |
||||||
element: this, |
element: this, |
||||||
height: o.height, |
height: o.height, |
||||||
items: this._formatItemArray(o.items), |
items: this._formatItemArray(o.items), |
||||||
text: o.text, |
text: o.text, |
||||||
value: BI.isNull(o.value) ? "" : o.value.childValue || o.value.value |
value: isNull(o.value) ? "" : o.value.childValue || o.value.value, |
||||||
}); |
}); |
||||||
}, |
} |
||||||
|
|
||||||
_formatItemArray: function () { |
_formatItemArray() { |
||||||
var sourceArray = BI.flatten(BI.deepClone(this.options.items)); |
const sourceArray = flatten(deepClone(this.options.items)); |
||||||
var targetArray = []; |
let targetArray = []; |
||||||
BI.each(sourceArray, function (idx, item) { |
each(sourceArray, (idx, item) => { |
||||||
if(BI.has(item, "el")) { |
if (has(item, "el")) { |
||||||
BI.each(item.children, function (id, it) { |
each(item.children, (id, it) => { |
||||||
it.text = item.el.text + "(" + it.text + ")"; |
it.text = `${item.el.text}(${it.text})`; |
||||||
}); |
}); |
||||||
targetArray = BI.concat(targetArray, item.children); |
targetArray = concat(targetArray, item.children); |
||||||
}else{ |
} else { |
||||||
targetArray.push(item); |
targetArray.push(item); |
||||||
} |
} |
||||||
}); |
}); |
||||||
|
|
||||||
return targetArray; |
return targetArray; |
||||||
}, |
} |
||||||
|
|
||||||
setValue: function (vals) { |
setValue(vals) { |
||||||
this.trigger.setValue(vals.childValue || vals.value); |
this.trigger.setValue(vals.childValue || vals.value); |
||||||
}, |
} |
||||||
|
|
||||||
populate: function (items) { |
populate(items) { |
||||||
this.trigger.populate(this._formatItemArray(items)); |
this.trigger.populate(this._formatItemArray(items)); |
||||||
} |
} |
||||||
}); |
} |
||||||
BI.shortcut("bi.down_list_select_text_trigger", BI.DownListSelectTextTrigger); |
|
||||||
|
Loading…
Reference in new issue