Files
cdTestPlant3/cdTMP/src/views/testmanage/projmanage/cpns/progress.vue

91 lines
2.3 KiB
Vue
Raw Normal View History

2024-03-05 16:28:47 +08:00
<template>
<div class="progress">
<a-modal
draggable
:visible="visible"
hide-cancel
:mask-closable="false"
:on-before-ok="handleClickConfirmButton"
2024-09-01 15:58:58 +08:00
:on-before-cancel="handleClickConfirmButton"
2024-03-05 16:28:47 +08:00
>
2024-03-12 19:22:55 +08:00
<template #title>正在生成{{ text }}</template>
2024-03-05 16:28:47 +08:00
<div><a-progress :percent="percent" size="large" /></div>
</a-modal>
</div>
</template>
<script setup>
import { ref, watch, onUnmounted } from "vue"
import { Notification } from "@arco-design/web-vue"
2024-09-01 15:58:58 +08:00
import seitaiGenerateApi from "@/api/generate/seitaiGenerate"
2024-03-05 16:28:47 +08:00
const emits = defineEmits(["clickConfirm"])
const props = defineProps({
visible: {
type: Boolean,
default: false
},
isComplete: {
type: Boolean,
default: false
2024-03-12 19:22:55 +08:00
},
text: {
type: String,
default: "测评大纲"
2024-03-05 16:28:47 +08:00
}
})
const percent = ref(0)
// 点击确定或关闭按钮判断是否完成未完成则无法关闭进度条modal
2024-09-01 15:58:58 +08:00
const handleClickConfirmButton = async () => {
2024-03-05 16:28:47 +08:00
if (props.isComplete) {
emits("clickConfirm")
return true
}
Notification.warning({
title: "无法关闭",
2024-03-29 19:03:35 +08:00
content: `生成${props.text}未完成,请等待生成完成后再关闭`
2024-03-05 16:28:47 +08:00
})
return false
}
// 打开modal后自动移动
let timer = null
watch(
() => props.visible,
(newVal, oldVal) => {
if (newVal) {
2024-06-07 18:03:11 +08:00
percent.value = 0
2024-03-05 16:28:47 +08:00
timer = setInterval(() => {
if (percent.value <= 0.95) {
let temp = parseFloat(percent.value.toFixed(2))
temp += 0.01
percent.value = parseFloat(temp.toFixed(2))
}
2024-06-07 18:03:11 +08:00
}, 120)
2024-03-05 16:28:47 +08:00
} else {
// 进度条清零
percent.value = 0
clearInterval(timer)
timer = null
}
}
)
// 监听是否完成大纲生成
watch(
() => props.isComplete,
(newVal, oldVal) => {
if (newVal) {
percent.value = 1
clearInterval(timer)
timer = null
}
}
)
onUnmounted(() => {
clearInterval(timer)
timer = null
// 进度条清零
percent.value = 0
})
</script>
<style lang="less" scoped></style>