crud loadOnce 模式支持字段过滤

This commit is contained in:
liaoxuezhi 2019-10-09 14:21:03 +08:00
parent d9f05f00d0
commit 8f548a205a
1 changed files with 17 additions and 11 deletions

View File

@ -91,7 +91,7 @@ export const CRUDStore = ServiceStore.named('CRUDStore')
updater && updater &&
isObjectShallowModified(originQuery, self.query, false) && isObjectShallowModified(originQuery, self.query, false) &&
setTimeout(() => updater(`?${qs.stringify(self.query, { encodeValuesOnly: true })}`), 4); setTimeout(() => updater(`?${qs.stringify(self.query, {encodeValuesOnly: true})}`), 4);
} }
const fetchInitData: ( const fetchInitData: (
@ -117,7 +117,16 @@ export const CRUDStore = ServiceStore.named('CRUDStore')
) { ) {
try { try {
if (options.forceReload === false && options.loadDataOnce && self.total) { if (options.forceReload === false && options.loadDataOnce && self.total) {
let items = self.items.concat(); let items = options.source
? resolveVariableAndFilter(
options.source,
createObject(self.mergedData, {
items: self.data.itemsRaw,
rows: self.data.itemsRaw
}),
'| raw'
)
: self.items.concat();
if (self.query.orderBy) { if (self.query.orderBy) {
const dir = /desc/i.test(self.query.orderDir) ? -1 : 1; const dir = /desc/i.test(self.query.orderDir) ? -1 : 1;
@ -212,6 +221,9 @@ export const CRUDStore = ServiceStore.named('CRUDStore')
}; };
if (options.loadDataOnce) { if (options.loadDataOnce) {
// 记录原始集合,后续可能基于原始数据做排序查找。
data.itemsRaw = oItems || oRows;
if (self.query.orderBy) { if (self.query.orderBy) {
const dir = /desc/i.test(self.query.orderDir) ? -1 : 1; const dir = /desc/i.test(self.query.orderDir) ? -1 : 1;
rowsData = sortArray(rowsData, self.query.orderBy, dir); rowsData = sortArray(rowsData, self.query.orderBy, dir);
@ -338,18 +350,13 @@ export const CRUDStore = ServiceStore.named('CRUDStore')
self.hasInnerModalOpen = value; self.hasInnerModalOpen = value;
}; };
const initFromScope = function(scope:any, source:string) { const initFromScope = function(scope: any, source: string) {
let rowsData: Array<any> = resolveVariableAndFilter( let rowsData: Array<any> = resolveVariableAndFilter(source, scope, '| raw');
source,
scope,
'| raw'
);
if (!Array.isArray(rowsData)) { if (!Array.isArray(rowsData)) {
return; return;
} }
const data = { const data = {
...self.pristine, ...self.pristine,
items: rowsData, items: rowsData,
@ -357,10 +364,9 @@ export const CRUDStore = ServiceStore.named('CRUDStore')
total: 0 total: 0
}; };
self.items.replace(rowsData); self.items.replace(rowsData);
self.reInitData(data); self.reInitData(data);
} };
return { return {
setPristineQuery, setPristineQuery,