Skip to content

Commit

Permalink
Feature bailongsen (#654)
Browse files Browse the repository at this point in the history
* fix: 自定义菜单渲染

* fix: 调整布局

* fix: 调试分配权限接口

* fix: 调试角色分配用户

* feat: The role assigned to a user is added

* feat:Added a resource configuration role

* [Bug][scaleph-security] fix web resource child routes error (#637)

fix: child routes error

* [Bug][docker] fix scaleph-seatunnel image error (#638)

* feature: add doris operator

* feature: add web-resource and role relation table

* feature: add web-resource and role relation mapper

* feature: add web-resource and role relation mapper

* fix: seatunnel base image

* [Bug][docker] fix scaleph-seatunnel image error (#639)

fix: seatunnel base image

* [Bug][docker] fix scaleph-seatunnel image error (#640)

fix: seatunnel base image

* [Bug][docker] fix scaleph-seatunnel image error (#641)

fix: seatunnel base image

* [Bug][docker] fix scaleph-seatunnel image error (#642)

* fix: seatunnel base image

* fix: seatunnel base image

* [Feature][scaleph-security] add security web resource and role relation api (#644)

* fix: seatunnel base image

* feature: add resource-web and role relation api

* [Feature][scaleph-security] add user and role relation api (#645)

* feature: add user and role relation api

* feature: add user and role relation api

* [Feature][scaleph-engine-doris] add selectdb doris-operator crd (#646)

* feature: doris operator crd definition

* fix: resource-web and role relation error

* [Bug][scaleph-security] fix umi route icon error (#647)

* fix: resource-web and role relation error

* fix: route icon error

* [Feature][scaleph-ui-react] add doris template web under project (#648)

* feature: add doris template mapper

* feature: add doris template service

* feature: add doris template service

* feature: add doris template web route

* feature: add doris template web

* [Feature][scaleph-engine-doris] add doris template steps form (#649)

* feature: upgrade flink kubernetes operator to 1.7.0

* feature: add doris template detail web

* feature: add doris template detail web

* feature: add doris template steps

* feature: add doris template steps

* feature: add doris template steps route

* feature: add doris template component step

* fix: knife4j error

* fix: knife4j error

* fix: knife4j error

* fix: knife4j error

* [Feature][scaleph-engine-doris] add doris template detail web (#650)

* fix: doris template step form item error

* feature: add doris template yaml step

* feature: add doris template yaml step

* feature: add createStatus for doris template

* feature: add yaml step for doris template steps

* feature: add yaml step for doris template steps

* feature: add yaml step for doris template steps

* feature: remove doris template createStatus field

* feature: refactor doris template step model

* feature: add yaml area for doris template detail web

* feature: add yaml area for doris template detail web

* [Feature][scaleph-engine-doris] add doris instance service (#651)

* feature: add doris instance service

* feature: add doris instance controller

* feature: add doris instance controller

* feature: add doris instance web

* feature: add doris instance steps

* feature: add doris instance steps

* feature: add doris instance steps

* fix: system nav bar error

* [Feature][scaleph-engine-doris] add doris instance steps form web (#652)

* fix: user resource

* fix: user resource

* feature: add doris instance steps form

* [Feature][scaleph-engine-doris] add doris instance detail web  (#653)

* feature: add doris instance detail web

* feature: add doris instance detail web

* feature: add doris instance detail web

* [Release] release 2.0.0-SNAPSHOT

---------

Co-authored-by: bailongsen <[email protected]>
Co-authored-by: kalencaya <[email protected]>
  • Loading branch information
3 people authored Dec 5, 2023
1 parent 6690fff commit 37601ab
Show file tree
Hide file tree
Showing 12 changed files with 1,121 additions and 127 deletions.
10 changes: 10 additions & 0 deletions scaleph-ui-react/src/locales/zh-CN/pages/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ export default {
'app.common.operate.label': '操作',
'app.common.operate.success': '操作成功',
'app.common.operate.new.label': '新增',
'app.common.operate.new.roles': '分配角色',
'app.common.operate.new.rolesUser': '角色分配用户',
'app.common.operate.new.rolesWeb': '角色配置web资源',
'app.common.operate.new.user': '配置用户',
'app.common.operate.new.webs': '配置web资源',
'app.common.operate.new.accreditUser': '已授权用户',
'app.common.operate.new.accreditRoles': '已授权角色',
'app.common.operate.new.notAccreditUser': '未授权用户',
'app.common.operate.new.notAccreditRoles': '未授权角色',
'app.common.operate.new.assets': '权限配置',
'app.common.operate.new.success': '新增成功',
'app.common.operate.new.failure': '新增失败',
'app.common.operate.new.directive': '没有?去创建',
Expand Down
26 changes: 26 additions & 0 deletions scaleph-ui-react/src/models/useMainSize.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { useLayoutEffect, useState } from "react";
import { throttle } from "lodash";

export default (mainCl = ".ant-pro-basicLayout-content") => {
const [container, setContainer] = useState<{ height: number; width: number }>({
width: 100,
height: 100
});
// const mainCl = '.ant-pro-basicLayout-content';
useLayoutEffect(() => {
const handler = throttle(() => {
const rt = document.querySelector(mainCl)?.getBoundingClientRect();
setContainer({
height: rt?.height,
width: rt?.width
});
}, 100);
handler();
window.addEventListener("resize", handler, false);
return () => {
window.removeEventListener("resize", handler, false);
};
}, []);

return container;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Table, Transfer } from 'antd';
import { difference } from 'lodash'; // 注意这里改为大写的Difference
import React from 'react';

// 定义组件的Props类型
interface Props {
leftColumns: any[]; // 左侧表格列配置数组
rightColumns: any[]; // 右侧表格列配置数组
containerHeight: number; // 容器高度
}

// 使用React.FC声明函数组件,并传入Props类型
const TableTransfer: React.FC<Props> = ({ leftColumns, rightColumns, ...restProps }) => (
<Transfer {...restProps}>
{({
direction,
filteredItems,
onItemSelectAll,
onItemSelect,
selectedKeys: listSelectedKeys,
disabled: listDisabled,
}) => {
const columns = direction === 'left' ? leftColumns : rightColumns;
// 表格行选择配置
const rowSelection = {
onSelectAll(selected: boolean, selectedRows: any[]) {
const treeSelectedKeys = selectedRows.map(({ key }) => key);
const diffKeys = selected
? difference(treeSelectedKeys, listSelectedKeys)
: difference(listSelectedKeys, treeSelectedKeys);
onItemSelectAll(diffKeys, selected);
},
onSelect: ({ id }: { id: string }, selected: boolean) => {
onItemSelect(id, selected);
},
selectedRowKeys: listSelectedKeys,
};

return (
<Table
scroll={{ y: restProps.containerHeight - 380 }}
rowSelection={rowSelection}
columns={columns}
dataSource={filteredItems}
size="small"
rowKey="id"
pagination={{
defaultPageSize: 20,
}}
style={{ pointerEvents: listDisabled ? 'none' : null }}
/>
);
}}
</Transfer>
);
export default React.memo(TableTransfer);
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
import mainHeight from '@/models/useMainSize';
import { SecResourceWeb } from '@/services/admin/typings';
import { AuthService } from '@/services/auth';
import { Button, Card, Form, message, Modal, Space } from 'antd';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { useIntl } from 'umi';
import TableTransfer from './TransferTable';

// 定义组件 Props 类型
interface ModalFormParentProps<T> {
data: T;
visible: boolean;
onVisibleChange?: (visible: boolean) => void;
onCancel: () => void;
onOK?: (values: any) => void;
}

const WebResourceForm: React.FC<ModalFormParentProps<SecResourceWeb>> = ({
data,
visible,
onVisibleChange,
onCancel,
}) => {
const intl = useIntl();
const [form] = Form.useForm();
const containerInfo = mainHeight('.ant-layout-content');
const [roleLists, setRoleLists] = useState<Role[]>([]);

// 角色表格列配置
const tableColumns = [
{
dataIndex: 'name',
title: '角色名称',
width: 300,
},
{
dataIndex: 'desc',
title: '描述',
width: 300,
},
];

// 角色类型定义
interface Role {
id: string;
name: string;
resourceAuthorized: number;
checkOut?: number;
}

// 合并数组
function mergeArrays(array1: Role[], array2: Role[]): Role[] {
array1.forEach((obj, index) => {
obj.checkOut = 0;
});
array2.forEach((obj, index) => {
obj.checkOut = 1;
});
return [...array1, ...array2];
}

// 异步获取数据
const fetchData = useCallback(async () => {
try {
const res1 = await AuthService.unauthorizedRoles({ resourceWebId: data?.id });
const res2 = await AuthService.authorizedRoles({ resourceWebId: data?.id });
if (res1?.records && res2?.records) {
const mergedArray = mergeArrays(res1.records, res2.records);
setRoleLists(mergedArray);
}
} catch (error) {
console.error(error);
}
}, [data]);

useEffect(() => {
if (data) {
fetchData();
}
}, [data, fetchData]);

// 页面标题
const returnTitle = useMemo(() => {
return (
<Space direction="vertical">
<span>{` ${intl.formatMessage({ id: `menu.${data?.name}` })}-资源分配详情`}</span>
</Space>
);
}, [data, intl]);

// 获取选中角色的 id 数组
const originTargetKeys = useMemo(() => {
return roleLists?.filter((item) => item.checkOut === 1).map((item) => item.id);
}, [roleLists]);

// 过滤方法
const handleFilter = useCallback((inputValue, item) => {
return item?.name.indexOf(inputValue) !== -1;
}, []);

// 角色转移事件处理
const handleChange = useCallback(
async (targetKeys, direction, moveKeys) => {
const roleIds = moveKeys.map((item: string | number) => +item);
const params = {
resourceWebId: data?.id,
roleIds: roleIds,
};
if (direction === 'right') {
// 绑定角色资源
await AuthService.resourceWebRoles(params).then((res) => {
if (res?.success) {
message.success(intl.formatMessage({ id: 'app.common.operate.edit.success' }), 2);
}
});
} else {
// 删除绑定的角色资源
await AuthService.resourceWebRolesDelete(params).then((res) => {
message.success(intl.formatMessage({ id: 'app.common.operate.edit.success' }), 2);
});
}
fetchData();
},
[data, fetchData, intl],
);

return (
<Modal
open={visible}
title={data.id ? intl.formatMessage({ id: 'app.common.operate.new.roles' }) : ''}
width={1100}
destroyOnClose={true}
onCancel={onCancel}
cancelText={intl.formatMessage({ id: 'app.common.operate.close.label' })}
centered
footer={[
<Button type="primary" onClick={onCancel}>
{intl.formatMessage({ id: 'app.common.operate.close.label' })}
</Button>,
]}
>
<div>
<Card
bodyStyle={{
minHeight: `${containerInfo.height - 200}px`,
}}
title={returnTitle}
>
<TableTransfer
containerHeight={containerInfo.height}
titles={[intl.formatMessage({ id: 'app.common.operate.new.notAccreditRoles' }), intl.formatMessage({ id: 'app.common.operate.new.accreditRoles' })]}
dataSource={roleLists}
targetKeys={originTargetKeys}
showSearch={true}
rowKey={(record: { id: any }) => record.id}
onChange={handleChange}
filterOption={handleFilter}
listStyle={{
width: 500,
}}
leftColumns={tableColumns}
rightColumns={tableColumns}
/>
</Card>
</div>
</Modal>
);
};

export default WebResourceForm;
34 changes: 32 additions & 2 deletions scaleph-ui-react/src/pages/Admin/Resource/Web/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { PRIVILEGE_CODE } from '@/constant';
import WebAssugnRoles from '@/pages/Admin/Resource/Web/components/WebAssugnRoles';
import WebResourceForm from '@/pages/Admin/Resource/Web/components/WebResourceForm';
import { PrivilegeService } from '@/services/admin/privilege.service';
import { ResourceWebService } from '@/services/admin/resourceWeb.service';
import { SecResourceWeb } from '@/services/admin/typings';
import { DeleteOutlined, EditOutlined, PlusOutlined } from '@ant-design/icons';
import { DeleteOutlined, EditOutlined, FormOutlined, PlusOutlined } from '@ant-design/icons';
import { ActionType, ProColumns, ProFormInstance, ProTable } from '@ant-design/pro-components';
import { Button, message, Modal, Space, Tag, Tooltip } from 'antd';
import { isEmpty } from 'lodash';
Expand All @@ -21,6 +22,10 @@ const WebResourceWeb: React.FC = () => {
parent: SecResourceWeb;
data: SecResourceWeb;
}>({ visiable: false, parent: {}, data: {} });
const [webAssignRoles, setWebAssignRoles] = useState<{
visiable: boolean;
data: SecResourceWeb;
}>({ visiable: false, parent: {}, data: {} });

const onExpand = (expanded: boolean, record: SecResourceWeb) => {
if (expanded && record.children && isEmpty(record.children)) {
Expand All @@ -44,6 +49,9 @@ const WebResourceWeb: React.FC = () => {
{
title: intl.formatMessage({ id: 'pages.admin.resource.web.name' }),
dataIndex: 'name',
// render: (dom, entity) => {
// return intl.formatMessage({ id: `menu.${entity?.name}` });
// },
},
{
title: intl.formatMessage({ id: 'pages.admin.resource.web.path' }),
Expand Down Expand Up @@ -91,12 +99,22 @@ const WebResourceWeb: React.FC = () => {
title: intl.formatMessage({ id: 'app.common.operate.label' }),
dataIndex: 'actions',
align: 'center',
width: 120,
width: 160,
fixed: 'right',
valueType: 'option',
render: (_, record) => (
<>
<Space>
{access.canAccess(PRIVILEGE_CODE.datadevProjectEdit) && (
<Tooltip title={intl.formatMessage({ id: 'app.common.operate.new.roles' })}>
<Button
shape="default"
type="link"
icon={<FormOutlined />}
onClick={() => setWebAssignRoles({ visiable: true, data: record })}
/>
</Tooltip>
)}
{access.canAccess(PRIVILEGE_CODE.datadevProjectEdit) && (
<Tooltip title={intl.formatMessage({ id: 'app.common.operate.new.label' })}>
<Button
Expand Down Expand Up @@ -236,6 +254,18 @@ const WebResourceWeb: React.FC = () => {
data={webResourceFormData.data}
/>
)}

{webAssignRoles.visiable && (
<WebAssugnRoles
visible={webAssignRoles.visiable}
onCancel={() => setWebAssignRoles({ visiable: false, data: {} })}
onVisibleChange={(visiable) => {
setWebAssignRoles({ visiable: visiable, data: {} });
actionRef.current?.reload();
}}
data={webAssignRoles.data}
/>
)}
</div>
);
};
Expand Down
Loading

0 comments on commit 37601ab

Please sign in to comment.