sendCode.vue
7.05 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
<template>
<div class="login_container">
<div class="login_title">我的验证码是</div>
<div class="title_dsc">
<span>验证码已发送至{{ ruleForm.phone }}</span>
<el-button type="primary" :loading="loading" class="send_code" @click="sendPhoneMsg" link>
{{ isWait ? '请等待' + timeCount + 's' : '发送验证码' }}
</el-button>
</div>
<el-form ref="ruleFormRef" :model="ruleForm" :rules="rules" class="login_from">
<!--<el-form-item prop="msgCodeAll">
<el-input v-model="ruleForm.msgCodeAll" :maxlength="6" placeholder="请输入验证码" class="msg_code_input"></el-input>
</el-form-item>-->
<el-form-item prop="code" class="code_wrap">
<el-input v-model="ruleForm.code" :maxlength="6" placeholder="请输入验证码" v-show="false"></el-input>
<el-input v-model="ruleForm.msgCode1" :maxlength="1" ref="input1"
@keyup="change($event, 'input2', '')"></el-input>
<el-input v-model="ruleForm.msgCode2" :maxlength="1" ref="input2"
@keyup="change($event, 'input3', 'input1')"></el-input>
<el-input v-model="ruleForm.msgCode3" :maxlength="1" ref="input3"
@keyup="change($event, 'input4', 'input2')"></el-input>
<el-input v-model="ruleForm.msgCode4" :maxlength="1" ref="input4"
@keyup="change($event, 'input5', 'input3')"></el-input>
<el-input v-model="ruleForm.msgCode5" :maxlength="1" ref="input5"
@keyup="change($event, 'input6', 'input4')"></el-input>
<el-input v-model="ruleForm.msgCode6" :maxlength="1" ref="input6"
@keyup="change($event, 'msgCode6His', 'input5')"></el-input>
</el-form-item>
</el-form>
<el-button type="primary" round :loading="loading" @click="submitForm" style="width: 100%" class="primary-btn">
登录
</el-button>
</div>
</template>
<script setup lang='ts'>
import * as api from "./../interface/login"
import {formValidationForm} from "./../utils/vaildation"
import router from "../router/index";
import '../assets/css/login.scss'
import {Encrypt, Decrypt} from './../utils/sm4Untils'
import {setToken, getTokenKey, removeTokenKey} from '../utils/auth'
import {loginMain} from '../store/index'
import {storeToRefs} from 'pinia';
let state = reactive({})
let loginAct = loginMain()
let {isWait, timeCount, registerTimer} = storeToRefs(loginAct)
const route = useRoute();
let ruleForm = reactive({
phone: undefined,
code: undefined,
msgCode1: undefined,
msgCode2: undefined,
msgCode3: undefined,
msgCode4: undefined,
msgCode5: undefined,
msgCode6: undefined,
msgCode6His: undefined
})
let loading = ref(false)
let input1 = ref(null)
let input2 = ref(null)
let input3 = ref(null)
let input4 = ref(null)
let input5 = ref(null)
let input6 = ref(null)
// ruleForm.phone = Decrypt(route.path.split("/").slice(-1).toString(), '5492123658175926')
// let phoneJson = Decrypt(route.query.p, '5492123658175926')
// ruleForm.phone = JSON.parse(phoneJson).p
ruleForm.phone = getTokenKey("p")
let change = (e: any, name1: string, name2: string) => {
if (e.keyCode == 8) {
if (name2 == 'input1') {
ruleForm.msgCode1 = ""
input1.value.focus()
} else if (name2 == 'input2') {
ruleForm.msgCode2 = ""
input2.value.focus()
} else if (name2 == 'input3') {
ruleForm.msgCode3 = ""
input3.value.focus()
} else if (name2 == 'input4') {
ruleForm.msgCode4 = ""
input4.value.focus()
} else if (name2 == 'input5') {
if (ruleForm.msgCode6His == "") {
ruleForm.msgCode5 = ""
input5.value.focus()
} else {
ruleForm.msgCode6His = ""
}
}
} else {
if (name1 == 'input2') {
input2.value.focus()
} else if (name1 == 'input3') {
input3.value.focus()
} else if (name1 == 'input4') {
input4.value.focus()
} else if (name1 == 'input5') {
input5.value.focus()
} else if (name1 == 'input6') {
input6.value.focus()
} else if (name1 == 'msgCode6His') {
ruleForm.msgCode6His = e.target.value
}
}
}
let rules = reactive<FormRules>({
phone: [
{required: true, message: "请输入手机号", trigger: ["blur", "change"]},
{validator: formValidationForm.Form().checkCellPhone_N, trigger: ["blur"]}
],
code: [
{required: true, message: "请输入验证码", trigger: ["blur", "change"]}
],
})
const ruleFormRef = ref<FormInstance>()
ruleForm.code = computed({
get() {
if (ruleForm.msgCode1 && ruleForm.msgCode2 && ruleForm.msgCode3 && ruleForm.msgCode4 && ruleForm.msgCode5 && ruleForm.msgCode6) {
return ruleForm.code = ruleForm.msgCode1 + ruleForm.msgCode2 + ruleForm.msgCode3 + ruleForm.msgCode4 + ruleForm.msgCode5 + ruleForm.msgCode6
}
},
set(value) {
/*const val = value.split('')
ruleForm.msgCode1 = val[0]
ruleForm.msgCode2 = val[1]
ruleForm.msgCode3 = val[2]
ruleForm.msgCode4 = val[3]
ruleForm.msgCode5 = val[4]
ruleForm.msgCode6 = val[5]*/
}
})
const sendPhoneMsg = () => {
if (!formValidationForm.checkCellPhone(ruleForm.phone)) {
ElMessage.error("请输入正确的手机号")
router.push('/login')
return
}
api.sendPhoneMsg({phone: ruleForm.phone}).then(res => {
if (registerTimer.value == null) {
registerTimer.value = setInterval(() => {
timeCount.value--
loginAct.setTimeCount(timeCount.value)
loginAct.setWait(true)
if (timeCount.value <= 0) {
loginAct.setWait(false)
clearInterval(registerTimer.value)
loginAct.setRegisterTimer()
}
}, 1000)
}
})
}
// let data = {"searchValue":null,"createBy":"","createTime":"2023-04-23 16:57:45","updateBy":"","updateTime":null,"remark":null,"params":{},"userId":58819,"nickName":"用户_W944z9r10Cf5","phoneNumber":"18801291704","companyName":"极易净水科技(上海)有限公司","userType":"5","email":"","userName":null,"avatar":"","password":"a6f7ecdf917b1c31b91fede7b2b36062","identityType":null,"identityTypeStr":null,"identityTypeStatus":"0","status":"0","delFlag":"0","loginIp":"","loginDate":null,"contact":null,"contactPhone":null,"pwdUpdateTime":null,"companyId":null,"productIds":null,"msgCode":null,"token":"54b07ffc861d41ecba6e67b511640903","loginType":null,"hasMsg":3,"hasRzsq":0}
let submitForm = () => {
/*setToken(data.token)
loginAct.setUserInfo(data)
router.push('/mine')*/
ruleFormRef.value.validate((vaild, fileds) => {
if (vaild) {
api.loginAPI(ruleForm).then(res => {
ElMessage.success("登录成功")
setToken(res.data.token)
removeTokenKey("p")
loginAct.setUserInfo(res.data)
router.push('/mine')
})
}
})
}
/*const submitForm = async (formEl: FormInstance | undefined) => {
if (!formEl) return
await formEl.validate((valid, fields) => {
if (valid) {
console.log('submit!')
} else {
console.log('error submit!', fields)
}
})
}*/
onMounted(()=> {
sendPhoneMsg()
})
const arrowPath = ref("/login")
defineExpose({arrowPath})
</script>
<style scoped>
</style>