fix: 优化watch 修改编辑用户弹窗样式

This commit is contained in:
ZhuRui
2026-07-27 09:51:30 +08:00
parent 17d5c85904
commit e3e66ec03b
11 changed files with 146 additions and 161 deletions
+22 -23
View File
@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { ref, Ref, watch, WatchSource, onUnmounted, computed } from 'vue';
import { ref, Ref, WatchSource, onUnmounted, computed } from 'vue';
import { useEffect } from './useEffect';
export interface UseRequestReturn<T> {
/** 纯净的数据,不包含后端外层壳 */
@@ -128,31 +129,29 @@ export function useRequest<T>(
const shouldAutoRun = computed(() => !manual && ready.value);
let hasAutoRun = false; // 标记是否已自动执行过,防止重复触发
watch(
shouldAutoRun,
(val) => {
if (val && !hasAutoRun) {
hasAutoRun = true;
run();
} else if (!val) {
// 当条件不满足时重置 hasAutoRun,使下次满足条件时能再次自动执行
hasAutoRun = false;
}
},
{ immediate: true },
);
useEffect(() => {
const val = shouldAutoRun.value;
if (val && !hasAutoRun) {
hasAutoRun = true;
run();
} else if (!val) {
// 当条件不满足时重置 hasAutoRun,使下次满足条件时能再次自动执行
hasAutoRun = false;
}
}, [shouldAutoRun]);
// refreshDeps 变化时重新请求(初始化时不再重复触发)
if (refreshDeps && refreshDeps.length > 0) {
watch(
refreshDeps,
() => {
if (shouldAutoRun.value) {
run();
}
},
{ deep: true },
);
let skipInitialRefresh = true;
useEffect(() => {
if (skipInitialRefresh) {
skipInitialRefresh = false;
return;
}
if (shouldAutoRun.value) {
run();
}
}, refreshDeps);
}
const getSignal = () => abortController?.signal;