@fairys/taro-tools-react 1.0.8 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/context/page.data.instance.d.ts +15 -15
- package/esm/context/page.info.data.instance.d.ts +10 -10
- package/lib/context/page.data.instance.d.ts +15 -15
- package/lib/context/page.info.data.instance.d.ts +10 -10
- package/package.json +1 -1
- package/src/context/page.data.instance.tsx +35 -25
- package/src/context/page.info.data.instance.tsx +32 -18
|
@@ -112,40 +112,40 @@ export interface PageDataOptions<T extends PageDataInstanceState = PageDataInsta
|
|
|
112
112
|
defaultPageSize?: number;
|
|
113
113
|
}
|
|
114
114
|
/**初始化实例*/
|
|
115
|
-
export declare function usePageDataInstance<T extends PageDataInstanceState = PageDataInstanceState
|
|
115
|
+
export declare function usePageDataInstance<T extends PageDataInstanceState = PageDataInstanceState, M extends PageDataInstance<T> = PageDataInstance<T>>(instance?: M): M;
|
|
116
116
|
/**页面级数据状态管理上下文*/
|
|
117
117
|
export declare const PageDataInstanceContext: import("react").Context<PageDataInstance<PageDataInstanceState>>;
|
|
118
118
|
/**获取上下文实例*/
|
|
119
|
-
export declare const usePageDataInstanceContext: <T extends PageDataInstanceState = PageDataInstanceState>() =>
|
|
120
|
-
export interface PageDataInstanceContextProviderProps<T extends PageDataInstanceState = PageDataInstanceState> extends PageDataOptions<T> {
|
|
121
|
-
instance?:
|
|
119
|
+
export declare const usePageDataInstanceContext: <T extends PageDataInstanceState = PageDataInstanceState, M extends PageDataInstance<T> = PageDataInstance<T>>() => M;
|
|
120
|
+
export interface PageDataInstanceContextProviderProps<T extends PageDataInstanceState = PageDataInstanceState, M extends PageDataInstance<T> = PageDataInstance<T>> extends PageDataOptions<T> {
|
|
121
|
+
instance?: M;
|
|
122
122
|
children: React.ReactNode;
|
|
123
123
|
/**请求之前处理参数*/
|
|
124
|
-
onBefore?:
|
|
124
|
+
onBefore?: M['onBefore'];
|
|
125
125
|
/**请求接口*/
|
|
126
|
-
getList?:
|
|
126
|
+
getList?: M['getList'];
|
|
127
127
|
/**请求之后处理返回值进行存储*/
|
|
128
|
-
onAfter?:
|
|
128
|
+
onAfter?: M['onAfter'];
|
|
129
129
|
/** 额外数据处理*/
|
|
130
|
-
onExtraData?:
|
|
130
|
+
onExtraData?: M['onExtraData'];
|
|
131
131
|
/** code!== 200 时 触发*/
|
|
132
|
-
onError?:
|
|
132
|
+
onError?: M['onError'];
|
|
133
133
|
/**获取弹框内重置参数*/
|
|
134
|
-
getResetValues?:
|
|
134
|
+
getResetValues?: M['getResetValues'];
|
|
135
135
|
/**默认查询参数*/
|
|
136
|
-
defaultQuery?:
|
|
136
|
+
defaultQuery?: M['defaultQuery'];
|
|
137
137
|
/**那些字段取值对象 code值*/
|
|
138
|
-
codeFields?:
|
|
138
|
+
codeFields?: M['codeFields'];
|
|
139
139
|
/**那些字段取值对象的 value 值 */
|
|
140
|
-
valueFields?:
|
|
140
|
+
valueFields?: M['valueFields'];
|
|
141
141
|
/**是否是第一次加载*/
|
|
142
142
|
isMountLoad?: boolean;
|
|
143
143
|
/**页面标题*/
|
|
144
144
|
title?: string;
|
|
145
145
|
}
|
|
146
146
|
/**页面级数据状态管理上下文提供者*/
|
|
147
|
-
export declare function PageDataInstanceContextProvider<T extends PageDataInstanceState = PageDataInstanceState>(props: PageDataInstanceContextProviderProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
147
|
+
export declare function PageDataInstanceContextProvider<T extends PageDataInstanceState = PageDataInstanceState, M extends PageDataInstance<T> = PageDataInstance<T>>(props: PageDataInstanceContextProviderProps<T, M>): import("react/jsx-runtime").JSX.Element;
|
|
148
148
|
/**
|
|
149
149
|
* 页面级数据状态管理
|
|
150
150
|
*/
|
|
151
|
-
export declare const usePageDataInstanceState: <T extends PageDataInstanceState = PageDataInstanceState>() => [T,
|
|
151
|
+
export declare const usePageDataInstanceState: <T extends PageDataInstanceState = PageDataInstanceState, M extends PageDataInstance<T> = PageDataInstance<T>>() => [T, M, string | undefined];
|
|
@@ -59,35 +59,35 @@ export declare class PageInfoDataInstance<T extends PageInfoDataInstanceState =
|
|
|
59
59
|
/**保存数据*/
|
|
60
60
|
main_saveInfo: () => Promise<void>;
|
|
61
61
|
}
|
|
62
|
-
export interface PageInfoDataOptions<T extends PageInfoDataInstanceState = PageInfoDataInstanceState> {
|
|
62
|
+
export interface PageInfoDataOptions<T extends PageInfoDataInstanceState = PageInfoDataInstanceState, M extends PageInfoDataInstance<T> = PageInfoDataInstance<T>> {
|
|
63
63
|
/**详情查询请求配置*/
|
|
64
|
-
requestInfoConfig?:
|
|
64
|
+
requestInfoConfig?: M['requestInfoConfig'];
|
|
65
65
|
/**详情保存请求配置*/
|
|
66
|
-
requestSaveInfoConfig?:
|
|
66
|
+
requestSaveInfoConfig?: M['requestSaveInfoConfig'];
|
|
67
67
|
/**初始值*/
|
|
68
68
|
initialValues?: Partial<T>;
|
|
69
69
|
/**editFormData是否使用valtio proxy 存储*/
|
|
70
70
|
isProxy?: boolean;
|
|
71
71
|
}
|
|
72
72
|
/**初始化实例*/
|
|
73
|
-
export declare const usePageInfoDataInstance: <T extends PageInfoDataInstanceState = PageInfoDataInstanceState
|
|
73
|
+
export declare const usePageInfoDataInstance: <T extends PageInfoDataInstanceState = PageInfoDataInstanceState, M extends PageInfoDataInstance<T> = PageInfoDataInstance<T>>(instance?: M) => M;
|
|
74
74
|
/**页面级数据状态管理上下文*/
|
|
75
75
|
export declare const PageInfoDataInstanceContext: import("react").Context<PageInfoDataInstance<PageInfoDataInstanceState>>;
|
|
76
76
|
/**获取上下文实例*/
|
|
77
|
-
export declare const usePageInfoDataInstanceContext: <T extends PageInfoDataInstanceState = PageInfoDataInstanceState>() =>
|
|
78
|
-
export interface PageInfoDataInstanceContextProviderProps<T extends PageInfoDataInstanceState = PageInfoDataInstanceState> extends PageInfoDataOptions<T> {
|
|
79
|
-
instance?:
|
|
77
|
+
export declare const usePageInfoDataInstanceContext: <T extends PageInfoDataInstanceState = PageInfoDataInstanceState, M extends PageInfoDataInstance<T> = PageInfoDataInstance<T>>() => M;
|
|
78
|
+
export interface PageInfoDataInstanceContextProviderProps<T extends PageInfoDataInstanceState = PageInfoDataInstanceState, M extends PageInfoDataInstance<T> = PageInfoDataInstance<T>> extends PageInfoDataOptions<T, M> {
|
|
79
|
+
instance?: M;
|
|
80
80
|
children: React.ReactNode;
|
|
81
81
|
/**页面标题*/
|
|
82
82
|
title?: string;
|
|
83
83
|
/**页面一加载是否请求详情接口*/
|
|
84
84
|
isMountRequestInfo?: boolean;
|
|
85
85
|
/**自定义hooks,挂载参数和设置完初始值后执行*/
|
|
86
|
-
useHooks?: (instance:
|
|
86
|
+
useHooks?: (instance: M) => void;
|
|
87
87
|
}
|
|
88
88
|
/**页面级数据状态管理上下文提供者*/
|
|
89
|
-
export declare function PageInfoDataInstanceContextProvider<T extends PageInfoDataInstanceState = PageInfoDataInstanceState>(props: PageInfoDataInstanceContextProviderProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
89
|
+
export declare function PageInfoDataInstanceContextProvider<T extends PageInfoDataInstanceState = PageInfoDataInstanceState, M extends PageInfoDataInstance<T> = PageInfoDataInstance<T>>(props: PageInfoDataInstanceContextProviderProps<T, M>): import("react/jsx-runtime").JSX.Element;
|
|
90
90
|
/**
|
|
91
91
|
* 页面级数据状态管理
|
|
92
92
|
*/
|
|
93
|
-
export declare const usePageInfoDataInstanceState: <T extends PageInfoDataInstanceState = PageInfoDataInstanceState>() => [T,
|
|
93
|
+
export declare const usePageInfoDataInstanceState: <T extends PageInfoDataInstanceState = PageInfoDataInstanceState, M extends PageInfoDataInstance<T> = PageInfoDataInstance<T>>() => [T, M, string | undefined];
|
|
@@ -112,40 +112,40 @@ export interface PageDataOptions<T extends PageDataInstanceState = PageDataInsta
|
|
|
112
112
|
defaultPageSize?: number;
|
|
113
113
|
}
|
|
114
114
|
/**初始化实例*/
|
|
115
|
-
export declare function usePageDataInstance<T extends PageDataInstanceState = PageDataInstanceState
|
|
115
|
+
export declare function usePageDataInstance<T extends PageDataInstanceState = PageDataInstanceState, M extends PageDataInstance<T> = PageDataInstance<T>>(instance?: M): M;
|
|
116
116
|
/**页面级数据状态管理上下文*/
|
|
117
117
|
export declare const PageDataInstanceContext: import("react").Context<PageDataInstance<PageDataInstanceState>>;
|
|
118
118
|
/**获取上下文实例*/
|
|
119
|
-
export declare const usePageDataInstanceContext: <T extends PageDataInstanceState = PageDataInstanceState>() =>
|
|
120
|
-
export interface PageDataInstanceContextProviderProps<T extends PageDataInstanceState = PageDataInstanceState> extends PageDataOptions<T> {
|
|
121
|
-
instance?:
|
|
119
|
+
export declare const usePageDataInstanceContext: <T extends PageDataInstanceState = PageDataInstanceState, M extends PageDataInstance<T> = PageDataInstance<T>>() => M;
|
|
120
|
+
export interface PageDataInstanceContextProviderProps<T extends PageDataInstanceState = PageDataInstanceState, M extends PageDataInstance<T> = PageDataInstance<T>> extends PageDataOptions<T> {
|
|
121
|
+
instance?: M;
|
|
122
122
|
children: React.ReactNode;
|
|
123
123
|
/**请求之前处理参数*/
|
|
124
|
-
onBefore?:
|
|
124
|
+
onBefore?: M['onBefore'];
|
|
125
125
|
/**请求接口*/
|
|
126
|
-
getList?:
|
|
126
|
+
getList?: M['getList'];
|
|
127
127
|
/**请求之后处理返回值进行存储*/
|
|
128
|
-
onAfter?:
|
|
128
|
+
onAfter?: M['onAfter'];
|
|
129
129
|
/** 额外数据处理*/
|
|
130
|
-
onExtraData?:
|
|
130
|
+
onExtraData?: M['onExtraData'];
|
|
131
131
|
/** code!== 200 时 触发*/
|
|
132
|
-
onError?:
|
|
132
|
+
onError?: M['onError'];
|
|
133
133
|
/**获取弹框内重置参数*/
|
|
134
|
-
getResetValues?:
|
|
134
|
+
getResetValues?: M['getResetValues'];
|
|
135
135
|
/**默认查询参数*/
|
|
136
|
-
defaultQuery?:
|
|
136
|
+
defaultQuery?: M['defaultQuery'];
|
|
137
137
|
/**那些字段取值对象 code值*/
|
|
138
|
-
codeFields?:
|
|
138
|
+
codeFields?: M['codeFields'];
|
|
139
139
|
/**那些字段取值对象的 value 值 */
|
|
140
|
-
valueFields?:
|
|
140
|
+
valueFields?: M['valueFields'];
|
|
141
141
|
/**是否是第一次加载*/
|
|
142
142
|
isMountLoad?: boolean;
|
|
143
143
|
/**页面标题*/
|
|
144
144
|
title?: string;
|
|
145
145
|
}
|
|
146
146
|
/**页面级数据状态管理上下文提供者*/
|
|
147
|
-
export declare function PageDataInstanceContextProvider<T extends PageDataInstanceState = PageDataInstanceState>(props: PageDataInstanceContextProviderProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
147
|
+
export declare function PageDataInstanceContextProvider<T extends PageDataInstanceState = PageDataInstanceState, M extends PageDataInstance<T> = PageDataInstance<T>>(props: PageDataInstanceContextProviderProps<T, M>): import("react/jsx-runtime").JSX.Element;
|
|
148
148
|
/**
|
|
149
149
|
* 页面级数据状态管理
|
|
150
150
|
*/
|
|
151
|
-
export declare const usePageDataInstanceState: <T extends PageDataInstanceState = PageDataInstanceState>() => [T,
|
|
151
|
+
export declare const usePageDataInstanceState: <T extends PageDataInstanceState = PageDataInstanceState, M extends PageDataInstance<T> = PageDataInstance<T>>() => [T, M, string | undefined];
|
|
@@ -59,35 +59,35 @@ export declare class PageInfoDataInstance<T extends PageInfoDataInstanceState =
|
|
|
59
59
|
/**保存数据*/
|
|
60
60
|
main_saveInfo: () => Promise<void>;
|
|
61
61
|
}
|
|
62
|
-
export interface PageInfoDataOptions<T extends PageInfoDataInstanceState = PageInfoDataInstanceState> {
|
|
62
|
+
export interface PageInfoDataOptions<T extends PageInfoDataInstanceState = PageInfoDataInstanceState, M extends PageInfoDataInstance<T> = PageInfoDataInstance<T>> {
|
|
63
63
|
/**详情查询请求配置*/
|
|
64
|
-
requestInfoConfig?:
|
|
64
|
+
requestInfoConfig?: M['requestInfoConfig'];
|
|
65
65
|
/**详情保存请求配置*/
|
|
66
|
-
requestSaveInfoConfig?:
|
|
66
|
+
requestSaveInfoConfig?: M['requestSaveInfoConfig'];
|
|
67
67
|
/**初始值*/
|
|
68
68
|
initialValues?: Partial<T>;
|
|
69
69
|
/**editFormData是否使用valtio proxy 存储*/
|
|
70
70
|
isProxy?: boolean;
|
|
71
71
|
}
|
|
72
72
|
/**初始化实例*/
|
|
73
|
-
export declare const usePageInfoDataInstance: <T extends PageInfoDataInstanceState = PageInfoDataInstanceState
|
|
73
|
+
export declare const usePageInfoDataInstance: <T extends PageInfoDataInstanceState = PageInfoDataInstanceState, M extends PageInfoDataInstance<T> = PageInfoDataInstance<T>>(instance?: M) => M;
|
|
74
74
|
/**页面级数据状态管理上下文*/
|
|
75
75
|
export declare const PageInfoDataInstanceContext: import("react").Context<PageInfoDataInstance<PageInfoDataInstanceState>>;
|
|
76
76
|
/**获取上下文实例*/
|
|
77
|
-
export declare const usePageInfoDataInstanceContext: <T extends PageInfoDataInstanceState = PageInfoDataInstanceState>() =>
|
|
78
|
-
export interface PageInfoDataInstanceContextProviderProps<T extends PageInfoDataInstanceState = PageInfoDataInstanceState> extends PageInfoDataOptions<T> {
|
|
79
|
-
instance?:
|
|
77
|
+
export declare const usePageInfoDataInstanceContext: <T extends PageInfoDataInstanceState = PageInfoDataInstanceState, M extends PageInfoDataInstance<T> = PageInfoDataInstance<T>>() => M;
|
|
78
|
+
export interface PageInfoDataInstanceContextProviderProps<T extends PageInfoDataInstanceState = PageInfoDataInstanceState, M extends PageInfoDataInstance<T> = PageInfoDataInstance<T>> extends PageInfoDataOptions<T, M> {
|
|
79
|
+
instance?: M;
|
|
80
80
|
children: React.ReactNode;
|
|
81
81
|
/**页面标题*/
|
|
82
82
|
title?: string;
|
|
83
83
|
/**页面一加载是否请求详情接口*/
|
|
84
84
|
isMountRequestInfo?: boolean;
|
|
85
85
|
/**自定义hooks,挂载参数和设置完初始值后执行*/
|
|
86
|
-
useHooks?: (instance:
|
|
86
|
+
useHooks?: (instance: M) => void;
|
|
87
87
|
}
|
|
88
88
|
/**页面级数据状态管理上下文提供者*/
|
|
89
|
-
export declare function PageInfoDataInstanceContextProvider<T extends PageInfoDataInstanceState = PageInfoDataInstanceState>(props: PageInfoDataInstanceContextProviderProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
89
|
+
export declare function PageInfoDataInstanceContextProvider<T extends PageInfoDataInstanceState = PageInfoDataInstanceState, M extends PageInfoDataInstance<T> = PageInfoDataInstance<T>>(props: PageInfoDataInstanceContextProviderProps<T, M>): import("react/jsx-runtime").JSX.Element;
|
|
90
90
|
/**
|
|
91
91
|
* 页面级数据状态管理
|
|
92
92
|
*/
|
|
93
|
-
export declare const usePageInfoDataInstanceState: <T extends PageInfoDataInstanceState = PageInfoDataInstanceState>() => [T,
|
|
93
|
+
export declare const usePageInfoDataInstanceState: <T extends PageInfoDataInstanceState = PageInfoDataInstanceState, M extends PageInfoDataInstance<T> = PageInfoDataInstance<T>>() => [T, M, string | undefined];
|
package/package.json
CHANGED
|
@@ -373,12 +373,13 @@ export interface PageDataOptions<T extends PageDataInstanceState = PageDataInsta
|
|
|
373
373
|
}
|
|
374
374
|
|
|
375
375
|
/**初始化实例*/
|
|
376
|
-
export function usePageDataInstance<
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
376
|
+
export function usePageDataInstance<
|
|
377
|
+
T extends PageDataInstanceState = PageDataInstanceState,
|
|
378
|
+
M extends PageDataInstance<T> = PageDataInstance<T>,
|
|
379
|
+
>(instance?: M) {
|
|
380
|
+
const ref = useRef<M>();
|
|
380
381
|
if (!ref.current) {
|
|
381
|
-
ref.current = instance || new PageDataInstance<T>();
|
|
382
|
+
ref.current = instance || (new PageDataInstance<T>() as M);
|
|
382
383
|
}
|
|
383
384
|
return ref.current;
|
|
384
385
|
}
|
|
@@ -387,33 +388,38 @@ export function usePageDataInstance<T extends PageDataInstanceState = PageDataIn
|
|
|
387
388
|
export const PageDataInstanceContext = createContext<PageDataInstance>(new PageDataInstance());
|
|
388
389
|
|
|
389
390
|
/**获取上下文实例*/
|
|
390
|
-
export const usePageDataInstanceContext = <
|
|
391
|
-
|
|
391
|
+
export const usePageDataInstanceContext = <
|
|
392
|
+
T extends PageDataInstanceState = PageDataInstanceState,
|
|
393
|
+
M extends PageDataInstance<T> = PageDataInstance<T>,
|
|
394
|
+
>() => {
|
|
395
|
+
const PageDataInstance = useContext(PageDataInstanceContext) as M;
|
|
392
396
|
return PageDataInstance;
|
|
393
397
|
};
|
|
394
398
|
|
|
395
|
-
export interface PageDataInstanceContextProviderProps<
|
|
396
|
-
extends
|
|
397
|
-
|
|
399
|
+
export interface PageDataInstanceContextProviderProps<
|
|
400
|
+
T extends PageDataInstanceState = PageDataInstanceState,
|
|
401
|
+
M extends PageDataInstance<T> = PageDataInstance<T>,
|
|
402
|
+
> extends PageDataOptions<T> {
|
|
403
|
+
instance?: M;
|
|
398
404
|
children: React.ReactNode;
|
|
399
405
|
/**请求之前处理参数*/
|
|
400
|
-
onBefore?:
|
|
406
|
+
onBefore?: M['onBefore'];
|
|
401
407
|
/**请求接口*/
|
|
402
|
-
getList?:
|
|
408
|
+
getList?: M['getList'];
|
|
403
409
|
/**请求之后处理返回值进行存储*/
|
|
404
|
-
onAfter?:
|
|
410
|
+
onAfter?: M['onAfter'];
|
|
405
411
|
/** 额外数据处理*/
|
|
406
|
-
onExtraData?:
|
|
412
|
+
onExtraData?: M['onExtraData'];
|
|
407
413
|
/** code!== 200 时 触发*/
|
|
408
|
-
onError?:
|
|
414
|
+
onError?: M['onError'];
|
|
409
415
|
/**获取弹框内重置参数*/
|
|
410
|
-
getResetValues?:
|
|
416
|
+
getResetValues?: M['getResetValues'];
|
|
411
417
|
/**默认查询参数*/
|
|
412
|
-
defaultQuery?:
|
|
418
|
+
defaultQuery?: M['defaultQuery'];
|
|
413
419
|
/**那些字段取值对象 code值*/
|
|
414
|
-
codeFields?:
|
|
420
|
+
codeFields?: M['codeFields'];
|
|
415
421
|
/**那些字段取值对象的 value 值 */
|
|
416
|
-
valueFields?:
|
|
422
|
+
valueFields?: M['valueFields'];
|
|
417
423
|
/**是否是第一次加载*/
|
|
418
424
|
isMountLoad?: boolean;
|
|
419
425
|
/**页面标题*/
|
|
@@ -421,9 +427,10 @@ export interface PageDataInstanceContextProviderProps<T extends PageDataInstance
|
|
|
421
427
|
}
|
|
422
428
|
|
|
423
429
|
/**页面级数据状态管理上下文提供者*/
|
|
424
|
-
export function PageDataInstanceContextProvider<
|
|
425
|
-
|
|
426
|
-
|
|
430
|
+
export function PageDataInstanceContextProvider<
|
|
431
|
+
T extends PageDataInstanceState = PageDataInstanceState,
|
|
432
|
+
M extends PageDataInstance<T> = PageDataInstance<T>,
|
|
433
|
+
>(props: PageDataInstanceContextProviderProps<T, M>) {
|
|
427
434
|
const {
|
|
428
435
|
instance,
|
|
429
436
|
children,
|
|
@@ -481,8 +488,11 @@ export function PageDataInstanceContextProvider<T extends PageDataInstanceState
|
|
|
481
488
|
/**
|
|
482
489
|
* 页面级数据状态管理
|
|
483
490
|
*/
|
|
484
|
-
export const usePageDataInstanceState = <
|
|
485
|
-
|
|
491
|
+
export const usePageDataInstanceState = <
|
|
492
|
+
T extends PageDataInstanceState = PageDataInstanceState,
|
|
493
|
+
M extends PageDataInstance<T> = PageDataInstance<T>,
|
|
494
|
+
>() => {
|
|
495
|
+
const PageMainDataInstance = usePageDataInstanceContext<T, M>();
|
|
486
496
|
const store = useSnapshot(PageMainDataInstance.store, { sync: true }) as T;
|
|
487
|
-
return [store, PageMainDataInstance, store.__defaultValue] as [T,
|
|
497
|
+
return [store, PageMainDataInstance, store.__defaultValue] as [T, M, string | undefined];
|
|
488
498
|
};
|
|
@@ -176,11 +176,14 @@ export class PageInfoDataInstance<
|
|
|
176
176
|
};
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
export interface PageInfoDataOptions<
|
|
179
|
+
export interface PageInfoDataOptions<
|
|
180
|
+
T extends PageInfoDataInstanceState = PageInfoDataInstanceState,
|
|
181
|
+
M extends PageInfoDataInstance<T> = PageInfoDataInstance<T>,
|
|
182
|
+
> {
|
|
180
183
|
/**详情查询请求配置*/
|
|
181
|
-
requestInfoConfig?:
|
|
184
|
+
requestInfoConfig?: M['requestInfoConfig'];
|
|
182
185
|
/**详情保存请求配置*/
|
|
183
|
-
requestSaveInfoConfig?:
|
|
186
|
+
requestSaveInfoConfig?: M['requestSaveInfoConfig'];
|
|
184
187
|
/**初始值*/
|
|
185
188
|
initialValues?: Partial<T>;
|
|
186
189
|
/**editFormData是否使用valtio proxy 存储*/
|
|
@@ -188,15 +191,18 @@ export interface PageInfoDataOptions<T extends PageInfoDataInstanceState = PageI
|
|
|
188
191
|
}
|
|
189
192
|
|
|
190
193
|
/**初始化实例*/
|
|
191
|
-
export const usePageInfoDataInstance = <
|
|
192
|
-
|
|
194
|
+
export const usePageInfoDataInstance = <
|
|
195
|
+
T extends PageInfoDataInstanceState = PageInfoDataInstanceState,
|
|
196
|
+
M extends PageInfoDataInstance<T> = PageInfoDataInstance<T>,
|
|
197
|
+
>(
|
|
198
|
+
instance?: M,
|
|
193
199
|
) => {
|
|
194
|
-
const ref = useRef<
|
|
200
|
+
const ref = useRef<M>();
|
|
195
201
|
if (!ref.current) {
|
|
196
202
|
if (instance) {
|
|
197
203
|
ref.current = instance;
|
|
198
204
|
} else {
|
|
199
|
-
ref.current = new PageInfoDataInstance<T>();
|
|
205
|
+
ref.current = new PageInfoDataInstance<T>() as M;
|
|
200
206
|
}
|
|
201
207
|
}
|
|
202
208
|
return ref.current;
|
|
@@ -206,28 +212,33 @@ export const usePageInfoDataInstance = <T extends PageInfoDataInstanceState = Pa
|
|
|
206
212
|
export const PageInfoDataInstanceContext = createContext<PageInfoDataInstance>(new PageInfoDataInstance());
|
|
207
213
|
|
|
208
214
|
/**获取上下文实例*/
|
|
209
|
-
export const usePageInfoDataInstanceContext = <
|
|
210
|
-
|
|
215
|
+
export const usePageInfoDataInstanceContext = <
|
|
216
|
+
T extends PageInfoDataInstanceState = PageInfoDataInstanceState,
|
|
217
|
+
M extends PageInfoDataInstance<T> = PageInfoDataInstance<T>,
|
|
218
|
+
>() => {
|
|
219
|
+
const PageInfoDataInstance = useContext(PageInfoDataInstanceContext) as M;
|
|
211
220
|
return PageInfoDataInstance;
|
|
212
221
|
};
|
|
213
222
|
|
|
214
223
|
export interface PageInfoDataInstanceContextProviderProps<
|
|
215
224
|
T extends PageInfoDataInstanceState = PageInfoDataInstanceState,
|
|
216
|
-
|
|
217
|
-
|
|
225
|
+
M extends PageInfoDataInstance<T> = PageInfoDataInstance<T>,
|
|
226
|
+
> extends PageInfoDataOptions<T, M> {
|
|
227
|
+
instance?: M;
|
|
218
228
|
children: React.ReactNode;
|
|
219
229
|
/**页面标题*/
|
|
220
230
|
title?: string;
|
|
221
231
|
/**页面一加载是否请求详情接口*/
|
|
222
232
|
isMountRequestInfo?: boolean;
|
|
223
233
|
/**自定义hooks,挂载参数和设置完初始值后执行*/
|
|
224
|
-
useHooks?: (instance:
|
|
234
|
+
useHooks?: (instance: M) => void;
|
|
225
235
|
}
|
|
226
236
|
|
|
227
237
|
/**页面级数据状态管理上下文提供者*/
|
|
228
|
-
export function PageInfoDataInstanceContextProvider<
|
|
229
|
-
|
|
230
|
-
|
|
238
|
+
export function PageInfoDataInstanceContextProvider<
|
|
239
|
+
T extends PageInfoDataInstanceState = PageInfoDataInstanceState,
|
|
240
|
+
M extends PageInfoDataInstance<T> = PageInfoDataInstance<T>,
|
|
241
|
+
>(props: PageInfoDataInstanceContextProviderProps<T, M>) {
|
|
231
242
|
const {
|
|
232
243
|
instance,
|
|
233
244
|
children,
|
|
@@ -268,8 +279,11 @@ export function PageInfoDataInstanceContextProvider<T extends PageInfoDataInstan
|
|
|
268
279
|
/**
|
|
269
280
|
* 页面级数据状态管理
|
|
270
281
|
*/
|
|
271
|
-
export const usePageInfoDataInstanceState = <
|
|
272
|
-
|
|
282
|
+
export const usePageInfoDataInstanceState = <
|
|
283
|
+
T extends PageInfoDataInstanceState = PageInfoDataInstanceState,
|
|
284
|
+
M extends PageInfoDataInstance<T> = PageInfoDataInstance<T>,
|
|
285
|
+
>() => {
|
|
286
|
+
const PageInfoDataInstance = usePageInfoDataInstanceContext<T, M>();
|
|
273
287
|
const store = useSnapshot(PageInfoDataInstance.store, { sync: true }) as T;
|
|
274
|
-
return [store, PageInfoDataInstance, store.__defaultValue] as [T,
|
|
288
|
+
return [store, PageInfoDataInstance, store.__defaultValue] as [T, M, string | undefined];
|
|
275
289
|
};
|