Skip to content

Commit

Permalink
feat(projects): page manage_user
Browse files Browse the repository at this point in the history
  • Loading branch information
honghuangdc committed Jan 28, 2024
1 parent a19f895 commit 8a170ee
Show file tree
Hide file tree
Showing 11 changed files with 703 additions and 52 deletions.
14 changes: 14 additions & 0 deletions src/constants/business.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,17 @@ export const roleStatusRecord: Record<Api.SystemManage.RoleStatus, App.I18n.I18n
};

export const roleStatusOptions = transformRecordToOption(roleStatusRecord);

export const userGenderRecord: Record<Api.SystemManage.UserGender, App.I18n.I18nKey> = {
'1': 'page.manage.user.gender.male',
'2': 'page.manage.user.gender.female'
};

export const userGenderOptions = transformRecordToOption(userGenderRecord);

export const userStatusRecord: Record<Api.SystemManage.UserStatus, App.I18n.I18nKey> = {
'1': 'page.manage.user.status.enable',
'2': 'page.manage.user.status.disable'
};

export const userStatusOptions = transformRecordToOption(userStatusRecord);
78 changes: 36 additions & 42 deletions src/hooks/common/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,40 @@ import { REG_CODE_SIX, REG_EMAIL, REG_PHONE, REG_PWD, REG_USER_NAME } from '@/co
import { $t } from '@/locales';

export function useFormRules() {
const constantRules = {
userName: [
createRequiredRule($t('form.userName.required')),
{
pattern: REG_USER_NAME,
message: $t('form.userName.invalid'),
trigger: 'change'
}
],
phone: [
createRequiredRule($t('form.phone.required')),
{
pattern: REG_PHONE,
message: $t('form.phone.invalid'),
trigger: 'change'
}
],
pwd: [
createRequiredRule($t('form.pwd.required')),
{
pattern: REG_PWD,
message: $t('form.pwd.invalid'),
trigger: 'change'
}
],
code: [
createRequiredRule($t('form.code.required')),
{
pattern: REG_CODE_SIX,
message: $t('form.code.invalid'),
trigger: 'change'
}
],
email: [
createRequiredRule($t('form.email.required')),
{
pattern: REG_EMAIL,
message: $t('form.email.invalid'),
trigger: 'change'
}
]
const patternRules = {
userName: {
pattern: REG_USER_NAME,
message: $t('form.userName.invalid'),
trigger: 'change'
},
phone: {
pattern: REG_PHONE,
message: $t('form.phone.invalid'),
trigger: 'change'
},
pwd: {
pattern: REG_PWD,
message: $t('form.pwd.invalid'),
trigger: 'change'
},
code: {
pattern: REG_CODE_SIX,
message: $t('form.code.invalid'),
trigger: 'change'
},
email: {
pattern: REG_EMAIL,
message: $t('form.email.invalid'),
trigger: 'change'
}
} satisfies Record<string, App.Global.FormRule>;

const formRules = {
userName: [createRequiredRule($t('form.userName.required')), patternRules.userName],
phone: [createRequiredRule($t('form.phone.required')), patternRules.phone],
pwd: [createRequiredRule($t('form.pwd.required')), patternRules.pwd],
code: [createRequiredRule($t('form.code.required')), patternRules.code],
email: [createRequiredRule($t('form.email.required')), patternRules.email]
} satisfies Record<string, App.Global.FormRule[]>;

/** the default required rule */
Expand All @@ -58,7 +51,8 @@ export function useFormRules() {
}

return {
constantRules,
patternRules,
formRules,
defaultRequiredRule,
createRequiredRule
};
Expand Down
29 changes: 29 additions & 0 deletions src/locales/langs/en-us.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,35 @@ const local: App.I18n.Schema = {
enable: 'Enable',
disable: 'Disable'
}
},
user: {
title: 'User List',
form: {
userName: 'Please enter user name',
userGender: 'Please select gender',
nickName: 'Please enter nick name',
userPhone: 'Please enter phone number',
userEmail: 'Please enter email',
userStatus: 'Please select user status',
userRole: 'Please select user role'
},
userName: 'User Name',
userGender: 'Gender',
nickName: 'Nick Name',
userPhone: 'Phone Number',
userEmail: 'Email',
userStatus: 'User Status',
userRole: 'User Role',
addUser: 'Add User',
editUser: 'Edit User',
gender: {
male: 'Male',
female: 'Female'
},
status: {
enable: 'Enable',
disable: 'Disable'
}
}
}
},
Expand Down
29 changes: 29 additions & 0 deletions src/locales/langs/zh-cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,35 @@ const local: App.I18n.Schema = {
enable: '启用',
disable: '禁用'
}
},
user: {
title: '用户列表',
form: {
userName: '请输入用户名',
userGender: '请选择性别',
nickName: '请输入昵称',
userPhone: '请输入手机号',
userEmail: '请输入邮箱',
userStatus: '请选择用户状态',
userRole: '请选择用户角色'
},
userName: '用户名',
userGender: '性别',
nickName: '昵称',
userPhone: '手机号',
userEmail: '邮箱',
userStatus: '用户状态',
userRole: '用户角色',
addUser: '新增用户',
editUser: '编辑用户',
gender: {
male: '男',
female: '女'
},
status: {
enable: '启用',
disable: '禁用'
}
}
}
},
Expand Down
21 changes: 21 additions & 0 deletions src/service/api/system-manage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,24 @@ export function fetchGetRoleList(params?: Api.SystemManage.RoleSearchParams) {
params
});
}

/**
* get all roles
*
* these roles are all enabled
*/
export function fetchGetAllRoles() {
return request<Api.SystemManage.AllRole[]>({
url: '/systemManage/getAllRoles',
method: 'get'
});
}

/** get user list */
export function fetchGetUserList(params?: Api.SystemManage.UserSearchParams) {
return request<Api.SystemManage.UserList>({
url: '/systemManage/getUserList',
method: 'get',
params
});
}
51 changes: 49 additions & 2 deletions src/typings/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ declare namespace Api {
* backend api module: "systemManage"
*/
namespace SystemManage {
type CommonSearchParams = Pick<Common.PaginatingCommonParams, 'current' | 'size'>;

/**
* role status
*
Expand All @@ -99,11 +101,56 @@ declare namespace Api {

/** role search params */
type RoleSearchParams = CommonType.RecordNullable<
Pick<Api.SystemManage.Role, 'roleName' | 'roleCode' | 'roleStatus'> &
Pick<Common.PaginatingCommonParams, 'current' | 'size'>
Pick<Api.SystemManage.Role, 'roleName' | 'roleCode' | 'roleStatus'> & CommonSearchParams
>;

/** role list */
type RoleList = Common.PaginatingQueryRecord<Role>;

/** all role */
type AllRole = Pick<Role, 'id' | 'roleName' | 'roleCode'>;

/**
* user gender
*
* - "1": "male"
* - "2": "female"
*/
type UserGender = '1' | '2';

/**
* user status
*
* - "1": enabled
* - "2": disabled
*/
type UserStatus = '1' | '2';

/** user */
type User = Common.CommonRecord<{
/** user name */
userName: string;
/** user gender */
userGender: UserGender | null;
/** user nick name */
nickName: string;
/** user phone */
userPhone: string;
/** user email */
userEmail: string;
/** user role code collection */
userRoles: string[];
/** user status */
userStatus: UserStatus | null;
}>;

/** user search params */
type UserSearchParams = CommonType.RecordNullable<
Pick<Api.SystemManage.User, 'userName' | 'userGender' | 'nickName' | 'userPhone' | 'userEmail' | 'userStatus'> &
CommonSearchParams
>;

/** user list */
type UserList = Common.PaginatingQueryRecord<User>;
}
}
29 changes: 29 additions & 0 deletions src/typings/app.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,35 @@ declare namespace App {
disable: string;
};
};
user: {
title: string;
form: {
userName: string;
userGender: string;
nickName: string;
userPhone: string;
userEmail: string;
userStatus: string;
userRole: string;
};
userName: string;
userGender: string;
nickName: string;
userPhone: string;
userEmail: string;
userStatus: string;
userRole: string;
addUser: string;
editUser: string;
gender: {
male: string;
female: string;
};
status: {
enable: string;
disable: string;
};
};
};
};
form: {
Expand Down
15 changes: 9 additions & 6 deletions src/views/_builtin/login/modules/pwd-login.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { reactive } from 'vue';
import { computed, reactive } from 'vue';
import { $t } from '@/locales';
import { loginModuleRecord } from '@/constants/app';
import { useRouterPush } from '@/hooks/common/router';
Expand All @@ -13,7 +13,6 @@ defineOptions({
const authStore = useAuthStore();
const { toggleLoginModule } = useRouterPush();
const { formRef, validate } = useNaiveForm();
const { constantRules } = useFormRules();
interface FormModel {
userName: string;
Expand All @@ -25,10 +24,14 @@ const model: FormModel = reactive({
password: '123456'
});
const rules: Record<keyof FormModel, App.Global.FormRule[]> = {
userName: constantRules.userName,
password: constantRules.pwd
};
const rules = computed<Record<keyof FormModel, App.Global.FormRule[]>>(() => {
const { formRules } = useFormRules(); // inside computed to make locale reactive
return {
userName: formRules.userName,
password: formRules.pwd
};
});
async function handleSubmit() {
await validate();
Expand Down
Loading

1 comment on commit 8a170ee

@vercel
Copy link

@vercel vercel bot commented on 8a170ee Jan 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

soybean-admin – ./

soybean-admin-soybeanjs.vercel.app
soybean-admin-eta.vercel.app
soybean-admin-git-main-soybeanjs.vercel.app

Please sign in to comment.