luoyifan пре 4 година
родитељ
комит
ea3b3b376d
3 измењених фајлова са 47 додато и 20 уклоњено
  1. 1 1
      src/DataSourceHelper.ts
  2. 1 1
      src/Defaults.ts
  3. 45 18
      src/controls/combo.js

+ 1 - 1
src/DataSourceHelper.ts

@@ -23,7 +23,7 @@ export function dataSourceReload(ctl: any, extraParam?: any, _successCb?: Functi
                 if (typeof successCallback === "function") {
                     successCallback(value)
                 } else {
-                    ctl.setDataReal(value)
+                    ctl.setData(value)
                 }
                 ctl.fireEvent('dataLoadComplete', ctl, true, value);
                 ctl.setLoading(false)

+ 1 - 1
src/Defaults.ts

@@ -7,9 +7,9 @@ export const windows = {
 export const combo = {
     labelAlign: 'right',
     labelWidth: 70,
-    selectOnFocus: true,
     valueField: 'id',
     displayField: 'text',
+    autoLoad: true,
 }
 
 export const text = {

+ 45 - 18
src/controls/combo.js

@@ -1,7 +1,6 @@
 import _ from 'lodash'
 import {combo} from '../Defaults'
 import {baseConfig} from "./base";
-import {lookupScope, lookupFn} from "../lib/lib";
 import {dataSourceReload} from "../DataSourceHelper";
 
 export default function () {
@@ -21,20 +20,21 @@ export default function () {
                         fields: [newConfig.valueField, newConfig.displayField],
                         data: newConfig.data
                     }
-                }
+                    delete newConfig.data
 
-                if (typeof newConfig.data !== 'object') {
+                } else if (typeof newConfig.data !== 'object') {
                     newConfig.store = {
                         fields: [newConfig.valueField, newConfig.displayField],
                         data: []
                     }
+                    delete newConfig.data
                 }
             }
 
             cc.call(this, newConfig)
         },
 
-        setDataReal(value) {
+        setData(value) {
             const {config} = value
             if (!this.store) {
                 this.store = new Ext.data.Store({
@@ -47,32 +47,59 @@ export default function () {
             }
         },
 
+        setLoading(value) {
+            if (value) {
+                if (!this.loadMask) {
+                    this.loadMask = new Ext.LoadMask(this, {msg: "loading..."});
+                }
+            } else {
+                if (this.loadMask) {
+                    this.loadMask.destroy()
+                    delete this.loadMask
+                }
+            }
+        },
+
+        reload() {
+            dataSourceReload(this)
+        },
+
         initComponent() {
+            const that = this
+            const toggle = () => {
+                if (that.isExpanded) {
+                    that.collapse()
+
+                } else {
+                    that.expand();
+                    that.doQuery(that.allQuery, true);
+                }
+            }
+
             this.on({
                 afterrender() {
                     const {config} = this
-                    const scope = lookupScope(this)
 
-                    if (config.dataSource) {
-                        _.defer(() => {
-                            dataSourceReload(this)
-                        })
+                    if (config.dataSource && config.autoLoad) {
+                        dataSourceReload(this)
                     }
+
+                    $(this.el.dom).on('click', toggle)
                 },
-                focus: {
-                    // 获得焦点后自动下拉
-                    fn(sender) {
-                        sender.expand();
-                        this.doQuery(this.allQuery, true);
-                    },
+                destory() {
+                    $(this.el.dom).off('click', toggle)
                 },
+                // focus: {
+                //     // 获得焦点后自动下拉
+                //     fn(sender) {
+                //         sender.expand();
+                //         this.doQuery(this.allQuery, true);
+                //     },
+                // },
             })
 
             initComponent.call(this)
         },
 
-        reload() {
-
-        }
     });
 }