Browse Source

Merge pull request #133655 in DEC/fineui from master to feature/x

* commit '8d46993c94a6f7597cfb2077eba44062c300e1eb':
  无JIRA 整理代码
  JSY-20326 fix: 【组件问题】带清除按钮的单选下拉框,清除后需要恢复到默认值
  JSY-20326 fix: 【组件问题】带清除按钮的单选下拉框,清除后需要恢复到默认值
es6
superman 2 years ago
parent
commit
82bb972cf1
  1. 168
      demo/js/case/combo/demo.text_value_combo.js
  2. 2
      demo/js/widget/singletree/demo.single_tree_combo.js
  3. 4
      src/case/button/treeitem/treeitem.js
  4. 7
      src/case/combo/textvaluecombo/combo.textvalue.js
  5. 1
      src/case/layer/pane.list.js
  6. 38
      src/case/trigger/trigger.text.js
  7. 24
      src/case/trigger/trigger.text.select.js
  8. 1
      src/widget/singletree/singletree.combo.js
  9. 1
      src/widget/singletree/singletree.trigger.js

168
demo/js/case/combo/demo.text_value_combo.js

@ -7,17 +7,8 @@ Demo.TextValueCombo = BI.inherit(BI.Widget, {
},
render: function () {
var combo, wrapper;
return {
type: "bi.button_group",
items: [{
type: "bi.text_value_combo",
ref: function () {
combo = this;
},
text: "默认值",
value: 22,
width: 300,
items: [{
var items = [{
text: "MVC-1",
iconCls: "date-font",
value: 1
@ -29,33 +20,144 @@ Demo.TextValueCombo = BI.inherit(BI.Widget, {
text: "MVC-3",
iconCls: "pull-right-font",
value: 3
}]
}, {
type: "bi.search_multi_text_value_combo",
items: Demo.CONSTANTS.ITEMS,
width: 200,
value: {
type: 1,
value: ["1", "2", "3"]
}];
// 创建下拉框各种场景用例
return {
type: "bi.vertical",
vgap: 20,
hgap: 20,
items: [
this.createCombo("无初始值,带提示文字", {
type: "bi.text_value_combo",
ref: function () {
combo = this;
},
defaultText: "请选择",
width: 300,
items: items,
listeners: [
{
eventName: BI.TextValueCombo.EVENT_CHANGE,
action: function () {
console.log(this.getValue());
}
}, {
type: "bi.button",
width: 90,
height: 25,
handler: function () {
wrapper.populate();
}
}, {
type: 'bi.label',
height: 1000
}],
]
}),
this.createCombo("自动根据value匹配text", {
type: "bi.text_value_combo",
ref: function () {
combo = this;
},
defaultText: "请选择",
width: 300,
value: 1,
items: items,
listeners: [
{
eventName: BI.TextValueCombo.EVENT_CHANGE,
action: function () {
console.log(this.getValue());
}
}
]
}),
this.createCombo("无初始值,可以清空", {
type: "bi.text_value_combo",
ref: function () {
combo = this;
},
defaultText: "请选择",
width: 300,
items: items,
allowClear: true,
listeners: [
{
eventName: BI.TextValueCombo.EVENT_CHANGE,
action: function () {
console.log(this.getValue());
}
}
]
}),
this.createCombo("有初始值,可以清空", {
type: "bi.text_value_combo",
ref: function () {
wrapper = this;
combo = this;
},
layouts: [{
defaultText: "请选择",
width: 300,
value: 1,
items: items,
allowClear: true,
listeners: [
{
eventName: BI.TextValueCombo.EVENT_CHANGE,
action: function () {
console.log(this.getValue());
}
}
]
}),
this.createCombo("有初始值,value不匹配,自动标红,可以清空", {
type: "bi.text_value_combo",
ref: function () {
combo = this;
},
defaultText: "请选择",
width: 300,
value: 111,
items: items,
allowClear: true,
listeners: [
{
eventName: BI.TextValueCombo.EVENT_CHANGE,
action: function () {
console.log(this.getValue());
}
}
]
}),
this.createCombo("有初始值,value不匹配,自动标红,指定标红文字", {
type: "bi.text_value_combo",
ref: function () {
combo = this;
},
width: 300,
text: "MVC-111",
value: 111,
items: items,
allowClear: true,
defaultText: "df",
listeners: [
{
eventName: BI.TextValueCombo.EVENT_CHANGE,
action: function () {
console.log(this.getValue());
}
}
]
})
]
};
},
createCombo: function (text, combo) {
return {
type: "bi.vertical",
vgap: 20
}]
items: [
{
el: {
type: "bi.label",
textAlign: "left",
text,
},
bgap: 10
}, {
el: combo
}
]
};
}
});

2
demo/js/widget/singletree/demo.single_tree_combo.js

@ -16,7 +16,7 @@ Demo.SingleTreeCombo = BI.inherit(BI.Widget, {
ref: function (_ref) {
self.tree = _ref;
},
text: "默认值",
defaultText: "请选择",
items: items,
width: 300,
value: "11"

4
src/case/button/treeitem/treeitem.js

@ -9,9 +9,6 @@ BI.BasicTreeItem = BI.inherit(BI.NodeButton, {
readonly: true,
isFirstNode: false,
isLastNode: false,
switcherIcon: {},
selectable: true,
disabled: false, // disabled不会影响展开收起功能
});
},
@ -25,7 +22,6 @@ BI.BasicTreeItem = BI.inherit(BI.NodeButton, {
{
el: {
type: "bi.layout",
width: 24,
height: o.height,
width: o.height,
cls: this.getLineCls(),

7
src/case/combo/textvaluecombo/combo.textvalue.js

@ -12,6 +12,7 @@ BI.TextValueCombo = BI.inherit(BI.Widget, {
chooseType: BI.ButtonGroup.CHOOSE_TYPE_SINGLE,
text: "",
value: "",
defaultText: "",
allowClear: false,
});
},
@ -36,6 +37,7 @@ BI.TextValueCombo = BI.inherit(BI.Widget, {
value: o.value,
warningTitle: o.warningTitle,
allowClear: o.allowClear,
defaultText: o.defaultText,
listeners: [
{
eventName: BI.SelectTextTrigger.EVENT_CLEAR,
@ -79,7 +81,10 @@ BI.TextValueCombo = BI.inherit(BI.Widget, {
},
_clear: function () {
this.setValue();
this.trigger.setValue();
this.popup.setValue();
this.element.removeClass("error");
this.trigger.element.removeClass("error");
},
_checkError: function (v) {

1
src/case/layer/pane.list.js

@ -38,6 +38,7 @@ BI.ListPane = BI.inherit(BI.Pane, {
chooseType: BI.ButtonGroup.CHOOSE_TYPE_SINGLE,
behaviors: {},
items: o.items,
value: o.value,
itemsCreator: function (op, calback) {
if (op.times === 1) {
self.empty();

38
src/case/trigger/trigger.text.js

@ -17,21 +17,28 @@ BI.TextTrigger = BI.inherit(BI.Trigger, {
allowClear: false,
title: function () {
return self.text.getText();
}
},
defaultText: "",
text: "",
};
},
render: function () {
var self = this, o = this.options, c = this._const;
var text = {
var text = this.getText();
var defaultText = this.getDefaultText();
var label = {
type: "bi.label",
ref: function (_ref) {
self.text = _ref;
},
cls: "select-text-label" + (BI.isKey(o.textCls) ? (" " + o.textCls) : ""),
cls: `select-text-label ${o.textCls} ${!BI.isNotEmptyString(text) && BI.isNotEmptyString(defaultText) ? "bi-tips" : ""}`,
textAlign: "left",
height: o.height,
text: o.text,
text: text || o.defaultText,
tipType: o.tipType,
warningTitle: o.warningTitle,
hgap: o.textHgap,
@ -56,7 +63,7 @@ BI.TextTrigger = BI.inherit(BI.Trigger, {
columnSize: ["fill", o.triggerWidth || o.height],
items: [
{
el: text,
el: label,
width: "fill"
}, {
el: o.allowClear ? {
@ -89,6 +96,16 @@ BI.TextTrigger = BI.inherit(BI.Trigger, {
});
},
getText: function () {
var o = this.options;
return BI.isFunction(o.text) ? o.text() : o.text;
},
getDefaultText: function () {
var o = this.options;
return BI.isFunction(o.defaultText) ? o.defaultText() : o.defaultText;
},
getTextor: function () {
return this.text;
},
@ -101,10 +118,19 @@ BI.TextTrigger = BI.inherit(BI.Trigger, {
},
setText: function (text) {
this.text.setText(text);
if (this.options.allowClear) {
this.clearBtn.setVisible(BI.isNotEmptyString(text));
}
if (BI.isKey(text)) {
this.text.setText(text);
this.text.element.removeClass("bi-tips");
} else if (BI.isKey(this.options.defaultText)) {
this.text.setText(this.options.defaultText);
this.text.element.addClass("bi-tips");
} else {
this.text.setText("");
this.text.element.removeClass("bi-tips");
}
},
setTipType: function (v) {

24
src/case/trigger/trigger.text.select.js

@ -13,6 +13,7 @@ BI.SelectTextTrigger = BI.inherit(BI.Trigger, {
height: 24,
allowClear: false,
valueFormatter: BI.emptyFn,
defaultText: "",
});
},
@ -26,6 +27,7 @@ BI.SelectTextTrigger = BI.inherit(BI.Trigger, {
height: o.height,
readonly: o.readonly,
text: obj.text,
defaultText: o.defaultText,
textCls: obj.textCls,
textHgap: o.textHgap,
textVgap: o.textVgap,
@ -48,13 +50,13 @@ BI.SelectTextTrigger = BI.inherit(BI.Trigger, {
});
},
_digest: function (vals, items) {
_digest: function (val, items) {
var o = this.options;
vals = BI.isArray(vals) ? vals : [vals];
val = BI.isArray(val) ? val[0] : val;
var result = [];
var formatItems = BI.Tree.transformToArrayFormat(items);
BI.each(formatItems, function (i, item) {
if (BI.deepContains(vals, item.value) && !BI.contains(result, item.text || item.value)) {
if (val === item.value && !BI.contains(result, item.text || item.value)) {
result.push(item.text || item.value);
}
});
@ -62,12 +64,18 @@ BI.SelectTextTrigger = BI.inherit(BI.Trigger, {
if (result.length > 0) {
return {
textCls: "",
text: o.valueFormatter(vals[0]) || result.join(","), // 只保留单个value的场景,后续会把BI.isArray(vals) ? vals : [vals];这种都去掉
text: o.valueFormatter(val) || result.join(","),
};
} else {
var text = BI.isFunction(o.text) ? o.text() : o.text;
if (BI.isEmptyString(text)) {
return {
textCls: "bi-water-mark",
text: BI.isFunction(o.text) ? o.text() : o.text
textCls: "bi-tips",
text: ""
};
}
return {
text: o.text
};
}
},
@ -77,8 +85,8 @@ BI.SelectTextTrigger = BI.inherit(BI.Trigger, {
this.trigger.setText(text);
},
setValue: function (vals) {
var formatValue = this._digest(vals, this.options.items);
setValue: function (val) {
var formatValue = this._digest(val, this.options.items);
this.trigger.setTextCls(formatValue.textCls);
this.trigger.setText(formatValue.text);
},

1
src/widget/singletree/singletree.combo.js

@ -25,6 +25,7 @@ BI.SingleTreeCombo = BI.inherit(BI.Widget, {
this.trigger = BI.createWidget(BI.extend({
type: "bi.single_tree_trigger",
text: o.text,
defaultText: o.defaultText,
height: o.height,
items: o.items,
value: o.value,

1
src/widget/singletree/singletree.trigger.js

@ -26,6 +26,7 @@ BI.SingleTreeTrigger = BI.inherit(BI.Trigger, {
type: "bi.select_text_trigger",
element: this,
text: o.text,
defaultText: o.defaultText,
items: o.items,
height: o.height,
warningTitle: o.warningTitle,

Loading…
Cancel
Save