LoginID.vue
5.2 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
<!--
* @Date: 2025-11-10 18:08:59
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-11-12 14:51:18
* @FilePath: /stdj_h5/src/views/LoginID.vue
* @Description: 登录页
-->
<template>
<div class="login-page">
<!-- 顶部LOGO标题 -->
<div class="logo-title">
<img class="logo-img" src="https://cdn.ipadbiz.cn/stdj/images/logo@2x.png" alt="Logo">
</div>
<!-- 戒子身份验证容器 -->
<div class="auth-card">
<div class="card-title">戒子身份验证</div>
<!-- 证件号码 -->
<div class="form-item">
<div class="input-with-icon phone">
<input class="input" type="text" placeholder="请输入证件号码" v-model="id_card" maxlength="18" />
</div>
</div>
<!-- 身份证验证按钮 -->
<div class="form-item">
<div class="btn primary" :class="{ disabled: id_login_disabled }" @click="on_click_login_by_id">立即查询</div>
</div>
</div>
</div>
</template>
<script setup>
import { ref, computed, onMounted } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { useTitle } from '@vueuse/core'
import { loginAPI } from '@/api/index.js'
import { showFailToast, showSuccessToast } from 'vant'
import Cookies from 'js-cookie'
useTitle('戒子身份验证')
const route = useRoute()
const router = useRouter()
// 表单状态
const logging = ref(false)
const id_card = ref('')
/**
* 身份证登录按钮禁用条件
* 说明:登录进行中或输入内容为空时不可操作
*/
const id_login_disabled = computed(function () {
return (
logging.value ||
!is_not_empty(id_card.value)
)
})
/**
* 校验输入是否非空
* 说明:仅校验输入值是否为空字符串(去除首尾空格)
* @param {string} v 输入内容
* @returns {boolean} 是否非空
*/
const is_not_empty = function (v) {
return String(v || '').trim().length > 0
}
/**
* 身份证登录
* 说明:仅凭身份证号进行登录
* @returns {Promise<void>}
*/
const on_login_by_id = async function () {
if (logging.value) return
if (!is_not_empty(id_card.value)) {
showFailToast('请输入证件号码')
return
}
try {
logging.value = true
const { code, data } = await loginAPI({ idcard: id_card.value })
if (code) {
Cookies.set('token-stdj', data.id, { expires: 1 })
showSuccessToast('登录成功')
setTimeout(() => {
// 直接跳转到戒子信息页
router.replace({ path: '/studentInfo' })
}, 1000)
}
} catch (e) {
showFailToast('网络异常,请稍后重试')
} finally {
logging.value = false
}
}
/**
* 点击身份证登录包装函数
* 说明:在禁用态下不触发真实登录逻辑
* @returns {void}
*/
const on_click_login_by_id = function () {
if (id_login_disabled.value) return
on_login_by_id()
}
onMounted(() => {
// 初始化时,检查是否已登录(通过token判断)
const token = Cookies.get('token-stdj')
if (token) {
// 已登录,直接跳转到戒子信息页
router.replace({ path: '/studentInfo' })
}
})
</script>
<style lang="less" scoped>
// 页面背景与布局
.login-page {
min-height: 100vh;
background-color: #FCF8F1; // 整个页面背景色
display: flex;
flex-direction: column;
align-items: center;
padding: 6rem 1rem;
background-image: url('https://cdn.ipadbiz.cn/stdj/images/bg002@2x.png');
background-size: cover;
background-position: center;
}
// 顶部Logo标题
.logo-title {
margin-bottom: 2rem;
}
.logo-img {
height: 5.5rem;
object-fit: contain;
margin-top: 1rem;
}
// 验证容器
.auth-card {
width: 100%;
max-width: 26rem;
background-color: rgba(174, 155, 99, 0.14); // 容器背景色
border-radius: 0.75rem;
padding: 1rem;
box-shadow: 0 0.25rem 1rem rgba(0, 0, 0, 0.06);
}
.card-title {
text-align: center;
color: #432C0E;
font-size: 1.125rem;
font-weight: 700;
margin-top: 0.75rem;
margin-bottom: 1.25rem;
}
// 表单项布局
.form-item {
margin-top: 1.25rem;
margin-bottom: 0.75rem;
}
// 输入框:带左侧图标
.input-with-icon {
position: relative;
}
.input-with-icon::before {
content: '';
position: absolute;
left: 0.75rem;
top: 50%;
width: 1rem;
height: 1rem;
background-size: contain;
background-position: center;
background-repeat: no-repeat;
transform: translateY(-50%);
}
.input-with-icon.phone::before {
background-image: url('https://cdn.ipadbiz.cn/stdj/images/%E8%BA%AB%E4%BB%BD@2x.png');
}
.input {
width: 100%;
height: 2.5rem;
border-radius: 0.5rem;
border: none;
background-color: #FFFFFF;
padding: 0 0.75rem 0 2.25rem; // 为左侧图标预留空间
box-shadow: inset 0 0 0 0.0625rem rgba(0, 0, 0, 0.08);
}
.input::placeholder {
color: #999999;
}
// 按钮样式
.btn {
height: 2.5rem;
padding: 0 0.75rem;
border: none;
border-radius: 0.5rem;
background-color: #A67939; // 获取验证码与立即验证背景色
color: #FFFFFF;
font-weight: 600;
text-align: center;
line-height: 2.5rem;
}
.btn.primary {
width: 100%;
}
.btn.disabled {
// 不可操作态:明显的灰显与禁止样式
opacity: 0.5;
cursor: not-allowed;
pointer-events: none;
filter: grayscale(30%);
box-shadow: none;
}
</style>