仰望星辰工作室

better-staridc-MNBT

better-staridc-MNBT/ templates/tdesign/spa/src/docker/views/LoginView.vue 10.0 KB · 441 行 原始文件
Z zfhsh first commit 2 个月前
1<template>
2 <div class="td-login">
3 <!-- 左侧背景图区 -->
4 <div class="login-banner">
5 <img :src="bgImg" alt="" class="banner-img" />
6 <div class="banner-overlay"></div>
7 <div class="banner-content">
8 <h1 class="banner-title">{{ siteName }}</h1>
9 <p class="banner-subtitle">Docker 容器控制台 · 弹性便捷的容器管理平台</p>
10 <ul class="banner-features">
11 <li><i class="mdi mdi-docker"></i> 容器应用一键部署</li>
12 <li><i class="mdi mdi-apps"></i> 精选应用商店</li>
13 <li><i class="mdi mdi-gauge"></i> 资源配额灵活管控</li>
14 </ul>
15 </div>
16 </div>
17
18 <!-- 右侧登录卡片区 -->
19 <div class="login-side">
20 <div class="login-card">
21 <div class="brand">
22 <img :src="logoImg" alt="Docker" class="brand-logo" />
23 <h2>Docker 容器控制台</h2>
24 <p class="sub">{{ siteName }} · 用户登录</p>
25 </div>
26
27 <!-- 内容输入区 -->
28 <div class="login-form">
29 <t-input
30 v-model="form.username"
31 placeholder="请输入账号"
32 size="large"
33 clearable
34 autofocus
35 @enter="onSubmit"
36 >
37 <template #prefix-icon><i class="mdi mdi-account-outline"></i></template>
38 </t-input>
39
40 <t-input
41 v-model="form.password"
42 :type="showPwd ? 'text' : 'password'"
43 placeholder="请输入密码"
44 size="large"
45 @enter="onSubmit"
46 >
47 <template #prefix-icon><i class="mdi mdi-lock-outline"></i></template>
48 <template #suffix-icon>
49 <i
50 class="mdi pwd-toggle"
51 :class="showPwd ? 'mdi-eye-off-outline' : 'mdi-eye-outline'"
52 @click.stop="showPwd = !showPwd"
53 ></i>
54 </template>
55 </t-input>
56
57 <t-button
58 theme="default"
59 variant="outline"
60 block
61 size="large"
62 :disabled="captchaOk"
63 @click="showCaptcha = true"
64 >
65 <template v-if="captchaOk">
66 <i class="mdi mdi-check-circle" style="color:#2ba471"></i> 验证通过
67 </template>
68 <template v-else>
69 <i class="mdi mdi-shield-check-outline"></i> 点击进行人机验证
70 </template>
71 </t-button>
72
73 <t-button
74 theme="primary"
75 block
76 size="large"
77 :loading="loading"
78 :disabled="!captchaOk"
79 @click="onSubmit"
80 >
81 登 录
82 </t-button>
83 </div>
84
85 <!-- 滑块验证码弹窗 -->
86 <Teleport to="body">
87 <Transition name="captcha-modal">
88 <div v-if="showCaptcha" class="captcha-overlay" @click.self="onCloseCaptcha">
89 <div class="captcha-dialog">
90 <div class="captcha-dialog__head">
91 <h3>安全验证</h3>
92 <button class="captcha-dialog__close" @click="onCloseCaptcha" title="关闭">
93 <i class="mdi mdi-close"></i>
94 </button>
95 </div>
96 <div class="captcha-dialog__body">
97 <SliderCaptcha
98 ref="captchaRef"
99 @success="onCaptchaSuccess"
100 @reset="onCaptchaReset"
101 />
102 </div>
103 </div>
104 </div>
105 </Transition>
106 </Teleport>
107
108 <p v-if="footer" class="footer-note" v-html="footer"></p>
109 </div>
110 </div>
111 </div>
112</template>
113
114<script setup>
115import { reactive, ref } from 'vue'
116import { MessagePlugin } from 'tdesign-vue-next'
117import { dockerLogin } from '@/docker/api/docker'
118import SliderCaptcha from '@/docker/components/SliderCaptcha.vue'
119import logoImg from '@/shared/assets/docker.svg'
120import bgImg from '@/shared/assets/login-bg.webp'
121
122const boot = window.__TD_BOOT__ || {}
123const siteName = boot.siteName || 'MNBT'
124const footer = boot.footer || ''
125
126const loading = ref(false)
127const showPwd = ref(false)
128const showCaptcha = ref(false)
129const captchaOk = ref(false)
130const captchaRef = ref(null)
131const form = reactive({ username: '', password: '' })
132
133function onCaptchaSuccess() {
134 captchaOk.value = true
135 // 短暂展示成功状态后关闭弹窗
136 setTimeout(() => {
137 showCaptcha.value = false
138 }, 800)
139}
140
141function onCaptchaReset() {
142 captchaOk.value = false
143}
144
145function onCloseCaptcha() {
146 showCaptcha.value = false
147}
148
149async function onSubmit() {
150 if (!form.username || !form.password) {
151 MessagePlugin.warning('请输入账号和密码')
152 return
153 }
154 if (!captchaOk.value) {
155 MessagePlugin.warning('请完成滑块验证')
156 return
157 }
158 loading.value = true
159 const r = await dockerLogin(form.username.trim(), form.password)
160 loading.value = false
161 if (!r.ok) {
162 // 登录失败后刷新验证码状态
163 captchaOk.value = false
164 showCaptcha.value = false
165 } else {
166 MessagePlugin.success(r.message || '登录成功')
167 setTimeout(() => {
168 window.location.href = './console.php'
169 }, 600)
170 }
171}
172</script>
173
174<style scoped>
175.td-login {
176 min-height: 100vh;
177 display: grid;
178 grid-template-columns: 1fr 480px;
179 background: #f5f7fa;
180}
181
182/* ============== 左侧背景图区 ============== */
183.login-banner {
184 position: relative;
185 overflow: hidden;
186 min-height: 100vh;
187}
188.banner-img {
189 position: absolute;
190 inset: 0;
191 width: 100%;
192 height: 100%;
193 object-fit: cover;
194 z-index: 0;
195}
196.banner-overlay {
197 position: absolute;
198 inset: 0;
199 background: linear-gradient(
200 135deg,
201 rgba(0, 30, 80, 0.6) 0%,
202 rgba(0, 50, 130, 0.4) 50%,
203 rgba(20, 80, 180, 0.3) 100%
204 );
205 z-index: 1;
206}
207.banner-content {
208 position: absolute;
209 left: 0;
210 right: 0;
211 bottom: 0;
212 padding: 60px;
213 z-index: 2;
214 color: #fff;
215 animation: banner-fade-in 0.8s ease-out;
216}
217.banner-title {
218 margin: 0;
219 font-size: 38px;
220 font-weight: 700;
221 letter-spacing: -0.02em;
222 text-shadow: 0 2px 16px rgba(0, 0, 0, 0.25);
223}
224.banner-subtitle {
225 margin: 12px 0 28px;
226 font-size: 15px;
227 opacity: 0.92;
228 text-shadow: 0 1px 8px rgba(0, 0, 0, 0.2);
229}
230.banner-features {
231 list-style: none;
232 margin: 0;
233 padding: 0;
234 display: flex;
235 flex-wrap: wrap;
236 gap: 18px;
237}
238.banner-features li {
239 display: flex;
240 align-items: center;
241 gap: 6px;
242 font-size: 13px;
243 opacity: 0.88;
244}
245.banner-features i {
246 font-size: 18px;
247 color: #4fc3f7;
248}
249
250@keyframes banner-fade-in {
251 from { opacity: 0; transform: translateY(20px); }
252 to { opacity: 1; transform: translateY(0); }
253}
254
255/* ============== 右侧登录卡片区 ============== */
256.login-side {
257 display: grid;
258 place-items: center;
259 padding: 32px;
260 min-height: 100vh;
261 background: #fff;
262}
263.login-card {
264 width: min(380px, 100%);
265 animation: card-fade-in 0.6s ease-out;
266}
267@keyframes card-fade-in {
268 from { opacity: 0; transform: translateX(20px); }
269 to { opacity: 1; transform: translateX(0); }
270}
271.brand {
272 margin-bottom: 32px;
273 text-align: center;
274}
275.brand-logo {
276 width: 96px;
277 height: auto;
278 margin-bottom: 10px;
279}
280.brand h2 {
281 margin: 0;
282 font-size: 22px;
283 font-weight: 700;
284 letter-spacing: -0.02em;
285 color: var(--td-text, #1f2937);
286}
287.sub {
288 margin: 8px 0 0;
289 font-size: 13px;
290 color: var(--td-text-secondary, #6b7280);
291}
292/* 内容输入区 */
293.login-form {
294 display: flex;
295 flex-direction: column;
296 gap: 16px;
297}
298.pwd-toggle {
299 cursor: pointer;
300 font-size: 17px;
301 color: var(--td-text-color-secondary, #6b7280);
302 transition: color 0.15s;
303}
304.pwd-toggle:hover {
305 color: var(--td-text-color-primary, #1f2937);
306}
307
308/* ---- 验证码弹窗 ---- */
309.captcha-overlay {
310 position: fixed;
311 inset: 0;
312 background: rgba(0, 0, 0, 0.45);
313 backdrop-filter: blur(4px);
314 display: grid;
315 place-items: center;
316 z-index: 9999;
317 padding: 24px;
318}
319.captcha-dialog {
320 width: min(420px, 100%);
321 background: #fff;
322 border-radius: 16px;
323 box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
324 overflow: hidden;
325 animation: captcha-dialog-in 0.25s ease-out;
326}
327@keyframes captcha-dialog-in {
328 from { opacity: 0; transform: scale(0.92) translateY(12px); }
329 to { opacity: 1; transform: scale(1) translateY(0); }
330}
331.captcha-dialog__head {
332 display: flex;
333 align-items: center;
334 justify-content: space-between;
335 padding: 16px 20px 0;
336}
337.captcha-dialog__head h3 {
338 margin: 0;
339 font-size: 16px;
340 font-weight: 600;
341 color: #1f2937;
342}
343.captcha-dialog__close {
344 border: none;
345 background: none;
346 padding: 4px;
347 border-radius: 6px;
348 cursor: pointer;
349 color: #999;
350 font-size: 18px;
351 transition: color 0.15s, background 0.15s;
352}
353.captcha-dialog__close:hover {
354 color: #333;
355 background: #f3f4f6;
356}
357.captcha-dialog__body {
358 padding: 16px 20px 20px;
359}
360
361/* 弹窗过渡动画 */
362.captcha-modal-enter-active {
363 transition: opacity 0.2s ease;
364}
365.captcha-modal-leave-active {
366 transition: opacity 0.15s ease;
367}
368.captcha-modal-enter-from,
369.captcha-modal-leave-to {
370 opacity: 0;
371}
372
373.footer-note {
374 margin: 24px 0 0;
375 text-align: center;
376 font-size: 12px;
377 color: var(--td-text-secondary, #6b7280);
378}
379
380/* ============== 响应式 ============== */
381@media (max-width: 960px) {
382 .td-login {
383 grid-template-columns: 1fr;
384 }
385 .login-banner {
386 min-height: 280px;
387 max-height: 36vh;
388 }
389 .banner-content {
390 padding: 32px;
391 }
392 .banner-title {
393 font-size: 26px;
394 }
395 .banner-subtitle {
396 margin: 8px 0 16px;
397 font-size: 13px;
398 }
399 .banner-features {
400 gap: 12px;
401 }
402 .banner-features li {
403 font-size: 12px;
404 }
405 .login-side {
406 padding: 24px;
407 min-height: auto;
408 }
409}
410
411@media (max-width: 600px) {
412 .login-banner {
413 min-height: 200px;
414 max-height: 30vh;
415 }
416 .banner-content {
417 padding: 20px;
418 }
419 .banner-title {
420 font-size: 20px;
421 }
422 .banner-features {
423 display: none;
424 }
425 .login-side {
426 padding: 20px 16px;
427 }
428}
429
430/* 验证码弹窗移动端 */
431@media (max-width: 600px) {
432 .captcha-dialog {
433 width: calc(100vw - 32px);
434 margin: 0 16px;
435 }
436 .captcha-dialog__body {
437 padding: 12px 14px 16px;
438 }
439 .captcha-dialog__head { padding: 14px 16px 0; }
440}
441</style>