From 074513acdfed38c8537a046801ee5dbc8f01e2eb Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期四, 22 二月 2024 10:06:42 +0800
Subject: [PATCH] #

---
 zy-asrs-flow/src/pages/system/user/index.jsx |  260 ++++++++++++++++++++++++++++++++-------------------
 1 files changed, 161 insertions(+), 99 deletions(-)

diff --git a/zy-asrs-flow/src/pages/system/user/index.jsx b/zy-asrs-flow/src/pages/system/user/index.jsx
index 5d817a5..dae8e2a 100644
--- a/zy-asrs-flow/src/pages/system/user/index.jsx
+++ b/zy-asrs-flow/src/pages/system/user/index.jsx
@@ -1,16 +1,19 @@
 
 import React, { useState, useRef, useEffect } from 'react';
-import { Button, message, Modal, Row, Col, Card, Tree, Input } from 'antd';
+import { Button, message, Modal, Row, Col, Card, Tree, Input, Tag } from 'antd';
 import {
     FooterToolbar,
     PageContainer,
     ProTable,
     LightFilter,
 } from '@ant-design/pro-components';
-import { PlusOutlined, ExportOutlined, DownOutlined } from '@ant-design/icons';
+import { PlusOutlined, ExportOutlined, DownOutlined, DeleteOutlined, ExclamationCircleOutlined } from '@ant-design/icons';
 import Http from '@/utils/http';
 import Edit from './components/edit'
+import Pwd from './components/pwd'
 import { TextFilter, SelectFilter, DatetimeRangeFilter, LinkFilter } from '@/components/TableSearch'
+import { transformTreeData, getTreeAllKeys } from '@/utils/tree-util'
+import { statusMap } from '@/utils/enum-util'
 
 const handleSave = async (val) => {
     const hide = message.loading('姝e湪娣诲姞');
@@ -86,6 +89,25 @@
     }
 };
 
+const handlePwd = async (val) => {
+    const hide = message.loading('姝e湪閲嶇疆');
+    try {
+        const resp = await Http.doPost('api/user/reset/pwd', 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();
@@ -95,28 +117,45 @@
     const [currentRow, setCurrentRow] = useState();
     const [searchParam, setSearchParam] = useState({});
     const [boxHeight, setBoxHeight] = useState();
+    const [deptTreeData, setDeptTreeData] = useState([]);
+    const [deptExpandedKeys, setDeptExpandedKeys] = useState([]);
+    const [pwdModalVisible, setPwdModalVisible] = useState(false);
+
+    const loadDeptTreeData = (param) => {
+        Http.doPostPromise('/api/dept/tree', param, (res) => {
+            const rootMenu = { id: 0, name: '鍏ㄩ儴', value: 0, children: [] };
+            rootMenu.children = res.data;
+            // const treeData = transformTreeData([rootMenu]);
+            const treeData = transformTreeData(res.data);
+            setDeptTreeData(treeData);
+            const treeAllKeys = getTreeAllKeys(treeData);
+            setDeptExpandedKeys(treeAllKeys);
+        })
+    }
 
     useEffect(() => {
         const handleResize = () => setBoxHeight(window.innerHeight - 368);
         window.addEventListener('resize', handleResize);
         handleResize();
+
+        loadDeptTreeData();
+
         return () => window.removeEventListener('resize', handleResize);
-    }, [boxHeight]);
+    }, []);
 
     const columns = [
         {
             title: 'No',
             dataIndex: 'index',
             valueType: 'indexBorder',
-            width: 48,
+            width: 30,
         },
         {
-            title: '鏄电О',
+            title: '鍚嶇О',
             dataIndex: 'nickname',
             valueType: 'text',
             hidden: false,
-            width: 140,
-            copyable: true,
+            width: 100,
             filterDropdown: (props) => <TextFilter
                 name='nickname'
                 {...props}
@@ -125,11 +164,11 @@
             />,
         },
         {
-            title: '璐﹀彿',
+            title: '鐧诲綍璐﹀彿',
             dataIndex: 'username',
             valueType: 'text',
             hidden: false,
-            width: 140,
+            width: 100,
             filterDropdown: (props) => <TextFilter
                 name='username'
                 {...props}
@@ -142,7 +181,7 @@
             dataIndex: 'password',
             valueType: 'password',
             hidden: true,
-            width: 140,
+            width: 100,
             filterDropdown: (props) => <TextFilter
                 name='password'
                 {...props}
@@ -154,7 +193,7 @@
             title: '澶村儚',
             dataIndex: 'avatar',
             valueType: 'text',
-            hidden: false,
+            hidden: true,
             width: 140,
             filterDropdown: (props) => <TextFilter
                 name='avatar'
@@ -181,7 +220,7 @@
             dataIndex: 'sex$',
             valueType: 'text',
             hidden: false,
-            width: 140,
+            width: 80,
             filterDropdown: (props) => <SelectFilter
                 name='sex'
                 {...props}
@@ -199,7 +238,7 @@
             dataIndex: 'phone',
             valueType: 'text',
             hidden: false,
-            width: 140,
+            width: 100,
             filterDropdown: (props) => <TextFilter
                 name='phone'
                 {...props}
@@ -211,7 +250,7 @@
             title: '閭',
             dataIndex: 'email',
             valueType: 'text',
-            hidden: false,
+            hidden: true,
             width: 140,
             filterDropdown: (props) => <TextFilter
                 name='email'
@@ -242,14 +281,21 @@
             dataIndex: 'deptId$',
             valueType: 'text',
             hidden: false,
-            width: 140,
-            filterDropdown: (props) => <LinkFilter
-                name='deptId'
-                major='dept'
-                {...props}
-                actionRef={actionRef}
-                setSearchParam={setSearchParam}
-            />,
+            width: 100,
+            render: (_, record) => {
+                if (_ && _ !== '-') {
+                    return <Tag color={""}>{_}</Tag>
+                } else {
+                    return '-'
+                }
+            },
+            // filterDropdown: (props) => <LinkFilter
+            //     name='deptId'
+            //     major='dept'
+            //     {...props}
+            //     actionRef={actionRef}
+            //     setSearchParam={setSearchParam}
+            // />,
         },
         {
             title: '鐪熷疄濮撳悕',
@@ -308,7 +354,11 @@
             dataIndex: 'status$',
             valueType: 'text',
             hidden: false,
-            width: 140,
+            width: 80,
+            render: (_, record) => {
+                const status = statusMap[record.status]
+                return <Tag color={status.color}>{status.text}</Tag>
+            },
             filterDropdown: (props) => <SelectFilter
                 name='status'
                 {...props}
@@ -377,7 +427,7 @@
         {
             title: '鎿嶄綔',
             dataIndex: 'option',
-            width: 140,
+            width: 150,
             valueType: 'option',
             render: (_, record) => [
                 <Button
@@ -392,8 +442,18 @@
                 </Button>,
                 <Button
                     type="link"
+                    key="pwd"
+                    onClick={() => {
+                        setPwdModalVisible(true);
+                        setCurrentRow(record);
+                    }}
+                >
+                    閲嶇疆瀵嗙爜
+                </Button>,
+                <Button
+                    type="link"
                     danger
-                    key="batchRemove"
+                    key="remove"
                     onClick={async () => {
                         Modal.confirm({
                             title: '鍒犻櫎',
@@ -425,51 +485,34 @@
                 <Col lg={6} md={24}>
                     <Card title="閮ㄩ棬" style={{ width: '100%', height: 'calc(100vh - 200px)' }}>
                         <Input
-                            style={{ marginBottom: 8 }}
+                            style={{ marginBottom: 10 }}
                             placeholder="Search"
                             onChange={(e) => {
                                 const { value } = e.target;
-                                console.log(value);
+                                loadDeptTreeData({
+                                    condition: value
+                                })
                             }}
                         />
-                        <Tree
-                            showLine
-                            switcherIcon={<DownOutlined />}
-                            blockNode
-                            defaultExpandAll
-                            onSelect={(selectedKeys, info) => {
-                                console.log(selectedKeys, info);
-                            }}
-                            treeData={[
-                                {
-                                    title: 'parent 1',
-                                    key: '0-0',
-                                    children: [
-                                        {
-                                            title: 'parent 1-0',
-                                            key: '0-0-0',
-                                            disabled: true,
-                                            children: [
-                                                {
-                                                    title: 'leaf',
-                                                    key: '0-0-0-0',
-                                                    disableCheckbox: true,
-                                                },
-                                                {
-                                                    title: 'leaf',
-                                                    key: '0-0-0-1',
-                                                },
-                                            ],
-                                        },
-                                        {
-                                            title: 'parent 1-1',
-                                            key: '0-0-1',
-                                            children: [{ title: <span style={{ color: '#1677ff' }}>sss</span>, key: '0-0-1-0' }],
-                                        },
-                                    ],
-                                },
-                            ]}
-                        />
+                        <div style={{height: 'calc(100vh - 350px)', overflowY: 'auto' }}>
+                            <Tree
+                                showLine
+                                blockNode
+                                defaultExpandAll    // 寮傛鍔犺浇澶辨晥
+                                expandedKeys={deptExpandedKeys}
+                                onExpand={setDeptExpandedKeys}
+                                treeData={deptTreeData}
+                                switcherIcon={<DownOutlined />}
+                                onSelect={(selectedKeys, info) => {
+                                    const deptId = selectedKeys[0];
+                                    setSearchParam(prevState => ({
+                                        ...prevState,
+                                        deptId: deptId
+                                    }));
+                                    actionRef.current?.reload();
+                                }}
+                            />
+                        </div>
                     </Card>
                 </Col>
                 <Col lg={18} md={24}>
@@ -480,7 +523,7 @@
                         formRef={formTableRef}
                         columns={columns}
                         cardBordered
-                        scroll={{ x: 1300, y: boxHeight }}
+                        scroll={{ y: boxHeight }}
                         dateFormatter="string"
                         pagination={{ pageSize: 20 }}
                         search={false}
@@ -504,6 +547,30 @@
                             actions: [
                                 <Button
                                     type="primary"
+                                    danger
+                                    key="removeBatch"
+                                    hidden={selectedRows?.length === 0}
+                                    onClick={async () => {
+                                        Modal.confirm({
+                                            title: '鏄惁纭鍒犻櫎鎵�閫夋暟鎹」?',
+                                            icon: <ExclamationCircleOutlined />,
+                                            content: '璇疯皑鎱庢搷浣�',
+                                            async onOk() {
+                                                const success = await handleRemove(selectedRows);
+                                                if (success) {
+                                                    setSelectedRows([]);
+                                                    actionRef.current.reload();
+                                                }
+                                            },
+                                            onCancel() { },
+                                        });
+                                    }}
+                                >
+                                    <DeleteOutlined />
+                                    鍒犻櫎
+                                </Button>,
+                                <Button
+                                    type="primary"
                                     key="save"
                                     onClick={async () => {
                                         setModalVisible(true)
@@ -524,7 +591,7 @@
                             ],
                         }}
                         request={(params, sorter, filter) =>
-                            Http.doPostPromise('/api/user/page', { ...params, ...searchParam }, (res) => {
+                            Http.doPostPromise('/api/user/page1', { ...params, ...searchParam }, (res) => {
                                 return {
                                     data: res.data.records,
                                     total: res.data.total,
@@ -532,6 +599,7 @@
                                 }
                             })
                         }
+                        tableAlertRender={false}
                         rowSelection={{
                             onChange: (ids, rows) => {
                                 setSelectedRows(rows);
@@ -549,41 +617,10 @@
                     />
                 </Col>
 
-                {selectedRows?.length > 0 && (
-                    <FooterToolbar
-                        extra={
-                            <div>
-                                宸查�夋嫨
-                                <a style={{ fontWeight: 600 }}>{selectedRows.length}</a>
-                                椤�
-                            </div>
-                        }
-                    >
-                        <Button
-                            key="remove"
-                            danger
-                            onClick={async () => {
-                                Modal.confirm({
-                                    title: '鍒犻櫎',
-                                    content: '纭畾鍒犻櫎璇ラ」鍚楋紵',
-                                    onOk: async () => {
-                                        const success = await handleRemove(selectedRows);
-                                        if (success) {
-                                            setSelectedRows([]);
-                                            actionRef.current?.reloadAndRest?.();
-                                        }
-                                    },
-                                });
-                            }}
-                        >
-                            鎵归噺鍒犻櫎
-                        </Button>
-                    </FooterToolbar>
-                )}
-
                 <Edit
                     open={modalVisible}
                     values={currentRow || {}}
+                    treeData={deptTreeData}
                     onCancel={
                         () => {
                             setModalVisible(false);
@@ -607,6 +644,31 @@
                     }
                     }
                 />
+
+                <Pwd
+                    open={pwdModalVisible}
+                    values={currentRow || {}}
+                    onCancel={
+                        () => {
+                            setPwdModalVisible(false);
+                            setCurrentRow(undefined);
+                        }
+                    }
+                    onSubmit={async (values) => {
+                        let ok = false;
+                        if (values.id) {
+                            ok = await handlePwd({ ...values })
+                        }
+                        if (ok) {
+                            setPwdModalVisible(false);
+                            setCurrentRow(undefined);
+                            if (actionRef.current) {
+                                actionRef.current.reload();
+                            }
+                        }
+                    }
+                    }
+                />
             </Row>
         </PageContainer>
     );

--
Gitblit v1.9.1