From ac4341ea6b66ae02427d39d35f41d42d78b2eb2e Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期五, 14 二月 2025 10:08:32 +0800
Subject: [PATCH] #

---
 zy-asrs-flow/src/pages/system/role/index.jsx |  554 ++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 340 insertions(+), 214 deletions(-)

diff --git a/zy-asrs-flow/src/pages/system/role/index.jsx b/zy-asrs-flow/src/pages/system/role/index.jsx
index ab1f26e..909771b 100644
--- a/zy-asrs-flow/src/pages/system/role/index.jsx
+++ b/zy-asrs-flow/src/pages/system/role/index.jsx
@@ -1,104 +1,127 @@
 
 import React, { useState, useRef, useEffect } from 'react';
-import { useIntl, FormattedMessage, useAccess } from '@umijs/max';
-import { Button, message, Modal } from 'antd';
-import { ActionType, FooterToolbar, PageContainer, ProColumns, ProTable } from '@ant-design/pro-components';
-import { PlusOutlined, DeleteOutlined, ExclamationCircleOutlined, UnlockOutlined } from '@ant-design/icons';
-import { getLogininforList, removeLogininfor, exportLogininfor, unlockLogininfor, cleanLogininfor } from '@/services/monitor/logininfor';
-import { request } from '@umijs/max';
-import Http from '@/utils/http'
+import { Button, message, Modal, Tag } from 'antd';
+import {
+    FooterToolbar,
+    PageContainer,
+    ProTable,
+    LightFilter,
+} from '@ant-design/pro-components';
+import { PlusOutlined, ExportOutlined } from '@ant-design/icons';
+import { FormattedMessage, useIntl } from '@umijs/max';
+import Http from '@/utils/http';
+import Edit from './components/edit'
+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";
 
-/**
- * 鍒犻櫎鑺傜偣
- *
- * @param selectedRows
- */
-const handleRemove = async (selectedRows) => {
-    if (!selectedRows) return true;
-    const hide = message.loading('姝e湪鍒犻櫎');
+const handleSave = async (val, intl) => {
+    const hide = message.loading(intl.formatMessage({ id: 'page.adding', defaultMessage: '姝e湪娣诲姞' }));
     try {
-        const resp = await removeLogininfor(selectedRows.map((row) => row.infoId).join(','));
-        hide();
+        const resp = await Http.doPost('api/role/save', val);
         if (resp.code === 200) {
-            message.success('鍒犻櫎鎴愬姛锛屽嵆灏嗗埛鏂�');
+            message.success(intl.formatMessage({ id: 'page.add.success', defaultMessage: '娣诲姞鎴愬姛' }));
+            return true;
         } else {
             message.error(resp.msg);
+            return false;
         }
-        return true;
     } catch (error) {
-        hide();
-        message.error('鍒犻櫎澶辫触锛岃閲嶈瘯');
+        message.error(intl.formatMessage({ id: 'page.add.fail', defaultMessage: '娣诲姞澶辫触璇烽噸璇曪紒' }));
         return false;
+    } finally {
+        hide();
     }
 };
 
-const handleClean = async () => {
-    const hide = message.loading('璇风◢鍊�');
+const handleUpdate = async (val, intl) => {
+    const hide = message.loading(intl.formatMessage({ id: 'page.updating', defaultMessage: '姝e湪鏇存柊' }));
     try {
-        const resp = await cleanLogininfor();
-        hide();
+        const resp = await Http.doPost('api/role/update', val);
         if (resp.code === 200) {
-            message.success('娓呯┖鎴愬姛锛屽嵆灏嗗埛鏂�');
+            message.success(intl.formatMessage({ id: 'page.update.success', defaultMessage: '鏇存柊鎴愬姛' }));
+            return true;
         } else {
             message.error(resp.msg);
+            return false;
         }
-        return true;
     } catch (error) {
-        hide();
-        message.error('璇锋眰澶辫触锛岃閲嶈瘯');
+        message.error(intl.formatMessage({ id: 'page.update.fail', defaultMessage: '鏇存柊澶辫触璇烽噸璇曪紒' }));
         return false;
+    } finally {
+        hide();
     }
 };
 
-const handleUnlock = async (userName) => {
-    const hide = message.loading('姝e湪瑙i攣');
+const handleRemove = async (rows, intl) => {
+    if (!rows) return true;
+    const hide = message.loading(intl.formatMessage({ id: 'page.deleting', defaultMessage: '姝e湪鍒犻櫎' }));
     try {
-        const resp = await unlockLogininfor(userName);
-        hide();
+        const resp = await Http.doPost('api/role/remove/' + rows.map((row) => row.id).join(','));
         if (resp.code === 200) {
-            message.success('瑙i攣鎴愬姛锛屽嵆灏嗗埛鏂�');
+            message.success(intl.formatMessage({ id: 'page.delete.success', defaultMessage: '鍒犻櫎鎴愬姛' }));
+            return true;
         } else {
             message.error(resp.msg);
+            return false;
         }
-        return true;
     } catch (error) {
-        hide();
-        message.error('瑙i攣澶辫触锛岃閲嶈瘯');
+        message.error(intl.formatMessage({ id: 'page.delete.fail', defaultMessage: '鍒犻櫎澶辫触锛岃閲嶈瘯锛�' }));
         return false;
+    } finally {
+        hide();
     }
 };
 
-/**
- * 瀵煎嚭鏁版嵁
- *
- * @param id
- */
-const handleExport = async () => {
-    const hide = message.loading('姝e湪瀵煎嚭');
+const handleExport = async (intl) => {
+    const hide = message.loading(intl.formatMessage({ id: 'page.exporting', defaultMessage: '姝e湪瀵煎嚭' }));
     try {
-        await exportLogininfor();
-        hide();
-        message.success('瀵煎嚭鎴愬姛');
+        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(intl.formatMessage({ id: 'page.export.success', defaultMessage: '瀵煎嚭鎴愬姛' }));
         return true;
     } catch (error) {
-        hide();
-        message.error('瀵煎嚭澶辫触锛岃閲嶈瘯');
+        message.error(intl.formatMessage({ id: 'page.export.fail', defaultMessage: '瀵煎嚭澶辫触锛岃閲嶈瘯' }));
         return false;
+    } finally {
+        hide();
     }
 };
 
+const handleScope = async (val, intl) => {
+    const hide = message.loading(intl.formatMessage({ id: 'page.assigning', defaultMessage: '姝e湪鍒嗛厤' }));
+    try {
+        const resp = await Http.doPost('api/role/scope/update', val);
+        if (resp.code === 200) {
+            message.success(intl.formatMessage({ id: 'page.assign.success', defaultMessage: '鍒嗛厤鎴愬姛' }));
+            return true;
+        } else {
+            message.error(resp.msg);
+            return false;
+        }
+    } catch (error) {
+        message.error(intl.formatMessage({ id: 'page.assign.fail', defaultMessage: '鍒嗛厤澶辫触璇烽噸璇曪紒' }));
+        return false;
+    } finally {
+        hide();
+    }
+};
 
-const LogininforTableList = () => {
-
+const Main = () => {
+    const intl = useIntl();
     const formTableRef = useRef();
-
     const actionRef = useRef();
     const [selectedRows, setSelectedRows] = useState([]);
-    const [statusOptions, setStatusOptions] = useState([]);
+    const [modalVisible, setModalVisible] = useState(false);
+    const [currentRow, setCurrentRow] = useState();
+    const [searchParam, setSearchParam] = useState({});
 
-    /** 鍥介檯鍖栭厤缃� */
-    const intl = useIntl();
+    const [scopeModalVisible, setScopeModalVisible] = useState(false);
+    const [menuIds, setMenuIds] = useState([]);
 
     useEffect(() => {
 
@@ -106,170 +129,211 @@
 
     const columns = [
         {
+            title: intl.formatMessage({
+                id: 'page.table.no',
+                defaultMessage: 'No'
+            }),
+            dataIndex: 'index',
+            valueType: 'indexBorder',
+            width: 60,
+        },
+        {
             title: '濮撳悕',
             dataIndex: 'name',
             valueType: 'text',
+            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}
+                actionRef={actionRef}
+                setSearchParam={setSearchParam}
+            />,
         },
-        // {
-        //     title: <FormattedMessage id="monitor.logininfor.info_id" defaultMessage="璁块棶缂栧彿" />,
-        //     dataIndex: 'infoId',
-        //     valueType: 'text',
-        //     hideInSearch: true,
-        // },
-        // {
-        //     title: <FormattedMessage id="monitor.logininfor.user_name" defaultMessage="鐢ㄦ埛璐﹀彿" />,
-        //     dataIndex: 'userName',
-        //     valueType: 'text',
-        // },
-        // {
-        //     title: <FormattedMessage id="monitor.logininfor.ipaddr" defaultMessage="鐧诲綍IP鍦板潃" />,
-        //     dataIndex: 'ipaddr',
-        //     valueType: 'text',
-        // },
-        // {
-        //     title: <FormattedMessage id="monitor.logininfor.login_location" defaultMessage="鐧诲綍鍦扮偣" />,
-        //     dataIndex: 'loginLocation',
-        //     valueType: 'text',
-        //     hideInSearch: true,
-        // },
-        // {
-        //     title: <FormattedMessage id="monitor.logininfor.browser" defaultMessage="娴忚鍣ㄧ被鍨�" />,
-        //     dataIndex: 'browser',
-        //     valueType: 'text',
-        //     hideInSearch: true,
-        // },
-        // {
-        //     title: <FormattedMessage id="monitor.logininfor.os" defaultMessage="鎿嶄綔绯荤粺" />,
-        //     dataIndex: 'os',
-        //     valueType: 'text',
-        //     hideInSearch: true,
-        // },
-        // {
-        //     title: <FormattedMessage id="monitor.logininfor.status" defaultMessage="鐧诲綍鐘舵��" />,
-        //     dataIndex: 'status',
-        //     valueType: 'select',
-        //     valueEnum: statusOptions,
-        //     // render: (_, record) => {
-        //     //     return (<DictTag enums={statusOptions} value={record.status} />);
-        //     // },
-        // },
-        // {
-        //     title: <FormattedMessage id="monitor.logininfor.msg" defaultMessage="鎻愮ず娑堟伅" />,
-        //     dataIndex: 'msg',
-        //     valueType: 'text',
-        //     hideInSearch: true,
-        // },
-        // {
-        //     title: <FormattedMessage id="monitor.logininfor.login_time" defaultMessage="璁块棶鏃堕棿" />,
-        //     dataIndex: 'loginTime',
-        //     valueType: 'dateTime',
-        // },
+        {
+            title: '淇敼鏃堕棿',
+            dataIndex: 'updateTime$',
+            valueType: 'text',
+            filterDropdown: (props) => <DatetimeRangeFilter
+                name='updateTime'
+                {...props}
+                actionRef={actionRef}
+                setSearchParam={setSearchParam}
+            />,
+        },
+        {
+            title: '鐘舵��',
+            dataIndex: 'status$',
+            valueType: 'text',
+            filterDropdown: (props) => <SelectFilter
+                name='status'
+                {...props}
+                actionRef={actionRef}
+                setSearchParam={setSearchParam}
+                data={[
+                    { label: '姝e父', value: 1 },
+                    { label: '绂佺敤', value: 0 },
+                ]}
+            />,
+            render: (_, record) => {
+                const status = statusMap[record.status]
+                return <Tag color={status.color}>{status.text}</Tag>
+            },
+        },
+        {
+            title: '澶囨敞',
+            dataIndex: 'memo',
+            valueType: 'text',
+            filterDropdown: (props) => <TextFilter
+                name='memo'
+                {...props}
+                actionRef={actionRef}
+                setSearchParam={setSearchParam}
+            />,
+        },
+        {
+            title: '鎿嶄綔',
+            dataIndex: 'option',
+            width: 260,
+            valueType: 'option',
+            render: (_, record) => [
+                <Button
+                    type="link"
+                    key="edit"
+                    onClick={() => {
+                        setModalVisible(true);
+                        setCurrentRow(record);
+                    }}
+                >
+                    <FormattedMessage id='page.edit' defaultMessage='缂栬緫' />
+                </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);
+                        });
+                    }}
+                >
+                    <FormattedMessage id='page.assign.permission' defaultMessage='鍒嗛厤鏉冮檺' />
+                </Button>,
+                <Button
+                    type="link"
+                    danger
+                    key="batchRemove"
+                    onClick={async () => {
+                        Modal.confirm({
+                            title: intl.formatMessage({ id: 'page.delete', defaultMessage: '鍒犻櫎' }),
+                            content: intl.formatMessage({ id: 'page.delete.confirm', defaultMessage: '纭畾鍒犻櫎璇ラ」鍚楋紵' }),
+                            onOk: async () => {
+                                const success = await handleRemove([record], intl);
+                                if (success) {
+                                    if (actionRef.current) {
+                                        actionRef.current.reload();
+                                    }
+                                }
+                            },
+                        });
+                    }}
+                >
+                    <FormattedMessage id='page.delete' defaultMessage='鍒犻櫎' />
+                </Button>,
+            ],
+        },
     ];
 
     return (
-        <PageContainer>
+        <PageContainer
+            header={{
+                breadcrumb: {},
+            }}
+        >
             <div style={{ width: '100%', float: 'right' }}>
                 <ProTable
-                    headerTitle={intl.formatMessage({
-                        id: 'pages.searchTable.title',
-                        defaultMessage: '淇℃伅',
-                    })}
+                    key="role"
+                    rowKey="id"
                     actionRef={actionRef}
                     formRef={formTableRef}
-                    rowKey="infoId"
-                    key="logininforList"
-                    search={{
-                        labelWidth: 120,
+                    columns={columns}
+                    cardBordered
+                    scroll={{ x: 1300 }}
+                    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 />
+                                <FormattedMessage id='page.add' defaultMessage='娣诲姞' />
+                            </Button>,
+                            <Button
+                                key="export"
+                                onClick={async () => {
+                                    handleExport(intl);
+                                }}
+                            >
+                                <ExportOutlined />
+                                <FormattedMessage id='page.export' defaultMessage='瀵煎嚭' />
+                            </Button>,
+                        ],
                     }}
-                    toolBarRender={() => [
-                        <Button
-                            key="remove"
-                            danger
-                            hidden={selectedRows?.length === 0}
-                            onClick={async () => {
-                                Modal.confirm({
-                                    title: '鏄惁纭鍒犻櫎鎵�閫夋暟鎹」?',
-                                    icon: <ExclamationCircleOutlined />,
-                                    content: '璇疯皑鎱庢搷浣�',
-                                    async onOk() {
-                                        const success = await handleRemove(selectedRows);
-                                        if (success) {
-                                            setSelectedRows([]);
-                                            actionRef.current?.reloadAndRest?.();
-                                        }
-                                    },
-                                    onCancel() { },
-                                });
-                            }}
-                        >
-                            <DeleteOutlined />
-                            <FormattedMessage id="pages.searchTable.delete" defaultMessage="鍒犻櫎" />
-                        </Button>,
-                        <Button
-                            type="primary"
-                            key="clean"
-                            danger
-                            hidden={selectedRows?.length === 0}
-                            onClick={async () => {
-                                Modal.confirm({
-                                    title: '鏄惁纭娓呯┖鎵�鏈夋暟鎹」?',
-                                    icon: <ExclamationCircleOutlined />,
-                                    content: '璇疯皑鎱庢搷浣�',
-                                    async onOk() {
-                                        const success = await handleClean();
-                                        if (success) {
-                                            setSelectedRows([]);
-                                            actionRef.current?.reloadAndRest?.();
-                                        }
-                                    },
-                                    onCancel() { },
-                                });
-                            }}
-                        >
-                            <DeleteOutlined />
-                            <FormattedMessage id="pages.searchTable.cleanAll" defaultMessage="娓呯┖" />
-                        </Button>,
-                        <Button
-                            type="primary"
-                            key="unlock"
-                            hidden={selectedRows?.length === 0}
-                            onClick={async () => {
-                                Modal.confirm({
-                                    title: '鏄惁纭瑙i攣璇ョ敤鎴风殑鏁版嵁椤�?',
-                                    icon: <ExclamationCircleOutlined />,
-                                    content: '璇疯皑鎱庢搷浣�',
-                                    async onOk() {
-                                        const success = await handleUnlock(selectedRows[0].userName);
-                                        if (success) {
-                                            setSelectedRows([]);
-                                            actionRef.current?.reloadAndRest?.();
-                                        }
-                                    },
-                                    onCancel() { },
-                                });
-                            }}
-                        >
-                            <UnlockOutlined />
-                            <FormattedMessage id="monitor.logininfor.unlock" defaultMessage="瑙i攣" />
-                        </Button>,
-                        <Button
-                            type="primary"
-                            key="export"
-                            onClick={async () => {
-                                handleExport();
-                            }}
-                        >
-                            <PlusOutlined />
-                            <FormattedMessage id="pages.searchTable.export" defaultMessage="瀵煎嚭" />
-                        </Button>,
-                    ]}
-                    request={(params) =>
-                        Http.doPost('/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,
@@ -277,34 +341,42 @@
                             }
                         })
                     }
-                    columns={columns}
                     rowSelection={{
-                        onChange: (_, selectedRows) => {
-                            setSelectedRows(selectedRows);
+                        onChange: (ids, rows) => {
+                            setSelectedRows(rows);
+                        }
+                    }}
+                    columnsState={{
+                        persistenceKey: TABLE_KEY,
+                        persistenceType: 'localStorage',
+                        defaultValue: {
+                            memo: { show: repairBug(TABLE_KEY, 'memo', false) },
+                            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="椤�" />
+                            <FormattedMessage id='page.selected' defaultMessage=' 椤瑰凡閫夋嫨' />
                         </div>
                     }
                 >
                     <Button
                         key="remove"
+                        danger
                         onClick={async () => {
                             Modal.confirm({
-                                title: '鍒犻櫎',
-                                content: '纭畾鍒犻櫎璇ラ」鍚楋紵',
-                                okText: '纭',
-                                cancelText: '鍙栨秷',
+                                title: intl.formatMessage({ id: 'page.delete', defaultMessage: '鍒犻櫎' }),
+                                content: intl.formatMessage({ id: 'page.delete.confirm', defaultMessage: '纭畾鍒犻櫎璇ラ」鍚楋紵' }),
                                 onOk: async () => {
-                                    const success = await handleRemove(selectedRows);
+                                    const success = await handleRemove(selectedRows, intl);
                                     if (success) {
                                         setSelectedRows([]);
                                         actionRef.current?.reloadAndRest?.();
@@ -313,12 +385,66 @@
                             });
                         }}
                     >
-                        <FormattedMessage id="pages.searchTable.batchDeletion" defaultMessage="鎵归噺鍒犻櫎" />
+                        <FormattedMessage id='page.delete.batch' defaultMessage='鎵归噺鍒犻櫎' />
                     </Button>
                 </FooterToolbar>
             )}
+
+            <Edit
+                open={modalVisible}
+                values={currentRow || {}}
+                onCancel={
+                    () => {
+                        setModalVisible(false);
+                        setCurrentRow(undefined);
+                    }
+                }
+                onSubmit={async (values) => {
+                    let ok = false;
+                    if (values.id) {
+                        ok = await handleUpdate({ ...values }, intl)
+                    } else {
+                        ok = await handleSave({ ...values }, intl)
+                    }
+                    if (ok) {
+                        setModalVisible(false);
+                        setCurrentRow(undefined);
+                        if (actionRef.current) {
+                            actionRef.current.reload();
+                        }
+                    }
+                }
+                }
+            />
+
+            <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 }, intl)
+                    }
+                    if (ok) {
+                        setScopeModalVisible(false);
+                        setCurrentRow(undefined);
+                        setMenuIds([]);
+                        if (actionRef.current) {
+                            actionRef.current.reload();
+                        }
+                    }
+                }}
+            />
         </PageContainer>
     );
 };
 
-export default LogininforTableList;
+export default Main;

--
Gitblit v1.9.1