luoyifan пре 3 година
родитељ
комит
161afda3d1
6 измењених фајлова са 159 додато и 28 уклоњено
  1. 47 4
      src/controls/MainTab.js
  2. 7 6
      src/controls/component.js
  3. 12 0
      src/controls/grid.js
  4. 7 6
      src/lib/fix.js
  5. 0 12
      src/lib/lib.ts
  6. 86 0
      src/lib/systemLib.ts

+ 47 - 4
src/controls/MainTab.js

@@ -1,5 +1,6 @@
 import _ from 'lodash'
 import $ from 'jquery'
+import qs from 'qs'
 
 export default function () {
 
@@ -14,11 +15,14 @@ export default function () {
         }),
 
         constructor(config) {
-            const self = this
+            const me = this
             const newConfig = _.defaultsDeep({}, config, {
                 listeners: {
                     tabchange(tabPanel, newCard, oldCard, eOpts) {
-                        console.log('tabChange')
+                        _.defer(() => {
+                            me.changeHash(newCard.path)
+                        })
+
                         $(window).trigger('tabChange', {
                             tabPanel, newCard, oldCard, eOpts
                         });
@@ -29,7 +33,40 @@ export default function () {
                     }
                 }
             })
-            this.superclass.constructor.call(self, newConfig)
+            this.superclass.constructor.call(me, newConfig)
+        },
+
+        initComponent() {
+            const me = this
+            this.on({
+                afterrender() {
+                    _.defer(() => {
+                        me.tryRestoryPage()
+                    })
+                }
+            })
+            this.superclass.initComponent.call(me)
+        },
+
+        tryRestoryPage() {
+            const me = this
+            let hash = '' + window.location.hash
+            if (hash && hash.indexOf('page=') > 0) {
+                if (hash.startsWith('#')) {
+                    hash = hash.substr(1)
+                }
+                if (hash) {
+                    const {page} = qs.parse(hash)
+                    if (page) {
+                        // this.openScope(page)
+                        me.fireEvent('restorypage', page)
+                    }
+                }
+            }
+        },
+
+        changeHash(pageUrl) {
+            window.location.hash = qs.stringify({page: pageUrl})
         },
 
         /**
@@ -38,6 +75,7 @@ export default function () {
          * @param config ExtJS配置对象
          */
         addScope(scopeInstance, config, reload) {
+            const me = this
             if (config.path) {
                 for (let i = 0; i < this.items.items.length; i++) {
                     // 找到当前 tabs 里有没有已经打开过
@@ -56,12 +94,17 @@ export default function () {
             }
 
             // 添加业务模块
-            this.add({
+            const newTab = this.add({
                 closable: true,
                 ...config,
             })
 
             this.setActiveTab(scopeInstance._handle);
+            newTab.on({
+                destroy(sender) {
+                    me.changeHash('')
+                }
+            })
         }
     });
 

+ 7 - 6
src/controls/component.js

@@ -5,12 +5,13 @@ export default function () {
     const ct = Ext.Component.prototype.constructor
     Ext.Component.override({
         constructor: function (config) {
-            const me = this
-            // 任意组件 Ext.Component 构造时调用的方法, 可以用来在渲染之前加工处理 VJSON
-            _.each(baseConfigProcessList, process => {
-                process.call(me, me, config)
-            })
-
+            if(config) {
+                const me = this
+                // 任意组件 Ext.Component 构造时调用的方法, 可以用来在渲染之前加工处理 VJSON
+                _.each(baseConfigProcessList, process => {
+                    process.call(me, me, config)
+                })
+            }
             ct.call(this, config)
         }
     });

+ 12 - 0
src/controls/grid.js

@@ -38,6 +38,12 @@ export default function () {
                     tooltip: '清空筛选',
                     iconCls: 'x-fa fa-filter',
                     handler: this.clearFilter
+                },
+                {
+                    xtype: 'button',
+                    tooltip: '清空筛选',
+                    iconCls: 'x-fa fa-cube',
+                    handler: this.test
                 }
             ]
 
@@ -230,6 +236,12 @@ export default function () {
             sender.up('grid').filters.clearFilters();
         },
 
+        test(sender) {
+            const grid = sender.up('grid')
+            // grid.refreshData()
+            // console.log('grid', grid)
+        },
+
         setLoading(value) {
             if (value) {
                 this.mask('读取中')

+ 7 - 6
src/lib/fix.js

@@ -12,14 +12,15 @@ class FixClass {
         }
 
         const scope = lookupScope(me)
-        const fixFnArray = []
         if (_.isArray(fix)) {
-            fixFnArray.push(_.map(fix, (f) => lookupFn(scope, f)))
+            _.each(fix, (f) => {
+                const fn = lookupFn(scope, f)
+                fn.call(this, me, config)
+            })
+
         } else if (_.isString(fix)) {
-            fixFnArray.push(lookupFn(scope, fix))
+            const fn = lookupFn(scope, fix)
+            fn.call(this, me, config)
         }
-
-        console.log(fixFnArray)
-        debugger
     }
 }

+ 0 - 12
src/lib/lib.ts

@@ -53,15 +53,3 @@ export function lookupScope(extHandle: any): Scope {
     const vm = extHandle.lookupViewModel()
     return vm.yvanScope
 }
-
-export function getClassName(me) {
-    return me.$className
-}
-
-/**
- * 用于任意组件 Ext.Component 构造时,获取当前组件对应的表格(如果不是 grid.columns 对象就会返回 undefined)
- * @param config 组件构造函数传入的 config 配置文件
- */
-export function getParentGrid(config) {
-    return config.$initParent?.grid
-}

+ 86 - 0
src/lib/systemLib.ts

@@ -71,6 +71,92 @@ export function calcObject(viewModel, paramObject) {
 }
 
 /**
+ * 用于任意组件 Ext.Component 构造时,获取当前组件对应的表格(如果不是 grid.columns 对象就会返回 undefined)
+ * @param config 组件构造函数传入的 config 配置文件
+ */
+export function getParentGrid(config) {
+    return config.$initParent?.grid
+}
+
+/**
+ * 动态的为 combo 或 columns.combo 设置下拉框的值
+ * @param sender 目标对象
+ * @param config 目标对象的配置(在构造函数之前也可以)
+ * @param getDictFn 获取字典的方法
+ * @param bizKey 传入字典的参数
+ */
+export function setComboStore(sender, config, getDictFn, bizKey) {
+
+    if (sender.$className === 'Ext.form.field.ComboBox') {
+        getDictFn(bizKey, (r) => {
+            if (sender.el?.dom) {
+                // 异步回传
+                sender.setStore(new Ext.data.Store(r))
+            } else {
+                // 同步回传
+                config.store = new Ext.data.Store(r)
+            }
+        })
+        return
+
+    } else if (sender.xtype === 'gridcolumn') {
+        const grid = getParentGrid(config)
+        const {editor, renderer} = config
+        getDictFn(bizKey, (r) => {
+            if (sender.rendered) {
+                // 已经渲染出来了, 用方法进行修改
+                const editor = sender.getEditor()
+                if (editor.xtype === 'combo') {
+                    const valueField = r.field[0]
+                    const displayField = r.field[1]
+                    editor.valueField = valueField
+                    editor.setDisplayField(displayField)
+                    editor.setStore(new Ext.data.Store({
+                        field: ['id', 'text'],
+                        data: [
+                            {id: "Y", text: "启用"},
+                            {id: "N", text: "禁用"},
+                            {id: "D", text: "删除"},
+                        ]
+                    }))
+                }
+
+            } else {
+                // 没有渲染之前,修改 config 即可
+                if (editor && editor.xtype === 'combo') {
+                    // 带编辑模式
+                    editor.store = new Ext.data.Store(r)
+                }
+            }
+
+            const renderer = (value, metaData) => {
+                const valueField = r.field[0]
+                const displayField = r.field[1]
+                _.each(r.data, row => {
+                    // 从 valueField 找到要显示的 displayField
+                    if (row[valueField] === value) {
+                        value = row[displayField]
+                        return false
+                    }
+                })
+
+                return value
+            }
+
+            if (sender.rendered) {
+                // 已经渲染出来了, 对列进行渲染
+                sender.renderer = renderer
+                sender.getView().refresh()
+            } else {
+                config.renderer = renderer
+            }
+        })
+        return
+    }
+    throw new TypeError("无法识别的组件类型")
+}
+
+/**
  * 调用服务器 Ajax
  */
 export function invokeServer(url: string, ...args: any[]) {