feat: 优化上传检查

This commit is contained in:
Lan
2025-03-02 15:14:18 +08:00
parent 1521aa5d94
commit 7b10de0ab1
+129 -215
View File
@@ -1,49 +1,32 @@
<template> <template>
<div <div class="min-h-screen flex items-center justify-center p-4 overflow-hidden transition-colors duration-300"
class="min-h-screen flex items-center justify-center p-4 overflow-hidden transition-colors duration-300" @paste.prevent="handlePaste">
@paste.prevent="handlePaste" <div class="rounded-3xl shadow-2xl overflow-hidden border w-full max-w-md transition-colors duration-300" :class="[
> isDarkMode
<div ? 'bg-white bg-opacity-10 backdrop-filter backdrop-blur-xl border-gray-700'
class="rounded-3xl shadow-2xl overflow-hidden border w-full max-w-md transition-colors duration-300" : 'bg-white border-gray-200'
:class="[ ]">
isDarkMode
? 'bg-white bg-opacity-10 backdrop-filter backdrop-blur-xl border-gray-700'
: 'bg-white border-gray-200'
]"
>
<div class="p-8"> <div class="p-8">
<h2 <h2 class="text-3xl font-extrabold text-center mb-8 cursor-pointer transition-colors duration-300" :class="[
class="text-3xl font-extrabold text-center mb-8 cursor-pointer transition-colors duration-300" isDarkMode
:class="[ ? 'text-transparent bg-clip-text bg-gradient-to-r from-indigo-300 via-purple-300 to-pink-300'
isDarkMode : 'text-indigo-600'
? 'text-transparent bg-clip-text bg-gradient-to-r from-indigo-300 via-purple-300 to-pink-300' ]" @click="toRetrieve">
: 'text-indigo-600'
]"
@click="toRetrieve"
>
{{ config.name }} {{ config.name }}
</h2> </h2>
<form @submit.prevent="handleSubmit" class="space-y-8"> <form @submit.prevent="handleSubmit" class="space-y-8">
<!-- 发送类型选择 --> <!-- 发送类型选择 -->
<div class="flex justify-center space-x-4 mb-6"> <div class="flex justify-center space-x-4 mb-6">
<button <button type="button" @click="sendType = 'file'" :class="[
type="button" 'px-4 py-2 rounded-lg',
@click="sendType = 'file'" sendType === 'file' ? 'bg-indigo-600 text-white' : 'bg-gray-700 text-gray-300'
:class="[ ]">
'px-4 py-2 rounded-lg',
sendType === 'file' ? 'bg-indigo-600 text-white' : 'bg-gray-700 text-gray-300'
]"
>
发送文件 发送文件
</button> </button>
<button <button type="button" @click="sendType = 'text'" :class="[
type="button" 'px-4 py-2 rounded-lg',
@click="sendType = 'text'" sendType === 'text' ? 'bg-indigo-600 text-white' : 'bg-gray-700 text-gray-300'
:class="[ ]">
'px-4 py-2 rounded-lg',
sendType === 'text' ? 'bg-indigo-600 text-white' : 'bg-gray-700 text-gray-300'
]"
>
发送文本 发送文本
</button> </button>
<!-- <button <!-- <button
@@ -67,37 +50,23 @@
isDarkMode isDarkMode
? 'bg-gray-800 bg-opacity-50 border-gray-600 hover:border-indigo-500' ? 'bg-gray-800 bg-opacity-50 border-gray-600 hover:border-indigo-500'
: 'bg-gray-100 border-gray-300 hover:border-indigo-500' : 'bg-gray-100 border-gray-300 hover:border-indigo-500'
]" ]" @click="triggerFileUpload" @dragover.prevent @drop.prevent="handleFileDrop">
@click="triggerFileUpload" <input id="file-upload" type="file" class="hidden" @change="handleFileUpload" ref="fileInput" />
@dragover.prevent
@drop.prevent="handleFileDrop"
>
<input
id="file-upload"
type="file"
class="hidden"
@change="handleFileUpload"
ref="fileInput"
/>
<div class="absolute inset-0 w-full h-full" v-if="uploadProgress > 0"> <div class="absolute inset-0 w-full h-full" v-if="uploadProgress > 0">
<BorderProgressBar :progress="uploadProgress" /> <BorderProgressBar :progress="uploadProgress" />
</div> </div>
<UploadCloudIcon <UploadCloudIcon :class="[
:class="[ 'w-16 h-16 transition-colors duration-300',
'w-16 h-16 transition-colors duration-300', isDarkMode
isDarkMode ? 'text-gray-400 group-hover:text-indigo-400'
? 'text-gray-400 group-hover:text-indigo-400' : 'text-gray-600 group-hover:text-indigo-600'
: 'text-gray-600 group-hover:text-indigo-600' ]" />
]" <p :class="[
/> 'mt-4 text-sm transition-colors duration-300 w-full text-center',
<p isDarkMode
:class="[ ? 'text-gray-400 group-hover:text-indigo-400'
'mt-4 text-sm transition-colors duration-300 w-full text-center', : 'text-gray-600 group-hover:text-indigo-600'
isDarkMode ]">
? 'text-gray-400 group-hover:text-indigo-400'
: 'text-gray-600 group-hover:text-indigo-600'
]"
>
<span class="block truncate"> <span class="block truncate">
{{ selectedFile ? selectedFile.name : '点击或拖放文件到此处上传' }} {{ selectedFile ? selectedFile.name : '点击或拖放文件到此处上传' }}
</span> </span>
@@ -110,18 +79,12 @@
<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" v-model="textContent" rows="7" :class="[
id="text-content" 'flex-grow px-4 py-3 rounded-xl placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-indigo-500 transition duration-300 resize-none',
v-model="textContent" isDarkMode
rows="7" ? 'bg-gray-800 bg-opacity-50 text-white'
:class="[ : 'bg-white text-gray-900 border border-gray-300'
'flex-grow px-4 py-3 rounded-xl placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-indigo-500 transition duration-300 resize-none', ]" placeholder="在此输入要发送的文本..."></textarea>
isDarkMode
? 'bg-gray-800 bg-opacity-50 text-white'
: 'bg-white text-gray-900 border border-gray-300'
]"
placeholder="在此输入要发送的文本..."
></textarea>
</div> </div>
</div> </div>
</transition> </transition>
@@ -130,51 +93,38 @@
<label :class="['text-sm font-medium', isDarkMode ? 'text-gray-300' : 'text-gray-700']"> <label :class="['text-sm font-medium', isDarkMode ? 'text-gray-300' : 'text-gray-700']">
过期方式 过期方式
</label> </label>
<select <select v-model="expirationMethod" :class="[
v-model="expirationMethod" 'px-4 py-2 rounded-xl focus:outline-none focus:ring-2 focus:ring-indigo-500',
:class="[ isDarkMode
'px-4 py-2 rounded-xl focus:outline-none focus:ring-2 focus:ring-indigo-500', ? 'bg-gray-800 bg-opacity-50 text-white'
isDarkMode : 'bg-white text-gray-900 border border-gray-300'
? 'bg-gray-800 bg-opacity-50 text-white' ]">
: 'bg-white text-gray-900 border border-gray-300'
]"
>
<option v-for="item in config.expireStyle" :value="item" :key="item"> <option v-for="item in config.expireStyle" :value="item" :key="item">
{{ getUnit(item) }} {{ getUnit(item) }}
</option> </option>
</select> </select>
<div v-if="expirationMethod !== 'forever'" class="flex items-center space-x-2"> <div v-if="expirationMethod !== 'forever'" class="flex items-center space-x-2">
<div class="relative flex-grow"> <div class="relative flex-grow">
<input <input v-model="expirationValue" type="number" :placeholder="getPlaceholder()" :class="[
v-model="expirationValue" 'w-full px-4 py-2 pr-16 rounded-xl placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-indigo-500',
type="number" isDarkMode
:placeholder="getPlaceholder()" ? 'bg-gray-800 bg-opacity-50 text-white'
:class="[ : 'bg-white text-gray-900 border border-gray-300'
'w-full px-4 py-2 pr-16 rounded-xl placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-indigo-500', ]" />
isDarkMode <span :class="[
? 'bg-gray-800 bg-opacity-50 text-white' 'absolute right-3 top-1/2 transform -translate-y-1/2',
: 'bg-white text-gray-900 border border-gray-300' isDarkMode ? 'text-gray-300' : 'text-gray-700'
]" ]">
/>
<span
:class="[
'absolute right-3 top-1/2 transform -translate-y-1/2',
isDarkMode ? 'text-gray-300' : 'text-gray-700'
]"
>
{{ getUnit() }} {{ getUnit() }}
</span> </span>
</div> </div>
</div> </div>
</div> </div>
<!-- 提交按钮 --> <!-- 提交按钮 -->
<button <button type="submit"
type="submit" class="w-full bg-gradient-to-r from-indigo-500 via-purple-500 to-pink-500 text-white font-bold py-4 px-6 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-500 focus:ring-opacity-50 transition-all duration-300 transform hover:scale-105 hover:shadow-lg relative overflow-hidden group">
class="w-full bg-gradient-to-r from-indigo-500 via-purple-500 to-pink-500 text-white font-bold py-4 px-6 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-500 focus:ring-opacity-50 transition-all duration-300 transform hover:scale-105 hover:shadow-lg relative overflow-hidden group"
>
<span <span
class="absolute top-0 left-0 w-full h-full bg-white opacity-0 group-hover:opacity-20 transition-opacity duration-300" class="absolute top-0 left-0 w-full h-full bg-white opacity-0 group-hover:opacity-20 transition-opacity duration-300"></span>
></span>
<span class="relative z-10 flex items-center justify-center text-lg"> <span class="relative z-10 flex items-center justify-center text-lg">
<SendIcon class="w-6 h-6 mr-2" /> <SendIcon class="w-6 h-6 mr-2" />
<span>安全寄送</span> <span>安全寄送</span>
@@ -188,22 +138,14 @@
</div> </div>
</div> </div>
<div <div class="px-8 py-4 bg-opacity-50 flex justify-between items-center"
class="px-8 py-4 bg-opacity-50 flex justify-between items-center" :class="[isDarkMode ? 'bg-gray-800' : 'bg-gray-100']">
:class="[isDarkMode ? 'bg-gray-800' : 'bg-gray-100']" <span class="text-sm flex items-center" :class="[isDarkMode ? 'text-gray-300' : 'text-gray-800']">
>
<span
class="text-sm flex items-center"
:class="[isDarkMode ? 'text-gray-300' : 'text-gray-800']"
>
<ShieldCheckIcon class="w-4 h-4 mr-1 text-green-400" /> <ShieldCheckIcon class="w-4 h-4 mr-1 text-green-400" />
安全加密 安全加密
</span> </span>
<button <button @click="toggleDrawer" class="text-sm hover:text-indigo-300 transition duration-300 flex items-center"
@click="toggleDrawer" :class="[isDarkMode ? 'text-indigo-400' : 'text-indigo-600']">
class="text-sm hover:text-indigo-300 transition duration-300 flex items-center"
:class="[isDarkMode ? 'text-indigo-400' : 'text-indigo-600']"
>
发件记录 发件记录
<ClipboardListIcon class="w-4 h-4 ml-1" /> <ClipboardListIcon class="w-4 h-4 ml-1" />
</button> </button>
@@ -212,84 +154,56 @@
<!-- 抽屉式发件记录 --> <!-- 抽屉式发件记录 -->
<transition name="drawer"> <transition name="drawer">
<div <div v-if="showDrawer"
v-if="showDrawer"
class="fixed inset-y-0 right-0 w-full sm:w-120 bg-opacity-70 backdrop-filter backdrop-blur-xl shadow-2xl z-50 overflow-hidden flex flex-col" class="fixed inset-y-0 right-0 w-full sm:w-120 bg-opacity-70 backdrop-filter backdrop-blur-xl shadow-2xl z-50 overflow-hidden flex flex-col"
:class="[isDarkMode ? 'bg-gray-900' : 'bg-white']" :class="[isDarkMode ? 'bg-gray-900' : 'bg-white']">
> <div class="flex justify-between items-center p-6 border-b"
<div :class="[isDarkMode ? 'border-gray-700' : 'border-gray-200']">
class="flex justify-between items-center p-6 border-b"
:class="[isDarkMode ? 'border-gray-700' : 'border-gray-200']"
>
<h3 class="text-2xl font-bold" :class="[isDarkMode ? 'text-white' : 'text-gray-800']"> <h3 class="text-2xl font-bold" :class="[isDarkMode ? 'text-white' : 'text-gray-800']">
发件记录 发件记录
</h3> </h3>
<button <button @click="toggleDrawer" class="hover:text-white transition duration-300"
@click="toggleDrawer" :class="[isDarkMode ? 'text-gray-400' : 'text-gray-800']">
class="hover:text-white transition duration-300"
:class="[isDarkMode ? 'text-gray-400' : 'text-gray-800']"
>
<XIcon class="w-6 h-6" /> <XIcon class="w-6 h-6" />
</button> </button>
</div> </div>
<div class="flex-grow overflow-y-auto p-6"> <div class="flex-grow overflow-y-auto p-6">
<transition-group name="list" tag="div" class="space-y-4"> <transition-group name="list" tag="div" class="space-y-4">
<div <div v-for="record in sendRecords" :key="record.id"
v-for="record in sendRecords"
:key="record.id"
class="bg-opacity-50 rounded-lg p-4 flex items-center shadow-md hover:shadow-lg transition duration-300 transform hover:scale-102" class="bg-opacity-50 rounded-lg p-4 flex items-center shadow-md hover:shadow-lg transition duration-300 transform hover:scale-102"
:class="[isDarkMode ? 'bg-gray-800 hover:bg-gray-700' : 'bg-gray-100 hover:bg-white']" :class="[isDarkMode ? 'bg-gray-800 hover:bg-gray-700' : 'bg-gray-100 hover:bg-white']">
>
<div class="flex-shrink-0 mr-4"> <div class="flex-shrink-0 mr-4">
<FileIcon <FileIcon class="w-10 h-10" :class="[isDarkMode ? 'text-indigo-400' : 'text-indigo-600']" />
class="w-10 h-10"
:class="[isDarkMode ? 'text-indigo-400' : 'text-indigo-600']"
/>
</div> </div>
<div class="flex-grow min-w-0 mr-4"> <div class="flex-grow min-w-0 mr-4">
<p <p class="font-medium text-lg truncate" :class="[isDarkMode ? 'text-white' : 'text-gray-800']">
class="font-medium text-lg truncate"
:class="[isDarkMode ? 'text-white' : 'text-gray-800']"
>
{{ record.filename ? record.filename : 'Text' }} {{ record.filename ? record.filename : 'Text' }}
</p> </p>
<p <p class="text-sm truncate" :class="[isDarkMode ? 'text-gray-400' : 'text-gray-600']">
class="text-sm truncate"
:class="[isDarkMode ? 'text-gray-400' : 'text-gray-600']"
>
{{ record.date }} · {{ record.size }} {{ record.date }} · {{ record.size }}
</p> </p>
</div> </div>
<div class="flex-shrink-0 flex space-x-2"> <div class="flex-shrink-0 flex space-x-2">
<button <button @click="copyRetrieveLink(record.retrieveCode)"
@click="copyRetrieveLink(record.retrieveCode)" class="p-2 rounded-full hover:bg-opacity-20 transition duration-300" :class="[
class="p-2 rounded-full hover:bg-opacity-20 transition duration-300"
:class="[
isDarkMode isDarkMode
? 'hover:bg-blue-400 text-blue-400' ? 'hover:bg-blue-400 text-blue-400'
: 'hover:bg-blue-100 text-blue-600' : 'hover:bg-blue-100 text-blue-600'
]" ]">
>
<ClipboardCopyIcon class="w-5 h-5" /> <ClipboardCopyIcon class="w-5 h-5" />
</button> </button>
<button <button @click="viewDetails(record)"
@click="viewDetails(record)" class="p-2 rounded-full hover:bg-opacity-20 transition duration-300" :class="[
class="p-2 rounded-full hover:bg-opacity-20 transition duration-300"
:class="[
isDarkMode isDarkMode
? 'hover:bg-green-400 text-green-400' ? 'hover:bg-green-400 text-green-400'
: 'hover:bg-green-100 text-green-600' : 'hover:bg-green-100 text-green-600'
]" ]">
>
<EyeIcon class="w-5 h-5" /> <EyeIcon class="w-5 h-5" />
</button> </button>
<button <button @click="deleteRecord(record.id)"
@click="deleteRecord(record.id)" class="p-2 rounded-full hover:bg-opacity-20 transition duration-300" :class="[
class="p-2 rounded-full hover:bg-opacity-20 transition duration-300"
:class="[
isDarkMode ? 'hover:bg-red-400 text-red-400' : 'hover:bg-red-100 text-red-600' isDarkMode ? 'hover:bg-red-400 text-red-400' : 'hover:bg-red-100 text-red-600'
]" ]">
>
<TrashIcon class="w-5 h-5" /> <TrashIcon class="w-5 h-5" />
</button> </button>
</div> </div>
@@ -301,53 +215,34 @@
<!-- 记录详情弹窗 --> <!-- 记录详情弹窗 -->
<transition name="fade"> <transition name="fade">
<div <div v-if="selectedRecord" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50">
v-if="selectedRecord"
class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50"
>
<div <div
class="p-8 rounded-2xl max-w-md w-full mx-4 shadow-2xl transform transition-all duration-300 ease-out backdrop-filter backdrop-blur-lg bg-opacity-70" class="p-8 rounded-2xl max-w-md w-full mx-4 shadow-2xl transform transition-all duration-300 ease-out backdrop-filter backdrop-blur-lg bg-opacity-70"
:class="[isDarkMode ? 'bg-gray-800' : 'bg-white']" :class="[isDarkMode ? 'bg-gray-800' : 'bg-white']">
> <h3 class="text-2xl font-bold mb-6" :class="[isDarkMode ? 'text-white' : 'text-gray-800']">
<h3
class="text-2xl font-bold mb-6"
: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">
<FileIcon <FileIcon class="w-6 h-6 mr-3" :class="[isDarkMode ? 'text-indigo-400' : 'text-indigo-600']" />
class="w-6 h-6 mr-3"
:class="[isDarkMode ? 'text-indigo-400' : 'text-indigo-600']"
/>
<p :class="[isDarkMode ? 'text-gray-300' : 'text-gray-800']"> <p :class="[isDarkMode ? 'text-gray-300' : 'text-gray-800']">
<span class="font-medium">文件名</span>{{ selectedRecord.filename }} <span class="font-medium">文件名</span>{{ selectedRecord.filename }}
</p> </p>
</div> </div>
<div class="flex items-center"> <div class="flex items-center">
<CalendarIcon <CalendarIcon class="w-6 h-6 mr-3" :class="[isDarkMode ? 'text-indigo-400' : 'text-indigo-600']" />
class="w-6 h-6 mr-3"
:class="[isDarkMode ? 'text-indigo-400' : 'text-indigo-600']"
/>
<p :class="[isDarkMode ? 'text-gray-300' : 'text-gray-800']"> <p :class="[isDarkMode ? 'text-gray-300' : 'text-gray-800']">
<span class="font-medium">发送日期</span>{{ selectedRecord.date }} <span class="font-medium">发送日期</span>{{ selectedRecord.date }}
</p> </p>
</div> </div>
<div class="flex items-center"> <div class="flex items-center">
<HardDriveIcon <HardDriveIcon class="w-6 h-6 mr-3" :class="[isDarkMode ? 'text-indigo-400' : 'text-indigo-600']" />
class="w-6 h-6 mr-3"
:class="[isDarkMode ? 'text-indigo-400' : 'text-indigo-600']"
/>
<p :class="[isDarkMode ? 'text-gray-300' : 'text-gray-800']"> <p :class="[isDarkMode ? 'text-gray-300' : 'text-gray-800']">
<span class="font-medium">文件大小</span>{{ selectedRecord.size }} <span class="font-medium">文件大小</span>{{ selectedRecord.size }}
</p> </p>
</div> </div>
<div class="flex items-center"> <div class="flex items-center">
<ClockIcon <ClockIcon class="w-6 h-6 mr-3" :class="[isDarkMode ? 'text-indigo-400' : 'text-indigo-600']" />
class="w-6 h-6 mr-3"
:class="[isDarkMode ? 'text-indigo-400' : 'text-indigo-600']"
/>
<p :class="[isDarkMode ? 'text-gray-300' : 'text-gray-800']"> <p :class="[isDarkMode ? 'text-gray-300' : 'text-gray-800']">
<span class="font-medium">过期时间</span>{{ selectedRecord.expiration }} <span class="font-medium">过期时间</span>{{ selectedRecord.expiration }}
</p> </p>
@@ -357,16 +252,12 @@
<!-- 取件码和二维码部分 --> <!-- 取件码和二维码部分 -->
<div class="mt-6 flex justify-between items-center"> <div class="mt-6 flex justify-between items-center">
<div class="flex flex-col items-center w-1/2 pr-2"> <div class="flex flex-col items-center w-1/2 pr-2">
<h4 <h4 class="text-lg font-semibold mb-3" :class="[isDarkMode ? 'text-white' : 'text-gray-800']">
class="text-lg font-semibold mb-3"
:class="[isDarkMode ? 'text-white' : 'text-gray-800']"
>
取件码 取件码
</h4> </h4>
<div <div
class="bg-gray-100 p-3 rounded-lg shadow-md cursor-pointer hover:bg-gray-200 transition-colors duration-300 w-full text-center" class="bg-gray-100 p-3 rounded-lg shadow-md cursor-pointer hover:bg-gray-200 transition-colors duration-300 w-full text-center"
@click="copyRetrieveCode(selectedRecord.retrieveCode)" @click="copyRetrieveCode(selectedRecord.retrieveCode)">
>
<p class="text-2xl font-bold text-indigo-600">{{ selectedRecord.retrieveCode }}</p> <p class="text-2xl font-bold text-indigo-600">{{ selectedRecord.retrieveCode }}</p>
</div> </div>
<p class="mt-2 text-sm" :class="[isDarkMode ? 'text-gray-400' : 'text-gray-600']"> <p class="mt-2 text-sm" :class="[isDarkMode ? 'text-gray-400' : 'text-gray-600']">
@@ -374,10 +265,7 @@
</p> </p>
</div> </div>
<div class="flex flex-col items-center w-1/2 pl-2"> <div class="flex flex-col items-center w-1/2 pl-2">
<h4 <h4 class="text-lg font-semibold mb-3" :class="[isDarkMode ? 'text-white' : 'text-gray-800']">
class="text-lg font-semibold mb-3"
:class="[isDarkMode ? 'text-white' : 'text-gray-800']"
>
二维码 二维码
</h4> </h4>
<div class="bg-white p-2 rounded-lg shadow-md"> <div class="bg-white p-2 rounded-lg shadow-md">
@@ -389,10 +277,8 @@
</div> </div>
</div> </div>
<button <button @click="selectedRecord = null"
@click="selectedRecord = null" class="mt-8 w-full bg-gradient-to-r from-indigo-500 to-purple-600 text-white px-6 py-3 rounded-lg font-medium hover:from-indigo-600 hover:to-purple-700 focus:outline-none focus:ring-2 focus:ring-purple-500 focus:ring-opacity-50 transition duration-300 transform hover:scale-105">
class="mt-8 w-full bg-gradient-to-r from-indigo-500 to-purple-600 text-white px-6 py-3 rounded-lg font-medium hover:from-indigo-600 hover:to-purple-700 focus:outline-none focus:ring-2 focus:ring-purple-500 focus:ring-opacity-50 transition duration-300 transform hover:scale-105"
>
关闭 关闭
</button> </button>
</div> </div>
@@ -454,27 +340,56 @@ const triggerFileUpload = () => {
const handleFileUpload = async (event: Event) => { const handleFileUpload = async (event: Event) => {
const target = event.target as HTMLInputElement const target = event.target as HTMLInputElement
if (target.files && target.files.length > 0) { if (target.files && target.files.length > 0) {
selectedFile.value = target.files[0] const file = target.files[0]
fileHash.value = await calculateFileHash(selectedFile.value) if (!config.openUpload && localStorage.getItem('token') === null) {
alertStore.showAlert('游客上传功能已关闭', 'error')
return
}
if (file.size > config.uploadSize) {
alertStore.showAlert(`文件大小超过限制 (${getStorageUnit(config.uploadSize)})`, 'error')
return
}
selectedFile.value = file
fileHash.value = await calculateFileHash(file)
console.log(fileHash.value) console.log(fileHash.value)
} }
} }
const handleFileDrop = async (event: DragEvent) => { const handleFileDrop = async (event: DragEvent) => {
if (event.dataTransfer?.files && event.dataTransfer.files.length > 0) { if (event.dataTransfer?.files && event.dataTransfer.files.length > 0) {
selectedFile.value = event.dataTransfer.files[0] const file = event.dataTransfer.files[0]
fileHash.value = await calculateFileHash(selectedFile.value) if (!config.openUpload && localStorage.getItem('token') === null) {
alertStore.showAlert('游客上传功能已关闭', 'error')
return
}
if (file.size > config.uploadSize) {
alertStore.showAlert(`文件大小超过限制 (${getStorageUnit(config.uploadSize)})`, 'error')
return
}
selectedFile.value = file
fileHash.value = await calculateFileHash(file)
} }
} }
const handlePaste = async (event: ClipboardEvent) => { const handlePaste = async (event: ClipboardEvent) => {
const items = event.clipboardData?.items const items = event.clipboardData?.items
if (!items) return if (!items) return
if (config.openUpload===0 && localStorage.getItem('token') === null) {
alertStore.showAlert('游客上传功能已关闭', 'error')
return
}
for (const item of items) { for (const item of items) {
if (item.kind === 'file') { if (item.kind === 'file') {
const file = item.getAsFile() const file = item.getAsFile()
if (file) { if (file) {
if (file.size > config.uploadSize) {
alertStore.showAlert(`文件大小超过限制 (${getStorageUnit(config.uploadSize)})`, 'error')
return
}
selectedFile.value = file selectedFile.value = file
fileHash.value = await calculateFileHash(file) fileHash.value = await calculateFileHash(file)
alertStore.showAlert('已从剪贴板添加文件:' + file.name, 'success') alertStore.showAlert('已从剪贴板添加文件:' + file.name, 'success')
@@ -493,7 +408,6 @@ const calculateFileHash = async (file: File): Promise<string> => {
fileReader.onload = async (e) => { fileReader.onload = async (e) => {
const chunk = new Uint8Array(e.target!.result as ArrayBuffer) const chunk = new Uint8Array(e.target!.result as ArrayBuffer)
// 计算当前切片的 SHA256
const hashBuffer = await crypto.subtle.digest('SHA-256', chunk) const hashBuffer = await crypto.subtle.digest('SHA-256', chunk)
const hashArray = Array.from(new Uint8Array(hashBuffer)) const hashArray = Array.from(new Uint8Array(hashBuffer))
const hashHex = hashArray.map((b) => b.toString(16).padStart(2, '0')).join('') const hashHex = hashArray.map((b) => b.toString(16).padStart(2, '0')).join('')