Compare commits
2 Commits
711262a097
...
e3fd214f4a
| Author | SHA1 | Date | |
|---|---|---|---|
| e3fd214f4a | |||
| 4b30915a10 |
@ -3,13 +3,13 @@ import React from 'react'
|
|||||||
import { connect } from 'dva'
|
import { connect } from 'dva'
|
||||||
// 组件库
|
// 组件库
|
||||||
import { Modal, Form, Input, InputNumber, message, Tabs, Button, Row, Col } from 'antd'
|
import { Modal, Form, Input, InputNumber, message, Tabs, Button, Row, Col } from 'antd'
|
||||||
import { LayoutCard, AlarmNotice } from '@woowalker/feui'
|
import { LayoutCard, AlarmNotice } from '../../feui'
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
import FormPage from '../FormPage'
|
import FormPage from '../FormPage'
|
||||||
import ListPage from '../Table/ListPage'
|
import ListPage from '../Table/ListPage'
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
import editPage from '../../models/editPage'
|
import editPage from '../../models/editPage'
|
||||||
import { Socket } from '@woowalker/feui'
|
import { Socket } from '../../feui'
|
||||||
import config from '../../config'
|
import config from '../../config'
|
||||||
// 样式
|
// 样式
|
||||||
import styles from './edit.css'
|
import styles from './edit.css'
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import React, { useState, useEffect, useRef } from 'react'
|
import React, { useState, useEffect, useRef } from 'react'
|
||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import { connect } from 'dva'
|
import { connect } from 'dva'
|
||||||
import { Icon, Badge } from 'antd'
|
import { Icon, Badge, Modal } from 'antd'
|
||||||
import { Scrollbars } from 'react-custom-scrollbars'
|
import { Scrollbars } from 'react-custom-scrollbars'
|
||||||
import IFComponent from '../common/IFComponent'
|
import IFComponent from '../common/IFComponent'
|
||||||
import Socket from '../utils/socket'
|
import Socket from '../utils/socket'
|
||||||
@ -14,6 +14,12 @@ function AlarmNotice (props) {
|
|||||||
TotalCount: 0,
|
TotalCount: 0,
|
||||||
Message: ''
|
Message: ''
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const loginRef = useRef(props.login)
|
||||||
|
useEffect(() => {
|
||||||
|
loginRef.current = props.login
|
||||||
|
}, [props.login])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let timer = -1
|
let timer = -1
|
||||||
if (msg && !msg.TotalCount && !msg.Message && visible) {
|
if (msg && !msg.TotalCount && !msg.Message && visible) {
|
||||||
@ -36,6 +42,7 @@ function AlarmNotice (props) {
|
|||||||
if (UserId && OrgId) {
|
if (UserId && OrgId) {
|
||||||
const socketIns = new Socket({
|
const socketIns = new Socket({
|
||||||
url: props.webSocketHost,
|
url: props.webSocketHost,
|
||||||
|
autoReconnect: true,
|
||||||
onopen: handleSocketOpened,
|
onopen: handleSocketOpened,
|
||||||
onmessage: handleSocketOnMsg
|
onmessage: handleSocketOnMsg
|
||||||
})
|
})
|
||||||
@ -48,7 +55,7 @@ function AlarmNotice (props) {
|
|||||||
}, [props.login.userId, props.login.OrgId, props.login.Tenant])
|
}, [props.login.userId, props.login.OrgId, props.login.Tenant])
|
||||||
|
|
||||||
const handleSocketOpened = (socketIns) => {
|
const handleSocketOpened = (socketIns) => {
|
||||||
const { user, userId: UserId, OrgId, Tenant } = props.login
|
const { user, userId: UserId, OrgId, Tenant } = loginRef.current
|
||||||
const openedPayload = {
|
const openedPayload = {
|
||||||
TypeCode: 'P0001',
|
TypeCode: 'P0001',
|
||||||
Tenant,
|
Tenant,
|
||||||
@ -56,6 +63,7 @@ function AlarmNotice (props) {
|
|||||||
UserId,
|
UserId,
|
||||||
UserName: user.NAME,
|
UserName: user.NAME,
|
||||||
OrgId,
|
OrgId,
|
||||||
|
Tenant,
|
||||||
ClientType: 0
|
ClientType: 0
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -65,16 +73,37 @@ function AlarmNotice (props) {
|
|||||||
|
|
||||||
const handleSocketOnMsg = (data) => {
|
const handleSocketOnMsg = (data) => {
|
||||||
if (data) {
|
if (data) {
|
||||||
|
console.log('收到消息', data)
|
||||||
const { TypeCode, Data } = JSON.parse(data)
|
const { TypeCode, Data } = JSON.parse(data)
|
||||||
if (TypeCode === 'M0003' && Data) {
|
if (TypeCode === 'M0003' && Data) {
|
||||||
Data.Message && !isEqual(Data.Message, refOfMsg.current.Message) && !visible && setVisible(true)
|
Data.Message && !isEqual(Data.Message, refOfMsg.current.Message) && !visible && setVisible(true)
|
||||||
setMsg(Data)
|
setMsg(Data)
|
||||||
|
} else if (TypeCode === 'MQ02') {
|
||||||
|
console.log('触发权限变更通知', data)
|
||||||
|
Modal.warning({
|
||||||
|
title: '权限变更通知',
|
||||||
|
content: '当前用户权限已变更!',
|
||||||
|
okText: '确认',
|
||||||
|
onOk: () => {
|
||||||
|
const { userId, OrgId, Tenant } = loginRef.current
|
||||||
|
props.dispatch({
|
||||||
|
type: 'login/getLoginInfo',
|
||||||
|
payload: {
|
||||||
|
UserId: userId,
|
||||||
|
OrgId,
|
||||||
|
Tenant,
|
||||||
|
onlyData: false,
|
||||||
|
noReload: true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleSocketSendMsg = (Data, socketIns) => {
|
const handleSocketSendMsg = (Data, socketIns) => {
|
||||||
const { userId: UserId, OrgId, Tenant } = props.login
|
const { userId: UserId, OrgId, Tenant } = loginRef.current
|
||||||
// 这里 Data 需要 JSON.stringify(Data) 是因为后端限制
|
// 这里 Data 需要 JSON.stringify(Data) 是因为后端限制
|
||||||
const payload = { TypeCode: 'M0003', Tenant, Data: JSON.stringify({ UserId, OrgId, ...Data }) }
|
const payload = { TypeCode: 'M0003', Tenant, Data: JSON.stringify({ UserId, OrgId, ...Data }) }
|
||||||
socketIns = socketIns || socket.current
|
socketIns = socketIns || socket.current
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import React, { useState, useMemo, useEffect } from 'react';
|
|||||||
import { connect } from 'dva';
|
import { connect } from 'dva';
|
||||||
import { withRouter } from 'dva/router';
|
import { withRouter } from 'dva/router';
|
||||||
import { Dropdown, Icon, Menu, message, Button, Modal } from 'antd';
|
import { Dropdown, Icon, Menu, message, Button, Modal } from 'antd';
|
||||||
import { HeaderSearch as OPTSearch, PictureThumb } from '@woowalker/feui';
|
import { HeaderSearch as OPTSearch, PictureThumb } from '../feui';
|
||||||
import ModifyPassword from '../components/MainPage/ModifyPassword';
|
import ModifyPassword from '../components/MainPage/ModifyPassword';
|
||||||
import FoUserInfoShow from '../components/MainPage/FoUserInfoShow';
|
import FoUserInfoShow from '../components/MainPage/FoUserInfoShow';
|
||||||
import FeedbackQuestion from '../components/MainPage/FeedbackQuestion';
|
import FeedbackQuestion from '../components/MainPage/FeedbackQuestion';
|
||||||
|
|||||||
@ -64,7 +64,7 @@ class Main extends React.Component {
|
|||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
{matchBackend ? <BackendLayout {...this.props} /> : <MainLayout {...this.props} />}
|
{matchBackend ? <BackendLayout {...this.props} /> : <MainLayout {...this.props} />}
|
||||||
{/* 去掉首页报警框 */}
|
{/* 去掉首页报警框 */}
|
||||||
{/* {matchLogin ? null : <AlarmEditModal />} */}
|
{matchLogin ? null : <AlarmEditModal />}
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -245,6 +245,144 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
// 登录、获取信息
|
// 登录、获取信息
|
||||||
|
*getLoginInfo({ payload, loginPayload }, { call, put, select }) {
|
||||||
|
const loginUserVerify = storage("lacal").getItem("loginUserVerify").val || {};
|
||||||
|
const { username, password } = loginUserVerify;
|
||||||
|
const webOrgId = storage("lacal").getItem("webOrgId").val;
|
||||||
|
const formConfigVersion = storage("lacal").getItem("formConfigVersion").val;
|
||||||
|
|
||||||
|
const newPayload = {
|
||||||
|
...payload,
|
||||||
|
Parameter1: payload.Parameter1 || username,
|
||||||
|
Parameter2: payload.Parameter2 || password,
|
||||||
|
Parameter4: payload.Parameter4 || webOrgId,
|
||||||
|
Parameter5: payload.Parameter5 || formConfigVersion,
|
||||||
|
Parameter7: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
const ret = yield call(appService.getLoginInfo, newPayload);
|
||||||
|
if (ret) {
|
||||||
|
if (loginPayload) {
|
||||||
|
const {
|
||||||
|
accessToken,
|
||||||
|
refreshToken,
|
||||||
|
expiresIn,
|
||||||
|
username,
|
||||||
|
password,
|
||||||
|
userid,
|
||||||
|
} = loginPayload;
|
||||||
|
storage("lacal").setItem("accessToken", accessToken); // access_token存入localStorage
|
||||||
|
storage("lacal").setItem("refreshToken", refreshToken);
|
||||||
|
storage("lacal").setItem("expiresIn", expiresIn);
|
||||||
|
storage("lacal").setItem("refreshTimestamp", new Date().getTime());
|
||||||
|
storage("lacal").setItem("userid", userid);
|
||||||
|
storage("lacal").setItem("loginUserVerify", { username, password }); // 登录凭证存入localStorage
|
||||||
|
}
|
||||||
|
storage("lacal").setItem("webOrgId", ret.User.ORG_ID);
|
||||||
|
storage("lacal").setItem("webUserInfo", ret.User);
|
||||||
|
storage("lacal").setItem("DataRule", ret.DataRule || []);
|
||||||
|
storage("lacal").setItem("OrgRule", ret.OrgRule || []);
|
||||||
|
storage("lacal").setItem("departmentId", ret.User.DEPARTMENT_ID);
|
||||||
|
storage("lacal").setItem("MineType", ret.User.MineType);
|
||||||
|
storage("lacal").setItem("UserType", ret.UserType);
|
||||||
|
storage("lacal").setItem("baseConfig", ret.BaseConfig);
|
||||||
|
storage("lacal").setItem("roles", ret.Roles || []);
|
||||||
|
storage("lacal").setItem("rolePerm", ret.Nav_RolePerm || {});
|
||||||
|
const localStorage = window.localStorage;
|
||||||
|
ret.FormConfigVersion &&
|
||||||
|
storage("lacal").setItem("formConfigVersion", ret.FormConfigVersion);
|
||||||
|
// 拍平 Menus
|
||||||
|
const flatMenus = [];
|
||||||
|
const copyMenus = cloneDeep(ret.Menus);
|
||||||
|
recurseMenu(copyMenus, undefined, flatMenus);
|
||||||
|
ret.Menus = copyMenus;
|
||||||
|
const safeFlatMenus = flatMenus.map(m => ({ ID: m.ID, NAME: m.NAME, CODE: m.CODE, MENU_LEVEL: m.MENU_LEVEL, idLevels: m.idLevels, nameLevels: m.nameLevels, menuLevels: m.menuLevels, Nav_MenuForm: m.Nav_MenuForm, IS_RESIDENT: m.IS_RESIDENT, ICON: m.ICON, IS_BACKEND: m.IS_BACKEND, MineType: m.MineType }));
|
||||||
|
const pruneMenus = (arr) => arr.map(it => ({ Node: { ID: it.Node.ID, NAME: it.Node.NAME, CODE: it.Node.CODE, MENU_LEVEL: it.Node.MENU_LEVEL, MineType: it.Node.MineType, Nav_MenuForm: it.Node.Nav_MenuForm, IS_RESIDENT: it.Node.IS_RESIDENT, ICON: it.Node.ICON, IS_BACKEND: it.Node.IS_BACKEND }, Children: (it.Children && it.Children.length) ? pruneMenus(it.Children) : [] }));
|
||||||
|
const safeMenus = pruneMenus(copyMenus);
|
||||||
|
storage("lacal").setItem("menus", safeMenus);
|
||||||
|
storage("lacal").setItem("flatMenus", safeFlatMenus);
|
||||||
|
|
||||||
|
const currentMineType = localStorage.getItem("currentMineType");
|
||||||
|
if (currentMineType) {
|
||||||
|
storage("lacal").setItem("currentMineType", currentMineType);
|
||||||
|
var filterObj = function (item) {
|
||||||
|
if (item.Node.MineType && item.Node.MineType.indexOf("_" + currentMineType + "_") > -1) {
|
||||||
|
if (item.Children.length !== 0) {
|
||||||
|
item.Children = item.Children.filter(function (child) {
|
||||||
|
if (child.Children.length !== 0) {
|
||||||
|
return filterObj(child);
|
||||||
|
} else {
|
||||||
|
if (child.Node.MineType) {
|
||||||
|
return child.Node.MineType.indexOf("_" + currentMineType + "_") > -1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (item.Children.length > 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (item.Node.MineType) {
|
||||||
|
return item.Node.MineType.indexOf("_" + currentMineType + "_") > -1;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
var filter = ret.Menus.filter(function (item) {
|
||||||
|
return filterObj(item);
|
||||||
|
});
|
||||||
|
|
||||||
|
ret.Menus = filter;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 存储 model state
|
||||||
|
yield put({
|
||||||
|
type: "save",
|
||||||
|
payload: {
|
||||||
|
loginInfo: ret,
|
||||||
|
OrgId: ret.User.ORG_ID,
|
||||||
|
OrgCode: ret.User.Nav_Org ? ret.User.Nav_Org.CODE : "",
|
||||||
|
baseConfig: ret.BaseConfig,
|
||||||
|
userType: ret.UserType,
|
||||||
|
currentMineType: currentMineType,
|
||||||
|
roles: ret.Roles,
|
||||||
|
rolePerm: ret.Nav_RolePerm,
|
||||||
|
userId: ret.User.ID,
|
||||||
|
user: ret.User,
|
||||||
|
flatMenus,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
// 不是很清楚为什么这里要清除这个 requestKey
|
||||||
|
// const localStorage = window.localStorage
|
||||||
|
if (localStorage) {
|
||||||
|
for (let i = 0; i < localStorage.length; i++) {
|
||||||
|
const key = localStorage.key(i);
|
||||||
|
if (key.indexOf("_requestKey") > -1) {
|
||||||
|
localStorage.removeItem(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 获取消息提醒
|
||||||
|
const getNoticesParams = initFilter(
|
||||||
|
ret.User.ORG_ID,
|
||||||
|
"",
|
||||||
|
"CREATE_TIME",
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
ret.User.ID
|
||||||
|
);
|
||||||
|
yield put({ type: "getNotices", payload: getNoticesParams });
|
||||||
|
|
||||||
|
// 刷新页面以应用新的权限
|
||||||
|
if (!payload.noReload) {
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
},
|
||||||
|
// 登录、获取信息
|
||||||
*toLogin({ payload, loginPayload }, { call, put, select }) {
|
*toLogin({ payload, loginPayload }, { call, put, select }) {
|
||||||
const ret = yield call(appService.getLoginInfo, payload);
|
const ret = yield call(appService.getLoginInfo, payload);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
|
|||||||
@ -17,7 +17,7 @@ export function request(url, options, onlyData, requestKey, onException) {
|
|||||||
if (response.status === 401) {
|
if (response.status === 401) {
|
||||||
window.localStorage.removeItem('accessToken')
|
window.localStorage.removeItem('accessToken')
|
||||||
history.replace({ pathname: '/login' })
|
history.replace({ pathname: '/login' })
|
||||||
throw new Error('token过期')
|
//throw new Error('token过期')
|
||||||
}
|
}
|
||||||
requestKey && window.localStorage.removeItem(requestKey)
|
requestKey && window.localStorage.removeItem(requestKey)
|
||||||
return response.json()
|
return response.json()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user