|
@@ -1,7 +1,7 @@
|
|
|
/*
|
|
/*
|
|
|
* @Author: your name
|
|
* @Author: your name
|
|
|
* @Date: 2022-01-13 15:22:48
|
|
* @Date: 2022-01-13 15:22:48
|
|
|
- * @LastEditTime: 2025-02-21 17:50:31
|
|
|
|
|
|
|
+ * @LastEditTime: 2025-05-21 17:50:49
|
|
|
* @LastEditors: code4eat awesomedema@gmail.com
|
|
* @LastEditors: code4eat awesomedema@gmail.com
|
|
|
* @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
|
* @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
|
|
* @FilePath: /KC-MiddlePlatform/src/pages/platform/setting/hospManage/index.tsx
|
|
* @FilePath: /KC-MiddlePlatform/src/pages/platform/setting/hospManage/index.tsx
|
|
@@ -131,14 +131,17 @@ const DrawerActBtn = ({ record }: { record: any }) => {
|
|
|
key: 'deptName',
|
|
key: 'deptName',
|
|
|
render: (_: any, record: any) => {
|
|
render: (_: any, record: any) => {
|
|
|
if (record.functionList) {
|
|
if (record.functionList) {
|
|
|
- const options = record.functionList.map((item: any, index: number) => ({ label: item.name, value: item.code }));
|
|
|
|
|
|
|
+ const options = record.functionList.map((item: any, index: number) => ({
|
|
|
|
|
+ label: item.name,
|
|
|
|
|
+ value: item.code
|
|
|
|
|
+ }));
|
|
|
|
|
|
|
|
const needItem = checkBoxCodes.filter((a) => a.menuId == record.menuId);
|
|
const needItem = checkBoxCodes.filter((a) => a.menuId == record.menuId);
|
|
|
-
|
|
|
|
|
const codes = needItem && needItem.length > 0 ? needItem[0].function.map((a: any) => a.code) : [];
|
|
const codes = needItem && needItem.length > 0 ? needItem[0].function.map((a: any) => a.code) : [];
|
|
|
|
|
|
|
|
const onCheckGroupChange = (checkedValue: CheckboxValueType[]) => {
|
|
const onCheckGroupChange = (checkedValue: CheckboxValueType[]) => {
|
|
|
if (checkedValue.length > 0) {
|
|
if (checkedValue.length > 0) {
|
|
|
|
|
+ // 1. 处理功能权限数据
|
|
|
const _temp = [...checkBoxCodes];
|
|
const _temp = [...checkBoxCodes];
|
|
|
const index = checkBoxCodes.findIndex((item) => item.menuId == record.menuId);
|
|
const index = checkBoxCodes.findIndex((item) => item.menuId == record.menuId);
|
|
|
|
|
|
|
@@ -146,7 +149,6 @@ const DrawerActBtn = ({ record }: { record: any }) => {
|
|
|
const transfered = needed.map((item: any) => ({ name: item.label, code: item.value }));
|
|
const transfered = needed.map((item: any) => ({ name: item.label, code: item.value }));
|
|
|
|
|
|
|
|
if (index >= 0) {
|
|
if (index >= 0) {
|
|
|
- //先去除旧的的对象
|
|
|
|
|
_temp.splice(index, 1);
|
|
_temp.splice(index, 1);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -155,19 +157,30 @@ const DrawerActBtn = ({ record }: { record: any }) => {
|
|
|
function: transfered,
|
|
function: transfered,
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- set_checkedMenuParentsIds([...checkedMenuParentsIds, record.menuId]);
|
|
|
|
|
|
|
+ // 2. 获取并添加父级菜单ID
|
|
|
|
|
+ const parents = findParents(hospAllMenuTree, record.menuId);
|
|
|
|
|
+ const parentsIds = parents ? parents.map((a) => a.menuId) : [];
|
|
|
|
|
|
|
|
|
|
+ // 3. 更新所有相关状态
|
|
|
|
|
+ set_checkedMenuParentsIds([...checkedMenuParentsIds, record.menuId, ...parentsIds]);
|
|
|
set_checkedTableMenuIds([...checkedTableMenuIds, record.menuId]);
|
|
set_checkedTableMenuIds([...checkedTableMenuIds, record.menuId]);
|
|
|
-
|
|
|
|
|
set_checkBoxCodes([..._temp]);
|
|
set_checkBoxCodes([..._temp]);
|
|
|
} else {
|
|
} else {
|
|
|
- //取消选择
|
|
|
|
|
|
|
+ // 取消选择时的处理
|
|
|
const _temp = checkBoxCodes;
|
|
const _temp = checkBoxCodes;
|
|
|
const index = checkBoxCodes.findIndex((item) => item.menuId == record.menuId);
|
|
const index = checkBoxCodes.findIndex((item) => item.menuId == record.menuId);
|
|
|
-
|
|
|
|
|
- _temp.splice(index, 1);
|
|
|
|
|
-
|
|
|
|
|
- set_checkBoxCodes([..._temp]);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if (index >= 0) {
|
|
|
|
|
+ _temp.splice(index, 1);
|
|
|
|
|
+ set_checkBoxCodes([..._temp]);
|
|
|
|
|
+
|
|
|
|
|
+ // 检查是否还有其他功能被选中
|
|
|
|
|
+ const hasOtherFunctions = _temp.some(item => item.menuId === record.menuId);
|
|
|
|
|
+ if (!hasOtherFunctions) {
|
|
|
|
|
+ // 如果没有其他功能被选中,从选中列表中移除
|
|
|
|
|
+ set_checkedTableMenuIds(checkedTableMenuIds.filter(id => id !== record.menuId));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -355,39 +368,90 @@ const DrawerActBtn = ({ record }: { record: any }) => {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const saveResult = async () => {
|
|
const saveResult = async () => {
|
|
|
- let old = [...oldSelectedMenuIds];
|
|
|
|
|
- //const needCancelMenus = needCancelCheckedMenus.map(a=>({hospId: record.id ,systemId: currentSelectedTreeNode.code,function:[],menuId:a}));
|
|
|
|
|
- const result = checkBoxCodes.map((item: any) => {
|
|
|
|
|
- old.splice(
|
|
|
|
|
- old.findIndex((a) => a == item.menuId),
|
|
|
|
|
- 1,
|
|
|
|
|
- );
|
|
|
|
|
- return { ...item, hospId: record.hospId, roleId: record.roleId, systemId: currentSelectedTreeNode.code };
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 1. 收集所有需要保存的菜单ID
|
|
|
|
|
+ const allMenuIds = new Set<string>();
|
|
|
|
|
|
|
|
- const needCancelMenus = old.map((a) => ({
|
|
|
|
|
- hospId: record.hospId,
|
|
|
|
|
- systemId: currentSelectedTreeNode.code,
|
|
|
|
|
- menuId: a,
|
|
|
|
|
- roleId: record.roleId,
|
|
|
|
|
- function: [],
|
|
|
|
|
- }));
|
|
|
|
|
|
|
+ // 2. 添加当前选中的菜单ID(类型转换为string)
|
|
|
|
|
+ checkedMenuParentsIds.forEach(id => allMenuIds.add(String(id)));
|
|
|
|
|
|
|
|
- const data = {
|
|
|
|
|
- hospId: record.hospId,
|
|
|
|
|
- roleId: record.roleId,
|
|
|
|
|
- systemId: currentSelectedTreeNode.code,
|
|
|
|
|
- menuIds: ifTixiMenu ? (ifTixiMenuAuth ? [currentSelectedTreeNode.code] : []) : [...new Set(checkedMenuParentsIds), currentSelectedTreeNode.code],
|
|
|
|
|
- functionList: [...result, ...needCancelMenus],
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ // 3. 添加系统ID
|
|
|
|
|
+ if (currentSelectedTreeNode?.code) {
|
|
|
|
|
+ allMenuIds.add(String(currentSelectedTreeNode.code));
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- const resp = await saveRoleRelaApiPerm(data);
|
|
|
|
|
- if (resp) {
|
|
|
|
|
- set_drawerTablereload(true);
|
|
|
|
|
- set_checkBoxCodes([]);
|
|
|
|
|
- set_checkedTableMenuIds([]);
|
|
|
|
|
- setInitCheckData();
|
|
|
|
|
|
|
+ // 4. 确保父级ID存在
|
|
|
|
|
+ const finalMenuIds = Array.from(allMenuIds).filter(id => {
|
|
|
|
|
+ const parents = findParents(hospAllMenuTree, id);
|
|
|
|
|
+ if (parents) {
|
|
|
|
|
+ return parents.every(parent => allMenuIds.has(String(parent.menuId)));
|
|
|
|
|
+ }
|
|
|
|
|
+ return true;
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // 5. 生成 result 和 needCancelMenus
|
|
|
|
|
+ let old = [...oldSelectedMenuIds];
|
|
|
|
|
+ const result = checkBoxCodes.map((item: any) => {
|
|
|
|
|
+ const index = old.findIndex((a) => a == item.menuId);
|
|
|
|
|
+ if (index !== -1) {
|
|
|
|
|
+ old.splice(index, 1);
|
|
|
|
|
+ }
|
|
|
|
|
+ return { ...item, hospId: record.hospId, roleId: record.roleId, systemId: currentSelectedTreeNode.code };
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ const needCancelMenus = old.map((a) => ({
|
|
|
|
|
+ hospId: record.hospId,
|
|
|
|
|
+ systemId: currentSelectedTreeNode.code,
|
|
|
|
|
+ menuId: a,
|
|
|
|
|
+ roleId: record.roleId,
|
|
|
|
|
+ function: [],
|
|
|
|
|
+ }));
|
|
|
|
|
+
|
|
|
|
|
+ const data = {
|
|
|
|
|
+ hospId: record.hospId,
|
|
|
|
|
+ roleId: record.roleId,
|
|
|
|
|
+ systemId: currentSelectedTreeNode.code,
|
|
|
|
|
+ menuIds: ifTixiMenu
|
|
|
|
|
+ ? (ifTixiMenuAuth ? [currentSelectedTreeNode.code] : [])
|
|
|
|
|
+ : finalMenuIds,
|
|
|
|
|
+ functionList: [...result, ...needCancelMenus],
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ // 6. 数据验证
|
|
|
|
|
+ if (!validateMenuIds(data.menuIds, hospAllMenuTree)) {
|
|
|
|
|
+ console.warn('菜单ID数据不完整,请检查');
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const resp = await saveRoleRelaApiPerm(data);
|
|
|
|
|
+ if (resp) {
|
|
|
|
|
+ set_drawerTablereload(true);
|
|
|
|
|
+ set_checkBoxCodes([]);
|
|
|
|
|
+ set_checkedTableMenuIds([]);
|
|
|
|
|
+ await setInitCheckData();
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.error('保存角色权限失败:', error);
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ // 添加数据验证函数
|
|
|
|
|
+ const validateMenuIds = (menuIds: string[], tree: any[]) => {
|
|
|
|
|
+ // 检查是否所有父级ID都存在
|
|
|
|
|
+ const missingParents = menuIds.filter(id => {
|
|
|
|
|
+ const parents = findParents(tree, id);
|
|
|
|
|
+ if (parents) {
|
|
|
|
|
+ return parents.some(parent => !menuIds.includes(parent.menuId));
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ if (missingParents.length > 0) {
|
|
|
|
|
+ console.warn('发现缺失的父级菜单ID:', missingParents);
|
|
|
|
|
+ return false;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ return true;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const onCancel = () => {
|
|
const onCancel = () => {
|
|
@@ -699,8 +763,13 @@ const DrawerActBtn = ({ record }: { record: any }) => {
|
|
|
const RoleManage: FC<PageProps> = ({ roleManageModel: state, dispatch }) => {
|
|
const RoleManage: FC<PageProps> = ({ roleManageModel: state, dispatch }) => {
|
|
|
const { reloadTable } = state;
|
|
const { reloadTable } = state;
|
|
|
const { initialState, setInitialState } = useModel('@@initialState');
|
|
const { initialState, setInitialState } = useModel('@@initialState');
|
|
|
- const [tableDataFilterParams, set_tableDataFilterParams] = useState<any | undefined>();
|
|
|
|
|
|
|
+ const [tableDataFilterParams, set_tableDataFilterParams] = useState<TableRequestParamsType>({
|
|
|
|
|
+ current: 1,
|
|
|
|
|
+ pageSize: 10,
|
|
|
|
|
+ roleName: '',
|
|
|
|
|
+ });
|
|
|
const [tableDataSearchKeywords, set_tableDataSearchKeywords] = useState<string>('');
|
|
const [tableDataSearchKeywords, set_tableDataSearchKeywords] = useState<string>('');
|
|
|
|
|
+ const [reload, set_reload] = useState(false);
|
|
|
|
|
|
|
|
const columns: ProColumns<TableListItem>[] = [
|
|
const columns: ProColumns<TableListItem>[] = [
|
|
|
{
|
|
{
|
|
@@ -886,9 +955,17 @@ const RoleManage: FC<PageProps> = ({ roleManageModel: state, dispatch }) => {
|
|
|
set_tableDataFilterParams({
|
|
set_tableDataFilterParams({
|
|
|
...tableDataFilterParams,
|
|
...tableDataFilterParams,
|
|
|
current: 1,
|
|
current: 1,
|
|
|
- [`${paramName}`]: tableDataSearchKeywords,
|
|
|
|
|
|
|
+ [`${paramName}`]: tableDataSearchKeywords
|
|
|
});
|
|
});
|
|
|
- };
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const handleTableChange = (pagination: any) => {
|
|
|
|
|
+ set_tableDataFilterParams({
|
|
|
|
|
+ ...tableDataFilterParams,
|
|
|
|
|
+ current: pagination.current,
|
|
|
|
|
+ pageSize: pagination.pageSize
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
const editUserBind = async (record: TableListItem) => {
|
|
const editUserBind = async (record: TableListItem) => {
|
|
|
//编辑角色与人员的绑定关系
|
|
//编辑角色与人员的绑定关系
|
|
@@ -949,7 +1026,7 @@ const RoleManage: FC<PageProps> = ({ roleManageModel: state, dispatch }) => {
|
|
|
set_tableDataFilterParams({
|
|
set_tableDataFilterParams({
|
|
|
...tableDataFilterParams,
|
|
...tableDataFilterParams,
|
|
|
current: 1,
|
|
current: 1,
|
|
|
- roleName: '',
|
|
|
|
|
|
|
+ roleName: ''
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
}}
|
|
}}
|
|
@@ -964,16 +1041,18 @@ const RoleManage: FC<PageProps> = ({ roleManageModel: state, dispatch }) => {
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
- <KCTable
|
|
|
|
|
- rowKey="roleId"
|
|
|
|
|
- columns={columns}
|
|
|
|
|
- options={false}
|
|
|
|
|
- newVer
|
|
|
|
|
- params={tableDataFilterParams}
|
|
|
|
|
- reload={reloadTable}
|
|
|
|
|
- scroll={{ y: `calc(100vh - 255px)` }}
|
|
|
|
|
- request={(params) => getData(params)}
|
|
|
|
|
- />
|
|
|
|
|
|
|
+ <div style={{ marginTop: 16 }}>
|
|
|
|
|
+ <KCTable
|
|
|
|
|
+ columns={columns}
|
|
|
|
|
+ scroll={{ y: `calc(100vh - 250px)` }}
|
|
|
|
|
+ reload={reload}
|
|
|
|
|
+ rowKey="id"
|
|
|
|
|
+ newVer
|
|
|
|
|
+ params={tableDataFilterParams}
|
|
|
|
|
+ request={(params) => getData(params)}
|
|
|
|
|
+ onChange={handleTableChange}
|
|
|
|
|
+ />
|
|
|
|
|
+ </div>
|
|
|
</div>
|
|
</div>
|
|
|
);
|
|
);
|
|
|
};
|
|
};
|