仰望星辰工作室

better-staridc-MNBT

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">用户中心 · 我的账户、个人信息与安全</p>
10 <ul class="banner-features">
11 <li><i class="mdi mdi-account-details"></i> 个人信息管理</li>
12 <li><i class="mdi mdi-shield-account-outline"></i> 账号安全保障</li>
13 <li><i class="mdi mdi-sync"></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="username">
28 <t-input v-model="form.username" 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="password">
33 <t-input
34 v-model="form.password"
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>
44 <t-button theme="primary" type="submit" block size="large" :loading="loading">
45 登 录
46 </t-button>
47 </t-form-item>
48 </t-form>
49
50 <p class="switch-note">
51 还没有账号?
52 <router-link to="/register" class="switch-link">立即注册</router-link>
53 </p>
54
55 <p v-if="footer" class="footer-note" v-html="footer"></p>
56 </div>
57 </div>
58 </div>
59</template>
60
61<script setup>
62import { reactive, ref, onMounted } from 'vue'
63import { useRoute, useRouter } from 'vue-router'
64import { MessagePlugin } from 'tdesign-vue-next'
65import { accountLogin, getMe } from '@/account/api/auth'
66import bgImg from '@/shared/assets/login-bg.webp'
67
68const route = useRoute()
69const router = useRouter()
70const boot = window.__TD_BOOT__ || {}
71const siteName = boot.siteName || 'MNBT'
72const footer = boot.footer || ''
73
74const formRef = ref()
75const loading = ref(false)
76
77const form = reactive({
78 username: '',
79 password: '',
80})
81
82const rules = {
83 username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
84 password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
85}
86
87async function onSubmit({ validateResult }) {
88 if (validateResult !== true) return
89 loading.value = true
90 const res = await accountLogin(form.username.trim(), form.password)
91 loading.value = false
92 if (res.ok) {
93 MessagePlugin.success('登录成功,正在跳转…')
94 const me = await getMe()
95 window.__TD_BOOT__ = { ...boot, loggedIn: true, accountUser: me.ok ? me.data.user : null }
96 const redirect = typeof route.query.redirect === 'string' ? route.query.redirect : '/dashboard'
97 router.replace(redirect)
98 return
99 }
100}
101
102onMounted(() => {
103 if (boot.loggedIn && boot.accountUser) {
104 router.replace('/dashboard')
105 }
106})
107</script>
108
109<style scoped>
110.td-login {
111 min-height: 100vh;
112 display: grid;
113 grid-template-columns: 1fr 480px;
114 background: #f5f7fa;
115}
116
117/* ============== 左侧背景图区 ============== */
118.login-banner {
119 position: relative;
120 overflow: hidden;
121 min-height: 100vh;
122}
123.banner-img {
124 position: absolute;
125 inset: 0;
126 width: 100%;
127 height: 100%;
128 object-fit: cover;
129 z-index: 0;
130}
131.banner-overlay {
132 position: absolute;
133 inset: 0;
134 background: linear-gradient(
135 135deg,
136 rgba(0, 30, 80, 0.65) 0%,
137 rgba(0, 50, 130, 0.45) 50%,
138 rgba(20, 80, 180, 0.35) 100%
139 );
140 z-index: 1;
141}
142.banner-content {
143 position: absolute;
144 left: 0;
145 right: 0;
146 bottom: 0;
147 padding: 60px;
148 z-index: 2;
149 color: #fff;
150 animation: banner-fade-in 0.8s ease-out;
151}
152.banner-title {
153 margin: 0;
154 font-size: 38px;
155 font-weight: 700;
156 letter-spacing: -0.02em;
157 text-shadow: 0 2px 16px rgba(0, 0, 0, 0.25);
158}
159.banner-subtitle {
160 margin: 12px 0 28px;
161 font-size: 15px;
162 opacity: 0.92;
163 text-shadow: 0 1px 8px rgba(0, 0, 0, 0.2);
164}
165.banner-features {
166 list-style: none;
167 margin: 0;
168 padding: 0;
169 display: flex;
170 flex-wrap: wrap;
171 gap: 18px;
172}
173.banner-features li {
174 display: flex;
175 align-items: center;
176 gap: 6px;
177 font-size: 13px;
178 opacity: 0.88;
179}
180.banner-features i {
181 font-size: 18px;
182 color: #4fc3f7;
183}
184
185@keyframes banner-fade-in {
186 from { opacity: 0; transform: translateY(20px); }
187 to { opacity: 1; transform: translateY(0); }
188}
189
190/* ============== 右侧登录卡片区 ============== */
191.login-side {
192 display: grid;
193 place-items: center;
194 padding: 32px;
195 min-height: 100vh;
196 background: #fff;
197}
198.login-card {
199 width: min(380px, 100%);
200 animation: card-fade-in 0.6s ease-out;
201}
202@keyframes card-fade-in {
203 from { opacity: 0; transform: translateX(20px); }
204 to { opacity: 1; transform: translateX(0); }
205}
206.brand {
207 margin-bottom: 32px;
208}
209.brand h2 {
210 margin: 0;
211 font-size: 24px;
212 font-weight: 700;
213 letter-spacing: -0.02em;
214 color: var(--td-text);
215}
216.sub {
217 margin: 8px 0 0;
218 font-size: 13px;
219 color: var(--td-text-secondary);
220}
221.switch-note {
222 margin: 20px 0 0;
223 text-align: center;
224 font-size: 13px;
225 color: var(--td-text-secondary);
226}
227.switch-link {
228 color: var(--td-brand);
229 font-weight: 500;
230}
231.footer-note {
232 margin: 16px 0 0;
233 text-align: center;
234 font-size: 12px;
235 color: var(--td-text-secondary);
236}
237
238/* ============== 响应式 ============== */
239@media (max-width: 960px) {
240 .td-login {
241 grid-template-columns: 1fr;
242 }
243 .login-banner {
244 min-height: 280px;
245 max-height: 36vh;
246 }
247 .banner-content {
248 padding: 32px;
249 }
250 .banner-title {
251 font-size: 26px;
252 }
253 .banner-subtitle {
254 margin: 8px 0 16px;
255 font-size: 13px;
256 }
257 .banner-features {
258 gap: 12px;
259 }
260 .banner-features li {
261 font-size: 12px;
262 }
263 .login-side {
264 padding: 24px;
265 min-height: auto;
266 }
267}
268
269@media (max-width: 600px) {
270 .login-banner {
271 min-height: 200px;
272 max-height: 30vh;
273 }
274 .banner-content {
275 padding: 20px;
276 }
277 .banner-title {
278 font-size: 20px;
279 }
280 .banner-features {
281 display: none;
282 }
283 .login-side {
284 padding: 20px 16px;
285 }
286}
287</style>