forked from Teller/fineui-start
linyang3
3 years ago
11 changed files with 1096 additions and 155 deletions
@ -0,0 +1,3 @@
|
||||
.bi-multilayer-single-tree-combo.bi-combo.combo-error { |
||||
border-color: red; |
||||
} |
@ -0,0 +1,3 @@
|
||||
.dec-amiba-components-tree-single-chooser-combo.combo-error { |
||||
border-color: red; |
||||
} |
@ -0,0 +1,142 @@
|
||||
!(function () { |
||||
|
||||
var originData = { |
||||
label: [ |
||||
// "a7ed634a-0b59-4392-b92d-93a408803287"
|
||||
], |
||||
labels: [ |
||||
{ |
||||
dimension: { |
||||
id: "4ac8a4f8-5798-4c18-9cdf-9b1b9e7f9372", |
||||
name: "部门", |
||||
status: 1, |
||||
description: null, |
||||
createTime: "2022-03-29 15:44:36.114" |
||||
}, |
||||
labels: [ |
||||
{ |
||||
id: "85253c00-268c-4c77-a87d-6c532853ff1d", |
||||
name: "研发", |
||||
description: null, |
||||
dimensionId: "4ac8a4f8-5798-4c18-9cdf-9b1b9e7f9372", |
||||
createTime: "2022-03-29 15:45:18.348" |
||||
}, |
||||
{ |
||||
id: "f18d4479-9220-43f5-a696-b408b59c75c0", |
||||
name: "行政", |
||||
description: null, |
||||
dimensionId: "4ac8a4f8-5798-4c18-9cdf-9b1b9e7f9372", |
||||
createTime: "2022-03-29 15:45:07.412" |
||||
}, |
||||
{ |
||||
id: "a7ed634a-0b59-4392-b92d-93a408803287", |
||||
name: "财务", |
||||
description: null, |
||||
dimensionId: "4ac8a4f8-5798-4c18-9cdf-9b1b9e7f9372", |
||||
createTime: "2022-03-29 15:45:12.398" |
||||
} |
||||
] |
||||
} |
||||
] |
||||
}; |
||||
|
||||
|
||||
var TestTreeSingleChooserModel = BI.inherit(Fix.Model, { |
||||
|
||||
state: function () { |
||||
// 所有标签
|
||||
var rawDimension = [], defaultDimension = {}; |
||||
BI.each(originData.labels, function (i, item) { |
||||
var temp = { |
||||
text: item.dimension.name, |
||||
value: item.dimension.id, |
||||
children: BI.isNotEmptyArray(item.labels) ? BI.sortBy(BI.map(item.labels, function (i, label) { |
||||
return { |
||||
text: label.name, |
||||
value: label.id |
||||
}; |
||||
}), [function (item) { |
||||
return BI.makeFirstPY(item["name"]); |
||||
}]) : [] |
||||
}; |
||||
rawDimension.push(temp); |
||||
}); |
||||
rawDimension = BI.sortBy(rawDimension, [function (item) { |
||||
return BI.makeFirstPY(item["text"]); |
||||
}]); |
||||
!BI.isEmpty(defaultDimension) && rawDimension.unshift(defaultDimension); |
||||
|
||||
console.log("state --> labels", rawDimension); |
||||
console.log("state --> label", originData.label); |
||||
|
||||
return { |
||||
labels: rawDimension, |
||||
label: originData.label |
||||
|
||||
}; |
||||
} |
||||
}); |
||||
BI.model("dec.amiba.test.tree.single.chooser.model", TestTreeSingleChooserModel); |
||||
|
||||
|
||||
var TestTreeSingleChooser = BI.inherit(BI.Widget, { |
||||
_store: function () { |
||||
return BI.Models.getModel("dec.amiba.test.tree.single.chooser.model"); |
||||
}, |
||||
|
||||
watch: { |
||||
labels: function (v) { |
||||
console.log("labels", v); |
||||
}, |
||||
label: function (v) { |
||||
console.log("label", v); |
||||
} |
||||
}, |
||||
mounted: function () { |
||||
var _this = this; |
||||
setTimeout(function () { |
||||
console.log("_this.dataLabelRef", _this.dataLabelRef); |
||||
_this.dataLabelRef.setValue(["a7ed634a-0b59-4392-b92d-93a408803287"]); |
||||
}, 3000); |
||||
}, |
||||
render: function () { |
||||
var _this = this, o = this.options, m = this.model; |
||||
console.log("_this.label", _this); |
||||
return { |
||||
type: "bi.vertical", |
||||
height: 150, |
||||
lgap: 20, |
||||
tgap: 20, |
||||
mounted: function () {}, |
||||
items: [ |
||||
{ |
||||
type: "bi.label", |
||||
textAlign: "left", |
||||
text: "层级单选下拉框" |
||||
}, |
||||
{ |
||||
type: "dec.amiba.components.tree.single.chooser.combo", |
||||
watermark: "请选择", |
||||
text: "无效值", |
||||
width: 300, |
||||
height: 32, |
||||
value: m.label, |
||||
items: m.labels, |
||||
ref: function (ref) { |
||||
_this.dataLabelRef = ref; |
||||
}, |
||||
listeners: [{ |
||||
eventName: "EVENT_CHANGE", |
||||
action: function (value) { |
||||
m.label = value; |
||||
} |
||||
}] |
||||
} |
||||
] |
||||
}; |
||||
} |
||||
}); |
||||
|
||||
BI.shortcut("dec.amiba.test.tree.single.chooser", TestTreeSingleChooser); |
||||
|
||||
})(); |
@ -0,0 +1,3 @@
|
||||
.dec-amiba-components-tree-single-chooser-combo&.combo-error{ |
||||
border-color: red; |
||||
} |
@ -0,0 +1,316 @@
|
||||
!(function () { |
||||
|
||||
/** |
||||
* 组件说明: |
||||
* - 只支持两级展开 |
||||
* - 第二级只允许单选 |
||||
* |
||||
* 可用方法: |
||||
* setValue([] or '') |
||||
* getValue() => [] |
||||
* populate() 刷新items |
||||
* |
||||
* 内部事件: |
||||
* EVENT_CHANGE,参数:value |
||||
*/ |
||||
|
||||
var SingleChooserPopup = BI.inherit(BI.Widget, { |
||||
props: function () { |
||||
return { |
||||
items: [], |
||||
value: [], |
||||
itemHeight: 32 |
||||
}; |
||||
}, |
||||
mounted: function () { |
||||
BI.each(this.refGroupList, function (index, refGroup) { |
||||
refGroup.ref.element.hide(); |
||||
}); |
||||
}, |
||||
render: function () { |
||||
var o = this.options; |
||||
var _this = this; |
||||
return { |
||||
type: "bi.button_group", |
||||
items: this._createItems(o.items), |
||||
layouts: [{ |
||||
type: "bi.vertical", |
||||
vgap: 5 |
||||
}], |
||||
ref: function (ref) { |
||||
_this.btnGroupRef = ref; |
||||
} |
||||
}; |
||||
}, |
||||
populate: function (items) { |
||||
this.btnGroupRef.populate(this._createItems(items)); |
||||
}, |
||||
getValue: function () { |
||||
var value = []; |
||||
BI.each(this.refGroupList, function (index, ref) { |
||||
BI.any(ref.selectRefs, function (index, selectRef) { |
||||
return (!BI.isNull(selectRef) && selectRef.isSelected()) ? (value.push(selectRef.getValue()), true) : false; |
||||
}); |
||||
}); |
||||
return value; |
||||
}, |
||||
setValue: function (value) { |
||||
value = BI.isArray(value) ? value : [value]; |
||||
BI.each(this.refGroupList, function (index, ref) { |
||||
BI.each(ref.selectRefs, function (index, selectRef) { |
||||
!BI.isNull(selectRef) && selectRef.setSelected(BI.contains(value, selectRef.getValue())); |
||||
}); |
||||
}); |
||||
}, |
||||
_createItems: function (items) { |
||||
var o = this.options; |
||||
var _this = this; |
||||
this.refGroupList = BI.map(items, function () { |
||||
return { |
||||
ref: null, |
||||
selectRefs: [] |
||||
}; |
||||
}); |
||||
if (BI.isNotEmptyArray(items)) { |
||||
return BI.map(items, function (index, item) { |
||||
var triggerRef = null; |
||||
return { |
||||
type: "bi.vertical", |
||||
items: [{ |
||||
type: "bi.basic_button", |
||||
render: function () { |
||||
return { |
||||
type: "bi.htape", |
||||
cls: "bi-list-item", |
||||
height: o.itemHeight, |
||||
items: [{ |
||||
width: 16, |
||||
lgap: 10, |
||||
el: { |
||||
type: "bi.icon_label", |
||||
baseCls: "fold-font", |
||||
height: o.itemHeight, |
||||
ref: function (ref) { |
||||
triggerRef = ref; |
||||
} |
||||
} |
||||
}, { |
||||
width: "fill", |
||||
lgap: 5, |
||||
el: { |
||||
type: "bi.label", |
||||
height: o.itemHeight, |
||||
text: item.text, |
||||
textAlign: "left" |
||||
} |
||||
}] |
||||
}; |
||||
}, |
||||
listeners: [{ |
||||
eventName: "BasicButton.EVENT_CHANGE", |
||||
action: function () { |
||||
triggerRef.element.toggleClass("unfold-font fold-font"); |
||||
_this.refGroupList[index].ref.element.toggle(); |
||||
} |
||||
}] |
||||
}, { |
||||
el: { |
||||
type: "bi.button_group", |
||||
chooseType: BI.Selection.Multi, |
||||
ref: function (ref) { |
||||
_this.refGroupList[index].ref = ref; |
||||
}, |
||||
items: BI.map(item.children, function (idx, child) { |
||||
return { |
||||
type: "bi.multi_select_item", |
||||
css: { |
||||
paddingLeft: "40px" |
||||
}, |
||||
cls: "bi-list-item-active", |
||||
ref: function (ref) { |
||||
_this.refGroupList[index].selectRefs[idx] = ref; |
||||
}, |
||||
height: o.itemHeight, |
||||
value: child.value, |
||||
text: child.text, |
||||
textLgap: 5, |
||||
listeners: [{ |
||||
eventName: "EVENT_CHANGE", |
||||
action: function () { |
||||
if (this.isSelected()) { |
||||
var self = this; |
||||
var ref = _this.refGroupList[index]; |
||||
BI.each(ref.selectRefs, function (index, selectRef) { |
||||
if (self !== selectRef && selectRef.isSelected()) { |
||||
selectRef.setSelected(false); |
||||
} |
||||
}); |
||||
} |
||||
_this.fireEvent("EVENT_CHANGE", _this.getValue()); |
||||
} |
||||
}], |
||||
logic: { |
||||
dynamic: true |
||||
} |
||||
}; |
||||
}), |
||||
layouts: [{ |
||||
type: "bi.vertical" |
||||
}] |
||||
} |
||||
}] |
||||
}; |
||||
}); |
||||
} |
||||
return [{ |
||||
type: "bi.label", |
||||
height: 25, |
||||
disabled: true, |
||||
text: BI.i18nText("Fine-Plugin_AMB_Component_No_Available_Select_Items") |
||||
}]; |
||||
|
||||
} |
||||
}); |
||||
BI.shortcut("dec.amiba.components.single.chooser.popup", SingleChooserPopup); |
||||
|
||||
/** |
||||
* value: |
||||
* [value, ...] |
||||
* |
||||
* items: |
||||
* [{ |
||||
* text: '', |
||||
* value: '', |
||||
* children: [{ |
||||
* text: '', |
||||
* value: '' |
||||
* }], |
||||
* ... |
||||
* }] |
||||
*/ |
||||
var SingleChooserCombo = BI.inherit(BI.Widget, { |
||||
props: { |
||||
itemHeight: 32, |
||||
text: null, // 显示值,在显示值为无效值的情况下表现为水印样式
|
||||
value: null, // 真实值,真实值为空的时候显示水印值
|
||||
watermark: null, // 提示水印
|
||||
baseCls: "dec-amiba-components-tree-single-chooser-combo" |
||||
}, |
||||
mounted: function () { |
||||
var o = this.options; |
||||
this.setValue(o.value, true); |
||||
}, |
||||
render: function () { |
||||
var o = this.options; |
||||
var _this = this; |
||||
return { |
||||
type: "bi.combo", |
||||
cls: "bi-border", |
||||
isDefaultInit: true, |
||||
adjustLength: 2, |
||||
el: { |
||||
type: "bi.text_trigger", |
||||
ref: function (ref) { |
||||
_this.triggerRef = ref; |
||||
}, |
||||
height: o.height, |
||||
readonly: o.readonly, |
||||
tipType: o.tipType, |
||||
warningTitle: o.warningTitle |
||||
}, |
||||
popup: { |
||||
maxHeight: 240, |
||||
minHeight: 25, |
||||
el: { |
||||
type: "bi.vertical", |
||||
items: [{ |
||||
type: "dec.amiba.components.single.chooser.popup", |
||||
ref: function (ref) { |
||||
_this.popupRef = ref; |
||||
}, |
||||
items: o.items, |
||||
value: o.value, |
||||
itemHeight: o.itemHeight, |
||||
listeners: [{ |
||||
eventName: "EVENT_CHANGE", |
||||
action: function (value) { |
||||
_this._adjustText(value, false); |
||||
_this.fireEvent("EVENT_CHANGE", value); |
||||
} |
||||
}] |
||||
}] |
||||
} |
||||
} |
||||
}; |
||||
}, |
||||
/** |
||||
* |
||||
* @param {array} value 选中值 |
||||
* @param {boolean}[optional] init 是否初始状态,mounted生命周期传true,其余传false或不传 |
||||
*/ |
||||
setValue: function (value, init) { |
||||
this._adjustText(value, init); |
||||
this.popupRef.setValue(value); |
||||
}, |
||||
getValue: function () { |
||||
return this.popupRef.getValue(); |
||||
}, |
||||
populate: function (items) { |
||||
this.popupRef.populate(items); |
||||
}, |
||||
_digest: function (value, init, items) { |
||||
var o = this.options; |
||||
var text = BI.isFunction(o.watermark) ? o.watermark() : o.watermark, textCls = "bi-water-mark"; |
||||
value = BI.isArray(value) ? value : [value]; |
||||
var result = []; |
||||
BI.each(items, function (i, item) { |
||||
BI.each(item.children, function (i, leafItem) { |
||||
if (BI.contains(value, leafItem.value)) { |
||||
result.push(leafItem.text); |
||||
} |
||||
}); |
||||
}); |
||||
var showError = false; |
||||
var valueText = result.length > 0 ? result.join(",") : BI.emptyStr; |
||||
if (init && BI.isNotEmptyString(o.text)) { |
||||
text = o.text; |
||||
if (BI.isEqual(text, valueText)) { |
||||
textCls = BI.emptyStr; |
||||
} else { |
||||
showError = true; |
||||
} |
||||
} else if (BI.isNotEmptyString(valueText)) { |
||||
text = valueText; |
||||
textCls = BI.emptyStr; |
||||
} |
||||
this._applyComboClass(showError); |
||||
return { |
||||
text: text, |
||||
textCls: textCls |
||||
}; |
||||
}, |
||||
/** |
||||
* 初始状态下,设置的显示值的优先级最高,根据真实值构造出来的文本值次之,水印文本最末 |
||||
* 非初始状态下,显示值不再有效 |
||||
* |
||||
* @param {*} value 真实值 |
||||
* @param {*} init 是否为初始状态 |
||||
*/ |
||||
_adjustText: function (value, init) { |
||||
var o = this.options; |
||||
var digestObj = this._digest(value, init, o.items); |
||||
this.triggerRef.setText(digestObj.text); |
||||
this.triggerRef.setTextCls(digestObj.textCls); |
||||
}, |
||||
// 切换下拉树控件样式
|
||||
_applyComboClass: function (showError) { |
||||
if (showError) { |
||||
this.element.addClass("combo-error"); |
||||
} else { |
||||
this.element.removeClass("combo-error"); |
||||
} |
||||
} |
||||
}); |
||||
BI.shortcut("dec.amiba.components.tree.single.chooser.combo", SingleChooserCombo); |
||||
|
||||
})(); |
Loading…
Reference in new issue