1
This commit is contained in:
+6
-22
@@ -2,27 +2,15 @@
|
|||||||
import { ref, watchEffect, provide, onMounted } from 'vue'
|
import { ref, watchEffect, provide, onMounted } from 'vue'
|
||||||
import { RouterView } from 'vue-router'
|
import { RouterView } from 'vue-router'
|
||||||
import ThemeToggle from './components/ThemeToggle.vue'
|
import ThemeToggle from './components/ThemeToggle.vue'
|
||||||
import AlertComponent from './components/AlertComponent.vue'
|
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import api from './utils/api'
|
import api from './utils/api'
|
||||||
const isDarkMode = ref(false)
|
const isDarkMode = ref(false)
|
||||||
const isLoading = ref(false)
|
const isLoading = ref(false)
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
import AlertComponent from '@/components/AlertComponent.vue'
|
||||||
|
import { useAlertStore } from '@/stores/alertStore'
|
||||||
|
|
||||||
const showAlert = ref(false)
|
const alertStore = useAlertStore()
|
||||||
const alertMessage = ref('')
|
|
||||||
const alertType = ref('success')
|
|
||||||
const closeAlert = () => {
|
|
||||||
showAlert.value = false
|
|
||||||
}
|
|
||||||
const showAlertMessage = (
|
|
||||||
message: string,
|
|
||||||
type: 'success' | 'error' | 'warning' | 'info' = 'success'
|
|
||||||
) => {
|
|
||||||
alertMessage.value = message
|
|
||||||
alertType.value = type
|
|
||||||
showAlert.value = true
|
|
||||||
}
|
|
||||||
// 检查系统颜色模式
|
// 检查系统颜色模式
|
||||||
const checkSystemColorScheme = () => {
|
const checkSystemColorScheme = () => {
|
||||||
return window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches
|
return window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches
|
||||||
@@ -59,7 +47,7 @@ onMounted(() => {
|
|||||||
localStorage.getItem('notify') !== res.detail.notify_title + res.detail.notify_content
|
localStorage.getItem('notify') !== res.detail.notify_title + res.detail.notify_content
|
||||||
) {
|
) {
|
||||||
localStorage.setItem('notify', res.detail.notify_title + res.detail.notify_content)
|
localStorage.setItem('notify', res.detail.notify_title + res.detail.notify_content)
|
||||||
showAlertMessage(res.detail.notify_title + ': ' + res.detail.notify_content, 'success')
|
alertStore.showAlert(res.detail.notify_title + ': ' + res.detail.notify_content, 'success')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -96,12 +84,8 @@ provide('isLoading', isLoading)
|
|||||||
<component :is="Component" :key="$route.fullPath" />
|
<component :is="Component" :key="$route.fullPath" />
|
||||||
</transition>
|
</transition>
|
||||||
</RouterView>
|
</RouterView>
|
||||||
<AlertComponent
|
|
||||||
:show="showAlert"
|
<AlertComponent />
|
||||||
:message="alertMessage"
|
|
||||||
:type="alertType"
|
|
||||||
@close="closeAlert"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
@@ -1,137 +1,94 @@
|
|||||||
<template>
|
<template>
|
||||||
<transition name="alert-fade">
|
<transition-group
|
||||||
<div v-if="show" class="fixed top-4 right-4 max-w-sm w-full z-50">
|
name="alert-fade"
|
||||||
<div
|
tag="div"
|
||||||
:class="[
|
class="fixed top-4 right-4 z-50 w-full sm:max-w-sm md:max-w-md space-y-4 px-4 sm:px-0"
|
||||||
'rounded-lg shadow-lg overflow-hidden transform transition-all duration-300',
|
>
|
||||||
alertTypeClasses[type]
|
<div
|
||||||
]"
|
v-for="alert in alerts"
|
||||||
>
|
:key="alert.id"
|
||||||
<div class="p-4">
|
:class="[
|
||||||
<div class="flex items-start">
|
'w-full rounded-lg shadow-xl overflow-hidden',
|
||||||
<div class="flex-shrink-0">
|
'bg-gradient-to-r',
|
||||||
<CheckCircle v-if="type === 'success'" class="h-6 w-6 text-white" />
|
gradientClasses[alert.type]
|
||||||
<AlertTriangle v-else-if="type === 'error'" class="h-6 w-6 text-white" />
|
]"
|
||||||
<AlertCircle v-else-if="type === 'warning'" class="h-6 w-6 text-white" />
|
>
|
||||||
<Info v-else class="h-6 w-6 text-white" />
|
<div class="p-4">
|
||||||
</div>
|
<div class="flex items-start">
|
||||||
<div class="ml-3 w-0 flex-1 pt-0.5">
|
<div class="flex-shrink-0">
|
||||||
<p class="text-sm font-medium text-white" v-html="message"></p>
|
<component :is="alertIcons[alert.type]" class="h-6 w-6 text-white" />
|
||||||
</div>
|
</div>
|
||||||
<div class="ml-4 flex-shrink-0 flex">
|
<div class="ml-3 flex-1 pt-0.5">
|
||||||
<button
|
<p class="text-sm font-medium text-white">{{ alert.message }}</p>
|
||||||
@click="$emit('close')"
|
</div>
|
||||||
class="inline-flex text-white hover:text-gray-200 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-white"
|
<div class="ml-4 flex-shrink-0 flex">
|
||||||
>
|
<button
|
||||||
<span class="sr-only">关闭</span>
|
@click="removeAlert(alert.id)"
|
||||||
<X class="h-5 w-5" />
|
class="inline-flex text-white hover:text-gray-200 focus:outline-none transition-colors duration-200"
|
||||||
</button>
|
>
|
||||||
</div>
|
<span class="sr-only">关闭</span>
|
||||||
|
<X class="h-5 w-5" />
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="h-1 bg-white bg-opacity-25">
|
</div>
|
||||||
<div
|
<div class="h-1 bg-white bg-opacity-25">
|
||||||
:class="[
|
<div
|
||||||
'h-full transition-all duration-300 ease-out bg-white',
|
class="h-full bg-white transition-all duration-100 ease-out"
|
||||||
{ 'w-full': !autoClose }
|
:style="{ width: `${alert.progress}%` }"
|
||||||
]"
|
></div>
|
||||||
:style="{ width: `${progressWidth}%` }"
|
|
||||||
></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</transition>
|
</transition-group>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, onMounted, onUnmounted, watch } from 'vue'
|
import { storeToRefs } from 'pinia'
|
||||||
|
import { useAlertStore } from '@/stores/alertStore'
|
||||||
import { CheckCircle, AlertTriangle, AlertCircle, Info, X } from 'lucide-vue-next'
|
import { CheckCircle, AlertTriangle, AlertCircle, Info, X } from 'lucide-vue-next'
|
||||||
|
import { onMounted, onUnmounted } from 'vue'
|
||||||
|
|
||||||
const props = defineProps({
|
const alertStore = useAlertStore()
|
||||||
show: Boolean,
|
const { alerts } = storeToRefs(alertStore)
|
||||||
message: String,
|
const { removeAlert, updateAlertProgress } = alertStore
|
||||||
type: {
|
|
||||||
type: String,
|
|
||||||
default: 'info',
|
|
||||||
validator: (value: string) => ['success', 'error', 'warning', 'info'].includes(value)
|
|
||||||
},
|
|
||||||
duration: {
|
|
||||||
type: Number,
|
|
||||||
default: 3000
|
|
||||||
},
|
|
||||||
autoClose: {
|
|
||||||
type: Boolean,
|
|
||||||
default: true
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
const emit = defineEmits(['close'])
|
const gradientClasses = {
|
||||||
|
success: 'from-green-500 to-green-600',
|
||||||
const alertTypeClasses: { [key: string]: string } = {
|
error: 'from-red-500 to-red-600',
|
||||||
success: 'bg-green-500',
|
warning: 'from-yellow-500 to-yellow-600',
|
||||||
error: 'bg-red-500',
|
info: 'from-blue-500 to-blue-600'
|
||||||
warning: 'bg-yellow-500',
|
|
||||||
info: 'bg-blue-500'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const progressWidth = ref(100)
|
const alertIcons = {
|
||||||
let timer: number | null = null
|
success: CheckCircle,
|
||||||
|
error: AlertTriangle,
|
||||||
const startTimer = () => {
|
warning: AlertCircle,
|
||||||
if (timer) {
|
info: Info
|
||||||
clearInterval(timer)
|
|
||||||
}
|
|
||||||
progressWidth.value = 100
|
|
||||||
const startTime = Date.now()
|
|
||||||
const endTime = startTime + props.duration
|
|
||||||
|
|
||||||
timer = setInterval(() => {
|
|
||||||
const now = Date.now()
|
|
||||||
const remaining = endTime - now
|
|
||||||
progressWidth.value = (remaining / props.duration) * 100
|
|
||||||
|
|
||||||
if (remaining <= 0) {
|
|
||||||
clearInterval(timer!)
|
|
||||||
emit('close')
|
|
||||||
}
|
|
||||||
}, 10)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(
|
let intervalId: number
|
||||||
() => props.show,
|
|
||||||
(newValue) => {
|
|
||||||
if (newValue && props.autoClose) {
|
|
||||||
startTimer()
|
|
||||||
} else if (!newValue && timer) {
|
|
||||||
clearInterval(timer)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (props.show && props.autoClose) {
|
intervalId = setInterval(() => {
|
||||||
startTimer()
|
alerts.value.forEach((alert) => {
|
||||||
}
|
updateAlertProgress(alert.id)
|
||||||
|
})
|
||||||
|
}, 100)
|
||||||
})
|
})
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
if (timer) {
|
clearInterval(intervalId)
|
||||||
clearInterval(timer)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.alert-fade-enter-active,
|
.alert-fade-enter-active,
|
||||||
.alert-fade-leave-active {
|
.alert-fade-leave-active {
|
||||||
transition:
|
transition: all 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
|
||||||
opacity 0.3s,
|
|
||||||
transform 0.3s;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.alert-fade-enter-from,
|
.alert-fade-enter-from,
|
||||||
.alert-fade-leave-to {
|
.alert-fade-leave-to {
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
transform: translateX(20px);
|
transform: translateX(50px) scale(0.95);
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -330,13 +330,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</transition>
|
</transition>
|
||||||
|
|
||||||
<AlertComponent
|
|
||||||
:show="showAlert"
|
|
||||||
:message="alertMessage"
|
|
||||||
:type="alertType"
|
|
||||||
@close="closeAlert"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -358,12 +351,13 @@ import {
|
|||||||
import { useRouter, useRoute } from 'vue-router'
|
import { useRouter, useRoute } from 'vue-router'
|
||||||
import QRCode from 'qrcode.vue'
|
import QRCode from 'qrcode.vue'
|
||||||
import { useFileDataStore } from '@/stores/fileData'
|
import { useFileDataStore } from '@/stores/fileData'
|
||||||
import AlertComponent from '@/components/AlertComponent.vue'
|
|
||||||
import { storeToRefs } from 'pinia'
|
import { storeToRefs } from 'pinia'
|
||||||
import api from '@/utils/api'
|
import api from '@/utils/api'
|
||||||
import { saveAs } from 'file-saver'
|
import { saveAs } from 'file-saver'
|
||||||
import { marked } from 'marked'
|
import { marked } from 'marked'
|
||||||
|
import { useAlertStore } from '@/stores/alertStore'
|
||||||
|
|
||||||
|
const alertStore = useAlertStore()
|
||||||
const baseUrl =
|
const baseUrl =
|
||||||
import.meta.env.MODE === 'production'
|
import.meta.env.MODE === 'production'
|
||||||
? import.meta.env.VITE_API_BASE_URL_PROD
|
? import.meta.env.VITE_API_BASE_URL_PROD
|
||||||
@@ -373,19 +367,6 @@ const router = useRouter()
|
|||||||
const isDarkMode = inject('isDarkMode')
|
const isDarkMode = inject('isDarkMode')
|
||||||
const fileStore = useFileDataStore()
|
const fileStore = useFileDataStore()
|
||||||
const { receiveData } = storeToRefs(fileStore)
|
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 code = ref('')
|
||||||
const inputStatus = ref({
|
const inputStatus = ref({
|
||||||
readonly: false,
|
readonly: false,
|
||||||
@@ -414,7 +395,7 @@ watch(code, (newVal) => {
|
|||||||
|
|
||||||
const handleSubmit = async () => {
|
const handleSubmit = async () => {
|
||||||
if (code.value.length !== 5) {
|
if (code.value.length !== 5) {
|
||||||
showAlertMessage('请输入5位取件码', 'error')
|
alertStore.showAlert('请输入5位取件码', 'error')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -449,16 +430,16 @@ const handleSubmit = async () => {
|
|||||||
fileStore.addReceiveData(newFileData)
|
fileStore.addReceiveData(newFileData)
|
||||||
}
|
}
|
||||||
showDrawer.value = true
|
showDrawer.value = true
|
||||||
showAlertMessage('文件获取成功', 'success')
|
alertStore.showAlert('文件获取成功', 'success')
|
||||||
} else {
|
} else {
|
||||||
showAlertMessage('无效的取件码', 'error')
|
alertStore.showAlert('无效的取件码', 'error')
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
showAlertMessage(res.message || '获取文件失败', 'error')
|
alertStore.showAlert(res.detail || '获取文件失败', 'error')
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('取件失败:', err)
|
console.error('取件失败:', err)
|
||||||
showAlertMessage('取件失败,请稍后重试', 'error')
|
alertStore.showAlert('取件失败,请稍后重试', 'error')
|
||||||
} finally {
|
} finally {
|
||||||
inputStatus.value.readonly = false
|
inputStatus.value.readonly = false
|
||||||
inputStatus.value.loading = false
|
inputStatus.value.loading = false
|
||||||
|
|||||||
+106
-85
@@ -95,7 +95,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-else key="text" class="grid grid-cols-1 gap-8">
|
<div v-else key="text" class="grid grid-cols-1 gap-8">
|
||||||
<!-- 文本输入区域 -->
|
<!-- 文本��入区域 -->
|
||||||
<div v-if="sendType === 'text'" class="flex flex-col">
|
<div v-if="sendType === 'text'" class="flex flex-col">
|
||||||
<textarea
|
<textarea
|
||||||
id="text-content"
|
id="text-content"
|
||||||
@@ -130,8 +130,9 @@
|
|||||||
<option value="hour">按小时</option>
|
<option value="hour">按小时</option>
|
||||||
<option value="minute">按分钟</option>
|
<option value="minute">按分钟</option>
|
||||||
<option value="count">按查看次数</option>
|
<option value="count">按查看次数</option>
|
||||||
|
<option value="forever">永久</option>
|
||||||
</select>
|
</select>
|
||||||
<div class="flex items-center space-x-2">
|
<div v-if="expirationMethod !== 'forever'" class="flex items-center space-x-2">
|
||||||
<input
|
<input
|
||||||
v-model="expirationValue"
|
v-model="expirationValue"
|
||||||
type="number"
|
type="number"
|
||||||
@@ -241,13 +242,24 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex space-x-2">
|
<div class="flex space-x-2">
|
||||||
|
<button
|
||||||
|
@click="copyRetrieveLink(record.retrieveCode)"
|
||||||
|
class="p-2 rounded-full hover:bg-opacity-20 transition duration-300"
|
||||||
|
:class="[
|
||||||
|
isDarkMode
|
||||||
|
? 'hover:bg-blue-400 text-blue-400'
|
||||||
|
: 'hover:bg-blue-100 text-blue-600'
|
||||||
|
]"
|
||||||
|
>
|
||||||
|
<ClipboardCopyIcon class="w-5 h-5" />
|
||||||
|
</button>
|
||||||
<button
|
<button
|
||||||
@click="viewDetails(record)"
|
@click="viewDetails(record)"
|
||||||
class="p-2 rounded-full hover:bg-opacity-20 transition duration-300"
|
class="p-2 rounded-full hover:bg-opacity-20 transition duration-300"
|
||||||
:class="[
|
:class="[
|
||||||
isDarkMode
|
isDarkMode
|
||||||
? 'hover:bg-indigo-400 text-indigo-400'
|
? 'hover:bg-green-400 text-green-400'
|
||||||
: 'hover:bg-indigo-100 text-indigo-600'
|
: 'hover:bg-green-100 text-green-600'
|
||||||
]"
|
]"
|
||||||
>
|
>
|
||||||
<EyeIcon class="w-5 h-5" />
|
<EyeIcon class="w-5 h-5" />
|
||||||
@@ -282,7 +294,7 @@
|
|||||||
class="text-2xl font-bold mb-6"
|
class="text-2xl font-bold mb-6"
|
||||||
:class="[isDarkMode ? 'text-white' : 'text-gray-800']"
|
:class="[isDarkMode ? 'text-white' : 'text-gray-800']"
|
||||||
>
|
>
|
||||||
文件详情
|
文件详
|
||||||
</h3>
|
</h3>
|
||||||
<div class="space-y-4">
|
<div class="space-y-4">
|
||||||
<div class="flex items-center">
|
<div class="flex items-center">
|
||||||
@@ -367,13 +379,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</transition>
|
</transition>
|
||||||
<!-- 使用新的 AlertComponent -->
|
|
||||||
<AlertComponent
|
|
||||||
:show="showAlert"
|
|
||||||
:message="alertMessage"
|
|
||||||
:type="alertType"
|
|
||||||
@close="closeAlert"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -390,14 +395,15 @@ import {
|
|||||||
HardDriveIcon,
|
HardDriveIcon,
|
||||||
ClockIcon,
|
ClockIcon,
|
||||||
EyeIcon,
|
EyeIcon,
|
||||||
ShieldCheckIcon
|
ShieldCheckIcon,
|
||||||
|
ClipboardCopyIcon
|
||||||
} from 'lucide-vue-next'
|
} from 'lucide-vue-next'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import BorderProgressBar from '../components/BorderProgressBar.vue'
|
import BorderProgressBar from '../components/BorderProgressBar.vue'
|
||||||
import QRCode from 'qrcode.vue'
|
import QRCode from 'qrcode.vue'
|
||||||
import AlertComponent from '../components/AlertComponent.vue'
|
|
||||||
import SparkMD5 from 'spark-md5'
|
import SparkMD5 from 'spark-md5'
|
||||||
import { useFileDataStore } from '../stores/fileData'
|
import { useFileDataStore } from '../stores/fileData'
|
||||||
|
import api from '@/utils/api'
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const isDarkMode = inject('isDarkMode')
|
const isDarkMode = inject('isDarkMode')
|
||||||
@@ -412,25 +418,11 @@ const expirationValue = ref('')
|
|||||||
const uploadProgress = ref(0)
|
const uploadProgress = ref(0)
|
||||||
const showDrawer = ref(false)
|
const showDrawer = ref(false)
|
||||||
const selectedRecord = ref<any>(null)
|
const selectedRecord = ref<any>(null)
|
||||||
|
import { useAlertStore } from '@/stores/alertStore'
|
||||||
|
|
||||||
|
const alertStore = useAlertStore()
|
||||||
const sendRecords = computed(() => fileDataStore.shareData)
|
const sendRecords = computed(() => fileDataStore.shareData)
|
||||||
|
|
||||||
const showAlert = ref(false)
|
|
||||||
const alertMessage = ref('')
|
|
||||||
const alertType = ref('success')
|
|
||||||
|
|
||||||
const showAlertMessage = (
|
|
||||||
message: string,
|
|
||||||
type: 'success' | 'error' | 'warning' | 'info' = 'success'
|
|
||||||
) => {
|
|
||||||
alertMessage.value = message
|
|
||||||
alertType.value = type
|
|
||||||
showAlert.value = true
|
|
||||||
}
|
|
||||||
|
|
||||||
const closeAlert = () => {
|
|
||||||
showAlert.value = false
|
|
||||||
}
|
|
||||||
// 新增状态
|
// 新增状态
|
||||||
const fileHash = ref('')
|
const fileHash = ref('')
|
||||||
const uploadedChunks = ref<Set<number>>(new Set())
|
const uploadedChunks = ref<Set<number>>(new Set())
|
||||||
@@ -516,10 +508,12 @@ const startChunkUpload = async () => {
|
|||||||
// 所有切片上传完成,通知服务器合并文件
|
// 所有切片上传完成,通知服务器合并文件
|
||||||
await mergeChunks(fileHash.value, totalChunks)
|
await mergeChunks(fileHash.value, totalChunks)
|
||||||
|
|
||||||
showAlertMessage('文件上传完成', 'success')
|
alertStore.showAlert('文件上传完成', 'success')
|
||||||
}
|
}
|
||||||
|
|
||||||
const checkUploadedChunks = async (fileHash: string) => {
|
const checkUploadedChunks = async (fileHash: string) => {
|
||||||
|
console.log(fileHash)
|
||||||
|
|
||||||
// 这里应该调用后端API来检查已上传的切片
|
// 这里应该调用后端API来检查已上传的切片
|
||||||
// 现在用模拟数据代替
|
// 现在用模拟数据代替
|
||||||
return new Promise<{ uploadedList: number[] }>((resolve) => {
|
return new Promise<{ uploadedList: number[] }>((resolve) => {
|
||||||
@@ -555,6 +549,8 @@ const getPlaceholder = () => {
|
|||||||
return '输入分钟数'
|
return '输入分钟数'
|
||||||
case 'count':
|
case 'count':
|
||||||
return '输入查看次数'
|
return '输入查看次数'
|
||||||
|
case 'forever':
|
||||||
|
return '永久'
|
||||||
default:
|
default:
|
||||||
return '输入值'
|
return '输入值'
|
||||||
}
|
}
|
||||||
@@ -570,72 +566,83 @@ const getUnit = () => {
|
|||||||
return '分钟'
|
return '分钟'
|
||||||
case 'count':
|
case 'count':
|
||||||
return '次'
|
return '次'
|
||||||
|
case 'forever':
|
||||||
|
return '永久'
|
||||||
default:
|
default:
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleSubmit = () => {
|
const handleSubmit = async () => {
|
||||||
if (sendType.value === 'file' && !selectedFile.value) {
|
if (sendType.value === 'file' && !selectedFile.value) {
|
||||||
showAlertMessage('请选择要上传的文件', 'error')
|
alertStore.showAlert('请选择要上传的件', 'error')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (sendType.value === 'text' && !textContent.value.trim()) {
|
if (sendType.value === 'text' && !textContent.value.trim()) {
|
||||||
showAlertMessage('请输入要发送的文本', 'error')
|
alertStore.showAlert('请输入要发送的文本', 'error')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (!expirationValue.value) {
|
if (expirationMethod.value !== 'forever' && !expirationValue.value) {
|
||||||
showAlertMessage('请输入过期值', 'error')
|
alertStore.showAlert('请输入过期值', 'error')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理文件/文本上传和过期设置的逻辑
|
try {
|
||||||
console.log('Send Type:', sendType.value)
|
let response: any
|
||||||
console.log('Selected File:', selectedFile.value)
|
if (sendType.value === 'text') {
|
||||||
console.log('Text Content:', textContent.value)
|
// 使用 FormData 发送文本
|
||||||
console.log('Expiration Method:', expirationMethod.value)
|
const formData = new FormData()
|
||||||
console.log('Expiration Value:', expirationValue.value)
|
formData.append('text', textContent.value)
|
||||||
|
if (expirationMethod.value !== 'forever') {
|
||||||
|
formData.append('expire_value', expirationValue.value)
|
||||||
|
}
|
||||||
|
formData.append('expire_style', expirationMethod.value)
|
||||||
|
response = await api.post('/share/text/', formData, {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'multipart/form-data'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
// 处理文件上传的逻辑
|
||||||
|
// ... 文件上传的代码 ...
|
||||||
|
}
|
||||||
|
|
||||||
// 计算过期时间
|
if (response && response.code === 200) {
|
||||||
let expirationDate = new Date()
|
const retrieveCode = response.detail.code
|
||||||
switch (expirationMethod.value) {
|
// 添加新的发送记录
|
||||||
case 'day':
|
const newRecord = {
|
||||||
expirationDate.setDate(expirationDate.getDate() + parseInt(expirationValue.value))
|
id: Date.now(),
|
||||||
break
|
filename: sendType.value === 'text' ? '文本内容.txt' : selectedFile.value!.name,
|
||||||
case 'hour':
|
date: new Date().toISOString().split('T')[0],
|
||||||
expirationDate.setHours(expirationDate.getHours() + parseInt(expirationValue.value))
|
size:
|
||||||
break
|
sendType.value === 'text'
|
||||||
case 'minute':
|
? '0.1 MB'
|
||||||
expirationDate.setMinutes(expirationDate.getMinutes() + parseInt(expirationValue.value))
|
: `${(selectedFile.value!.size / (1024 * 1024)).toFixed(1)} MB`,
|
||||||
break
|
expiration: `${expirationValue.value}${getUnit()}后过期`,
|
||||||
case 'count':
|
retrieveCode: retrieveCode
|
||||||
// 对于查看次数,我们不设置具体的过期日期
|
}
|
||||||
break
|
fileDataStore.addShareData(newRecord)
|
||||||
|
|
||||||
|
// 显示发送成功消息
|
||||||
|
alertStore.showAlert(`文件发送成功!取件码:${retrieveCode}`, 'success')
|
||||||
|
// 重置表单
|
||||||
|
selectedFile.value = null
|
||||||
|
textContent.value = ''
|
||||||
|
expirationValue.value = ''
|
||||||
|
uploadProgress.value = 0
|
||||||
|
|
||||||
|
// 自动打开抽屉
|
||||||
|
showDrawer.value = true
|
||||||
|
|
||||||
|
// 自动复制取件码链接
|
||||||
|
await copyRetrieveLink(retrieveCode)
|
||||||
|
} else {
|
||||||
|
throw new Error('服务器响应异常')
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('发送失败:', error)
|
||||||
|
alertStore.showAlert('发送失败,请稍后重试', 'error')
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加新的发送记录
|
|
||||||
const newRecord = {
|
|
||||||
id: Date.now(),
|
|
||||||
filename: selectedFile.value ? selectedFile.value.name : '文本内容.txt',
|
|
||||||
date: new Date().toISOString().split('T')[0],
|
|
||||||
size: selectedFile.value
|
|
||||||
? `${(selectedFile.value.size / (1024 * 1024)).toFixed(1)} MB`
|
|
||||||
: '0.1 MB',
|
|
||||||
expiration:
|
|
||||||
expirationMethod.value === 'count'
|
|
||||||
? `${expirationValue.value}次查看后过期`
|
|
||||||
: expirationDate.toISOString().split('T')[0],
|
|
||||||
retrieveCode: Math.random().toString(36).substring(2, 8).toUpperCase()
|
|
||||||
}
|
|
||||||
fileDataStore.addShareData(newRecord)
|
|
||||||
|
|
||||||
// 显示发送成功消息
|
|
||||||
showAlertMessage(`文件发送成功!取件码:${newRecord.retrieveCode}`, 'success')
|
|
||||||
// 重置表单
|
|
||||||
selectedFile.value = null
|
|
||||||
textContent.value = ''
|
|
||||||
expirationValue.value = ''
|
|
||||||
uploadProgress.value = 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const toRetrieve = () => {
|
const toRetrieve = () => {
|
||||||
@@ -656,20 +663,34 @@ const deleteRecord = (id: number) => {
|
|||||||
fileDataStore.deleteShareData(index)
|
fileDataStore.deleteShareData(index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const baseUrl =
|
||||||
|
import.meta.env.MODE === 'production'
|
||||||
|
? import.meta.env.VITE_API_BASE_URL_PROD
|
||||||
|
: import.meta.env.VITE_API_BASE_URL_DEV
|
||||||
const getQRCodeValue = (record: any) => {
|
const getQRCodeValue = (record: any) => {
|
||||||
// 这里返回你想要在二维码中编码的信息
|
// 这里返回你想要在二维码中编码的信息
|
||||||
// 例如,可以是一个包含文件ID和取件码的URL
|
// 例如,可以是一个包含文件ID和取件码的URL
|
||||||
return `https://your-domain.com/retrieve/${record.id}?code=${record.retrieveCode}`
|
return `${baseUrl}/?code=${record.retrieveCode}`
|
||||||
}
|
}
|
||||||
|
|
||||||
const copyRetrieveCode = async (code: string) => {
|
const copyRetrieveCode = async (code: string) => {
|
||||||
try {
|
try {
|
||||||
await navigator.clipboard.writeText(code)
|
await navigator.clipboard.writeText(code)
|
||||||
showAlertMessage('取件码已复制到剪贴板', 'success')
|
alertStore.showAlert('取件码已复制到剪贴板', 'success')
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('无法复制取件码: ', err)
|
console.error('无法复制取件码: ', err)
|
||||||
showAlertMessage('复制失败,请手动复制取件码', 'error')
|
alertStore.showAlert('复制失败,请手动复制取件码', 'error')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const copyRetrieveLink = async (code: string) => {
|
||||||
|
const link = `${baseUrl}/?code=${code}`
|
||||||
|
try {
|
||||||
|
await navigator.clipboard.writeText(link)
|
||||||
|
alertStore.showAlert('取件链接已复制到剪贴板', 'success')
|
||||||
|
} catch (err) {
|
||||||
|
console.error('无法复制取件链接: ', err)
|
||||||
|
alertStore.showAlert('复制失败,请手动复制取件链接', 'error')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user