@fairys/taro-tools-react 0.0.8 → 0.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 +95 -19
- package/esm/context/page.data.instance.js +213 -42
- package/esm/context/page.info.data.instance.d.ts +31 -10
- package/esm/context/page.info.data.instance.js +82 -23
- package/esm/utils/valtio/instance.d.ts +2 -0
- package/esm/utils/valtio/instance.js +2 -0
- package/package.json +1 -1
- package/src/context/page.data.instance.tsx +477 -0
- package/src/context/page.info.data.instance.tsx +274 -0
- package/src/utils/valtio/instance.ts +4 -2
- package/src/context/page.data.instance.ts +0 -215
- package/src/context/page.info.data.instance.ts +0 -182
|
@@ -6,6 +6,8 @@ export interface PageDataInstanceState extends Object {
|
|
|
6
6
|
page?: number;
|
|
7
7
|
/**分页数*/
|
|
8
8
|
pageSize?: number;
|
|
9
|
+
/**默认分页数*/
|
|
10
|
+
defaultPageSize?: number;
|
|
9
11
|
/**总数*/
|
|
10
12
|
total?: number;
|
|
11
13
|
/**是否最后一页*/
|
|
@@ -17,55 +19,129 @@ export interface PageDataInstanceState extends Object {
|
|
|
17
19
|
/**选择行数据*/
|
|
18
20
|
selectedRows?: any[];
|
|
19
21
|
selectedRowKeys?: any[];
|
|
22
|
+
/**一下是tab多页签使用*/
|
|
23
|
+
tabKey?: string;
|
|
24
|
+
/**tab多页签配置*/
|
|
25
|
+
tabItems?: {
|
|
26
|
+
/**tab页签key*/
|
|
27
|
+
key: string;
|
|
28
|
+
/**tab页签显示名称*/
|
|
29
|
+
label: string;
|
|
30
|
+
/**tab页签接口*/
|
|
31
|
+
api?: (payload: any, tabKey: string, instance: PageDataInstance) => Promise<{
|
|
32
|
+
code?: number;
|
|
33
|
+
data?: any;
|
|
34
|
+
message?: string;
|
|
35
|
+
}>;
|
|
36
|
+
/**tab页签默认查询参数*/
|
|
37
|
+
query?: Record<string, any>;
|
|
38
|
+
[s: string]: any;
|
|
39
|
+
}[];
|
|
40
|
+
/**是否是tab多页签*/
|
|
41
|
+
isTabs?: boolean;
|
|
42
|
+
/**是否展开查询条件*/
|
|
43
|
+
expandSearch?: boolean;
|
|
20
44
|
/**数据默认值不使用*/
|
|
21
45
|
__defaultValue?: string;
|
|
22
46
|
[s: string]: any;
|
|
23
47
|
}
|
|
24
48
|
export declare class PageDataInstance<T extends PageDataInstanceState = PageDataInstanceState> extends ProxyInstanceObjectBase<T> {
|
|
49
|
+
/**不使用ref存储的字段*/
|
|
50
|
+
notRefFields: string[];
|
|
51
|
+
/**请求之前处理参数*/
|
|
52
|
+
onBefore?: (payload: any, store: T, instance: PageDataInstance<T>) => Partial<T>;
|
|
53
|
+
/**请求接口*/
|
|
54
|
+
getList?: (payload: any, instance: PageDataInstance<T>) => Promise<{
|
|
55
|
+
code?: number;
|
|
56
|
+
data?: any;
|
|
57
|
+
message?: string;
|
|
58
|
+
}>;
|
|
59
|
+
/**请求之后处理返回值进行存储*/
|
|
60
|
+
onAfter?: (data: Record<string, any>, instance: PageDataInstance<T>) => Partial<T>;
|
|
61
|
+
/** code!==1 时 触发*/
|
|
62
|
+
onError?: (data: Record<string, any>, instance: PageDataInstance<T>) => void;
|
|
63
|
+
/**重置获取值的方法*/
|
|
64
|
+
getResetValues?: (instance: PageDataInstance<T>) => Record<string, any>;
|
|
65
|
+
/**默认查询参数*/
|
|
66
|
+
defaultQuery?: Record<string, any>;
|
|
67
|
+
/**那些字段取值对象 code值*/
|
|
68
|
+
codeFields?: string[];
|
|
69
|
+
/**那些字段取值对象的 value 值 */
|
|
70
|
+
valueFields?: string[];
|
|
25
71
|
/**是否滚动加载分页*/
|
|
26
72
|
is_scroll_page: boolean;
|
|
27
73
|
/**默认值*/
|
|
28
74
|
defaultInital: T;
|
|
29
|
-
requestConfig?: {
|
|
30
|
-
/**请求之前处理参数*/
|
|
31
|
-
onBefore?: (payload: any, store: T) => Partial<T>;
|
|
32
|
-
/**请求接口*/
|
|
33
|
-
getList?: (payload: any) => Promise<{
|
|
34
|
-
code?: number;
|
|
35
|
-
data?: any;
|
|
36
|
-
message?: string;
|
|
37
|
-
}>;
|
|
38
|
-
/**请求之后处理返回值进行存储*/
|
|
39
|
-
onAfter?: (data: Record<string, any>) => Partial<T>;
|
|
40
|
-
/** code!==1 时 触发*/
|
|
41
|
-
onError?: (data: Record<string, any>) => void;
|
|
42
|
-
};
|
|
43
|
-
constructor(options?: PageDataOptions<T>);
|
|
44
75
|
store: T;
|
|
76
|
+
ctor: (options?: PageDataOptions<T>) => void;
|
|
45
77
|
/**初始化状态值*/
|
|
46
78
|
main_page_store: (initalValues?: Partial<T>, file?: string[]) => this;
|
|
79
|
+
/**格式化请求参数*/
|
|
80
|
+
formateParams: (params: Record<string, any>) => {};
|
|
81
|
+
/**更新查询条件*/
|
|
82
|
+
updatedSearch: (value?: Record<string, any>) => void;
|
|
47
83
|
/**更新页面级的 pageLoading */
|
|
48
|
-
|
|
84
|
+
updatedPageLoading: (loading?: boolean) => void;
|
|
85
|
+
/**更新页面级的 loadMore */
|
|
86
|
+
updatedLoading: (value: Record<string, boolean>) => void;
|
|
49
87
|
/**内置——查询列表*/
|
|
50
88
|
main_getList: () => Promise<void>;
|
|
51
89
|
/**内置——翻页*/
|
|
52
90
|
main_onPageChange: (page: number) => void;
|
|
53
91
|
/**内置——翻页切换*/
|
|
54
92
|
main_onShowSizeChange: (_: number, pageSize: number) => void;
|
|
93
|
+
/**弹框内字段重置,如果没有获取字段值的方法,则直接清理所有字段值*/
|
|
94
|
+
main_onReset: () => void;
|
|
55
95
|
/**内置——查询方法*/
|
|
56
96
|
main_onSearch: () => void;
|
|
57
97
|
/**加载更多*/
|
|
58
98
|
main_onLoadMore: () => void;
|
|
59
99
|
}
|
|
60
100
|
export interface PageDataOptions<T extends PageDataInstanceState = PageDataInstanceState> {
|
|
61
|
-
/**请求配置*/
|
|
62
|
-
requestConfig?: PageDataInstance<T>['requestConfig'];
|
|
63
101
|
/**初始值*/
|
|
64
102
|
initialValues?: Partial<T>;
|
|
65
103
|
/**是否滚动加载更多*/
|
|
66
104
|
is_scroll_page?: boolean;
|
|
105
|
+
/**默认tab key*/
|
|
106
|
+
defaultTabKey?: string;
|
|
107
|
+
/**tab多页签配置*/
|
|
108
|
+
tabItems?: PageDataInstanceState['tabItems'];
|
|
109
|
+
/**默认分页数*/
|
|
110
|
+
defaultPageSize?: number;
|
|
111
|
+
}
|
|
112
|
+
/**初始化实例*/
|
|
113
|
+
export declare function usePageDataInstance<T extends PageDataInstanceState = PageDataInstanceState>(instance?: PageDataInstance<T>): PageDataInstance<T>;
|
|
114
|
+
/**页面级数据状态管理上下文*/
|
|
115
|
+
export declare const PageDataInstanceContext: import("react").Context<PageDataInstance<PageDataInstanceState>>;
|
|
116
|
+
/**获取上下文实例*/
|
|
117
|
+
export declare const usePageDataInstanceContext: <T extends PageDataInstanceState = PageDataInstanceState>() => PageDataInstance<T>;
|
|
118
|
+
export interface PageDataInstanceContextProviderProps<T extends PageDataInstanceState = PageDataInstanceState> extends PageDataOptions<T> {
|
|
119
|
+
instance?: PageDataInstance<T>;
|
|
120
|
+
children: React.ReactNode;
|
|
121
|
+
/**请求之前处理参数*/
|
|
122
|
+
onBefore?: PageDataInstance<T>['onBefore'];
|
|
123
|
+
/**请求接口*/
|
|
124
|
+
getList?: PageDataInstance<T>['getList'];
|
|
125
|
+
/**请求之后处理返回值进行存储*/
|
|
126
|
+
onAfter?: PageDataInstance<T>['onAfter'];
|
|
127
|
+
/** code!== 200 时 触发*/
|
|
128
|
+
onError?: PageDataInstance<T>['onError'];
|
|
129
|
+
/**获取弹框内重置参数*/
|
|
130
|
+
getResetValues?: PageDataInstance<T>['getResetValues'];
|
|
131
|
+
/**默认查询参数*/
|
|
132
|
+
defaultQuery?: PageDataInstance<T>['defaultQuery'];
|
|
133
|
+
/**那些字段取值对象 code值*/
|
|
134
|
+
codeFields?: PageDataInstance<T>['codeFields'];
|
|
135
|
+
/**那些字段取值对象的 value 值 */
|
|
136
|
+
valueFields?: PageDataInstance<T>['valueFields'];
|
|
137
|
+
/**是否是第一次加载*/
|
|
138
|
+
isMountLoad?: boolean;
|
|
139
|
+
/**页面标题*/
|
|
140
|
+
title?: string;
|
|
67
141
|
}
|
|
142
|
+
/**页面级数据状态管理上下文提供者*/
|
|
143
|
+
export declare function PageDataInstanceContextProvider<T extends PageDataInstanceState = PageDataInstanceState>(props: PageDataInstanceContextProviderProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
68
144
|
/**
|
|
69
145
|
* 页面级数据状态管理
|
|
70
146
|
*/
|
|
71
|
-
export declare const
|
|
147
|
+
export declare const usePageDataInstanceState: <T extends PageDataInstanceState = PageDataInstanceState>() => [T, PageDataInstance<T>, string | undefined];
|
|
@@ -1,32 +1,49 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { proxy, ref as external_valtio_ref, useSnapshot } from "valtio";
|
|
2
3
|
import { ProxyInstanceObjectBase } from "../utils/valtio/instance.js";
|
|
3
|
-
import { useRef } from "react";
|
|
4
|
+
import { createContext, useContext, useMemo, useRef } from "react";
|
|
4
5
|
import { globalSettingDataInstance } from "./global.setting.data.instance.js";
|
|
5
|
-
|
|
6
|
+
import taro, { useDidShow } from "@tarojs/taro";
|
|
7
|
+
class page_data_instance_PageDataInstance extends ProxyInstanceObjectBase {
|
|
8
|
+
notRefFields = [
|
|
9
|
+
'search',
|
|
10
|
+
'loading'
|
|
11
|
+
];
|
|
12
|
+
onBefore;
|
|
13
|
+
getList;
|
|
14
|
+
onAfter;
|
|
15
|
+
onError;
|
|
16
|
+
getResetValues;
|
|
17
|
+
defaultQuery = {};
|
|
18
|
+
codeFields = [];
|
|
19
|
+
valueFields = [];
|
|
6
20
|
is_scroll_page = true;
|
|
7
21
|
defaultInital = {
|
|
8
22
|
page: 1,
|
|
9
23
|
pageSize: 10,
|
|
10
24
|
total: 0,
|
|
11
|
-
search:
|
|
12
|
-
dataList:
|
|
13
|
-
selectedRows:
|
|
14
|
-
selectedRowKeys:
|
|
25
|
+
search: {},
|
|
26
|
+
dataList: external_valtio_ref([]),
|
|
27
|
+
selectedRows: external_valtio_ref([]),
|
|
28
|
+
selectedRowKeys: external_valtio_ref([]),
|
|
15
29
|
loading: {
|
|
16
30
|
pageLoading: false
|
|
17
31
|
},
|
|
18
32
|
hasLastPage: false
|
|
19
33
|
};
|
|
20
|
-
requestConfig = {};
|
|
21
|
-
constructor(options){
|
|
22
|
-
super();
|
|
23
|
-
if (options?.initialValues) this.main_page_store(options.initialValues);
|
|
24
|
-
if (options.requestConfig) this.requestConfig = options.requestConfig || {};
|
|
25
|
-
if (options?.is_scroll_page !== void 0) this.is_scroll_page = options?.is_scroll_page;
|
|
26
|
-
}
|
|
27
34
|
store = proxy({
|
|
28
35
|
...this.defaultInital
|
|
29
36
|
});
|
|
37
|
+
ctor = (options)=>{
|
|
38
|
+
if (options?.initialValues) this.main_page_store(options.initialValues);
|
|
39
|
+
if (options.defaultPageSize) this.store.defaultPageSize = options.defaultPageSize;
|
|
40
|
+
if (options?.is_scroll_page !== void 0) this.is_scroll_page = options?.is_scroll_page;
|
|
41
|
+
if (options?.defaultTabKey) this.store.tabKey = options.defaultTabKey;
|
|
42
|
+
if (options?.tabItems) {
|
|
43
|
+
this.store.tabItems = external_valtio_ref(options.tabItems);
|
|
44
|
+
this.store.isTabs = Array.isArray(options.tabItems) && options.tabItems.length > 0;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
30
47
|
main_page_store = (initalValues = {}, file)=>{
|
|
31
48
|
const newStore = {
|
|
32
49
|
...this.defaultInital,
|
|
@@ -37,77 +54,186 @@ class PageDataInstance extends ProxyInstanceObjectBase {
|
|
|
37
54
|
'loading'
|
|
38
55
|
]);
|
|
39
56
|
};
|
|
40
|
-
|
|
57
|
+
formateParams = (params)=>{
|
|
58
|
+
const _query = {};
|
|
59
|
+
const keys = Object.keys(params);
|
|
60
|
+
for(let index = 0; index < keys.length; index++){
|
|
61
|
+
const key = keys[index];
|
|
62
|
+
if ((this.valueFields || []).includes(key)) _query[key] = params[key]?.value;
|
|
63
|
+
else if ((this.codeFields || []).includes(key)) _query[key] = params[key]?.code;
|
|
64
|
+
else _query[key] = params[key];
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
..._query
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
updatedSearch = (value = {})=>{
|
|
71
|
+
const keys = Object.keys(value);
|
|
72
|
+
if (!this.store.search) this.store.search = {};
|
|
73
|
+
for(let index = 0; index < keys.length; index++){
|
|
74
|
+
const key = keys[index];
|
|
75
|
+
this.store.search[key] = value[key];
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
updatedPageLoading = (loading = true)=>{
|
|
41
79
|
if ('object' == typeof this.store?.loading) this.store.loading.pageLoading = loading;
|
|
42
80
|
else this.store.loading = {
|
|
43
81
|
pageLoading: loading
|
|
44
82
|
};
|
|
45
83
|
};
|
|
84
|
+
updatedLoading = (value)=>{
|
|
85
|
+
if ('object' == typeof this.store?.loading) this.store.loading = {
|
|
86
|
+
...this.store.loading,
|
|
87
|
+
...value
|
|
88
|
+
};
|
|
89
|
+
else this.store.loading = {
|
|
90
|
+
...value
|
|
91
|
+
};
|
|
92
|
+
};
|
|
46
93
|
main_getList = async ()=>{
|
|
47
|
-
|
|
94
|
+
let pageField = 'page';
|
|
95
|
+
let pageSizeField = 'pageSize';
|
|
96
|
+
let dataListField = 'dataList';
|
|
97
|
+
let totalField = 'total';
|
|
98
|
+
let selectedRowsField = 'selectedRows';
|
|
99
|
+
let selectedRowKeysField = 'selectedRowKeys';
|
|
100
|
+
let _request;
|
|
101
|
+
let defaultQuery = {};
|
|
102
|
+
if (this.store.isTabs) {
|
|
103
|
+
const tabKey = this.store.tabKey;
|
|
104
|
+
const findTab = this.store.tabItems?.find((item)=>item.key === tabKey);
|
|
105
|
+
if (findTab?.api) _request = findTab.api;
|
|
106
|
+
defaultQuery = findTab?.query || {};
|
|
107
|
+
pageField = `${tabKey}Page`;
|
|
108
|
+
pageSizeField = `${tabKey}PageSize`;
|
|
109
|
+
dataListField = `${tabKey}DataList`;
|
|
110
|
+
totalField = `${tabKey}Total`;
|
|
111
|
+
selectedRowsField = `${tabKey}SelectedRows`;
|
|
112
|
+
selectedRowKeysField = `${tabKey}SelectedRowKeys`;
|
|
113
|
+
} else _request = this.getList;
|
|
114
|
+
if (!_request) return void console.error("\u672A\u914D\u7F6E getList \u8BF7\u6C42\u65B9\u6CD5,\u8BF7\u68C0\u67E5\u662F\u5426\u914D\u7F6E\u4E86 getList \u65B9\u6CD5");
|
|
115
|
+
taro.showLoading({
|
|
116
|
+
title: "\u52A0\u8F7D\u4E2D..."
|
|
117
|
+
});
|
|
48
118
|
try {
|
|
49
|
-
this.
|
|
119
|
+
this.updatedPageLoading(true);
|
|
50
120
|
const payload = {
|
|
121
|
+
...this.defaultQuery,
|
|
122
|
+
...defaultQuery,
|
|
51
123
|
...this.store.search,
|
|
52
|
-
page: this.store
|
|
53
|
-
pageSize: this.store.
|
|
124
|
+
page: this.store[pageField] || 1,
|
|
125
|
+
pageSize: this.store[pageSizeField] || this.store.defaultPageSize || 20
|
|
54
126
|
};
|
|
55
|
-
let newParams = {
|
|
127
|
+
let newParams = this.formateParams({
|
|
56
128
|
...payload
|
|
57
|
-
};
|
|
58
|
-
if (this.
|
|
59
|
-
const result = await this.
|
|
60
|
-
this.
|
|
129
|
+
});
|
|
130
|
+
if (this.onBefore) newParams = this.onBefore(payload, this.store, this);
|
|
131
|
+
const result = await this.getList?.(newParams, this);
|
|
132
|
+
this.updatedPageLoading(false);
|
|
61
133
|
this.store.loading.loadMore = false;
|
|
62
134
|
if (result && result.code === globalSettingDataInstance.store.requestSuccessCode) {
|
|
63
135
|
let saveData = {};
|
|
64
|
-
if (this.
|
|
136
|
+
if (this.onAfter) saveData = this.onAfter(result, this);
|
|
65
137
|
else {
|
|
66
138
|
const dataList = result?.data?.list || result?.data?.rows || result?.data?.records || [];
|
|
67
139
|
let newDataList = [];
|
|
68
|
-
if (1 === this.store
|
|
140
|
+
if (1 === this.store[pageField]) newDataList = dataList;
|
|
69
141
|
else if (this.is_scroll_page) newDataList = [
|
|
70
|
-
...this.store
|
|
142
|
+
...this.store[dataListField] || [],
|
|
71
143
|
...dataList
|
|
72
144
|
];
|
|
73
145
|
saveData = {
|
|
74
|
-
|
|
75
|
-
|
|
146
|
+
[dataListField]: newDataList,
|
|
147
|
+
[totalField]: result?.data?.total || 0
|
|
76
148
|
};
|
|
77
|
-
if (1 === this.store
|
|
78
|
-
saveData
|
|
79
|
-
saveData
|
|
149
|
+
if (1 === this.store[pageField]) {
|
|
150
|
+
saveData[selectedRowsField] = external_valtio_ref([]);
|
|
151
|
+
saveData[selectedRowKeysField] = external_valtio_ref([]);
|
|
80
152
|
}
|
|
81
153
|
}
|
|
82
154
|
if (saveData) this._setValues(saveData);
|
|
83
|
-
} else if (this.
|
|
155
|
+
} else if (this.onError) this.onError(result, this);
|
|
84
156
|
} catch (error) {
|
|
85
157
|
console.log(error);
|
|
86
158
|
this.store.loading.loadMore = false;
|
|
87
|
-
this.
|
|
159
|
+
this.updatedPageLoading(false);
|
|
88
160
|
}
|
|
161
|
+
taro.hideLoading();
|
|
89
162
|
};
|
|
90
163
|
main_onPageChange = (page)=>{
|
|
91
|
-
this.
|
|
164
|
+
if (this.store.isTabs) {
|
|
165
|
+
const tabKey = this.store.tabKey;
|
|
166
|
+
this._setValues({
|
|
167
|
+
[`${tabKey}Page`]: 1
|
|
168
|
+
});
|
|
169
|
+
} else this._setValues({
|
|
92
170
|
page
|
|
93
171
|
});
|
|
94
172
|
this.main_getList();
|
|
95
173
|
};
|
|
96
174
|
main_onShowSizeChange = (_, pageSize)=>{
|
|
97
|
-
this.
|
|
175
|
+
if (this.store.isTabs) {
|
|
176
|
+
const tabKey = this.store.tabKey;
|
|
177
|
+
this._setValues({
|
|
178
|
+
[`${tabKey}Page`]: 1,
|
|
179
|
+
[`${tabKey}PageSize`]: pageSize
|
|
180
|
+
});
|
|
181
|
+
} else this._setValues({
|
|
98
182
|
page: 1,
|
|
99
183
|
pageSize
|
|
100
184
|
});
|
|
101
185
|
this.main_getList();
|
|
102
186
|
};
|
|
187
|
+
main_onReset = ()=>{
|
|
188
|
+
if (this.getResetValues) {
|
|
189
|
+
const values = this.getResetValues(this);
|
|
190
|
+
if (values) this.updatedSearch({
|
|
191
|
+
...values
|
|
192
|
+
});
|
|
193
|
+
} else {
|
|
194
|
+
const keys = Object.keys(this.store.search || {});
|
|
195
|
+
for(let index = 0; index < keys.length; index++){
|
|
196
|
+
const key = keys[index];
|
|
197
|
+
this.store.search[key] = void 0;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
};
|
|
103
201
|
main_onSearch = ()=>{
|
|
104
202
|
this.main_onPageChange(1);
|
|
203
|
+
this.store.expandSearch = false;
|
|
105
204
|
};
|
|
106
205
|
main_onLoadMore = ()=>{
|
|
107
206
|
if (this.store.loading?.pageLoading) return;
|
|
207
|
+
const isTabs = this.store.isTabs;
|
|
208
|
+
if (isTabs) {
|
|
209
|
+
const tabKey = this.store.tabKey;
|
|
210
|
+
const total = this.store[`${tabKey}Total`] || 0;
|
|
211
|
+
const page = this.store[`${tabKey}Page`] || 1;
|
|
212
|
+
const pageSize = this.store[`${tabKey}PageSize`] || this.store.defaultPageSize || 20;
|
|
213
|
+
const count = Math.ceil(total / pageSize);
|
|
214
|
+
let hasLastPage = false;
|
|
215
|
+
if (page >= count && total) {
|
|
216
|
+
hasLastPage = true;
|
|
217
|
+
this._setValues({
|
|
218
|
+
[`${tabKey}HasLastPage`]: hasLastPage
|
|
219
|
+
});
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
const nextPage = page + 1;
|
|
223
|
+
if (nextPage >= count && total) hasLastPage = true;
|
|
224
|
+
this.updatedLoading({
|
|
225
|
+
[`${tabKey}LoadMore`]: true
|
|
226
|
+
});
|
|
227
|
+
this._setValues({
|
|
228
|
+
[`${tabKey}Page`]: nextPage,
|
|
229
|
+
[`${tabKey}HasLastPage`]: hasLastPage
|
|
230
|
+
});
|
|
231
|
+
this.main_getList();
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
108
234
|
const total = this.store.total || 0;
|
|
109
235
|
const page = this.store.page || 1;
|
|
110
|
-
const pageSize = this.store.pageSize || 20;
|
|
236
|
+
const pageSize = this.store.pageSize || this.store.defaultPageSize || 20;
|
|
111
237
|
const count = Math.ceil(total / pageSize);
|
|
112
238
|
let hasLastPage = false;
|
|
113
239
|
if (page >= count && total) {
|
|
@@ -127,13 +253,58 @@ class PageDataInstance extends ProxyInstanceObjectBase {
|
|
|
127
253
|
this.main_getList();
|
|
128
254
|
};
|
|
129
255
|
}
|
|
130
|
-
|
|
131
|
-
const
|
|
132
|
-
|
|
256
|
+
function usePageDataInstance(instance) {
|
|
257
|
+
const ref = useRef();
|
|
258
|
+
if (!ref.current) ref.current = instance || new page_data_instance_PageDataInstance();
|
|
259
|
+
return ref.current;
|
|
260
|
+
}
|
|
261
|
+
const PageDataInstanceContext = /*#__PURE__*/ createContext(new page_data_instance_PageDataInstance());
|
|
262
|
+
const usePageDataInstanceContext = ()=>{
|
|
263
|
+
const PageDataInstance = useContext(PageDataInstanceContext);
|
|
264
|
+
return PageDataInstance;
|
|
265
|
+
};
|
|
266
|
+
function PageDataInstanceContextProvider(props) {
|
|
267
|
+
const { instance, children, initialValues, is_scroll_page, defaultTabKey, tabItems, defaultPageSize, onBefore, getList, onAfter, onError, getResetValues, defaultQuery, codeFields, valueFields, isMountLoad, title } = props;
|
|
268
|
+
const pageInstance = usePageDataInstance(instance);
|
|
269
|
+
instance.onBefore = onBefore;
|
|
270
|
+
instance.getList = getList;
|
|
271
|
+
instance.onAfter = onAfter;
|
|
272
|
+
instance.onError = onError;
|
|
273
|
+
instance.getResetValues = getResetValues;
|
|
274
|
+
instance.codeFields = codeFields;
|
|
275
|
+
instance.valueFields = valueFields;
|
|
276
|
+
instance.defaultQuery = defaultQuery;
|
|
277
|
+
useMemo(()=>pageInstance.ctor({
|
|
278
|
+
initialValues,
|
|
279
|
+
is_scroll_page,
|
|
280
|
+
defaultTabKey,
|
|
281
|
+
tabItems,
|
|
282
|
+
defaultPageSize
|
|
283
|
+
}), [
|
|
284
|
+
pageInstance
|
|
285
|
+
]);
|
|
286
|
+
useMemo(()=>{
|
|
287
|
+
if (isMountLoad) pageInstance.main_onSearch();
|
|
288
|
+
}, []);
|
|
289
|
+
useDidShow(()=>{
|
|
290
|
+
if (title) taro.setNavigationBarTitle({
|
|
291
|
+
title
|
|
292
|
+
});
|
|
293
|
+
});
|
|
294
|
+
return /*#__PURE__*/ jsx(PageDataInstanceContext.Provider, {
|
|
295
|
+
value: pageInstance,
|
|
296
|
+
children: children
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
const usePageDataInstanceState = ()=>{
|
|
300
|
+
const PageMainDataInstance = usePageDataInstanceContext();
|
|
301
|
+
const store = useSnapshot(PageMainDataInstance.store, {
|
|
302
|
+
sync: true
|
|
303
|
+
});
|
|
133
304
|
return [
|
|
134
305
|
store,
|
|
135
|
-
|
|
306
|
+
PageMainDataInstance,
|
|
136
307
|
store.__defaultValue
|
|
137
308
|
];
|
|
138
309
|
};
|
|
139
|
-
export { PageDataInstance,
|
|
310
|
+
export { page_data_instance_PageDataInstance as PageDataInstance, PageDataInstanceContext, PageDataInstanceContextProvider, usePageDataInstance, usePageDataInstanceContext, usePageDataInstanceState };
|
|
@@ -13,41 +13,42 @@ export interface PageInfoDataInstanceState extends Object {
|
|
|
13
13
|
[s: string]: any;
|
|
14
14
|
}
|
|
15
15
|
export declare class PageInfoDataInstance<T extends PageInfoDataInstanceState = PageInfoDataInstanceState> extends ProxyInstanceObjectBase<T> {
|
|
16
|
+
notRefFields: string[];
|
|
16
17
|
/**默认值*/
|
|
17
18
|
defaultInital: T;
|
|
18
19
|
requestInfoConfig?: {
|
|
19
20
|
/**详情查询-请求之前处理参数*/
|
|
20
|
-
onBefore?: (store: T) => Promise<Partial<T>> | Partial<T>;
|
|
21
|
+
onBefore?: (store: T, instance: PageInfoDataInstance<T>) => Promise<Partial<T>> | Partial<T>;
|
|
21
22
|
/**详情查询-请求接口*/
|
|
22
|
-
getInfo?: (payload: any) => Promise<{
|
|
23
|
+
getInfo?: (payload: any, instance: PageInfoDataInstance<T>) => Promise<{
|
|
23
24
|
code?: number;
|
|
24
25
|
data?: any;
|
|
25
26
|
message?: string;
|
|
26
27
|
}>;
|
|
27
28
|
/**详情查询-请求之后处理返回值进行存储*/
|
|
28
|
-
onAfter?: (data: Record<string, any>) => Partial<T>;
|
|
29
|
+
onAfter?: (data: Record<string, any>, instance: PageInfoDataInstance<T>) => Partial<T>;
|
|
29
30
|
/**详情查询-code!==1 时 触发*/
|
|
30
|
-
onError?: (data: Record<string, any>) => void;
|
|
31
|
+
onError?: (data: Record<string, any>, instance: PageInfoDataInstance<T>) => void;
|
|
31
32
|
};
|
|
32
33
|
requestSaveInfoConfig?: {
|
|
33
34
|
/**详情保存-请求之前处理参数*/
|
|
34
|
-
onSaveBefore?: (store: T) => Promise<Record<string, any>> | Record<string, any>;
|
|
35
|
+
onSaveBefore?: (store: T, instance: PageInfoDataInstance<T>) => Promise<Record<string, any>> | Record<string, any>;
|
|
35
36
|
/**详情保存接口*/
|
|
36
|
-
onSaveInfo?: (payload: any) => Promise<{
|
|
37
|
+
onSaveInfo?: (payload: any, instance: PageInfoDataInstance<T>) => Promise<{
|
|
37
38
|
code?: number;
|
|
38
39
|
data?: any;
|
|
39
40
|
message?: string;
|
|
40
41
|
}>;
|
|
41
42
|
/**详情保存-请求之后处理返回值进行存储*/
|
|
42
|
-
onSaveAfter?: (data: Record<string, any>) => void;
|
|
43
|
+
onSaveAfter?: (data: Record<string, any>, instance: PageInfoDataInstance<T>) => void;
|
|
43
44
|
/**详情查询-code!==1 时 触发*/
|
|
44
|
-
onSaveError?: (data: Record<string, any>) => void;
|
|
45
|
+
onSaveError?: (data: Record<string, any>, instance: PageInfoDataInstance<T>) => void;
|
|
45
46
|
/**保存成功-跳转页面*/
|
|
46
47
|
saveSuccessNavigate?: string | 'navigateBack' | number | ((data: any) => void);
|
|
47
48
|
/**是否显示成功提示*/
|
|
48
49
|
isShowSuccessMessage?: boolean;
|
|
49
50
|
};
|
|
50
|
-
|
|
51
|
+
ctor(options?: PageInfoDataOptions<T>): void;
|
|
51
52
|
store: T;
|
|
52
53
|
/**初始化状态值*/
|
|
53
54
|
main_page_store: (initalValues?: Partial<T>, file?: string[]) => this;
|
|
@@ -65,8 +66,28 @@ export interface PageInfoDataOptions<T extends PageInfoDataInstanceState = PageI
|
|
|
65
66
|
requestSaveInfoConfig?: PageInfoDataInstance<T>['requestSaveInfoConfig'];
|
|
66
67
|
/**初始值*/
|
|
67
68
|
initialValues?: Partial<T>;
|
|
69
|
+
/**editFormData是否使用valtio proxy 存储*/
|
|
70
|
+
isProxy?: boolean;
|
|
68
71
|
}
|
|
72
|
+
/**初始化实例*/
|
|
73
|
+
export declare const usePageInfoDataInstance: <T extends PageInfoDataInstanceState = PageInfoDataInstanceState>(instance: PageInfoDataInstance<T>) => PageInfoDataInstance<T>;
|
|
74
|
+
/**页面级数据状态管理上下文*/
|
|
75
|
+
export declare const PageInfoDataInstanceContext: import("react").Context<PageInfoDataInstance<PageInfoDataInstanceState>>;
|
|
76
|
+
/**获取上下文实例*/
|
|
77
|
+
export declare const usePageInfoDataInstanceContext: <T extends PageInfoDataInstanceState = PageInfoDataInstanceState>() => PageInfoDataInstance<T>;
|
|
78
|
+
export interface PageInfoDataInstanceContextProviderProps<T extends PageInfoDataInstanceState = PageInfoDataInstanceState> extends PageInfoDataOptions<T> {
|
|
79
|
+
instance?: PageInfoDataInstance<T>;
|
|
80
|
+
children: React.ReactNode;
|
|
81
|
+
/**页面标题*/
|
|
82
|
+
title?: string;
|
|
83
|
+
/**页面一加载是否请求详情接口*/
|
|
84
|
+
isMountRequestInfo?: boolean;
|
|
85
|
+
/**自定义hooks,挂载参数和设置完初始值后执行*/
|
|
86
|
+
useHooks?: (instance: PageInfoDataInstance<T>) => void;
|
|
87
|
+
}
|
|
88
|
+
/**页面级数据状态管理上下文提供者*/
|
|
89
|
+
export declare function PageInfoDataInstanceContextProvider<T extends PageInfoDataInstanceState = PageInfoDataInstanceState>(props: PageInfoDataInstanceContextProviderProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
69
90
|
/**
|
|
70
91
|
* 页面级数据状态管理
|
|
71
92
|
*/
|
|
72
|
-
export declare const
|
|
93
|
+
export declare const usePageInfoDataInstanceState: <T extends PageInfoDataInstanceState = PageInfoDataInstanceState>() => [T, PageInfoDataInstance<T>, string | undefined];
|