gaoluyang
2026-05-18 530a2ce7c5483f7a04bec7b80251634fee9e3399
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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
<template>
  <div class="login-page">
    <div class="login-card">
      <div class="card-header">
        <div class="logo">
          <svg-icon icon-class="user" />
        </div>
        <h1>客户关系管理系统</h1>
        <p>高效管理客户资源,驱动业务增长</p>
      </div>
 
      <el-form ref="loginRef" :model="loginForm" :rules="loginRules">
        <el-form-item prop="username">
          <el-input
            v-model="loginForm.username"
            type="text"
            size="large"
            auto-complete="off"
            placeholder="请输入账号"
          >
            <template #prefix><el-icon><User /></el-icon></template>
          </el-input>
        </el-form-item>
 
        <el-form-item prop="password">
          <el-input
            v-model="loginForm.password"
            type="password"
            size="large"
            auto-complete="off"
            placeholder="请输入密码"
            show-password
            @keyup.enter="handleLogin"
          >
            <template #prefix><el-icon><Lock /></el-icon></template>
          </el-input>
        </el-form-item>
 
        <div class="form-options">
          <el-checkbox v-model="loginForm.rememberMe">记住密码</el-checkbox>
          <router-link v-if="register" :to="'/register'">立即注册</router-link>
        </div>
 
        <el-button
          :loading="loading"
          size="large"
          type="primary"
          class="login-btn"
          @click.prevent="handleLogin"
        >
          <span v-if="!loading">登 录</span>
          <span v-else>登录中...</span>
        </el-button>
      </el-form>
    </div>
 
    <div class="bg-pattern">
      <div class="pattern-item"></div>
      <div class="pattern-item"></div>
      <div class="pattern-item"></div>
    </div>
  </div>
</template>
 
<script setup>
import { getCodeImg } from "@/api/login"
import Cookies from "js-cookie"
import { encrypt, decrypt } from "@/utils/jsencrypt"
import useUserStore from "@/store/modules/user"
 
const userStore = useUserStore()
const route = useRoute()
const router = useRouter()
const { proxy } = getCurrentInstance()
 
const loginForm = ref({
  username: "",
  password: "",
  rememberMe: false,
})
 
const loginRules = {
  username: [{ required: true, trigger: "blur", message: "请输入账号" }],
  password: [{ required: true, trigger: "blur", message: "请输入密码" }],
}
 
const loading = ref(false)
const captchaEnabled = ref(true)
const register = ref(false)
const redirect = ref(undefined)
 
watch(
  route,
  (newRoute) => {
    redirect.value = newRoute.query && newRoute.query.redirect
  },
  { immediate: true }
)
 
function handleLogin() {
  proxy.$refs.loginRef.validate((valid) => {
    if (valid) {
      loading.value = true
      Cookies.set("username", loginForm.value.username, { expires: 30 })
      Cookies.set("password", encrypt(loginForm.value.password), { expires: 30 })
      Cookies.set("rememberMe", loginForm.value.rememberMe, { expires: 30 })
      userStore
        .loginCheckFactory(loginForm.value)
        .then(() => {
          const query = route.query
          const otherQueryParams = Object.keys(query).reduce((acc, cur) => {
            if (cur !== "redirect") {
              acc[cur] = query[cur]
            }
            return acc
          }, {})
          router.push({ path: redirect.value || "/", query: otherQueryParams })
        })
        .catch(() => {
          loading.value = false
          if (captchaEnabled.value) {
            getCode()
          }
        })
    }
  })
}
 
function getCode() {
  getCodeImg().then((res) => {
    captchaEnabled.value = res.captchaEnabled === undefined ? true : res.captchaEnabled
    if (captchaEnabled.value) {
      loginForm.value.uuid = res.uuid
    }
  })
}
 
function getCookie() {
  const username = Cookies.get("username")
  const password = Cookies.get("password")
  const rememberMe = Cookies.get("rememberMe")
  loginForm.value = {
    username: username === undefined ? loginForm.value.username : username,
    password: password === undefined ? loginForm.value.password : decrypt(password),
    rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
  }
}
 
getCode()
getCookie()
</script>
 
<style lang="scss" scoped>
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--el-color-primary-light-9) 0%, var(--el-color-primary-light-8) 50%, var(--el-color-primary-light-9) 100%);
  position: relative;
  overflow: hidden;
}
 
.bg-pattern {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
 
  .pattern-item {
    position: absolute;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--el-color-primary-light-7), var(--el-color-primary-light-9));
  }
 
  .pattern-item:nth-child(1) {
    width: 500px;
    height: 500px;
    top: -150px;
    right: -100px;
  }
 
  .pattern-item:nth-child(2) {
    width: 350px;
    height: 350px;
    bottom: -100px;
    left: -80px;
  }
 
  .pattern-item:nth-child(3) {
    width: 200px;
    height: 200px;
    top: 40%;
    left: 15%;
    background: linear-gradient(135deg, var(--el-color-primary-light-8), var(--el-color-primary-light-9));
  }
}
 
.login-card {
  width: 420px;
  padding: 48px 40px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 20px;
  box-shadow: 
    0 4px 6px -1px rgba(0, 0, 0, 0.05),
    0 10px 15px -3px rgba(0, 0, 0, 0.08),
    0 20px 25px -5px rgba(0, 0, 0, 0.05);
  backdrop-filter: blur(10px);
  position: relative;
  z-index: 1;
}
 
.card-header {
  text-align: center;
  margin-bottom: 36px;
 
  .logo {
    width: 72px;
    height: 72px;
    margin: 0 auto 20px;
    background: linear-gradient(135deg, var(--el-color-primary) 0%, var(--el-color-primary-light-3) 100%);
    border-radius: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 20px var(--el-color-primary-light-5);
 
    :deep(svg) {
      width: 36px;
      height: 36px;
      color: #fff;
    }
  }
 
  h1 {
    font-size: 24px;
    font-weight: 600;
    color: #1f2937;
    margin: 0 0 8px;
  }
 
  p {
    font-size: 14px;
    color: #6b7280;
    margin: 0;
  }
}
 
:deep(.el-form-item) {
  margin-bottom: 20px;
}
 
:deep(.el-input__wrapper) {
  border-radius: 12px;
  box-shadow: 0 0 0 1px #e5e7eb;
  padding: 0 16px;
  height: 48px;
  transition: all 0.2s;
 
  &:hover {
    box-shadow: 0 0 0 1px var(--el-color-primary-light-5);
  }
 
  &:focus-within {
    box-shadow: 0 0 0 2px var(--el-color-primary);
  }
}
 
:deep(.el-input__inner) {
  height: 48px;
  font-size: 15px;
  color: #374151;
 
  &::placeholder {
    color: #9ca3af;
  }
}
 
:deep(.el-input__prefix) {
  color: #9ca3af;
  font-size: 18px;
}
 
.form-options {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 8px 0 24px;
 
  :deep(.el-checkbox__label) {
    color: #6b7280;
    font-size: 14px;
  }
 
  :deep(.el-checkbox__input.is-checked .el-checkbox__inner) {
    background-color: var(--el-color-primary);
    border-color: var(--el-color-primary);
  }
 
  a {
    color: var(--el-color-primary);
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    transition: color 0.2s;
 
    &:hover {
      color: var(--el-color-primary-light-3);
    }
  }
}
 
.login-btn {
  width: 100%;
  height: 48px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 500;
  background: linear-gradient(135deg, var(--el-color-primary) 0%, var(--el-color-primary-light-3) 100%);
  border: none;
  box-shadow: 0 4px 14px var(--el-color-primary-light-5);
  transition: all 0.2s;
 
  &:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px var(--el-color-primary-light-4);
  }
}
 
@media (max-width: 480px) {
  .login-card {
    width: 90%;
    padding: 36px 24px;
  }
 
  .card-header {
    h1 {
      font-size: 20px;
    }
  }
}
</style>