CRUD 可以不依赖 api 直接读取环境数据, 同时修复跳转下一页携带数据格式不一致的问题

This commit is contained in:
liaoxuezhi 2019-09-12 11:50:46 +08:00
parent 1485c25e87
commit 136d3a00c8
2 changed files with 42 additions and 10 deletions

View File

@ -461,9 +461,12 @@ export default class CRUD extends React.Component<CRUDProps, any> {
{
...dialogAction
},
createObject(store.data.items[ctx.nextIndex], {
index: ctx.nextIndex
})
createObject(
createObject(store.data, {
index: ctx.nextIndex
}),
store.data.items[ctx.nextIndex]
)
);
} else if (
action.actionType === 'prev' &&
@ -475,9 +478,12 @@ export default class CRUD extends React.Component<CRUDProps, any> {
{
...dialogAction
},
createObject(store.data.items[ctx.prevIndex], {
index: ctx.prevIndex
})
createObject(
createObject(store.data, {
index: ctx.prevIndex
}),
store.data.items[ctx.prevIndex]
)
);
} else if (values.length) {
const value = values[0];
@ -570,8 +576,8 @@ export default class CRUD extends React.Component<CRUDProps, any> {
);
this.lastQuery = store.query;
const data = createObject(store.data, store.query);
isEffectiveApi(api, data) &&
store
isEffectiveApi(api, data)
? store
.fetchInitData(api, data, {
successMessage: messages && messages.fetchSuccess,
errorMessage: messages && messages.fetchFailed,
@ -598,7 +604,8 @@ export default class CRUD extends React.Component<CRUDProps, any> {
Math.max(interval, 3000)
));
return value;
});
})
: source && store.initFromScope(data, source);
}
silentSearch(values?: object) {

View File

@ -340,6 +340,30 @@ export const CRUDStore = ServiceStore.named('CRUDStore')
self.hasInnerModalOpen = value;
};
const initFromScope = function(scope:any, source:string) {
let rowsData: Array<any> = resolveVariableAndFilter(
source,
scope,
'| raw'
);
if (!Array.isArray(rowsData)) {
return;
}
const data = {
...self.pristine,
items: rowsData,
count: 0,
total: 0
};
self.items.replace(rowsData);
self.reInitData(data);
}
return {
setPristineQuery,
updateQuery,
@ -351,7 +375,8 @@ export const CRUDStore = ServiceStore.named('CRUDStore')
setFilterVisible,
setSelectedItems,
setUnSelectedItems,
setInnerModalOpened
setInnerModalOpened,
initFromScope
};
});