Skip to content

Commit ae0a127

Browse files
authored
feat: update the user profile security page (#79)
* feat: update the user profile security page * chore: update the update func naming
1 parent 80f3272 commit ae0a127

File tree

9 files changed

+352
-77
lines changed

9 files changed

+352
-77
lines changed

apps/web-antd/src/adapter/vxe-table.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { VxeTableGridOptions } from '@vben/plugins/vxe-table';
2+
import type { Recordable } from '@vben/types';
23

34
import { h } from 'vue';
45

apps/web-antd/src/api/core/user.ts

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { requestClient } from '#/api/request';
77
export interface MyUserInfo extends UserInfo {
88
id: number;
99
nickname: string;
10-
email: string;
10+
email?: string;
1111
phone?: string;
1212
dept?: string;
1313
last_login_time: string;
@@ -19,7 +19,7 @@ export interface SysUserResult {
1919
dept_id?: number;
2020
username: string;
2121
nickname: string;
22-
email: string;
22+
email?: string;
2323
phone?: string;
2424
avatar?: string;
2525
status: number;
@@ -46,18 +46,13 @@ export interface SysUpdateUserParams {
4646
username: string;
4747
nickname: string;
4848
avatar?: string;
49-
email: string;
49+
email?: string;
5050
phone?: string;
5151
roles: number[];
5252
}
5353

54-
export interface SysAddUserParams {
55-
dept_id?: number;
56-
username: string;
57-
nickname: string;
54+
export interface SysAddUserParams extends SysUpdateUserParams {
5855
password: string;
59-
email: string;
60-
roles: number[];
6156
}
6257

6358
export interface SysResetPasswordParams {
@@ -66,6 +61,16 @@ export interface SysResetPasswordParams {
6661
confirm_password: string;
6762
}
6863

64+
export interface SysUpdateUserPhoneParams {
65+
phone: string;
66+
captcha: string;
67+
}
68+
69+
export interface SysUpdateUserEmailParams {
70+
email: string;
71+
captcha: string;
72+
}
73+
6974
/**
7075
* 获取用户信息
7176
*/
@@ -99,6 +104,20 @@ export async function updateSysUserPasswordApi(
99104
return requestClient.put(`/api/v1/sys/users/${pk}/password`, data);
100105
}
101106

102-
export async function deleteSysUserApi(username: string) {
103-
return requestClient.delete(`/api/v1/sys/users/${username}`);
107+
export async function deleteSysUserApi(pk: number) {
108+
return requestClient.delete(`/api/v1/sys/users/${pk}`);
109+
}
110+
111+
export async function updateSysUserPhoneApi(
112+
pk: number,
113+
data: SysUpdateUserPhoneParams,
114+
) {
115+
return requestClient.put(`/api/v1/sys/users/${pk}/phones`, data);
116+
}
117+
118+
export async function updateSysUserEmailApi(
119+
pk: number,
120+
data: SysUpdateUserEmailParams,
121+
) {
122+
return requestClient.put(`/api/v1/sys/users/${pk}/emails`, data);
104123
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { requestClient } from '#/api/request';
2+
3+
interface phoneCaptchaParams {
4+
phone: string;
5+
}
6+
7+
/**
8+
* 发送短信验证码
9+
*/
10+
export async function getPhoneCaptchaApi(data: phoneCaptchaParams) {
11+
return requestClient.post('/api/v1/phone/captcha', data);
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { requestClient } from '#/api/request';
2+
3+
export interface emailCaptchaParams {
4+
email: string;
5+
}
6+
7+
/**
8+
* 获取邮箱验证码
9+
*/
10+
export async function getEmailCaptchaApi(data: emailCaptchaParams) {
11+
return requestClient.post('/api/v1/email/captcha', data);
12+
}

apps/web-antd/src/views/_core/profile/data.ts

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { AnyFunction } from '@vben/types';
2+
13
import type { VbenFormSchema } from '#/adapter/form';
24
import type { OnActionClickFn, VxeGridProps } from '#/adapter/vxe-table';
35
import type { OnlineMonitorResult } from '#/api';
@@ -6,13 +8,77 @@ import { $t } from '@vben/locales';
68

79
import { z } from '#/adapter/form';
810

9-
export const schema: VbenFormSchema[] = [
11+
const CODE_LENGTH = 6;
12+
export function phoneSchema(sendCodeFunc: AnyFunction): VbenFormSchema[] {
13+
return [
14+
{
15+
component: 'Input',
16+
fieldName: 'phone',
17+
label: '手机号',
18+
rules: z
19+
.string()
20+
.min(1, { message: $t('authentication.mobileTip') })
21+
.refine((v) => /^\d{11}$/.test(v), {
22+
message: $t('authentication.mobileErrortip'),
23+
}),
24+
},
25+
{
26+
component: 'VbenPinInput',
27+
componentProps: {
28+
codeLength: CODE_LENGTH,
29+
createText: (countdown: number) => {
30+
return countdown > 0
31+
? $t('authentication.sendText', [countdown])
32+
: $t('authentication.sendCode');
33+
},
34+
handleSendCode: sendCodeFunc,
35+
placeholder: $t('authentication.code'),
36+
},
37+
fieldName: 'captcha',
38+
label: '验证码',
39+
rules: z.string().length(CODE_LENGTH, {
40+
message: $t('authentication.codeTip', [CODE_LENGTH]),
41+
}),
42+
},
43+
];
44+
}
45+
46+
export function emailSchema(sendCodeFunc: AnyFunction): VbenFormSchema[] {
47+
return [
48+
{
49+
component: 'Input',
50+
fieldName: 'email',
51+
label: '邮箱',
52+
rules: z.string().email({ message: '无效的邮箱地址' }),
53+
},
54+
{
55+
component: 'VbenPinInput',
56+
componentProps: {
57+
codeLength: CODE_LENGTH,
58+
createText: (countdown: number) => {
59+
return countdown > 0
60+
? $t('authentication.sendText', [countdown])
61+
: $t('authentication.sendCode');
62+
},
63+
handleSendCode: sendCodeFunc,
64+
placeholder: $t('authentication.code'),
65+
},
66+
fieldName: 'captcha',
67+
label: '验证码',
68+
rules: z.string().length(CODE_LENGTH, {
69+
message: $t('authentication.codeTip', [CODE_LENGTH]),
70+
}),
71+
},
72+
];
73+
}
74+
75+
export const passwordSchema: VbenFormSchema[] = [
1076
{
1177
component: 'InputPassword',
1278
fieldName: 'old_password',
13-
label: '旧密码',
79+
label: '当前密码',
1480
rules: z
15-
.string({ message: '请输入旧密码' })
81+
.string({ message: '请输入当前密码' })
1682
.min(6, '密码长度不能少于 6 个字符')
1783
.max(20, '密码长度不能超过 20 个字符'),
1884
},

apps/web-antd/src/views/_core/profile/index.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { getUserInfoApi } from '#/api';
99
import ComingSoon from '#/views/_core/fallback/coming-soon.vue';
1010
import BasicInfo from '#/views/_core/profile/basic-info.vue';
1111
import OnlineDevice from '#/views/_core/profile/online-device.vue';
12-
import ResetPassword from '#/views/_core/profile/reset-password.vue';
12+
import Security from '#/views/_core/profile/security.vue';
1313
1414
const userinfo = ref<MyUserInfo>();
1515
const tabList = [
@@ -64,9 +64,9 @@ onMounted(() => {
6464
@tab-change="(key: string) => onTabChange(key)"
6565
>
6666
<div v-if="tabKey === '0'">
67-
<ResetPassword :id="userinfo?.id || 0" />
67+
<Security :userinfo="userinfo" />
6868
</div>
69-
<div class="h-[294px]" v-else-if="tabKey === '1'">
69+
<div v-else-if="tabKey === '1'">
7070
<ComingSoon />
7171
</div>
7272
<div v-else>

apps/web-antd/src/views/_core/profile/reset-password.vue

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)