#
luxiaotao1123
2024-02-21 dca78d5fd0c67fd841d6841ef2cd94a10669c356
zy-asrs-flow/src/pages/system/role/index.jsx
@@ -1,18 +1,21 @@
import React, { useState, useRef, useEffect } from 'react';
import { useIntl, FormattedMessage } from '@umijs/max';
import { Button, message, Modal } from 'antd';
import { FooterToolbar, PageContainer, ProTable } from '@ant-design/pro-components';
import {
    FooterToolbar,
    PageContainer,
    ProTable,
    LightFilter,
} from '@ant-design/pro-components';
import { PlusOutlined, ExportOutlined } from '@ant-design/icons';
import { getLogininforList, removeLogininfor, exportLogininfor } from '@/services/monitor/logininfor';
import Http from '@/utils/http';
import Edit from './components/edit'
import { TextFilter, SelectFilter, DatetimeRangeFilter, LinkFilter } from '@/components/TableSearch'
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;
@@ -21,9 +24,10 @@
            return false;
        }
    } catch (error) {
        hide();
        message.error('添加失败请重试!');
        return false;
    } finally {
        hide();
    }
};
@@ -31,7 +35,6 @@
    const hide = message.loading('正在更新');
    try {
        const resp = await Http.doPost('api/role/update', val);
        hide();
        if (resp.code === 200) {
            message.success('更新成功');
            return true;
@@ -40,9 +43,10 @@
            return false;
        }
    } catch (error) {
        hide();
        message.error('配置失败请重试!');
        return false;
    } finally {
        hide();
    }
};
@@ -51,7 +55,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;
@@ -60,35 +63,37 @@
            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 LogininforTableList = () => {
const Main = () => {
    const formTableRef = useRef();
    const actionRef = useRef();
    const [selectedRows, setSelectedRows] = useState([]);
    const [modalVisible, setModalVisible] = useState(false);
    const [currentRow, setCurrentRow] = useState();
    const intl = useIntl();
    const [searchParam, setSearchParam] = useState({});
    useEffect(() => {
@@ -96,24 +101,80 @@
    const columns = [
        {
            title: 'No',
            dataIndex: 'index',
            valueType: 'indexBorder',
            width: 48,
        },
        {
            title: '姓名',
            dataIndex: 'name',
            valueType: 'text',
            copyable: true,
            filterDropdown: (props) => <TextFilter
                name='name'
                {...props}
                actionRef={actionRef}
                setSearchParam={setSearchParam}
            />,
        },
        {
            title: '标识',
            dataIndex: 'code',
            valueType: 'text',
            filterDropdown: (props) => <TextFilter
                name='code'
                {...props}
                actionRef={actionRef}
                setSearchParam={setSearchParam}
            />,
        },
        {
            title: '机构',
            dataIndex: 'hostId$',
            valueType: 'text',
            filterDropdown: (props) => <LinkFilter
                name='hostId'
                major='host'
                {...props}
                actionRef={actionRef}
                setSearchParam={setSearchParam}
            />,
        },
        {
            title: '状态',
            dataIndex: 'status$',
            valueType: 'text',
            filterDropdown: (props) => <SelectFilter
                name='status'
                {...props}
                actionRef={actionRef}
                setSearchParam={setSearchParam}
                data={[
                    { label: '正常', value: 1 },
                    { label: '禁用', value: 0 },
                ]}
            />,
        },
        {
            title: '修改时间',
            dataIndex: 'updateTime$',
            valueType: 'text',
            filterDropdown: (props) => <DatetimeRangeFilter
                name='updateTime'
                {...props}
                actionRef={actionRef}
                setSearchParam={setSearchParam}
            />,
        },
        {
            title: '操作',
            dataIndex: 'option',
            width: '220px',
            width: 140,
            valueType: 'option',
            render: (_, record) => [
                <Button
                    type="link"
                    size="small"
                    key="edit"
                    onClick={() => {
                        setModalVisible(true);
@@ -124,7 +185,6 @@
                </Button>,
                <Button
                    type="link"
                    size="small"
                    danger
                    key="batchRemove"
                    onClick={async () => {
@@ -152,40 +212,57 @@
        <PageContainer>
            <div style={{ width: '100%', float: 'right' }}>
                <ProTable
                    headerTitle={intl.formatMessage({
                        id: 'pages.searchTable.title',
                        defaultMessage: '信息',
                    })}
                    key="role"
                    rowKey="id"
                    actionRef={actionRef}
                    formRef={formTableRef}
                    rowKey="id"
                    key="logininforList"
                    search={{
                        labelWidth: 120,
                    columns={columns}
                    cardBordered
                    dateFormatter="string"
                    pagination={{ pageSize: 20 }}
                    search={false}
                    toolbar={{
                        multipleLine: true,
                        search: {
                            onSearch: (value) => {
                                setSearchParam(prevState => ({
                                    ...prevState,
                                    condition: value
                                }));
                                actionRef.current?.reload();
                            },
                        },
                        filter: (
                            <LightFilter
                                onValuesChange={(val) => {
                                }}
                            >
                            </LightFilter>
                        ),
                        actions: [
                            <Button
                                type="primary"
                                key="save"
                                onClick={async () => {
                                    setModalVisible(true)
                                }}
                            >
                                <PlusOutlined />
                                添加
                            </Button>,
                            <Button
                                key="export"
                                onClick={async () => {
                                    handleExport();
                                }}
                            >
                                <ExportOutlined />
                                导出
                            </Button>,
                        ],
                    }}
                    toolBarRender={() => [
                        <Button
                            type="primary"
                            key="save"
                            onClick={async () => {
                                setModalVisible(true)
                            }}
                        >
                            <PlusOutlined />
                            添加
                        </Button>,
                        <Button
                            key="export"
                            onClick={async () => {
                                handleExport();
                            }}
                        >
                            <ExportOutlined />
                            导出
                        </Button>,
                    ]}
                    request={(params) =>
                        Http.doPostPromise('/api/role/page', params, (res) => {
                    request={(params, sorter, filter) =>
                        Http.doPostPromise('/api/role/page', { ...params, ...searchParam }, (res) => {
                            return {
                                data: res.data.records,
                                total: res.data.total,
@@ -193,21 +270,30 @@
                            }
                        })
                    }
                    columns={columns}
                    rowSelection={{
                        onChange: (ids, rows) => {
                            setSelectedRows(rows);
                        }
                    }}
                    columnsState={{
                        persistenceKey: 'pro-table-role',
                        persistenceType: 'localStorage',
                        defaultValue: {
                            option: { fixed: 'right', disable: true },
                        },
                        onChange(value) {
                        },
                    }}
                />
            </div>
            {selectedRows?.length > 0 && (
                <FooterToolbar
                    extra={
                        <div>
                            <FormattedMessage id="pages.searchTable.chosen" defaultMessage="已选择" />
                            已选择
                            <a style={{ fontWeight: 600 }}>{selectedRows.length}</a>
                            <FormattedMessage id="pages.searchTable.item" defaultMessage="项" />
                            项
                        </div>
                    }
                >
@@ -218,8 +304,6 @@
                            Modal.confirm({
                                title: '删除',
                                content: '确定删除该项吗?',
                                okText: '确认',
                                cancelText: '取消',
                                onOk: async () => {
                                    const success = await handleRemove(selectedRows);
                                    if (success) {
@@ -230,7 +314,7 @@
                            });
                        }}
                    >
                        <FormattedMessage id="pages.searchTable.batchDeletion" defaultMessage="批量删除" />
                        批量删除
                    </Button>
                </FooterToolbar>
            )}
@@ -265,4 +349,4 @@
    );
};
export default LogininforTableList;
export default Main;