瀏覽代碼

自动关闭弹窗

lifanagju_citu 6 月之前
父節點
當前提交
61e498edce
共有 2 個文件被更改,包括 11 次插入8 次删除
  1. 5 8
      src/App.vue
  2. 6 0
      src/plugins/confirm/confirm.vue

+ 5 - 8
src/App.vue

@@ -5,18 +5,15 @@ import Confirm from '@/plugins/confirm'
 import axios from 'axios'
 import axios from 'axios'
 
 
 const timer = ref(null)
 const timer = ref(null)
+const autoCloseTime = 30000
 onMounted(() => {
 onMounted(() => {
   nextTick(() => {
   nextTick(() => {
-    console.log('NODE_ENV', import.meta.env?.NODE_ENV)
-    console.log('process_ENV', process.env.NODE_ENV)
-    console.log('version', import.meta.env?.VITE_VERSION)
-    console.log('tenant-id', import.meta.env.VITE_TENANTCODE)
-    console.log('baseUrl', import.meta.env.VITE_BASE_URL)
+    console.log('baseurl', import.meta.env?.VITE_BASE_URL, 'version', import.meta.env?.VITE_VERSION)
     //
     //
     const process_ENV = process?.env?.NODE_ENV || ''
     const process_ENV = process?.env?.NODE_ENV || ''
-    if (process_ENV === 'development') { // development production
+    if (process_ENV === 'production') { // development production
       if (timer.value) clearInterval(timer.value)
       if (timer.value) clearInterval(timer.value)
-      timer.value = setInterval(() => { checkVersion() }, 60000)
+      timer.value = setInterval(() => { checkVersion() }, autoCloseTime)
     }
     }
   })
   })
 })
 })
@@ -35,7 +32,7 @@ const checkVersion = () => {
     // cache: 'no-store' // 禁用缓存
     // cache: 'no-store' // 禁用缓存
   }).then((res) => {
   }).then((res) => {
     if (res?.data?.data !== version) {
     if (res?.data?.data !== version) {
-      Confirm('系统提示', '发现新版本,是否立即刷新页面').then(() => {
+      Confirm('系统提示', '发现新版本,是否立即刷新页面', { autoCloseTime }).then(() => {
         window.location.reload()
         window.location.reload()
       })
       })
     }
     }

+ 6 - 0
src/plugins/confirm/confirm.vue

@@ -20,6 +20,12 @@ const hideCancelBtn = props.option.hideCancelBtn || false
 const cancelText = props.option.cancelText || '取消'
 const cancelText = props.option.cancelText || '取消'
 const sureText = props.option.sureText || '确认'
 const sureText = props.option.sureText || '确认'
 const otherBtnText = props.option.otherBtnText || ''
 const otherBtnText = props.option.otherBtnText || ''
+const autoCloseTime = props.option.autoCloseTime || 0
+
+// 自动关闭弹窗
+if (autoCloseTime && Number.isInteger(autoCloseTime) && autoCloseTime >= 1000) {
+  setTimeout(() => { props.cancel }, autoCloseTime)
+}
 // const show = () => {
 // const show = () => {
 //   dialog.value = true
 //   dialog.value = true
 // }
 // }