|
@@ -1,198 +1,196 @@
|
|
|
-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 logoImg from "@/assets/img/logo.png";
|
|
|
-import logoImg2 from "@/assets/img/logo2.png";
|
|
|
-import NotFound from "@/components/NotFound";
|
|
|
+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 logoImg from '@/assets/img/logo.png'
|
|
|
+import logoImg2 from '@/assets/img/logo2.png'
|
|
|
+import NotFound from '@/components/NotFound'
|
|
|
|
|
|
-import { RouterType, RouterTypeRow } from "@/types";
|
|
|
-import tabLeftArr from "./data";
|
|
|
-import { C1_APIgetInfo } from "@/store/action/C1User";
|
|
|
-import { envTxtRes } from "@/utils/envTxt";
|
|
|
+import { RouterType, RouterTypeRow } from '@/types'
|
|
|
+import tabLeftArr from './data'
|
|
|
+import { C1_APIgetInfo } from '@/store/action/C1User'
|
|
|
+import { envTxtRes } from '@/utils/envTxt'
|
|
|
|
|
|
function Layout() {
|
|
|
// 左侧菜单 和 路由 信息
|
|
|
- const [list, setList] = useState([] as RouterType);
|
|
|
+ const [list, setList] = useState([] as RouterType)
|
|
|
|
|
|
// 用户名
|
|
|
- const [userName, setUserName] = useState("-");
|
|
|
+ const [userName, setUserName] = useState('-')
|
|
|
|
|
|
// 进页面更新用户信息
|
|
|
const getUserInfo = useCallback(async () => {
|
|
|
- const userInfo = getTokenInfo().user;
|
|
|
+ const userInfo = getTokenInfo().user
|
|
|
if (userInfo && userInfo.id) {
|
|
|
- const res = await C1_APIgetInfo(userInfo.id);
|
|
|
+ const res = await C1_APIgetInfo(userInfo.id)
|
|
|
if (res.code === 0) {
|
|
|
// 设置右上角的名字
|
|
|
- setUserName(res.data.realName);
|
|
|
+ setUserName(res.data.realName)
|
|
|
|
|
|
// 铁塔管理员只能看 进度 和 场景
|
|
|
- const arrTemp = ["2.1", "2.2"];
|
|
|
+ const arrTemp = ['2.1', '2.2']
|
|
|
|
|
|
- const flag = res.data.roleId === 4;
|
|
|
+ const flag = res.data.roleId === 4
|
|
|
|
|
|
- tabLeftArr.forEach((v) => {
|
|
|
- v.son.forEach((v2) => {
|
|
|
+ tabLeftArr.forEach(v => {
|
|
|
+ v.son.forEach(v2 => {
|
|
|
if (flag) {
|
|
|
// 是铁塔管理员
|
|
|
- if (arrTemp.includes(v2.id)) v2.done = true;
|
|
|
- else v2.done = false;
|
|
|
- } else v2.done = true;
|
|
|
- });
|
|
|
- });
|
|
|
+ if (arrTemp.includes(v2.id)) v2.done = true
|
|
|
+ else v2.done = false
|
|
|
+ } else v2.done = true
|
|
|
+ })
|
|
|
+ })
|
|
|
|
|
|
setList(
|
|
|
- tabLeftArr.map((v) => ({
|
|
|
+ tabLeftArr.map(v => ({
|
|
|
...v,
|
|
|
- son: v.son.filter((v2) => v2.done),
|
|
|
+ son: v.son.filter(v2 => v2.done)
|
|
|
}))
|
|
|
- );
|
|
|
+ )
|
|
|
}
|
|
|
}
|
|
|
- }, []);
|
|
|
+ }, [])
|
|
|
|
|
|
useEffect(() => {
|
|
|
- getUserInfo();
|
|
|
- }, [getUserInfo]);
|
|
|
+ getUserInfo()
|
|
|
+ }, [getUserInfo])
|
|
|
|
|
|
// 点击跳转
|
|
|
const pathCutFu = useCallback((path: string) => {
|
|
|
- history.push(path);
|
|
|
- }, []);
|
|
|
+ history.push(path)
|
|
|
+ }, [])
|
|
|
|
|
|
// 当前路径选中的左侧菜单
|
|
|
- const location = useLocation();
|
|
|
- const [path, setPath] = useState("");
|
|
|
+ const location = useLocation()
|
|
|
+ const [path, setPath] = useState('')
|
|
|
+
|
|
|
+ const businessUrlArr = useRef(['/lookZL', '/lookXS', '/lookBX', '/lookDS', '/lookWX'])
|
|
|
|
|
|
useEffect(() => {
|
|
|
- const arr = location.pathname.split("/");
|
|
|
- let pathTemp = "/";
|
|
|
- if (arr[1]) pathTemp = "/" + arr[1];
|
|
|
+ const arr = location.pathname.split('/')
|
|
|
+ let pathTemp = '/'
|
|
|
+ if (arr[1]) pathTemp = '/' + arr[1]
|
|
|
+
|
|
|
+ // 匹配相机列表的 查看
|
|
|
+ if (pathTemp === '/lookList') pathTemp = '/'
|
|
|
+
|
|
|
+ // 匹配业务订单的查看
|
|
|
+ if (businessUrlArr.current.includes(pathTemp)) pathTemp = '/business'
|
|
|
|
|
|
- setPath(pathTemp);
|
|
|
- }, [location]);
|
|
|
+ setPath(pathTemp)
|
|
|
+ }, [location])
|
|
|
|
|
|
// 修改密码相关
|
|
|
- const [open, setOpen] = useState(false);
|
|
|
+ const [open, setOpen] = useState(false)
|
|
|
|
|
|
// 拿到新密码的输入框的值
|
|
|
- const oldPasswordValue = useRef("");
|
|
|
+ const oldPasswordValue = useRef('')
|
|
|
|
|
|
- const checkPassWord = (rule: any, value: any = "") => {
|
|
|
- if (value !== oldPasswordValue.current)
|
|
|
- return Promise.reject("新密码不一致!");
|
|
|
- else return Promise.resolve(value);
|
|
|
- };
|
|
|
+ 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("新旧密码不能相同!");
|
|
|
+ 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);
|
|
|
+ newPassword: encodeStr(Base64.encode(values.newPassword))
|
|
|
+ }
|
|
|
+ const res: any = await passWordEditAPI(obj)
|
|
|
if (res.code === 0) {
|
|
|
- MessageFu.success("修改成功!");
|
|
|
- loginExit();
|
|
|
+ MessageFu.success('修改成功!')
|
|
|
+ loginExit()
|
|
|
}
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
// 点击退出登录
|
|
|
const loginExit = () => {
|
|
|
- removeTokenInfo();
|
|
|
- history.push("/login");
|
|
|
- };
|
|
|
+ removeTokenInfo()
|
|
|
+ history.push('/login')
|
|
|
+ }
|
|
|
|
|
|
// 路由信息(过滤之后的)
|
|
|
const RouterCom = useMemo(() => {
|
|
|
- const arr: RouterTypeRow = [];
|
|
|
- list.forEach((v) => {
|
|
|
+ const arr: RouterTypeRow = []
|
|
|
+ list.forEach(v => {
|
|
|
if (v.son && v.son[0]) {
|
|
|
- v.son.forEach((v2) => {
|
|
|
- if (v2.done) arr.push(v2);
|
|
|
- });
|
|
|
+ v.son.forEach(v2 => {
|
|
|
+ if (v2.done) arr.push(v2)
|
|
|
+ })
|
|
|
}
|
|
|
- });
|
|
|
- return arr;
|
|
|
- }, [list]);
|
|
|
+ })
|
|
|
+ return arr
|
|
|
+ }, [list])
|
|
|
|
|
|
// 第一个页面不是 项目 管理 的时候 动态 跳转
|
|
|
useEffect(() => {
|
|
|
- if (RouterCom && RouterCom[0] && RouterCom[0].id !== "1.1")
|
|
|
- history.replace(RouterCom[0].path);
|
|
|
- }, [RouterCom]);
|
|
|
+ if (RouterCom && RouterCom[0] && RouterCom[0].id !== '1.1') history.replace(RouterCom[0].path)
|
|
|
+ }, [RouterCom])
|
|
|
|
|
|
return (
|
|
|
<div className={styles.Layout}>
|
|
|
{/* 左边 */}
|
|
|
- <div className="layoutLeft">
|
|
|
- <div className="layoutLeftTop">
|
|
|
- <img src={envTxtRes === "四维" ? logoImg : logoImg2} alt="" />
|
|
|
+ <div className='layoutLeft'>
|
|
|
+ <div className='layoutLeftTop'>
|
|
|
+ <img src={envTxtRes === '四维' ? logoImg : logoImg2} alt='' />
|
|
|
</div>
|
|
|
{/* 左边主体 */}
|
|
|
- <div className="layoutLeftMain">
|
|
|
- {list.map((v) => (
|
|
|
+ <div className='layoutLeftMain'>
|
|
|
+ {list.map(v => (
|
|
|
<div
|
|
|
- className={classNames("layoutLRowBox")}
|
|
|
+ className={classNames('layoutLRowBox')}
|
|
|
key={v.id}
|
|
|
- hidden={v.son.every((c) => !c.done)}
|
|
|
+ hidden={v.son.every(c => !c.done)}
|
|
|
>
|
|
|
- <div className="layoutLRowBoxTxt">{v.name}</div>
|
|
|
- {v.son.map((v2) => (
|
|
|
- <div
|
|
|
- key={v2.id}
|
|
|
- className={classNames(
|
|
|
- "layoutLRowBoxRow",
|
|
|
- path === v2.path ? "active" : ""
|
|
|
- )}
|
|
|
- onClick={() => pathCutFu(v2.path)}
|
|
|
- >
|
|
|
- {v2.name}
|
|
|
- </div>
|
|
|
- ))}
|
|
|
+ <div className='layoutLRowBoxTxt'>{v.name}</div>
|
|
|
+ {v.son
|
|
|
+ .filter(c => !c.noShow)
|
|
|
+ .map(v2 => (
|
|
|
+ <div
|
|
|
+ key={v2.id}
|
|
|
+ className={classNames('layoutLRowBoxRow', path === v2.path ? 'active' : '')}
|
|
|
+ onClick={() => pathCutFu(v2.path)}
|
|
|
+ >
|
|
|
+ {v2.name}
|
|
|
+ </div>
|
|
|
+ ))}
|
|
|
</div>
|
|
|
))}
|
|
|
</div>
|
|
|
</div>
|
|
|
{/* 右边 */}
|
|
|
- <div className="layoutRight">
|
|
|
- <div className="layoutRightTop">
|
|
|
+ <div className='layoutRight'>
|
|
|
+ <div className='layoutRightTop'>
|
|
|
{/* 用户相关 */}
|
|
|
- <div className="user">
|
|
|
- {userName || "匿名"}
|
|
|
- <div className="userInco userInco1">
|
|
|
+ <div className='user'>
|
|
|
+ {userName || '匿名'}
|
|
|
+ <div className='userInco userInco1'>
|
|
|
<CaretUpOutlined rev={undefined} />
|
|
|
</div>
|
|
|
- <div className="userInco userInco2">
|
|
|
+ <div className='userInco userInco2'>
|
|
|
<CaretDownOutlined rev={undefined} />
|
|
|
</div>
|
|
|
- <div className="userSet">
|
|
|
+ <div className='userSet'>
|
|
|
<div>
|
|
|
<span onClick={() => setOpen(true)}>修改密码</span>
|
|
|
<Popconfirm
|
|
|
- placement="bottom"
|
|
|
- title="确定退出吗?"
|
|
|
- okText="确定"
|
|
|
- cancelText="取消"
|
|
|
+ placement='bottom'
|
|
|
+ title='确定退出吗?'
|
|
|
+ okText='确定'
|
|
|
+ cancelText='取消'
|
|
|
onConfirm={loginExit}
|
|
|
okButtonProps={{ loading: false }}
|
|
|
>
|
|
@@ -203,16 +201,16 @@ function Layout() {
|
|
|
</div>
|
|
|
</div>
|
|
|
{/* 右边主体 */}
|
|
|
- <div className="layoutRightMain">
|
|
|
+ <div className='layoutRightMain'>
|
|
|
{/* 二级路由页面 */}
|
|
|
- <div className="mainBoxR">
|
|
|
+ <div className='mainBoxR'>
|
|
|
<React.Suspense fallback={<SpinLoding />}>
|
|
|
<Switch>
|
|
|
- {RouterCom.map((v) => (
|
|
|
+ {RouterCom.map(v => (
|
|
|
<AuthRoute key={v.id} exact path={v.path} component={v.Com} />
|
|
|
))}
|
|
|
|
|
|
- <Route path="*" component={NotFound} />
|
|
|
+ <Route path='*' component={NotFound} />
|
|
|
</Switch>
|
|
|
</React.Suspense>
|
|
|
</div>
|
|
@@ -223,7 +221,7 @@ function Layout() {
|
|
|
<Modal
|
|
|
destroyOnClose
|
|
|
open={open}
|
|
|
- title="修改密码"
|
|
|
+ title='修改密码'
|
|
|
onCancel={() => setOpen(false)}
|
|
|
footer={
|
|
|
[] // 设置footer为空,去掉 取消 确定默认按钮
|
|
@@ -231,41 +229,41 @@ function Layout() {
|
|
|
>
|
|
|
<Form
|
|
|
scrollToFirstError={true}
|
|
|
- name="basic"
|
|
|
+ name='basic'
|
|
|
labelCol={{ span: 5 }}
|
|
|
wrapperCol={{ span: 16 }}
|
|
|
onFinish={onFinish}
|
|
|
- autoComplete="off"
|
|
|
+ autoComplete='off'
|
|
|
>
|
|
|
<Form.Item
|
|
|
- label="旧密码"
|
|
|
- name="oldPassword"
|
|
|
- rules={[{ required: true, message: "不能为空!" }]}
|
|
|
- getValueFromEvent={(e) => e.target.value.replace(/\s+/g, "")}
|
|
|
+ label='旧密码'
|
|
|
+ name='oldPassword'
|
|
|
+ rules={[{ required: true, message: '不能为空!' }]}
|
|
|
+ getValueFromEvent={e => e.target.value.replace(/\s+/g, '')}
|
|
|
>
|
|
|
<Input.Password maxLength={20} />
|
|
|
</Form.Item>
|
|
|
|
|
|
<Form.Item
|
|
|
- label="新密码"
|
|
|
- name="newPassword"
|
|
|
+ label='新密码'
|
|
|
+ name='newPassword'
|
|
|
rules={[
|
|
|
- { required: true, message: "不能为空!" },
|
|
|
- { min: 6, max: 15, message: "密码长度为6-15个字符!" },
|
|
|
+ { required: true, message: '不能为空!' },
|
|
|
+ { min: 6, max: 15, message: '密码长度为6-15个字符!' }
|
|
|
]}
|
|
|
- getValueFromEvent={(e) => e.target.value.replace(/\s+/g, "")}
|
|
|
+ getValueFromEvent={e => e.target.value.replace(/\s+/g, '')}
|
|
|
>
|
|
|
<Input.Password
|
|
|
maxLength={15}
|
|
|
- onChange={(e) => (oldPasswordValue.current = e.target.value)}
|
|
|
+ onChange={e => (oldPasswordValue.current = e.target.value)}
|
|
|
/>
|
|
|
</Form.Item>
|
|
|
|
|
|
<Form.Item
|
|
|
- label="确定新密码"
|
|
|
- name="checkPass"
|
|
|
+ label='确定新密码'
|
|
|
+ name='checkPass'
|
|
|
rules={[{ validator: checkPassWord }]}
|
|
|
- getValueFromEvent={(e) => e.target.value.replace(/\s+/g, "")}
|
|
|
+ getValueFromEvent={e => e.target.value.replace(/\s+/g, '')}
|
|
|
>
|
|
|
<Input.Password maxLength={15} />
|
|
|
</Form.Item>
|
|
@@ -273,16 +271,16 @@ function Layout() {
|
|
|
<Form.Item wrapperCol={{ offset: 14, span: 16 }}>
|
|
|
<Button onClick={() => setOpen(false)}>取消</Button>
|
|
|
 
|
|
|
- <Button type="primary" htmlType="submit">
|
|
|
+ <Button type='primary' htmlType='submit'>
|
|
|
确定
|
|
|
</Button>
|
|
|
</Form.Item>
|
|
|
</Form>
|
|
|
</Modal>
|
|
|
</div>
|
|
|
- );
|
|
|
+ )
|
|
|
}
|
|
|
|
|
|
// 使用 React.memo 来优化组件,避免组件的无效更新,类似 类组件里面的PureComponent
|
|
|
-const MemoLayout = React.memo(Layout);
|
|
|
-export default MemoLayout;
|
|
|
+const MemoLayout = React.memo(Layout)
|
|
|
+export default MemoLayout
|