@fairys/taro-tools-react 1.0.4 → 1.0.6
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/auth.data.instance.d.ts +3 -3
- package/esm/context/auth.data.instance.js +6 -6
- package/esm/context/global.data.instance.d.ts +4 -0
- package/esm/context/global.data.instance.js +5 -0
- package/esm/context/page.info.data.instance.d.ts +1 -1
- package/lib/components/EnterLoading/index.d.ts +14 -0
- package/lib/components/EnterLoading/index.js +112 -0
- package/lib/components/MainPage/index.d.ts +10 -0
- package/lib/components/MainPage/index.js +102 -0
- package/lib/components/Mesage/index.d.ts +48 -0
- package/lib/components/Mesage/index.js +172 -0
- package/lib/components/Portal/index.d.ts +8 -0
- package/lib/components/Portal/index.js +45 -0
- package/lib/components/Toast/index.d.ts +1 -0
- package/lib/components/Toast/index.js +54 -0
- package/lib/components/connectToastMessage/index.d.ts +10 -0
- package/lib/components/connectToastMessage/index.js +62 -0
- package/lib/components/index.d.ts +6 -0
- package/lib/components/index.js +105 -0
- package/lib/context/auth.data.instance.d.ts +81 -0
- package/lib/context/auth.data.instance.js +155 -0
- package/lib/context/global.data.instance.d.ts +54 -0
- package/lib/context/global.data.instance.js +122 -0
- package/lib/context/global.setting.data.instance.d.ts +56 -0
- package/lib/context/global.setting.data.instance.js +79 -0
- package/lib/context/index.d.ts +5 -0
- package/lib/context/index.js +96 -0
- package/lib/context/page.data.instance.d.ts +151 -0
- package/lib/context/page.data.instance.js +382 -0
- package/lib/context/page.info.data.instance.d.ts +93 -0
- package/lib/context/page.info.data.instance.js +226 -0
- package/lib/index.d.ts +3 -0
- package/lib/styles/index.css +715 -0
- package/lib/utils/index.d.ts +4 -0
- package/lib/utils/index.js +87 -0
- package/lib/utils/navigate.d.ts +109 -0
- package/lib/utils/navigate.js +99 -0
- package/lib/utils/request.d.ts +179 -0
- package/lib/utils/request.js +358 -0
- package/lib/utils/useId.d.ts +2 -0
- package/lib/utils/useId.js +50 -0
- package/lib/utils/valtio/index.d.ts +9 -0
- package/lib/utils/valtio/index.js +99 -0
- package/lib/utils/valtio/instance.d.ts +17 -0
- package/lib/utils/valtio/instance.js +80 -0
- package/package.json +4 -3
- package/src/context/auth.data.instance.ts +6 -6
- package/src/context/global.data.instance.ts +11 -0
- package/src/context/page.info.data.instance.tsx +1 -1
- package/src/utils/navigate.ts +1 -0
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.n = (module)=>{
|
|
5
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
+
__webpack_require__.d(getter, {
|
|
7
|
+
a: getter
|
|
8
|
+
});
|
|
9
|
+
return getter;
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
(()=>{
|
|
13
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
14
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: definition[key]
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
})();
|
|
20
|
+
(()=>{
|
|
21
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
+
})();
|
|
23
|
+
(()=>{
|
|
24
|
+
__webpack_require__.r = (exports1)=>{
|
|
25
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
+
value: 'Module'
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
+
value: true
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
})();
|
|
33
|
+
var __webpack_exports__ = {};
|
|
34
|
+
__webpack_require__.r(__webpack_exports__);
|
|
35
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
+
usePageInfoDataInstance: ()=>usePageInfoDataInstance,
|
|
37
|
+
PageInfoDataInstanceContext: ()=>PageInfoDataInstanceContext,
|
|
38
|
+
PageInfoDataInstanceContextProvider: ()=>PageInfoDataInstanceContextProvider,
|
|
39
|
+
usePageInfoDataInstanceContext: ()=>usePageInfoDataInstanceContext,
|
|
40
|
+
usePageInfoDataInstanceState: ()=>usePageInfoDataInstanceState,
|
|
41
|
+
PageInfoDataInstance: ()=>page_info_data_instance_PageInfoDataInstance
|
|
42
|
+
});
|
|
43
|
+
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
|
|
44
|
+
const external_valtio_namespaceObject = require("valtio");
|
|
45
|
+
const instance_js_namespaceObject = require("../utils/valtio/instance.js");
|
|
46
|
+
const external_react_namespaceObject = require("react");
|
|
47
|
+
const navigate_js_namespaceObject = require("../utils/navigate.js");
|
|
48
|
+
var navigate_js_default = /*#__PURE__*/ __webpack_require__.n(navigate_js_namespaceObject);
|
|
49
|
+
const external_global_data_instance_js_namespaceObject = require("./global.data.instance.js");
|
|
50
|
+
const external_global_setting_data_instance_js_namespaceObject = require("./global.setting.data.instance.js");
|
|
51
|
+
const taro_namespaceObject = require("@tarojs/taro");
|
|
52
|
+
var taro_default = /*#__PURE__*/ __webpack_require__.n(taro_namespaceObject);
|
|
53
|
+
class page_info_data_instance_PageInfoDataInstance extends instance_js_namespaceObject.ProxyInstanceObjectBase {
|
|
54
|
+
notRefFields = [
|
|
55
|
+
'loading'
|
|
56
|
+
];
|
|
57
|
+
defaultInital = {
|
|
58
|
+
editType: 'add',
|
|
59
|
+
editFormData: (0, external_valtio_namespaceObject.ref)({}),
|
|
60
|
+
isInfoSuccess: false,
|
|
61
|
+
loading: {
|
|
62
|
+
pageLoading: false
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
requestInfoConfig;
|
|
66
|
+
requestSaveInfoConfig = {};
|
|
67
|
+
ctor(options) {
|
|
68
|
+
if (options?.isProxy) {
|
|
69
|
+
this.notRefFields = [
|
|
70
|
+
'editFormData',
|
|
71
|
+
'loading'
|
|
72
|
+
];
|
|
73
|
+
this.store.editFormData = {};
|
|
74
|
+
}
|
|
75
|
+
if (options?.initialValues) this.main_page_store(options.initialValues);
|
|
76
|
+
}
|
|
77
|
+
store = (0, external_valtio_namespaceObject.proxy)({
|
|
78
|
+
...this.defaultInital
|
|
79
|
+
});
|
|
80
|
+
main_page_store = (initalValues = {}, file)=>{
|
|
81
|
+
const newStore = {
|
|
82
|
+
...this.defaultInital,
|
|
83
|
+
...initalValues
|
|
84
|
+
};
|
|
85
|
+
return this._ctor(newStore, [
|
|
86
|
+
...file || [],
|
|
87
|
+
'loading'
|
|
88
|
+
]);
|
|
89
|
+
};
|
|
90
|
+
updatedLoading = (loading = true)=>{
|
|
91
|
+
if ('object' == typeof this.store?.loading) this.store.loading.pageLoading = loading;
|
|
92
|
+
else this.store.loading = {
|
|
93
|
+
pageLoading: loading
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
main_getInfo = async ()=>{
|
|
97
|
+
if (!this.requestInfoConfig?.getInfo) return void console.error("\u672A\u914D\u7F6E requestInfoConfig.getInfo \u8BF7\u6C42\u65B9\u6CD5");
|
|
98
|
+
taro_default().showLoading({
|
|
99
|
+
title: "\u52A0\u8F7D\u4E2D..."
|
|
100
|
+
});
|
|
101
|
+
try {
|
|
102
|
+
this.updatedLoading(true);
|
|
103
|
+
let newParams = {};
|
|
104
|
+
if (this.requestInfoConfig?.onBefore) newParams = await this.requestInfoConfig.onBefore(this.store, this);
|
|
105
|
+
const result = await this.requestInfoConfig.getInfo?.(newParams, this);
|
|
106
|
+
this.updatedLoading(false);
|
|
107
|
+
if (result && result.code === external_global_setting_data_instance_js_namespaceObject.globalSettingDataInstance.store.requestSuccessCode) {
|
|
108
|
+
let saveData = {};
|
|
109
|
+
saveData = this.requestInfoConfig?.onAfter ? this.requestInfoConfig.onAfter(result, this) : {
|
|
110
|
+
editFormData: {
|
|
111
|
+
...result?.data
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
if (saveData) this._setValues({
|
|
115
|
+
...saveData,
|
|
116
|
+
isInfoSuccess: true
|
|
117
|
+
});
|
|
118
|
+
} else if (this.requestInfoConfig?.onError) this.requestInfoConfig.onError(result, this);
|
|
119
|
+
} catch (error) {
|
|
120
|
+
console.log(error);
|
|
121
|
+
this.updatedLoading(false);
|
|
122
|
+
}
|
|
123
|
+
taro_default().hideLoading();
|
|
124
|
+
};
|
|
125
|
+
main_saveInfo = async ()=>{
|
|
126
|
+
if (this.requestSaveInfoConfig?.onSaveInfo) return void console.error("\u672A\u914D\u7F6E requestSaveInfoConfig.onSaveInfo \u8BF7\u6C42\u65B9\u6CD5");
|
|
127
|
+
try {
|
|
128
|
+
this.updatedLoading(true);
|
|
129
|
+
taro_default().showLoading({
|
|
130
|
+
title: "\u4FDD\u5B58\u4E2D..."
|
|
131
|
+
});
|
|
132
|
+
const newParams = await this.requestSaveInfoConfig?.onSaveBefore?.(this.store, this) || this.store.editFormData || {};
|
|
133
|
+
const result = await this.requestSaveInfoConfig.onSaveInfo?.(newParams, this);
|
|
134
|
+
taro_default().hideLoading();
|
|
135
|
+
this.updatedLoading(false);
|
|
136
|
+
if (result && result.code === external_global_setting_data_instance_js_namespaceObject.globalSettingDataInstance.store.requestSuccessCode) {
|
|
137
|
+
if (this.requestSaveInfoConfig?.isShowSuccessMessage === false) external_global_data_instance_js_namespaceObject.globalDataInstance.showMessage({
|
|
138
|
+
content: result.message || "\u4FDD\u5B58\u6210\u529F"
|
|
139
|
+
});
|
|
140
|
+
else taro_default().showToast({
|
|
141
|
+
title: result.message || "\u4FDD\u5B58\u6210\u529F",
|
|
142
|
+
icon: 'none'
|
|
143
|
+
});
|
|
144
|
+
if (this.requestSaveInfoConfig?.onSaveAfter) this.requestSaveInfoConfig.onSaveAfter(result, this);
|
|
145
|
+
const saveSuccessNavigate = this.requestSaveInfoConfig?.saveSuccessNavigate;
|
|
146
|
+
if (saveSuccessNavigate) {
|
|
147
|
+
if ('navigateBack' === saveSuccessNavigate) navigate_js_default().navigateBack();
|
|
148
|
+
else if ('function' == typeof saveSuccessNavigate) saveSuccessNavigate(result);
|
|
149
|
+
else if ('number' == typeof saveSuccessNavigate) navigate_js_default().navigateBack({
|
|
150
|
+
delta: saveSuccessNavigate
|
|
151
|
+
});
|
|
152
|
+
else if ('string' == typeof saveSuccessNavigate) navigate_js_default().navigateTo({
|
|
153
|
+
url: saveSuccessNavigate
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
} else if (this.requestSaveInfoConfig?.onSaveError) this.requestSaveInfoConfig.onSaveError(result, this);
|
|
157
|
+
} catch (error) {
|
|
158
|
+
console.log(error);
|
|
159
|
+
this.updatedLoading(false);
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
const usePageInfoDataInstance = (instance)=>{
|
|
164
|
+
const ref = (0, external_react_namespaceObject.useRef)();
|
|
165
|
+
if (!ref.current) if (instance) ref.current = instance;
|
|
166
|
+
else ref.current = new page_info_data_instance_PageInfoDataInstance();
|
|
167
|
+
return ref.current;
|
|
168
|
+
};
|
|
169
|
+
const PageInfoDataInstanceContext = /*#__PURE__*/ (0, external_react_namespaceObject.createContext)(new page_info_data_instance_PageInfoDataInstance());
|
|
170
|
+
const usePageInfoDataInstanceContext = ()=>{
|
|
171
|
+
const PageInfoDataInstance = (0, external_react_namespaceObject.useContext)(PageInfoDataInstanceContext);
|
|
172
|
+
return PageInfoDataInstance;
|
|
173
|
+
};
|
|
174
|
+
function PageInfoDataInstanceContextProvider(props) {
|
|
175
|
+
const { instance, children, initialValues, requestInfoConfig, requestSaveInfoConfig, isProxy, title, isMountRequestInfo, useHooks } = props;
|
|
176
|
+
const pageInfoInstance = usePageInfoDataInstance(instance);
|
|
177
|
+
pageInfoInstance.requestInfoConfig = requestInfoConfig;
|
|
178
|
+
pageInfoInstance.requestSaveInfoConfig = requestSaveInfoConfig;
|
|
179
|
+
(0, external_react_namespaceObject.useMemo)(()=>pageInfoInstance.ctor({
|
|
180
|
+
initialValues,
|
|
181
|
+
isProxy
|
|
182
|
+
}), [
|
|
183
|
+
pageInfoInstance
|
|
184
|
+
]);
|
|
185
|
+
useHooks?.(pageInfoInstance);
|
|
186
|
+
(0, taro_namespaceObject.useDidShow)(()=>{
|
|
187
|
+
if (title) taro_default().setNavigationBarTitle({
|
|
188
|
+
title
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
192
|
+
if (isMountRequestInfo) pageInfoInstance.main_getInfo();
|
|
193
|
+
}, []);
|
|
194
|
+
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(PageInfoDataInstanceContext.Provider, {
|
|
195
|
+
value: pageInfoInstance,
|
|
196
|
+
children: children
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
const usePageInfoDataInstanceState = ()=>{
|
|
200
|
+
const PageInfoDataInstance = usePageInfoDataInstanceContext();
|
|
201
|
+
const store = (0, external_valtio_namespaceObject.useSnapshot)(PageInfoDataInstance.store, {
|
|
202
|
+
sync: true
|
|
203
|
+
});
|
|
204
|
+
return [
|
|
205
|
+
store,
|
|
206
|
+
PageInfoDataInstance,
|
|
207
|
+
store.__defaultValue
|
|
208
|
+
];
|
|
209
|
+
};
|
|
210
|
+
exports.PageInfoDataInstance = __webpack_exports__.PageInfoDataInstance;
|
|
211
|
+
exports.PageInfoDataInstanceContext = __webpack_exports__.PageInfoDataInstanceContext;
|
|
212
|
+
exports.PageInfoDataInstanceContextProvider = __webpack_exports__.PageInfoDataInstanceContextProvider;
|
|
213
|
+
exports.usePageInfoDataInstance = __webpack_exports__.usePageInfoDataInstance;
|
|
214
|
+
exports.usePageInfoDataInstanceContext = __webpack_exports__.usePageInfoDataInstanceContext;
|
|
215
|
+
exports.usePageInfoDataInstanceState = __webpack_exports__.usePageInfoDataInstanceState;
|
|
216
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
217
|
+
"PageInfoDataInstance",
|
|
218
|
+
"PageInfoDataInstanceContext",
|
|
219
|
+
"PageInfoDataInstanceContextProvider",
|
|
220
|
+
"usePageInfoDataInstance",
|
|
221
|
+
"usePageInfoDataInstanceContext",
|
|
222
|
+
"usePageInfoDataInstanceState"
|
|
223
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
224
|
+
Object.defineProperty(exports, '__esModule', {
|
|
225
|
+
value: true
|
|
226
|
+
});
|
package/lib/index.d.ts
ADDED