|
@@ -1,9 +1,9 @@
|
|
import _ from 'lodash'
|
|
import _ from 'lodash'
|
|
import {grid} from '../Defaults'
|
|
import {grid} from '../Defaults'
|
|
import {baseConfig} from "./base";
|
|
import {baseConfig} from "./base";
|
|
-import {invokeMethod} from "../utils";
|
|
|
|
import {lookupFn, lookupScope} from "../lib/lib";
|
|
import {lookupFn, lookupScope} from "../lib/lib";
|
|
import {serverInvokeUrlTransform} from "../lib/config";
|
|
import {serverInvokeUrlTransform} from "../lib/config";
|
|
|
|
+import {calcObject} from "../lib/systemLib";
|
|
|
|
|
|
export default function () {
|
|
export default function () {
|
|
|
|
|
|
@@ -19,33 +19,6 @@ export default function () {
|
|
|
|
|
|
}, baseConfig(config, 'row-item'), config, grid)
|
|
}, baseConfig(config, 'row-item'), config, grid)
|
|
|
|
|
|
-
|
|
|
|
- if (_.isPlainObject(dataSource) && dataSource.method === 'invoke' && !window["IS_DESIGN_MODE"]) {
|
|
|
|
- newConfig.store = {
|
|
|
|
- autoLoad: newConfig.autoLoad,
|
|
|
|
- remoteSort: newConfig.remoteSort,
|
|
|
|
- remoteFilter: newConfig.remoteFilter,
|
|
|
|
- proxy: {
|
|
|
|
- type: 'jsonAjax',
|
|
|
|
- $owner: me,
|
|
|
|
- url: serverInvokeUrlTransform(dataSource.url),
|
|
|
|
- extraParams: dataSource.params,
|
|
|
|
- reader: {
|
|
|
|
- type: 'json',
|
|
|
|
- rootProperty: 'data',
|
|
|
|
- totalProperty: 'pagination.total',
|
|
|
|
- successProperty: 'success',
|
|
|
|
- messageProperty: 'msg'
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- listeners: {
|
|
|
|
- load: function (store, records, successful, operation) {
|
|
|
|
- me.fireEvent('dataLoadComplete', me, successful, records);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
const buttons = [
|
|
const buttons = [
|
|
{
|
|
{
|
|
xtype: 'button',
|
|
xtype: 'button',
|
|
@@ -113,37 +86,81 @@ export default function () {
|
|
this.superclass.constructor.call(this, newConfig)
|
|
this.superclass.constructor.call(this, newConfig)
|
|
},
|
|
},
|
|
|
|
|
|
- setData(value) {
|
|
|
|
- if (!this.store) {
|
|
|
|
- const {config} = this
|
|
|
|
- this.store = new Ext.data.Store({
|
|
|
|
- fields: getFileds(config),
|
|
|
|
- data: value
|
|
|
|
- })
|
|
|
|
- } else {
|
|
|
|
- this.store.getProxy().setData(value)
|
|
|
|
- this.store.load()
|
|
|
|
|
|
+ _setDataReal(value) {
|
|
|
|
+ const me = this
|
|
|
|
+ me.setStore(new Ext.data.Store({
|
|
|
|
+ fields: getFileds(this),
|
|
|
|
+ data: value
|
|
|
|
+ }))
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 轻量级刷新
|
|
|
|
+ */
|
|
|
|
+ refreshData() {
|
|
|
|
+ const store = this.getStore()
|
|
|
|
+ if (store) {
|
|
|
|
+ store.reload()
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
|
|
- reload() {
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 重新载入数据(重新计算参数)
|
|
|
|
+ */
|
|
|
|
+ reload(reloadParams = {}) {
|
|
const me = this
|
|
const me = this
|
|
const {config} = me
|
|
const {config} = me
|
|
|
|
|
|
if (config.dataSourceCallbackFn) {
|
|
if (config.dataSourceCallbackFn) {
|
|
|
|
+ // 函数请求刷新
|
|
const scope = lookupScope(this)
|
|
const scope = lookupScope(this)
|
|
- me.setLoading(true)
|
|
|
|
|
|
+ // me.setLoading(true)
|
|
config.dataSourceCallbackFn.call(scope, me, {
|
|
config.dataSourceCallbackFn.call(scope, me, {
|
|
successCallback(value) {
|
|
successCallback(value) {
|
|
- me.setData(value)
|
|
|
|
- me.setLoading(false)
|
|
|
|
|
|
+ me._setDataReal(value)
|
|
|
|
+ // me.setLoading(false)
|
|
me.fireEvent('dataLoadComplete', me, true, value);
|
|
me.fireEvent('dataLoadComplete', me, true, value);
|
|
},
|
|
},
|
|
failCallback(error) {
|
|
failCallback(error) {
|
|
- me.setLoading(false)
|
|
|
|
|
|
+ // me.setLoading(false)
|
|
me.fireEvent('dataLoadComplete', me, false, error);
|
|
me.fireEvent('dataLoadComplete', me, false, error);
|
|
}
|
|
}
|
|
})
|
|
})
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // if (this.store) {
|
|
|
|
+ // this.store.reload({aaaa: 1, bbbb: 2})
|
|
|
|
+ // }
|
|
|
|
+ const {dataSource} = config
|
|
|
|
+ if (_.isPlainObject(dataSource) && dataSource.method === 'invoke' && !window["IS_DESIGN_MODE"]) {
|
|
|
|
+ const scope = lookupScope(me)
|
|
|
|
+
|
|
|
|
+ calcObject(scope.viewModel, dataSource.params).then(params => {
|
|
|
|
+
|
|
|
|
+ me.setStore(new Ext.data.Store({
|
|
|
|
+ remoteSort: config.remoteSort,
|
|
|
|
+ remoteFilter: config.remoteFilter,
|
|
|
|
+ proxy: {
|
|
|
|
+ type: 'jsonAjax',
|
|
|
|
+ $owner: me,
|
|
|
|
+ url: serverInvokeUrlTransform(dataSource.url),
|
|
|
|
+ extraParams: _.defaultsDeep({}, reloadParams, params),
|
|
|
|
+ reader: {
|
|
|
|
+ type: 'json',
|
|
|
|
+ rootProperty: 'data',
|
|
|
|
+ totalProperty: 'pagination.total',
|
|
|
|
+ successProperty: 'success',
|
|
|
|
+ messageProperty: 'msg'
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ listeners: {
|
|
|
|
+ load: function (store, records, successful, operation) {
|
|
|
|
+ me.fireEvent('dataLoadComplete', me, successful, records);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }))
|
|
|
|
+ })
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
|
|
@@ -160,8 +177,17 @@ export default function () {
|
|
this.on({
|
|
this.on({
|
|
afterrender(sender) {
|
|
afterrender(sender) {
|
|
const {config} = this
|
|
const {config} = this
|
|
- if (config.dataSourceCallbackFn && config.autoLoad) {
|
|
|
|
- me.reload()
|
|
|
|
|
|
+ if (config.autoLoad) {
|
|
|
|
+ if (config.dataSourceCallbackFn) {
|
|
|
|
+ me.reload()
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ const {dataSource} = config
|
|
|
|
+ if (_.isPlainObject(dataSource) && dataSource.method === 'invoke') {
|
|
|
|
+ me.reload()
|
|
|
|
+ return
|
|
|
|
+ }
|
|
}
|
|
}
|
|
},
|
|
},
|
|
destory() {
|
|
destory() {
|
|
@@ -251,14 +277,23 @@ function convertDataSource(sender, scope, newConfig) {
|
|
|
|
|
|
if (typeof dataSource === 'function') {
|
|
if (typeof dataSource === 'function') {
|
|
// dataSource 是函数的情况下,在 afterrender 之后进行回调
|
|
// dataSource 是函数的情况下,在 afterrender 之后进行回调
|
|
- newConfig.store = {
|
|
|
|
|
|
+ newConfig.store = new Ext.data.Store({
|
|
fields: getFileds(newConfig),
|
|
fields: getFileds(newConfig),
|
|
- data: []
|
|
|
|
- }
|
|
|
|
|
|
+ // data: [],
|
|
|
|
+ autoLoad: true,
|
|
|
|
+ proxy: {
|
|
|
|
+ type: 'memory',
|
|
|
|
+ data: [],
|
|
|
|
+ // reader: {
|
|
|
|
+ // type: 'json',
|
|
|
|
+ // rootProperty: 'users'
|
|
|
|
+ // }
|
|
|
|
+ }
|
|
|
|
+ })
|
|
newConfig.dataSourceCallbackFn = dataSource
|
|
newConfig.dataSourceCallbackFn = dataSource
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- throw new TypeError('无法识别的调用方法')
|
|
|
|
|
|
+ // throw new TypeError('无法识别的调用方法')
|
|
}
|
|
}
|