瀏覽代碼

tree 过滤

luoyifan 3 年之前
父節點
當前提交
378beabd56
共有 3 個文件被更改,包括 70 次插入56 次删除
  1. 3 0
      src/Defaults.ts
  2. 60 56
      src/controls/yvtree.js
  3. 7 0
      src/lib/lib.ts

+ 3 - 0
src/Defaults.ts

@@ -167,6 +167,9 @@ export const tree = {
     autoLoad: true,
     hideFilter: false,
     hideToolbar: false,
+    hideRefresh: false,
+    hideExpand: false,
+    hideCollapse: false,
 }
 
 export const search = {

+ 60 - 56
src/controls/yvtree.js

@@ -17,6 +17,65 @@ export default function () {
 
             }, baseConfig(config, 'row-item'), config, tree)
 
+            _.assign(newConfig, {
+                root: [],
+                rootVisible: false,
+                tbar: [
+                    {
+                        xtype: 'trigger',
+                        triggerCls: 'x-form-clear-trigger',
+                        flex: 1,
+                        emptyText: '搜索过滤',
+                        enableKeyEvents: true,
+                        listeners: {
+                            change: {
+                                fn(sender, e) {
+                                    const scope = sender.up("yvtree")
+                                    scope.filterByText(this.getRawValue());
+                                },
+                                buffer: 500
+                            },
+                        }
+                    },
+                ],
+            })
+
+            if (!newConfig.hideRefresh) {
+                newConfig.tbar.push({
+                    xtype: 'button', iconCls: 'x-fa fa-refresh', tooltip: '刷新',
+                    listeners: {
+                        click(sender) {
+                            const scope = sender.up("yvtree")
+                            scope.reload()
+                        }
+                    }
+                })
+            }
+
+            if (!newConfig.hideExpand) {
+                newConfig.tbar.push({
+                    xtype: 'button', iconCls: 'x-fa fa-plus-square-o', tooltip: '全部展开',
+                    listeners: {
+                        click(sender) {
+                            const scope = sender.up("yvtree")
+                            scope.expandAll()
+                        }
+                    }
+                })
+            }
+
+            if (!newConfig.hideCollapse) {
+                newConfig.tbar.push({
+                    xtype: 'button', iconCls: 'x-fa fa-minus-square-o', tooltip: '全部收起',
+                    listeners: {
+                        click(sender) {
+                            const scope = sender.up("yvtree")
+                            scope.collapseAll()
+                        }
+                    }
+                })
+            }
+
             this.superclass.constructor.call(this, newConfig)
         },
 
@@ -248,62 +307,7 @@ export default function () {
             }, null, [this, view]);
         },
 
-        root: [],
-        rootVisible: false,
-        tbar: [
-            {
-                xtype: 'trigger',
-                triggerCls: 'x-form-clear-trigger',
-                onTriggerClick(sender) {
-                    sender.setValue('');
-                    const scope = sender.up("yvtree")
-                    scope.clearFilter()
-                },
-                flex: 1,
-                emptyText: '搜索过滤',
-                enableKeyEvents: true,
-                listeners: {
-                    keyup: {
-                        fn(sender, e) {
-                            if (e.ESC == e.getKey()) {
-                                sender.onTriggerClick(sender);
-                            } else {
-                                const scope = sender.up("yvtree")
-                                scope.filterByText(this.getRawValue());
-                            }
-                        },
-                        buffer: 500
-                    }
-                }
-            },
-            {
-                xtype: 'button', iconCls: 'x-fa fa-refresh', tooltip: '刷新',
-                listeners: {
-                    click(sender) {
-                        const scope = sender.up("yvtree")
-                        scope.reload()
-                    }
-                }
-            },
-            {
-                xtype: 'button', iconCls: 'x-fa fa-plus-square-o', tooltip: '全部展开',
-                listeners: {
-                    click(sender) {
-                        const scope = sender.up("yvtree")
-                        scope.expandAll()
-                    }
-                }
-            },
-            {
-                xtype: 'button', iconCls: 'x-fa fa-minus-square-o', tooltip: '全部收起',
-                listeners: {
-                    click(sender) {
-                        const scope = sender.up("yvtree")
-                        scope.collapseAll()
-                    }
-                }
-            }
-        ],
+
     })
 }
 

+ 7 - 0
src/lib/lib.ts

@@ -25,16 +25,23 @@ export function getRegParamList(methodName: string) {
     return regParamList[methodName]
 }
 
+/**
+ * 模拟点击按钮
+ */
 export function raiseClick(buttonHandle) {
     if (!buttonHandle) {
         return false
     }
     if (buttonHandle.disabled) {
+        // 按钮是禁止状态
         return false
     }
     if (buttonHandle.hidden) {
+        // 按钮是隐藏状态
         return false
     }
+
+    // 按钮点击
     buttonHandle.click()
     return true
 }