Procházet zdrojové kódy

combogrid 初步完成

luoyifan před 3 roky
rodič
revize
baeb5ddae4
2 změnil soubory, kde provedl 95 přidání a 13 odebrání
  1. 61 13
      src/controls/input/combogrid.js
  2. 34 0
      src/lib/systemLib.ts

+ 61 - 13
src/controls/input/combogrid.js

@@ -1,6 +1,7 @@
 import _ from 'lodash'
 import {comboGrid, comboGridPicker} from '../../Defaults'
 import {calcObjectFlat, clearViewModelByLookup, lookupScope, stopEvent, tryWriteByExpress, tryWriteObject} from "../..";
+import {msg} from "../../message";
 
 export default function () {
 
@@ -42,19 +43,36 @@ export default function () {
                 },
                 afterrender(sender) {
                     const $dom = $(sender.inputEl.dom)
-                    $dom.on('keyup', (e) => {
-                        if (e.key === 'Enter') {
-                            that.onTriggerClick(that, that.getPickerTrigger(), e);
-                            return
-                        }
-                        // 取消 keyup 事件,让 ext 不要吧当前输入的值记录到 value 中
-                        stopEvent(e)
-                    })
+                    if (sender.column) {
+                        // 列模式,拦截 keydown
+                        $dom.on('keydown', (e) => {
+                            if (e.key === 'Enter') {
+                                stopEvent(e)
+                                that.onTriggerClick(that, that.getPickerTrigger(), e);
+                                return
+                            }
+                        })
+
+                    } else {
+                        // 常规模式,拦截 keyup
+                        $dom.on('keyup', (e) => {
+                            if (e.key === 'Enter') {
+                                stopEvent(e)
+                                that.onTriggerClick(that, that.getPickerTrigger(), e);
+                                return
+                            }
+                            // 取消 keyup 事件,让 ext 不要吧当前输入的值记录到 value 中
+                            stopEvent(e)
+                        })
+                    }
                     $dom.on('input', e => {
-                        that.filterChange(that, e.target.value)
+                        // that.filterChange(that, e.target.value)
                         stopEvent(e)
                     })
                     $dom.on('change', e => {
+                        if (that.isExpanded) {
+                            that.filterChange(that, e.target.value)
+                        }
                         stopEvent(e)
                     })
                 },
@@ -113,8 +131,17 @@ export default function () {
                                             me.setFocus()
                                         })
                                     },
+                                    keydown(sender, e) {
+                                        if (me.column) {
+                                            // 列模式,拦截 keydown
+                                            me.processKey(e)
+                                        }
+                                    },
                                     keyup(sender, e) {
-                                        me.processKey(e)
+                                        if (!me.column) {
+                                            // 常规模式,拦截 keyup
+                                            me.processKey(e)
+                                        }
                                     }
                                 })
                             },
@@ -174,11 +201,22 @@ export default function () {
             if (record.isModel) {
                 record = record.data
             }
+
             tryWriteObject(lookup, record, (path, value) => {
                 if (path === 'queryValue') {
                     me.setValue(value)
                 } else {
-                    scope.viewModel.set(path, value)
+                    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)
+                    }
                 }
             })
 
@@ -189,20 +227,30 @@ export default function () {
             // 展开时,根据 lookup 带入查询参数
             const {param} = this
             const scope = lookupScope(this)
+            const queryValue = this.getRawValue()
+
             const reloadParam = calcObjectFlat({
                 ...scope.viewModel.data,
-                queryValue: this.getRawValue()
+                queryValue
             }, param)
 
+            console.log('reload', reloadParam)
             this.grid.reload(reloadParam)
         },
 
         onTriggerClick() {
-            const {isExpanded, readOnly, disabled} = this
+            const {isExpanded, readOnly, disabled, grid} = this
+
+            if (!grid) {
+                msg('正在初始化,请稍后')
+                return
+            }
+
             if (isExpanded || readOnly || disabled) {
                 // 已弹出、只读、禁用状态下,不允许弹出
                 return
             }
+
             this._superBlur = true
             this.superclass.onTriggerClick.apply(this, arguments)
             this._superBlur = false

+ 34 - 0
src/lib/systemLib.ts

@@ -719,6 +719,40 @@ class SystemEventFu {
     }
 
     @Lib({
+        title: '从其他资源获取表格设置',
+        author: '罗一帆',
+        createAt: '2021-07-02',
+        updateAt: '2021-07-02',
+        type: 'system',
+        category: '表单',
+        args: [
+            {
+                type: 'viewModel',
+                title: 'propertyName 属性路径',
+                name: 'propertyName',
+            },
+            {
+                type: 'refs',
+                title: 'gridRef 表格引用名',
+                allowEmpty: true,
+                name: 'gridRefName',
+            }
+        ]
+    })
+    getGrid(url) {
+        return function (sender, config) {
+            // @ts-ignore
+            require([url], (grid) => {
+                if (sender.rendered) {
+                    sender.grid = grid.default
+                } else {
+                    config.grid = grid.default
+                }
+            })
+        }
+    }
+
+    @Lib({
         title: '清空 viewModel 某个属性,并刷新表格',
         author: '罗一帆',
         createAt: '2021-07-02',