|
@@ -1,7 +1,15 @@
|
|
|
import _ from 'lodash'
|
|
|
import {comboGrid, comboGridPicker} from '../../Defaults'
|
|
|
-import {calcObjectFlat, clearViewModelByLookup, lookupScope, stopEvent, tryWriteByExpress, tryWriteObject} from "../..";
|
|
|
+import {
|
|
|
+ calcObjectFlat,
|
|
|
+ lookupScope,
|
|
|
+ tryEnable,
|
|
|
+ stopEvent,
|
|
|
+ tryVarSimple,
|
|
|
+ tryWriteObject
|
|
|
+} from "../..";
|
|
|
import {msg} from "../../message";
|
|
|
+import {isChartEvent} from '../../utils'
|
|
|
|
|
|
export default function () {
|
|
|
|
|
@@ -43,9 +51,17 @@ export default function () {
|
|
|
},
|
|
|
afterrender(sender) {
|
|
|
const $dom = $(sender.inputEl.dom)
|
|
|
+ that.scope = lookupScope(sender)
|
|
|
+
|
|
|
if (sender.column) {
|
|
|
// 列模式,拦截 keydown
|
|
|
$dom.on('keydown', (e) => {
|
|
|
+ if (isChartEvent(e) && !that.tryEnable()) {
|
|
|
+ // 没有达成 editEnable 条件,不用响应
|
|
|
+ stopEvent(e)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
if (e.key === 'Enter') {
|
|
|
stopEvent(e)
|
|
|
that.onTriggerClick(that, that.getPickerTrigger(), e);
|
|
@@ -56,6 +72,16 @@ export default function () {
|
|
|
} else {
|
|
|
// 常规模式,拦截 keyup
|
|
|
$dom.on('keyup', (e) => {
|
|
|
+ if (e.key === 'Escape' || e.key === 'ArrowRight' || e.key === 'ArrowLeft') {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isChartEvent(e) && !that.tryEnable()) {
|
|
|
+ // 没有达成 editEnable 条件,不用响应
|
|
|
+ stopEvent(e)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
if (e.key === 'Enter') {
|
|
|
stopEvent(e)
|
|
|
that.onTriggerClick(that, that.getPickerTrigger(), e);
|
|
@@ -64,15 +90,14 @@ export default function () {
|
|
|
// 取消 keyup 事件,让 ext 不要吧当前输入的值记录到 value 中
|
|
|
stopEvent(e)
|
|
|
})
|
|
|
+ $dom.on('change', e => {
|
|
|
+ if (that.isExpanded) {
|
|
|
+ that.filterChange(that, e.target.value)
|
|
|
+ }
|
|
|
+ stopEvent(e)
|
|
|
+ })
|
|
|
}
|
|
|
$dom.on('input', e => {
|
|
|
- // that.filterChange(that, e.target.value)
|
|
|
- stopEvent(e)
|
|
|
- })
|
|
|
- $dom.on('change', e => {
|
|
|
- if (that.isExpanded) {
|
|
|
- that.filterChange(that, e.target.value)
|
|
|
- }
|
|
|
stopEvent(e)
|
|
|
})
|
|
|
},
|
|
@@ -203,49 +228,47 @@ export default function () {
|
|
|
}
|
|
|
|
|
|
tryWriteObject(lookup, record, (path, value) => {
|
|
|
- if (path === 'queryValue') {
|
|
|
- me.setValue(value)
|
|
|
- } else {
|
|
|
- if (me.column) {
|
|
|
- // 列模式下,写当前编辑行
|
|
|
- const parentGrid = me.column.up('grid')
|
|
|
- const parentRecord = parentGrid.getSelectionModel().getLastSelected()
|
|
|
- // Ext.data.Record / Ext.data.Model
|
|
|
- parentRecord.set(path, value)
|
|
|
-
|
|
|
- } else {
|
|
|
- // 常规模式下,写 viewModel
|
|
|
- scope.viewModel.set(path, value)
|
|
|
- }
|
|
|
- }
|
|
|
+ me._lookupSet(path, value)
|
|
|
+ })
|
|
|
+ // lookup
|
|
|
+ // fromColumn: 'toTarget'
|
|
|
+ // fromColumn: 'toTarget'
|
|
|
+ // fromColumn: 'toTarget'
|
|
|
+ _.forOwn(lookup, (toTarget, fromColumn) => {
|
|
|
+ const value = _.get(record, fromColumn)
|
|
|
+ me._lookupSet(toTarget, value)
|
|
|
})
|
|
|
|
|
|
+ const {lookupClearOnChange} = me
|
|
|
+ if (_.isArray(lookupClearOnChange)) {
|
|
|
+ _.each(lookupClearOnChange, item => {
|
|
|
+ me._lookupSet(item, '')
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
me.collapse();
|
|
|
},
|
|
|
|
|
|
onExpand() {
|
|
|
// 展开时,根据 lookup 带入查询参数
|
|
|
- const {param} = this
|
|
|
- const scope = lookupScope(this)
|
|
|
- const queryValue = this.getRawValue()
|
|
|
-
|
|
|
- const reloadParam = calcObjectFlat({
|
|
|
- ...scope.viewModel.data,
|
|
|
- queryValue
|
|
|
- }, param)
|
|
|
+ const reloadParam = calcObjectFlat(this.getExpressData(), this.param)
|
|
|
|
|
|
- console.log('reload', reloadParam)
|
|
|
this.grid.reload(reloadParam)
|
|
|
},
|
|
|
|
|
|
- onTriggerClick() {
|
|
|
- const {isExpanded, readOnly, disabled, grid} = this
|
|
|
+ onTriggerClick(sender) {
|
|
|
+ const {isExpanded, readOnly, disabled, grid,} = this
|
|
|
|
|
|
if (!grid) {
|
|
|
msg('正在初始化,请稍后')
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ if (!this.tryEnable()) {
|
|
|
+ // 没有达成 editEnable 条件,不用弹出
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
if (isExpanded || readOnly || disabled) {
|
|
|
// 已弹出、只读、禁用状态下,不允许弹出
|
|
|
return
|
|
@@ -265,13 +288,52 @@ export default function () {
|
|
|
* 本方法只会从 API 或外部调用,键盘输入的内容不会记录在内
|
|
|
*/
|
|
|
setValue(value) {
|
|
|
- const me = this;
|
|
|
+ const me = this
|
|
|
|
|
|
// 设值用户看到的表面内容
|
|
|
- this.setRawValue(value);
|
|
|
+ this.setRawValue(value)
|
|
|
|
|
|
// 设值 setValue 调用链,正常触发 change 事件等
|
|
|
- return me.mixins.field.setValue.call(me, value);
|
|
|
+ return me.mixins.field.setValue.call(me, value)
|
|
|
+ },
|
|
|
+
|
|
|
+ _lookupSet(path, value) {
|
|
|
+ const me = this
|
|
|
+ path = tryVarSimple(path)
|
|
|
+
|
|
|
+ if (me.column) {
|
|
|
+
|
|
|
+ // 判断写入目标,是否与自己绑定的属性相等
|
|
|
+ if (path === 'queryValue' || me.column.dataIndex === path) {
|
|
|
+ me.setValue(value)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 列模式下,写当前编辑行
|
|
|
+ const parentRecord = me._lookupEditorRecord()
|
|
|
+ if (parentRecord) {
|
|
|
+ // Ext.data.Record / Ext.data.Model
|
|
|
+ parentRecord.set(path, value)
|
|
|
+ } else {
|
|
|
+ debugger
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ // 常规模式下,写 viewModel
|
|
|
+ me.scope.viewModel.set(path, value)
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ _lookupGrid() {
|
|
|
+ return this.column.up('grid')
|
|
|
+ },
|
|
|
+
|
|
|
+ _lookupEditorRecord() {
|
|
|
+ // parentGrid.getSelectionModel().getLastSelected()
|
|
|
+ const grid = this._lookupGrid()
|
|
|
+ const rowIdx = grid.editingPlugin?.activeEditor?.context?.rowIdx
|
|
|
+ if (_.isNumber(rowIdx)) {
|
|
|
+ return grid.store.getAt(rowIdx)
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
onChange: function (newVal, oldVal) {
|
|
@@ -288,17 +350,54 @@ export default function () {
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
+ * 得到能用于 express 表达式计算的上下文数据
|
|
|
+ */
|
|
|
+ getExpressData() {
|
|
|
+ const queryValue = this.getRawValue()
|
|
|
+
|
|
|
+ if (this.column) {
|
|
|
+ // 列模式, 准备好判断 editEnable 表达式用的数据
|
|
|
+ const parentRecord = this._lookupEditorRecord()
|
|
|
+ if (!parentRecord) {
|
|
|
+ debugger
|
|
|
+ }
|
|
|
+
|
|
|
+ return {
|
|
|
+ ...this.scope.viewModel.data,
|
|
|
+ ...parentRecord.data,
|
|
|
+ queryValue,
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ // 编辑模式,准备好判断用的数据
|
|
|
+ return {
|
|
|
+ ...this.scope.viewModel.data,
|
|
|
+ queryValue,
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ tryEnable() {
|
|
|
+ return tryEnable(this.getExpressData(), this.editEnable)
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
* 清空所有值
|
|
|
*/
|
|
|
onClearClick(sender, e) {
|
|
|
const me = this
|
|
|
- const {config} = me
|
|
|
- const {lookup} = config
|
|
|
+ const {lookup, lookupClearOnChange} = me
|
|
|
|
|
|
me.fireEvent('clear', sender, e)
|
|
|
|
|
|
me.setValue('')
|
|
|
- clearViewModelByLookup(sender, lookup)
|
|
|
+ _.forOwn(lookup, (toTarget, fromColumn) => {
|
|
|
+ me._lookupSet(toTarget, '')
|
|
|
+ })
|
|
|
+
|
|
|
+ _.each(lookupClearOnChange, item => {
|
|
|
+ me._lookupSet(item, '')
|
|
|
+ })
|
|
|
}
|
|
|
});
|
|
|
|