|
@@ -1076,6 +1076,7 @@
|
|
|
:before-upload="beforeUpload"
|
|
|
:show-file-list="false"
|
|
|
:on-change="handleChange"
|
|
|
+ :disabled="isCanClickImport"
|
|
|
>
|
|
|
<div class="mt-24px text-black">将文件拖动到此处,<span class="text-blue">或点击上传</span></div>
|
|
|
<div class="mt-8px text-12px">支持的文件格式:.xls,.xlsx</div>
|
|
@@ -1098,11 +1099,11 @@
|
|
|
导入模板
|
|
|
</el-button>
|
|
|
</div>
|
|
|
- <div v-if="uploadProgress" class="mt-4">
|
|
|
+ <div v-if="progressData > 0" class="mt-4">
|
|
|
<el-progress
|
|
|
:text-inside="true"
|
|
|
:stroke-width="24"
|
|
|
- :percentage="100"
|
|
|
+ :percentage="progressData"
|
|
|
status="success"
|
|
|
/>
|
|
|
</div>
|
|
@@ -1153,7 +1154,7 @@
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
|
-import { computed, nextTick, onActivated, onMounted, ref, watch } from 'vue'
|
|
|
+import { computed, nextTick, onActivated, onMounted, onUnmounted, ref, watch } from 'vue'
|
|
|
import { useAppStore } from '~src/store'
|
|
|
import { useRouter } from 'vue-router'
|
|
|
import HcUpload from './components/division/HcUpload.vue'
|
|
@@ -2748,12 +2749,90 @@ const divisionSaveClick = ()=>{
|
|
|
divisionDialogShow.value = false
|
|
|
window?.location?.reload() //刷新页面
|
|
|
}
|
|
|
+// 添加一个定时器引用
|
|
|
+const progressTimer = ref(null)
|
|
|
+//是否可以点击节点导入
|
|
|
+const isCanClickImport = ref(false)
|
|
|
+
|
|
|
+const getIsImportData = async () => {
|
|
|
+ const { error, code, data } = await divisionApi.getIsImport({
|
|
|
+ projectId: projectId.value,
|
|
|
+ contractId: contractId.value,
|
|
|
+
|
|
|
+ })
|
|
|
+ if (!error && code === 200) {
|
|
|
+ isCanClickImport.value = data
|
|
|
+ if (data) {
|
|
|
+ getImportProgressData()
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ isCanClickImport.value = false
|
|
|
+ }
|
|
|
+}
|
|
|
+const progressData = ref(0)
|
|
|
+const getImportProgressData = async () => {
|
|
|
+ const { error, code, data } = await divisionApi.getImportProgress({
|
|
|
+ projectId: projectId.value,
|
|
|
+ contractId: contractId.value,
|
|
|
+
|
|
|
+ })
|
|
|
+ if (!error && code === 200) {
|
|
|
+ progressData.value = Number(data)
|
|
|
+ // 如果进度到达100%,清除定时器
|
|
|
+ if (progressData.value >= 100) {
|
|
|
+ clearProgressTimer()
|
|
|
+ // 可以添加完成后的处理逻辑
|
|
|
+ window.$message.success('导入完成')
|
|
|
+ divisionImportDialog.value = false
|
|
|
+ window.location.reload()
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ progressData.value = 0
|
|
|
+ }
|
|
|
+}
|
|
|
//节点导入
|
|
|
const divisionImportDialog = ref(false)
|
|
|
+// 修改 divisionImportDialog 的监听
|
|
|
+watch(() => divisionImportDialog.value, (newVal) => {
|
|
|
+ if (newVal && isCanClickImport.value) {
|
|
|
+ // 弹窗打开且允许导入时,开启定时器
|
|
|
+ startProgressTimer()
|
|
|
+ } else {
|
|
|
+ // 弹窗关闭时清除定时器
|
|
|
+ clearProgressTimer()
|
|
|
+ }
|
|
|
+})
|
|
|
+// 开启进度查询定时器
|
|
|
+const startProgressTimer = () => {
|
|
|
+ // 确保先清除可能存在的定时器
|
|
|
+ clearProgressTimer()
|
|
|
+
|
|
|
+ // 立即执行一次
|
|
|
+ getImportProgressData()
|
|
|
+
|
|
|
+ // 设置定时器,每5秒执行一次
|
|
|
+ progressTimer.value = setInterval(() => {
|
|
|
+ getImportProgressData()
|
|
|
+ }, 5000)
|
|
|
+}
|
|
|
+
|
|
|
+// 清除定时器
|
|
|
+const clearProgressTimer = () => {
|
|
|
+ if (progressTimer.value) {
|
|
|
+ clearInterval(progressTimer.value)
|
|
|
+ progressTimer.value = null
|
|
|
+ }
|
|
|
+}
|
|
|
+// 在组件销毁时清理定时器
|
|
|
+onUnmounted(() => {
|
|
|
+ clearProgressTimer()
|
|
|
+})
|
|
|
+
|
|
|
//上传文件
|
|
|
const dialogUploadRef = ref(null)
|
|
|
-const divisionImportClick = ()=>{
|
|
|
-
|
|
|
+const divisionImportClick = async ()=>{
|
|
|
+ await getIsImportData()
|
|
|
+ await nextTick()
|
|
|
divisionImportDialog.value = true
|
|
|
fileList.value = []
|
|
|
|
|
@@ -2797,9 +2876,9 @@ const handleSuccess = (res) => {
|
|
|
|
|
|
divisionImportDialog.value = false
|
|
|
|
|
|
- setTimeout(()=>{
|
|
|
- window?.location?.reload() //刷新页面
|
|
|
- }, 1000)
|
|
|
+// setTimeout(()=>{
|
|
|
+// window?.location?.reload() //刷新页面
|
|
|
+// }, 1000)
|
|
|
|
|
|
} else {
|
|
|
window.$message.error(res.msg || '上传失败')
|
|
@@ -2818,9 +2897,14 @@ const handleError = (error) => {
|
|
|
fileList.value = []
|
|
|
|
|
|
}
|
|
|
-const confirmTap = ()=>{
|
|
|
+const confirmTap = async ()=>{
|
|
|
confirmLoading.value = true
|
|
|
dialogUploadRef.value.submit()
|
|
|
+ await getIsImportData()
|
|
|
+ if ( isCanClickImport.value) {
|
|
|
+ await getImportProgressData()
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
|
|
|
}
|