refactor(signup): 去掉注册验证码
后端已移除验证码功能。 - Signup.vue 删表单项、验证码图、getCaptchaSrc、打开弹窗拉图的 watch、 "Invalid captcha" 错误分支和 .captcha 样式 - authModal store 删 signupForm.captcha、captchaSrc、setCaptchaSrc - api.ts 删 getCaptcha(),signup() 参数去掉 captcha Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -9,7 +9,6 @@ export function signup(data: {
|
||||
username: string
|
||||
email: string
|
||||
password: string
|
||||
captcha: string
|
||||
}) {
|
||||
return http.post("register", data)
|
||||
}
|
||||
@@ -26,10 +25,6 @@ export function getProblemTagList() {
|
||||
return http.get<Tag[]>("problem/tags")
|
||||
}
|
||||
|
||||
export function getCaptcha() {
|
||||
return http.get("captcha")
|
||||
}
|
||||
|
||||
export function getHitokoto() {
|
||||
return http.get("hitokoto")
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { getCaptcha, signup } from "../api"
|
||||
import { signup } from "../api"
|
||||
import { storeToRefs } from "pinia"
|
||||
import { useAuthModalStore } from "../store/authModal"
|
||||
|
||||
@@ -10,7 +10,6 @@ const {
|
||||
signupForm: form,
|
||||
signupLoading: isLoading,
|
||||
signupError: msg,
|
||||
captchaSrc,
|
||||
} = storeToRefs(authStore)
|
||||
const signupRef = useTemplateRef("signupRef")
|
||||
|
||||
@@ -31,9 +30,6 @@ const rules: FormRules = {
|
||||
trigger: "blur",
|
||||
},
|
||||
],
|
||||
captcha: [
|
||||
{ required: true, message: "验证码必填", trigger: "blur", min: 1, max: 10 },
|
||||
],
|
||||
}
|
||||
|
||||
function goLogin() {
|
||||
@@ -50,20 +46,15 @@ function submit() {
|
||||
username: form.value.username,
|
||||
email: form.value.email,
|
||||
password: form.value.password,
|
||||
captcha: form.value.captcha,
|
||||
})
|
||||
} catch (err: any) {
|
||||
if (err.data === "Invalid captcha") {
|
||||
authStore.setSignupError("验证码不正确")
|
||||
} else if (err.data === "Username already exists") {
|
||||
if (err.data === "Username already exists") {
|
||||
authStore.setSignupError("用户名已存在")
|
||||
} else if (err.data === "Email already exists") {
|
||||
authStore.setSignupError("邮箱已存在")
|
||||
} else {
|
||||
authStore.setSignupError("无法注册")
|
||||
}
|
||||
getCaptchaSrc()
|
||||
form.value.captcha = ""
|
||||
} finally {
|
||||
authStore.setSignupLoading(false)
|
||||
}
|
||||
@@ -74,14 +65,6 @@ function submit() {
|
||||
})
|
||||
}
|
||||
|
||||
async function getCaptchaSrc() {
|
||||
const res = await getCaptcha()
|
||||
authStore.setCaptchaSrc(res.data)
|
||||
}
|
||||
|
||||
watch(signupModalOpen, (v) => {
|
||||
if (v) getCaptchaSrc()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -134,18 +117,6 @@ watch(signupModalOpen, (v) => {
|
||||
autocomplete="new-password"
|
||||
/>
|
||||
</n-form-item>
|
||||
<n-form-item label="验证码" path="captcha">
|
||||
<n-space>
|
||||
<n-input
|
||||
v-model:value="form.captcha"
|
||||
clearable
|
||||
name="captcha"
|
||||
id="signup-captcha"
|
||||
autocomplete="off"
|
||||
/>
|
||||
<img class="captcha" :src="captchaSrc" @click="getCaptchaSrc" />
|
||||
</n-space>
|
||||
</n-form-item>
|
||||
<n-alert v-if="msg" type="error" :show-icon="false"> {{ msg }}</n-alert>
|
||||
<n-form-item>
|
||||
<n-space>
|
||||
@@ -158,10 +129,3 @@ watch(signupModalOpen, (v) => {
|
||||
</n-form>
|
||||
</n-modal>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.captcha {
|
||||
height: 34px;
|
||||
cursor: pointer;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -25,15 +25,11 @@ export const useAuthModalStore = defineStore("authModal", () => {
|
||||
email: "",
|
||||
password: "",
|
||||
passwordAgain: "",
|
||||
captcha: "",
|
||||
})
|
||||
|
||||
const signupLoading = ref(false)
|
||||
const signupError = ref("")
|
||||
|
||||
// ==================== 验证码 ====================
|
||||
const captchaSrc = ref("")
|
||||
|
||||
// ==================== 模态框操作 ====================
|
||||
/**
|
||||
* 打开登录模态框
|
||||
@@ -123,13 +119,6 @@ export const useAuthModalStore = defineStore("authModal", () => {
|
||||
signupError.value = ""
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置验证码图片地址
|
||||
*/
|
||||
function setCaptchaSrc(src: string) {
|
||||
captchaSrc.value = src
|
||||
}
|
||||
|
||||
return {
|
||||
// 模态框状态
|
||||
loginModalOpen,
|
||||
@@ -145,9 +134,6 @@ export const useAuthModalStore = defineStore("authModal", () => {
|
||||
signupLoading,
|
||||
signupError,
|
||||
|
||||
// 验证码
|
||||
captchaSrc,
|
||||
|
||||
// 模态框操作
|
||||
openLoginModal,
|
||||
closeLoginModal,
|
||||
@@ -165,6 +151,5 @@ export const useAuthModalStore = defineStore("authModal", () => {
|
||||
setSignupLoading,
|
||||
setSignupError,
|
||||
clearSignupError,
|
||||
setCaptchaSrc,
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user