diff --git a/.vscode/launch.json b/.vscode/launch.json index dd08d4d..8547588 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -43,7 +43,7 @@ //南昌研发结束 // 镇江研发开始 "-g postgres://FashionAdmin:123456@10.8.30.36:5432/data_center", - "--redisHost localhost", + "--redisHost 10.8.30.112", "--redisPort 6379", "--apiEmisUrl http://10.8.30.161:1111", // 镇江研发结束 diff --git a/web/client/src/layout/containers/layout/index.jsx b/web/client/src/layout/containers/layout/index.jsx index 9c7eb26..2a79c2f 100644 --- a/web/client/src/layout/containers/layout/index.jsx +++ b/web/client/src/layout/containers/layout/index.jsx @@ -10,9 +10,13 @@ import { resize } from '../../actions/global'; import * as NProgress from 'nprogress'; import PerfectScrollbar from 'perfect-scrollbar'; import { useLocation } from "react-router"; +import { RouteTable } from '$utils'; +import { RouteRequest } from '@peace/utils'; +import Cookie from 'js-cookie'; +import { login, LOGIN_SUCCESS } from '../../../sections/auth/actions/auth'; NProgress.configure({ - template: ` + template: `
@@ -23,303 +27,352 @@ NProgress.configure({ }); let scrollbar +let requestUser = true +let requestlogout = false; + // const location111 = useLocation(); const LayoutContainer = props => { - const { - dispatch, msg, user, copyright, children, sections, clientWidth, clientHeight, - location, match, routes, history, socket, - } = props - const [collapsed, setCollapsed] = useState(false) + const { + dispatch, msg, user, copyright, children, sections, clientWidth, clientHeight, + location, match, routes, history, socket, apiRoot + } = props + const [collapsed, setCollapsed] = useState(false) - NProgress.start(); + NProgress.start(); - const resize_ = () => { - dispatch(resize( - document.getElementById('DrApp').clientHeight, - document.getElementById('DrApp').clientWidth - (collapsed ? 120 : 240) - )); - } - function deepCopy(data) {//深拷贝 - //string,number,bool,null,undefined,symbol - //object,array,date - if (data && typeof data === "object") { - //针对函数的拷贝 - if (typeof data === "function") { - let tempFunc = data.bind(null); - tempFunc.prototype = deepCopy(data.prototype); - return tempFunc; - } + const resize_ = () => { + dispatch(resize( + document.getElementById('DrApp').clientHeight, + document.getElementById('DrApp').clientWidth - (collapsed ? 120 : 240) + )); + } + function deepCopy (data) {//深拷贝 + //string,number,bool,null,undefined,symbol + //object,array,date + if (data && typeof data === "object") { + //针对函数的拷贝 + if (typeof data === "function") { + let tempFunc = data.bind(null); + tempFunc.prototype = deepCopy(data.prototype); + return tempFunc; + } - switch (Object.prototype.toString.call(data)) { - case "[object String]": - return data.toString(); - case "[object Number]": - return Number(data.toString()); - case "[object Boolean]": - return new Boolean(data.toString()); - case "[object Date]": - return new Date(data.getTime()); - case "[object Array]": - var arr = []; - for (let i = 0; i < data.length; i++) { - arr[i] = deepCopy(data[i]); - } - return arr; + switch (Object.prototype.toString.call(data)) { + case "[object String]": + return data.toString(); + case "[object Number]": + return Number(data.toString()); + case "[object Boolean]": + return new Boolean(data.toString()); + case "[object Date]": + return new Date(data.getTime()); + case "[object Array]": + var arr = []; + for (let i = 0; i < data.length; i++) { + arr[i] = deepCopy(data[i]); + } + return arr; - //js自带对象或用户自定义类实例 - case "[object Object]": - var obj = {}; - for (let key in data) { - //会遍历原型链上的属性方法,可以用hasOwnProperty来控制 (obj.hasOwnProperty(prop) - obj[key] = deepCopy(data[key]); - } - return obj; - } - } else { - //string,number,bool,null,undefined,symbol - return data; - } - } - const [allItems, setAllItems] = useState([]) - // const [headerItems, setHeaderItems] = useState([]) - const [leftItems, setLeftItems] = useState([]) - const [leftChange, setLeftChange] = useState(true) - const [leftShow, setLeftShow] = useState(false) - useEffect(() => { - let topItems = []//头部导航 - const lastSelectedKeys = localStorage.getItem('poms_selected_sider') - let nextItems = []//所有导航 - for (let c of sections) { - if (typeof c.getNavItem == 'function') { - let item = c.getNavItem(user, dispatch); - if (item) { - nextItems.push.apply(nextItems, item) - if (item.length > 0) { - for (let j = 0; j < item.length; j++) { - let itm = deepCopy(item[j]); - if (itm.hasOwnProperty('items')) { - for (let i = 0; i < itm.items.length; i++) { - itm.items[i].fatherKey = itm.itemKey - delete itm.items[i].items - } - // topItems.push(itm) - // } - // else { - // topItems.push.apply(topItems, item) - } + //js自带对象或用户自定义类实例 + case "[object Object]": + var obj = {}; + for (let key in data) { + //会遍历原型链上的属性方法,可以用hasOwnProperty来控制 (obj.hasOwnProperty(prop) + obj[key] = deepCopy(data[key]); + } + return obj; + } + } else { + //string,number,bool,null,undefined,symbol + return data; + } + } + const [allItems, setAllItems] = useState([]) + // const [headerItems, setHeaderItems] = useState([]) + const [leftItems, setLeftItems] = useState([]) + const [leftChange, setLeftChange] = useState(true) + const [leftShow, setLeftShow] = useState(false) + useEffect(() => { + let topItems = []//头部导航 + const lastSelectedKeys = localStorage.getItem('poms_selected_sider') + let nextItems = []//所有导航 + for (let c of sections) { + if (typeof c.getNavItem == 'function') { + let item = c.getNavItem(user, dispatch); + if (item) { + nextItems.push.apply(nextItems, item) + if (item.length > 0) { + for (let j = 0; j < item.length; j++) { + let itm = deepCopy(item[j]); + if (itm.hasOwnProperty('items')) { + for (let i = 0; i < itm.items.length; i++) { + itm.items[i].fatherKey = itm.itemKey + delete itm.items[i].items } - } - } + // topItems.push(itm) + // } + // else { + // topItems.push.apply(topItems, item) + } + } + } } - } - setAllItems(nextItems) - // setHeaderItems(topItems) - if (lastSelectedKeys) {//如果有缓存 - for (let i = 0; i < nextItems.length; i++) { - if (JSON.parse(lastSelectedKeys)[0] == nextItems[i].itemKey) { + } + } + setAllItems(nextItems) + // setHeaderItems(topItems) + if (lastSelectedKeys) {//如果有缓存 + for (let i = 0; i < nextItems.length; i++) { + if (JSON.parse(lastSelectedKeys)[0] == nextItems[i].itemKey) { - // let openArr = [] - // for (let j = 0; j < nextItems[i].items.length; j++) { - // openArr.push(nextItems[i].items[j].itemKey) - // } - // localStorage.setItem('poms_open_sider', JSON.stringify(openArr)) - setLeftItems(nextItems[i].items) - } + // let openArr = [] + // for (let j = 0; j < nextItems[i].items.length; j++) { + // openArr.push(nextItems[i].items[j].itemKey) + // } + // localStorage.setItem('poms_open_sider', JSON.stringify(openArr)) + setLeftItems(nextItems[i].items) } - setLeftShow(true) - } - else { - setLeftShow(false) - } + } + setLeftShow(true) + } + else { + setLeftShow(false) + } - window.addEventListener('resize', resize_); - return () => { - window.removeEventListener('resize', resize_); - } - }, []) + window.addEventListener('resize', resize_); + return () => { + window.removeEventListener('resize', resize_); + } + }, []) - useEffect(() => { - let pathnameArr = location.pathname.split('/') - let openArr = [] - for (let i = 0; i < allItems.length; i++) { - if (allItems[i].items) { - for (let j = 0; j < allItems[i].items.length; j++) { - if (allItems[i].items[j].items) { - for (let k = 0; k < allItems[i].items[j].items.length; k++) { - if (allItems[i].items[j].items[k].to == location.pathname) { - for (let o = 0; o < allItems[i].items.length; o++) { - openArr.push(allItems[i].items[o].itemKey) - } - localStorage.setItem('poms_selected_sider', JSON.stringify([pathnameArr[1]])) - // localStorage.setItem('poms_open_sider', JSON.stringify(openArr)) - setLeftItems(allItems[i].items) - setLeftShow(true) - } + useEffect(() => { + let pathnameArr = location.pathname.split('/') + let openArr = [] + for (let i = 0; i < allItems.length; i++) { + if (allItems[i].items) { + for (let j = 0; j < allItems[i].items.length; j++) { + if (allItems[i].items[j].items) { + for (let k = 0; k < allItems[i].items[j].items.length; k++) { + if (allItems[i].items[j].items[k].to == location.pathname) { + for (let o = 0; o < allItems[i].items.length; o++) { + openArr.push(allItems[i].items[o].itemKey) } - } - } + localStorage.setItem('poms_selected_sider', JSON.stringify([pathnameArr[1]])) + // localStorage.setItem('poms_open_sider', JSON.stringify(openArr)) + setLeftItems(allItems[i].items) + setLeftShow(true) + } + } + } } - } - }, [location]) + } + } + }, [location]) - useEffect(() => { - NProgress.done(); - if ((!user || !user.authorized)) { - history.push('/signin'); - } - if (msg) { - if (msg.done) { - Notification.success({ - // title: msg.done, - content: msg.done, - duration: 2, - }) - } - if (msg.error) { - Notification.error({ - // title: msg.error, - content: msg.error, - duration: 2, - }) - } - } - const dom = document.getElementById('page-content'); - if (dom) { - if (!scrollbar) { - scrollbar = new PerfectScrollbar('#page-content', { suppressScrollX: true }); - scrollbar.update(); - } else { - scrollbar.update(); - dom.scrollTop = 0; - } - } - }) + useEffect(() => { + NProgress.done(); + if ((!user || !user.authorized)) { + // history.push('/signin'); + getUserInfoByToken() + } + if (msg) { + if (msg.done) { + Notification.success({ + // title: msg.done, + content: msg.done, + duration: 2, + }) + } + if (msg.error) { + Notification.error({ + // title: msg.error, + content: msg.error, + duration: 2, + }) + } + } + const dom = document.getElementById('page-content'); + if (dom) { + if (!scrollbar) { + scrollbar = new PerfectScrollbar('#page-content', { suppressScrollX: true }); + scrollbar.update(); + } else { + scrollbar.update(); + dom.scrollTop = 0; + } + } + }) + const getUserInfoByToken = () => { + if (requestUser) { + requestUser = false; + RouteRequest.get(RouteTable.getDomain).then(res => { + console.log(res); + let token = Cookie.get('pepToken', { domain: res.root }); + dispatch(login({ token })).then(res => { + if (res.type == 'LOGIN_SUCCESS') { + const data = res.payload?.user || {} + dispatch(push('/businessManagement/pmReport/reserveItemsReporting')); + localStorage.setItem('poms_open_sider', JSON.stringify(["pmReport"])) + localStorage.setItem('poms_selected_sider', JSON.stringify(["businessManagement"])) + localStorage.setItem('word', JSON.stringify('')) //系统登录代码时候存的,不清楚意义 + dispatch(actions.layout.initWebSocket({ ioUrl: apiRoot, token: data.token, hrUserId: data.hrUserInfo && hrUserInfo.id })) + } else { + redirectToLogin(true); + } + }, error => { + redirectToLogin(true); + }) + }, error => { + message.error('鉴权失败', 5); + redirectToLogin(true); + }) + } + } - // websocket 使用测试 - useEffect(() => { - // console.log(socket) - if (socket) { - socket.on('CAMERA_ONLINE', function (msg) { - console.info(msg); - if (msg.online == 'ON') { - Notification.success({ - title: 'Hi', - content: (
{msg.name}
已上线。
), - duration: 2, - }) - } - if (msg.online == 'OFF') { - Notification.error({ - title: 'Hi', - content: (
{msg.name}
发生离线。
), - duration: 2, - }) - } - }); - return () => { - socket.off("CAMERA_ONLINE"); + const redirectToLogin = (toLogin = false) => { + //重定位至大平台的登录页 + if (!requestlogout) { + requestlogout = true;//目的执行一遍。退出登录后,redirectToLogin执行两遍,注释window.location.href,可message.warning验证 + RouteRequest.get(RouteTable.getPepWebUrl).then(res => { + if (res.url) { + if (toLogin) { + window.location.href = `${res.url}/signin`; + } + else { + window.location.href = `${res.url}/signin?isLogout=true`; + } } - } - }, [socket]) + }); + } + } - return ( - - { - <> - -
{ - setCollapsed(!collapsed); - }} - collapsed={collapsed} - history={history} - tochange={(val) => { - // setLeftChange(!leftChange) //会导致顶部右上角转小圈 - if (val.fatherKey) { - localStorage.setItem('poms_selected_sider', JSON.stringify([val.itemKey])); - const historyOpenKeys = localStorage.getItem('poms_open_sider'); - const openKeys = historyOpenKeys && JSON.parse(historyOpenKeys).concat(val.openKey || val.itemKey) || [val.openKey || val.itemKey] - localStorage.setItem('poms_open_sider', JSON.stringify(openKeys)); - // for (let i = 0; i < allItems.length; i++) { - // if (val.fatherKey == allItems[i].itemKey) { - // let openArr = [] - // for (let j = 0; j < allItems[i].items.length; j++) { - // openArr.push(allItems[i].items[j].itemKey) - // } - // localStorage.setItem('poms_selected_sider', JSON.stringify([val.fatherKey])) - // localStorage.setItem('poms_open_sider', JSON.stringify(openArr)) - // setLeftItems(allItems[i].items) - // } - // } - // setLeftShow(true) - } - else { - localStorage.setItem('poms_open_sider', JSON.stringify([])) - localStorage.removeItem('poms_selected_sider') - // setLeftShow(false) - } - history.push(val.to); - }} - /> - - - {leftShow ? ( - - ) : ('')} - -
-
-
- {children} -
- -
- -
-
-
-
- + + // websocket 使用测试 + useEffect(() => { + // console.log(socket) + if (socket) { + socket.on('CAMERA_ONLINE', function (msg) { + console.info(msg); + if (msg.online == 'ON') { + Notification.success({ + title: 'Hi', + content: (
{msg.name}
已上线。
), + duration: 2, + }) + } + if (msg.online == 'OFF') { + Notification.error({ + title: 'Hi', + content: (
{msg.name}
发生离线。
), + duration: 2, + }) } - - ) + }); + return () => { + socket.off("CAMERA_ONLINE"); + } + } + }, [socket]) + + return ( + + { + <> + +
{ + setCollapsed(!collapsed); + }} + collapsed={collapsed} + history={history} + tochange={(val) => { + // setLeftChange(!leftChange) //会导致顶部右上角转小圈 + if (val.fatherKey) { + localStorage.setItem('poms_selected_sider', JSON.stringify([val.itemKey])); + const historyOpenKeys = localStorage.getItem('poms_open_sider'); + const openKeys = historyOpenKeys && JSON.parse(historyOpenKeys).concat(val.openKey || val.itemKey) || [val.openKey || val.itemKey] + localStorage.setItem('poms_open_sider', JSON.stringify(openKeys)); + // for (let i = 0; i < allItems.length; i++) { + // if (val.fatherKey == allItems[i].itemKey) { + // let openArr = [] + // for (let j = 0; j < allItems[i].items.length; j++) { + // openArr.push(allItems[i].items[j].itemKey) + // } + // localStorage.setItem('poms_selected_sider', JSON.stringify([val.fatherKey])) + // localStorage.setItem('poms_open_sider', JSON.stringify(openArr)) + // setLeftItems(allItems[i].items) + // } + // } + // setLeftShow(true) + } + else { + localStorage.setItem('poms_open_sider', JSON.stringify([])) + localStorage.removeItem('poms_selected_sider') + // setLeftShow(false) + } + history.push(val.to); + }} + /> + + + {leftShow ? ( + + ) : ('')} + +
+
+
+ {children} +
+ +
+
+
+
+ + } + + ) } -function mapStateToProps(state) { - const { global, auth, ajaxResponse, webSocket } = state; - return { - title: global.title, - copyright: global.copyright, - sections: global.sections, - actions: global.actions, - clientWidth: global.clientWidth, - clientHeight: global.clientHeight, - msg: ajaxResponse.msg, - user: auth.user, - socket: webSocket.socket - }; +function mapStateToProps (state) { + const { global, auth, ajaxResponse, webSocket } = state; + return { + title: global.title, + copyright: global.copyright, + sections: global.sections, + actions: global.actions, + clientWidth: global.clientWidth, + clientHeight: global.clientHeight, + msg: ajaxResponse.msg, + user: auth.user, + socket: webSocket.socket, + apiRoot: global.apiRoot, + }; } export default connect(mapStateToProps)(LayoutContainer); \ No newline at end of file diff --git a/web/client/src/sections/auth/actions/auth.js b/web/client/src/sections/auth/actions/auth.js index afcb759..14d2f8d 100644 --- a/web/client/src/sections/auth/actions/auth.js +++ b/web/client/src/sections/auth/actions/auth.js @@ -4,7 +4,7 @@ import { ApiTable, AxyRequest, EmisRequest } from '$utils' import { Request } from '@peace/utils'; export const INIT_AUTH = 'INIT_AUTH'; -export function initAuth(userData) { +export function initAuth (userData) { const sessionUser = JSON.parse(sessionStorage.getItem('dcUser')) const user = userData || sessionUser || {}; if (user.authorized && !sessionUser) { @@ -21,7 +21,7 @@ export function initAuth(userData) { export const REQUEST_LOGIN = 'REQUEST_LOGIN'; export const LOGIN_SUCCESS = 'LOGIN_SUCCESS'; export const LOGIN_ERROR = 'LOGIN_ERROR'; -export function login(username, password) { +export function login ({ username, password, token }) { return dispatch => { dispatch({ type: REQUEST_LOGIN }); @@ -43,7 +43,7 @@ export function login(username, password) { // }, // }); - return Request.post(ApiTable.login, { username, password, code: 'HR' }) + return Request.post(ApiTable.login, { username, password, token, code: 'HR' }) .then(user => { sessionStorage.setItem('dcUser', JSON.stringify(user)); return dispatch({ @@ -63,7 +63,7 @@ export function login(username, password) { } export const LOGOUT = 'LOGOUT'; -export function logout() { +export function logout () { const user = JSON.parse(sessionStorage.getItem('dcUser')) user && user.token ? Request.put(ApiTable.logout, { diff --git a/web/client/src/utils/webapi.js b/web/client/src/utils/webapi.js index 4b3ee44..8b2a2ce 100644 --- a/web/client/src/utils/webapi.js +++ b/web/client/src/utils/webapi.js @@ -28,5 +28,7 @@ export const RouteTable = { apiRoot: "/api/root", fileUpload: "/_upload/new", cleanUpUploadTrash: "/_upload/cleanup", - getServiceUrl: '/_service/url' + getServiceUrl: '/_service/url', + getDomain: '/domain', + }; diff --git a/web/config.js b/web/config.js index 076ab7c..1e24a34 100644 --- a/web/config.js +++ b/web/config.js @@ -12,6 +12,8 @@ dev && console.log('\x1B[33m%s\x1b[0m', '请遵循并及时更新 readme.md, args.option(['p', 'port'], '启动端口'); args.option(['u', 'api-url'], 'webapi的URL'); args.option('apiHrUrl', 'webapi的URL 外网可访问'); +args.option(['d', 'domain'], 'web domain'); + // 七牛 args.option('qnak', 'qiniuAccessKey'); @@ -24,6 +26,7 @@ const flags = args.parse(process.argv); const API_URL = process.env.API_URL || flags.apiUrl; const API_DC_URL = process.env.API_DC_URL || flags.apiHrUrl; +const FS_REPORT_DOMAIN = process.FS_REPORT_DOMAIN || flags.domain; // 七牛 const ANXINCLOUD_QINIU_AK = process.env.ANXINCLOUD_QINIU_ACCESSKEY || flags.qnak; @@ -76,7 +79,8 @@ const product = { }, service: { url: ANXINCLOUD_PM_SERVICES - } + }, + domain: FS_REPORT_DOMAIN } }, { entry: require('./client').entry,// 静态信息 diff --git a/web/package.json b/web/package.json index a9521a2..c7ed003 100644 --- a/web/package.json +++ b/web/package.json @@ -7,7 +7,7 @@ "test": "mocha", "start-vite": "cross-env NODE_ENV=developmentVite npm run start-params", "start": "cross-env NODE_ENV=development npm run start-params", - "start-params": "node server -p 5700 -u http://localhost:4700 --apiHrUrl http://localhost:4700 --qnak 5XrM4wEB9YU6RQwT64sPzzE6cYFKZgssdP5Kj3uu --qnsk w6j2ixR_i-aelc6I7S3HotKIX-ukMzcKmDfH6-M5 --qnbkt pep-process-report --qndmn https://pepsource.anxinyun.cn --pmrs http://10.8.30.109:14000", + "start-params": "node server -p 5700 -u http://localhost:4700 --apiHrUrl http://localhost:4700 -d localhost --qnak 5XrM4wEB9YU6RQwT64sPzzE6cYFKZgssdP5Kj3uu --qnsk w6j2ixR_i-aelc6I7S3HotKIX-ukMzcKmDfH6-M5 --qnbkt pep-process-report --qndmn https://pepsource.anxinyun.cn --pmrs http://10.8.30.109:14000", "deploy": "export NODE_ENV=production&& npm run build && node server", "build-dev": "cross-env NODE_ENV=development&&webpack --config webpack.config.js", "build": "cross-env NODE_ENV=production&&webpack --config webpack.config.prod.js" @@ -60,6 +60,7 @@ "ezuikit-js": "^0.6.1", "fs-attachment": "^1.0.0", "fs-web-server-scaffold": "^1.0.6", + "js-cookie": "^3.0.1", "js-export-excel": "^1.1.4", "koa-better-http-proxy": "^0.2.5", "koa-proxy": "^1.0.0-alpha.3",