添加登录注册接口

This commit is contained in:
2026-02-23 10:08:37 +08:00
parent 86d58330d5
commit e2632d921f
8 changed files with 101 additions and 86 deletions

View File

@@ -56,11 +56,14 @@
</template>
<script setup lang="ts">
import { Login } from '@/api/login'
import { computed, reactive, ref } from 'vue'
import { useRouter } from 'vue-router'
import { validateEmail, validatePass, validatePrivacy } from './tools'
import OtherLogin from './other-login.vue'
import VisibleCode from './visible-code.vue'
import { useUserInfoStore } from '@/stores'
const userInfoStore = useUserInfoStore()
const router = useRouter()
const ruleForm = reactive({
email: [{ validator: validateEmail, trigger: 'blur' }],
@@ -84,16 +87,29 @@
const onSubmit = () => {
formRef.value?.validate?.((valid) => {
if (valid) {
console.log('submit!')
// console.log('submit!')
isVisible.value = true
} else {
console.log('error submit!')
console.warn('error submit!')
}
})
}
const onVerifyCode = (code: string) => {
console.log(code)
router.push({ name: 'mainInput' })
// console.log(code)
Login({
email: formData.email,
password: formData.password,
verificationCode: code
})
.then((res) => {
if (res) {
userInfoStore.setToken(res)
router.push({ name: 'mainInput' })
}
})
.catch(() => {
console.warn('error verify code!')
})
}
</script>

View File

@@ -60,11 +60,14 @@
</template>
<script setup lang="ts">
import { Register } from '@/api/login'
import { computed, reactive, ref } from 'vue'
import { useRouter } from 'vue-router'
import { validateName, validateEmail, validatePass, validatePrivacy } from './tools'
import OtherLogin from './other-login.vue'
import VisibleCode from './visible-code.vue'
import { useUserInfoStore } from '@/stores'
const userInfoStore = useUserInfoStore()
const router = useRouter()
const ruleForm = reactive({
name: [{ validator: validateName, trigger: 'blur' }],
@@ -90,16 +93,31 @@
const onSubmit = () => {
formRef.value?.validate?.((valid) => {
if (valid) {
console.log('submit!')
// console.log('submit!')
isVisible.value = true
} else {
console.log('error submit!')
console.warn('error submit!')
}
})
}
const onVerifyCode = (code: string) => {
console.log(code)
router.push({ name: 'nuic' })
Register({
username: formData.name,
email: formData.email,
password: formData.password,
verificationCode: code
})
.then((res) => {
if (res) {
userInfoStore.setToken(res)
router.push({ name: 'nuic' })
}
})
.catch(() => {
console.warn('error verify code!')
})
// router.push({ name: 'nuic' })
}
</script>

View File

@@ -12,6 +12,7 @@
</template>
<script setup lang="ts">
import { SendVerificationCode } from '@/api/login'
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
import { CountDown } from '@/utils/tools'
import InputCode from '@/components/input-code.vue'
@@ -44,11 +45,20 @@
clearTime()
})
onMounted(() => {
setTime()
onSendCode()
})
const onSendCode = async () => {
const email = props.email
if (!email) {
console.warn('请输入邮箱')
return
}
setTime()
await SendVerificationCode({ email })
}
const onResend = () => {
if (time.value > 0) return
setTime()
onSendCode()
}
const onVerify = () => {
if (code.value.length !== 6) return