From 84152dddc1702df2d62a82ba9217f300aa3b3471 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期三, 14 二月 2024 22:23:08 +0800
Subject: [PATCH] #

---
 zy-asrs-flow/src/pages/system/role/index.jsx           |  155 ++++++++++++++++--------------
 zy-asrs-flow/src/utils/http.js                         |   46 ++++----
 zy-asrs-flow/src/pages/system/role/components/edit.jsx |   82 ++++++++++++++++
 3 files changed, 186 insertions(+), 97 deletions(-)

diff --git a/zy-asrs-flow/src/pages/system/role/components/edit.jsx b/zy-asrs-flow/src/pages/system/role/components/edit.jsx
new file mode 100644
index 0000000..1f4c578
--- /dev/null
+++ b/zy-asrs-flow/src/pages/system/role/components/edit.jsx
@@ -0,0 +1,82 @@
+import React, { useEffect, useState } from 'react';
+import {
+    ProForm,
+    ProFormDigit,
+    ProFormText,
+    ProFormRadio,
+    ProFormTextArea,
+} from '@ant-design/pro-components';
+import { Form, Modal } from 'antd';
+import { useIntl, FormattedMessage } from '@umijs/max';
+
+const Edit = (props) => {
+    const [form] = Form.useForm();
+    const { } = props;
+    const intl = useIntl();
+
+    useEffect(() => {
+        form.resetFields();
+        form.setFieldsValue({
+            ...props.values
+        })
+    }, [form, props])
+
+    const handleCancel = () => {
+        props.onCancel();
+    };
+
+    const handleOk = () => {
+        form.submit();
+    }
+
+    const handleFinish = async (values) => {
+        props.onSubmit({ ...values });
+    }
+
+    return (
+        <>
+            <Modal
+                title="Edit"
+                width={640}
+                forceRender
+                destroyOnClose
+                open={props.open}
+                onCancel={handleCancel}
+                onOk={handleOk}
+            >
+                <ProForm
+                    form={form}
+                    submitter={false}
+                    onFinish={handleFinish}
+                    layout="horizontal"
+                    grid={true}
+                >
+                    <ProFormText
+                        name="name"
+                        label="瑙掕壊鍚嶇О"
+                        placeholder="璇疯緭鍏�"
+                        rules={[
+                            {
+                                required: true,
+                                message: "璇疯緭鍏ヨ鑹插悕绉帮紒",
+                            },
+                        ]}
+                    />
+                    <ProFormText
+                        name="code"
+                        label="瑙掕壊鏍囪瘑"
+                        placeholder="璇疯緭鍏�"
+                        rules={[
+                            {
+                                required: true,
+                                message: "璇疯緭鍏ヨ鑹叉爣璇嗭紒",
+                            },
+                        ]}
+                    />
+                </ProForm>
+            </Modal>
+        </>
+    )
+}
+
+export default Edit;
\ No newline at end of file
diff --git a/zy-asrs-flow/src/pages/system/role/index.jsx b/zy-asrs-flow/src/pages/system/role/index.jsx
index fe8716b..b9d4a8a 100644
--- a/zy-asrs-flow/src/pages/system/role/index.jsx
+++ b/zy-asrs-flow/src/pages/system/role/index.jsx
@@ -3,16 +3,48 @@
 import { useIntl, FormattedMessage } 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} from '@/services/monitor/logininfor';
-import Http from '@/utils/http'
+import { PlusOutlined, DeleteOutlined, ExclamationCircleOutlined, ExportOutlined } from '@ant-design/icons';
+import { getLogininforList, removeLogininfor, exportLogininfor } from '@/services/monitor/logininfor';
+import Http from '@/utils/http';
+import Edit from './components/edit'
 
+const handleSave = async (val) => {
+    const hide = message.loading('姝e湪娣诲姞');
+    try {
+        const resp = await Http.doPost('api/role/save', val);
+        hide();
+        if (resp.code === 200) {
+            message.success('娣诲姞鎴愬姛');
+            return true;
+        } else {
+            message.error(resp.msg);
+            return false;
+        }
+    } catch (error) {
+        hide();
+        message.error('娣诲姞澶辫触璇烽噸璇曪紒');
+        return false;
+    }
+};
 
-/**
- * 鍒犻櫎鑺傜偣
- *
- * @param selectedRows
- */
+const handleUpdate = async (val) => {
+    const hide = message.loading('姝e湪鏇存柊');
+    try {
+        const resp = await updateRole(val);
+        hide();
+        if (resp.code === 200) {
+            message.success('鏇存柊鎴愬姛');
+        } else {
+            message.error(resp.msg);
+        }
+        return true;
+    } catch (error) {
+        hide();
+        message.error('閰嶇疆澶辫触璇烽噸璇曪紒');
+        return false;
+    }
+};
+
 const handleRemove = async (selectedRows) => {
     if (!selectedRows) return true;
     const hide = message.loading('姝e湪鍒犻櫎');
@@ -32,11 +64,6 @@
     }
 };
 
-/**
- * 瀵煎嚭鏁版嵁
- *
- * @param id
- */
 const handleExport = async () => {
     const hide = message.loading('姝e湪瀵煎嚭');
     try {
@@ -53,14 +80,12 @@
 
 
 const LogininforTableList = () => {
-
     const formTableRef = useRef();
-
     const actionRef = useRef();
     const [selectedRows, setSelectedRows] = useState([]);
-    const [statusOptions, setStatusOptions] = useState([]);
+    const [modalVisible, setModalVisible] = useState(false);
+    const [currentRow, setCurrentRow] = useState();
 
-    /** 鍥介檯鍖栭厤缃� */
     const intl = useIntl();
 
     useEffect(() => {
@@ -78,60 +103,6 @@
             dataIndex: 'code',
             valueType: 'text',
         },
-        // {
-        //     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',
-        // },
     ];
 
     return (
@@ -175,17 +146,26 @@
                         </Button>,
                         <Button
                             type="primary"
+                            key="save"
+                            onClick={async () => {
+                                setModalVisible(true)
+                            }}
+                        >
+                            <PlusOutlined />
+                            娣诲姞
+                        </Button>,
+                        <Button
                             key="export"
                             onClick={async () => {
                                 handleExport();
                             }}
                         >
-                            <PlusOutlined />
-                            <FormattedMessage id="pages.searchTable.export" defaultMessage="瀵煎嚭" />
+                            <ExportOutlined />
+                            瀵煎嚭
                         </Button>,
                     ]}
                     request={(params) =>
-                        Http.doPost('/api/role/page', params, (res) => {
+                        Http.doPostPromise('/api/role/page', params, (res) => {
                             return {
                                 data: res.data.records,
                                 total: res.data.total,
@@ -233,6 +213,33 @@
                     </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})
+                    } else {
+                        ok = await handleSave({...values})
+                    }
+                    if (ok) {
+                        setModalVisible(false);
+                        setCurrentRow(undefined);
+                        if (actionRef.current) {
+                            actionRef.current.reload();
+                        }
+                    }
+                }
+                }
+            />
         </PageContainer>
     );
 };
diff --git a/zy-asrs-flow/src/utils/http.js b/zy-asrs-flow/src/utils/http.js
index 4743ae6..904db20 100644
--- a/zy-asrs-flow/src/utils/http.js
+++ b/zy-asrs-flow/src/utils/http.js
@@ -1,7 +1,18 @@
 import { request } from '@umijs/max';
 import { message, Modal } from 'antd';
 
-const doGet = (url, params, fn) => {
+const doGet = async (url, params) => {
+    const res = await request(url, {
+        method: 'GET',
+        params
+    });
+    if (res.code === 200) {
+        return res;
+    }
+    message.error(res.msg)
+}
+
+const doGetPromise = (url, params, fn) => {
     return request(url, {
         method: 'GET',
         params
@@ -18,18 +29,21 @@
     });
 }
 
-const doGetSync = async (url, params) => {
+const doPost = async (url, params, fn) => {
     const res = await request(url, {
-        method: 'GET',
-        params
+        method: 'POST',
+        headers: {
+            'Content-Type': 'application/json'
+        },
+        data: { ...params }
     });
-    if (res.code === 200) {
-        return res;
+    if (fn) {
+        fn(res);
     }
-    message.error(res.msg)
+    return res;
 }
 
-const doPost = (url, params, fn) => {
+const doPostPromise = (url, params, fn) => {
     return request(url, {
         method: 'POST',
         headers: {
@@ -49,20 +63,6 @@
     });
 }
 
-const doPostSync = async (url, params) => {
-    const res = await request(url, {
-        method: 'POST',
-        headers: {
-            'Content-Type': 'application/json'
-        },
-        data: { ...params }
-    });
-    if (res.code === 200) {
-        return res;
-    }
-    message.error(res.msg)
-}
-
-const Http = { doGet, doGetSync, doPost, doPostSync }
+const Http = { doGet, doGetPromise, doPost, doPostPromise }
 
 export default Http;
\ No newline at end of file

--
Gitblit v1.9.1