-
-
-
-
-
-
-
-
+
+
-
+
diff --git a/src/stores/alertStore.ts b/src/stores/alertStore.ts
new file mode 100644
index 0000000..a25d102
--- /dev/null
+++ b/src/stores/alertStore.ts
@@ -0,0 +1,45 @@
+import { defineStore } from 'pinia'
+
+interface Alert {
+ id: number
+ message: string
+ type: 'success' | 'error' | 'warning' | 'info'
+ progress: number
+ duration: number
+ startTime: number
+}
+
+export const useAlertStore = defineStore('alert', {
+ state: () => ({
+ alerts: [] as Alert[]
+ }),
+ actions: {
+ showAlert(
+ message: string,
+ type: 'success' | 'error' | 'warning' | 'info' = 'info',
+ duration = 5000
+ ) {
+ const id = Date.now()
+ const startTime = Date.now()
+ this.alerts.push({ id, message, type, progress: 100, duration, startTime })
+ setTimeout(() => this.removeAlert(id), duration)
+ },
+ removeAlert(id: number) {
+ const index = this.alerts.findIndex((alert) => alert.id === id)
+ if (index > -1) {
+ this.alerts.splice(index, 1)
+ }
+ },
+ updateAlertProgress(id: number) {
+ const alert = this.alerts.find((a) => a.id === id)
+ if (alert) {
+ const elapsedTime = Date.now() - alert.startTime
+ const progress = 100 - (elapsedTime / alert.duration) * 100
+ alert.progress = Math.max(0, progress)
+ if (alert.progress <= 0) {
+ this.removeAlert(id)
+ }
+ }
+ }
+ }
+})
diff --git a/src/views/RetrievewFileView.vue b/src/views/RetrievewFileView.vue
index b59f9f3..664639f 100644
--- a/src/views/RetrievewFileView.vue
+++ b/src/views/RetrievewFileView.vue
@@ -330,13 +330,6 @@
-
-
@@ -358,12 +351,13 @@ import {
import { useRouter, useRoute } from 'vue-router'
import QRCode from 'qrcode.vue'
import { useFileDataStore } from '@/stores/fileData'
-import AlertComponent from '@/components/AlertComponent.vue'
import { storeToRefs } from 'pinia'
import api from '@/utils/api'
import { saveAs } from 'file-saver'
import { marked } from 'marked'
+import { useAlertStore } from '@/stores/alertStore'
+const alertStore = useAlertStore()
const baseUrl =
import.meta.env.MODE === 'production'
? import.meta.env.VITE_API_BASE_URL_PROD
@@ -373,19 +367,6 @@ const router = useRouter()
const isDarkMode = inject('isDarkMode')
const fileStore = useFileDataStore()
const { receiveData } = storeToRefs(fileStore)
-const showAlert = ref(false)
-const alertMessage = ref('')
-const alertType = ref('success')
-
-const showAlertMessage = (message, type) => {
- alertMessage.value = message
- alertType.value = type
- showAlert.value = true
-}
-
-const closeAlert = () => {
- showAlert.value = false
-}
const code = ref('')
const inputStatus = ref({
readonly: false,
@@ -414,7 +395,7 @@ watch(code, (newVal) => {
const handleSubmit = async () => {
if (code.value.length !== 5) {
- showAlertMessage('请输入5位取件码', 'error')
+ alertStore.showAlert('请输入5位取件码', 'error')
return
}
@@ -449,16 +430,16 @@ const handleSubmit = async () => {
fileStore.addReceiveData(newFileData)
}
showDrawer.value = true
- showAlertMessage('文件获取成功', 'success')
+ alertStore.showAlert('文件获取成功', 'success')
} else {
- showAlertMessage('无效的取件码', 'error')
+ alertStore.showAlert('无效的取件码', 'error')
}
} else {
- showAlertMessage(res.message || '获取文件失败', 'error')
+ alertStore.showAlert(res.detail || '获取文件失败', 'error')
}
} catch (err) {
console.error('取件失败:', err)
- showAlertMessage('取件失败,请稍后重试', 'error')
+ alertStore.showAlert('取件失败,请稍后重试', 'error')
} finally {
inputStatus.value.readonly = false
inputStatus.value.loading = false
diff --git a/src/views/SendFileView.vue b/src/views/SendFileView.vue
index d59ebd8..4c3c964 100644
--- a/src/views/SendFileView.vue
+++ b/src/views/SendFileView.vue
@@ -95,7 +95,7 @@