#
luxiaotao1123
2024-02-24 d86db78f18c03d97b7b856fd37cd10d6297eecc7
zy-asrs-flow/src/pages/system/role/index.jsx
@@ -1,7 +1,6 @@
import React, { useState, useRef, useEffect } from 'react';
import { useIntl, FormattedMessage } from '@umijs/max';
import { Button, message, Modal } from 'antd';
import { Button, message, Modal, Tag } from 'antd';
import {
    FooterToolbar,
    PageContainer,
@@ -11,13 +10,17 @@
import { PlusOutlined, ExportOutlined } from '@ant-design/icons';
import Http from '@/utils/http';
import Edit from './components/edit'
import { TextFilter, SelectFilter } from '@/components/TableSearch'
import Scope from './components/scope'
import { TextFilter, SelectFilter, DatetimeRangeFilter, LinkFilter } from '@/components/TableSearch'
import { statusMap } from '@/utils/enum-util'
import { repairBug } from '@/utils/common-util';
const TABLE_KEY = "pro-table-role";
const handleSave = async (val) => {
    const hide = message.loading('正在添加');
    try {
        const resp = await Http.doPost('api/role/save', val);
        hide();
        if (resp.code === 200) {
            message.success('添加成功');
            return true;
@@ -26,9 +29,10 @@
            return false;
        }
    } catch (error) {
        hide();
        message.error('添加失败请重试!');
        return false;
    } finally {
        hide();
    }
};
@@ -36,7 +40,6 @@
    const hide = message.loading('正在更新');
    try {
        const resp = await Http.doPost('api/role/update', val);
        hide();
        if (resp.code === 200) {
            message.success('更新成功');
            return true;
@@ -45,9 +48,10 @@
            return false;
        }
    } catch (error) {
        hide();
        message.error('配置失败请重试!');
        return false;
    } finally {
        hide();
    }
};
@@ -56,7 +60,6 @@
    const hide = message.loading('正在删除');
    try {
        const resp = await Http.doPost('api/role/remove/' + rows.map((row) => row.id).join(','));
        hide();
        if (resp.code === 200) {
            message.success('删除成功');
            return true;
@@ -65,26 +68,47 @@
            return false;
        }
    } catch (error) {
        hide();
        message.error('删除失败,请重试');
        return false;
    } finally {
        hide();
    }
};
const handleExport = async () => {
    const hide = message.loading('正在导出');
    try {
        await Http.doPost('api/role/export');
        hide();
        const resp = await Http.doPostBlob('api/role/export');
        const blob = new Blob([resp], { type: 'application/vnd.ms-excel' });
        window.location.href = window.URL.createObjectURL(blob);
        message.success('导出成功');
        return true;
    } catch (error) {
        hide();
        message.error('导出失败,请重试');
        return false;
    } finally {
        hide();
    }
};
const handleScope = async (val) => {
    const hide = message.loading('正在分配');
    try {
        const resp = await Http.doPost('api/role/scope/update', val);
        if (resp.code === 200) {
            message.success('分配成功');
            return true;
        } else {
            message.error(resp.msg);
            return false;
        }
    } catch (error) {
        message.error('分配失败请重试!');
        return false;
    } finally {
        hide();
    }
};
const Main = () => {
    const formTableRef = useRef();
@@ -94,7 +118,8 @@
    const [currentRow, setCurrentRow] = useState();
    const [searchParam, setSearchParam] = useState({});
    const intl = useIntl();
    const [scopeModalVisible, setScopeModalVisible] = useState(false);
    const [menuIds, setMenuIds] = useState([]);
    useEffect(() => {
@@ -105,24 +130,41 @@
            title: 'No',
            dataIndex: 'index',
            valueType: 'indexBorder',
            width: 48,
            width: 60,
        },
        {
            title: '姓名',
            dataIndex: 'name',
            valueType: 'text',
            copyable: true,
            filterDropdown: (props) => <TextFilter
                name='name'
                {...props}
                actionRef={actionRef}
                setSearchParam={setSearchParam}
            />,
            render: (_, record) => {
                return (
                    <a
                        onClick={() => {
                            Http.doGetPromise('/api/role/scope/list', { roleId: record.id }, (res) => {
                                if (res.data) {
                                    setMenuIds(res.data);
                                }
                                setScopeModalVisible(true);
                                setCurrentRow(record);
                            });
                        }}
                    >
                        {_}
                    </a>
                );
            },
        },
        {
            title: '标识',
            dataIndex: 'code',
            valueType: 'text',
            copyable: true,
            filterDropdown: (props) => <TextFilter
                name='code'
                {...props}
@@ -131,9 +173,15 @@
            />,
        },
        {
            title: '公司',
            dataIndex: 'hostId$',
            title: '修改时间',
            dataIndex: 'updateTime$',
            valueType: 'text',
            filterDropdown: (props) => <DatetimeRangeFilter
                name='updateTime'
                {...props}
                actionRef={actionRef}
                setSearchParam={setSearchParam}
            />,
        },
        {
            title: '状态',
@@ -149,17 +197,26 @@
                    { label: '禁用', value: 0 },
                ]}
            />,
            render: (_, record) => {
                const status = statusMap[record.status]
                return <Tag color={status.color}>{status.text}</Tag>
            },
        },
        {
            title: '修改时间',
            dataIndex: 'updateTime$',
            title: '备注',
            dataIndex: 'memo',
            valueType: 'text',
            filterDropdown: (props) => <TextFilter
                name='memo'
                {...props}
                actionRef={actionRef}
                setSearchParam={setSearchParam}
            />,
        },
        {
            title: '操作',
            dataIndex: 'option',
            width: '220px',
            width: 260,
            valueType: 'option',
            render: (_, record) => [
                <Button
@@ -171,6 +228,21 @@
                    }}
                >
                    编辑
                </Button>,
                <Button
                    type="link"
                    key="scope"
                    onClick={() => {
                        Http.doGetPromise('/api/role/scope/list', { roleId: record.id }, (res) => {
                            if (res.data) {
                                setMenuIds(res.data);
                            }
                            setScopeModalVisible(true);
                            setCurrentRow(record);
                        });
                    }}
                >
                    分配权限
                </Button>,
                <Button
                    type="link"
@@ -198,7 +270,11 @@
    ];
    return (
        <PageContainer>
        <PageContainer
            header={{
                breadcrumb: {},
            }}
        >
            <div style={{ width: '100%', float: 'right' }}>
                <ProTable
                    key="role"
@@ -207,9 +283,12 @@
                    formRef={formTableRef}
                    columns={columns}
                    cardBordered
                    scroll={{ x: 1300 }}
                    dateFormatter="string"
                    pagination={{ pageSize: 20 }}
                    search={false}
                    toolbar={{
                        multipleLine: true,
                        search: {
                            onSearch: (value) => {
                                setSearchParam(prevState => ({
@@ -263,9 +342,10 @@
                        }
                    }}
                    columnsState={{
                        persistenceKey: 'pro-table-role',
                        persistenceKey: TABLE_KEY,
                        persistenceType: 'localStorage',
                        defaultValue: {
                            memo: { show: repairBug(TABLE_KEY, 'memo', false) },
                            option: { fixed: 'right', disable: true },
                        },
                        onChange(value) {
@@ -278,9 +358,9 @@
                <FooterToolbar
                    extra={
                        <div>
                            <FormattedMessage id="pages.searchTable.chosen" defaultMessage="已选择" />
                            已选择
                            <a style={{ fontWeight: 600 }}>{selectedRows.length}</a>
                            <FormattedMessage id="pages.searchTable.item" defaultMessage="项" />
                            项
                        </div>
                    }
                >
@@ -332,6 +412,33 @@
                }
                }
            />
            <Scope
                open={scopeModalVisible}
                values={currentRow || {}}
                originMenuIds={menuIds}
                onCancel={
                    () => {
                        setScopeModalVisible(false);
                        setCurrentRow(undefined);
                        setMenuIds([]);
                    }
                }
                onSubmit={async (values) => {
                    let ok = false;
                    if (values.id) {
                        ok = await handleScope({ ...values })
                    }
                    if (ok) {
                        setScopeModalVisible(false);
                        setCurrentRow(undefined);
                        setMenuIds([]);
                        if (actionRef.current) {
                            actionRef.current.reload();
                        }
                    }
                }}
            />
        </PageContainer>
    );
};