Skip to content

Commit b2dd170

Browse files
committed
实现注册功能
1 parent 2205526 commit b2dd170

File tree

2 files changed

+74
-55
lines changed

2 files changed

+74
-55
lines changed

src/api/login/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import request from '@/config/axios'
22
import { getRefreshToken } from '@/utils/auth'
3-
import type {RegisterVO, UserLoginVO} from './types'
3+
import type { RegisterVO, UserLoginVO } from './types'
44

55
export interface SmsCodeVO {
66
mobile: string
@@ -19,7 +19,6 @@ export const login = (data: UserLoginVO) => {
1919

2020
// 注册
2121
export const register = (data: RegisterVO) => {
22-
console.log("data: RegisterVO=========",data)
2322
return request.post({ url: '/system/auth/register', data })
2423
}
2524

src/views/Login/components/RegisterForm.vue

Lines changed: 73 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@
3737
/>
3838
</el-form-item>
3939
</el-col>
40+
<el-col :span="24" style="padding-right: 10px; padding-left: 10px">
41+
<el-form-item prop="username">
42+
<el-input
43+
v-model="registerData.registerForm.nickname"
44+
placeholder="昵称"
45+
size="large"
46+
:prefix-icon="iconAvatar"
47+
/>
48+
</el-form-item>
49+
</el-col>
4050
<el-col :span="24" style="padding-right: 10px; padding-left: 10px">
4151
<el-form-item prop="password">
4252
<el-input
@@ -86,7 +96,7 @@
8696
</el-form>
8797
</template>
8898
<script lang="ts" setup>
89-
import {ElLoading, ElMessageBox} from 'element-plus'
99+
import { ElLoading } from 'element-plus'
90100
import LoginFormTitle from './LoginFormTitle.vue'
91101
import type { RouteLocationNormalizedLoaded } from 'vue-router'
92102
import { useIcon } from '@/hooks/web/useIcon'
@@ -110,35 +120,37 @@ const loginLoading = ref(false)
110120
const verify = ref()
111121
const captchaType = ref('blockPuzzle') // blockPuzzle 滑块 clickWord 点击文字
112122
113-
114-
115123
const getShow = computed(() => unref(getLoginState) === LoginStateEnum.REGISTER)
116124
117125
const equalToPassword = (rule, value, callback) => {
118126
if (registerData.registerForm.password !== value) {
119-
callback(new Error("两次输入的密码不一致"));
127+
callback(new Error('两次输入的密码不一致'))
120128
} else {
121-
callback();
129+
callback()
122130
}
123-
};
131+
}
124132
125133
const registerRules = {
126134
tenantName: [
127-
{ required: true, trigger: "blur", message: "请输入您所属的租户" },
128-
{ min: 2, max: 20, message: "租户账号长度必须介于 2 和 20 之间", trigger: "blur" }
135+
{ required: true, trigger: 'blur', message: '请输入您所属的租户' },
136+
{ min: 2, max: 20, message: '租户账号长度必须介于 2 和 20 之间', trigger: 'blur' }
129137
],
130138
username: [
131-
{ required: true, trigger: "blur", message: "请输入您的账号" },
132-
{ min: 2, max: 20, message: "用户账号长度必须介于 2 和 20 之间", trigger: "blur" }
139+
{ required: true, trigger: 'blur', message: '请输入您的账号' },
140+
{ min: 4, max: 30, message: '用户账号长度必须介于 4 和 30 之间', trigger: 'blur' }
141+
],
142+
nickname: [
143+
{ required: true, trigger: 'blur', message: '请输入您的昵称' },
144+
{ min: 0, max: 30, message: '昵称长度必须介于 0 和 30 之间', trigger: 'blur' }
133145
],
134146
password: [
135-
{ required: true, trigger: "blur", message: "请输入您的密码" },
136-
{ min: 5, max: 20, message: "用户密码长度必须介于 5 和 20 之间", trigger: "blur" },
137-
{ pattern: /^[^<>"'|\\]+$/, message: "不能包含非法字符:< > \" ' \\\ |", trigger: "blur" }
147+
{ required: true, trigger: 'blur', message: '请输入您的密码' },
148+
{ min: 5, max: 20, message: '用户密码长度必须介于 5 和 20 之间', trigger: 'blur' },
149+
{ pattern: /^[^<>"'|\\]+$/, message: '不能包含非法字符:< > " \' \\\ |', trigger: 'blur' }
138150
],
139151
confirmPassword: [
140-
{ required: true, trigger: "blur", message: "请再次输入您的密码" },
141-
{ required: true, validator: equalToPassword, trigger: "blur" }
152+
{ required: true, trigger: 'blur', message: '请再次输入您的密码' },
153+
{ required: true, validator: equalToPassword, trigger: 'blur' }
142154
]
143155
}
144156
@@ -148,59 +160,67 @@ const registerData = reactive({
148160
tenantEnable: import.meta.env.VITE_APP_TENANT_ENABLE,
149161
registerForm: {
150162
tenantName: '',
151-
nickname: "芋艿",
152-
tenantId: 0,
163+
nickname: '',
164+
tenantId: 0,
153165
username: '',
154166
password: '',
155-
confirmPassword: "",
167+
confirmPassword: '',
156168
captchaVerification: ''
157169
}
158170
})
159171
160-
async function handleRegister() {
172+
async function handleRegister(params) {
161173
loading.value = true
162-
await getTenantId()
163-
registerData.registerForm.tenantId = authUtil.getTenantId()
174+
try {
175+
if (registerData.tenantEnable) {
176+
await getTenantId()
177+
registerData.registerForm.tenantId = authUtil.getTenantId()
178+
}
179+
180+
if (registerData.captchaEnable) {
181+
registerData.registerForm.captchaVerification = params.captchaVerification
182+
}
164183
165-
LoginApi.register(registerData.registerForm).then(() => {
166-
const username = registerData.registerForm.username;
167-
ElMessageBox.alert("<font color='green'>恭喜你,您的账号 " + username + " 注册成功!</font>", "系统提示", {
168-
dangerouslyUseHTMLString: true,
169-
type: "success",
170-
}).then(async () => {
171-
const res = await LoginApi.login(registerData.registerForm)
172-
if (!res) {
173-
return
174-
}
175-
loading.value = ElLoading.service({
176-
lock: true,
177-
text: '正在加载系统中...',
178-
background: 'rgba(0, 0, 0, 0.7)'
179-
})
180-
authUtil.removeLoginForm()
181-
authUtil.setToken(res)
182-
if (!redirect.value) {
183-
redirect.value = '/'
184-
}
185-
// 判断是否为SSO登录
186-
if (redirect.value.indexOf('sso') !== -1) {
187-
window.location.href = window.location.href.replace('/login?redirect=', '')
188-
} else {
189-
push({path: redirect.value || permissionStore.addRouters[0].path})
190-
}
191-
loginLoading.value = false
192-
loading.value.close()
184+
console.log(
185+
'registerData.registerForm.captchaVerification====',
186+
registerData.registerForm.captchaVerification
187+
)
188+
189+
const res = await LoginApi.register(registerData.registerForm)
190+
if (!res) {
191+
return
192+
}
193+
loading.value = ElLoading.service({
194+
lock: true,
195+
text: '正在加载系统中...',
196+
background: 'rgba(0, 0, 0, 0.7)'
193197
})
194-
})
198+
199+
authUtil.removeLoginForm()
200+
201+
authUtil.setToken(res)
202+
if (!redirect.value) {
203+
redirect.value = '/'
204+
}
205+
// 判断是否为SSO登录
206+
if (redirect.value.indexOf('sso') !== -1) {
207+
window.location.href = window.location.href.replace('/login?redirect=', '')
208+
} else {
209+
push({ path: redirect.value || permissionStore.addRouters[0].path })
210+
}
211+
} finally {
212+
loginLoading.value = false
213+
loading.value.close()
214+
}
195215
}
196216
197217
// 获取验证码
198218
const getCode = async () => {
199-
// 情况一,未开启:则直接登录
219+
// 情况一,未开启:则直接注册
200220
if (registerData.captchaEnable === 'false') {
201-
await handleRegister()
221+
await handleRegister({})
202222
} else {
203-
// 情况二,已开启:则展示验证码;只有完成验证码的情况,才进行登录
223+
// 情况二,已开启:则展示验证码;只有完成验证码的情况,才进行注册
204224
// 弹出验证码
205225
verify.value.show()
206226
}

0 commit comments

Comments
 (0)