mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-04 21:08:55 +08:00
CRUD 可以不依赖 api 直接读取环境数据, 同时修复跳转下一页携带数据格式不一致的问题
This commit is contained in:
parent
1485c25e87
commit
136d3a00c8
@ -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) {
|
||||
|
@ -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
|
||||
};
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user