better-staridc-MNBT
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">管理后台 · 安全可控的运维管理平台</p>
10 <ul class="banner-features">
11 <li><i class="mdi mdi-shield-check-outline"></i> 多层安全防护</li>
12 <li><i class="mdi mdi-chart-timeline-variant"></i> 实时数据监控</li>
13 <li><i class="mdi mdi-server-network"></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 <h2>{{ siteName }}</h2>
23 <p class="sub">管理后台 · 管理员登录</p>
24 </div>
25
26 <t-form ref="formRef" :data="form" :rules="rules" :label-width="0" @submit="onSubmit">
27 <t-form-item name="user">
28 <t-input v-model="form.user" placeholder="管理员账号" clearable size="large" @enter="onSubmit">
29 <template #prefix-icon><i class="mdi mdi-account"></i></template>
30 </t-input>
31 </t-form-item>
32 <t-form-item name="pass">
33 <t-input
34 v-model="form.pass"
35 type="password"
36 placeholder="密码"
37 size="large"
38 @enter="onSubmit"
39 >
40 <template #prefix-icon><i class="mdi mdi-lock"></i></template>
41 </t-input>
42 </t-form-item>
43 <t-form-item v-if="needCaptcha" name="code">
44 <div class="captcha-row">
45 <t-input
46 v-model="form.code"
47 placeholder="验证码"
48 maxlength="8"
49 size="large"
50 @enter="onSubmit"
51 >
52 <template #prefix-icon><i class="mdi mdi-check-all"></i></template>
53 </t-input>
54 <img
55 class="captcha-img"
56 :src="captchaUrl"
57 alt="验证码"
58 title="点击刷新"
59 @click="refreshCaptcha"
60 />
61 </div>
62 </t-form-item>
63 <t-form-item>
64 <t-button theme="primary" type="submit" block size="large" :loading="loading">
65 登 录
66 </t-button>
67 </t-form-item>
68 </t-form>
69
70 <p v-if="footer" class="footer-note" v-html="footer"></p>
71 </div>
72 </div>
73 </div>
74</template>
75
76<script setup>
77import { reactive, ref, computed, onMounted } from 'vue'
78import { useRouter } from 'vue-router'
79import { MessagePlugin } from 'tdesign-vue-next'
80import { login } from '@/admin/api/auth'
81import bgImg from '@/shared/assets/login-bg.webp'
82
83const router = useRouter()
84const boot = window.__TD_BOOT__ || {}
85const siteName = boot.siteName || 'MNBT'
86const footer = boot.footer || ''
87const needCaptcha = !!boot.needCaptcha
88
89const formRef = ref()
90const loading = ref(false)
91const captchaSeed = ref(Date.now())
92
93const form = reactive({
94 user: '',
95 pass: '',
96 code: '',
97})
98
99const rules = {
100 user: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
101 pass: [{ required: true, message: '请输入密码', trigger: 'blur' }],
102 code: needCaptcha
103 ? [{ required: true, message: '请输入验证码', trigger: 'blur' }]
104 : [],
105}
106
107const captchaUrl = computed(() => `${boot.codeUrl || './code.php'}?r=${captchaSeed.value}`)
108
109function refreshCaptcha() {
110 captchaSeed.value = Date.now()
111}
112
113async function onSubmit({ validateResult }) {
114 if (validateResult !== true) return
115 loading.value = true
116 const code = needCaptcha ? form.code : '0000'
117 const res = await login(form.user.trim(), form.pass, code)
118 loading.value = false
119 if (res.ok) {
120 MessagePlugin.success('登录成功,正在跳转…')
121 window.__TD_BOOT__ = { ...boot, loggedIn: true, adminUser: form.user.trim() }
122 window.location.href = './index.php'
123 return
124 }
125 if (needCaptcha) refreshCaptcha()
126}
127
128onMounted(() => {
129 if (boot.loggedIn) {
130 router.replace('/dashboard')
131 }
132})
133</script>
134
135<style scoped>
136.td-login {
137 min-height: 100vh;
138 display: grid;
139 grid-template-columns: 1fr 480px;
140 background: #f5f7fa;
141}
142
143/* ============== 左侧背景图区 ============== */
144.login-banner {
145 position: relative;
146 overflow: hidden;
147 min-height: 100vh;
148}
149.banner-img {
150 position: absolute;
151 inset: 0;
152 width: 100%;
153 height: 100%;
154 object-fit: cover;
155 z-index: 0;
156}
157.banner-overlay {
158 position: absolute;
159 inset: 0;
160 background: linear-gradient(
161 135deg,
162 rgba(0, 30, 80, 0.65) 0%,
163 rgba(0, 50, 130, 0.45) 50%,
164 rgba(20, 80, 180, 0.35) 100%
165 );
166 z-index: 1;
167}
168.banner-content {
169 position: absolute;
170 left: 0;
171 right: 0;
172 bottom: 0;
173 padding: 60px;
174 z-index: 2;
175 color: #fff;
176 animation: banner-fade-in 0.8s ease-out;
177}
178.banner-title {
179 margin: 0;
180 font-size: 38px;
181 font-weight: 700;
182 letter-spacing: -0.02em;
183 text-shadow: 0 2px 16px rgba(0, 0, 0, 0.25);
184}
185.banner-subtitle {
186 margin: 12px 0 28px;
187 font-size: 15px;
188 opacity: 0.92;
189 text-shadow: 0 1px 8px rgba(0, 0, 0, 0.2);
190}
191.banner-features {
192 list-style: none;
193 margin: 0;
194 padding: 0;
195 display: flex;
196 flex-wrap: wrap;
197 gap: 18px;
198}
199.banner-features li {
200 display: flex;
201 align-items: center;
202 gap: 6px;
203 font-size: 13px;
204 opacity: 0.88;
205}
206.banner-features i {
207 font-size: 18px;
208 color: #4fc3f7;
209}
210
211@keyframes banner-fade-in {
212 from { opacity: 0; transform: translateY(20px); }
213 to { opacity: 1; transform: translateY(0); }
214}
215
216/* ============== 右侧登录卡片区 ============== */
217.login-side {
218 display: grid;
219 place-items: center;
220 padding: 32px;
221 min-height: 100vh;
222 background: #fff;
223}
224.login-card {
225 width: min(380px, 100%);
226 animation: card-fade-in 0.6s ease-out;
227}
228@keyframes card-fade-in {
229 from { opacity: 0; transform: translateX(20px); }
230 to { opacity: 1; transform: translateX(0); }
231}
232.brand {
233 margin-bottom: 32px;
234}
235.brand h2 {
236 margin: 0;
237 font-size: 24px;
238 font-weight: 700;
239 letter-spacing: -0.02em;
240 color: var(--td-text);
241}
242.sub {
243 margin: 8px 0 0;
244 font-size: 13px;
245 color: var(--td-text-secondary);
246}
247.captcha-row {
248 display: flex;
249 gap: 10px;
250 width: 100%;
251}
252.captcha-row :deep(.t-input) {
253 flex: 1;
254 min-width: 0;
255}
256.captcha-img {
257 height: 40px;
258 border-radius: 6px;
259 cursor: pointer;
260 border: 1px solid var(--td-border);
261 flex-shrink: 0;
262}
263.footer-note {
264 margin: 24px 0 0;
265 text-align: center;
266 font-size: 12px;
267 color: var(--td-text-secondary);
268}
269
270/* ============== 响应式 ============== */
271@media (max-width: 960px) {
272 .td-login {
273 grid-template-columns: 1fr;
274 }
275 .login-banner {
276 min-height: 280px;
277 max-height: 36vh;
278 }
279 .banner-content {
280 padding: 32px;
281 }
282 .banner-title {
283 font-size: 26px;
284 }
285 .banner-subtitle {
286 margin: 8px 0 16px;
287 font-size: 13px;
288 }
289 .banner-features {
290 gap: 12px;
291 }
292 .banner-features li {
293 font-size: 12px;
294 }
295 .login-side {
296 padding: 24px;
297 min-height: auto;
298 }
299}
300
301@media (max-width: 600px) {
302 .login-banner {
303 min-height: 200px;
304 max-height: 30vh;
305 }
306 .banner-content {
307 padding: 20px;
308 }
309 .banner-title {
310 font-size: 20px;
311 }
312 .banner-features {
313 display: none;
314 }
315 .login-side {
316 padding: 20px 16px;
317 }
318}
319</style>