Commit f6450718 by chenwq

```

feat(ui): 新增UCascader组件并扩展SearchForm支持级联选择器

- 添加UCascader组件封装Antd Cascader
- 在SearchForm组件中集成cascader类型字段
- 扩展FieldType联合类型添加cascader选项
- 更新UI包导出包含新组件

feat(account): 实现账号管理页面功能

- 创建完整的账号管理页面(AccountManage)
- 集成用户列表查询、搜索、分页功能
- 实现组织架构级联选择搜索
- 添加角色筛选和状态筛选功能
- 设计表格列展示用户信息详情

feat(api): 扩展用户管理和组织架构API接口

- 新增user模块提供用户分页查询接口
- 更新org模块OrgNode接口字段结构
- 添加role模块获取角色选项接口
- 完善权限点定义包含用户管理相关权限

refactor(search): 优化SearchForm日期范围选择器属性

- 为日期范围选择器添加disabled和size属性传递
- 确保组件属性正确透传到底层组件
```
1 parent d03ce44f
import { Cascader, type CascaderProps } from 'antd';
import type { DefaultOptionType } from 'antd/es/cascader';
export type UCascaderProps = CascaderProps<DefaultOptionType, keyof DefaultOptionType, false>;
/** 项目统一级联选择。 */
export function UCascader(props: UCascaderProps) {
return <Cascader {...props} />;
}
...@@ -12,6 +12,9 @@ export type { UInputProps } from './components/Input'; ...@@ -12,6 +12,9 @@ export type { UInputProps } from './components/Input';
export { USelect } from './components/Select'; export { USelect } from './components/Select';
export type { USelectProps } from './components/Select'; export type { USelectProps } from './components/Select';
export { UCascader } from './components/Cascader';
export type { UCascaderProps } from './components/Cascader';
export { UForm, UFormItem } from './components/Form'; export { UForm, UFormItem } from './components/Form';
export { UTypography, UTitle, UText, UParagraph } from './components/Typography'; export { UTypography, UTitle, UText, UParagraph } from './components/Typography';
......
...@@ -24,6 +24,9 @@ export const P = { ...@@ -24,6 +24,9 @@ export const P = {
*/ */
SYSTEM_ROLE_VIEW: 'system:role:view', SYSTEM_ROLE_VIEW: 'system:role:view',
SYSTEM_ROLE_SAVE: 'system:role:save', SYSTEM_ROLE_SAVE: 'system:role:save',
/** 账号管理 */
SYSTEM_USER_VIEW: 'system:user:view',
SYSTEM_USER_SAVE: 'system:user:save',
// 复用片段 // 复用片段
VIEW: ':view', VIEW: ':view',
MANAGE: ':manage', MANAGE: ':manage',
......
...@@ -9,3 +9,4 @@ export * from './modules/store'; ...@@ -9,3 +9,4 @@ export * from './modules/store';
export * from './modules/role'; export * from './modules/role';
export * from './modules/org'; export * from './modules/org';
export * from './modules/system'; export * from './modules/system';
export * from './modules/user';
...@@ -3,8 +3,14 @@ ...@@ -3,8 +3,14 @@
import { ApiClient } from '../core/client'; import { ApiClient } from '../core/client';
export interface OrgNode { export interface OrgNode {
id: string; id: number;
name: string; parentId: number;
label: string;
permCode?: string;
nodeType: number;
product?: string;
sort: number;
status: number;
children?: OrgNode[]; children?: OrgNode[];
} }
......
...@@ -35,6 +35,10 @@ export interface RolePageResult { ...@@ -35,6 +35,10 @@ export interface RolePageResult {
size: number; size: number;
pages: number; pages: number;
} }
export interface RoleOption {
roleId: number;
roleName: string;
}
export interface PermissionMatrix { export interface PermissionMatrix {
roleId: string; roleId: string;
...@@ -45,6 +49,9 @@ export interface PermissionMatrix { ...@@ -45,6 +49,9 @@ export interface PermissionMatrix {
} }
class Role extends ApiClient { class Role extends ApiClient {
options() {
return this.get<RoleOption[]>('/system/role/options');
}
page(payload: RolePageParams) { page(payload: RolePageParams) {
return this.post<RolePageResult>('/system/role/page', payload as Record<string, unknown>); return this.post<RolePageResult>('/system/role/page', payload as Record<string, unknown>);
} }
......
import { ApiClient } from '../core/client';
export interface UserPageParams {
current?: number;
size?: number;
keyword?: string;
mobile?: string;
orgId?: number;
roleId?: number;
status?: number;
}
export interface UserPageItem {
userId: number;
account: string;
name: string;
mobile: string;
email?: string;
orgId?: number;
orgPath?: string;
dataScope?: number;
dataScopeLabel?: string;
status: number;
lastLoginAt?: string;
roleNames?: string[];
roleCodes?: string[];
remark?: string;
}
export interface UserPageResult {
records: UserPageItem[];
total: number;
current: number;
size: number;
pages: number;
}
class User extends ApiClient {
page(params: UserPageParams) {
return this.post<UserPageResult>('/system/user/page', params);
}
}
export const user = new User();
import { UButton, UDatePicker, UForm, UFormItem, UInput, URadio, USelect } from '@uj/ui'; import { UCascader, UButton, UDatePicker, UForm, UFormItem, UInput, URadio, USelect } from '@uj/ui';
import type { FieldSchema } from '../formSchema'; import type { FieldSchema } from '../formSchema';
export interface SearchPagination { export interface SearchPagination {
...@@ -43,9 +43,13 @@ export function SearchForm<T extends Record<string, unknown>>({ ...@@ -43,9 +43,13 @@ export function SearchForm<T extends Record<string, unknown>>({
mode={field.type === 'selectMultiple' ? 'multiple' : undefined} mode={field.type === 'selectMultiple' ? 'multiple' : undefined}
/> />
); );
if (field.type === 'cascader')
return <UCascader {...common} style={{ width }} options={field.options} />;
if (field.type === 'date') return <UDatePicker {...common} style={{ width }} />; if (field.type === 'date') return <UDatePicker {...common} style={{ width }} />;
if (field.type === 'dateRange') if (field.type === 'dateRange')
return <UDatePicker.RangePicker {...common} style={{ width }} />; return (
<UDatePicker.RangePicker disabled={common.disabled} size={common.size} style={{ width }} />
);
if (field.type === 'radio') return <URadio.Group {...common} options={field.options} />; if (field.type === 'radio') return <URadio.Group {...common} options={field.options} />;
return field.type === 'textarea' ? ( return field.type === 'textarea' ? (
<UInput.TextArea {...common} style={{ width }} /> <UInput.TextArea {...common} style={{ width }} />
......
import type { ReactNode } from 'react'; import type { ReactNode } from 'react';
export type FieldType = export type FieldType =
'input' | 'textarea' | 'select' | 'selectMultiple' | 'date' | 'dateRange' | 'radio' | 'switch'; | 'input'
| 'textarea'
| 'select'
| 'selectMultiple'
| 'cascader'
| 'date'
| 'dateRange'
| 'radio'
| 'switch';
export interface FieldOption { export interface FieldOption {
label: string; label: string;
value: string | number; value: string | number;
children?: FieldOption[];
} }
export interface FieldSchema<T extends Record<string, unknown> = Record<string, unknown>> { export interface FieldSchema<T extends Record<string, unknown> = Record<string, unknown>> {
name: keyof T & string; name: keyof T & string;
......
import PagePlaceholder from '@/components/PagePlaceholder'; import { useMemo, useState } from 'react';
import { Skeleton } from '@uj/ui'; import { useQuery } from '@tanstack/react-query';
import type { ColumnsType } from 'antd/es/table';
import { UCard, USwitch, UTag, UText, UTitle } from '@uj/ui';
import {
DataTable,
SearchForm,
type FieldSchema,
type RowActionSchema,
type SearchPagination,
} from '@/components';
import { P, PermButton } from '@/access';
import { org, role, user, type UserPageParams } from '@/api';
import { createAccountPageParams, toOrgCascaderOptions, withAllOption } from './tools/account';
const accountStatusOptions = [
{ label: '启用', value: 1 },
{ label: '停用', value: 0 },
];
interface AccountRow {
id: number;
account: string;
name: string;
mobile: string;
orgPath: string;
roleNames: string[];
dataScopeLabel: string;
status: number;
lastLoginAt: string;
}
function toParams(values: Record<string, unknown>, pagination: SearchPagination): UserPageParams {
return createAccountPageParams(values, pagination);
}
export default function AccountManage() { export default function AccountManage() {
const loading = false; const [params, setParams] = useState<UserPageParams>({ current: 1, size: 20 });
if (loading) return <Skeleton variant="default" />; const [queryVersion, setQueryVersion] = useState(0);
return <PagePlaceholder title="账号管理" description="账号开通、禁用与角色绑定(建设中)" />; const {
data: result,
isLoading,
isFetching,
} = useQuery({
queryKey: ['user-page', params, queryVersion],
queryFn: () => user.page(params),
});
const { data: roleOptions = [] } = useQuery({
queryKey: ['role-options'],
queryFn: () => role.options(),
});
const { data: orgTree = [] } = useQuery({ queryKey: ['org-tree'], queryFn: () => org.tree() });
const data = useMemo<AccountRow[]>(
() =>
result?.records.map((item) => ({
id: item.userId,
account: item.account,
name: item.name,
mobile: item.mobile,
orgPath: item.orgPath ?? '—',
roleNames: item.roleNames ?? [],
dataScopeLabel: item.dataScopeLabel ?? '—',
status: item.status,
lastLoginAt: item.lastLoginAt ?? '—',
})) ?? [],
[result],
);
const fields: FieldSchema<Record<string, unknown>>[] = [
{ name: 'keyword', label: '账号 / 姓名', type: 'input', placeholder: '模糊搜索' },
{ name: 'orgId', label: '所属组织', type: 'cascader', options: toOrgCascaderOptions(orgTree) },
{
name: 'roleId',
label: '角色',
type: 'select',
options: withAllOption(
roleOptions.map((item) => ({ label: item.roleName, value: item.roleId })),
),
},
{
name: 'status',
label: '状态',
type: 'select',
options: withAllOption(accountStatusOptions),
},
];
const columns: ColumnsType<AccountRow> = [
{
title: '账号',
dataIndex: 'account',
width: 140,
render: (value) => (
<UText style={{ color: '#315ce8', fontFamily: 'monospace' }}>{value}</UText>
),
},
{ title: '姓名', dataIndex: 'name', width: 110 },
{ title: '手机号', dataIndex: 'mobile', width: 140 },
{ title: '所属组织', dataIndex: 'orgPath', width: 260 },
{
title: '角色',
dataIndex: 'roleNames',
width: 220,
render: (names: string[]) =>
names.length
? names.map((name) => (
<UTag key={name} color="blue">
{name}
</UTag>
))
: '—',
},
{ title: '数据域', dataIndex: 'dataScopeLabel', width: 140 },
{
title: '状态',
width: 90,
render: (_, row) => <USwitch checked={row.status === 1} disabled />,
},
{ title: '最后登录', dataIndex: 'lastLoginAt', width: 170 },
];
const rowActions: RowActionSchema<AccountRow>[] = [
{ label: '编辑', permission: P.SYSTEM_USER_SAVE, onClick: () => undefined },
{ label: '重置密码', permission: P.SYSTEM_USER_SAVE, onClick: () => undefined },
{ label: '停用', permission: P.SYSTEM_USER_SAVE, danger: true, onClick: () => undefined },
];
return (
<div style={{ padding: 10, display: 'flex', flexDirection: 'column', gap: 16 }}>
<div style={{ display: 'flex', justifyContent: 'space-between' }}>
<div>
<UTitle level={3} style={{ margin: 0 }}>
账号管理
</UTitle>
<UText type="secondary">维护系统用户账号,分配角色与组织归属。</UText>
</div>
<PermButton permission={P.SYSTEM_USER_SAVE}>新增账号</PermButton>
</div>
<UCard size="small">
<SearchForm
fields={fields}
initialValues={{ roleId: '', status: '' }}
onSearch={(values, pagination) => {
setParams(toParams(values, pagination));
setQueryVersion((version) => version + 1);
}}
onReset={(values, pagination) => {
setParams(toParams(values, pagination));
setQueryVersion((version) => version + 1);
}}
/>
</UCard>
<UCard size="small" styles={{ body: { padding: 0 } }}>
<DataTable<AccountRow>
rowKey="id"
columns={columns}
rowActions={rowActions}
actionColumnWidth={220}
loading={isLoading || isFetching}
pageData={result ? { ...result, records: data } : undefined}
pagination={{
current: params.current ?? 1,
pageSize: params.size ?? 20,
total: result?.total ?? 0,
onChange: (current, size) => {
setParams((previous) => ({ ...previous, current, size }));
setQueryVersion((version) => version + 1);
},
}}
/>
</UCard>
</div>
);
} }
import type { OrgNode, UserPageParams } from '@/api';
import type { SearchPagination } from '@/components';
import type { FieldOption } from '@/components/formSchema';
export function toOrgCascaderOptions(nodes: OrgNode[]): FieldOption[] {
return nodes.map((node) => ({
value: node.id,
label: node.label,
children: node.children?.length ? toOrgCascaderOptions(node.children) : undefined,
}));
}
/** 为模块内的下拉选项统一补充“全部”。 */
export function withAllOption(options: FieldOption[]): FieldOption[] {
return [{ label: '全部', value: '' }, ...options];
}
export function createAccountPageParams(
values: Record<string, unknown>,
pagination: SearchPagination,
): UserPageParams {
const orgPath = values.orgId;
const orgId = Array.isArray(orgPath) ? orgPath.at(-1) : undefined;
return {
current: pagination.current,
size: pagination.size,
keyword: values.keyword as string | undefined,
mobile: values.mobile as string | undefined,
orgId: typeof orgId === 'number' ? orgId : undefined,
roleId: values.roleId === '' || values.roleId === undefined ? undefined : Number(values.roleId),
status: values.status === '' || values.status === undefined ? undefined : Number(values.status),
};
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!