Files
OpenIsle/open-isle-cli/src/views/SignupReasonPageView.vue
2025-07-15 11:04:42 +08:00

131 lines
3.2 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<div class="reason-page">
<div class="reason-content">
<div class="reason-title">请填写注册理由</div>
<div class="reason-description">
为了我们社区的良性发展请填写注册理由我们将根据你的理由审核你的注册, 谢谢!
</div>
<BaseInput textarea rows="4" v-model="reason" placeholder="20个字以上" />
<div v-if="error" class="error-message">{{ error }}</div>
<div v-if="!isWaitingForRegister" class="signup-page-button-primary" @click="submit">提交</div>
<div v-else class="signup-page-button-primary disabled">提交中...</div>
</div>
</div>
</template>
<script>
import BaseInput from '../components/BaseInput.vue'
import { API_BASE_URL, toast } from '../main'
import { googleSignIn } from '../utils/google'
export default {
name: 'SignupReasonPageView',
components: { BaseInput },
data() {
return {
reason: '',
error: '',
isGoogle: false,
isWaitingForRegister: false
}
},
mounted() {
this.isGoogle = this.$route.query.google === '1'
if (!this.isGoogle) {
if (!sessionStorage.getItem('signup_username')) {
this.$router.push('/signup')
}
}
},
methods: {
async submit() {
if (!this.reason || this.reason.length < 20) {
this.error = '请至少输入20个字'
return
}
if (this.isGoogle) {
googleSignIn(() => { this.$router.push('/') }, this.reason)
return
}
try {
this.isWaitingForRegister = true
const res = await fetch(`${API_BASE_URL}/api/auth/register`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
username: sessionStorage.getItem('signup_username'),
email: sessionStorage.getItem('signup_email'),
password: sessionStorage.getItem('signup_password'),
reason: this.reason
})
})
const data = await res.json()
if (res.ok) {
toast.success('验证码已发送,请查收邮箱')
this.$router.push('/signup?verify=1')
} else {
toast.error(data.error || '发送失败')
}
} catch (e) {
toast.error('发送失败')
} finally {
this.isWaitingForRegister = false
}
}
}
}
</script>
<style scoped>
.reason-page {
display: flex;
justify-content: center;
align-items: center;
background-color: var(--background-color);
height: calc(100vh - var(--header-height));
}
.reason-title {
font-size: 24px;
font-weight: bold;
}
.reason-description {
font-size: 14px;
}
.reason-content {
display: flex;
flex-direction: column;
gap: 20px;
width: 400px;
}
.error-message {
color: red;
font-size: 14px;
}
.signup-page-button-primary {
background-color: var(--primary-color);
color: white;
padding: 10px 20px;
border-radius: 10px;
text-align: center;
cursor: pointer;
}
.signup-page-button-primary:hover {
background-color: var(--primary-color-hover);
}
.signup-page-button-primary.disabled {
background-color: var(--primary-color-disabled);
}
.signup-page-button-primary.disabled:hover {
cursor: not-allowed;
}
</style>