UserManage.jsx 71.3 KB
Newer Older
1
/* eslint-disable no-unused-expressions */
皮倩雯's avatar
皮倩雯 committed
2
/* eslint-disable eqeqeq */
3
import React, { useState, useEffect, useRef, useMemo } from 'react';
陈前坚's avatar
陈前坚 committed
4
import {
5
  Tree,
陈前坚's avatar
陈前坚 committed
6 7 8 9 10 11 12
  Table,
  Space,
  message,
  Modal,
  Input,
  notification,
  Tooltip,
陈前坚's avatar
陈前坚 committed
13
  Card,
陈前坚's avatar
陈前坚 committed
14
  Button,
15
  Spin,
陈前坚's avatar
陈前坚 committed
16 17
  Dropdown,
  Menu,
皮倩雯's avatar
皮倩雯 committed
18
  Popconfirm,
19 20
  Form,
  Radio,
21
  Pagination,
22 23
  Upload,
  Alert
陈前坚's avatar
陈前坚 committed
24 25
} from 'antd';
import {
26
  UserOutlined,
陈前坚's avatar
陈前坚 committed
27
  UserAddOutlined,
陈前坚's avatar
陈前坚 committed
28
  UsergroupAddOutlined,
29 30
  SnippetsOutlined,
  UserSwitchOutlined,
陈前坚's avatar
陈前坚 committed
31
  EditOutlined,
陈前坚's avatar
陈前坚 committed
32
  EditTwoTone,
陈前坚's avatar
陈前坚 committed
33
  DeleteOutlined,
34
  IdcardOutlined,
35
  SafetyOutlined,
陈前坚's avatar
陈前坚 committed
36
  UnlockOutlined,
陈前坚's avatar
陈前坚 committed
37
  ApartmentOutlined,
陈前坚's avatar
陈前坚 committed
38
  StopOutlined,
陈前坚's avatar
陈前坚 committed
39 40
  DoubleLeftOutlined,
  DoubleRightOutlined,
陈前坚's avatar
陈前坚 committed
41
  DownOutlined,
mayongxin's avatar
mayongxin committed
42
  BorderlessTableOutlined,
皮倩雯's avatar
皮倩雯 committed
43 44 45 46 47
  LockOutlined,
  PlusSquareFilled,
  EllipsisOutlined,
  PlusOutlined,
  SyncOutlined,
48
  ClusterOutlined,
皮倩雯's avatar
皮倩雯 committed
49
  MessageOutlined,
50
  UploadOutlined
陈前坚's avatar
陈前坚 committed
51
} from '@ant-design/icons';
52
import PageContainer from '@/components/BasePageContainer';
53
import { encipher } from '@wisdom-utils/utils/lib/helpers';
陈前坚's avatar
陈前坚 committed
54 55
import voca from 'voca';
import zhCN from 'antd/es/locale/zh_CN';
56 57
import {
  addToOrg,
陈前坚's avatar
陈前坚 committed
58
  addToOrgs,
59 60 61
  getOneOUUserListNew,
  getUserRelationList,
  getUserTree,
皮倩雯's avatar
皮倩雯 committed
62
  // eslint-disable-next-line import/named
张烨's avatar
张烨 committed
63 64
  deleteUser as postDeleteUser,
  setUserState as postSetUserState,
陈前坚's avatar
陈前坚 committed
65
  multiDeleteUsers,
mayongxin's avatar
mayongxin committed
66
  setOrgArea,
mayongxin's avatar
mayongxin committed
67
  getOrgArea,
mayongxin's avatar
mayongxin committed
68
  GetMapSetByGroupID,
mayongxin's avatar
mayongxin committed
69 70 71 72 73 74
  GetOUTreeNew,
  GetUserRelationListNew,
  GetUserByKeyNew,
  UserStateOUNew,
  JumpToAnotherOUNew,
  DeleteUserNew,
皮倩雯's avatar
皮倩雯 committed
75
  loadAllUserRole,
76
  DragGroup,
77 78
  GetAllSite,
  SetGroupManager,
皮倩雯's avatar
皮倩雯 committed
79
  ChangeSMSState,
80
  AddUserAppBindWhiteList,
81
  ExportUserData,
82
  ExportUserTemplate,
83
  ImportUserData,
84 85
  GetPasswordRegularization,
  SysConfiguration
邓超's avatar
邓超 committed
86
} from '@/services/userManage/api';
87
import { AddUserAuthSetting, GetUserAuthSet } from '@/services/database/api';
88
import TreeComponents from '@/components/ExpendableTree';
陈前坚's avatar
陈前坚 committed
89
import classnames from 'classnames';
陈前坚's avatar
陈前坚 committed
90
import AddUserModal from './AddUserModal';
91 92 93 94 95 96
import AddSubOrgModal from './AddSubOrgModal';
import EditOrgModal from './EditOrgModal';
import DeleteOrgModal from './DeleteOrgModal';
import RelateRoleModal from './RelateRoleModal';
import EditUserModal from './EditUserModal';
import ChangePasswordModal from './ChangePasswordModal';
陈前坚's avatar
陈前坚 committed
97
import styles from './UserManage.less';
邓超's avatar
邓超 committed
98 99 100 101 102
const TdCell = props => {
  // onMouseEnter, onMouseLeave在数据量多的时候,会严重阻塞表格单元格渲染,严重影响性能
  const { onMouseEnter, onMouseLeave, ...restProps } = props;
  return <td {...restProps} />;
};
陈前坚's avatar
陈前坚 committed
103

104 105
const path = require('path');

陈前坚's avatar
陈前坚 committed
106
const UserManage = () => {
107
  const [selectValue, setSelctValue] = useState(); // 用户鉴权
108

陈前坚's avatar
陈前坚 committed
109
  const [treeLoading, setTreeLoading] = useState(false);
陈前坚's avatar
陈前坚 committed
110
  const [tableLoading, setTableLoading] = useState(false);
陈前坚's avatar
陈前坚 committed
111
  const [loading, setLoading] = useState(true);
112
  const [currentOrgOperate, setCurrentOrgOperate] = useState(false); // 是否禁用当前机构操作
陈前坚's avatar
陈前坚 committed
113 114
  const [multiOperate, setMultiOperate] = useState(true); // 是否禁用用户批量操作
  const [multiOperateButtonType, setMultiOperateButtonType] = useState(''); // 更改批量操作按钮样式
陈前坚's avatar
陈前坚 committed
115

陈前坚's avatar
陈前坚 committed
116
  const [treeData, setTreeData] = useState([]); // 用户机构树
陈前坚's avatar
陈前坚 committed
117
  const [treeDataCopy, setTreeDataCopy] = useState([]); // 机构树数据备份,用于更改机构
陈前坚's avatar
陈前坚 committed
118 119
  const [treeState, setTreeState] = useState(true); // 树第一次加载
  const [treeVisible, setTreeVisible] = useState(true); // 树是否可见
陈前坚's avatar
陈前坚 committed
120
  const [tableData, setTableData] = useState([]); // 用户表
121
  const [selectColor, setSelectColor] = useState({}); // 当前选中颜色,操作时设置
陈前坚's avatar
陈前坚 committed
122
  const [orgFilters, setOrgFilters] = useState([]); // 用户列筛选
陈前坚's avatar
陈前坚 committed
123
  const [searchWord, setSearchWord] = useState(''); // 关键字
皮倩雯's avatar
皮倩雯 committed
124
  const [currentSelectOrg1, setCurrentSelectOrg1] = useState('-1');
125
  const [currentSelectOrg, setCurrentSelectOrg] = useState('-1'); // 左侧机构树-选中组织,字符串类型默认全部机构'-1',注意用户表中的OUID是数字
陈前坚's avatar
陈前坚 committed
126
  const [currentSelectOldOrg, setCurrentSelectOldOrg] = useState([]); // 更改机构时的树-原先选中组织
皮倩雯's avatar
皮倩雯 committed
127
  const [showSearchStyle, setShowSearchStyle] = useState(false); // 是否显示模糊查询样式
陈前坚's avatar
陈前坚 committed
128

陈前坚's avatar
陈前坚 committed
129 130 131 132 133
  /** ***Modal弹框,是否可视**** */
  const [userVisible, setUserVisible] = useState(false); // 添加用户
  const [addOrgVisible, setAddOrgVisible] = useState(false); // 添加机构
  const [editOrgVisible, setEditOrgVisible] = useState(false); // 编辑机构
  const [deleteOrgVisible, setDeleteOrgVisible] = useState(false); // 删除机构
mayongxin's avatar
mayongxin committed
134
  const [editOrgExtentVisible, setEditOrgExtentVisible] = useState(false); // 删除机构
陈前坚's avatar
陈前坚 committed
135
  const [roleVisible, setRoleVisible] = useState(false); // 关联角色
陈前坚's avatar
陈前坚 committed
136 137 138
  const [changeOrgVisible, setChangeOrgVisible] = useState(false); // 更改机构
  const [passwordVisible, setPasswordVisible] = useState(false); // 修改密码
  const [editUserVisible, setEditUserVisible] = useState(false); // 编辑用户
皮倩雯's avatar
皮倩雯 committed
139
  // const [freezeUserVisible, setFreezeUserVisible] = useState(false); // 冻结用户
陈前坚's avatar
陈前坚 committed
140
  const [deleteUserVisible, setDeleteUserVisible] = useState(false); // 删除用户
mayongxin's avatar
mayongxin committed
141
  const [authUserVisible, setAuthUserVisible] = useState(false); // 鉴权用户
陈前坚's avatar
陈前坚 committed
142

陈前坚's avatar
陈前坚 committed
143
  const [orgTitle, setOrgTitle] = useState('当前机构'); // 弹框标题
皮倩雯's avatar
皮倩雯 committed
144
  const [orgTitle1, setOrgTitle1] = useState('当前机构'); // 弹框标题
145
  const [description, setDescription] = useState(''); // 机构描述信息
146 147
  const [selectedRowKeys, setSelectedRowKeys] = useState([]); // 已选用户数,机构改变时重置
  const [tableLength, setTableLength] = useState(0); // 当前机构用户总数
陈前坚's avatar
陈前坚 committed
148
  const [orgID, setOrgID] = useState(); // 当前选择的机构ID
陈前坚's avatar
陈前坚 committed
149 150
  const [newOrgID, setNewOrgID] = useState(); // 更改机构新选择的ID
  const [currentUser, setCurrentUser] = useState({}); // 当前用户
151

皮倩雯's avatar
皮倩雯 committed
152 153 154
  const [mult, setMult] = useState(''); // 判断是否是批量关联
  const [multiRoleList, setMultiRoleList] = useState([]);
  const [multistationList, setMultiStationList] = useState([]);
陈前坚's avatar
陈前坚 committed
155 156 157 158
  const [userIDs, setUserIDs] = useState(''); // 批量删除的用户
  const [orgIDs, setOrgIDs] = useState(''); // 批量操作的机构
  const [multiDelete, setMultiDelete] = useState(false); // 是否批量删除用户
  const [multiChangeOrgs, setMultiChangeOrgs] = useState(false); // 是否批量更改机构
陈前坚's avatar
陈前坚 committed
159
  const [multiRelateRoles, setMultiRelateRoles] = useState(false); // 是否批量更改机构
陈前坚's avatar
陈前坚 committed
160

陈前坚's avatar
陈前坚 committed
161 162
  const [rolelist, setRolelist] = useState([]); // 角色列表
  const [stationlist, setStationlist] = useState([]); // 站点列表
mayongxin's avatar
mayongxin committed
163

皮倩雯's avatar
皮倩雯 committed
164 165 166 167
  const [orgAreas, setOrgAreas] = useState([]);
  const [currentOrgArea, setCurrentOrgArea] = useState('');
  const [currentOrgDistinct, setCurrentOrgDistinct] = useState('');
  const [saveExtentFlag, setSaveExtentFlag] = useState(0);
皮倩雯's avatar
皮倩雯 committed
168
  const [filteredValue, setFilteredValue] = useState([]);
皮倩雯's avatar
皮倩雯 committed
169 170
  const [keep1, setKeep1] = useState([4]); // 存储树选择
  const [id, setId] = useState('');
陈前坚's avatar
陈前坚 committed
171
  const { Search } = Input;
172
  const [hoverItemIndex, setHoverItemIndex] = useState(0); // hover流程索引
173
  const [keepTree, setKeepTree] = useState([]); // 保存所有一级id用于控制只展开一项一级菜单
174 175

  const [expendKey, setExpendKey] = useState(''); // 保存默认展开项
176
  const [expendKeyOrg, setExpendKeyOrg] = useState(''); // 保存默认展开项
177 178
  const [menuID, setMenuID] = useState(''); // 选中的树IDs
  const [flag, setFlag] = useState(1); // 刷新标志
179 180
  const userContainer = useRef();
  const flagRef = useRef(1);
181 182

  const [searchWordOrg, setSearchWordOrg] = useState('');
183
  const [keepDataList, setKeepDataList] = useState([]);
184
  const [siteList, setSiteList] = useState([]);
皮倩雯's avatar
皮倩雯 committed
185
  const [searchFlag, setSearchFlag] = useState(0);
186
  const setRowClassName = record =>
187
    record.userId === selectColor.userId ? styles.clickRowStyle : '';
188

189 190 191 192 193 194
  const [demoVisivle, setDemoVisible] = useState(false);
  const [searchTreeValue, setSearchTreeValue] = useState('');

  const [total, setTotal] = useState(0);
  const [pageSize, setPageSize] = useState(20);
  const [currentPage, setCurrentPage] = useState(1);
195
  const [treeDataTotal, setTreeDataTotal] = useState();
皮倩雯's avatar
皮倩雯 committed
196
  const [totalSearch, setTotalSearch] = useState(0);
197 198 199 200 201
  const [importAccountVisible, setImportAccountVisible] = useState(false);
  const [passwordLevel, setPasswordLevel] = useState(''); // 密码等级
  const [rules, setRules] = useState();
  const [btnDisabled, setBtnDisabled] = useState(true);
  const [pasType, setPasType] = useState('');
202 203
  const [file, setFile] = useState(''); // 上传文件信息
  const [alertTxt, setAlertTxt] = useState(''); // 上传文件信息
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
  const [importUserForm] = Form.useForm(); // 添加用户

  const getPasswordRule = () => {
    GetPasswordRegularization().then(res => {
      if (res.code === 0) {
        setRules(res.data);
      }
    });
  };

  const passwordType = () => {
    SysConfiguration().then(res => {
      if (res.code === 0) {
        setPasType(res.data);
      }
    });
  };

  // 密码强度验证
  const changeValue = changedFields => {
    if (changedFields[0].name[0] === 'password') {
      // console.log(changedFields[0].value);
      checkStrong(changedFields[0].value);
      const regex = /^(?=.*[a-zA-Z])(?=.*\d)[\w]{6,16}$/; // 调整后的正则表达式,不包含空白字符
      console.log(regex.test(changedFields[0].value), 'regex.test(changedFields[0].value')

      if (regex.test(changedFields[0].value)) {
        setBtnDisabled(false)
      } else {
        setBtnDisabled(true)
      }
      // console.log(checkStrong(changedFields[0].value));
    }
  };
  const checkStrong = sValue => {
    let modes = 0;
    // 正则表达式验证符合要求的
    if (sValue.length < 1) return modes;
    if (/\d/.test(sValue)) modes++; // 数字
    if (/[a-z]/.test(sValue)) modes++; // 小写
    if (/[A-Z]/.test(sValue)) modes++; // 大写
    if (/[_\W]/.test(sValue)) modes++; // 特殊字符
    console.log(modes, 'modes');
    // 逻辑处理
    // eslint-disable-next-line default-case
    switch (modes) {
      case 1:
        setPasswordLevel('弱');
        break;
      case 2:
        if (sValue.length > 8) {
          setPasswordLevel('中');
        } else {
          setPasswordLevel('弱');
        }
        break;
      case 3:
        if (sValue.length > 8) {
          setPasswordLevel('强');
        } else {
          setPasswordLevel('中');
        }
        break;
      case 4:
        setPasswordLevel('强');
        break;
    }
  };
陈前坚's avatar
陈前坚 committed
272 273 274 275 276 277
  // 用户表列名
  const columns = [
    {
      title: '登录名',
      dataIndex: 'loginName',
      key: 'loginName',
皮倩雯's avatar
皮倩雯 committed
278
      render: item => searchStyle(item),
陈前坚's avatar
陈前坚 committed
279 280 281 282 283
    },
    {
      title: '用户姓名',
      dataIndex: 'userName',
      key: 'userName',
皮倩雯's avatar
皮倩雯 committed
284
      render: item => searchStyle(item),
陈前坚's avatar
陈前坚 committed
285
    },
286 287
    {
      title: '所在机构',
288 289
      dataIndex: 'groupLevel',
      key: 'groupLevel',
290
      ellipsis: true,
皮倩雯's avatar
皮倩雯 committed
291
      render: (text, record) => {
292 293
        let arr = text?.split('/');
        if (arr?.length > 2) {
294 295 296 297 298 299
          let str = `${arr[0]}/.../${arr[arr.length - 1]}`;
          return (
            <Tooltip title={text}>
              <span>{str}</span>
            </Tooltip>
          );
皮倩雯's avatar
皮倩雯 committed
300 301 302 303 304 305
        } else {
          if (arr) {
            return <span>{text}</span>;
          } else {
            return <span>{record.groupName}</span>;
          }
306 307
        }
      },
308
    },
陈前坚's avatar
陈前坚 committed
309 310 311 312
    {
      title: '手机号码',
      dataIndex: 'phone',
      key: 'phone',
313
      // width: 150,
陈前坚's avatar
陈前坚 committed
314
      ellipsis: true,
皮倩雯's avatar
皮倩雯 committed
315 316 317
      render: text => {
        if (text) {
          return searchStyle(text);
318
        }
tianfen's avatar
tianfen committed
319
        return <span>未绑定</span>;
320
      },
陈前坚's avatar
陈前坚 committed
321
    },
322 323 324 325
    {
      title: '站点权限',
      dataIndex: 'stationCount',
      key: 'stationCount',
326
      width: 100,
327
    },
陈前坚's avatar
陈前坚 committed
328
    {
329 330
      title: '权限设置',
      key: 'action',
331
      width: 200,
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
      align: 'center',
      render: record => (
        <Space size="middle">
          <Tooltip title="关联权限">
            <IdcardOutlined
              onClick={() => relateRole(record)}
              style={{ fontSize: '16px', color: '#1890FF' }}
            />
          </Tooltip>
          <Tooltip title="更改机构">
            <ApartmentOutlined
              onClick={() => changeOrg(record)}
              style={{ fontSize: '16px', color: '#1890FF' }}
            />
          </Tooltip>
          <Tooltip title="设置为主管">
            <Popconfirm
              placement="bottomRight"
              title={
                <p>
                  确定将用户
                  <span className={styles.redText}>{voca.stripTags(record.loginName)}</span>
                  设置为{orgTitle}主管吗?
                </p>
              }
              okText="确认"
              cancelText="取消"
              onConfirm={() => {
360
                SetGroupManager({ groupId: record.groupId, userId: record.userId }).then(res => {
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
                  if (res.code === 0) {
                    // eslint-disable-next-line no-unused-expressions
                    currentSelectOrg === '-1' ? submitSearchUser() : onSelect([currentSelectOrg]);
                  } else {
                    notification.error({
                      message: '设置失败',
                      description: res.msg,
                    });
                  }
                });
              }}
            >
              <UserOutlined
                style={{ fontSize: '16px', color: record.isManager ? '#FAAD14' : '#1890FF' }}
              />
            </Popconfirm>
          </Tooltip>
皮倩雯's avatar
皮倩雯 committed
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414
          <Tooltip title={record.isSendSMS === 0 ? '不接收短信' : '接收短信'}>
            <Popconfirm
              placement="bottomRight"
              title={
                record.isSendSMS === 0 ? (
                  <p>
                    确定设置用户
                    <span className={styles.redText}>{voca.stripTags(record.loginName)}</span>
                    可以接收短信吗?
                  </p>
                ) : (
                  <p>
                    确定设置用户
                    <span className={styles.redText}>{voca.stripTags(record.loginName)}</span>
                    不可接收短信吗?
                  </p>
                )
              }
              okText="确认"
              cancelText="取消"
              onConfirm={() => {
                ChangeSMSState({ userId: record.userId }).then(res => {
                  if (res.code === 0) {
                    currentSelectOrg === '-1' ? submitSearchUser() : onSelect([currentSelectOrg]);
                  } else {
                    notification.error({
                      message: '设置失败',
                      description: res.msg,
                    });
                  }
                });
              }}
            >
              <MessageOutlined
                style={{ fontSize: '16px', color: record.isSendSMS === 0 ? '#e86060' : '#1890FF' }}
              />
            </Popconfirm>
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454
          </Tooltip>
          <Tooltip title={record.whitelist === 0 ? '加入终端白名单' : '取消终端白名单'}>
            <Popconfirm
              placement="bottomRight"
              title={
                record.whitelist === 0 ? (
                  <p>
                    确定用户
                    <span className={styles.redText}>{voca.stripTags(record.loginName)}</span>
                    加入终端白名单吗?
                  </p>
                ) : (
                  <p>
                    确定用户
                    <span className={styles.redText}>{voca.stripTags(record.loginName)}</span>
                    取消加入终端白名单吗?
                  </p>
                )
              }
              okText="确认"
              cancelText="取消"
              onConfirm={() => {
                AddUserAppBindWhiteList({ userId: record.userId, state: !record.whitelist ? 1 : 0 }).then(res => {
                  if (res.code === 0) {
                    currentSelectOrg === '-1' ? submitSearchUser() : onSelect([currentSelectOrg]);
                    notification.success({
                      message: '设置成功',
                      description: res.msg,
                    });
                  } else {
                    notification.error({
                      message: '设置失败',
                      description: res.msg,
                    });
                  }
                });
              }}
            >
              <SafetyOutlined
                style={{ fontSize: '16px', color: record.whitelist === 0 ? '#e86060' : '#1890FF' }}
455
              // style={{ fontSize: '16px', color: '#1890FF' }}
456 457
              />
            </Popconfirm>
皮倩雯's avatar
皮倩雯 committed
458
          </Tooltip>
459 460
        </Space>
      ),
陈前坚's avatar
陈前坚 committed
461 462 463 464
    },
    {
      title: '操作',
      key: 'action',
465
      width: 100,
466
      align: 'center',
陈前坚's avatar
陈前坚 committed
467
      render: record => (
陈前坚's avatar
陈前坚 committed
468
        <Space size="middle">
469
          <Tooltip title="修改密码">
陈前坚's avatar
陈前坚 committed
470
            <UnlockOutlined
陈前坚's avatar
陈前坚 committed
471 472 473
              onClick={() => changePassword(record)}
              style={{ fontSize: '16px', color: '#1890FF' }}
            />
474
          </Tooltip>
475
          {/* <Tooltip title="编辑用户">
476
            <EditTwoTone onClick={() => editUser(record)} style={{ fontSize: '16px' }} />
477
          </Tooltip> */}
皮倩雯's avatar
皮倩雯 committed
478
          {(record.state == 0 || record.state == null) && (
479
            <>
480
              {record.loginName == 'panda' || record.loginName == 'admin' ? (
邓超's avatar
邓超 committed
481
                <StopOutlined style={{ fontSize: '16px', color: '#1890ff' }} disabled />
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
              ) : (
                <Tooltip title="冻结用户">
                  <Popconfirm
                    placement="bottomRight"
                    title={
                      <p>
                        即将冻结用户{' '}
                        <span className={styles.redText}>{voca.stripTags(record.loginName)}</span>
                        ,是否确认冻结?
                      </p>
                    }
                    okText="确认"
                    cancelText="取消"
                    onConfirm={() => freezeUser(record)}
                  >
497
                    <StopOutlined style={{ fontSize: '16px', color: '#1890ff' }} />
498 499 500
                  </Popconfirm>
                </Tooltip>
              )}
501 502
            </>
          )}
皮倩雯's avatar
皮倩雯 committed
503
          {record.state == 1 && (
504
            <>
505
              {console.log(record.state, 'record.state1')}
506
              <Tooltip title="解冻用户">
皮倩雯's avatar
皮倩雯 committed
507 508 509 510
                <Popconfirm
                  placement="bottomRight"
                  title={
                    <p>
511
                      即将解冻用户
512
                      <span className={styles.redText}>{voca.stripTags(record.loginName)}</span>
皮倩雯's avatar
皮倩雯 committed
513 514 515 516 517 518 519
                      ,是否确认解冻?
                    </p>
                  }
                  okText="确认"
                  cancelText="取消"
                  onConfirm={() => freezeUser(record)}
                >
520
                  <StopOutlined style={{ fontSize: '16px', color: '#e86060' }} />
皮倩雯's avatar
皮倩雯 committed
521
                </Popconfirm>
522 523 524
              </Tooltip>
            </>
          )}
525
          {record.loginName == 'panda' || record.loginName == 'admin' ? (
邓超's avatar
邓超 committed
526
            <DeleteOutlined style={{ fontSize: '16px', color: '#e86060' }} disabled />
527
          ) : (
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543
            <Popconfirm
              placement="bottomRight"
              title={
                <p>
                  即将删除用户{' '}
                  <span className={styles.redText}>{voca.stripTags(record.loginName)}</span>
                  ,是否确认删除?
                </p>
              }
              // title={`确认删除用户${currentUser}`}
              okText="确认"
              cancelText="取消"
              onConfirm={() => deleteUser(record)}
            >
              <DeleteOutlined style={{ fontSize: '16px', color: '#e86060' }} />
            </Popconfirm>
544
          )}
陈前坚's avatar
陈前坚 committed
545 546 547 548
        </Space>
      ),
    },
  ];
549 550

  useEffect(() => {
551 552 553
    if (!searchWord) {
      setExpendKey(menuID);
    }
554
  }, [menuID]);
555 556 557
  // 获取用户机构树
  useEffect(() => {
    window.addEventListener('resize', resizeListener);
558 559 560 561 562
    GetAllSite().then(res => {
      if (res.code === 0) {
        setSiteList(res.data.map(item => ({ value: item.GroupId, label: item.GroupName })));
      }
    });
563 564
    getPasswordRule()
    passwordType()
565

566 567 568 569 570 571 572 573 574 575 576 577 578 579 580
    updateTrees();
    return () => {
      window.removeEventListener('resize', resizeListener);
    };
  }, []);

  // 更新获取初始范围
  useEffect(() => {
    getOrgArea().then(res => {
      if (res.msg === 'Ok') {
        console.log(res);
        setOrgAreas(res.Results);
      }
    });
  }, [saveExtentFlag]);
581 582 583 584 585 586 587 588

  useEffect(() => {
    if (!changeOrgVisible) {
      setExpendKeyOrg('');
      setSearchWordOrg('');
      GetOUTreeNew({ keyword: '' })
        .then(newres => {
          if (newres.code === 0) {
589
            let res = newres.data.list;
590 591 592 593 594 595 596 597 598
            setTreeDataCopy(res);
          }
        })
        .catch(err => {
          setTreeLoading(false);
          message.error(err);
        });
    }
  }, [changeOrgVisible]);
599 600 601 602
  const resizeListener = () => {
    flagRef.current += 1;
    setFlag(flagRef.current);
  };
皮倩雯's avatar
皮倩雯 committed
603 604 605 606
  // 模糊查询匹配的样式
  const searchStyle = val => {
    let n;
    if (showSearchStyle) {
607 608 609 610 611 612
      const escapedSearchValue = searchWord.replace(/\\/g, '\\\\');
      const regex = new RegExp(escapedSearchValue, 'g');
      n = val.replace(
        regex,
        `<span style='color:red'>${searchWord}</span>`
      );
皮倩雯's avatar
皮倩雯 committed
613 614 615 616 617
    } else {
      n = val;
    }
    return <div dangerouslySetInnerHTML={{ __html: n }} />;
  };
618 619 620 621
  // 获取搜索框的值
  const handleSearch = e => {
    setSearchWord(e.target.value);
  };
622 623 624 625 626 627 628 629 630 631

  // 获取搜索框的值
  const handleSearchOrg = e => {
    setSearchWordOrg(e.target.value);
  };

  const submitSearch = () => {
    GetOUTreeNew({ keyword: searchWordOrg })
      .then(newres => {
        if (newres.code === 0) {
632
          let res = newres.data.list;
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654
          setTreeDataCopy(res);
          let aa = [];
          res.map(i => {
            if (i.children.length > 0) {
              aa.push(i.id);
            }
            aa = i.id;
          });
          setExpendKeyOrg(aa.toString());
        } else {
          notification.error({
            message: '获取失败',
            // eslint-disable-next-line no-undef
            description: res.message,
          });
        }
      })
      .catch(err => {
        setTreeLoading(false);
        message.error(err);
      });
  };
皮倩雯's avatar
皮倩雯 committed
655
  // 复选框
陈前坚's avatar
陈前坚 committed
656
  const rowSelection = {
657 658 659
    selectedRowKeys,
    onChange: (RowKeys, Rows) => {
      setSelectedRowKeys(RowKeys);
皮倩雯's avatar
皮倩雯 committed
660
      getCheckList(RowKeys);
661
      setUserIDs(RowKeys.toString()); // 数组转字符串,逗号连接
662
      setOrgIDs(Rows.map(item => item.groupId).toString());
陈前坚's avatar
陈前坚 committed
663
      // 选中行数大于0时设置批量操作可行
664
      if (RowKeys.length > 0) {
665
        setSelectColor({});
陈前坚's avatar
陈前坚 committed
666 667 668 669 670 671
        setMultiOperate(false);
        setMultiOperateButtonType('primary');
      } else {
        setMultiOperate(true);
        setMultiOperateButtonType('default');
      }
陈前坚's avatar
陈前坚 committed
672 673
    },
  };
陈前坚's avatar
陈前坚 committed
674 675 676
  // 渲染机构树
  const mapTree = org => {
    const haveChildren = Array.isArray(org.children) && org.children.length > 0;
677 678 679
    const indexsearch = org.text.indexOf(searchTreeValue);
    const beforeStr = org.text.substring(0, indexsearch);
    const afterStr = org.text.slice(indexsearch + searchTreeValue.length);
陈前坚's avatar
陈前坚 committed
680
    return {
皮倩雯's avatar
皮倩雯 committed
681
      title: (
皮倩雯's avatar
皮倩雯 committed
682
        <div className={styles.title1}>
683 684
          <span className={styles.titleText}>
            {org.children.length == 0 ? (
685 686 687 688 689 690 691 692
              <ApartmentOutlined
                style={{
                  fontSize: '14px',
                  color: '#1890FF',
                  verticalAlign: 'middle',
                  marginTop: '-3px',
                }}
              />
693 694 695
            ) : (
              <span />
            )}
696 697 698 699 700 701 702 703 704
            {org.text.includes(searchTreeValue) && searchTreeValue != '' ? (
              <span>
                {beforeStr}
                <span className={styles.titleSearch}>{searchTreeValue}</span>
                {afterStr}
              </span>
            ) : (
              <span>{org.text}</span>
            )}
705
          </span>
706 707 708 709 710 711 712 713 714 715 716 717
          <span
            className={classnames({
              [styles.tip1]: true,
              [styles.listHover]: org === hoverItemIndex,
            })}
            onMouseEnter={() => {
              setHoverItemIndex(org);
            }}
            onMouseLeave={() => {
              setHoverItemIndex('');
            }}
          >
718
            <Tooltip title="添加用户" className={styles.fs1}>
719 720 721 722 723 724 725 726 727 728 729
              <UserAddOutlined
                style={{ marginLeft: 20, lineHeight: '24px' }}
                onClick={e => {
                  e.stopPropagation();
                  addUser();
                }}
                onMouseEnter={e => {
                  setOrgID(org);
                  setOrgTitle1(org.text);
                }}
              />
皮倩雯's avatar
皮倩雯 committed
730
            </Tooltip>
皮倩雯's avatar
皮倩雯 committed
731
            <Dropdown overlay={orgButtonMenu1}>
732
              <EllipsisOutlined
733
                style={{ marginLeft: 10, fontSize: '20px', lineHeight: '24px' }}
734
                onClick={e => e.stopPropagation()}
皮倩雯's avatar
皮倩雯 committed
735 736 737
                onMouseEnter={e => {
                  setOrgID(org);
                  setOrgTitle1(org.text);
738
                  // getMapSetByGroupID(org.id);
皮倩雯's avatar
皮倩雯 committed
739 740 741
                  setCurrentSelectOrg1(org.id);
                  setId(org.text);
                }}
742
              />
皮倩雯's avatar
皮倩雯 committed
743 744 745 746
            </Dropdown>
          </span>
        </div>
      ),
陈前坚's avatar
陈前坚 committed
747 748 749 750 751
      key: org.id,
      // 判断它是否存在子集,若果存在就进行再次进行遍历操作,知道不存在子集便对其他的元素进行操作
      children: haveChildren ? org.children.map(i => mapTree(i)) : [],
    };
  };
752

皮倩雯's avatar
皮倩雯 committed
753 754 755 756 757 758 759 760 761 762
  const mapTree1 = org => {
    const haveChildren = Array.isArray(org.children) && org.children.length > 0;
    return {
      title: org.text,
      key: org.id,
      // 判断它是否存在子集,若果存在就进行再次进行遍历操作,知道不存在子集便对其他的元素进行操作
      children: haveChildren ? org.children.map(i => mapTree1(i)) : [],
    };
  };

陈前坚's avatar
陈前坚 committed
763
  // 重新渲染树
764
  const updateTrees = e => {
陈前坚's avatar
陈前坚 committed
765
    setTreeLoading(true);
766
    GetOUTreeNew({ groupId: -1, keyword: e })
皮倩雯's avatar
皮倩雯 committed
767
      .then(newres => {
768
        setTreeLoading(false);
皮倩雯's avatar
皮倩雯 committed
769
        if (newres.code === 0) {
770 771
          let res = newres.data.list;
          setTreeDataTotal(newres.data.count);
772
          setTreeData(res);
皮倩雯's avatar
皮倩雯 committed
773 774 775 776 777
          let aa = [];
          res.forEach(i => {
            aa.push(i.id);
          });
          setKeepTree(aa);
778

779 780
          // 第一次加载,默认选择第一个组织
          if (treeState) {
皮倩雯's avatar
皮倩雯 committed
781
            onSelect([res[0].id]);
782 783
            setTreeState(false);
          }
陈前坚's avatar
陈前坚 committed
784 785 786 787
        } else {
          setTreeLoading(false);
          notification.error({
            message: '获取失败',
皮倩雯's avatar
皮倩雯 committed
788
            // eslint-disable-next-line no-undef
陈前坚's avatar
陈前坚 committed
789 790
            description: res.message,
          });
陈前坚's avatar
陈前坚 committed
791 792 793
        }
      })
      .catch(err => {
陈前坚's avatar
陈前坚 committed
794
        setTreeLoading(false);
陈前坚's avatar
陈前坚 committed
795 796
        message.error(err);
      });
陈前坚's avatar
陈前坚 committed
797
  };
张烨's avatar
张烨 committed
798

799 800
  const updateTrees1 = e => {
    setTreeLoading(true);
801
    GetOUTreeNew({ groupId: -1 })
802 803
      .then(newres => {
        if (newres.code === 0) {
804 805
          let res = newres.data.list;
          setTreeDataTotal(newres.data.count);
806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831
          console.log(res);
          setTreeLoading(false);
          setTreeData(res);
          setTreeDataCopy(res);
          let aa = [];
          res.forEach(i => {
            aa.push(i.id);
          });
          setKeepTree(aa);
          setMenuID(e.toString());
          setExpendKey(e);
        } else {
          setTreeLoading(false);
          notification.error({
            message: '获取失败',
            // eslint-disable-next-line no-undef
            description: res.message,
          });
        }
      })
      .catch(err => {
        setTreeLoading(false);
        message.error(err);
      });
  };

陈前坚's avatar
陈前坚 committed
832
  // 点击树节点,获取当前机构下所有用户
833
  const onSelect = (props, e, size, index) => {
皮倩雯's avatar
皮倩雯 committed
834
    setSearchFlag(0);
皮倩雯's avatar
皮倩雯 committed
835 836 837 838
    if (e) {
      props[0] = e.node.key;
    } else {
      props[0] = props.toString();
839
    }
皮倩雯's avatar
皮倩雯 committed
840
    setKeep1(props);
陈前坚's avatar
陈前坚 committed
841
    setTableLoading(true);
陈前坚's avatar
陈前坚 committed
842
    if (!props[0]) {
张烨's avatar
张烨 committed
843
      setCurrentSelectOrg(currentSelectOrg);
皮倩雯's avatar
皮倩雯 committed
844
      setCurrentSelectOrg1(currentSelectOrg);
陈前坚's avatar
陈前坚 committed
845
    } else {
张烨's avatar
张烨 committed
846
      setCurrentSelectOrg(props[0]);
皮倩雯's avatar
皮倩雯 committed
847
      setCurrentSelectOrg1(props[0]);
陈前坚's avatar
陈前坚 committed
848
    }
mayongxin's avatar
mayongxin committed
849
    GetMapSetByGroupID({
皮倩雯's avatar
皮倩雯 committed
850 851 852
      groupID: props[0],
    }).then(res => {
      if (res.code === 0) {
皮倩雯's avatar
皮倩雯 committed
853
        if (res.code.MapRange != null) {
854 855 856
          setCurrentOrgArea(res.data.MapRange);
          setCurrentOrgDistinct(res.data.AreeName);
        }
mayongxin's avatar
mayongxin committed
857
      }
皮倩雯's avatar
皮倩雯 committed
858
    });
张烨's avatar
张烨 committed
859
    setOrgID(props[0] || currentSelectOrg);
陈前坚's avatar
陈前坚 committed
860 861
    // 树节点变化(即props不为空)时才请求,避免重复请求
    if (props[0]) {
862
      setMenuID(props[0]);
皮倩雯's avatar
皮倩雯 committed
863
      // eslint-disable-next-line no-console
864 865 866 867 868
      let sizedata = '';
      let currentData = '';
      if (currentSelectOrg !== props[0]) {
        setPageSize(20);
        setCurrentPage(1);
869 870
        sizedata = size || 20;
        currentData = index || 1;
871 872
      } else {
        // 分页查询
873 874
        sizedata = size || pageSize;
        currentData = index || currentPage;
875 876 877
      }

      getOneOUUserListNew(props[0] || currentSelectOrg, sizedata, currentData)
陈前坚's avatar
陈前坚 committed
878
        .then(res => {
879
          setCurrentOrgOperate(false); // 重置禁用当前机构操作为false
880
          setMultiOperate(true); // 重新禁止用户批量操作
881
          setSelectedRowKeys([]); // 重置选中用户数
陈前坚's avatar
陈前坚 committed
882
          if (res.code === 0) {
883
            setTotal(res.data.count);
陈前坚's avatar
陈前坚 committed
884 885 886 887
            setTableLoading(false);
            setSearchWord(''); // 搜索框置空
            setOrgTitle(res.data.GroupName);
            // 返回用户表数据结构处理,扁平化
888
            let temp = res.data.data;
陈前坚's avatar
陈前坚 committed
889
            // 设置过滤字段
890
            let arr = temp.map(item => item.groupName);
陈前坚's avatar
陈前坚 committed
891 892 893
            arr = arr.filter((value, index) => arr.indexOf(value) === index);
            setOrgFilters(arr.map(item => ({ text: item, value: item })));
            setTableLength(temp.length);
894
            let datalist = [];
陈前坚's avatar
陈前坚 committed
895
            const table = temp.map((item, index) => {
896
              if (item.loginName == 'panda' || item.loginName == 'admin') {
897
                datalist.push(item.userId);
898
              }
陈前坚's avatar
陈前坚 committed
899 900 901
              item.key = index;
              return item;
            });
902
            setKeepDataList(datalist);
皮倩雯's avatar
皮倩雯 committed
903
            setShowSearchStyle(false);
904
            console.log(table);
陈前坚's avatar
陈前坚 committed
905 906 907
            setTableData(table);
          } else {
            setTableLoading(false);
皮倩雯's avatar
皮倩雯 committed
908 909 910 911
            // notification.error({
            //   message: '获取失败',
            //   description: res.msg,
            // });
陈前坚's avatar
陈前坚 committed
912 913 914
          }
        })
        .catch(err => {
陈前坚's avatar
陈前坚 committed
915
          setTableLoading(false);
陈前坚's avatar
陈前坚 committed
916 917 918 919 920
          message.error(err);
        });
    } else {
      setTableLoading(false);
    }
陈前坚's avatar
陈前坚 committed
921
  };
陈前坚's avatar
陈前坚 committed
922

陈前坚's avatar
陈前坚 committed
923
  // 添加用户
924
  const addUser = e => {
陈前坚's avatar
陈前坚 committed
925 926
    setUserVisible(true);
  };
陈前坚's avatar
陈前坚 committed
927 928
  // 添加顶级机构
  const addOrg = () => {
陈前坚's avatar
陈前坚 committed
929
    setAddOrgVisible(true);
陈前坚's avatar
陈前坚 committed
930
    setOrgID('-1');
陈前坚's avatar
陈前坚 committed
931
  };
陈前坚's avatar
陈前坚 committed
932
  // 添加下级机构
933
  const addSubOrg = e => {
陈前坚's avatar
陈前坚 committed
934 935 936 937
    setAddOrgVisible(true);
  };
  // 编辑机构
  const editOrg = () => {
陈前坚's avatar
陈前坚 committed
938
    setEditOrgVisible(true);
陈前坚's avatar
陈前坚 committed
939
  };
陈前坚's avatar
陈前坚 committed
940 941
  // 删除机构
  const deleteOrg = () => {
陈前坚's avatar
陈前坚 committed
942
    setDeleteOrgVisible(true);
943 944 945 946 947
    if (orgID.id == keep1) {
      setTreeState(true);
    } else {
      setTreeState(false);
    }
陈前坚's avatar
陈前坚 committed
948
  };
陈前坚's avatar
陈前坚 committed
949

950 951
  /** ***其他操作*** */
  // 导出用户
952
  const exportRoles = async (data) => {
953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972
    if(data.isModal){
      let downloadLink = document.createElement('a');
      downloadLink.href = path.join(__dirname, `/civmanage/用户导出模板.xls`);
      downloadLink.download = '用户导出模板.xls';
  
      document.body.appendChild(downloadLink);
      downloadLink.click();
  
      document.body.removeChild(downloadLink);
    } else {
      ExportUserData({
        groupId: data.all ? 0 : menuID ? menuID : 0,
        key: data.all ? '' : searchWord,
        isModel: data.isModal ? true : false,
      }).then(res => {
        // window.open(`http:192.168.10.167:8088/${res.data}`)
        window.open(`${window.origin}/${res.data}`)
        console.log(res, 'resssssssssssssssssss');
      })
    }
973 974 975 976 977 978 979 980
  }

  // 导入用户
  const importRoles = () => {
    console.log('66666666666666666');
    setImportAccountVisible(true)
  }

陈前坚's avatar
陈前坚 committed
981
  /** ***用户批量操作****** */
陈前坚's avatar
陈前坚 committed
982
  // 关联角色
陈前坚's avatar
陈前坚 committed
983
  const relateRoles = () => {
皮倩雯's avatar
皮倩雯 committed
984
    setMult('Yes');
陈前坚's avatar
陈前坚 committed
985
    getEmptyRoleList();
986
    // getCheckList()
陈前坚's avatar
陈前坚 committed
987
    setRoleVisible(true);
陈前坚's avatar
陈前坚 committed
988
    setMultiRelateRoles(true);
陈前坚's avatar
陈前坚 committed
989
  };
990
  // 批量更改机构
陈前坚's avatar
陈前坚 committed
991 992 993 994 995 996 997 998 999 1000
  const changeOrgs = () => {
    setChangeOrgVisible(true);
    setMultiChangeOrgs(true);
  };
  // 删除用户
  const deleteUsers = () => {
    setDeleteUserVisible(true);
    setMultiDelete(true);
  };

陈前坚's avatar
陈前坚 committed
1001
  /** ***右侧表格相关操作****** */
陈前坚's avatar
陈前坚 committed
1002
  // 关联角色
陈前坚's avatar
陈前坚 committed
1003
  const relateRole = record => {
1004
    // getEmptyRoleList(record.userId);
皮倩雯's avatar
皮倩雯 committed
1005 1006
    setMult('No');
    getRoleList(record);
陈前坚's avatar
陈前坚 committed
1007
    setRoleVisible(true);
张烨's avatar
张烨 committed
1008
    setCurrentUser(record);
1009
    setSelectColor(record);
陈前坚's avatar
陈前坚 committed
1010
  };
陈前坚's avatar
陈前坚 committed
1011
  // 更改机构
陈前坚's avatar
陈前坚 committed
1012
  const changeOrg = record => {
1013
    setChangeOrgVisible(true);
1014
    setMultiChangeOrgs(false);
张烨's avatar
张烨 committed
1015
    setCurrentUser(record);
1016
    setSelectColor(record);
1017
    setCurrentSelectOldOrg(record.groupId);
陈前坚's avatar
陈前坚 committed
1018
  };
陈前坚's avatar
陈前坚 committed
1019
  // 修改密码
陈前坚's avatar
陈前坚 committed
1020 1021
  const changePassword = record => {
    setPasswordVisible(true);
张烨's avatar
张烨 committed
1022
    setCurrentUser(record);
1023
    setSelectColor(record);
陈前坚's avatar
陈前坚 committed
1024
  };
陈前坚's avatar
陈前坚 committed
1025
  // 编辑用户
陈前坚's avatar
陈前坚 committed
1026 1027
  const editUser = record => {
    setEditUserVisible(true);
张烨's avatar
张烨 committed
1028
    setCurrentUser(record);
1029
    setSelectColor(record);
陈前坚's avatar
陈前坚 committed
1030
  };
陈前坚's avatar
陈前坚 committed
1031
  // 冻结用户
陈前坚's avatar
陈前坚 committed
1032
  const freezeUser = record => {
皮倩雯's avatar
皮倩雯 committed
1033
    // setFreezeUserVisible(true);
张烨's avatar
张烨 committed
1034
    setCurrentUser(record);
1035
    setSelectColor(record);
皮倩雯's avatar
皮倩雯 committed
1036 1037 1038 1039 1040 1041
    let state = '';
    if (record.state === '0' || record.state === null) {
      state = '1';
    } else {
      state = '0';
    }
1042
    UserStateOUNew({ ouid: record.userId })
皮倩雯's avatar
皮倩雯 committed
1043 1044 1045 1046
      .then(res => {
        if (res.code === 0) {
          // 重新获取用户表
          // eslint-disable-next-line no-unused-expressions
1047
          currentSelectOrg === '-1' ? submitSearchUser() : onSelect([currentSelectOrg]);
皮倩雯's avatar
皮倩雯 committed
1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062
          notification.success({
            message: '提交成功',
            duration: 2,
          });
        } else {
          notification.error({
            message: '提交失败',
            description: res.msg,
          });
        }
      })
      .catch(err => {
        setTableLoading(false);
        message.error(err);
      });
陈前坚's avatar
陈前坚 committed
1063
  };
陈前坚's avatar
陈前坚 committed
1064
  // 删除用户
陈前坚's avatar
陈前坚 committed
1065
  const deleteUser = record => {
皮倩雯's avatar
皮倩雯 committed
1066
    setCurrentUser(record.userName);
1067
    setSelectColor(record);
皮倩雯's avatar
皮倩雯 committed
1068
    DeleteUserNew({
1069
      userId: record.userId,
皮倩雯's avatar
皮倩雯 committed
1070 1071 1072 1073 1074 1075 1076 1077
    })
      .then(res => {
        if (res.code === 0) {
          notification.success({
            message: '提交成功',
            duration: 2,
          });
          // eslint-disable-next-line no-unused-expressions
1078
          currentSelectOrg === '-1' ? submitSearchUser() : onSelect([currentSelectOrg]);
皮倩雯's avatar
皮倩雯 committed
1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089
        } else {
          notification.error({
            message: '提交失败',
            description: res.msg,
          });
        }
      })
      .catch(err => {
        setTableLoading(false);
        message.error(err);
      });
陈前坚's avatar
陈前坚 committed
1090
  };
1091

陈前坚's avatar
陈前坚 committed
1092
  // 查找用户
1093 1094 1095 1096
  const submitSearchUser = (size, current) => {
    setMenuID('');
    if (!current) {
      setCurrentPage(1);
1097
    }
1098

1099
    setTableLoading(true);
1100 1101 1102 1103 1104 1105
    let data = current ? current : 1;
    let newSize = size ? size : 20;
    if (!searchWord) {
      setMenuID(treeDataCopy[0].id);
    }
    getOneOUUserListNew(0, newSize, data, searchWord)
陈前坚's avatar
陈前坚 committed
1106
      .then(res => {
皮倩雯's avatar
皮倩雯 committed
1107
        setSearchFlag(1);
1108
        setTableLoading(false);
皮倩雯's avatar
皮倩雯 committed
1109
        if (res.code === 0) {
1110
          setTotal(res.data.count);
1111
          setSelectedRowKeys([]); // 重置选中用户数
1112
          setCurrentOrgOperate(true); // 禁止当前机构操作
1113
          setMultiOperate(true); // 禁用批量操作
1114
          setOrgTitle('全部机构搜索结果'); // 设置表头
1115
          setCurrentSelectOrg('-1'); // 清空选中机构
皮倩雯's avatar
皮倩雯 committed
1116
          setShowSearchStyle(true);
1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135

          // 返回用户表数据结构处理,扁平化
          let temp = res.data.data;
          // 设置过滤字段
          let arr = temp.map(item => item.groupName);
          arr = arr.filter((value, index) => arr.indexOf(value) === index);
          setOrgFilters(arr.map(item => ({ text: item, value: item })));
          setTableLength(temp.length);
          let datalist = [];
          const table = temp.map((item, index) => {
            if (item.loginName == 'panda' || item.loginName == 'admin') {
              datalist.push(item.userId);
            }
            item.key = index;
            return item;
          });
          setKeepDataList(datalist);

          setTableData(table);
陈前坚's avatar
陈前坚 committed
1136
        } else {
1137
          setTableLoading(false);
陈前坚's avatar
陈前坚 committed
1138
          notification.error({
1139
            message: '获取失败',
皮倩雯's avatar
皮倩雯 committed
1140
            description: res.msg,
陈前坚's avatar
陈前坚 committed
1141 1142 1143 1144
          });
        }
      })
      .catch(err => {
1145
        setTableLoading(false);
陈前坚's avatar
陈前坚 committed
1146 1147 1148
        message.error(err);
      });
  };
张烨's avatar
张烨 committed
1149

陈前坚's avatar
陈前坚 committed
1150
  /** ***表单提交相关操作****** */
1151
  // 根据当前 userId 获取用户关联角色
1152
  const getRoleList = e => {
1153
    setLoading(true);
1154
    GetUserRelationListNew({ userId: e.userId })
陈前坚's avatar
陈前坚 committed
1155
      .then(res => {
皮倩雯's avatar
皮倩雯 committed
1156
        if (res.code === 0) {
mayongxin's avatar
mayongxin committed
1157
          const { roleList, stationList } = res.data;
1158 1159
          setRolelist(roleList);
          setStationlist(stationList);
1160
          setLoading(false);
陈前坚's avatar
陈前坚 committed
1161
        } else {
1162
          setLoading(false);
陈前坚's avatar
陈前坚 committed
1163 1164 1165
        }
      })
      .catch(err => {
1166
        setLoading(false);
陈前坚's avatar
陈前坚 committed
1167 1168 1169 1170
        setTableLoading(false);
        message.error(err);
      });
  };
陈前坚's avatar
陈前坚 committed
1171 1172 1173
  // 获取全部未勾选的角色列表与站点列表
  const getEmptyRoleList = () => {
    setLoading(true);
1174
    GetUserRelationListNew({ userId: 0 })
陈前坚's avatar
陈前坚 committed
1175
      .then(res => {
皮倩雯's avatar
皮倩雯 committed
1176
        if (res.code === 0) {
mayongxin's avatar
mayongxin committed
1177
          const { roleList, stationList } = res.data;
陈前坚's avatar
陈前坚 committed
1178 1179
          setRolelist(roleList);
          setStationlist(stationList);
1180
          setLoading(false);
陈前坚's avatar
陈前坚 committed
1181
        } else {
1182
          setLoading(false);
陈前坚's avatar
陈前坚 committed
1183 1184 1185 1186 1187 1188 1189 1190
        }
      })
      .catch(err => {
        setLoading(false);
        setTableLoading(false);
        message.error(err);
      });
  };
1191

皮倩雯's avatar
皮倩雯 committed
1192 1193 1194 1195 1196 1197 1198 1199 1200 1201
  const getCheckList = e => {
    let aa = [];
    let bb = [];
    loadAllUserRole(e).then(res => {
      if (res.code === 0) {
        if (res.data.roleList !== undefined) {
          // eslint-disable-next-line array-callback-return
          Object.keys(res.data.roleList).map((item, index) => {
            aa.push(item);
          });
1202
        }
皮倩雯's avatar
皮倩雯 committed
1203 1204 1205 1206 1207
        if (res.data.siteList !== undefined) {
          // eslint-disable-next-line array-callback-return
          Object.keys(res.data.siteList).map((item1, index1) => {
            bb.push(item1);
          });
1208
        }
皮倩雯's avatar
皮倩雯 committed
1209 1210
        setMultiRoleList(aa);
        setMultiStationList(bb);
1211
      }
皮倩雯's avatar
皮倩雯 committed
1212 1213
    });
  };
陈前坚's avatar
陈前坚 committed
1214
  // 提交-更改机构
皮倩雯's avatar
皮倩雯 committed
1215
  const submitChangeOrg = () => {
1216
    // addToOrg(currentUser.userId, currentUser.OUID, newOrgID)
mayongxin's avatar
mayongxin committed
1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237
    // .then(res => {
    //   if (res.success) {
    //     setChangeOrgVisible(false);
    //     // 跳转到新组织机构下的用户表
    //     onSelect([newOrgID]);
    //     // setExpandedKeys([`${newOrgID}`]);
    //     notification.success({
    //       message: '提交成功',
    //       duration: 2,
    //     });
    //   } else {
    //     notification.error({
    //       message: '提交失败',
    //       description: res.message,
    //     });
    //   }
    // })
    // .catch(err => {
    //   message.error(err);
    // });
    JumpToAnotherOUNew({
1238 1239
      userId: currentUser.userId,
      oldOUID: currentUser.groupId,
皮倩雯's avatar
皮倩雯 committed
1240
      newOUID: newOrgID,
mayongxin's avatar
mayongxin committed
1241
    })
陈前坚's avatar
陈前坚 committed
1242
      .then(res => {
陈前坚's avatar
陈前坚 committed
1243 1244 1245 1246
        if (res.code === 0) {
          setChangeOrgVisible(false);
          // 跳转到新组织机构下的用户表
          onSelect([newOrgID]);
皮倩雯's avatar
皮倩雯 committed
1247
          // setExpandedKeys([`${newOrgID}`]);
陈前坚's avatar
陈前坚 committed
1248 1249
          notification.success({
            message: '提交成功',
1250
            duration: 2,
陈前坚's avatar
陈前坚 committed
1251 1252 1253 1254
          });
        } else {
          notification.error({
            message: '提交失败',
陈前坚's avatar
陈前坚 committed
1255
            description: res.msg,
陈前坚's avatar
陈前坚 committed
1256 1257 1258 1259 1260 1261
          });
        }
      })
      .catch(err => {
        message.error(err);
      });
皮倩雯's avatar
皮倩雯 committed
1262
  };
1263

皮倩雯's avatar
皮倩雯 committed
1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274
  // 提交-批量更改机构
  const submitChangeOrgs = () =>
    addToOrgs(userIDs, orgIDs, newOrgID)
      .then(res => {
        if (res.code === 0) {
          setChangeOrgVisible(false);
          // 跳转到新组织机构下的用户表
          const temp = orgIDs.split(',');
          // 批量更改机构成功后设置老的orgIDs为全部是newOrgID的数组,并转字符串
          setOrgIDs(temp.map(() => newOrgID).toString());
          onSelect([newOrgID]);
陈前坚's avatar
陈前坚 committed
1275 1276
          notification.success({
            message: '提交成功',
1277
            duration: 2,
陈前坚's avatar
陈前坚 committed
1278 1279 1280 1281
          });
        } else {
          notification.error({
            message: '提交失败',
mayongxin's avatar
mayongxin committed
1282
            description: res.msg,
陈前坚's avatar
陈前坚 committed
1283 1284 1285 1286 1287 1288
          });
        }
      })
      .catch(err => {
        message.error(err);
      });
皮倩雯's avatar
皮倩雯 committed
1289 1290 1291 1292 1293 1294 1295 1296 1297

  // 提交-冻结用户
  // const submitFreezeUser = () => {
  //   let state = '';
  //   if (currentUser.state === '0' || currentUser.state === null) {
  //     state = '1';
  //   } else {
  //     state = '0';
  //   }
1298
  //   // postSetUserState(currentUser.userId, state)
皮倩雯's avatar
皮倩雯 committed
1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321
  //   //   .then(res => {
  //   //     if (res.success) {
  //   //       setFreezeUserVisible(false);
  //   //       // 重新获取用户表
  //   //       // eslint-disable-next-line no-unused-expressions
  //   //       currentSelectOrg === '-1'
  //   //         ? submitSearchUser()
  //   //         : onSelect([currentSelectOrg]);
  //   //       notification.success({
  //   //         message: '提交成功',
  //   //         duration: 2,
  //   //       });
  //   //     } else {
  //   //       notification.error({
  //   //         message: '提交失败',
  //   //         description: res.message,
  //   //       });
  //   //     }
  //   //   })
  //   //   .catch(err => {
  //   //     setTableLoading(false);
  //   //     message.error(err);
  //   //   });
1322
  //   UserStateOUNew({ ouid: currentUser.userId, state })
皮倩雯's avatar
皮倩雯 committed
1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346
  //     .then(res => {
  //       if (res.code === 0) {
  //         // setFreezeUserVisible(false);
  //         // 重新获取用户表
  //         // eslint-disable-next-line no-unused-expressions
  //         currentSelectOrg === '-1'
  //           ? submitSearchUser()
  //           : onSelect([currentSelectOrg]);
  //         notification.success({
  //           message: '提交成功',
  //           duration: 2,
  //         });
  //       } else {
  //         notification.error({
  //           message: '提交失败',
  //           description: res.msg,
  //         });
  //       }
  //     })
  //     .catch(err => {
  //       setTableLoading(false);
  //       message.error(err);
  //     });
  // };
陈前坚's avatar
陈前坚 committed
1347
  // 提交-删除用户
陈前坚's avatar
陈前坚 committed
1348
  const submitDeleteUser = () => {
皮倩雯's avatar
皮倩雯 committed
1349
    DeleteUserNew({
1350
      userId: currentUser.userId,
皮倩雯's avatar
皮倩雯 committed
1351 1352 1353
    })
      .then(res => {
        if (res.code === 0) {
陈前坚's avatar
陈前坚 committed
1354 1355
          notification.success({
            message: '提交成功',
1356
            duration: 2,
陈前坚's avatar
陈前坚 committed
1357
          });
1358
          // eslint-disable-next-line no-unused-expressions
1359
          currentSelectOrg === '-1' ? submitSearchUser() : onSelect([currentSelectOrg]);
陈前坚's avatar
陈前坚 committed
1360 1361 1362
        } else {
          notification.error({
            message: '提交失败',
mayongxin's avatar
mayongxin committed
1363
            description: res.msg,
陈前坚's avatar
陈前坚 committed
1364 1365 1366 1367 1368 1369 1370 1371 1372 1373
          });
        }
      })
      .catch(err => {
        setTableLoading(false);
        message.error(err);
      });
  };
  // 提交-批量删除用户
  const submitDeleteUsers = () => {
1374 1375 1376 1377 1378 1379
    let data = [];
    keepDataList.length > 0 &&
      keepDataList.map(i => {
        let aa = userIDs.split(',').indexOf(i);
        if (aa !== -1) {
          data.push(aa);
陈前坚's avatar
陈前坚 committed
1380 1381
        }
      });
1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410
    if (data.length > 0) {
      notification.error({
        message: '操作失败',
        description: '选中项包含不可删除的用户pandaadmin',
      });
    } else {
      multiDeleteUsers(userIDs)
        .then(res => {
          if (res.code === 0) {
            setDeleteUserVisible(false);
            notification.success({
              message: '提交成功',
              duration: 2,
            });
            // 重新获取用户表,查找用户时currentSelectOrg为'-1',无需跳转
            // eslint-disable-next-line no-unused-expressions
            currentSelectOrg === '-1' ? submitSearchUser() : onSelect([currentSelectOrg]);
          } else {
            notification.error({
              message: '提交失败',
              description: res.msg,
            });
          }
        })
        .catch(err => {
          setTableLoading(false);
          message.error(err);
        });
    }
陈前坚's avatar
陈前坚 committed
1411
  };
1412
  // 重置默认第一个
1413
  const handleReset = () => {
1414
    GetOUTreeNew({ groupId: -1 })
1415 1416
      .then(newres => {
        if (newres.code === 0) {
1417
          let res = newres.data.list;
1418
          setTreeLoading(false);
皮倩雯's avatar
皮倩雯 committed
1419
          setSearchFlag(0);
1420
          setSearchWord('');
皮倩雯's avatar
皮倩雯 committed
1421
          setFilteredValue([]);
1422
          // 第一次加载,默认选择第一个组织
1423
          onSelect([res[0].id], false);
1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436
        } else {
          setTreeLoading(false);
          notification.error({
            message: '获取失败',
            // eslint-disable-next-line no-undef
            description: res.message,
          });
        }
      })
      .catch(err => {
        setTreeLoading(false);
        message.error(err);
      });
1437
  };
皮倩雯's avatar
皮倩雯 committed
1438
  const onChangeInput = filters => {
1439
    setFilteredValue(filters.OUName);
皮倩雯's avatar
皮倩雯 committed
1440
  };
1441

皮倩雯's avatar
皮倩雯 committed
1442
  // 更改机构范围
1443
  const submitExtent = (extent, areaName, flags) => {
皮倩雯's avatar
皮倩雯 committed
1444
    setTreeLoading(true);
1445
    if (flags === 0) {
1446 1447 1448 1449
      setTreeLoading(false);
      notification.warn({
        message: '提交失败',
        description: '请框选范围',
皮倩雯's avatar
皮倩雯 committed
1450
      });
皮倩雯's avatar
皮倩雯 committed
1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467
    } else if (extent) {
      setOrgArea({
        OUID: currentSelectOrg1,
        areaName,
        extent,
      }).then(res => {
        if (res.msg === '') {
          setTreeLoading(false);
          setEditOrgExtentVisible(false);
          setSaveExtentFlag(saveExtentFlag + 1);
          message.success('机构范围设置成功!');
        } else {
          setTreeLoading(false);
          setEditOrgExtentVisible(false);
          message.warn(res.Message);
        }
      });
mayongxin's avatar
mayongxin committed
1468
    }
皮倩雯's avatar
皮倩雯 committed
1469
  };
1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485
  // 返回拖拽完毕后的信息
  const loop = (datas, key, parentID, callback) => {
    for (let i = 0; i < datas.length; i++) {
      if (datas[i].id === key) {
        return callback(datas[i], i, datas, parentID);
      }
      if (datas[i].children) {
        loop(datas[i].children, key, datas[i].id, callback);
      }
    }
  };
  // 树的拖拽
  const handleDrop = infos => {
    const dropKey = infos.node.key;
    const dragKey = infos.dragNode.key;
    const dropPos = infos.node.pos.split('-');
1486
    const dropPosition = infos.dropPosition - Number(dropPos[dropPos.length - 1]);
陈前坚's avatar
陈前坚 committed
1487

1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537
    const datas = JSON.parse(JSON.stringify(treeData));
    // 找到拖拽的元素
    let dragObj;
    let dropObj;
    let parId;
    let dragList;
    // 保存拖拽到的节点信息
    loop(datas, dropKey, -1, item => {
      dropObj = item;
    });
    // 保存节点信息并删除节点
    loop(datas, dragKey, -1, (item, index, arr) => {
      arr.splice(index, 1);
      dragObj = item;
    });
    // 将节点插入到正确的位置
    if (!infos.dropToGap) {
      dropObj.children = dropObj.children || [];
      // 在哪里插入,示例添加到头部,可以是随意位置
      dropObj.children.unshift(dragObj);
      parId = dropObj.id;
      dragList = dropObj.children.map(val => val.id);
    } else {
      let ar;
      let i;
      loop(datas, dropKey, -1, (item, index, arr, parentID) => {
        ar = arr;
        i = index;
        parId = parentID;
      });
      if (dropPosition === -1) {
        ar.splice(i, 0, dragObj);
      } else {
        ar.splice(i + 1, 0, dragObj);
      }
      dragList = ar.map(ele => ele.id);
    }
    DragGroup({
      dragGroupType: 2,
      groupId: dragKey.toString(),
      groupList: dragList.map(item => item.toString()),
      parentId: parId.toString(),
    }).then(res => {
      if (res.code === 0) {
        updateTrees();
      } else {
        message.error(res.msg);
      }
    });
  };
皮倩雯's avatar
皮倩雯 committed
1538 1539 1540
  const addChange = e => {
    e.domEvent.stopPropagation();
  };
1541

陈前坚's avatar
陈前坚 committed
1542 1543 1544
  /** ***操作按钮**** */
  // 机构操作
  const orgButtonMenu = (
皮倩雯's avatar
皮倩雯 committed
1545
    <Menu onClick={e => addChange(e)}>
1546
      <Menu.Item key="1" onClick={addUser} icon={<UserAddOutlined style={{ marginTop: '5px' }} />}>
陈前坚's avatar
陈前坚 committed
1547 1548
        添加用户
      </Menu.Item>
1549 1550 1551 1552
    </Menu>
  );
  const orgButtonMenu1 = (
    <Menu onClick={e => addChange(e)}>
1553 1554 1555 1556 1557
      <Menu.Item
        key="2"
        onClick={addSubOrg}
        icon={<ClusterOutlined style={{ marginTop: '5px' }} />}
      >
陈前坚's avatar
陈前坚 committed
1558
        添加下级机构
陈前坚's avatar
陈前坚 committed
1559
      </Menu.Item>
1560
      <Menu.Item key="3" onClick={editOrg} icon={<EditOutlined style={{ marginTop: '5px' }} />}>
陈前坚's avatar
陈前坚 committed
1561
        编辑当前机构
陈前坚's avatar
陈前坚 committed
1562
      </Menu.Item>
1563
      <Menu.Item key="4" onClick={deleteOrg} icon={<DeleteOutlined style={{ marginTop: '5px' }} />}>
陈前坚's avatar
陈前坚 committed
1564
        删除当前机构
陈前坚's avatar
陈前坚 committed
1565
      </Menu.Item>
1566
      {/* <Menu.Item
1567 1568 1569 1570
        key="5"
        onClick={EditOrgScope}
        icon={<BorderlessTableOutlined style={{ marginTop: '5px' }} />}
      >
mayongxin's avatar
mayongxin committed
1571
        编辑机构范围
1572
      </Menu.Item> */}
陈前坚's avatar
陈前坚 committed
1573 1574 1575 1576 1577
    </Menu>
  );
  // 用户批量操作
  const userButtonMenu = (
    <Menu>
1578
      <Menu.Item key="1" onClick={relateRoles} icon={<IdcardOutlined />}>
陈前坚's avatar
陈前坚 committed
1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589
        批量关联角色
      </Menu.Item>
      <Menu.Item key="2" onClick={changeOrgs} icon={<ApartmentOutlined />}>
        批量更改机构
      </Menu.Item>
      <Menu.Item key="3" onClick={deleteUsers} icon={<DeleteOutlined />}>
        批量删除用户
      </Menu.Item>
    </Menu>
  );

1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611
  // 本地上传文件
  const beforeUpload = val => {
    console.log(val);
    importUserForm.setFieldsValue({ fileName: val.name });
    setFile(val);
    return false;
  };

  const handleOk = () => {
    // if(!file) {
    //   message.error('请上传文件!')
    //   return false
    // }
    importUserForm.validateFields().then(res => {
      console.log(res, 'resssssssssssss');
      const formData = new FormData();
      formData.append('file', file);
      const params = { query: encipher((res.password), pasType ? pasType : '').toUpperCase(), data: formData }
      console.log(params, 'paramssssssssssssssss');

      ImportUserData(params).then(res => {
        console.log(res, 'ressssssssssssssss');
涂伟's avatar
涂伟 committed
1612 1613 1614 1615
        if (res.code === 0) {
          if (res.data.includes('成功')) {
            message.success(res.data)
            setImportAccountVisible(false);
1616
            submitSearchUser()
涂伟's avatar
涂伟 committed
1617 1618 1619
          } else {
            setAlertTxt(res.data || '导入失败!')
          }
1620
        } else {
涂伟's avatar
涂伟 committed
1621
          setAlertTxt(res.msg || '导入失败!')
1622 1623 1624 1625 1626
        }
      })
    })
  }

1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679
  // 校验文件名字不为空
  const filenameVerification = (file, special) => {
    // 文件名含有特殊字符  提示不能上传   {+,:/?#[]@!$&\\*+;=}
    // 规则对象(flag)
    let flag = !special ? new RegExp('[`~!@#$^&*=|{}\':;\',\\[\\]/?~!@#¥&*——|{}【】‘;:”“\'。,、?]') : new RegExp('[`~!@#$^&*=|{}\':;\',\\[\\]?~!@#¥&*——|{}【】‘;:”“\'。,、?]');
    if (flag.test(file.name)) {
      return {
        type: 'error',
        content: `文件名格式错误,请检查文件名是否含有特殊字符${'~!@#$^&*=|{}\':;\',\\[\\]/?~!@#¥&*——|{}【】‘;:”“\'。,、?'}`,
      };
    }
    return {
      type: 'success',
      content: `上传成功!`,
    };
  }

  const uploadProps = {
    name: 'file',
    action: `${window.origin}/PandaOMS/OMS/UserCenter/ImportAccountData?password=${encipher(importUserForm.getFieldValue('password'), pasType ? pasType : '').toUpperCase()}`,
    // headers: {
    //   authorization: 'authorization-text',
    // },
    // fileList: [],
    showUploadList: false,
    onChange: ({ file, fileList, event }) => {
      console.log(file, 'filefilefilefilefile');

      if (!file.size && file.status !== 'removed') {
        return message.error('上传文件为空,禁止上传!')
      }
      // 检验名字,名字不通过不允许显示
      if (filenameVerification(file).type === 'error') return false;
      // 返回的链接在file.response内;不设置url,预览图表不可点击
      if (file.status === 'done' && file.response.code === 0) {
        // file.url = `${window.origin}/PandaWorkFlow/WorkFlow/AccountManage/DownloadFiles?filePath=${file.response.data}`
        // file.sourcePath = file.response.data;
        message.success(file.response.data)
        setImportAccountVisible(false)
      } else if (file.status === 'done' && file.response.code !== 0) {
        file.status = 'error';
        message.error(file.response.msg)
      }
      // if (file.status === 'done') {
      //   onChange(fileList.map(v => v.sourcePath).join(','))
      // }
    },
  };

  // 其他操作
  const otherButtonMenu = (
    <Menu>
      {/* <Upload {...props}> */}
1680 1681
      <Menu.Item key="11" onClick={importRoles} icon={<UsergroupAddOutlined />}>
        导入用户
1682 1683 1684 1685 1686
      </Menu.Item>
      {/* </Upload> */}
      {/* <Menu.Item key="11" onClick={importRoles} icon={<IdcardOutlined />}>
        批量导入角色
      </Menu.Item> */}
1687 1688 1689
      <Menu.Item key="22" onClick={() => { exportRoles({ isModal: true }) }} icon={<SnippetsOutlined />}>
        导出模板
      </Menu.Item>
涂伟's avatar
涂伟 committed
1690
      <Menu.Item key="33" onClick={() => { exportRoles({ all: true }) }} icon={<UserSwitchOutlined />}>
1691 1692 1693 1694
        导出全部用户
      </Menu.Item>
      <Menu.Item key="44" onClick={exportRoles} icon={<UserSwitchOutlined />}>
        导出用户
1695 1696 1697 1698
      </Menu.Item>
    </Menu>
  );

皮倩雯's avatar
皮倩雯 committed
1699 1700 1701
  const kee = () => {
    setUserVisible(false);
  };
1702

1703 1704 1705 1706 1707 1708 1709 1710 1711
  const onSearch = value => {
    setSearchTreeValue(value);
    updateTrees(value);
  };

  // 监听分页
  const paginationChange = (page, pageSizes) => {
    setCurrentPage(page);
    setPageSize(pageSizes);
1712 1713 1714 1715 1716
    if (searchWord) {
      submitSearchUser(pageSizes, page);
    } else {
      onSelect([currentSelectOrg], '', pageSizes, page);
    }
1717 1718
  };

陈前坚's avatar
陈前坚 committed
1719
  return (
1720 1721
    <PageContainer className={styles.userManageContainer}>
      <div className={styles.contentContainer}>
陈前坚's avatar
陈前坚 committed
1722
        {/* 左侧机构树 */}
陈前坚's avatar
陈前坚 committed
1723
        <Spin spinning={treeLoading} tip="loading...">
陈前坚's avatar
陈前坚 committed
1724
          <Card
1725
            style={{ overflowY: 'hidden', height: '100%' }}
陈前坚's avatar
陈前坚 committed
1726 1727 1728 1729 1730
            className={classnames({
              [styles.orgContainer]: true,
              [styles.orgContainerHide]: !treeVisible,
            })}
          >
1731
            <div style={{ display: 'flex', flexDirection: 'column', height: '100%' }}>
1732 1733 1734
              <div
                style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}
              >
1735
                <span
陈前坚's avatar
陈前坚 committed
1736
                  style={{
1737 1738
                    fontSize: '15px ',
                    fontWeight: 'bold',
1739
                    marginLeft: '7px',
陈前坚's avatar
陈前坚 committed
1740
                  }}
1741
                >
1742
                  机构列表({treeDataTotal}个)
1743 1744 1745 1746 1747 1748 1749
                </span>
                <Tooltip title="添加顶级机构">
                  <PlusSquareFilled
                    onClick={() => addOrg()}
                    style={{
                      color: '#1890FF',
                      fontSize: '25px',
1750
                      // marginLeft: '51%',
1751 1752 1753 1754
                    }}
                  />
                </Tooltip>
              </div>
1755
              <hr style={{ width: '97%', color: '#eeecec', marginLeft: '8px' }} />
1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767
              <Search
                style={{
                  marginBottom: 8,
                  width: '98%',
                  marginLeft: '7px',
                }}
                placeholder="快速搜索机构"
                onSearch={onSearch}
              />
              {searchTreeValue !== '' ? (
                <>
                  {treeData.length > 0 && (
1768 1769
                    //   <div style={{ height: '100%', overflowY: 'scroll' }}>
                    <Tree
程恺文's avatar
程恺文 committed
1770
                      height={780}
1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781
                      showIcon="true"
                      blockNode
                      defaultExpandAll
                      onSelect={onSelect}
                      treeData={treeData.map(t => mapTree(t))}
                      draggable
                      onDrop={handleDrop}
                      selectedKeys={[menuID]}
                      keepTree={keepTree}
                    />
                    //        </div>
1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802
                  )}
                </>
              ) : (
                <>
                  {treeData.length > 0 && (
                    <div style={{ height: '100%', overflowY: 'scroll' }}>
                      <TreeComponents
                        showIcon="true"
                        blockNode
                        autoExpandParent
                        onSelect={onSelect}
                        treeData={treeData.map(t => mapTree(t))}
                        draggable
                        onDrop={handleDrop}
                        selectedKeys={[menuID]}
                        keepTree={keepTree}
                        expandedKeys={expendKey}
                      />
                    </div>
                  )}
                </>
陈前坚's avatar
陈前坚 committed
1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816
              )}
            </div>
            <div className={styles.switcher}>
              {treeVisible && (
                <Tooltip title="隐藏机构列表">
                  <DoubleLeftOutlined onClick={() => setTreeVisible(false)} />
                </Tooltip>
              )}
              {!treeVisible && (
                <Tooltip title="显示机构列表">
                  <DoubleRightOutlined onClick={() => setTreeVisible(true)} />
                </Tooltip>
              )}
            </div>
陈前坚's avatar
陈前坚 committed
1817
          </Card>
陈前坚's avatar
陈前坚 committed
1818
        </Spin>
1819

陈前坚's avatar
陈前坚 committed
1820
        {/* 右侧用户表 */}
陈前坚's avatar
陈前坚 committed
1821
        <div
1822
          ref={userContainer}
陈前坚's avatar
陈前坚 committed
1823
          className={classnames({
1824
            [styles.userContainer]: true,
陈前坚's avatar
陈前坚 committed
1825 1826
          })}
        >
陈前坚's avatar
陈前坚 committed
1827
          <div style={{ height: '50px' }}>
1828
            <span
1829
              className={styles.title}
1830
              title={`${orgTitle}(已选${selectedRowKeys.length}/共${tableLength}人)`}
1831 1832
            >
              {orgTitle}(已选{selectedRowKeys.length}/共{tableLength}人)
1833
            </span>
陈前坚's avatar
陈前坚 committed
1834
            <span style={{ float: 'right', margin: '10px' }}>
陈前坚's avatar
陈前坚 committed
1835
              <Search
1836
                style={{ width: 260, marginRight: '15px' }}
1837
                placeholder="搜索登录名/用户姓名/手机号"
1838
                onSearch={e => submitSearchUser()}
陈前坚's avatar
陈前坚 committed
1839 1840 1841 1842
                onChange={e => handleSearch(e)}
                enterButton
                value={searchWord}
              />
皮倩雯's avatar
皮倩雯 committed
1843

1844
              <Button style={{ marginRight: '15px' }} icon={<SyncOutlined />} onClick={handleReset}>
1845 1846
                重置
              </Button>
皮倩雯's avatar
皮倩雯 committed
1847

1848 1849 1850 1851 1852 1853
              <Dropdown overlay={otherButtonMenu}>
                <Button type="primary" style={{ marginRight: '10px' }}>
                  其他操作 <DownOutlined />
                </Button>
              </Dropdown>

陈前坚's avatar
陈前坚 committed
1854 1855 1856 1857 1858
              <Dropdown overlay={userButtonMenu} disabled={multiOperate}>
                <Button type={multiOperateButtonType}>
                  用户批量操作 <DownOutlined />
                </Button>
              </Dropdown>
陈前坚's avatar
陈前坚 committed
1859 1860
            </span>
          </div>
1861 1862 1863 1864 1865 1866 1867 1868 1869
          {userContainer.current && (
            <Table
              // style={{ height: 'calc(100% -50px)' }}
              rowSelection={{
                type: 'checkbox',
                ...rowSelection,
              }}
              rowClassName={setRowClassName}
              size="small"
1870
              rowKey={record => record.userId}
1871 1872 1873 1874 1875 1876 1877 1878 1879
              locale={zhCN}
              bordered
              columns={columns}
              dataSource={tableData}
              loading={tableLoading}
              scroll={{
                x: 'max-content',
                y: `calc(${userContainer.current.clientHeight}px - 150px)`,
              }}
1880
              pagination={false}
1881 1882 1883 1884 1885
              onRow={record => ({
                onDoubleClick: () => {
                  editUser(record);
                },
              })}
1886 1887 1888
              onChange={onChangeInput}
            />
          )}
1889 1890 1891 1892 1893 1894 1895 1896
          <div
            style={{
              display: 'flex',
              justifyContent: 'flex-end',
              marginTop: '10px',
              marginRight: '5px',
            }}
          >
1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909
            <Pagination
              total={total}
              showTotal={(totals, range) => `第${range[0]}-${range[1]} 条/共 ${totals} 条`}
              defaultPageSize={pageSize}
              defaultCurrent={1}
              showSizeChanger
              pageSizeOptions={[10, 20, 50, 100]}
              current={currentPage}
              onChange={paginationChange}
              style={{ marginBottom: '10px' }}
              size="small"
              showQuickJumper
            />
1910
          </div>
1911
        </div>
1912

陈前坚's avatar
陈前坚 committed
1913
        {/* Modal弹框 */}
1914
        {/* 添加用户 */}
陈前坚's avatar
陈前坚 committed
1915 1916 1917
        <AddUserModal
          visible={userVisible}
          orgID={orgID}
1918
          orgTitle1={orgTitle1}
皮倩雯's avatar
皮倩雯 committed
1919
          onCancel={kee}
1920
          updateTrees1={updateTrees1}
1921
          siteList={siteList}
1922
          onSelect={onSelect}
陈前坚's avatar
陈前坚 committed
1923
        />
1924
        {/* 添加下级机构 */}
1925
        <AddSubOrgModal
1926
          visible={addOrgVisible}
1927
          orgTitle1={orgTitle1}
1928
          orgID={orgID}
1929
          onCancel={() => setAddOrgVisible(false)}
1930 1931
          onSelect={onSelect}
          updateTrees1={updateTrees1}
1932
        />
1933
        {/* 编辑机构 */}
1934
        <EditOrgModal
1935
          visible={editOrgVisible}
1936
          orgID={orgID}
1937
          orgTitle1={orgTitle1}
1938
          // description={description}
1939
          onCancel={() => setEditOrgVisible(false)}
1940 1941 1942 1943
          updateTrees={updateTrees}
        />
        {/* 删除机构 */}
        <DeleteOrgModal
皮倩雯's avatar
皮倩雯 committed
1944
          title="删除机构"
1945
          visible={deleteOrgVisible}
1946
          orgTitle={orgTitle1}
1947 1948
          orgID={orgID}
          updateTrees={updateTrees}
1949
          onCancel={() => setDeleteOrgVisible(false)}
1950
        />
陈前坚's avatar
陈前坚 committed
1951
        {/* 关联角色 */}
1952 1953 1954 1955
        <RelateRoleModal
          currentUser={currentUser}
          userIDs={userIDs}
          currentSelectOrg={currentSelectOrg}
陈前坚's avatar
陈前坚 committed
1956
          visible={roleVisible}
1957
          rolelist={rolelist}
1958 1959 1960
          multiRoleList={multiRoleList}
          multistationList={multistationList}
          mult={mult}
1961 1962 1963 1964
          loading={loading}
          stationlist={stationlist}
          multiRelateRoles={multiRelateRoles}
          onSelect={onSelect}
1965
          submitSearchUser={submitSearchUser}
陈前坚's avatar
陈前坚 committed
1966 1967 1968 1969
          onCancel={() => {
            setRoleVisible(false);
            setMultiRelateRoles(false);
          }}
1970
        />
陈前坚's avatar
陈前坚 committed
1971
        {/* 更改机构 */}
1972 1973 1974
        <Modal
          title="更改机构"
          visible={changeOrgVisible}
陈前坚's avatar
陈前坚 committed
1975
          onOk={multiChangeOrgs ? submitChangeOrgs : submitChangeOrg}
1976
          maskClosable={false}
陈前坚's avatar
陈前坚 committed
1977 1978 1979 1980
          onCancel={() => {
            setChangeOrgVisible(false);
            setMultiChangeOrgs(false);
          }}
1981 1982
          okText="确认"
          cancelText="取消"
1983
          width="500px"
1984
        >
1985 1986 1987 1988 1989 1990 1991 1992 1993
          {/* <span>请选择要更改的目标机构:</span> */}
          <Search
            style={{ width: 260, marginBottom: '10px' }}
            placeholder="请输入机构名称"
            onSearch={submitSearch}
            onChange={e => handleSearchOrg(e)}
            enterButton
            value={searchWordOrg}
          />
1994 1995
          <div style={{ height: '500px', overflowY: 'scroll' }}>
            {changeOrgVisible && treeDataCopy.length > 0 && (
1996
              <TreeComponents
1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011
                showIcon="true"
                showLine={{ showLeafIcon: false }}
                // defaultExpandAll
                // 未切换时原先的节点,注意要转字符串
                selectedKeys={[`${currentSelectOldOrg}`]}
                onSelect={value => {
                  setNewOrgID(value[0]);
                  // 切换后选中的节点
                  setCurrentSelectOldOrg(value[0]);
                }}
                expandedKeys={expendKeyOrg}
                treeData={treeDataCopy.map(t => mapTree1(t))}
              />
            )}
          </div>
2012
        </Modal>
陈前坚's avatar
陈前坚 committed
2013
        {/* 修改密码 */}
2014
        <ChangePasswordModal
陈前坚's avatar
陈前坚 committed
2015
          visible={passwordVisible}
2016
          currentUser={currentUser}
2017 2018
          submitSearchUser={submitSearchUser}
          currentSelectOrg={currentSelectOrg}
2019
          onSelect={onSelect}
陈前坚's avatar
陈前坚 committed
2020
          onCancel={() => setPasswordVisible(false)}
2021
        />
陈前坚's avatar
陈前坚 committed
2022
        {/* 编辑用户 */}
2023
        <EditUserModal
陈前坚's avatar
陈前坚 committed
2024
          visible={editUserVisible}
2025
          currentUser={currentUser}
2026 2027
          submitSearchUser={submitSearchUser}
          currentSelectOrg={currentSelectOrg}
2028
          onSelect={onSelect}
陈前坚's avatar
陈前坚 committed
2029
          onCancel={() => setEditUserVisible(false)}
2030
        />
陈前坚's avatar
陈前坚 committed
2031
        {/* 冻结用户 */}
皮倩雯's avatar
皮倩雯 committed
2032
        {/* <Modal
2033
          title="请确认"
陈前坚's avatar
陈前坚 committed
2034 2035 2036 2037 2038 2039
          visible={freezeUserVisible}
          onOk={submitFreezeUser}
          onCancel={() => setFreezeUserVisible(false)}
          okText="确认"
          cancelText="取消"
        >
张烨's avatar
张烨 committed
2040 2041
          <p>
            即将{+currentUser.state ? '激活' : '冻结'}用户{' '}
2042 2043 2044
            <span className={styles.redText}>
              {voca.stripTags(currentUser.loginName)}
            </span>
张烨's avatar
张烨 committed
2045 2046 2047
            ,是否确认
            {+currentUser.state ? '激活' : '冻结'}?
          </p>
皮倩雯's avatar
皮倩雯 committed
2048
        </Modal> */}
2049
        {/* 多选删除用户 */}
2050 2051 2052
        <Modal
          title="确认删除用户"
          visible={deleteUserVisible}
陈前坚's avatar
陈前坚 committed
2053
          onOk={multiDelete ? submitDeleteUsers : submitDeleteUser}
2054
          maskClosable={false}
陈前坚's avatar
陈前坚 committed
2055 2056 2057 2058
          onCancel={() => {
            setDeleteUserVisible(false);
            setMultiDelete(false);
          }}
2059 2060 2061
          okText="确认"
          cancelText="取消"
        >
2062
          <p>将删除多个用户, 是否确认删除?</p>
2063
        </Modal>
2064
        {/* <MapScopeEditModal
皮倩雯's avatar
皮倩雯 committed
2065
          title={id}
mayongxin's avatar
mayongxin committed
2066
          mapId={createGuid()}
mayongxin's avatar
mayongxin committed
2067
          visible={editOrgExtentVisible}
皮倩雯's avatar
皮倩雯 committed
2068
          stationId={currentSelectOrg1}
mayongxin's avatar
mayongxin committed
2069 2070 2071 2072
          onCancel={() => setEditOrgExtentVisible(false)}
          confirmModal={submitExtent}
          distinct={currentOrgDistinct}
          extent={currentOrgArea}
2073
        /> */}
2074
        {/* <AuthModal
皮倩雯's avatar
皮倩雯 committed
2075 2076 2077
          visible={authUserVisible}
          currentUser={currentUser}
          onCancel={() => setAuthUserVisible(false)}
2078
        /> */}
陈前坚's avatar
陈前坚 committed
2079
      </div>
2080 2081 2082 2083 2084 2085 2086 2087
      <Modal
        title="确认密码"
        visible={importAccountVisible}
        // onOk={multiDelete ? submitDeleteUsers : submitDeleteUser}
        maskClosable={false}
        destroyOnClose
        onCancel={() => {
          setImportAccountVisible(false);
2088
          setAlertTxt('')
2089 2090 2091 2092
        }}
        afterClose={() => {
          importUserForm.resetFields();
          setPasswordLevel('');
2093
          setAlertTxt('')
2094
        }}
2095
        width={520}
2096 2097 2098 2099 2100 2101
        okText="确认"
        cancelText="取消"
        footer={[
          <Button key="back" onClick={() => setImportAccountVisible(false)} style={{ 'marginRight': '5px' }}>
            取消
          </Button>,
2102 2103 2104 2105 2106 2107 2108 2109 2110 2111
          // <Upload {...uploadProps}>
          <Button key="submit"
            type="primary"
            // loading={loading}
            onClick={handleOk}
          // disabled={btnDisabled}
          >
            确认
          </Button>
          // </Upload>,
2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144
        ]}
      >
        <div className={styles.modalContent}>
          <Form form={importUserForm} labelCol={{ span: 4 }} onFieldsChange={changeValue}>
            <div className={styles.formBox}>
              <Form.Item
                hasFeedback
                name="password"
                label="账号密码"
                rules={[
                  {
                    pattern: rules ? rules.regex : `/^(?=.*[a-zA-Z])(?=.*d)[wS]{6,16}$/`,
                    message: rules ? rules.tip : '长度6-16位,必须包含数字与字母',
                  },
                  {
                    pattern: /^(?!.*(?:SELECT|UPDATE|INSERT|AND|OR|'|"|;|--|\\)).*$/,
                    message: '当前密码存在sql注入风险,请重新输入', // 防止sql注入
                  },
                  { required: true },
                ]}
              >
                <Input.Password
                  placeholder={rules ? rules.tip : '请输入账号密码长度6~16位,必须包含数字与字母'}
                  maxLength="16"
                  onCopy={e => {
                    e.preventDefault();
                  }}
                  onPaste={e => {
                    // 禁止粘贴
                    e.preventDefault();
                  }}
                />
              </Form.Item>
2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195
              <Form.Item
                hasFeedback
                name="password2"
                label="确认密码"
                rules={[
                  ({ getFieldValue }) => ({
                    validator(_, value) {
                      if (!value || getFieldValue('password') === value) {
                        return Promise.resolve();
                      }
                      return Promise.reject(new Error('两次输入的密码不一致!'));
                    },
                  }),
                  { required: true },
                ]}
              >
                <Input.Password
                  placeholder={'请确认密码'}
                  maxLength="16"
                  onCopy={e => {
                    e.preventDefault();
                  }}
                  onPaste={e => {
                    // 禁止粘贴
                    e.preventDefault();
                  }}
                />
              </Form.Item>
              <Form.Item label="本地导入">
                <div style={{ display: 'flex' }}>
                  <Form.Item
                    name="fileName"
                    style={{ marginBottom: '0' }}
                    rules={[
                      { required: true, message: '请上传文件!' },
                    ]}>
                    <Input disabled />
                  </Form.Item>
                  <Upload beforeUpload={beforeUpload} showUploadList={false}>
                    <Button
                      type="primary"
                      style={{ marginLeft: '10px' }}
                      icon={<UploadOutlined />}
                      shape="circle"
                    />
                  </Upload>
                </div>
              </Form.Item>
              {alertTxt ? <Alert
                message="错误信息"
                description={
涂伟's avatar
涂伟 committed
2196
                  <div dangerouslySetInnerHTML={{ __html: alertTxt }} />
2197 2198 2199 2200 2201 2202
                }
                type="error"
                closable
              // onClose={onClose}
              /> : null}

2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216
              <div
                style={{ right: '70px' }}
                className={classnames(styles.tipsText, {
                  [styles.tipsRed]: passwordLevel === '弱',
                  [styles.tipsOrange]: passwordLevel === '中',
                  [styles.tipsGreen]: passwordLevel === '强',
                })}
              >
                {passwordLevel}
              </div>
            </div>
          </Form>
        </div>
      </Modal>
陈前坚's avatar
陈前坚 committed
2217
    </PageContainer>
2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259
    // <DraggleLayout
    //     containerWidth={550}
    //     containerHeight={220}
    //     min={50}
    //     max={500}
    //     initLeftWidth={100}
    //     onWidthChange={w => setWidth(w)}
    //     handler={
    //       <div
    //         style={{
    //           width: 4,
    //           height: '100%',
    //           background: 'rgb(77, 81, 100)',
    //         }}
    //       />
    //     }
    //   >
    //     <div
    //       style={{
    //         backgroundColor: `rgb(36, 205, 208)`,
    //         color: `#fff`,
    //         height: '100%',
    //         display: 'flex',
    //         alignItems: 'center',
    //         justifyContent: 'center',
    //       }}
    //     >
    //       left
    //     </div>
    //     <div
    //       style={{
    //         backgroundColor: `rgb(116, 140, 253)`,
    //         color: `#fff`,
    //         height: '100%',
    //         display: 'flex',
    //         alignItems: 'center',
    //         justifyContent: 'center',
    //       }}
    //     >
    //       right
    //     </div>
    //   </DraggleLayout>
陈前坚's avatar
陈前坚 committed
2260 2261 2262 2263
  );
};

export default UserManage;