mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 19:49:19 +08:00
refactor: 重构用户模型
This commit is contained in:
@@ -41,8 +41,8 @@ export namespace AccountDTO {
|
||||
|
||||
/** 账户过滤条件 */
|
||||
export interface AccountFilterDTO {
|
||||
/** 登录账号(模糊查询) */
|
||||
loginCode?: string;
|
||||
/** 登录用户名(模糊查询) */
|
||||
username?: string;
|
||||
/** 用户姓名(模糊查询) */
|
||||
realName?: string;
|
||||
/** 手机号码(精确查询) */
|
||||
|
||||
@@ -23,8 +23,8 @@ export namespace AccountVO {
|
||||
role?: 'member' | 'owner';
|
||||
/** 公司成员角色展示名 */
|
||||
roleName?: string;
|
||||
/** 登录账号 */
|
||||
loginCode: string;
|
||||
/** 登录用户名(可空) */
|
||||
username?: string | null;
|
||||
/** 手机号码 */
|
||||
phone?: string;
|
||||
/** 用户姓名 */
|
||||
|
||||
@@ -16,7 +16,7 @@ export namespace AuthApi {
|
||||
|
||||
/** 注册接口参数 */
|
||||
export interface RegisterParams {
|
||||
loginCode?: string;
|
||||
username?: string;
|
||||
phone?: string;
|
||||
password: string;
|
||||
}
|
||||
@@ -38,7 +38,7 @@ export namespace AuthApi {
|
||||
};
|
||||
departmentId?: number;
|
||||
positionId?: number;
|
||||
loginCode: string;
|
||||
username?: string | null;
|
||||
phone?: string;
|
||||
realName: string;
|
||||
avatar?: string;
|
||||
|
||||
@@ -5,14 +5,14 @@
|
||||
export namespace SuperAccountDTO {
|
||||
/** 超管创建账户参数 */
|
||||
export interface SuperCreateAccountDTO {
|
||||
/** 登录账号 */
|
||||
loginCode: string;
|
||||
/** 登录用户名(可选) */
|
||||
username?: string;
|
||||
/** 密码 */
|
||||
password: string;
|
||||
/** 用户姓名 */
|
||||
realName: string;
|
||||
/** 手机号码 */
|
||||
phone?: string;
|
||||
phone: string;
|
||||
/** 公司ID */
|
||||
companyId: number;
|
||||
/** 部门ID */
|
||||
@@ -29,8 +29,8 @@ export namespace SuperAccountDTO {
|
||||
|
||||
/** 超管更新账户参数 */
|
||||
export interface SuperUpdateAccountDTO {
|
||||
/** 登录账号 */
|
||||
loginCode?: string;
|
||||
/** 登录用户名 */
|
||||
username?: string;
|
||||
/** 用户姓名 */
|
||||
realName?: string;
|
||||
/** 手机号码 */
|
||||
@@ -53,8 +53,8 @@ export namespace SuperAccountDTO {
|
||||
|
||||
/** 账户过滤条件 */
|
||||
export interface AccountFilterDTO {
|
||||
/** 登录账号(模糊查询) */
|
||||
loginCode?: string;
|
||||
/** 登录用户名(模糊查询) */
|
||||
username?: string;
|
||||
/** 用户姓名(模糊查询) */
|
||||
realName?: string;
|
||||
/** 手机号码(精确查询) */
|
||||
|
||||
@@ -19,8 +19,8 @@ export namespace SuperAccountVO {
|
||||
positionId?: number;
|
||||
/** 岗位名称 */
|
||||
positionName?: string;
|
||||
/** 登录账号 */
|
||||
loginCode: string;
|
||||
/** 登录用户名(可空) */
|
||||
username?: string | null;
|
||||
/** 手机号码 */
|
||||
phone?: string;
|
||||
/** 用户姓名 */
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
export namespace UserDTO {
|
||||
/** 更新用户信息参数 */
|
||||
export interface UpdateUserInfoDTO {
|
||||
/** 登录账号(用户名) */
|
||||
loginCode?: string;
|
||||
/** 登录用户名(用户名) */
|
||||
username?: string;
|
||||
/** 用户名称 */
|
||||
realName?: string;
|
||||
/** 头像图片ID */
|
||||
@@ -29,8 +29,8 @@ export namespace UserDTO {
|
||||
export interface UserFilterDTO {
|
||||
/** 用户名称(模糊查询) */
|
||||
realName?: string;
|
||||
/** 登录账号(模糊查询) */
|
||||
loginCode?: string;
|
||||
/** 登录用户名(模糊查询) */
|
||||
username?: string;
|
||||
/** 手机号码(精确查询) */
|
||||
phone?: string;
|
||||
/** 用户角色 */
|
||||
|
||||
@@ -18,8 +18,8 @@ export namespace UserVO {
|
||||
departmentId?: number;
|
||||
/** 岗位id */
|
||||
positionId?: number;
|
||||
/** 登录账号 */
|
||||
loginCode: string;
|
||||
/** 登录用户名(可空) */
|
||||
username?: string | null;
|
||||
/** 手机号码 */
|
||||
phone?: string;
|
||||
/** 用户名称 */
|
||||
|
||||
@@ -56,7 +56,7 @@ const companyOptions = computed(() =>
|
||||
// 用户选项
|
||||
const userOptions = computed(() =>
|
||||
userList.value.map((user) => ({
|
||||
label: `${user.realName} (${user.loginCode})`,
|
||||
label: `${user.realName} (${user.username})`,
|
||||
value: user.id,
|
||||
user,
|
||||
})),
|
||||
@@ -146,14 +146,14 @@ const loadUsers = async (reset = false) => {
|
||||
|
||||
const params: PageQueryDTO<{
|
||||
companyId?: number;
|
||||
loginCode?: string;
|
||||
username?: string;
|
||||
realName?: string;
|
||||
}> = {
|
||||
page: userPage.value,
|
||||
pageSize: userPageSize.value,
|
||||
filters: {
|
||||
realName: userSearchValue.value || undefined,
|
||||
loginCode: userSearchValue.value || undefined,
|
||||
username: userSearchValue.value || undefined,
|
||||
companyId: formData.value.companyId,
|
||||
},
|
||||
};
|
||||
@@ -369,7 +369,7 @@ defineExpose({
|
||||
<div class="flex-1">
|
||||
<div class="text-lg font-medium">{{ selectedUser.realName }}</div>
|
||||
<div class="text-gray-500">
|
||||
登录账号: {{ selectedUser.loginCode }}
|
||||
登录用户名: {{ selectedUser.username }}
|
||||
</div>
|
||||
<div class="text-gray-500">
|
||||
手机号码: {{ selectedUser.phone || '-' }}
|
||||
|
||||
@@ -211,7 +211,7 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
userInfo = {
|
||||
...user,
|
||||
userId: user.id.toString(),
|
||||
username: user.loginCode,
|
||||
username: user.username || user.phone || '',
|
||||
desc: user.remark || '',
|
||||
homePath: preferences.app.defaultHomePath,
|
||||
avatar: user.avatar || '',
|
||||
|
||||
@@ -17,11 +17,11 @@ const formSchema = computed((): VbenFormSchema[] => {
|
||||
{
|
||||
component: 'VbenInput',
|
||||
componentProps: {
|
||||
placeholder: '请输入登录账号或手机号',
|
||||
placeholder: '请输入登录用户名或手机号',
|
||||
},
|
||||
fieldName: 'account',
|
||||
label: '登录账号',
|
||||
rules: z.string().min(1, { message: '请输入登录账号或手机号' }),
|
||||
rules: z.string().min(1, { message: '请输入登录用户名或手机号' }),
|
||||
},
|
||||
{
|
||||
component: 'VbenInputPassword',
|
||||
|
||||
@@ -18,10 +18,10 @@ const formSchema = computed((): VbenFormSchema[] => {
|
||||
{
|
||||
component: 'VbenInput',
|
||||
componentProps: {
|
||||
placeholder: '请输入登录账号(可选)',
|
||||
placeholder: '请输入登录用户名(可选)',
|
||||
},
|
||||
fieldName: 'loginCode',
|
||||
label: '登录账号',
|
||||
fieldName: 'username',
|
||||
label: '登录用户名',
|
||||
rules: z.string().optional(),
|
||||
},
|
||||
{
|
||||
@@ -103,7 +103,7 @@ const formSchema = computed((): VbenFormSchema[] => {
|
||||
|
||||
function handleSubmit(value: Recordable<any>) {
|
||||
// 验证至少填写一个登录方式
|
||||
if (!value.loginCode && !value.phone) {
|
||||
if (!value.username && !value.phone) {
|
||||
// 这里可以添加错误提示
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ const accountFormModalRef = ref();
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = ref({
|
||||
loginCode: undefined as string | undefined,
|
||||
username: undefined as string | undefined,
|
||||
realName: undefined as string | undefined,
|
||||
phone: undefined as string | undefined,
|
||||
companyId: undefined as number | undefined,
|
||||
@@ -68,11 +68,11 @@ const gridReloadRef = ref<(() => void) | null>(null);
|
||||
const formOptions = computed(() => ({
|
||||
schemas: [
|
||||
{
|
||||
fieldName: 'loginCode',
|
||||
label: '登录账号',
|
||||
fieldName: 'username',
|
||||
label: '登录用户名',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入登录账号(回车搜索)',
|
||||
placeholder: '请输入登录用户名(回车搜索)',
|
||||
onPressEnter: () => gridReloadRef.value?.(),
|
||||
},
|
||||
},
|
||||
@@ -127,8 +127,8 @@ const accountTableBaseColumns: VxeGridProps<any>['columns'] = [
|
||||
title: '序号',
|
||||
},
|
||||
{
|
||||
field: 'loginCode',
|
||||
title: '登录账号',
|
||||
field: 'username',
|
||||
title: '登录用户名',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
|
||||
@@ -44,7 +44,7 @@ const presetCompany = ref<CompanyVO.CompanyInfoVO | null>(null);
|
||||
const formData = ref<
|
||||
SuperAccountDTO.SuperCreateAccountDTO & { status?: number }
|
||||
>({
|
||||
loginCode: '',
|
||||
username: '',
|
||||
password: '',
|
||||
realName: '',
|
||||
phone: '',
|
||||
@@ -66,7 +66,7 @@ const statusOptions = [
|
||||
|
||||
function resetForm() {
|
||||
formData.value = {
|
||||
loginCode: '',
|
||||
username: '',
|
||||
password: '',
|
||||
realName: '',
|
||||
phone: '',
|
||||
@@ -97,7 +97,7 @@ function open(
|
||||
|
||||
if (accountData) {
|
||||
formData.value = {
|
||||
loginCode: accountData.loginCode,
|
||||
username: accountData.username,
|
||||
password: '',
|
||||
realName: accountData.realName,
|
||||
phone: accountData.phone || '',
|
||||
@@ -170,20 +170,20 @@ defineExpose({
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label="登录账号"
|
||||
name="loginCode"
|
||||
label="登录用户名"
|
||||
name="username"
|
||||
:rules="[
|
||||
{ required: true, message: '请输入登录账号' },
|
||||
{ min: 3, max: 20, message: '登录账号长度为3-20个字符' },
|
||||
{ min: 3, max: 20, message: '登录用户名长度为3-20个字符' },
|
||||
{
|
||||
pattern: /^[a-zA-Z0-9_]+$/,
|
||||
message: '登录账号只能包含字母、数字和下划线',
|
||||
pattern: /^$|^[a-zA-Z0-9_]+$/,
|
||||
message: '登录用户名只能包含字母、数字和下划线',
|
||||
},
|
||||
]"
|
||||
>
|
||||
<Input
|
||||
v-model:value="formData.loginCode"
|
||||
placeholder="请输入登录账号"
|
||||
v-model:value="formData.username"
|
||||
placeholder="可选,留空由用户自行设置"
|
||||
allow-clear
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
@@ -218,7 +218,10 @@ defineExpose({
|
||||
<Form.Item
|
||||
label="手机号"
|
||||
name="phone"
|
||||
:rules="[{ pattern: /^1[3-9]\d{9}$/, message: '请输入有效的手机号' }]"
|
||||
:rules="[
|
||||
{ required: true, message: '请输入手机号' },
|
||||
{ pattern: /^1[3-9]\d{9}$/, message: '请输入有效的手机号' },
|
||||
]"
|
||||
>
|
||||
<Input v-model:value="formData.phone" placeholder="请输入手机号" />
|
||||
</Form.Item>
|
||||
|
||||
@@ -69,7 +69,7 @@ const companyPagination = ref({
|
||||
const currentCompany = ref<CompanyVO.CompanyInfoVO | null>(null);
|
||||
|
||||
const searchForm = ref({
|
||||
loginCode: undefined as string | undefined,
|
||||
username: undefined as string | undefined,
|
||||
realName: undefined as string | undefined,
|
||||
phone: undefined as string | undefined,
|
||||
status: undefined as number | undefined,
|
||||
@@ -98,8 +98,8 @@ const accountTableBaseColumns: VxeGridProps<SuperAccountVO.AccountInfoVO>['colum
|
||||
[
|
||||
{ type: 'seq' as const, minWidth: 56, title: '序号' },
|
||||
{
|
||||
field: 'loginCode',
|
||||
title: '登录账号',
|
||||
field: 'username',
|
||||
title: '登录用户名',
|
||||
minWidth: 120,
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
@@ -214,7 +214,7 @@ const gridOptions: VxeGridProps<SuperAccountVO.AccountInfoVO> = {
|
||||
page: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
filters: {
|
||||
loginCode: searchForm.value.loginCode || undefined,
|
||||
username: searchForm.value.username || undefined,
|
||||
realName: searchForm.value.realName || undefined,
|
||||
phone: searchForm.value.phone || undefined,
|
||||
status: searchForm.value.status,
|
||||
@@ -502,9 +502,9 @@ onMounted(() => {
|
||||
<template #extra>
|
||||
<Space wrap size="small" class="max-w-[min(100%,42rem)]">
|
||||
<Input
|
||||
v-model:value="searchForm.loginCode"
|
||||
v-model:value="searchForm.username"
|
||||
allow-clear
|
||||
placeholder="登录账号"
|
||||
placeholder="登录用户名"
|
||||
class="w-[120px]"
|
||||
@press-enter="refreshTable"
|
||||
/>
|
||||
|
||||
@@ -141,8 +141,8 @@ async function loadAccounts() {
|
||||
(a: AccountVO.AccountInfoVO) => ({
|
||||
value: a.id,
|
||||
label: a.realName
|
||||
? `${a.realName}${a.loginCode ? `(${a.loginCode})` : ''}`
|
||||
: a.loginCode || `用户#${a.id}`,
|
||||
? `${a.realName}${a.username ? `(${a.username})` : ''}`
|
||||
: a.username || `用户#${a.id}`,
|
||||
}),
|
||||
);
|
||||
} catch {
|
||||
|
||||
@@ -37,7 +37,7 @@ const avatarSrc = computed(() => {
|
||||
|
||||
// 表单数据(与更新接口 DTO 一致,头像 ID 用 undefined 表示未变更/未上传)
|
||||
const formData = reactive<UserDTO.UpdateUserInfoDTO>({
|
||||
loginCode: '',
|
||||
username: '',
|
||||
realName: '',
|
||||
phone: '',
|
||||
remark: '',
|
||||
@@ -50,7 +50,7 @@ async function fetchUserInfo() {
|
||||
loading.value = true;
|
||||
const data = await getUserInfoApi();
|
||||
userInfo.value = data;
|
||||
formData.loginCode = data.loginCode || '';
|
||||
formData.username = data.username || '';
|
||||
formData.realName = data.realName || '';
|
||||
formData.phone = data.phone || '';
|
||||
formData.remark = data.remark || '';
|
||||
@@ -118,7 +118,7 @@ async function handleSubmit() {
|
||||
|
||||
function handleReset() {
|
||||
if (userInfo.value) {
|
||||
formData.loginCode = userInfo.value.loginCode || '';
|
||||
formData.username = userInfo.value.username || '';
|
||||
formData.realName = userInfo.value.realName || '';
|
||||
formData.phone = userInfo.value.phone || '';
|
||||
formData.remark = userInfo.value.remark || '';
|
||||
@@ -210,13 +210,23 @@ fetchUserInfo();
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 用户名 -->
|
||||
<!-- 登录用户名(可选,用于账号登录) -->
|
||||
<Form.Item
|
||||
label="用户名"
|
||||
name="loginCode"
|
||||
:rules="[{ required: true, message: '请输入用户名' }]"
|
||||
label="登录用户名"
|
||||
name="username"
|
||||
:rules="[
|
||||
{ min: 3, max: 20, message: '登录用户名长度为3-20个字符' },
|
||||
{
|
||||
pattern: /^$|^[a-zA-Z0-9_]+$/,
|
||||
message: '登录用户名只能包含字母、数字和下划线',
|
||||
},
|
||||
]"
|
||||
>
|
||||
<Input v-model:value="formData.loginCode" placeholder="请输入用户名" />
|
||||
<Input
|
||||
v-model:value="formData.username"
|
||||
placeholder="可选,设置后可用账号登录"
|
||||
allow-clear
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<!-- 真实姓名 -->
|
||||
|
||||
Reference in New Issue
Block a user