Browse Source

Pull request #2718: KERNEL-11286 refactor: 下拉框value,text,defaultText属性规则统一

Merge in VISUAL/fineui from ~DAILER/fineui:master to master

* commit '5e51a257066c54b5d6313b6158ab6e7fbd85ba47':
  KERNEL-11286 refactor: 下拉框value,text,defaultText属性规则统一
es6
Dailer 3 years ago
parent
commit
ebbe1d2f78
  1. 7
      src/case/combo/searchtextvaluecombo/combo.searchtextvalue.js
  2. 31
      src/case/combo/searchtextvaluecombo/trigger.searchtextvalue.js
  3. 282
      src/case/editor/editor.defaulttext.js

7
src/case/combo/searchtextvaluecombo/combo.searchtextvalue.js

@ -56,7 +56,7 @@ BI.SearchTextValueCombo = BI.inherit(BI.Widget, {
listeners: [{ listeners: [{
eventName: BI.SearchTextValueTrigger.EVENT_CHANGE, eventName: BI.SearchTextValueTrigger.EVENT_CHANGE,
action: function () { action: function () {
self.setValue(this.getValue()); self.setValue(this.getValue()[0]);
self.combo.hideView(); self.combo.hideView();
self.fireEvent(BI.SearchTextValueCombo.EVENT_CHANGE); self.fireEvent(BI.SearchTextValueCombo.EVENT_CHANGE);
} }
@ -81,7 +81,7 @@ BI.SearchTextValueCombo = BI.inherit(BI.Widget, {
listeners: [{ listeners: [{
eventName: BI.TextValueComboPopup.EVENT_CHANGE, eventName: BI.TextValueComboPopup.EVENT_CHANGE,
action: function () { action: function () {
self.setValue(this.getValue()); self.setValue(this.getValue()[0]);
self.combo.hideView(); self.combo.hideView();
self.fireEvent(BI.SearchTextValueCombo.EVENT_CHANGE); self.fireEvent(BI.SearchTextValueCombo.EVENT_CHANGE);
} }
@ -113,8 +113,7 @@ BI.SearchTextValueCombo = BI.inherit(BI.Widget, {
}, },
_clear: function () { _clear: function () {
this.trigger.attr("text", ""); this.setValue();
this.setValue([]);
}, },
_checkError: function (v) { _checkError: function (v) {

31
src/case/combo/searchtextvaluecombo/trigger.searchtextvalue.js

@ -9,6 +9,7 @@ BI.SearchTextValueTrigger = BI.inherit(BI.Trigger, {
height: 24, height: 24,
watermark: BI.i18nText("BI-Basic_Search"), watermark: BI.i18nText("BI-Basic_Search"),
allowClear: false, allowClear: false,
title: () => this.editor.getText(),
}; };
}, },
@ -26,7 +27,7 @@ BI.SearchTextValueTrigger = BI.inherit(BI.Trigger, {
width: 24, width: 24,
}; };
var stateText = this._digest(o.value, o.items); var stateText = this._digest(o.value, o.items) || o.text;
return { return {
type: "bi.horizontal_fill", type: "bi.horizontal_fill",
@ -40,7 +41,7 @@ BI.SearchTextValueTrigger = BI.inherit(BI.Trigger, {
}, },
isAutoSearch: false, isAutoSearch: false,
el: { el: {
type: "bi.state_editor", type: "bi.default_text_editor",
ref: function () { ref: function () {
self.editor = this; self.editor = this;
}, },
@ -49,7 +50,6 @@ BI.SearchTextValueTrigger = BI.inherit(BI.Trigger, {
text: stateText, text: stateText,
value: o.value, value: o.value,
height: o.height, height: o.height,
tipText: ""
}, },
popup: { popup: {
type: "bi.search_text_value_combo_popup", type: "bi.search_text_value_combo_popup",
@ -106,22 +106,11 @@ BI.SearchTextValueTrigger = BI.inherit(BI.Trigger, {
this.editor.setState(v); this.editor.setState(v);
}, },
_digest: function (vals, items) { _digest: function (value, items) {
var o = this.options; var result = BI.find(items, function (i, item) {
vals = BI.isArray(vals) ? vals : [vals]; return item.value === value;
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)) {
result.push(item.text || item.value);
}
}); });
return result?.text;
if (result.length > 0) {
return result.join(",");
} else {
return BI.isFunction(o.text) ? o.text() : o.text;
}
}, },
stopEditing: function () { stopEditing: function () {
@ -137,9 +126,9 @@ BI.SearchTextValueTrigger = BI.inherit(BI.Trigger, {
}, },
setValue: function (vals) { setValue: function (vals) {
var stateText = this._digest(vals, this.options.items); var digestText = this._digest(vals, this.options.items);
this._setState(stateText); this._setState(digestText);
this.options.allowClear && this.clearBtn.setVisible(BI.isNotEmptyString(stateText)); this.options.allowClear && this.clearBtn.setVisible(BI.isNotEmptyString(digestText));
}, },
getValue: function () { getValue: function () {

282
src/case/editor/editor.defaulttext.js

@ -0,0 +1,282 @@
/**
* dailer
* 有默认提示文字的输入框
* @class BI.DefaultTextEditor
* @extends BI.Widget
*/
BI.DefaultTextEditor = BI.inherit(BI.Widget, {
props: function () {
return {
baseCls: "bi-default-text-editor",
hgap: 4,
vgap: 2,
lgap: 0,
rgap: 0,
tgap: 0,
bgap: 0,
validationChecker: BI.emptyFn,
quitChecker: BI.emptyFn,
allowBlank: true,
watermark: "",
errorText: "",
height: 24,
defaultText: "", // 默认显示值,默认显示值与显示值的区别是默认显示值标记灰色
text: "", // 显示值
el: {}
};
},
render: function () {
var self = this, o = this.options;
this.editor = BI.createWidget(o.el, {
type: "bi.editor",
simple: o.simple,
height: o.height,
hgap: o.hgap,
vgap: o.vgap,
lgap: o.lgap,
rgap: o.rgap,
tgap: o.tgap,
bgap: o.bgap,
value: o.value,
validationChecker: o.validationChecker,
quitChecker: o.quitChecker,
allowBlank: o.allowBlank,
watermark: o.watermark,
errorText: o.errorText,
invisible: true,
});
this.text = BI.createWidget({
type: "bi.text_button",
cls: BI.isKey(o.text) ? "tip-text-style" : "bi-water-mark tip-text-style",
textAlign: "left",
height: o.height,
text: BI.isKey(o.text) ? o.text : o.defaultText,
hgap: o.hgap + 2,
handler: function () {
self._showInput();
self.editor.focus();
self.editor.setValue("");
},
title: o.title,
warningTitle: o.warningTitle,
tipType: o.tipType
});
this.text.on(BI.TextButton.EVENT_CHANGE, function () {
BI.nextTick(function () {
self.fireEvent(BI.DefaultTextEditor.EVENT_CLICK_LABEL);
});
});
this.editor.on(BI.Controller.EVENT_CHANGE, function () {
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
});
this.editor.on(BI.Editor.EVENT_FOCUS, function () {
self.fireEvent(BI.DefaultTextEditor.EVENT_FOCUS, arguments);
});
this.editor.on(BI.Editor.EVENT_BLUR, function () {
self.fireEvent(BI.DefaultTextEditor.EVENT_BLUR, arguments);
});
this.editor.on(BI.Editor.EVENT_CLICK, function () {
self.fireEvent(BI.DefaultTextEditor.EVENT_CLICK, arguments);
});
this.editor.on(BI.Editor.EVENT_CHANGE, function () {
self.fireEvent(BI.DefaultTextEditor.EVENT_CHANGE, arguments);
});
this.editor.on(BI.Editor.EVENT_KEY_DOWN, function (v) {
self.fireEvent(BI.DefaultTextEditor.EVENT_KEY_DOWN, arguments);
});
this.editor.on(BI.Editor.EVENT_VALID, function () {
self.fireEvent(BI.DefaultTextEditor.EVENT_VALID, arguments);
});
this.editor.on(BI.Editor.EVENT_CONFIRM, function () {
self._showHint();
self.fireEvent(BI.DefaultTextEditor.EVENT_CONFIRM, arguments);
});
this.editor.on(BI.Editor.EVENT_CHANGE_CONFIRM, function () {
self._showHint();
self.fireEvent(BI.DefaultTextEditor.EVENT_CHANGE_CONFIRM, arguments);
});
this.editor.on(BI.Editor.EVENT_START, function () {
self.fireEvent(BI.DefaultTextEditor.EVENT_START, arguments);
});
this.editor.on(BI.Editor.EVENT_PAUSE, function () {
self.fireEvent(BI.DefaultTextEditor.EVENT_PAUSE, arguments);
});
this.editor.on(BI.Editor.EVENT_STOP, function () {
self.fireEvent(BI.DefaultTextEditor.EVENT_STOP, arguments);
});
this.editor.on(BI.Editor.EVENT_SPACE, function () {
self.fireEvent(BI.DefaultTextEditor.EVENT_SPACE, arguments);
});
this.editor.on(BI.Editor.EVENT_ERROR, function () {
self.fireEvent(BI.DefaultTextEditor.EVENT_ERROR, arguments);
});
this.editor.on(BI.Editor.EVENT_ENTER, function () {
self.fireEvent(BI.DefaultTextEditor.EVENT_ENTER, arguments);
});
this.editor.on(BI.Editor.EVENT_RESTRICT, function () {
self.fireEvent(BI.DefaultTextEditor.EVENT_RESTRICT, arguments);
});
this.editor.on(BI.Editor.EVENT_EMPTY, function () {
self.fireEvent(BI.DefaultTextEditor.EVENT_EMPTY, arguments);
});
return {
type: "bi.absolute",
items: [
{
el: this.editor,
left: 0,
right: 0,
top: 0,
bottom: 0
}, {
el: this.text,
left: 0,
right: 0,
top: 0,
bottom: 0
}
]
};
},
setWaterMark: function (v) {
this.options.watermark = v;
this.editor.setWaterMark(v);
},
setTitle: function (title) {
this.text.setTitle(title);
},
setWarningTitle: function (title) {
this.text.setWarningTitle(title);
},
doRedMark: function () {
if (this.editor.getValue() === "" && BI.isKey(this.options.watermark)) {
return;
}
this.text.doRedMark.apply(this.text, arguments);
},
unRedMark: function () {
this.text.unRedMark.apply(this.text, arguments);
},
doHighLight: function () {
if (this.editor.getValue() === "" && BI.isKey(this.options.watermark)) {
return;
}
this.text.doHighLight.apply(this.text, arguments);
},
unHighLight: function () {
this.text.unHighLight.apply(this.text, arguments);
},
focus: function () {
if (this.options.disabled === false) {
this._showInput();
this.editor.focus();
}
},
blur: function () {
this.editor.blur();
this._showHint();
},
_showInput: function () {
this.editor.visible();
this.text.invisible();
},
_showHint: function () {
this.editor.invisible();
this.text.visible();
},
_setText: function (v) {
this.text.setText(v);
this.text.setTitle(v);
},
isValid: function () {
return this.editor.isValid();
},
setErrorText: function (text) {
this.editor.setErrorText(text);
},
getErrorText: function () {
return this.editor.getErrorText();
},
isEditing: function () {
return this.editor.isEditing();
},
getLastValidValue: function () {
return this.editor.getLastValidValue();
},
getLastChangedValue: function () {
return this.editor.getLastChangedValue();
},
setValue: function (k) {
this.editor.setValue(k);
},
getValue: function () {
return this.editor.getValue();
},
getState: function () {
return this.text.getValue();
},
setState: function (v) {
var o = this.options;
if (BI.isKey(v)) {
this.text.setText(v);
this.text.element.removeClass("bi-water-mark");
return;
}
this.text.setText(o.defaultText);
this.text.element.addClass("bi-water-mark");
},
setTipType: function (v) {
this.text.options.tipType = v;
},
getText: function () {
return this.text.getText();
}
});
BI.DefaultTextEditor.EVENT_CHANGE = "EVENT_CHANGE";
BI.DefaultTextEditor.EVENT_FOCUS = "EVENT_FOCUS";
BI.DefaultTextEditor.EVENT_BLUR = "EVENT_BLUR";
BI.DefaultTextEditor.EVENT_CLICK = "EVENT_CLICK";
BI.DefaultTextEditor.EVENT_KEY_DOWN = "EVENT_KEY_DOWN";
BI.DefaultTextEditor.EVENT_CLICK_LABEL = "EVENT_CLICK_LABEL";
BI.DefaultTextEditor.EVENT_START = "EVENT_START";
BI.DefaultTextEditor.EVENT_PAUSE = "EVENT_PAUSE";
BI.DefaultTextEditor.EVENT_STOP = "EVENT_STOP";
BI.DefaultTextEditor.EVENT_CONFIRM = "EVENT_CONFIRM";
BI.DefaultTextEditor.EVENT_CHANGE_CONFIRM = "EVENT_CHANGE_CONFIRM";
BI.DefaultTextEditor.EVENT_VALID = "EVENT_VALID";
BI.DefaultTextEditor.EVENT_ERROR = "EVENT_ERROR";
BI.DefaultTextEditor.EVENT_ENTER = "EVENT_ENTER";
BI.DefaultTextEditor.EVENT_RESTRICT = "EVENT_RESTRICT";
BI.DefaultTextEditor.EVENT_SPACE = "EVENT_SPACE";
BI.DefaultTextEditor.EVENT_EMPTY = "EVENT_EMPTY";
BI.shortcut("bi.default_text_editor", BI.DefaultTextEditor);
Loading…
Cancel
Save