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
|
username: string
|
||||||
email: string
|
email: string
|
||||||
password: string
|
password: string
|
||||||
captcha: string
|
|
||||||
}) {
|
}) {
|
||||||
return http.post("register", data)
|
return http.post("register", data)
|
||||||
}
|
}
|
||||||
@@ -26,10 +25,6 @@ export function getProblemTagList() {
|
|||||||
return http.get<Tag[]>("problem/tags")
|
return http.get<Tag[]>("problem/tags")
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getCaptcha() {
|
|
||||||
return http.get("captcha")
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getHitokoto() {
|
export function getHitokoto() {
|
||||||
return http.get("hitokoto")
|
return http.get("hitokoto")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { getCaptcha, signup } from "../api"
|
import { signup } from "../api"
|
||||||
import { storeToRefs } from "pinia"
|
import { storeToRefs } from "pinia"
|
||||||
import { useAuthModalStore } from "../store/authModal"
|
import { useAuthModalStore } from "../store/authModal"
|
||||||
|
|
||||||
@@ -10,7 +10,6 @@ const {
|
|||||||
signupForm: form,
|
signupForm: form,
|
||||||
signupLoading: isLoading,
|
signupLoading: isLoading,
|
||||||
signupError: msg,
|
signupError: msg,
|
||||||
captchaSrc,
|
|
||||||
} = storeToRefs(authStore)
|
} = storeToRefs(authStore)
|
||||||
const signupRef = useTemplateRef("signupRef")
|
const signupRef = useTemplateRef("signupRef")
|
||||||
|
|
||||||
@@ -31,9 +30,6 @@ const rules: FormRules = {
|
|||||||
trigger: "blur",
|
trigger: "blur",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
captcha: [
|
|
||||||
{ required: true, message: "验证码必填", trigger: "blur", min: 1, max: 10 },
|
|
||||||
],
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function goLogin() {
|
function goLogin() {
|
||||||
@@ -50,20 +46,15 @@ function submit() {
|
|||||||
username: form.value.username,
|
username: form.value.username,
|
||||||
email: form.value.email,
|
email: form.value.email,
|
||||||
password: form.value.password,
|
password: form.value.password,
|
||||||
captcha: form.value.captcha,
|
|
||||||
})
|
})
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
if (err.data === "Invalid captcha") {
|
if (err.data === "Username already exists") {
|
||||||
authStore.setSignupError("验证码不正确")
|
|
||||||
} else if (err.data === "Username already exists") {
|
|
||||||
authStore.setSignupError("用户名已存在")
|
authStore.setSignupError("用户名已存在")
|
||||||
} else if (err.data === "Email already exists") {
|
} else if (err.data === "Email already exists") {
|
||||||
authStore.setSignupError("邮箱已存在")
|
authStore.setSignupError("邮箱已存在")
|
||||||
} else {
|
} else {
|
||||||
authStore.setSignupError("无法注册")
|
authStore.setSignupError("无法注册")
|
||||||
}
|
}
|
||||||
getCaptchaSrc()
|
|
||||||
form.value.captcha = ""
|
|
||||||
} finally {
|
} finally {
|
||||||
authStore.setSignupLoading(false)
|
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>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -134,18 +117,6 @@ watch(signupModalOpen, (v) => {
|
|||||||
autocomplete="new-password"
|
autocomplete="new-password"
|
||||||
/>
|
/>
|
||||||
</n-form-item>
|
</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-alert v-if="msg" type="error" :show-icon="false"> {{ msg }}</n-alert>
|
||||||
<n-form-item>
|
<n-form-item>
|
||||||
<n-space>
|
<n-space>
|
||||||
@@ -158,10 +129,3 @@ watch(signupModalOpen, (v) => {
|
|||||||
</n-form>
|
</n-form>
|
||||||
</n-modal>
|
</n-modal>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
|
||||||
.captcha {
|
|
||||||
height: 34px;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|||||||
@@ -25,15 +25,11 @@ export const useAuthModalStore = defineStore("authModal", () => {
|
|||||||
email: "",
|
email: "",
|
||||||
password: "",
|
password: "",
|
||||||
passwordAgain: "",
|
passwordAgain: "",
|
||||||
captcha: "",
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const signupLoading = ref(false)
|
const signupLoading = ref(false)
|
||||||
const signupError = ref("")
|
const signupError = ref("")
|
||||||
|
|
||||||
// ==================== 验证码 ====================
|
|
||||||
const captchaSrc = ref("")
|
|
||||||
|
|
||||||
// ==================== 模态框操作 ====================
|
// ==================== 模态框操作 ====================
|
||||||
/**
|
/**
|
||||||
* 打开登录模态框
|
* 打开登录模态框
|
||||||
@@ -123,13 +119,6 @@ export const useAuthModalStore = defineStore("authModal", () => {
|
|||||||
signupError.value = ""
|
signupError.value = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置验证码图片地址
|
|
||||||
*/
|
|
||||||
function setCaptchaSrc(src: string) {
|
|
||||||
captchaSrc.value = src
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
// 模态框状态
|
// 模态框状态
|
||||||
loginModalOpen,
|
loginModalOpen,
|
||||||
@@ -145,9 +134,6 @@ export const useAuthModalStore = defineStore("authModal", () => {
|
|||||||
signupLoading,
|
signupLoading,
|
||||||
signupError,
|
signupError,
|
||||||
|
|
||||||
// 验证码
|
|
||||||
captchaSrc,
|
|
||||||
|
|
||||||
// 模态框操作
|
// 模态框操作
|
||||||
openLoginModal,
|
openLoginModal,
|
||||||
closeLoginModal,
|
closeLoginModal,
|
||||||
@@ -165,6 +151,5 @@ export const useAuthModalStore = defineStore("authModal", () => {
|
|||||||
setSignupLoading,
|
setSignupLoading,
|
||||||
setSignupError,
|
setSignupError,
|
||||||
clearSignupError,
|
clearSignupError,
|
||||||
setCaptchaSrc,
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user