impact
2 years ago
14 changed files with 263 additions and 240 deletions
@ -1,99 +1,116 @@
|
||||
/** |
||||
* @class BI.TextValueDownListCombo |
||||
* @extend BI.Widget |
||||
*/ |
||||
BI.TextValueDownListCombo = BI.inherit(BI.Widget, { |
||||
_defaultConfig: function (config) { |
||||
return BI.extend(BI.TextValueDownListCombo.superclass._defaultConfig.apply(this, arguments), { |
||||
baseCls: "bi-text-value-down-list-combo bi-border-radius " + (config.simple ? "bi-border-bottom" : "bi-border"), |
||||
import { |
||||
shortcut, |
||||
Widget, |
||||
extend, |
||||
isNotNull, |
||||
createWidget, |
||||
Selection, |
||||
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, |
||||
}); |
||||
}, |
||||
} |
||||
|
||||
_init: function () { |
||||
var self = this, o = this.options; |
||||
BI.TextValueDownListCombo.superclass._init.apply(this, arguments); |
||||
_init() { |
||||
const o = this.options; |
||||
super._init(...arguments); |
||||
this._createValueMap(); |
||||
|
||||
var value; |
||||
if(BI.isNotNull(o.value)) { |
||||
let value; |
||||
if (isNotNull(o.value)) { |
||||
value = this._digest(o.value); |
||||
} |
||||
|
||||
this.combo = BI.createWidget({ |
||||
type: "bi.down_list_combo", |
||||
this.combo = createWidget({ |
||||
type: DownListCombo.xtype, |
||||
element: this, |
||||
chooseType: BI.Selection.Single, |
||||
chooseType: Selection.Single, |
||||
adjustLength: 2, |
||||
width: BI.toPix(o.width, 2), |
||||
height: BI.toPix(o.height, 2), |
||||
width: toPix(o.width, 2), |
||||
height: toPix(o.height, 2), |
||||
el: { |
||||
type: "bi.down_list_select_text_trigger", |
||||
ref: function (_ref) { |
||||
self.trigger = _ref; |
||||
ref: _ref => { |
||||
this.trigger = _ref; |
||||
}, |
||||
cls: "text-value-down-list-trigger", |
||||
height: BI.toPix(o.height, 2), |
||||
height: toPix(o.height, 2), |
||||
items: o.items, |
||||
text: o.text, |
||||
value: value |
||||
value, |
||||
}, |
||||
value: BI.isNull(value) ? [] : [value], |
||||
items: BI.deepClone(o.items) |
||||
value: isNull(value) ? [] : [value], |
||||
items: deepClone(o.items), |
||||
}); |
||||
|
||||
this.combo.on(BI.DownListCombo.EVENT_CHANGE, function () { |
||||
var currentVal = self.combo.getValue()[0].value; |
||||
if (currentVal !== self.value) { |
||||
self.setValue(currentVal); |
||||
self.fireEvent(BI.TextValueDownListCombo.EVENT_CHANGE); |
||||
this.combo.on(DownListCombo.EVENT_CHANGE, () => { |
||||
const currentVal = this.combo.getValue()[0].value; |
||||
if (currentVal !== this.value) { |
||||
this.setValue(currentVal); |
||||
this.fireEvent(TextValueDownListCombo.EVENT_CHANGE); |
||||
} |
||||
}); |
||||
|
||||
this.combo.on(BI.DownListCombo.EVENT_SON_VALUE_CHANGE, function () { |
||||
var currentVal = self.combo.getValue()[0].childValue; |
||||
if (currentVal !== self.value) { |
||||
self.setValue(currentVal); |
||||
self.fireEvent(BI.TextValueDownListCombo.EVENT_CHANGE); |
||||
this.combo.on(DownListCombo.EVENT_SON_VALUE_CHANGE, () => { |
||||
const currentVal = this.combo.getValue()[0].childValue; |
||||
if (currentVal !== this.value) { |
||||
this.setValue(currentVal); |
||||
this.fireEvent(TextValueDownListCombo.EVENT_CHANGE); |
||||
} |
||||
}); |
||||
}, |
||||
} |
||||
|
||||
_createValueMap: function () { |
||||
var self = this; |
||||
_createValueMap() { |
||||
this.valueMap = {}; |
||||
BI.each(BI.flatten(this.options.items), function (idx, item) { |
||||
if (BI.has(item, "el")) { |
||||
BI.each(item.children, function (id, it) { |
||||
self.valueMap[it.value] = {value: item.el.value, childValue: it.value}; |
||||
each(flatten(this.options.items), (idx, item) => { |
||||
if (has(item, "el")) { |
||||
each(item.children, (id, it) => { |
||||
this.valueMap[it.value] = { value: item.el.value, childValue: it.value }; |
||||
}); |
||||
} else { |
||||
self.valueMap[item.value] = {value: item.value}; |
||||
this.valueMap[item.value] = { value: item.value }; |
||||
} |
||||
}); |
||||
}, |
||||
} |
||||
|
||||
_digest: function (v) { |
||||
_digest(v) { |
||||
this.value = v; |
||||
|
||||
return this.valueMap[v]; |
||||
}, |
||||
} |
||||
|
||||
setValue: function (v) { |
||||
setValue(v) { |
||||
v = this._digest(v); |
||||
this.combo.setValue([v]); |
||||
this.trigger?.setValue(v); |
||||
}, |
||||
} |
||||
|
||||
getValue: function () { |
||||
var v = this.combo.getValue()[0]; |
||||
getValue() { |
||||
const v = this.combo.getValue()[0]; |
||||
|
||||
return [v.childValue || v.value]; |
||||
}, |
||||
} |
||||
|
||||
populate: function (items) { |
||||
this.options.items = BI.flatten(items); |
||||
populate(items) { |
||||
this.options.items = flatten(items); |
||||
this.combo.populate(items); |
||||
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 @@
|
||||
/** |
||||
* 选择字段trigger, downlist专用 |
||||
* 显示形式为 父亲值(儿子值) |
||||
* |
||||
* @class BI.DownListSelectTextTrigger |
||||
* @extends BI.Trigger |
||||
*/ |
||||
BI.DownListSelectTextTrigger = BI.inherit(BI.Trigger, { |
||||
import { shortcut, extend, createWidget, isNull, flatten, deepClone, each, has, concat } from "@/core"; |
||||
import { Trigger } from "@/base"; |
||||
import { SelectTextTrigger } from "@/case"; |
||||
|
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.DownListSelectTextTrigger.superclass._defaultConfig.apply(this, arguments), { |
||||
@shortcut() |
||||
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", |
||||
height: 24, |
||||
text: "" |
||||
text: "", |
||||
}); |
||||
}, |
||||
} |
||||
|
||||
_init: function () { |
||||
BI.DownListSelectTextTrigger.superclass._init.apply(this, arguments); |
||||
var o = this.options; |
||||
this.trigger = BI.createWidget({ |
||||
type: "bi.select_text_trigger", |
||||
_init() { |
||||
super._init(...arguments); |
||||
const o = this.options; |
||||
this.trigger = createWidget({ |
||||
type: SelectTextTrigger.xtype, |
||||
element: this, |
||||
height: o.height, |
||||
items: this._formatItemArray(o.items), |
||||
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 () { |
||||
var sourceArray = BI.flatten(BI.deepClone(this.options.items)); |
||||
var targetArray = []; |
||||
BI.each(sourceArray, function (idx, item) { |
||||
if(BI.has(item, "el")) { |
||||
BI.each(item.children, function (id, it) { |
||||
it.text = item.el.text + "(" + it.text + ")"; |
||||
_formatItemArray() { |
||||
const sourceArray = flatten(deepClone(this.options.items)); |
||||
let targetArray = []; |
||||
each(sourceArray, (idx, item) => { |
||||
if (has(item, "el")) { |
||||
each(item.children, (id, it) => { |
||||
it.text = `${item.el.text}(${it.text})`; |
||||
}); |
||||
targetArray = BI.concat(targetArray, item.children); |
||||
}else{ |
||||
targetArray = concat(targetArray, item.children); |
||||
} else { |
||||
targetArray.push(item); |
||||
} |
||||
}); |
||||
|
||||
return targetArray; |
||||
}, |
||||
} |
||||
|
||||
setValue: function (vals) { |
||||
setValue(vals) { |
||||
this.trigger.setValue(vals.childValue || vals.value); |
||||
}, |
||||
} |
||||
|
||||
populate: function (items) { |
||||
populate(items) { |
||||
this.trigger.populate(this._formatItemArray(items)); |
||||
} |
||||
}); |
||||
BI.shortcut("bi.down_list_select_text_trigger", BI.DownListSelectTextTrigger); |
||||
} |
||||
|
Loading…
Reference in new issue