@fairys/taro-tools-react 1.0.16 → 1.0.18
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/components/MainPage/index.d.ts +16 -1
- package/esm/components/MainPage/index.js +29 -4
- package/esm/context/page.data.instance.d.ts +13 -1
- package/esm/context/page.data.instance.js +24 -0
- package/esm/context/page.info.data.instance.d.ts +2 -0
- package/esm/context/page.info.data.instance.js +3 -0
- package/esm/styles/index.css +8 -0
- package/esm/utils/request.d.ts +2 -2
- package/esm/utils/valtio/context.d.ts +7 -0
- package/esm/utils/valtio/context.js +15 -0
- package/esm/utils/valtio/index.d.ts +4 -3
- package/esm/utils/valtio/index.js +13 -6
- package/esm/utils/valtio/instance.d.ts +4 -0
- package/esm/utils/valtio/instance.js +11 -6
- package/lib/components/MainPage/index.d.ts +16 -1
- package/lib/components/MainPage/index.js +28 -0
- package/lib/context/index.js +2 -2
- package/lib/context/page.data.instance.d.ts +13 -1
- package/lib/context/page.data.instance.js +24 -0
- package/lib/context/page.info.data.instance.d.ts +2 -0
- package/lib/context/page.info.data.instance.js +3 -0
- package/lib/index.js +2 -2
- package/lib/styles/index.css +8 -0
- package/lib/utils/request.d.ts +2 -2
- package/lib/utils/valtio/context.d.ts +7 -0
- package/lib/utils/valtio/context.js +55 -0
- package/lib/utils/valtio/index.d.ts +4 -3
- package/lib/utils/valtio/index.js +25 -5
- package/lib/utils/valtio/instance.d.ts +4 -0
- package/lib/utils/valtio/instance.js +10 -2
- package/package.json +1 -1
- package/src/components/MainPage/index.tsx +62 -2
- package/src/context/page.data.instance.tsx +56 -2
- package/src/context/page.info.data.instance.tsx +6 -0
- package/src/utils/request.ts +2 -2
- package/src/utils/valtio/context.tsx +15 -0
- package/src/utils/valtio/index.ts +26 -8
- package/src/utils/valtio/instance.ts +12 -1
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { ViewProps } from '@tarojs/components';
|
|
1
|
+
import { ViewProps, ScrollViewProps } from '@tarojs/components';
|
|
2
2
|
export interface FairysTaroMainPageProps extends ViewProps {
|
|
3
3
|
}
|
|
4
|
+
/**
|
|
5
|
+
* 主页面(如果外部使用scroll-view组件,需要设置高度,否则内容会出现滚动)
|
|
6
|
+
*/
|
|
4
7
|
export declare const FairysTaroMainPage: (props: FairysTaroMainPageProps) => import("react/jsx-runtime").JSX.Element;
|
|
5
8
|
/**查询*/
|
|
6
9
|
export declare const FairysTaroMainPageSearch: (props: FairysTaroMainPageProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -8,3 +11,15 @@ export declare const FairysTaroMainPageSearch: (props: FairysTaroMainPageProps)
|
|
|
8
11
|
export declare const FairysTaroMainPageBody: (props: FairysTaroMainPageProps) => import("react/jsx-runtime").JSX.Element;
|
|
9
12
|
/**底部*/
|
|
10
13
|
export declare const FairysTaroMainPageFooter: (props: FairysTaroMainPageProps) => import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
export interface FairysTaroMainPageScrollViewProps extends ScrollViewProps {
|
|
15
|
+
/**下拉刷新状态*/
|
|
16
|
+
refresherStatus?: boolean;
|
|
17
|
+
/**是否还有更多数据*/
|
|
18
|
+
hasMore?: boolean;
|
|
19
|
+
/**加载更多文本*/
|
|
20
|
+
loadMoreText?: React.ReactNode;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 主页面滚动视图
|
|
24
|
+
*/
|
|
25
|
+
export declare const FairysTaroMainPageScrollView: (props: FairysTaroMainPageScrollViewProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { View } from "@tarojs/components";
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ScrollView, View } from "@tarojs/components";
|
|
3
3
|
import clsx from "clsx";
|
|
4
|
-
import { useMemo } from "react";
|
|
4
|
+
import { Fragment, useMemo } from "react";
|
|
5
5
|
const FairysTaroMainPage = (props)=>{
|
|
6
6
|
const { className: itemClassName, children, ...rest } = props;
|
|
7
7
|
const cls = useMemo(()=>clsx('fairys_taro-ui-main-page fairystaro__box-border fairystaro__w-full fairystaro__h-full fairystaro__flex fairystaro__flex-col fairystaro__overflow-auto', itemClassName), [
|
|
@@ -46,4 +46,29 @@ const FairysTaroMainPageFooter = (props)=>{
|
|
|
46
46
|
children: children
|
|
47
47
|
});
|
|
48
48
|
};
|
|
49
|
-
|
|
49
|
+
const FairysTaroMainPageScrollView = (props)=>{
|
|
50
|
+
const { className: itemClassName, children, refresherStatus, hasMore = true, loadMoreText, onScrollToLower, ...rest } = props;
|
|
51
|
+
const cls = useMemo(()=>clsx('fairys_taro-ui-main-page-scroll-view fairystaro__box-border fairystaro__w-screen fairystaro__h-screen', itemClassName), [
|
|
52
|
+
itemClassName
|
|
53
|
+
]);
|
|
54
|
+
return /*#__PURE__*/ jsxs(ScrollView, {
|
|
55
|
+
scrollY: true,
|
|
56
|
+
refresherEnabled: true,
|
|
57
|
+
enhanced: true,
|
|
58
|
+
usingSticky: true,
|
|
59
|
+
refresherTriggered: refresherStatus,
|
|
60
|
+
className: cls,
|
|
61
|
+
...rest,
|
|
62
|
+
onScrollToLower: (...args)=>{
|
|
63
|
+
if (hasMore) onScrollToLower?.(...args);
|
|
64
|
+
},
|
|
65
|
+
children: [
|
|
66
|
+
children,
|
|
67
|
+
loadMoreText ? /*#__PURE__*/ jsx(View, {
|
|
68
|
+
className: "fairys_taro-ui-main-page-scroll-view-load-more",
|
|
69
|
+
children: loadMoreText
|
|
70
|
+
}) : /*#__PURE__*/ jsx(Fragment, {})
|
|
71
|
+
]
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
export { FairysTaroMainPage, FairysTaroMainPageBody, FairysTaroMainPageFooter, FairysTaroMainPageScrollView, FairysTaroMainPageSearch };
|
|
@@ -2,6 +2,10 @@ import { ProxyInstanceObjectBase } from '../utils/valtio/instance';
|
|
|
2
2
|
export interface PageDataInstanceState extends Record<string, any> {
|
|
3
3
|
/**loading存储*/
|
|
4
4
|
loading?: Record<string, boolean>;
|
|
5
|
+
/**下拉刷新状态*/
|
|
6
|
+
refresherStatus?: boolean;
|
|
7
|
+
/**上拉加载*/
|
|
8
|
+
loadMoreStatus?: boolean;
|
|
5
9
|
/**当前页*/
|
|
6
10
|
page?: number;
|
|
7
11
|
/**分页数*/
|
|
@@ -37,6 +41,10 @@ export interface PageDataInstanceState extends Record<string, any> {
|
|
|
37
41
|
query?: Record<string, any>;
|
|
38
42
|
[s: string]: any;
|
|
39
43
|
}[];
|
|
44
|
+
/**tab多页签下拉刷新状态*/
|
|
45
|
+
tabRefresherStatus?: Record<string, boolean>;
|
|
46
|
+
/**tab多页签上拉加载状态*/
|
|
47
|
+
tabLoadMoreStatus?: Record<string, boolean>;
|
|
40
48
|
/**是否是tab多页签*/
|
|
41
49
|
isTabs?: boolean;
|
|
42
50
|
/**是否展开查询条件*/
|
|
@@ -84,7 +92,11 @@ export declare class PageDataInstance<T extends PageDataInstanceState = PageData
|
|
|
84
92
|
updatedSearch: (value?: Record<string, any>) => void;
|
|
85
93
|
/**更新页面级的 pageLoading */
|
|
86
94
|
updatedPageLoading: (loading?: boolean) => void;
|
|
87
|
-
|
|
95
|
+
/**
|
|
96
|
+
* 更新加载状态对象
|
|
97
|
+
*
|
|
98
|
+
* @param value - 包含页面键和对应加载状态的键值对对象
|
|
99
|
+
*/
|
|
88
100
|
updatedLoading: (value: Record<string, boolean>) => void;
|
|
89
101
|
/**内置——查询列表*/
|
|
90
102
|
main_getList: () => Promise<void>;
|
|
@@ -30,6 +30,10 @@ class page_data_instance_PageDataInstance extends ProxyInstanceObjectBase {
|
|
|
30
30
|
loading: {
|
|
31
31
|
pageLoading: false
|
|
32
32
|
},
|
|
33
|
+
tabRefresherStatus: {},
|
|
34
|
+
refresherStatus: false,
|
|
35
|
+
loadMoreStatus: false,
|
|
36
|
+
tabLoadMoreStatus: {},
|
|
33
37
|
hasLastPage: false
|
|
34
38
|
};
|
|
35
39
|
store = proxy({
|
|
@@ -126,6 +130,16 @@ class page_data_instance_PageDataInstance extends ProxyInstanceObjectBase {
|
|
|
126
130
|
page: this.store[pageField] || 1,
|
|
127
131
|
pageSize: this.store[pageSizeField] || this.store.defaultPageSize || 20
|
|
128
132
|
};
|
|
133
|
+
if (1 === payload.page) if (this.store.isTabs) {
|
|
134
|
+
const tabKey = this.store.tabKey;
|
|
135
|
+
if (!this.store.tabRefresherStatus) this.store.tabRefresherStatus = {};
|
|
136
|
+
this.store.tabRefresherStatus[tabKey] = true;
|
|
137
|
+
} else this.store.refresherStatus = true;
|
|
138
|
+
else if (this.store.isTabs) {
|
|
139
|
+
const tabKey = this.store.tabKey;
|
|
140
|
+
if (!this.store.tabLoadMoreStatus) this.store.tabLoadMoreStatus = {};
|
|
141
|
+
this.store.tabLoadMoreStatus[tabKey] = true;
|
|
142
|
+
} else this.store.loadMoreStatus = true;
|
|
129
143
|
let newParams = this.formateParams({
|
|
130
144
|
...payload
|
|
131
145
|
});
|
|
@@ -167,6 +181,16 @@ class page_data_instance_PageDataInstance extends ProxyInstanceObjectBase {
|
|
|
167
181
|
this.store.loading.loadMore = false;
|
|
168
182
|
this.updatedPageLoading(false);
|
|
169
183
|
}
|
|
184
|
+
if (this.store.isTabs) {
|
|
185
|
+
const tabKey = this.store.tabKey;
|
|
186
|
+
if (!this.store.tabRefresherStatus) this.store.tabRefresherStatus = {};
|
|
187
|
+
if (!this.store.tabLoadMoreStatus) this.store.tabLoadMoreStatus = {};
|
|
188
|
+
this.store.tabLoadMoreStatus[tabKey] = false;
|
|
189
|
+
this.store.tabRefresherStatus[tabKey] = false;
|
|
190
|
+
} else {
|
|
191
|
+
this.store.refresherStatus = false;
|
|
192
|
+
this.store.loadMoreStatus = false;
|
|
193
|
+
}
|
|
170
194
|
taro.hideLoading();
|
|
171
195
|
};
|
|
172
196
|
main_onPageChange = (page)=>{
|
|
@@ -14,6 +14,7 @@ class page_info_data_instance_PageInfoDataInstance extends ProxyInstanceObjectBa
|
|
|
14
14
|
editType: 'add',
|
|
15
15
|
editFormData: external_valtio_ref({}),
|
|
16
16
|
isInfoSuccess: false,
|
|
17
|
+
refresherStatus: false,
|
|
17
18
|
loading: {
|
|
18
19
|
pageLoading: false
|
|
19
20
|
}
|
|
@@ -56,6 +57,7 @@ class page_info_data_instance_PageInfoDataInstance extends ProxyInstanceObjectBa
|
|
|
56
57
|
taro.showLoading({
|
|
57
58
|
title: "\u52A0\u8F7D\u4E2D..."
|
|
58
59
|
});
|
|
60
|
+
this.store.refresherStatus = true;
|
|
59
61
|
try {
|
|
60
62
|
this.updatedLoading(true);
|
|
61
63
|
let newParams = {};
|
|
@@ -78,6 +80,7 @@ class page_info_data_instance_PageInfoDataInstance extends ProxyInstanceObjectBa
|
|
|
78
80
|
console.log(error);
|
|
79
81
|
this.updatedLoading(false);
|
|
80
82
|
}
|
|
83
|
+
this.store.refresherStatus = false;
|
|
81
84
|
taro.hideLoading();
|
|
82
85
|
};
|
|
83
86
|
main_saveInfo = async ()=>{
|
package/esm/styles/index.css
CHANGED
|
@@ -83,6 +83,10 @@
|
|
|
83
83
|
height: 100%;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
.fairystaro__h-screen {
|
|
87
|
+
height: 100vh;
|
|
88
|
+
}
|
|
89
|
+
|
|
86
90
|
.fairystaro__max-h-full {
|
|
87
91
|
max-height: 100%;
|
|
88
92
|
}
|
|
@@ -95,6 +99,10 @@
|
|
|
95
99
|
width: 100%;
|
|
96
100
|
}
|
|
97
101
|
|
|
102
|
+
.fairystaro__w-screen {
|
|
103
|
+
width: 100vw;
|
|
104
|
+
}
|
|
105
|
+
|
|
98
106
|
.fairystaro__flex {
|
|
99
107
|
display: flex;
|
|
100
108
|
}
|
package/esm/utils/request.d.ts
CHANGED
|
@@ -41,11 +41,11 @@ export interface RequestInstanceCreateOptions {
|
|
|
41
41
|
};
|
|
42
42
|
dev: Record<string, string | {
|
|
43
43
|
target: string;
|
|
44
|
-
pathRewrite
|
|
44
|
+
pathRewrite?: Record<string, string>;
|
|
45
45
|
}>;
|
|
46
46
|
pro: Record<string, string | {
|
|
47
47
|
target: string;
|
|
48
|
-
pathRewrite
|
|
48
|
+
pathRewrite?: Record<string, string>;
|
|
49
49
|
}>;
|
|
50
50
|
};
|
|
51
51
|
/**启用token校验*/
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
export declare const ValtioContext: import("react").Context<any>;
|
|
3
|
+
export declare function ValtioContextProvider<T>({ value, children }: {
|
|
4
|
+
value: T;
|
|
5
|
+
children?: ReactNode;
|
|
6
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export declare function useValtioContext<T>(): T;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
3
|
+
const ValtioContext = /*#__PURE__*/ createContext(void 0);
|
|
4
|
+
function ValtioContextProvider({ value, children }) {
|
|
5
|
+
return /*#__PURE__*/ jsx(ValtioContext.Provider, {
|
|
6
|
+
value: value,
|
|
7
|
+
children: children
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
function useValtioContext() {
|
|
11
|
+
const context = useContext(ValtioContext);
|
|
12
|
+
if (!context) throw new Error('useValtioContext must be used within a ValtioContextProvider');
|
|
13
|
+
return context;
|
|
14
|
+
}
|
|
15
|
+
export { ValtioContext, ValtioContextProvider, useValtioContext };
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { ProxyInstanceObjectBase } from './instance';
|
|
2
2
|
export * from './instance';
|
|
3
|
+
export * from './context';
|
|
3
4
|
/**创建简单的状态管理*/
|
|
4
|
-
export declare const useValtioState: <T extends object>(inital?: T) =>
|
|
5
|
+
export declare const useValtioState: <T extends object>(inital?: T) => [T, ProxyInstanceObjectBase<T>, any];
|
|
5
6
|
export declare const useValtioInstaceState: <T extends object = any, K extends ProxyInstanceObjectBase<T> = ProxyInstanceObjectBase<T>, M extends {
|
|
6
7
|
new (...args: any[]): K;
|
|
7
8
|
} = {
|
|
8
9
|
new (...args: any[]): K;
|
|
9
|
-
}>(Instance: M) =>
|
|
10
|
+
}>(Instance: M) => [T, K, any];
|
|
10
11
|
/**
|
|
11
12
|
* 创建valtio proxy 状态管理
|
|
12
13
|
*/
|
|
13
|
-
export declare const useValtioProxyState: <T extends object>(inital?: T) =>
|
|
14
|
+
export declare const useValtioProxyState: <T extends object>(inital?: T) => [T, T, any];
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { useRef } from "react";
|
|
2
2
|
import { proxy, useSnapshot } from "valtio";
|
|
3
|
-
import {
|
|
3
|
+
import { useProxyInstanceObjectBase } from "./instance.js";
|
|
4
4
|
export * from "./instance.js";
|
|
5
|
+
export * from "./context.js";
|
|
5
6
|
const useValtioState = (inital)=>{
|
|
6
|
-
const instance =
|
|
7
|
+
const instance = useProxyInstanceObjectBase(inital);
|
|
7
8
|
const state = useSnapshot(instance.store);
|
|
8
9
|
return [
|
|
9
10
|
state,
|
|
@@ -11,8 +12,13 @@ const useValtioState = (inital)=>{
|
|
|
11
12
|
state.__defaultValue
|
|
12
13
|
];
|
|
13
14
|
};
|
|
15
|
+
const usNewInstance = (Instance)=>{
|
|
16
|
+
const ref = useRef();
|
|
17
|
+
if (!ref.current) ref.current = new Instance();
|
|
18
|
+
return ref.current;
|
|
19
|
+
};
|
|
14
20
|
const useValtioInstaceState = (Instance)=>{
|
|
15
|
-
const instance =
|
|
21
|
+
const instance = usNewInstance(Instance);
|
|
16
22
|
const state = useSnapshot(instance.store);
|
|
17
23
|
return [
|
|
18
24
|
state,
|
|
@@ -21,11 +27,12 @@ const useValtioInstaceState = (Instance)=>{
|
|
|
21
27
|
];
|
|
22
28
|
};
|
|
23
29
|
const useValtioProxyState = (inital)=>{
|
|
24
|
-
const instance = useRef(
|
|
25
|
-
|
|
30
|
+
const instance = useRef();
|
|
31
|
+
if (!instance.current) instance.current = proxy(inital || {});
|
|
32
|
+
const state = useSnapshot(instance.current);
|
|
26
33
|
return [
|
|
27
34
|
state,
|
|
28
|
-
instance,
|
|
35
|
+
instance.current,
|
|
29
36
|
state.__defaultValue
|
|
30
37
|
];
|
|
31
38
|
};
|
|
@@ -15,3 +15,7 @@ export declare class ProxyInstanceObjectBase<T extends Object = any> {
|
|
|
15
15
|
/**创建 ref 对象 (ref对象不做监听更新)*/
|
|
16
16
|
_createRef: <K extends Object = any>(inital?: K) => K;
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* 创建单个proxy对象数据基础实例封装
|
|
20
|
+
*/
|
|
21
|
+
export declare const useProxyInstanceObjectBase: <T extends object>(inital?: T) => ProxyInstanceObjectBase<T>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { proxy, ref } from "valtio";
|
|
2
|
-
import react from "react";
|
|
1
|
+
import { proxy, ref as external_valtio_ref } from "valtio";
|
|
2
|
+
import react, { useRef } from "react";
|
|
3
3
|
class ProxyInstanceObjectBase {
|
|
4
4
|
notRefFields = [];
|
|
5
5
|
store = proxy({});
|
|
@@ -13,8 +13,8 @@ class ProxyInstanceObjectBase {
|
|
|
13
13
|
const value = values[key];
|
|
14
14
|
if (Array.isArray(fields) && fields.includes(key)) this.store[key] = values[key];
|
|
15
15
|
else if (Array.isArray(this.notRefFields) && this.notRefFields.includes(key)) this.store[key] = value;
|
|
16
|
-
else if (react.isValidElement(value) || 'function' == typeof value) this.store[key] =
|
|
17
|
-
else if ('object' == typeof value && null !== value) this.store[key] =
|
|
16
|
+
else if (react.isValidElement(value) || 'function' == typeof value) this.store[key] = external_valtio_ref(values[key]);
|
|
17
|
+
else if ('object' == typeof value && null !== value) this.store[key] = external_valtio_ref(values[key]);
|
|
18
18
|
else this.store[key] = values[key];
|
|
19
19
|
});
|
|
20
20
|
return this;
|
|
@@ -31,6 +31,11 @@ class ProxyInstanceObjectBase {
|
|
|
31
31
|
} else delete this.store[names];
|
|
32
32
|
return this;
|
|
33
33
|
};
|
|
34
|
-
_createRef = (inital)=>
|
|
34
|
+
_createRef = (inital)=>external_valtio_ref(inital || {});
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
const useProxyInstanceObjectBase = (inital)=>{
|
|
37
|
+
const ref = useRef();
|
|
38
|
+
if (!ref.current) ref.current = new ProxyInstanceObjectBase()._ctor(inital);
|
|
39
|
+
return ref.current;
|
|
40
|
+
};
|
|
41
|
+
export { ProxyInstanceObjectBase, useProxyInstanceObjectBase };
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { ViewProps } from '@tarojs/components';
|
|
1
|
+
import { ViewProps, ScrollViewProps } from '@tarojs/components';
|
|
2
2
|
export interface FairysTaroMainPageProps extends ViewProps {
|
|
3
3
|
}
|
|
4
|
+
/**
|
|
5
|
+
* 主页面(如果外部使用scroll-view组件,需要设置高度,否则内容会出现滚动)
|
|
6
|
+
*/
|
|
4
7
|
export declare const FairysTaroMainPage: (props: FairysTaroMainPageProps) => import("react/jsx-runtime").JSX.Element;
|
|
5
8
|
/**查询*/
|
|
6
9
|
export declare const FairysTaroMainPageSearch: (props: FairysTaroMainPageProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -8,3 +11,15 @@ export declare const FairysTaroMainPageSearch: (props: FairysTaroMainPageProps)
|
|
|
8
11
|
export declare const FairysTaroMainPageBody: (props: FairysTaroMainPageProps) => import("react/jsx-runtime").JSX.Element;
|
|
9
12
|
/**底部*/
|
|
10
13
|
export declare const FairysTaroMainPageFooter: (props: FairysTaroMainPageProps) => import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
export interface FairysTaroMainPageScrollViewProps extends ScrollViewProps {
|
|
15
|
+
/**下拉刷新状态*/
|
|
16
|
+
refresherStatus?: boolean;
|
|
17
|
+
/**是否还有更多数据*/
|
|
18
|
+
hasMore?: boolean;
|
|
19
|
+
/**加载更多文本*/
|
|
20
|
+
loadMoreText?: React.ReactNode;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 主页面滚动视图
|
|
24
|
+
*/
|
|
25
|
+
export declare const FairysTaroMainPageScrollView: (props: FairysTaroMainPageScrollViewProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -34,6 +34,7 @@ var __webpack_exports__ = {};
|
|
|
34
34
|
__webpack_require__.r(__webpack_exports__);
|
|
35
35
|
__webpack_require__.d(__webpack_exports__, {
|
|
36
36
|
FairysTaroMainPageFooter: ()=>FairysTaroMainPageFooter,
|
|
37
|
+
FairysTaroMainPageScrollView: ()=>FairysTaroMainPageScrollView,
|
|
37
38
|
FairysTaroMainPage: ()=>FairysTaroMainPage,
|
|
38
39
|
FairysTaroMainPageSearch: ()=>FairysTaroMainPageSearch,
|
|
39
40
|
FairysTaroMainPageBody: ()=>FairysTaroMainPageBody
|
|
@@ -87,14 +88,41 @@ const FairysTaroMainPageFooter = (props)=>{
|
|
|
87
88
|
children: children
|
|
88
89
|
});
|
|
89
90
|
};
|
|
91
|
+
const FairysTaroMainPageScrollView = (props)=>{
|
|
92
|
+
const { className: itemClassName, children, refresherStatus, hasMore = true, loadMoreText, onScrollToLower, ...rest } = props;
|
|
93
|
+
const cls = (0, external_react_namespaceObject.useMemo)(()=>external_clsx_default()('fairys_taro-ui-main-page-scroll-view fairystaro__box-border fairystaro__w-screen fairystaro__h-screen', itemClassName), [
|
|
94
|
+
itemClassName
|
|
95
|
+
]);
|
|
96
|
+
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(components_namespaceObject.ScrollView, {
|
|
97
|
+
scrollY: true,
|
|
98
|
+
refresherEnabled: true,
|
|
99
|
+
enhanced: true,
|
|
100
|
+
usingSticky: true,
|
|
101
|
+
refresherTriggered: refresherStatus,
|
|
102
|
+
className: cls,
|
|
103
|
+
...rest,
|
|
104
|
+
onScrollToLower: (...args)=>{
|
|
105
|
+
if (hasMore) onScrollToLower?.(...args);
|
|
106
|
+
},
|
|
107
|
+
children: [
|
|
108
|
+
children,
|
|
109
|
+
loadMoreText ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(components_namespaceObject.View, {
|
|
110
|
+
className: "fairys_taro-ui-main-page-scroll-view-load-more",
|
|
111
|
+
children: loadMoreText
|
|
112
|
+
}) : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_react_namespaceObject.Fragment, {})
|
|
113
|
+
]
|
|
114
|
+
});
|
|
115
|
+
};
|
|
90
116
|
exports.FairysTaroMainPage = __webpack_exports__.FairysTaroMainPage;
|
|
91
117
|
exports.FairysTaroMainPageBody = __webpack_exports__.FairysTaroMainPageBody;
|
|
92
118
|
exports.FairysTaroMainPageFooter = __webpack_exports__.FairysTaroMainPageFooter;
|
|
119
|
+
exports.FairysTaroMainPageScrollView = __webpack_exports__.FairysTaroMainPageScrollView;
|
|
93
120
|
exports.FairysTaroMainPageSearch = __webpack_exports__.FairysTaroMainPageSearch;
|
|
94
121
|
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
95
122
|
"FairysTaroMainPage",
|
|
96
123
|
"FairysTaroMainPageBody",
|
|
97
124
|
"FairysTaroMainPageFooter",
|
|
125
|
+
"FairysTaroMainPageScrollView",
|
|
98
126
|
"FairysTaroMainPageSearch"
|
|
99
127
|
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
100
128
|
Object.defineProperty(exports, '__esModule', {
|
package/lib/context/index.js
CHANGED
|
@@ -6,7 +6,7 @@ var __webpack_modules__ = {
|
|
|
6
6
|
"./global.message.data.instance": function(module) {
|
|
7
7
|
module.exports = require("./global.message.data.instance.js");
|
|
8
8
|
},
|
|
9
|
-
"
|
|
9
|
+
"context/global.setting.data.instance": function(module) {
|
|
10
10
|
module.exports = require("./global.setting.data.instance.js");
|
|
11
11
|
},
|
|
12
12
|
"./page.data.instance": function(module) {
|
|
@@ -83,7 +83,7 @@ var __webpack_exports__ = {};
|
|
|
83
83
|
return _auth_data_instance__WEBPACK_IMPORTED_MODULE_3__[key];
|
|
84
84
|
}).bind(0, __WEBPACK_IMPORT_KEY__);
|
|
85
85
|
__webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
|
|
86
|
-
var _global_setting_data_instance__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__("
|
|
86
|
+
var _global_setting_data_instance__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__("context/global.setting.data.instance");
|
|
87
87
|
var __WEBPACK_REEXPORT_OBJECT__ = {};
|
|
88
88
|
for(var __WEBPACK_IMPORT_KEY__ in _global_setting_data_instance__WEBPACK_IMPORTED_MODULE_4__)if ("default" !== __WEBPACK_IMPORT_KEY__) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
|
|
89
89
|
return _global_setting_data_instance__WEBPACK_IMPORTED_MODULE_4__[key];
|
|
@@ -2,6 +2,10 @@ import { ProxyInstanceObjectBase } from '../utils/valtio/instance';
|
|
|
2
2
|
export interface PageDataInstanceState extends Record<string, any> {
|
|
3
3
|
/**loading存储*/
|
|
4
4
|
loading?: Record<string, boolean>;
|
|
5
|
+
/**下拉刷新状态*/
|
|
6
|
+
refresherStatus?: boolean;
|
|
7
|
+
/**上拉加载*/
|
|
8
|
+
loadMoreStatus?: boolean;
|
|
5
9
|
/**当前页*/
|
|
6
10
|
page?: number;
|
|
7
11
|
/**分页数*/
|
|
@@ -37,6 +41,10 @@ export interface PageDataInstanceState extends Record<string, any> {
|
|
|
37
41
|
query?: Record<string, any>;
|
|
38
42
|
[s: string]: any;
|
|
39
43
|
}[];
|
|
44
|
+
/**tab多页签下拉刷新状态*/
|
|
45
|
+
tabRefresherStatus?: Record<string, boolean>;
|
|
46
|
+
/**tab多页签上拉加载状态*/
|
|
47
|
+
tabLoadMoreStatus?: Record<string, boolean>;
|
|
40
48
|
/**是否是tab多页签*/
|
|
41
49
|
isTabs?: boolean;
|
|
42
50
|
/**是否展开查询条件*/
|
|
@@ -84,7 +92,11 @@ export declare class PageDataInstance<T extends PageDataInstanceState = PageData
|
|
|
84
92
|
updatedSearch: (value?: Record<string, any>) => void;
|
|
85
93
|
/**更新页面级的 pageLoading */
|
|
86
94
|
updatedPageLoading: (loading?: boolean) => void;
|
|
87
|
-
|
|
95
|
+
/**
|
|
96
|
+
* 更新加载状态对象
|
|
97
|
+
*
|
|
98
|
+
* @param value - 包含页面键和对应加载状态的键值对对象
|
|
99
|
+
*/
|
|
88
100
|
updatedLoading: (value: Record<string, boolean>) => void;
|
|
89
101
|
/**内置——查询列表*/
|
|
90
102
|
main_getList: () => Promise<void>;
|
|
@@ -73,6 +73,10 @@ class page_data_instance_PageDataInstance extends instance_js_namespaceObject.Pr
|
|
|
73
73
|
loading: {
|
|
74
74
|
pageLoading: false
|
|
75
75
|
},
|
|
76
|
+
tabRefresherStatus: {},
|
|
77
|
+
refresherStatus: false,
|
|
78
|
+
loadMoreStatus: false,
|
|
79
|
+
tabLoadMoreStatus: {},
|
|
76
80
|
hasLastPage: false
|
|
77
81
|
};
|
|
78
82
|
store = (0, external_valtio_namespaceObject.proxy)({
|
|
@@ -169,6 +173,16 @@ class page_data_instance_PageDataInstance extends instance_js_namespaceObject.Pr
|
|
|
169
173
|
page: this.store[pageField] || 1,
|
|
170
174
|
pageSize: this.store[pageSizeField] || this.store.defaultPageSize || 20
|
|
171
175
|
};
|
|
176
|
+
if (1 === payload.page) if (this.store.isTabs) {
|
|
177
|
+
const tabKey = this.store.tabKey;
|
|
178
|
+
if (!this.store.tabRefresherStatus) this.store.tabRefresherStatus = {};
|
|
179
|
+
this.store.tabRefresherStatus[tabKey] = true;
|
|
180
|
+
} else this.store.refresherStatus = true;
|
|
181
|
+
else if (this.store.isTabs) {
|
|
182
|
+
const tabKey = this.store.tabKey;
|
|
183
|
+
if (!this.store.tabLoadMoreStatus) this.store.tabLoadMoreStatus = {};
|
|
184
|
+
this.store.tabLoadMoreStatus[tabKey] = true;
|
|
185
|
+
} else this.store.loadMoreStatus = true;
|
|
172
186
|
let newParams = this.formateParams({
|
|
173
187
|
...payload
|
|
174
188
|
});
|
|
@@ -210,6 +224,16 @@ class page_data_instance_PageDataInstance extends instance_js_namespaceObject.Pr
|
|
|
210
224
|
this.store.loading.loadMore = false;
|
|
211
225
|
this.updatedPageLoading(false);
|
|
212
226
|
}
|
|
227
|
+
if (this.store.isTabs) {
|
|
228
|
+
const tabKey = this.store.tabKey;
|
|
229
|
+
if (!this.store.tabRefresherStatus) this.store.tabRefresherStatus = {};
|
|
230
|
+
if (!this.store.tabLoadMoreStatus) this.store.tabLoadMoreStatus = {};
|
|
231
|
+
this.store.tabLoadMoreStatus[tabKey] = false;
|
|
232
|
+
this.store.tabRefresherStatus[tabKey] = false;
|
|
233
|
+
} else {
|
|
234
|
+
this.store.refresherStatus = false;
|
|
235
|
+
this.store.loadMoreStatus = false;
|
|
236
|
+
}
|
|
213
237
|
taro_default().hideLoading();
|
|
214
238
|
};
|
|
215
239
|
main_onPageChange = (page)=>{
|
|
@@ -58,6 +58,7 @@ class page_info_data_instance_PageInfoDataInstance extends instance_js_namespace
|
|
|
58
58
|
editType: 'add',
|
|
59
59
|
editFormData: (0, external_valtio_namespaceObject.ref)({}),
|
|
60
60
|
isInfoSuccess: false,
|
|
61
|
+
refresherStatus: false,
|
|
61
62
|
loading: {
|
|
62
63
|
pageLoading: false
|
|
63
64
|
}
|
|
@@ -100,6 +101,7 @@ class page_info_data_instance_PageInfoDataInstance extends instance_js_namespace
|
|
|
100
101
|
taro_default().showLoading({
|
|
101
102
|
title: "\u52A0\u8F7D\u4E2D..."
|
|
102
103
|
});
|
|
104
|
+
this.store.refresherStatus = true;
|
|
103
105
|
try {
|
|
104
106
|
this.updatedLoading(true);
|
|
105
107
|
let newParams = {};
|
|
@@ -122,6 +124,7 @@ class page_info_data_instance_PageInfoDataInstance extends instance_js_namespace
|
|
|
122
124
|
console.log(error);
|
|
123
125
|
this.updatedLoading(false);
|
|
124
126
|
}
|
|
127
|
+
this.store.refresherStatus = false;
|
|
125
128
|
taro_default().hideLoading();
|
|
126
129
|
};
|
|
127
130
|
main_saveInfo = async ()=>{
|
package/lib/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __webpack_modules__ = {
|
|
|
3
3
|
"./components": function(module) {
|
|
4
4
|
module.exports = require("./components/index.js");
|
|
5
5
|
},
|
|
6
|
-
"./context": function(module) {
|
|
6
|
+
"./context?4a23": function(module) {
|
|
7
7
|
module.exports = require("./context/index.js");
|
|
8
8
|
},
|
|
9
9
|
"./utils": function(module) {
|
|
@@ -59,7 +59,7 @@ var __webpack_exports__ = {};
|
|
|
59
59
|
return _components__WEBPACK_IMPORTED_MODULE_0__[key];
|
|
60
60
|
}).bind(0, __WEBPACK_IMPORT_KEY__);
|
|
61
61
|
__webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
|
|
62
|
-
var _context__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./context");
|
|
62
|
+
var _context__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./context?4a23");
|
|
63
63
|
var __WEBPACK_REEXPORT_OBJECT__ = {};
|
|
64
64
|
for(var __WEBPACK_IMPORT_KEY__ in _context__WEBPACK_IMPORTED_MODULE_1__)if ("default" !== __WEBPACK_IMPORT_KEY__) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
|
|
65
65
|
return _context__WEBPACK_IMPORTED_MODULE_1__[key];
|
package/lib/styles/index.css
CHANGED
|
@@ -83,6 +83,10 @@
|
|
|
83
83
|
height: 100%;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
.fairystaro__h-screen {
|
|
87
|
+
height: 100vh;
|
|
88
|
+
}
|
|
89
|
+
|
|
86
90
|
.fairystaro__max-h-full {
|
|
87
91
|
max-height: 100%;
|
|
88
92
|
}
|
|
@@ -95,6 +99,10 @@
|
|
|
95
99
|
width: 100%;
|
|
96
100
|
}
|
|
97
101
|
|
|
102
|
+
.fairystaro__w-screen {
|
|
103
|
+
width: 100vw;
|
|
104
|
+
}
|
|
105
|
+
|
|
98
106
|
.fairystaro__flex {
|
|
99
107
|
display: flex;
|
|
100
108
|
}
|
package/lib/utils/request.d.ts
CHANGED
|
@@ -41,11 +41,11 @@ export interface RequestInstanceCreateOptions {
|
|
|
41
41
|
};
|
|
42
42
|
dev: Record<string, string | {
|
|
43
43
|
target: string;
|
|
44
|
-
pathRewrite
|
|
44
|
+
pathRewrite?: Record<string, string>;
|
|
45
45
|
}>;
|
|
46
46
|
pro: Record<string, string | {
|
|
47
47
|
target: string;
|
|
48
|
-
pathRewrite
|
|
48
|
+
pathRewrite?: Record<string, string>;
|
|
49
49
|
}>;
|
|
50
50
|
};
|
|
51
51
|
/**启用token校验*/
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
export declare const ValtioContext: import("react").Context<any>;
|
|
3
|
+
export declare function ValtioContextProvider<T>({ value, children }: {
|
|
4
|
+
value: T;
|
|
5
|
+
children?: ReactNode;
|
|
6
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export declare function useValtioContext<T>(): T;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
ValtioContext: ()=>ValtioContext,
|
|
28
|
+
ValtioContextProvider: ()=>ValtioContextProvider,
|
|
29
|
+
useValtioContext: ()=>useValtioContext
|
|
30
|
+
});
|
|
31
|
+
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
|
|
32
|
+
const external_react_namespaceObject = require("react");
|
|
33
|
+
const ValtioContext = /*#__PURE__*/ (0, external_react_namespaceObject.createContext)(void 0);
|
|
34
|
+
function ValtioContextProvider({ value, children }) {
|
|
35
|
+
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(ValtioContext.Provider, {
|
|
36
|
+
value: value,
|
|
37
|
+
children: children
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
function useValtioContext() {
|
|
41
|
+
const context = (0, external_react_namespaceObject.useContext)(ValtioContext);
|
|
42
|
+
if (!context) throw new Error('useValtioContext must be used within a ValtioContextProvider');
|
|
43
|
+
return context;
|
|
44
|
+
}
|
|
45
|
+
exports.ValtioContext = __webpack_exports__.ValtioContext;
|
|
46
|
+
exports.ValtioContextProvider = __webpack_exports__.ValtioContextProvider;
|
|
47
|
+
exports.useValtioContext = __webpack_exports__.useValtioContext;
|
|
48
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
49
|
+
"ValtioContext",
|
|
50
|
+
"ValtioContextProvider",
|
|
51
|
+
"useValtioContext"
|
|
52
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
53
|
+
Object.defineProperty(exports, '__esModule', {
|
|
54
|
+
value: true
|
|
55
|
+
});
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { ProxyInstanceObjectBase } from './instance';
|
|
2
2
|
export * from './instance';
|
|
3
|
+
export * from './context';
|
|
3
4
|
/**创建简单的状态管理*/
|
|
4
|
-
export declare const useValtioState: <T extends object>(inital?: T) =>
|
|
5
|
+
export declare const useValtioState: <T extends object>(inital?: T) => [T, ProxyInstanceObjectBase<T>, any];
|
|
5
6
|
export declare const useValtioInstaceState: <T extends object = any, K extends ProxyInstanceObjectBase<T> = ProxyInstanceObjectBase<T>, M extends {
|
|
6
7
|
new (...args: any[]): K;
|
|
7
8
|
} = {
|
|
8
9
|
new (...args: any[]): K;
|
|
9
|
-
}>(Instance: M) =>
|
|
10
|
+
}>(Instance: M) => [T, K, any];
|
|
10
11
|
/**
|
|
11
12
|
* 创建valtio proxy 状态管理
|
|
12
13
|
*/
|
|
13
|
-
export declare const useValtioProxyState: <T extends object>(inital?: T) =>
|
|
14
|
+
export declare const useValtioProxyState: <T extends object>(inital?: T) => [T, T, any];
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __webpack_modules__ = {
|
|
3
|
+
"./context?fe51": function(module) {
|
|
4
|
+
module.exports = require("./context.js");
|
|
5
|
+
},
|
|
3
6
|
"./instance": function(module) {
|
|
4
7
|
module.exports = require("./instance.js");
|
|
5
8
|
},
|
|
@@ -71,8 +74,19 @@ var __webpack_exports__ = {};
|
|
|
71
74
|
return _instance__WEBPACK_IMPORTED_MODULE_2__[key];
|
|
72
75
|
}).bind(0, __WEBPACK_IMPORT_KEY__);
|
|
73
76
|
__webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
|
|
77
|
+
var _context__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__("./context?fe51");
|
|
78
|
+
var __WEBPACK_REEXPORT_OBJECT__ = {};
|
|
79
|
+
for(var __WEBPACK_IMPORT_KEY__ in _context__WEBPACK_IMPORTED_MODULE_3__)if ([
|
|
80
|
+
"useValtioProxyState",
|
|
81
|
+
"default",
|
|
82
|
+
"useValtioInstaceState",
|
|
83
|
+
"useValtioState"
|
|
84
|
+
].indexOf(__WEBPACK_IMPORT_KEY__) < 0) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
|
|
85
|
+
return _context__WEBPACK_IMPORTED_MODULE_3__[key];
|
|
86
|
+
}).bind(0, __WEBPACK_IMPORT_KEY__);
|
|
87
|
+
__webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
|
|
74
88
|
const useValtioState = (inital)=>{
|
|
75
|
-
const instance = (0,
|
|
89
|
+
const instance = (0, _instance__WEBPACK_IMPORTED_MODULE_2__.useProxyInstanceObjectBase)(inital);
|
|
76
90
|
const state = (0, valtio__WEBPACK_IMPORTED_MODULE_1__.useSnapshot)(instance.store);
|
|
77
91
|
return [
|
|
78
92
|
state,
|
|
@@ -80,8 +94,13 @@ var __webpack_exports__ = {};
|
|
|
80
94
|
state.__defaultValue
|
|
81
95
|
];
|
|
82
96
|
};
|
|
97
|
+
const usNewInstance = (Instance)=>{
|
|
98
|
+
const ref = (0, react__WEBPACK_IMPORTED_MODULE_0__.useRef)();
|
|
99
|
+
if (!ref.current) ref.current = new Instance();
|
|
100
|
+
return ref.current;
|
|
101
|
+
};
|
|
83
102
|
const useValtioInstaceState = (Instance)=>{
|
|
84
|
-
const instance = (
|
|
103
|
+
const instance = usNewInstance(Instance);
|
|
85
104
|
const state = (0, valtio__WEBPACK_IMPORTED_MODULE_1__.useSnapshot)(instance.store);
|
|
86
105
|
return [
|
|
87
106
|
state,
|
|
@@ -90,11 +109,12 @@ var __webpack_exports__ = {};
|
|
|
90
109
|
];
|
|
91
110
|
};
|
|
92
111
|
const useValtioProxyState = (inital)=>{
|
|
93
|
-
const instance = (0, react__WEBPACK_IMPORTED_MODULE_0__.useRef)(
|
|
94
|
-
|
|
112
|
+
const instance = (0, react__WEBPACK_IMPORTED_MODULE_0__.useRef)();
|
|
113
|
+
if (!instance.current) instance.current = (0, valtio__WEBPACK_IMPORTED_MODULE_1__.proxy)(inital || {});
|
|
114
|
+
const state = (0, valtio__WEBPACK_IMPORTED_MODULE_1__.useSnapshot)(instance.current);
|
|
95
115
|
return [
|
|
96
116
|
state,
|
|
97
|
-
instance,
|
|
117
|
+
instance.current,
|
|
98
118
|
state.__defaultValue
|
|
99
119
|
];
|
|
100
120
|
};
|
|
@@ -15,3 +15,7 @@ export declare class ProxyInstanceObjectBase<T extends Object = any> {
|
|
|
15
15
|
/**创建 ref 对象 (ref对象不做监听更新)*/
|
|
16
16
|
_createRef: <K extends Object = any>(inital?: K) => K;
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* 创建单个proxy对象数据基础实例封装
|
|
20
|
+
*/
|
|
21
|
+
export declare const useProxyInstanceObjectBase: <T extends object>(inital?: T) => ProxyInstanceObjectBase<T>;
|
|
@@ -33,7 +33,8 @@ var __webpack_require__ = {};
|
|
|
33
33
|
var __webpack_exports__ = {};
|
|
34
34
|
__webpack_require__.r(__webpack_exports__);
|
|
35
35
|
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
-
ProxyInstanceObjectBase: ()=>ProxyInstanceObjectBase
|
|
36
|
+
ProxyInstanceObjectBase: ()=>ProxyInstanceObjectBase,
|
|
37
|
+
useProxyInstanceObjectBase: ()=>useProxyInstanceObjectBase
|
|
37
38
|
});
|
|
38
39
|
const external_valtio_namespaceObject = require("valtio");
|
|
39
40
|
const external_react_namespaceObject = require("react");
|
|
@@ -71,9 +72,16 @@ class ProxyInstanceObjectBase {
|
|
|
71
72
|
};
|
|
72
73
|
_createRef = (inital)=>(0, external_valtio_namespaceObject.ref)(inital || {});
|
|
73
74
|
}
|
|
75
|
+
const useProxyInstanceObjectBase = (inital)=>{
|
|
76
|
+
const ref = (0, external_react_namespaceObject.useRef)();
|
|
77
|
+
if (!ref.current) ref.current = new ProxyInstanceObjectBase()._ctor(inital);
|
|
78
|
+
return ref.current;
|
|
79
|
+
};
|
|
74
80
|
exports.ProxyInstanceObjectBase = __webpack_exports__.ProxyInstanceObjectBase;
|
|
81
|
+
exports.useProxyInstanceObjectBase = __webpack_exports__.useProxyInstanceObjectBase;
|
|
75
82
|
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
76
|
-
"ProxyInstanceObjectBase"
|
|
83
|
+
"ProxyInstanceObjectBase",
|
|
84
|
+
"useProxyInstanceObjectBase"
|
|
77
85
|
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
78
86
|
Object.defineProperty(exports, '__esModule', {
|
|
79
87
|
value: true
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"author": "SunLxy <1011771396@qq.com>",
|
|
4
4
|
"description": "框架组件库",
|
|
5
5
|
"homepage": "https://github.com/autumn-fairy-tales/fairys-taro-react",
|
|
6
|
-
"version": "1.0.
|
|
6
|
+
"version": "1.0.18",
|
|
7
7
|
"main": "esm/index.js",
|
|
8
8
|
"types": "esm/index.d.ts",
|
|
9
9
|
"module": "esm/index.js",
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { ViewProps, View } from '@tarojs/components';
|
|
1
|
+
import { ViewProps, View, ScrollView, ScrollViewProps } from '@tarojs/components';
|
|
2
2
|
import clsx from 'clsx';
|
|
3
|
-
import { useMemo } from 'react';
|
|
3
|
+
import { Fragment, useMemo } from 'react';
|
|
4
4
|
|
|
5
5
|
export interface FairysTaroMainPageProps extends ViewProps {}
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* 主页面(如果外部使用scroll-view组件,需要设置高度,否则内容会出现滚动)
|
|
9
|
+
*/
|
|
7
10
|
export const FairysTaroMainPage = (props: FairysTaroMainPageProps) => {
|
|
8
11
|
const { className: itemClassName, children, ...rest } = props;
|
|
9
12
|
|
|
@@ -70,3 +73,60 @@ export const FairysTaroMainPageFooter = (props: FairysTaroMainPageProps) => {
|
|
|
70
73
|
</View>
|
|
71
74
|
);
|
|
72
75
|
};
|
|
76
|
+
|
|
77
|
+
export interface FairysTaroMainPageScrollViewProps extends ScrollViewProps {
|
|
78
|
+
/**下拉刷新状态*/
|
|
79
|
+
refresherStatus?: boolean;
|
|
80
|
+
/**是否还有更多数据*/
|
|
81
|
+
hasMore?: boolean;
|
|
82
|
+
/**加载更多文本*/
|
|
83
|
+
loadMoreText?: React.ReactNode;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 主页面滚动视图
|
|
88
|
+
*/
|
|
89
|
+
export const FairysTaroMainPageScrollView = (props: FairysTaroMainPageScrollViewProps) => {
|
|
90
|
+
const {
|
|
91
|
+
className: itemClassName,
|
|
92
|
+
children,
|
|
93
|
+
refresherStatus,
|
|
94
|
+
hasMore = true,
|
|
95
|
+
loadMoreText,
|
|
96
|
+
onScrollToLower,
|
|
97
|
+
...rest
|
|
98
|
+
} = props;
|
|
99
|
+
|
|
100
|
+
const cls = useMemo(
|
|
101
|
+
() =>
|
|
102
|
+
clsx(
|
|
103
|
+
'fairys_taro-ui-main-page-scroll-view fairystaro__box-border fairystaro__w-screen fairystaro__h-screen',
|
|
104
|
+
itemClassName,
|
|
105
|
+
),
|
|
106
|
+
[itemClassName],
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
return (
|
|
110
|
+
<ScrollView
|
|
111
|
+
scrollY
|
|
112
|
+
refresherEnabled
|
|
113
|
+
enhanced
|
|
114
|
+
usingSticky
|
|
115
|
+
refresherTriggered={refresherStatus}
|
|
116
|
+
className={cls}
|
|
117
|
+
{...rest}
|
|
118
|
+
onScrollToLower={(...args) => {
|
|
119
|
+
if (hasMore) {
|
|
120
|
+
onScrollToLower?.(...args);
|
|
121
|
+
}
|
|
122
|
+
}}
|
|
123
|
+
>
|
|
124
|
+
{children}
|
|
125
|
+
{loadMoreText ? (
|
|
126
|
+
<View className="fairys_taro-ui-main-page-scroll-view-load-more">{loadMoreText}</View>
|
|
127
|
+
) : (
|
|
128
|
+
<Fragment />
|
|
129
|
+
)}
|
|
130
|
+
</ScrollView>
|
|
131
|
+
);
|
|
132
|
+
};
|
|
@@ -7,6 +7,10 @@ import Taro, { useDidShow } from '@tarojs/taro';
|
|
|
7
7
|
export interface PageDataInstanceState extends Record<string, any> {
|
|
8
8
|
/**loading存储*/
|
|
9
9
|
loading?: Record<string, boolean>;
|
|
10
|
+
/**下拉刷新状态*/
|
|
11
|
+
refresherStatus?: boolean;
|
|
12
|
+
/**上拉加载*/
|
|
13
|
+
loadMoreStatus?: boolean;
|
|
10
14
|
/**当前页*/
|
|
11
15
|
page?: number;
|
|
12
16
|
/**分页数*/
|
|
@@ -42,6 +46,10 @@ export interface PageDataInstanceState extends Record<string, any> {
|
|
|
42
46
|
query?: Record<string, any>;
|
|
43
47
|
[s: string]: any;
|
|
44
48
|
}[];
|
|
49
|
+
/**tab多页签下拉刷新状态*/
|
|
50
|
+
tabRefresherStatus?: Record<string, boolean>;
|
|
51
|
+
/**tab多页签上拉加载状态*/
|
|
52
|
+
tabLoadMoreStatus?: Record<string, boolean>;
|
|
45
53
|
/**是否是tab多页签*/
|
|
46
54
|
isTabs?: boolean;
|
|
47
55
|
/**是否展开查询条件*/
|
|
@@ -95,6 +103,14 @@ export class PageDataInstance<
|
|
|
95
103
|
selectedRowKeys: ref([]),
|
|
96
104
|
/**加载状态*/
|
|
97
105
|
loading: { pageLoading: false },
|
|
106
|
+
/**tab多页签下拉刷新状态*/
|
|
107
|
+
tabRefresherStatus: {},
|
|
108
|
+
/**下拉刷新状态*/
|
|
109
|
+
refresherStatus: false,
|
|
110
|
+
/**上拉加载*/
|
|
111
|
+
loadMoreStatus: false,
|
|
112
|
+
/**tab多页签上拉加载状态*/
|
|
113
|
+
tabLoadMoreStatus: {},
|
|
98
114
|
/**是否最后一页*/
|
|
99
115
|
hasLastPage: false,
|
|
100
116
|
} as unknown as T;
|
|
@@ -151,7 +167,6 @@ export class PageDataInstance<
|
|
|
151
167
|
this.store.search[key] = value[key];
|
|
152
168
|
}
|
|
153
169
|
};
|
|
154
|
-
|
|
155
170
|
/**更新页面级的 pageLoading */
|
|
156
171
|
updatedPageLoading = (loading: boolean = true) => {
|
|
157
172
|
if (typeof this.store?.loading === 'object') {
|
|
@@ -160,7 +175,11 @@ export class PageDataInstance<
|
|
|
160
175
|
this.store.loading = { pageLoading: loading };
|
|
161
176
|
}
|
|
162
177
|
};
|
|
163
|
-
|
|
178
|
+
/**
|
|
179
|
+
* 更新加载状态对象
|
|
180
|
+
*
|
|
181
|
+
* @param value - 包含页面键和对应加载状态的键值对对象
|
|
182
|
+
*/
|
|
164
183
|
updatedLoading = (value: Record<string, boolean>) => {
|
|
165
184
|
if (typeof this.store?.loading === 'object') {
|
|
166
185
|
this.store.loading = { ...this.store.loading, ...value };
|
|
@@ -209,6 +228,27 @@ export class PageDataInstance<
|
|
|
209
228
|
page: this.store[pageField] || 1,
|
|
210
229
|
pageSize: this.store[pageSizeField] || this.store.defaultPageSize || 20,
|
|
211
230
|
};
|
|
231
|
+
if (payload.page === 1) {
|
|
232
|
+
if (this.store.isTabs) {
|
|
233
|
+
const tabKey = this.store.tabKey;
|
|
234
|
+
if (!this.store.tabRefresherStatus) {
|
|
235
|
+
this.store.tabRefresherStatus = {};
|
|
236
|
+
}
|
|
237
|
+
this.store.tabRefresherStatus[tabKey] = true;
|
|
238
|
+
} else {
|
|
239
|
+
this.store.refresherStatus = true;
|
|
240
|
+
}
|
|
241
|
+
} else {
|
|
242
|
+
if (this.store.isTabs) {
|
|
243
|
+
const tabKey = this.store.tabKey;
|
|
244
|
+
if (!this.store.tabLoadMoreStatus) {
|
|
245
|
+
this.store.tabLoadMoreStatus = {};
|
|
246
|
+
}
|
|
247
|
+
this.store.tabLoadMoreStatus[tabKey] = true;
|
|
248
|
+
} else {
|
|
249
|
+
this.store.loadMoreStatus = true;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
212
252
|
let newParams = this.formateParams({ ...payload }) as any;
|
|
213
253
|
if (this.onBefore) {
|
|
214
254
|
newParams = this.onBefore(payload, this.store, this);
|
|
@@ -252,6 +292,20 @@ export class PageDataInstance<
|
|
|
252
292
|
this.store.loading.loadMore = false;
|
|
253
293
|
this.updatedPageLoading(false);
|
|
254
294
|
}
|
|
295
|
+
if (this.store.isTabs) {
|
|
296
|
+
const tabKey = this.store.tabKey;
|
|
297
|
+
if (!this.store.tabRefresherStatus) {
|
|
298
|
+
this.store.tabRefresherStatus = {};
|
|
299
|
+
}
|
|
300
|
+
if (!this.store.tabLoadMoreStatus) {
|
|
301
|
+
this.store.tabLoadMoreStatus = {};
|
|
302
|
+
}
|
|
303
|
+
this.store.tabLoadMoreStatus[tabKey] = false;
|
|
304
|
+
this.store.tabRefresherStatus[tabKey] = false;
|
|
305
|
+
} else {
|
|
306
|
+
this.store.refresherStatus = false;
|
|
307
|
+
this.store.loadMoreStatus = false;
|
|
308
|
+
}
|
|
255
309
|
Taro.hideLoading();
|
|
256
310
|
};
|
|
257
311
|
/**内置——翻页*/
|
|
@@ -16,6 +16,8 @@ export interface PageInfoDataInstanceState extends Record<string, any> {
|
|
|
16
16
|
editType?: 'add' | 'edit' | 'info';
|
|
17
17
|
/**查询详情是否成功*/
|
|
18
18
|
isInfoSuccess?: boolean;
|
|
19
|
+
/**下拉刷新状态*/
|
|
20
|
+
refresherStatus?: boolean;
|
|
19
21
|
/**数据默认值不使用*/
|
|
20
22
|
__defaultValue?: string;
|
|
21
23
|
}
|
|
@@ -32,6 +34,8 @@ export class PageInfoDataInstance<
|
|
|
32
34
|
editFormData: ref({}),
|
|
33
35
|
/**查询详情是否成功*/
|
|
34
36
|
isInfoSuccess: false,
|
|
37
|
+
/**下拉刷新状态*/
|
|
38
|
+
refresherStatus: false,
|
|
35
39
|
/**加载状态*/
|
|
36
40
|
loading: { pageLoading: false },
|
|
37
41
|
} as unknown as T;
|
|
@@ -104,6 +108,7 @@ export class PageInfoDataInstance<
|
|
|
104
108
|
return;
|
|
105
109
|
}
|
|
106
110
|
Taro.showLoading({ title: '加载中...' });
|
|
111
|
+
this.store.refresherStatus = true;
|
|
107
112
|
try {
|
|
108
113
|
this.updatedLoading(true);
|
|
109
114
|
let newParams = {} as any;
|
|
@@ -127,6 +132,7 @@ export class PageInfoDataInstance<
|
|
|
127
132
|
console.log(error);
|
|
128
133
|
this.updatedLoading(false);
|
|
129
134
|
}
|
|
135
|
+
this.store.refresherStatus = false;
|
|
130
136
|
Taro.hideLoading();
|
|
131
137
|
};
|
|
132
138
|
|
package/src/utils/request.ts
CHANGED
|
@@ -101,8 +101,8 @@ export interface RequestInstanceCreateOptions {
|
|
|
101
101
|
dev?: string;
|
|
102
102
|
pro?: string;
|
|
103
103
|
};
|
|
104
|
-
dev: Record<string, string | { target: string; pathRewrite
|
|
105
|
-
pro: Record<string, string | { target: string; pathRewrite
|
|
104
|
+
dev: Record<string, string | { target: string; pathRewrite?: Record<string, string> }>;
|
|
105
|
+
pro: Record<string, string | { target: string; pathRewrite?: Record<string, string> }>;
|
|
106
106
|
};
|
|
107
107
|
/**启用token校验*/
|
|
108
108
|
isEnableTokenAuth?: boolean;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createContext, ReactNode, useContext } from 'react';
|
|
2
|
+
|
|
3
|
+
export const ValtioContext = createContext(undefined);
|
|
4
|
+
|
|
5
|
+
export function ValtioContextProvider<T>({ value, children }: { value: T; children?: ReactNode }) {
|
|
6
|
+
return <ValtioContext.Provider value={value}>{children}</ValtioContext.Provider>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function useValtioContext<T>() {
|
|
10
|
+
const context = useContext<T>(ValtioContext);
|
|
11
|
+
if (!context) {
|
|
12
|
+
throw new Error('useValtioContext must be used within a ValtioContextProvider');
|
|
13
|
+
}
|
|
14
|
+
return context;
|
|
15
|
+
}
|
|
@@ -1,13 +1,28 @@
|
|
|
1
1
|
import { useRef } from 'react';
|
|
2
2
|
import { useSnapshot, proxy } from 'valtio';
|
|
3
|
-
import { ProxyInstanceObjectBase } from './instance';
|
|
3
|
+
import { ProxyInstanceObjectBase, useProxyInstanceObjectBase } from './instance';
|
|
4
4
|
export * from './instance';
|
|
5
|
+
export * from './context';
|
|
5
6
|
|
|
6
7
|
/**创建简单的状态管理*/
|
|
7
8
|
export const useValtioState = <T extends object>(inital?: T) => {
|
|
8
|
-
const instance =
|
|
9
|
+
const instance = useProxyInstanceObjectBase(inital);
|
|
9
10
|
const state = useSnapshot(instance.store);
|
|
10
|
-
return [state, instance, (state as any).__defaultValue] as
|
|
11
|
+
return [state, instance, (state as any).__defaultValue] as [T, ProxyInstanceObjectBase<T>, any];
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const usNewInstance = <
|
|
15
|
+
T extends object = any,
|
|
16
|
+
K extends ProxyInstanceObjectBase<T> = ProxyInstanceObjectBase<T>,
|
|
17
|
+
M extends { new (...args: any[]): K } = { new (...args: any[]): K },
|
|
18
|
+
>(
|
|
19
|
+
Instance: M,
|
|
20
|
+
) => {
|
|
21
|
+
const ref = useRef<K>();
|
|
22
|
+
if (!ref.current) {
|
|
23
|
+
ref.current = new Instance();
|
|
24
|
+
}
|
|
25
|
+
return ref.current;
|
|
11
26
|
};
|
|
12
27
|
|
|
13
28
|
export const useValtioInstaceState = <
|
|
@@ -17,16 +32,19 @@ export const useValtioInstaceState = <
|
|
|
17
32
|
>(
|
|
18
33
|
Instance: M,
|
|
19
34
|
) => {
|
|
20
|
-
const instance =
|
|
35
|
+
const instance = usNewInstance<T, K, M>(Instance);
|
|
21
36
|
const state = useSnapshot(instance.store);
|
|
22
|
-
return [state, instance, (state as any).__defaultValue] as
|
|
37
|
+
return [state, instance, (state as any).__defaultValue] as [T, K, any];
|
|
23
38
|
};
|
|
24
39
|
|
|
25
40
|
/**
|
|
26
41
|
* 创建valtio proxy 状态管理
|
|
27
42
|
*/
|
|
28
43
|
export const useValtioProxyState = <T extends object>(inital?: T) => {
|
|
29
|
-
const instance = useRef(
|
|
30
|
-
|
|
31
|
-
|
|
44
|
+
const instance = useRef<T>();
|
|
45
|
+
if (!instance.current) {
|
|
46
|
+
instance.current = proxy(inital || ({} as T));
|
|
47
|
+
}
|
|
48
|
+
const state = useSnapshot(instance.current);
|
|
49
|
+
return [state, instance.current, (state as any).__defaultValue] as [T, T, any];
|
|
32
50
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { proxy, ref } from 'valtio';
|
|
2
|
-
import React from 'react';
|
|
2
|
+
import React, { useRef } from 'react';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* 单个proxy对象数据基础实例封装
|
|
@@ -59,3 +59,14 @@ export class ProxyInstanceObjectBase<T extends Object = any> {
|
|
|
59
59
|
return ref<K>(inital || ({} as K)) as K;
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 创建单个proxy对象数据基础实例封装
|
|
65
|
+
*/
|
|
66
|
+
export const useProxyInstanceObjectBase = <T extends object>(inital?: T) => {
|
|
67
|
+
const ref = useRef<ProxyInstanceObjectBase<T>>();
|
|
68
|
+
if (!ref.current) {
|
|
69
|
+
ref.current = new ProxyInstanceObjectBase<T>()._ctor(inital);
|
|
70
|
+
}
|
|
71
|
+
return ref.current;
|
|
72
|
+
};
|