mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/fe-manage.git
synced 2025-12-14 05:16:45 +08:00
fix -- 导入组长和路径图
This commit is contained in:
45
src/utils/useCommon.js
Normal file
45
src/utils/useCommon.js
Normal file
@@ -0,0 +1,45 @@
|
||||
import {ref} from "vue";
|
||||
import {message} from "ant-design-vue";
|
||||
|
||||
export function useInterval(fun, time) {
|
||||
const timer = ref();
|
||||
|
||||
function start(d) {
|
||||
clearInterval(timer.value)
|
||||
timer.value = setInterval(async () => {
|
||||
if (await fun(d)) {
|
||||
clearInterval(timer.value)
|
||||
}
|
||||
}, time);
|
||||
}
|
||||
|
||||
return {start}
|
||||
}
|
||||
|
||||
export function useTimeout(asyncFun, time) {
|
||||
const timer = ref();
|
||||
const maxCount = ref(0);
|
||||
|
||||
function start(d) {
|
||||
clearTimeout(timer.value)
|
||||
maxCount.value = 0
|
||||
execute(d)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
return {start}
|
||||
}
|
||||
Reference in New Issue
Block a user