main.html
10 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>文件上传</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
position: relative;
overflow: hidden;
}
/* 全局遮罩层 */
#global-blur {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.2); /* 半透明遮罩 */
z-index: 2; /* 在 container 上面 */
display: none; /* 默认隐藏,拖拽时显示 */
pointer-events: none; /* 允许事件穿透模糊层 */
}
/* main 容器 */
.container {
z-index: 1; /* 在模糊层之下 */
text-align: center;
width: 600px;
background-color: #fff;
padding: 50px;
border-radius: 15px;
box-shadow: 0 0 15px rgba(0, 0, 0, 0.1);
transition: filter 0.3s ease; /* 添加过渡效果 */
}
/* 当模糊时,应用到 container */
.container.blurred {
filter: blur(10px); /* 对 main 容器应用模糊效果 */
}
.upload-box {
border: 2px dashed #4caf50;
padding: 40px;
cursor: pointer;
border-radius: 15px;
margin-top: 20px;
position: relative;
}
.upload-box input[type="file"] {
display: none;
}
.upload-box label {
color: #4caf50;
font-size: 20px;
cursor: pointer;
}
.file-display {
display: none;
margin-top: 20px;
padding: 20px;
background-color: #f9f9f9;
border: 1px solid #ddd;
border-radius: 15px;
text-align: left;
position: relative; /* 修正删除按钮错位问题 */
}
.file-display img {
width: 40px;
height: 40px;
vertical-align: middle;
margin-right: 10px;
}
.file-display span {
font-size: 18px;
font-weight: bold;
}
.file-display .file-size {
font-size: 16px;
color: #888;
}
.file-display .remove-btn {
position: absolute;
right: 10px; /* 调整删除按钮的位置 */
top: 50%;
transform: translateY(-50%); /* 垂直居中 */
background-color: red;
color: white;
border: none;
border-radius: 50%;
width: 25px;
height: 25px;
cursor: pointer;
font-size: 16px;
line-height: 22px;
text-align: center;
}
.submit-button {
display: inline-block;
background-color: #000;
color: white;
padding: 15px 40px;
border-radius: 30px;
font-size: 18px;
font-weight: bold;
border: none;
cursor: pointer;
margin-top: 20px;
}
.submit-button:hover {
background-color: #333;
}
.submit-button::after {
content: '→';
font-size: 18px;
margin-left: 8px;
}
/* 弹窗样式 */
.popup {
position: fixed;
top: 35%;
left: 30%;
width: 40%;
height: 30%;
background-color: rgba(0, 0, 0, 0.8); /* 半透明黑色背景 */
border-radius: 15px;
display: none;
justify-content: center;
align-items: center;
text-align: center;
z-index: 9999; /* 确保弹窗在最上层 */
color: white;
font-size: 24px;
font-weight: bold;
padding: 20px;
flex-direction: column; /* 让文字上下排列 */
backdrop-filter: blur(5px); /* 添加背景模糊效果 */
}
.popup h2 {
margin-bottom: 10px;
font-size: 32px;
}
.popup p {
font-size: 20px;
}
/* 美化弹窗内容 */
.popup .upload-icon {
font-size: 60px;
margin-bottom: 20px;
color: #4caf50;
}
</style>
</head>
<body>
<!-- 全局模糊层 -->
<div id="global-blur"></div>
<div class="container" id="container">
<h1 style="font-size: 28px;">文件上传</h1>
<p style="font-size: 18px;">请选择一个 CSV 文件上传,我们将为您分析数据</p>
<!-- 文件上传区域 -->
<form id="upload-form" action="/upload" method="post" enctype="multipart/form-data">
<div class="upload-box" id="upload-box">
<label>点击这里或拖拽文件上传</label>
<input id="file-upload" type="file" name="file" accept=".csv" required>
</div>
<!-- 文件展示区域 -->
<div id="file-display" class="file-display">
<img src="https://img.icons8.com/color/48/000000/csv.png" alt="CSV">
<span id="file-name">文件名</span>
<span class="file-size" id="file-size">大小</span>
<button type="button" class="remove-btn" id="remove-btn">×</button>
</div>
<button type="submit" class="submit-button">Start now</button>
</form>
</div>
<!-- 弹窗 -->
<div class="popup" id="popup">
<h2>文件拖拽到此处即可上传</h2>
<p>支持的文件格式:CSV</p>
</div>
<script>
const fileInput = document.getElementById('file-upload');
const fileDisplay = document.getElementById('file-display');
const fileNameDisplay = document.getElementById('file-name');
const fileSizeDisplay = document.getElementById('file-size');
const removeBtn = document.getElementById('remove-btn');
const uploadBox = document.getElementById('upload-box');
const popup = document.getElementById('popup');
const globalBlur = document.getElementById('global-blur');
const container = document.getElementById('container');
// 点击上传区域时,触发文件选择框
uploadBox.addEventListener('click', function() {
fileInput.click();
});
// 监听文件选择事件
fileInput.addEventListener('change', function () {
const file = fileInput.files[0];
if (file) {
if (file.name.endsWith('.csv')) {
fileNameDisplay.textContent = file.name;
fileSizeDisplay.textContent = `, ${Math.round(file.size / 1024)} KB`;
fileDisplay.style.display = 'block';
} else {
alert('只允许上传 CSV 文件');
fileInput.value = ''; // 清除文件
}
// 隐藏模糊层和弹窗
globalBlur.style.display = 'none';
popup.style.display = 'none';
container.classList.remove('blurred'); // 移除模糊效果
}
});
// 删除按钮逻辑
removeBtn.addEventListener('click', function () {
fileDisplay.style.display = 'none';
fileInput.value = '';
// 隐藏模糊层和弹窗
globalBlur.style.display = 'none';
popup.style.display = 'none';
container.classList.remove('blurred'); // 移除模糊效果
});
// 监听整个页面的拖拽进入事件,显示弹窗和模糊层
document.addEventListener('dragenter', function (e) {
e.preventDefault();
globalBlur.style.display = 'block'; // 显示全局模糊层
popup.style.display = 'flex'; // 显示弹出框
container.classList.add('blurred'); // 对 container 添加模糊效果
});
// 监听拖拽离开弹窗区域,隐藏弹窗和模糊层
document.addEventListener('dragleave', function (e) {
e.preventDefault();
// 如果鼠标离开整个窗口,则隐藏模糊层和弹窗
if (e.clientX <= 0 || e.clientY <= 0 || e.clientX >= window.innerWidth || e.clientY >= window.innerHeight) {
globalBlur.style.display = 'none';
popup.style.display = 'none';
container.classList.remove('blurred');
}
});
// 在弹窗上允许拖拽
popup.addEventListener('dragover', function (e) {
e.preventDefault();
});
// 在弹窗上接收文件
popup.addEventListener('drop', function (e) {
e.preventDefault();
globalBlur.style.display = 'none';
popup.style.display = 'none';
container.classList.remove('blurred');
const file = e.dataTransfer.files[0];
if (file && file.name.endsWith('.csv')) {
fileInput.files = e.dataTransfer.files;
const event = new Event('change');
fileInput.dispatchEvent(event);
} else {
alert('只允许上传 CSV 文件');
}
});
// 在页面其他地方的 drop 事件,隐藏模糊层和弹窗
document.addEventListener('drop', function (e) {
e.preventDefault();
globalBlur.style.display = 'none';
popup.style.display = 'none';
container.classList.remove('blurred');
// 不处理文件上传
});
// 防止在页面其他位置的拖拽行为
document.addEventListener('dragover', function (e) {
e.preventDefault();
});
</script>
</body>
</html>