feat(react-web-next): 新增.editorconfig和.prettierrc配置文件,添加public/.gitkeep占位文件

This commit is contained in:
2025-09-23 10:32:35 +08:00
parent 10ddfd6f75
commit 408b500b6a
199 changed files with 16850 additions and 34874 deletions
@@ -0,0 +1,59 @@
import React, { useEffect, useState } from 'react';
import { Modal, Tree, message } from 'antd';
import { roleApi } from '@/services/role';
import { buildTree } from '@/utils/tree';
type Key = string | number;
export interface AssignAuthProps {
roleId?: number;
tenantId?: string;
open: boolean;
onClose: () => void;
}
const AssignAuth: React.FC<AssignAuthProps> = ({ roleId, tenantId, open, onClose }) => {
const [treeData, setTreeData] = useState<any[]>([]);
const [checkedKeys, setCheckedKeys] = useState<Key[]>([]);
useEffect(() => {
(async () => {
if (open && roleId && tenantId) {
const menus = await roleApi.menuForAuth(roleId, tenantId);
const nodes = menus.map((m: any) => ({ id: m.id, pId: m.pId, title: m.name, name: m.name }));
setTreeData(buildTree(nodes));
setCheckedKeys(menus.filter((m: any) => m.checked).map((m: any) => m.id));
}
})();
}, [open, roleId, tenantId]);
const handleOk = async () => {
if (!roleId) return;
const hide = message.loading('淇濆瓨涓?..');
try {
await roleApi.assignMenu({ roleId, menuIds: checkedKeys });
message.success('鏉冮檺鍒嗛厤鎴愬姛');
onClose();
} catch (e) {
message.error('鏉冮檺鍒嗛厤澶辫触');
} finally {
hide();
}
};
return (
<Modal title="鏉冮檺鍒嗛厤" open={open} destroyOnClose onOk={handleOk} onCancel={onClose}>
<Tree
defaultExpandAll
checkable
treeData={treeData}
checkedKeys={checkedKeys}
onCheck={(keys: any) => setCheckedKeys(Array.isArray(keys) ? keys : keys.checked)}
/>
</Modal>
);
};
export default AssignAuth;
@@ -0,0 +1,38 @@
import React from 'react';
import { ModalForm, ProForm, ProFormRadio, ProFormText } from '@ant-design/pro-components';
import { RoleItem } from '@/services/role';
export interface RoleFormProps {
open: boolean;
title: string;
initialValues?: Partial<RoleItem>;
onOpenChange: (v: boolean) => void;
onFinish: (values: RoleItem) => Promise<boolean>;
}
const RoleForm: React.FC<RoleFormProps> = ({ open, title, initialValues, onOpenChange, onFinish }) => {
return (
<ModalForm<RoleItem>
title={title}
visible={open}
onVisibleChange={onOpenChange}
onFinish={onFinish}
initialValues={initialValues ?? { dataScope: 'ALL' }}
modalProps={{ destroyOnClose: true }}
width={500}
>
<ProForm.Group>
<ProFormText name="name" label="角色名称" rules={[{ required: true, message: '角色名不能为空' }]} width="lg" />
<ProFormText name="code" label="编码" rules={[{ required: true, message: '编码不能为空' }]} width="lg" />
<ProFormRadio.Group
name="dataScope"
label="数据权限"
width="lg"
options={[{ label: '全部', value: 'ALL' }, { label: '本人', value: 'CREATOR' }]}
/>
</ProForm.Group>
</ModalForm>
);
};
export default RoleForm;
@@ -0,0 +1,137 @@
import React, { useEffect, useState } from 'react';
import { PageContainer, ProTable, ProFormSelect, ProFormText } from '@ant-design/pro-components';
import { Popconfirm, Space, message } from 'antd';
import { ActionBar, GlassCard, GradientButton, SearchBarPlus } from '@/components/ui';
import { PlusOutlined } from '@ant-design/icons';
import { roleApi, RoleItem } from '@/services/role';
import RoleForm from './components/RoleForm';
import AssignAuth from './components/AssignAuth';
const RolePage: React.FC = () => {
const [apps, setApps] = useState<any[]>([]);
const [params, setParams] = useState<{ tenantId?: string; searchKey?: string; searchValue?: string }>({});
const [createOpen, setCreateOpen] = useState(false);
const [editOpen, setEditOpen] = useState(false);
const [assignOpen, setAssignOpen] = useState(false);
const [current, setCurrent] = useState<RoleItem | undefined>(undefined);
useEffect(() => {
(async () => {
const list = await roleApi.apps();
setApps(list || []);
if (list?.length) {
const tenantId = list[0].clientId;
setParams((p) => ({ ...p, tenantId }));
}
})();
}, []);
const columns = [
{ dataIndex: 'index', valueType: 'indexBorder', width: 48 },
{ title: 'ID', dataIndex: 'id' },
{ title: '角色名称', dataIndex: 'name' },
{ title: '编码', dataIndex: 'code' },
{ title: '数据权限', dataIndex: 'dataScope', renderText: (v: any) => (v === 'ALL' ? '全部' : '自定义') },
{
title: '操作', valueType: 'option', width: 220,
render: (_: any, record: RoleItem) => (
<Space>
<a onClick={() => { setCurrent(record); setEditOpen(true); }}>编辑</a>
<a onClick={() => { setCurrent(record); setAssignOpen(true); }}>授权</a>
<Popconfirm title={`确认删除角色[${record.name}]?`} onConfirm={async () => {
const hide = message.loading('删除中...');
try {
await roleApi.delete(record.id!);
message.success('删除成功');
} catch (e) {
message.error('删除失败');
} finally { hide(); }
}}>
<a>删除</a>
</Popconfirm>
</Space>
)
}
];
return (
<PageContainer header={{ title: '角色管理' }}>
<SearchBarPlus
defaultCollapsed={false}
split
span={6}
onTenantChanged={() => { /* 切换租户后服务端上下文生效 */ }}
onFinish={async (values) => setParams(values)}
>
<ProFormSelect name="tenantId" label="所属应用" allowClear={false} options={(apps || []).map((i) => ({ label: i.clientId, value: i.clientId }))} />
<ProFormSelect name="searchKey" label="搜索" valueEnum={{ name: '角色名称' }} />
<ProFormText name="searchValue" placeholder="请输入关键字" />
</SearchBarPlus>
<ActionBar
left={
<GradientButton size="middle" key="add" type="primary" onClick={() => setCreateOpen(true)}>
<PlusOutlined /> 新增
</GradientButton>
}
/>
<GlassCard>
<ProTable<RoleItem>
rowKey="id"
headerTitle="角色列表"
request={async (p) => roleApi.page({ ...p, ...params })}
columns={columns as any}
search={false}
pagination={{ showSizeChanger: true, showQuickJumper: true }}
toolBarRender={false}
/>
</GlassCard>
<RoleForm
title="新增角色"
open={createOpen}
onOpenChange={setCreateOpen}
onFinish={async (values) => {
const hide = message.loading('保存中...');
try {
await roleApi.saveOrUpdate(values);
message.success('新增成功');
return true;
} catch (e) {
message.error('保存失败');
return false;
} finally { hide(); }
}}
/>
<RoleForm
title="修改角色"
open={editOpen}
initialValues={current}
onOpenChange={setEditOpen}
onFinish={async (values) => {
const hide = message.loading('保存中...');
try {
await roleApi.saveOrUpdate({ ...current, ...values });
message.success('修改成功');
return true;
} catch (e) {
message.error('修改失败');
return false;
} finally { hide(); }
}}
/>
<AssignAuth
open={assignOpen}
roleId={current?.id}
tenantId={params.tenantId}
onClose={() => setAssignOpen(false)}
/>
</PageContainer>
);
};
export default RolePage;