Skip to content

Commit

Permalink
rewrited: Register.vue
Browse files Browse the repository at this point in the history
  • Loading branch information
Muska-Ami committed Sep 6, 2024
1 parent ae26fbb commit 4967355
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 31 deletions.
4 changes: 4 additions & 0 deletions src/api/v2/users/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import info from './info'
import login from './login'
import register from './register'
import reset from './reset'
import send from './send'

export default {
info: info,
login: login,
register: register,
send: send,
reset: reset
}
4 changes: 2 additions & 2 deletions src/api/v2/users/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
import { post } from '@/utils/request'
import base from '@/api/base'

const info = async (username: string, password: string) => {
const login = async (username: string, password: string) => {
const rs = post(`${base.api_v2_url}/users/login`, {
username: username,
password: password
})
return base.buildResponse(await rs)
}

export default info
export default login
24 changes: 24 additions & 0 deletions src/api/v2/users/register.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//@ts-ignore
import { post } from '@/utils/request'
import base from '@/api/base'

const register = async (
username: string,
password: string,
confirm_password: string,
email: string,
verify: number,
qq: number
) => {
const rs = post(`${base.api_v2_url}/users/register`, {
username: username,
password: password,
confirm_password: confirm_password,
email: email,
verify: verify,
qq: qq
})
return base.buildResponse(await rs)
}

export default register
12 changes: 12 additions & 0 deletions src/api/v2/users/send.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//@ts-ignore
import { get } from '@/utils/request'
import base from '@/api/base'

const send = async (email: string) => {
const rs = get(`${base.api_v2_url}/users/send`, {
email: email
})
return base.buildResponse(await rs)
}

export default send
67 changes: 41 additions & 26 deletions src/views/Register.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<n-input type="text" v-model:value="model.verify" placeholder="验证码" />
</n-grid-item>
<n-grid-item span="0:6 600:1">
<n-button ghost round type="primary" @click="sendcode" v-bind:disabled="verify.isClick">
<n-button ghost round type="primary" @click="sendCode" v-bind:disabled="verify.isClick">
{{ verify.msg }}
</n-button>
</n-grid-item>
Expand All @@ -39,7 +39,7 @@
<div style="display: flex; margin-bottom: 20px; justify-content: flex-end">
<n-space>
<n-button type="primary" @click="register" style="margin-right: 10px"> 注册 </n-button>
<n-button ghost type="primary" style="--n-border: none" @click="gologin">
<n-button ghost type="primary" style="--n-border: none" @click="goLogin">
已有账户?去登录
</n-button>
</n-space>
Expand All @@ -50,8 +50,8 @@
<script setup>
import { ref } from 'vue'
import { useLoadingBar, useMessage } from 'naive-ui'
import { post } from '@/utils/request'
import router from '@/router/index'
import api from '@/api'
const refkey = 0
const formRef = ref(null)
Expand All @@ -65,7 +65,7 @@ const model = ref([
email: '',
confirmpwd: '',
qq: '',
verify: ''
verify: null
}
])
Expand All @@ -74,42 +74,57 @@ const verify = ref({
msg: `发送验证码`
})
function gologin() {
function goLogin() {
router.push('/login')
}
function sendcode() {
async function sendCode() {
console.log('尝试发送验证码')
verify.value.isClick = true
verify.value.msg = ref(`正在处理`)
ldb.start()
const rs = post('https://api.locyanfrp.cn/User/SendRegCode', model.value)
rs.then((res) => {
if (res.status) {
message.success(res.message)
verify.value.msg = ref(`已发送`)
} else {
message.error(res.message)
verify.value.isClick = false
verify.value.msg = ref(`发送验证码`)
}
ldb.finish()
console.log('处理发送验证码事件完毕')
})
let rs
try {
rs = await api.v2.users.send(model.value.email)
} catch (e) {
message.error('请求邮件验证代码失败: ' + e)
}
if (!rs) return
if (rs.status) {
message.success('已发送,若未收到请检查收件箱')
verify.value.msg = ref(`已发送`)
} else {
message.error(rs.data.msg)
verify.value.isClick = ref(false)
verify.value.msg = ref(`发送验证码`)
}
ldb.finish()
// console.log('处理发送验证码事件完毕')
}
function register() {
async function register() {
ldb.start()
const rs = post('https://api.locyanfrp.cn/User/DoReg', model.value)
rs.then((res) => {
if (res.status) {
message.success(res.message)
let rs
try {
rs = await api.v2.users.register(
model.value.username,
model.value.password,
model.value.confirmpwd,
model.value.email,
model.value.verify
)
} catch (e) {
message.error('请求注册失败: ' + e)
}
if (!rs) return
// const rs = post('https://api.locyanfrp.cn/User/DoReg', model.value)
if (rs.status === 200) {
message.success(rs.data.msg)
router.push('/login')
} else {
message.error(res.message)
message.error(rs.data.msg)
}
ldb.finish()
})
}
const rules = {
Expand Down
6 changes: 3 additions & 3 deletions src/views/ResetPassword.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
type="text"
v-model:value="model.username"
placeholder="用户名"
@keyup.enter="sendresetmail"
@keyup.enter="sendResetMail"
/>
</n-form-item>
<div style="display: flex; justify-content: flex-end">
<n-space>
<n-button type="primary" @click="sendresetmail" style="margin-right: 10px">
<n-button type="primary" @click="sendResetMail" style="margin-right: 10px">
发送邮件
</n-button>
<n-button ghost type="primary" @click="gologin"> 登录</n-button>
Expand Down Expand Up @@ -124,7 +124,7 @@ function doresetrequest() {
})
}
function sendresetmail() {
function sendResetMail() {
if (status.value === 'sending') {
message.warning('上一个请求正在处理!')
return
Expand Down

0 comments on commit 4967355

Please sign in to comment.