th-design 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.
|
@@ -24,7 +24,7 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
|
|
|
24
24
|
* @Author: luohq luohq@2345.com
|
|
25
25
|
* @Date: 2025-10-14 14:02:00
|
|
26
26
|
* @LastEditors: luohq luohq@2345.com
|
|
27
|
-
* @LastEditTime: 2026-01-20
|
|
27
|
+
* @LastEditTime: 2026-01-20 15:31:42
|
|
28
28
|
* @FilePath: /tellhowComponent/src/components/ThSelect/index.tsx
|
|
29
29
|
* @Description: 选择器组件
|
|
30
30
|
*/
|
|
@@ -194,6 +194,7 @@ var ThSelect = function ThSelect(props) {
|
|
|
194
194
|
var initValueRef = useRef(null);
|
|
195
195
|
var scopeKey = location.pathname;
|
|
196
196
|
var prevScopeKeyRef = useRef(scopeKey);
|
|
197
|
+
var prevPathRef = useRef(window.location.pathname + window.location.hash);
|
|
197
198
|
var _useState29 = useState(false),
|
|
198
199
|
_useState30 = _slicedToArray(_useState29, 2),
|
|
199
200
|
isEditing = _useState30[0],
|
|
@@ -217,19 +218,65 @@ var ThSelect = function ThSelect(props) {
|
|
|
217
218
|
var isFirstRender = useRef(true);
|
|
218
219
|
useEffect(function () {
|
|
219
220
|
return function () {
|
|
220
|
-
// 组件卸载,自动清除该组件缓存
|
|
221
221
|
if (cacheKey && scopeKey) {
|
|
222
222
|
customSelectCache.clearEntry(scopeKey, cacheKey);
|
|
223
223
|
}
|
|
224
224
|
};
|
|
225
225
|
}, [cacheKey, scopeKey]);
|
|
226
226
|
useEffect(function () {
|
|
227
|
-
// 路由切换,清除上一个路由的缓存
|
|
228
227
|
if (cacheKey && prevScopeKeyRef.current !== scopeKey) {
|
|
229
228
|
customSelectCache.clearEntry(prevScopeKeyRef.current, cacheKey);
|
|
230
229
|
}
|
|
231
230
|
prevScopeKeyRef.current = scopeKey;
|
|
232
231
|
}, [cacheKey, scopeKey]);
|
|
232
|
+
useEffect(function () {
|
|
233
|
+
var onRouteChange = function onRouteChange() {
|
|
234
|
+
var nextPath = window.location.pathname + window.location.hash;
|
|
235
|
+
if (cacheKey && prevPathRef.current !== nextPath) {
|
|
236
|
+
customSelectCache.clearEntry(prevPathRef.current, cacheKey);
|
|
237
|
+
}
|
|
238
|
+
prevPathRef.current = nextPath;
|
|
239
|
+
};
|
|
240
|
+
var patchHistory = function patchHistory() {
|
|
241
|
+
var win = window;
|
|
242
|
+
if (!win.__th_route_patched__) {
|
|
243
|
+
win.__th_route_patched__ = true;
|
|
244
|
+
win.__th_route_original_push__ = history.pushState;
|
|
245
|
+
win.__th_route_original_replace__ = history.replaceState;
|
|
246
|
+
history.pushState = function () {
|
|
247
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
248
|
+
args[_key] = arguments[_key];
|
|
249
|
+
}
|
|
250
|
+
win.__th_route_original_push__.apply(history, args);
|
|
251
|
+
window.dispatchEvent(new Event('th-route-change'));
|
|
252
|
+
};
|
|
253
|
+
history.replaceState = function () {
|
|
254
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
255
|
+
args[_key2] = arguments[_key2];
|
|
256
|
+
}
|
|
257
|
+
win.__th_route_original_replace__.apply(history, args);
|
|
258
|
+
window.dispatchEvent(new Event('th-route-change'));
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
win.__th_route_patch_count__ = (win.__th_route_patch_count__ || 0) + 1;
|
|
262
|
+
};
|
|
263
|
+
patchHistory();
|
|
264
|
+
window.addEventListener('popstate', onRouteChange);
|
|
265
|
+
window.addEventListener('hashchange', onRouteChange);
|
|
266
|
+
window.addEventListener('th-route-change', onRouteChange);
|
|
267
|
+
return function () {
|
|
268
|
+
window.removeEventListener('popstate', onRouteChange);
|
|
269
|
+
window.removeEventListener('hashchange', onRouteChange);
|
|
270
|
+
window.removeEventListener('th-route-change', onRouteChange);
|
|
271
|
+
var win = window;
|
|
272
|
+
win.__th_route_patch_count__ = Math.max((win.__th_route_patch_count__ || 1) - 1, 0);
|
|
273
|
+
if (win.__th_route_patch_count__ === 0 && win.__th_route_patched__) {
|
|
274
|
+
history.pushState = win.__th_route_original_push__;
|
|
275
|
+
history.replaceState = win.__th_route_original_replace__;
|
|
276
|
+
win.__th_route_patched__ = false;
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
}, [cacheKey]);
|
|
233
280
|
useEffect(function () {
|
|
234
281
|
if (typeof value === 'string') {
|
|
235
282
|
if (name && value) {
|