debugStore的一个小bug,pagination支持宽窄分开设置

This commit is contained in:
Xu Chang 2024-05-07 10:19:47 +08:00
parent 23f12303cb
commit b52598a9c0
13 changed files with 68 additions and 16 deletions

View File

@ -144,7 +144,7 @@ async function doRoutines(store, contextBuilder, routines) {
await context.begin();
try {
await context.initialize();
const result = execWatcher(store, routine, context);
const result = await execWatcher(store, routine, context);
await context.commit();
console.log(`例程【${name}】执行完成,耗时${Date.now() - start}毫秒,结果是`, result);
}

View File

@ -45,7 +45,7 @@ export function onPathSet(option) {
});
assert(oakPath2, '没有正确的path信息请检查是否配置正确');
const { actions, cascadeActions } = option;
// 在这里适配宽窄屏处理getTotal,不到运行时处理了 by Xc
// 在这里适配宽窄屏处理getTotal/pagination,不到运行时处理了 by Xc
let getTotal2;
if (getTotal) {
const { width } = this.props;
@ -78,6 +78,16 @@ export function onPathSet(option) {
}
}
}
let pagination2;
if (pagination) {
if (pagination instanceof Array) {
const { width } = this.props;
pagination2 = pagination.find(ele => width === 'xs' && ele.deviceWidth === 'mobile' || width !== 'xs' && ele.deviceWidth === 'pc');
}
else {
pagination2 = pagination;
}
}
else {
// 不设置的默认情况宽屏取100窄屏不取
const { width } = this.props;
@ -90,7 +100,7 @@ export function onPathSet(option) {
entity: entity2,
isList,
projection: projection2,
pagination: pagination,
pagination: pagination2,
filters: filters2,
sorters: sorters2,
id: oakId,

View File

@ -635,10 +635,12 @@ export function createComponent(option, features) {
? Object.assign({}, data, {
oakFullpath: '',
oakLoading: !!option.entity && !!option.projection,
width: 'xs',
})
: {
oakFullpath: '',
oakLoading: !!option.entity && !!option.projection,
width: 'xs',
},
properties: Object.assign({}, translatePropertiesToPropertyDefinitions(properties), OakPropertyTypes),
methods: {

9
es/types/Page.d.ts vendored
View File

@ -34,11 +34,12 @@ type FeatureDef<IsList extends boolean, ED extends EntityDict & BaseEntityDict,
behavior?: 'reRender' | 'refresh';
callback?: (this: ComponentPublicThisType<ED, T, Cxt, FrontCxt, AD, FD, FormedData, IsList, TData, TProperty, TMethod, EMethod>) => void;
};
type DevideWidth = 'pc' | 'mobile';
interface ComponentOption<IsList extends boolean, ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends AsyncContext<ED>, FrontCxt extends SyncContext<ED>, AD extends Record<string, Aspect<ED, AsyncContext<ED>>>, FD extends Record<string, Feature>, FormedData extends Record<string, any>, TData extends DataOption, TProperty extends DataOption, TMethod extends Record<string, Function>, EMethod extends Record<string, Function> = {}> {
isList?: IsList;
getTotal?: {
max: number;
deviceWidth?: 'pc' | 'mobile' | 'all';
deviceWidth?: DevideWidth | 'all';
} | number;
entity?: T | ((this: ComponentPublicThisType<ED, T, Cxt, FrontCxt, AD, FD, FormedData, IsList, TData, TProperty, TMethod, EMethod>) => T);
path?: string;
@ -49,7 +50,11 @@ interface ComponentOption<IsList extends boolean, ED extends EntityDict & BaseEn
actions?: ActionDef<ED, T>[] | ((this: ComponentPublicThisType<ED, T, Cxt, FrontCxt, AD, FD, FormedData, IsList, TData, TProperty, TMethod, EMethod>) => ActionDef<ED, T>[]);
projection?: ED[T]['Selection']['data'] | ((this: ComponentPublicThisType<ED, T, Cxt, FrontCxt, AD, FD, FormedData, IsList, TData, TProperty, TMethod, EMethod>) => ED[T]['Selection']['data'] | undefined);
append?: boolean;
pagination?: Pick<Pagination, 'currentPage' | 'pageSize' | 'randomRange'>;
pagination?: Pick<Pagination, 'currentPage' | 'pageSize' | 'randomRange'> | [
Pick<Pagination, 'currentPage' | 'pageSize' | 'randomRange'> & {
deviceWidth: DevideWidth;
}
];
filters?: Array<{
filter: NonNullable<ED[T]['Selection']['filter']> | ((this: ComponentPublicThisType<ED, T, Cxt, FrontCxt, AD, FD, FormedData, IsList, TData, TProperty, TMethod, EMethod>) => ED[T]['Selection']['filter'] | undefined);
'#name'?: string;

View File

@ -147,7 +147,7 @@ async function doRoutines(store, contextBuilder, routines) {
await context.begin();
try {
await context.initialize();
const result = execWatcher(store, routine, context);
const result = await execWatcher(store, routine, context);
await context.commit();
console.log(`例程【${name}】执行完成,耗时${Date.now() - start}毫秒,结果是`, result);
}

View File

@ -800,7 +800,7 @@ class ListNode extends Node {
async loadMore() {
const { filters, sorters, pagination, entity } = this;
const { pageSize, more, currentPage, count } = pagination;
if (!more || this.loadingMore) {
if (!more || this.loadingMore || this.loading || !count) {
return;
}
// 要根据total来计算下一页

View File

@ -48,7 +48,7 @@ function onPathSet(option) {
});
(0, assert_1.assert)(oakPath2, '没有正确的path信息请检查是否配置正确');
const { actions, cascadeActions } = option;
// 在这里适配宽窄屏处理getTotal,不到运行时处理了 by Xc
// 在这里适配宽窄屏处理getTotal/pagination,不到运行时处理了 by Xc
let getTotal2;
if (getTotal) {
const { width } = this.props;
@ -81,6 +81,16 @@ function onPathSet(option) {
}
}
}
let pagination2;
if (pagination) {
if (pagination instanceof Array) {
const { width } = this.props;
pagination2 = pagination.find(ele => width === 'xs' && ele.deviceWidth === 'mobile' || width !== 'xs' && ele.deviceWidth === 'pc');
}
else {
pagination2 = pagination;
}
}
else {
// 不设置的默认情况宽屏取100窄屏不取
const { width } = this.props;
@ -93,7 +103,7 @@ function onPathSet(option) {
entity: entity2,
isList,
projection: projection2,
pagination: pagination,
pagination: pagination2,
filters: filters2,
sorters: sorters2,
id: oakId,

View File

@ -638,10 +638,12 @@ function createComponent(option, features) {
? Object.assign({}, data, {
oakFullpath: '',
oakLoading: !!option.entity && !!option.projection,
width: 'xs',
})
: {
oakFullpath: '',
oakLoading: !!option.entity && !!option.projection,
width: 'xs',
},
properties: Object.assign({}, translatePropertiesToPropertyDefinitions(properties), OakPropertyTypes),
methods: {

9
lib/types/Page.d.ts vendored
View File

@ -34,11 +34,12 @@ type FeatureDef<IsList extends boolean, ED extends EntityDict & BaseEntityDict,
behavior?: 'reRender' | 'refresh';
callback?: (this: ComponentPublicThisType<ED, T, Cxt, FrontCxt, AD, FD, FormedData, IsList, TData, TProperty, TMethod, EMethod>) => void;
};
type DevideWidth = 'pc' | 'mobile';
interface ComponentOption<IsList extends boolean, ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends AsyncContext<ED>, FrontCxt extends SyncContext<ED>, AD extends Record<string, Aspect<ED, AsyncContext<ED>>>, FD extends Record<string, Feature>, FormedData extends Record<string, any>, TData extends DataOption, TProperty extends DataOption, TMethod extends Record<string, Function>, EMethod extends Record<string, Function> = {}> {
isList?: IsList;
getTotal?: {
max: number;
deviceWidth?: 'pc' | 'mobile' | 'all';
deviceWidth?: DevideWidth | 'all';
} | number;
entity?: T | ((this: ComponentPublicThisType<ED, T, Cxt, FrontCxt, AD, FD, FormedData, IsList, TData, TProperty, TMethod, EMethod>) => T);
path?: string;
@ -49,7 +50,11 @@ interface ComponentOption<IsList extends boolean, ED extends EntityDict & BaseEn
actions?: ActionDef<ED, T>[] | ((this: ComponentPublicThisType<ED, T, Cxt, FrontCxt, AD, FD, FormedData, IsList, TData, TProperty, TMethod, EMethod>) => ActionDef<ED, T>[]);
projection?: ED[T]['Selection']['data'] | ((this: ComponentPublicThisType<ED, T, Cxt, FrontCxt, AD, FD, FormedData, IsList, TData, TProperty, TMethod, EMethod>) => ED[T]['Selection']['data'] | undefined);
append?: boolean;
pagination?: Pick<Pagination, 'currentPage' | 'pageSize' | 'randomRange'>;
pagination?: Pick<Pagination, 'currentPage' | 'pageSize' | 'randomRange'> | [
Pick<Pagination, 'currentPage' | 'pageSize' | 'randomRange'> & {
deviceWidth: DevideWidth;
}
];
filters?: Array<{
filter: NonNullable<ED[T]['Selection']['filter']> | ((this: ComponentPublicThisType<ED, T, Cxt, FrontCxt, AD, FD, FormedData, IsList, TData, TProperty, TMethod, EMethod>) => ED[T]['Selection']['filter'] | undefined);
'#name'?: string;

View File

@ -184,7 +184,7 @@ async function doRoutines<ED extends EntityDict & BaseEntityDict, Cxt extends As
await context.begin();
try {
await context.initialize();
const result = execWatcher(store, routine as Watcher<ED, keyof ED, Cxt>, context);
const result = await execWatcher(store, routine as Watcher<ED, keyof ED, Cxt>, context);
await context.commit();
console.log(`例程【${name}】执行完成,耗时${Date.now() - start}毫秒,结果是`, result);
}

View File

@ -21,6 +21,7 @@ import { judgeRelation } from 'oak-domain/lib/store/relation';
import { combineFilters } from 'oak-domain/lib/store/filter';
import { generateNewId } from 'oak-domain/lib/utils/uuid';
import { Cache } from './features/cache';
import { Pagination } from './types/Pagination';
export function onPathSet<
ED extends EntityDict & BaseEntityDict,
@ -89,7 +90,7 @@ export function onPathSet<
const { actions, cascadeActions } = option;
// 在这里适配宽窄屏处理getTotal,不到运行时处理了 by Xc
// 在这里适配宽窄屏处理getTotal/pagination,不到运行时处理了 by Xc
let getTotal2: undefined | number;
if (getTotal) {
const { width } = this.props;
@ -122,6 +123,16 @@ export function onPathSet<
}
}
}
let pagination2: Pick<Pagination, 'currentPage' | 'pageSize' | 'randomRange'> | undefined;
if (pagination) {
if (pagination instanceof Array) {
const { width } = this.props;
pagination2 = pagination.find(ele => width === 'xs' && ele.deviceWidth === 'mobile' || width !== 'xs' && ele.deviceWidth === 'pc')
}
else {
pagination2 = pagination;
}
}
else {
// 不设置的默认情况宽屏取100窄屏不取
const { width } = this.props;
@ -134,7 +145,7 @@ export function onPathSet<
entity: entity2,
isList,
projection: projection2,
pagination: pagination,
pagination: pagination2,
filters: filters2,
sorters: sorters2,
id: oakId,

View File

@ -921,6 +921,7 @@ export function createComponent<
oakActions?: string;
oakZombie?: boolean;
oakDisablePulldownRefresh?: boolean;
width?: 'xs',
} & Record<string, any>;
features: BasicFeatures<ED> & FD;
oakOption: OakComponentOption<
@ -945,10 +946,12 @@ export function createComponent<
? Object.assign({}, data, {
oakFullpath: '',
oakLoading: !!option.entity && !!option.projection,
width: 'xs',
})
: {
oakFullpath: '',
oakLoading: !!option.entity && !!option.projection,
width: 'xs',
},
properties: Object.assign(
{},

View File

@ -119,6 +119,8 @@ type FeatureDef<
callback?: (this: ComponentPublicThisType<ED, T, Cxt, FrontCxt, AD, FD, FormedData, IsList, TData, TProperty, TMethod, EMethod>) => void;
};
type DevideWidth = 'pc' | 'mobile';
interface ComponentOption<
IsList extends boolean,
ED extends EntityDict & BaseEntityDict,
@ -136,7 +138,7 @@ interface ComponentOption<
isList?: IsList;
getTotal?: {
max: number;
deviceWidth?: 'pc' | 'mobile' | 'all';
deviceWidth?: DevideWidth | 'all';
} | number;
entity?: T | ((this: ComponentPublicThisType<ED, T, Cxt, FrontCxt, AD, FD, FormedData, IsList, TData, TProperty, TMethod, EMethod>) => T);
path?: string;
@ -147,7 +149,9 @@ interface ComponentOption<
actions?: ActionDef<ED, T>[] | ((this: ComponentPublicThisType<ED, T, Cxt, FrontCxt, AD, FD, FormedData, IsList, TData, TProperty, TMethod, EMethod>) => ActionDef<ED, T>[]);
projection?: ED[T]['Selection']['data'] | ((this: ComponentPublicThisType<ED, T, Cxt, FrontCxt, AD, FD, FormedData, IsList, TData, TProperty, TMethod, EMethod>) => ED[T]['Selection']['data'] | undefined);
append?: boolean;
pagination?: Pick<Pagination, 'currentPage' | 'pageSize' | 'randomRange'>;
pagination?: Pick<Pagination, 'currentPage' | 'pageSize' | 'randomRange'> | [
Pick<Pagination, 'currentPage' | 'pageSize' | 'randomRange'> & { deviceWidth: DevideWidth }
];
filters?: Array<{
filter: NonNullable<ED[T]['Selection']['filter']> | ((this: ComponentPublicThisType<ED, T, Cxt, FrontCxt, AD, FD, FormedData, IsList, TData, TProperty, TMethod, EMethod>) => ED[T]['Selection']['filter'] | undefined);
'#name'?: string;