Browse Source

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

* commit 'ebbe1d2f789236ebee93e0041ab6dbf83162f9f0':
  KERNEL-11286 refactor: 下拉框value,text,defaultText属性规则统一
es6
superman 3 years ago
parent
commit
6053eb7e6c
  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: [{
eventName: BI.SearchTextValueTrigger.EVENT_CHANGE,
action: function () {
self.setValue(this.getValue());
self.setValue(this.getValue()[0]);
self.combo.hideView();
self.fireEvent(BI.SearchTextValueCombo.EVENT_CHANGE);
}
@ -81,7 +81,7 @@ BI.SearchTextValueCombo = BI.inherit(BI.Widget, {
listeners: [{
eventName: BI.TextValueComboPopup.EVENT_CHANGE,
action: function () {
self.setValue(this.getValue());
self.setValue(this.getValue()[0]);
self.combo.hideView();
self.fireEvent(BI.SearchTextValueCombo.EVENT_CHANGE);
}
@ -113,8 +113,7 @@ BI.SearchTextValueCombo = BI.inherit(BI.Widget, {
},
_clear: function () {
this.trigger.attr("text", "");
this.setValue([]);
this.setValue();
},
_checkError: function (v) {

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

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