mirror of
https://gitee.com/czh-dev/upload-hub
synced 2026-05-06 20:32:48 +08:00
refactor:将FileUpload页面模块化成单独的组件
This commit is contained in:
@@ -15,5 +15,8 @@
|
||||
"dom.iterable",
|
||||
"scripthost"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"include": [
|
||||
"src/**/*"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<template>
|
||||
<div v-if="show" class="about-modal" @click="closeOnOutside">
|
||||
<div class="about-content" @click.stop>
|
||||
<h2>关于</h2>
|
||||
<p>这个人很懒,什么都没有留下,只说自己爱吃炸排骨。。。</p>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'AboutModal',
|
||||
props: { show: Boolean },
|
||||
methods: {
|
||||
close() {
|
||||
this.$emit('close');
|
||||
},
|
||||
closeOnOutside(event) {
|
||||
if (event.target.classList.contains('about-modal')) this.close();
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.about-modal {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
.about-content {
|
||||
background: #fff;
|
||||
padding: 20px;
|
||||
border-radius: 8px;
|
||||
width: 400px;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.about-content h2 {
|
||||
margin-top: 0;
|
||||
font-size: 1.2rem;
|
||||
color: #1976d2;
|
||||
}
|
||||
|
||||
.about-content p {
|
||||
margin: 10px 0;
|
||||
font-size: 14px;
|
||||
color: #666;
|
||||
}
|
||||
</style>
|
||||
488
upload-file-frontend/src/components/FileGallery/FileGallery.vue
Normal file
488
upload-file-frontend/src/components/FileGallery/FileGallery.vue
Normal file
@@ -0,0 +1,488 @@
|
||||
<template>
|
||||
<div class="gallery-container" @scroll="handleScroll">
|
||||
<div class="gallery-header">
|
||||
<label for="storage-select">存储类型:</label>
|
||||
<select id="storage-select" v-model="selectedStorageType" @change="fetchFiles(true)">
|
||||
<option v-for="option in storageOptions" :key="option.value" :value="option.value">
|
||||
{{ option.label }}
|
||||
</option>
|
||||
</select>
|
||||
<label for="file-name-input"> 文件名:</label>
|
||||
<el-input v-model="selectedFileName" placeholder="请输入文件名" class="file-name-input" style="width: 150px;"
|
||||
@change="fetchFiles(true)"></el-input>
|
||||
</div>
|
||||
<div v-if="filePage.length === 0 && !loading" class="empty-tips">
|
||||
🖼️ 暂无已上传的文件
|
||||
</div>
|
||||
<div v-else-if="loading && filePage.length === 0" class="loading-tips">
|
||||
加载中...
|
||||
</div>
|
||||
<div v-else class="file-grid">
|
||||
<div v-for="file in filePage" :key="file.id" class="file-card">
|
||||
<div class="preview-wrapper">
|
||||
<img v-if="isImage(file)" :src="file.accessUrl" :alt="file.fileName" class="preview-image"
|
||||
@click="openImagePreview(file)" loading="lazy" />
|
||||
<div v-else-if="isVideo(file)" class="video-preview" @click="openVideoPreview(file)">
|
||||
<div class="play-button">▶</div>
|
||||
</div>
|
||||
<div v-else-if="isPdf(file)" class="pdf-preview" @click="openPdfPreview(file)">
|
||||
<div class="pdf-icon">📜</div>
|
||||
</div>
|
||||
<div v-else class="file-icon">📄</div>
|
||||
<div class="copy-button" @click.stop="copyUrl(file.accessUrl)" title="复制文件URL">📋</div>
|
||||
</div>
|
||||
<div class="file-meta">
|
||||
<div class="filename">{{ file.fileName }}</div>
|
||||
<div class="file-size-status">
|
||||
<div class="file-size">{{ formatSize(file.totalSize) }}</div>
|
||||
<div class="status-indicator">{{ formattedDate(file.createTime) }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="loading && filePage.length > 0" class="loading-more">加载更多...</div>
|
||||
|
||||
<!-- 预览弹窗 -->
|
||||
<div v-if="showImagePreview" class="image-preview-modal" @click="closeImagePreview">
|
||||
<div class="image-preview-content" @click.stop>
|
||||
<img :src="selectedImageUrl" alt="预览图片" class="full-image" />
|
||||
<div class="close-button" @click="closeImagePreview">✖</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="showVideoPreview" class="video-preview-modal" @click="closeVideoPreview">
|
||||
<div class="video-preview-content" @click.stop>
|
||||
<video :src="selectedVideoUrl" controls class="full-video" autoplay></video>
|
||||
<div class="close-button" @click="closeVideoPreview">✖</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="showPdfPreview" class="pdf-preview-modal" @click="closePdfPreview">
|
||||
<div class="pdf-preview-content" @click.stop>
|
||||
<div v-if="loadingPdf" class="loading-overlay">
|
||||
<div class="loading-spinner"></div>
|
||||
<p>加载 PDF 中...</p>
|
||||
</div>
|
||||
<iframe v-show="!loadingPdf" :src="selectedPdfUrl" class="full-pdf" frameborder="0" @load="onPdfLoad"></iframe>
|
||||
<div class="close-button" @click="closePdfPreview">✖</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { pageFiles } from '@/utils/api';
|
||||
|
||||
export default {
|
||||
name: 'FileGallery',
|
||||
props: {
|
||||
storageOptions: {
|
||||
type: Array,
|
||||
default: () => [
|
||||
{ label: 'Local', value: 'local' },
|
||||
{ label: 'MinIO', value: 'minio' },
|
||||
{ label: 'OSS', value: 'oss' }
|
||||
]
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
selectedStorageType: 'local',
|
||||
selectedFileName: '',
|
||||
currentPage: 1,
|
||||
pageSize: 10,
|
||||
loading: false,
|
||||
hasMore: true,
|
||||
filePage: [],
|
||||
showImagePreview: false,
|
||||
selectedImageUrl: '',
|
||||
showVideoPreview: false,
|
||||
selectedVideoUrl: '',
|
||||
showPdfPreview: false,
|
||||
selectedPdfUrl: '',
|
||||
loadingPdf: false
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
async fetchFiles(reset = false) {
|
||||
if (this.loading || (!reset && !this.hasMore)) return;
|
||||
this.loading = true;
|
||||
if (reset) {
|
||||
this.currentPage = 1;
|
||||
this.filePage = [];
|
||||
this.hasMore = true;
|
||||
}
|
||||
try {
|
||||
const response = await pageFiles({
|
||||
page: this.currentPage,
|
||||
pageSize: this.pageSize,
|
||||
storageType: this.selectedStorageType,
|
||||
fileName: this.selectedFileName
|
||||
});
|
||||
const files = response.data.records || [];
|
||||
this.filePage = reset ? files : this.filePage.concat(files);
|
||||
this.hasMore = files.length === this.pageSize;
|
||||
if (this.hasMore) this.currentPage++;
|
||||
} catch (error) {
|
||||
console.error('获取文件列表失败:', error);
|
||||
this.$message.error('加载文件列表失败');
|
||||
} finally {
|
||||
this.loading = false;
|
||||
}
|
||||
},
|
||||
handleScroll(event) {
|
||||
const container = event.target;
|
||||
const isBottom = container.scrollTop + container.clientHeight >= container.scrollHeight - 10;
|
||||
if (isBottom && !this.loading && this.hasMore) this.fetchFiles();
|
||||
},
|
||||
isImage(file) {
|
||||
return file.contentType.startsWith('image/');
|
||||
},
|
||||
isVideo(file) {
|
||||
return file.contentType.startsWith('video/');
|
||||
},
|
||||
isPdf(file) {
|
||||
return file.contentType === 'application/pdf';
|
||||
},
|
||||
formatSize(bytes) {
|
||||
if (bytes === 0) return '0 B';
|
||||
const k = 1024;
|
||||
const sizes = ['B', 'KB', 'MB', 'GB'];
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
|
||||
},
|
||||
formattedDate(date) {
|
||||
const d = new Date(date);
|
||||
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
|
||||
},
|
||||
openImagePreview(file) {
|
||||
this.selectedImageUrl = file.accessUrl;
|
||||
this.showImagePreview = true;
|
||||
},
|
||||
closeImagePreview() {
|
||||
this.showImagePreview = false;
|
||||
this.selectedImageUrl = '';
|
||||
},
|
||||
openVideoPreview(file) {
|
||||
this.selectedVideoUrl = file.accessUrl;
|
||||
this.showVideoPreview = true;
|
||||
},
|
||||
closeVideoPreview() {
|
||||
this.showVideoPreview = false;
|
||||
this.selectedVideoUrl = '';
|
||||
},
|
||||
openPdfPreview(file) {
|
||||
this.selectedPdfUrl = `${file.accessUrl}?response-content-disposition=inline`;
|
||||
this.showPdfPreview = true;
|
||||
this.loadingPdf = true;
|
||||
},
|
||||
onPdfLoad() {
|
||||
this.loadingPdf = false;
|
||||
},
|
||||
closePdfPreview() {
|
||||
this.showPdfPreview = false;
|
||||
this.selectedPdfUrl = '';
|
||||
this.loadingPdf = false;
|
||||
},
|
||||
async copyUrl(url) {
|
||||
try {
|
||||
await navigator.clipboard.writeText(url);
|
||||
this.$message({ message: '文件URL已复制到剪贴板', type: 'success', duration: 2000 });
|
||||
} catch (error) {
|
||||
console.error('复制URL失败:', error);
|
||||
this.$message.error('复制URL失败');
|
||||
}
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.fetchFiles(true);
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
/* eslint-disable */
|
||||
.gallery-container {
|
||||
padding: 1rem 2rem 2rem;
|
||||
height: 400px;
|
||||
background: #fcfdff;
|
||||
border-top: 1px solid #f0f7ff;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.gallery-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.gallery-header label {
|
||||
font-size: 14px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.gallery-header select {
|
||||
padding: 6px 12px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 4px;
|
||||
font-size: 14px;
|
||||
background: #fff;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.empty-tips,
|
||||
.loading-tips {
|
||||
text-align: center;
|
||||
color: #999;
|
||||
font-size: 1.2rem;
|
||||
padding: 4rem 0;
|
||||
}
|
||||
|
||||
.file-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.loading-more {
|
||||
text-align: center;
|
||||
color: #666;
|
||||
font-size: 14px;
|
||||
padding: 1rem 0;
|
||||
}
|
||||
|
||||
.file-card {
|
||||
background: #fff;
|
||||
border-radius: 6px;
|
||||
box-shadow: 0 1px 6px rgba(0, 0, 0, 0.1);
|
||||
overflow: hidden;
|
||||
transition: transform 0.2s, box-shadow 0.2s;
|
||||
}
|
||||
|
||||
.file-card:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 3px 8px rgba(25, 118, 210, 0.2);
|
||||
}
|
||||
|
||||
.copy-button {
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
right: 8px;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
opacity: 0;
|
||||
transition: opacity 0.2s;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.file-card:hover .copy-button {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.preview-wrapper {
|
||||
position: relative;
|
||||
padding-top: 100%;
|
||||
background: #f8fafd;
|
||||
}
|
||||
|
||||
.preview-image {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
border-bottom: 1px solid #eee;
|
||||
}
|
||||
|
||||
.file-icon {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
font-size: 2rem;
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.file-meta {
|
||||
padding: 0.8rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.file-size-status {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.filename {
|
||||
font-weight: 500;
|
||||
color: #333;
|
||||
font-size: 0.9rem;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.file-size {
|
||||
font-size: 0.7rem;
|
||||
color: #666;
|
||||
margin: 0.2rem 0;
|
||||
}
|
||||
|
||||
.status-indicator {
|
||||
padding: 0.15rem 0.4rem;
|
||||
border-radius: 3px;
|
||||
font-size: 0.65rem;
|
||||
background: #e8f5e9;
|
||||
color: #2e7d32;
|
||||
}
|
||||
|
||||
.image-preview-modal,
|
||||
.video-preview-modal,
|
||||
.pdf-preview-modal {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: rgba(0, 0, 0, 0.8);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
z-index: 200;
|
||||
}
|
||||
|
||||
.image-preview-content,
|
||||
.video-preview-content,
|
||||
.pdf-preview-content {
|
||||
position: relative;
|
||||
width: 90vw;
|
||||
height: 90vh;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.full-image,
|
||||
.full-video {
|
||||
max-width: 100%;
|
||||
max-height: 100%;
|
||||
width: auto;
|
||||
height: auto;
|
||||
object-fit: contain;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
.full-pdf {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.close-button {
|
||||
position: absolute;
|
||||
top: 10px;
|
||||
right: 10px;
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
background: rgba(255, 255, 255, 0.9);
|
||||
color: #333;
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
cursor: pointer;
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.video-preview {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.play-button {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
color: white;
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
font-size: 20px;
|
||||
opacity: 0.8;
|
||||
margin-top: -105px;
|
||||
}
|
||||
|
||||
.pdf-preview {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.pdf-icon {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
font-size: 2rem;
|
||||
opacity: 0.8;
|
||||
margin-top: -105px;
|
||||
}
|
||||
|
||||
.loading-overlay {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
z-index: 201;
|
||||
}
|
||||
|
||||
.loading-spinner {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border: 4px solid #f0f7ff;
|
||||
border-top: 4px solid #1976d2;
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
.loading-overlay p {
|
||||
margin-top: 10px;
|
||||
color: #fff;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
0% {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
|
||||
100% {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,60 +0,0 @@
|
||||
<template>
|
||||
<div class="hello">
|
||||
<h1>{{ msg }}</h1>
|
||||
<p>
|
||||
For a guide and recipes on how to configure / customize this project,<br>
|
||||
check out the
|
||||
<a href="https://cli.vuejs.org" target="_blank" rel="noopener">vue-cli documentation</a>.
|
||||
</p>
|
||||
<h3>Installed CLI Plugins</h3>
|
||||
<ul>
|
||||
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-babel" target="_blank" rel="noopener">babel</a></li>
|
||||
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-router" target="_blank" rel="noopener">router</a></li>
|
||||
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-vuex" target="_blank" rel="noopener">vuex</a></li>
|
||||
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint" target="_blank" rel="noopener">eslint</a></li>
|
||||
</ul>
|
||||
<h3>Essential Links</h3>
|
||||
<ul>
|
||||
<li><a href="https://vuejs.org" target="_blank" rel="noopener">Core Docs</a></li>
|
||||
<li><a href="https://forum.vuejs.org" target="_blank" rel="noopener">Forum</a></li>
|
||||
<li><a href="https://chat.vuejs.org" target="_blank" rel="noopener">Community Chat</a></li>
|
||||
<li><a href="https://twitter.com/vuejs" target="_blank" rel="noopener">Twitter</a></li>
|
||||
<li><a href="https://news.vuejs.org" target="_blank" rel="noopener">News</a></li>
|
||||
</ul>
|
||||
<h3>Ecosystem</h3>
|
||||
<ul>
|
||||
<li><a href="https://router.vuejs.org" target="_blank" rel="noopener">vue-router</a></li>
|
||||
<li><a href="https://vuex.vuejs.org" target="_blank" rel="noopener">vuex</a></li>
|
||||
<li><a href="https://github.com/vuejs/vue-devtools#vue-devtools" target="_blank" rel="noopener">vue-devtools</a></li>
|
||||
<li><a href="https://vue-loader.vuejs.org" target="_blank" rel="noopener">vue-loader</a></li>
|
||||
<li><a href="https://github.com/vuejs/awesome-vue" target="_blank" rel="noopener">awesome-vue</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'HelloWorld',
|
||||
props: {
|
||||
msg: String
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
||||
<style scoped lang="scss">
|
||||
h3 {
|
||||
margin: 40px 0 0;
|
||||
}
|
||||
ul {
|
||||
list-style-type: none;
|
||||
padding: 0;
|
||||
}
|
||||
li {
|
||||
display: inline-block;
|
||||
margin: 0 10px;
|
||||
}
|
||||
a {
|
||||
color: #42b983;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,133 @@
|
||||
<template>
|
||||
<div v-if="show" class="settings-modal" @click="closeOnOutside">
|
||||
<div class="settings-content" @click.stop>
|
||||
<h2>上传设置</h2>
|
||||
<form @submit.prevent="save">
|
||||
<div class="form-group">
|
||||
<label>允许上传的文件格式(用英文逗号分隔,例如 .jpg,.png):</label>
|
||||
<input v-model="tempAllowedFormats" type="text" placeholder=".jpg,.png,.mp4" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>最大上传大小(MB):</label>
|
||||
<input v-model.number="tempMaxSizeMB" type="number" min="1" step="1" />
|
||||
</div>
|
||||
<div class="form-actions">
|
||||
<button type="submit">保存</button>
|
||||
<button type="button" @click="close">取消</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'SettingsModal',
|
||||
props: {
|
||||
show: Boolean,
|
||||
allowedFormats: String,
|
||||
maxUploadSize: Number
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
tempAllowedFormats: this.allowedFormats,
|
||||
tempMaxSizeMB: this.maxUploadSize / (1024 * 1024)
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
show(newVal) {
|
||||
if (newVal) {
|
||||
this.tempAllowedFormats = this.allowedFormats;
|
||||
this.tempMaxSizeMB = this.maxUploadSize / (1024 * 1024);
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
save() {
|
||||
this.$emit('save', {
|
||||
allowedFormats: this.tempAllowedFormats,
|
||||
maxUploadSize: this.tempMaxSizeMB * 1024 * 1024
|
||||
});
|
||||
this.close();
|
||||
},
|
||||
close() {
|
||||
this.$emit('close');
|
||||
},
|
||||
closeOnOutside(event) {
|
||||
if (event.target.classList.contains('settings-modal')) this.close();
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.settings-modal {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
.settings-content {
|
||||
background: #fff;
|
||||
padding: 20px;
|
||||
border-radius: 8px;
|
||||
width: 400px;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
|
||||
.settings-content h2 {
|
||||
margin-top: 0;
|
||||
font-size: 1.2rem;
|
||||
color: #1976d2;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.form-group label {
|
||||
display: block;
|
||||
margin-bottom: 5px;
|
||||
font-size: 14px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.form-group input {
|
||||
width: 100%;
|
||||
padding: 8px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 4px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.form-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.form-actions button {
|
||||
padding: 8px 16px;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.form-actions button[type="submit"] {
|
||||
background: #1976d2;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.form-actions button[type="button"] {
|
||||
background: #eee;
|
||||
color: #333;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,174 @@
|
||||
<template>
|
||||
<div v-if="show" class="storage-config-modal" @click="closeOnOutside">
|
||||
<div class="storage-config-content" @click.stop>
|
||||
<h2>存储系统配置</h2>
|
||||
<div class="form-group">
|
||||
<label>存储类型:</label>
|
||||
<select v-model="config.type" @change="fetchConfig">
|
||||
<option v-for="option in storageOptions" :key="option.value" :value="option.value">
|
||||
{{ option.label }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Endpoint:</label>
|
||||
<input v-model="config.endpoint" type="text" placeholder="请输入Endpoint" />
|
||||
</div>
|
||||
<div class="form-group" v-if="config.type !== 'local'">
|
||||
<label>Access Key:</label>
|
||||
<input v-model="config.accessKey" type="text" placeholder="请输入Access Key" />
|
||||
</div>
|
||||
<div class="form-group" v-if="config.type !== 'local'">
|
||||
<label>Secret Key:</label>
|
||||
<input v-model="config.secretKey" type="password" placeholder="请输入Secret Key" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Bucket:</label>
|
||||
<input v-model="config.bucket" type="text" placeholder="请输入Bucket" />
|
||||
</div>
|
||||
<div class="form-actions">
|
||||
<button type="button" @click="saveConfig">保存</button>
|
||||
<button type="button" @click="close">取消</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { getStorageConfig, setStorageConfig } from '@/utils/api';
|
||||
|
||||
export default {
|
||||
name: 'StorageConfigModal',
|
||||
props: {
|
||||
show: Boolean,
|
||||
storageOptions: Array
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
config: {
|
||||
type: 'local',
|
||||
endpoint: '',
|
||||
accessKey: '',
|
||||
secretKey: '',
|
||||
bucket: ''
|
||||
}
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
async fetchConfig() {
|
||||
try {
|
||||
const response = await getStorageConfig({ type: this.config.type });
|
||||
const config = response.data;
|
||||
this.config = config ? { ...config } : {
|
||||
type: this.config.type,
|
||||
endpoint: '',
|
||||
accessKey: '',
|
||||
secretKey: '',
|
||||
bucket: ''
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('获取存储配置失败:', error);
|
||||
this.$message.error('获取存储配置失败');
|
||||
}
|
||||
},
|
||||
async saveConfig() {
|
||||
try {
|
||||
await setStorageConfig(this.config);
|
||||
this.$message.success('存储配置保存成功');
|
||||
this.close();
|
||||
} catch (error) {
|
||||
console.error('保存存储配置失败:', error);
|
||||
this.$message.error('保存存储配置失败');
|
||||
}
|
||||
},
|
||||
close() {
|
||||
this.$emit('close');
|
||||
},
|
||||
closeOnOutside(event) {
|
||||
if (event.target.classList.contains('storage-config-modal')) this.close();
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.fetchConfig();
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.storage-config-modal {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: rgba(25, 118, 210, 0.2);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.storage-config-content {
|
||||
background: #ffffff;
|
||||
padding: 2rem;
|
||||
border-radius: 12px;
|
||||
width: 480px;
|
||||
box-shadow: 0 8px 32px rgba(25, 118, 210, 0.15);
|
||||
}
|
||||
|
||||
.storage-config-content h2 {
|
||||
color: #1976d2;
|
||||
font-size: 1.5rem;
|
||||
margin: 0 0 2rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.form-group label {
|
||||
display: block;
|
||||
margin-bottom: 0.5rem;
|
||||
font-size: 0.9rem;
|
||||
color: #4a5568;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.form-group input,
|
||||
.form-group select {
|
||||
width: 93%;
|
||||
padding: 0.75rem 1rem;
|
||||
border: 1px solid #cbd5e0;
|
||||
border-radius: 8px;
|
||||
font-size: 0.95rem;
|
||||
background: #f8fafc;
|
||||
}
|
||||
|
||||
.form-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 12px;
|
||||
margin-top: 24px;
|
||||
}
|
||||
|
||||
.form-actions button {
|
||||
padding: 10px 20px;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.form-actions button:first-child {
|
||||
background: #1976d2;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.form-actions button:last-child {
|
||||
background: #f0f7ff;
|
||||
color: #1976d2;
|
||||
border: 1px solid #d0e4fc;
|
||||
}
|
||||
</style>
|
||||
@@ -1,6 +1,7 @@
|
||||
import Vue from 'vue'
|
||||
import VueRouter from 'vue-router'
|
||||
import FileUpload from '@/views/FileUpload.vue';
|
||||
// import FileUpload from '@/views/FileUpload.vue';
|
||||
import MainPage from '@/views/MainPage.vue';
|
||||
|
||||
Vue.use(VueRouter)
|
||||
|
||||
@@ -8,7 +9,7 @@ const routes = [
|
||||
{
|
||||
path: '/',
|
||||
name: 'home',
|
||||
component: FileUpload
|
||||
component: MainPage
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
<template>
|
||||
<div class="about">
|
||||
<h1>This is an about page</h1>
|
||||
</div>
|
||||
</template>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,18 +0,0 @@
|
||||
<template>
|
||||
<div class="home">
|
||||
<img alt="Vue logo" src="../assets/logo.png">
|
||||
<HelloWorld msg="Welcome to Your Vue.js App"/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
// @ is an alias to /src
|
||||
import HelloWorld from '@/components/HelloWorld.vue'
|
||||
|
||||
export default {
|
||||
name: 'HomeView',
|
||||
components: {
|
||||
HelloWorld
|
||||
}
|
||||
}
|
||||
</script>
|
||||
263
upload-file-frontend/src/views/MainPage.vue
Normal file
263
upload-file-frontend/src/views/MainPage.vue
Normal file
@@ -0,0 +1,263 @@
|
||||
<template>
|
||||
<div class="upload-container">
|
||||
<div class="upload-window">
|
||||
<div class="header-wrapper">
|
||||
<h1 class="page-title">
|
||||
<span class="cloud-icon">☁️</span>
|
||||
文件上传中心
|
||||
</h1>
|
||||
<div class="menu-container" @mouseenter="showMenu = true" @mouseleave="showMenu = false">
|
||||
<div class="menu-icon">☰</div>
|
||||
<div v-show="showMenu" class="dropdown-menu">
|
||||
<div class="menu-item" @click="openSettings">上传设置</div>
|
||||
<div class="menu-item" @click="openStorageConfig">存储配置</div>
|
||||
<div class="menu-item" @click="openAbout">关于</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tab-bar">
|
||||
<div v-for="tab in tabs" :key="tab.value" :class="['tab', { 'active': activeTab === tab.value }]"
|
||||
@click="switchTab(tab.value)">
|
||||
{{ tab.label }}
|
||||
<div class="tab-underline"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="activeTab !== 'gallery' && !isWipTab" class="upload-content">
|
||||
<upload-file :file-list.sync="fileList" :accept="allowedFormats" :max-size="maxUploadSize" width="100%"
|
||||
height="400px" :storage-type="activeTab" />
|
||||
</div>
|
||||
<div v-else-if="isWipTab" class="wip-container">
|
||||
<div class="wip-message">
|
||||
<span class="wip-icon">🚧</span>
|
||||
<h2>功能建设中</h2>
|
||||
<p v-if="activeTab === 'obs'">正在加班加点搬砖中,敬请期待!</p>
|
||||
<p v-else-if="activeTab === 'qiniu'">七牛云功能正在被疯狂调教,马上就能和大家见面啦!</p>
|
||||
</div>
|
||||
</div>
|
||||
<file-gallery v-else />
|
||||
<settings-modal :show="showSettings" :allowed-formats="allowedFormats" :max-upload-size="maxUploadSize"
|
||||
@save="saveSettings" @close="closeSettings" />
|
||||
<storage-config-modal :show="showStorageConfig" :storage-options="storageOptions" @close="closeStorageConfig" />
|
||||
<about-modal :show="showAbout" @close="closeAbout" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import UploadFile from '@/components/UploadFile/UploadFile.vue';
|
||||
import FileGallery from '@/components/FileGallery/FileGallery.vue';
|
||||
import SettingsModal from '@/components/SettingsModal/SettingsModal.vue';
|
||||
import StorageConfigModal from '@/components/StorageConfigModal/StorageConfigModal.vue';
|
||||
import AboutModal from '@/components/AboutModal/AboutModal.vue';
|
||||
|
||||
export default {
|
||||
name: 'MainPage',
|
||||
components: { UploadFile, FileGallery, SettingsModal, StorageConfigModal, AboutModal },
|
||||
data() {
|
||||
return {
|
||||
fileList: [],
|
||||
activeTab: 'local',
|
||||
tabs: [
|
||||
{ label: 'Local', value: 'local' },
|
||||
{ label: 'MinIO', value: 'minio' },
|
||||
{ label: 'OSS', value: 'oss' },
|
||||
{ label: 'OBS', value: 'obs' },
|
||||
{ label: 'QiNiu', value: 'qiniu' },
|
||||
{ label: '已上传文件', value: 'gallery' }
|
||||
],
|
||||
showMenu: false,
|
||||
showSettings: false,
|
||||
showStorageConfig: false,
|
||||
showAbout: false,
|
||||
allowedFormats: '.jpg,.png,.mp4',
|
||||
maxUploadSize: 100 * 1024 * 1024,
|
||||
storageOptions: [
|
||||
{ label: 'Local', value: 'local' },
|
||||
{ label: 'MinIO', value: 'minio' },
|
||||
{ label: 'OSS', value: 'oss' }
|
||||
]
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
isWipTab() {
|
||||
return this.activeTab === 'obs' || this.activeTab === 'qiniu';
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
switchTab(tabValue) {
|
||||
this.activeTab = tabValue;
|
||||
if (this.isWipTab) {
|
||||
this.$message({
|
||||
message: tabValue === 'obs' ? 'OBS功能施工中...' : '七牛云功能开发中...',
|
||||
type: 'info',
|
||||
duration: 2000
|
||||
});
|
||||
}
|
||||
},
|
||||
openSettings() {
|
||||
this.showSettings = true;
|
||||
this.showMenu = false;
|
||||
},
|
||||
saveSettings(settings) {
|
||||
this.allowedFormats = settings.allowedFormats;
|
||||
this.maxUploadSize = settings.maxUploadSize;
|
||||
this.showSettings = false;
|
||||
},
|
||||
closeSettings() {
|
||||
this.showSettings = false;
|
||||
},
|
||||
openStorageConfig() {
|
||||
this.showStorageConfig = true;
|
||||
this.showMenu = false;
|
||||
},
|
||||
closeStorageConfig() {
|
||||
this.showStorageConfig = false;
|
||||
},
|
||||
openAbout() {
|
||||
this.showAbout = true;
|
||||
this.showMenu = false;
|
||||
},
|
||||
closeAbout() {
|
||||
this.showAbout = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.upload-container {
|
||||
width: 100%;
|
||||
background: #ffffff;
|
||||
border-radius: 14px;
|
||||
box-shadow: 0 12px 24px rgba(25, 118, 210, 0.1);
|
||||
overflow: hidden;
|
||||
border: 1px solid #e3f2fd;
|
||||
}
|
||||
|
||||
.header-wrapper {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 1.5rem 2rem;
|
||||
background: #1976d2;
|
||||
}
|
||||
|
||||
.page-title {
|
||||
margin: 0;
|
||||
color: white;
|
||||
font-size: 1.5rem;
|
||||
font-weight: 600;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.cloud-icon {
|
||||
font-size: 1.8rem;
|
||||
}
|
||||
|
||||
.menu-container {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.menu-icon {
|
||||
color: white;
|
||||
font-size: 1.8rem;
|
||||
cursor: pointer;
|
||||
padding: 0 10px;
|
||||
}
|
||||
|
||||
.dropdown-menu {
|
||||
position: absolute;
|
||||
top: 100%;
|
||||
right: 0;
|
||||
background: #fff;
|
||||
border-radius: 6px;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
||||
min-width: 120px;
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.menu-item {
|
||||
padding: 8px 16px;
|
||||
color: #333;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.menu-item:hover {
|
||||
background: #f0f7ff;
|
||||
}
|
||||
|
||||
.tab-bar {
|
||||
display: flex;
|
||||
padding: 0 2rem;
|
||||
background: #f8fafd;
|
||||
border-bottom: 1px solid #e0eefc;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.tab {
|
||||
padding: 14px 32px;
|
||||
font-size: 14px;
|
||||
color: #607d9f;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.tab.active {
|
||||
color: #1976d2;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.tab.active .tab-underline {
|
||||
width: 100%;
|
||||
background: #1976d2;
|
||||
}
|
||||
|
||||
.tab-underline {
|
||||
height: 2px;
|
||||
width: 0;
|
||||
transition: width 0.3s;
|
||||
}
|
||||
|
||||
.upload-content {
|
||||
padding: 2rem;
|
||||
background: #fcfdff;
|
||||
min-height: 400px;
|
||||
border-top: 1px solid #f0f7ff;
|
||||
}
|
||||
|
||||
.wip-container {
|
||||
padding: 2rem;
|
||||
height: 400px;
|
||||
background: #fcfdff;
|
||||
border-top: 1px solid #f0f7ff;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.wip-message {
|
||||
text-align: center;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.wip-icon {
|
||||
font-size: 3rem;
|
||||
margin-bottom: 1rem;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.wip-message h2 {
|
||||
font-size: 1.5rem;
|
||||
color: #1976d2;
|
||||
margin: 0.5rem 0;
|
||||
}
|
||||
|
||||
.wip-message p {
|
||||
font-size: 1rem;
|
||||
max-width: 400px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user