37
37
/>
38
38
</el-form-item >
39
39
</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 >
40
50
<el-col :span =" 24" style =" padding-right : 10px ; padding-left : 10px " >
41
51
<el-form-item prop =" password" >
42
52
<el-input
86
96
</el-form >
87
97
</template >
88
98
<script lang="ts" setup>
89
- import {ElLoading , ElMessageBox } from ' element-plus'
99
+ import { ElLoading } from ' element-plus'
90
100
import LoginFormTitle from ' ./LoginFormTitle.vue'
91
101
import type { RouteLocationNormalizedLoaded } from ' vue-router'
92
102
import { useIcon } from ' @/hooks/web/useIcon'
@@ -110,35 +120,37 @@ const loginLoading = ref(false)
110
120
const verify = ref ()
111
121
const captchaType = ref (' blockPuzzle' ) // blockPuzzle 滑块 clickWord 点击文字
112
122
113
-
114
-
115
123
const getShow = computed (() => unref (getLoginState ) === LoginStateEnum .REGISTER )
116
124
117
125
const equalToPassword = (rule , value , callback ) => {
118
126
if (registerData .registerForm .password !== value ) {
119
- callback (new Error (" 两次输入的密码不一致" ));
127
+ callback (new Error (' 两次输入的密码不一致' ))
120
128
} else {
121
- callback ();
129
+ callback ()
122
130
}
123
- };
131
+ }
124
132
125
133
const registerRules = {
126
134
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' }
129
137
],
130
138
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' }
133
145
],
134
146
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' }
138
150
],
139
151
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' }
142
154
]
143
155
}
144
156
@@ -148,59 +160,67 @@ const registerData = reactive({
148
160
tenantEnable: import .meta .env .VITE_APP_TENANT_ENABLE ,
149
161
registerForm: {
150
162
tenantName: ' ' ,
151
- nickname: " 芋艿 " ,
152
- tenantId: 0 ,
163
+ nickname: ' ' ,
164
+ tenantId: 0 ,
153
165
username: ' ' ,
154
166
password: ' ' ,
155
- confirmPassword: " " ,
167
+ confirmPassword: ' ' ,
156
168
captchaVerification: ' '
157
169
}
158
170
})
159
171
160
- async function handleRegister() {
172
+ async function handleRegister(params ) {
161
173
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
+ }
164
183
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)'
193
197
})
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
+ }
195
215
}
196
216
197
217
// 获取验证码
198
218
const getCode = async () => {
199
- // 情况一,未开启:则直接登录
219
+ // 情况一,未开启:则直接注册
200
220
if (registerData .captchaEnable === ' false' ) {
201
- await handleRegister ()
221
+ await handleRegister ({} )
202
222
} else {
203
- // 情况二,已开启:则展示验证码;只有完成验证码的情况,才进行登录
223
+ // 情况二,已开启:则展示验证码;只有完成验证码的情况,才进行注册
204
224
// 弹出验证码
205
225
verify .value .show ()
206
226
}
0 commit comments