mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/fe-manage.git
synced 2025-12-14 05:16:45 +08:00
-- fix bug
This commit is contained in:
@@ -1,45 +1,79 @@
|
||||
import {ref} from "vue";
|
||||
import {onMounted, ref, watch} from "vue";
|
||||
import {message} from "ant-design-vue";
|
||||
import {ASYNC_STUDENT_STATUS} from "@/api/apis";
|
||||
import {request} from "@/api/request";
|
||||
import dialog from "@/utils/dialog";
|
||||
|
||||
export function useInterval(fun, time) {
|
||||
const timer = ref();
|
||||
const timer = ref();
|
||||
|
||||
function start(d) {
|
||||
clearInterval(timer.value)
|
||||
timer.value = setInterval(async () => {
|
||||
if (await fun(d)) {
|
||||
clearInterval(timer.value)
|
||||
}
|
||||
}, time);
|
||||
}
|
||||
function start(d) {
|
||||
clearInterval(timer.value);
|
||||
timer.value = setInterval(async () => {
|
||||
if (await fun(d)) {
|
||||
clearInterval(timer.value);
|
||||
}
|
||||
}, time);
|
||||
}
|
||||
|
||||
return {start}
|
||||
return { start };
|
||||
}
|
||||
|
||||
export function useTimeout(asyncFun, time) {
|
||||
const timer = ref();
|
||||
const maxCount = ref(0);
|
||||
const timer = ref();
|
||||
const maxCount = ref(0);
|
||||
|
||||
function start(d) {
|
||||
clearTimeout(timer.value)
|
||||
maxCount.value = 0
|
||||
execute(d)
|
||||
function start(d) {
|
||||
clearTimeout(timer.value);
|
||||
maxCount.value = 0;
|
||||
execute(d);
|
||||
}
|
||||
|
||||
async function execute(d) {
|
||||
if (maxCount.value > 300) {
|
||||
message.error("等待超时,请联系管理员!");
|
||||
throw Error("等待超时 查询任务结束");
|
||||
}
|
||||
|
||||
async function execute(d) {
|
||||
if (maxCount.value > 300) {
|
||||
message.error("等待超时,请联系管理员!")
|
||||
throw Error("等待超时 查询任务结束")
|
||||
}
|
||||
try {
|
||||
await asyncFun(d)
|
||||
maxCount.value = maxCount.value + 1
|
||||
timer.value = setTimeout(() => execute(d), time);
|
||||
} catch (e) {
|
||||
clearTimeout(timer.value)
|
||||
console.log(e)
|
||||
}
|
||||
try {
|
||||
await asyncFun(d);
|
||||
maxCount.value = maxCount.value + 1;
|
||||
timer.value = setTimeout(() => execute(d), time);
|
||||
} catch (e) {
|
||||
clearTimeout(timer.value);
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
return {start}
|
||||
return { start };
|
||||
}
|
||||
|
||||
export function useAsyncStu(id, type, func) {
|
||||
const loading = ref(false);
|
||||
|
||||
const { start } = useTimeout(async () => {
|
||||
const { data } = await request(ASYNC_STUDENT_STATUS, { id, type });
|
||||
if (!data) {
|
||||
loading.value = false;
|
||||
throw Error("查询任务结束");
|
||||
}
|
||||
loading.value = true;
|
||||
}, 10000);
|
||||
|
||||
watch(loading, () => {
|
||||
loading.value && dialog({
|
||||
duration: 3500,
|
||||
cancel: false,
|
||||
content: "您选择的学员正在添加中,请耐心等待,进行其他操作不影响此次添加"
|
||||
});
|
||||
loading.value || (func && func());
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
console.log(22222222);
|
||||
console.log(id);
|
||||
console.log(type);
|
||||
id && type && start();
|
||||
});
|
||||
return { loading, start };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user