import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react' import { CaretUpOutlined, CaretDownOutlined } from '@ant-design/icons' import styles from './index.module.scss' import SpinLoding from '@/components/SpinLoding' import { Route, Switch, useLocation } from 'react-router-dom' import AuthRoute from '@/components/AuthRoute' import classNames from 'classnames' import history from '@/utils/history' import { Button, Form, Input, Modal, Popconfirm } from 'antd' import { Base64 } from 'js-base64' import encodeStr from '@/utils/pass' import { passWordEditAPI } from '@/store/action/layout' import { getTokenInfo, removeTokenInfo } from '@/utils/storage' import { MessageFu } from '@/utils/message' import logonImg from '@/assets/img/logo.png' const NotFound = React.lazy(() => import('@/components/NotFound')) function Layout() { const list = useMemo(() => { return [ { id: 100, img: 1, name: '场景管理', path: '/list', Com: React.lazy(() => import('../A1List')) }, { id: 900, img: 2, name: '用户管理', path: '/user', Com: React.lazy(() => import('../A9User')) }, { id: 901, img: 3, name: '系统日志', path: '/log', Com: React.lazy(() => import('../Z2log')) } ] }, []) useEffect(() => { // 如果是超级管理员 // const userInfo = getTokenInfo().user // if (userInfo.isAdmin === 1) { // list.push({ // id: 900, // name: '用户管理', // path: '/user', // Com: React.lazy(() => import('../A9User')) // }) // } }, [list]) // 点击跳转 const pathCutFu = useCallback((path: string) => { history.push(path) }, []) // 当前路径选中的左侧菜单 const location = useLocation() const [path, setPath] = useState('') useEffect(() => { const arr = location.pathname.split('/') let pathTemp = '/' if (arr[1]) pathTemp = '/' + arr[1] setPath(pathTemp) }, [location]) const userInfo = useMemo(() => { return getTokenInfo().user }, []) // 修改密码相关 const [open, setOpen] = useState(false) // 拿到新密码的输入框的值 const oldPasswordValue = useRef('') const checkPassWord = (rule: any, value: any = '') => { if (value !== oldPasswordValue.current) return Promise.reject('新密码不一致!') else return Promise.resolve(value) } const onFinish = async (values: any) => { // 通过校验之后发送请求 if (values.oldPassword === values.newPassword) return MessageFu.warning('新旧密码不能相同!') const obj = { oldPassword: encodeStr(Base64.encode(values.oldPassword)), newPassword: encodeStr(Base64.encode(values.newPassword)) } const res: any = await passWordEditAPI(obj) if (res.code === 0) { MessageFu.success('修改成功!') loginExit() } } // 点击退出登录 const loginExit = () => { removeTokenInfo() history.push('/login') } return (