diff --git a/api/.vscode/launch.json b/api/.vscode/launch.json index cfc15dc..3a4a4a3 100644 --- a/api/.vscode/launch.json +++ b/api/.vscode/launch.json @@ -42,7 +42,7 @@ // 测试 "--clickHouseUrl http://10.8.30.161", - "--clickHousePepEmis pepca_dev", + "--clickHousePepEmis pepca8", "--clickHouseCamworkflow camworkflow", "--clickHouseHr hrm", ] diff --git a/web/client/src/layout/containers/layout/index.jsx b/web/client/src/layout/containers/layout/index.jsx index 592b911..3fbd266 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'; + NProgress.configure({ - template: ` + template: `
@@ -23,303 +27,359 @@ NProgress.configure({ }); let scrollbar +let requestUser = true // 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, + } = props + const [collapsed, setCollapsed] = useState(false) - NProgress.start(); + NProgress.start(); - const resize_ = () => { - dispatch(resize( - document.getElementById('HrApp').clientHeight, - document.getElementById('HrApp').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('HrApp').clientHeight, + document.getElementById('HrApp').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 }); + history.push('/humanAffairs/archivesCenter/personnelArchives/personnelFiles') - // 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"); + dispatch(login(values.username, values.password)).then(res => { + const data = res.payload.user + localStorage.setItem('word', JSON.stringify(values.password)) + dispatch(actions.layout.initWebSocket({ ioUrl: apiRoot, token: data.token, hrUserId: data.hrUserInfo && hrUserInfo.id })) + }) + + // dispatch(getUserInfoByTokenUrl(token)).then(userRes => { + // if (userRes.success) { + // sessionStorage.setItem('user', JSON.stringify(userRes.payload.data)); + // dispatch({ + // type: 'INIT_AUTH', + // payload: { + // user: userRes.payload.data + // } + // }) + // // window.location.href = window.location.href; + // } else { + // redirectToLogin(true); + // } + // }, error => { + // redirectToLogin(true); + // }) + }, error => { + message.error('鉴权失败', 5); + redirectToLogin(true); + }) + } + } + + 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 + }; } export default connect(mapStateToProps)(LayoutContainer); \ No newline at end of file diff --git a/web/client/src/utils/webapi.js b/web/client/src/utils/webapi.js index b2b85cb..68238ce 100644 --- a/web/client/src/utils/webapi.js +++ b/web/client/src/utils/webapi.js @@ -42,5 +42,6 @@ export const RouteTable = { apiRoot: "/api/root", fileUpload: "/_upload/new", cleanUpUploadTrash: "/_upload/cleanup", - getWeeklyService: '/_service/weekly' + getWeeklyService: '/_service/weekly', + getDomain: '/domain', }; diff --git a/web/config.js b/web/config.js index 0e8eab1..8f762c2 100644 --- a/web/config.js +++ b/web/config.js @@ -13,6 +13,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'); @@ -23,10 +25,13 @@ args.option('qndmn', 'qiniuDomain'); //基本动作-周报后端服务 args.option('wkys', 'weeklyServices'); + + const flags = args.parse(process.argv); const API_URL = process.env.API_URL || flags.apiUrl; const API_HR_URL = process.env.API_HR_URL || flags.apiHrUrl; +const FS_HR_DOMAIN = process.env.FS_HR_DOMAIN || flags.domain; // 七牛 const ANXINCLOUD_QINIU_AK = process.env.ANXINCLOUD_QINIU_ACCESSKEY || flags.qnak; @@ -40,6 +45,7 @@ const ANXINCLOUD_WEEKLY_SERVICES = process.env.ANXINCLOUD_WEEKLY_SERVICES || fla if ( !API_URL || !API_HR_URL + || !FS_HR_DOMAIN || !ANXINCLOUD_QINIU_AK || !ANXINCLOUD_QINIU_SK || !ANXINCLOUD_QINIU_BUCKET_RESOURCE || !ANXINCLOUD_QINIU_DOMAIN_QNDMN_RESOURCE ) { console.log('缺少启动参数,异常退出'); @@ -79,7 +85,8 @@ const product = { }, service: { weekly: ANXINCLOUD_WEEKLY_SERVICES - } + }, + domain: FS_HR_DOMAIN, } }, { entry: require('./client').entry,// 静态信息 diff --git a/web/package.json b/web/package.json index 46345f6..93f261b 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 XuDgkao6cL0HidoMAPnA5OB10Mc_Ew08mpIfRJK5 --qnsk yewcieZLzKZuDfig0wLZ9if9jKp2P_1jd3CMJPSa --qnbkt dev-hr --qndmn http://rjkwed13l.hn-bkt.clouddn.com --wkys http://10.8.30.109:14000", + "start-params": "node server -p 5700 -u http://localhost:4700 --apiHrUrl http://localhost:4700 -d localhost --qnak XuDgkao6cL0HidoMAPnA5OB10Mc_Ew08mpIfRJK5 --qnsk yewcieZLzKZuDfig0wLZ9if9jKp2P_1jd3CMJPSa --qnbkt dev-hr --qndmn http://rjkwed13l.hn-bkt.clouddn.com --wkys 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" @@ -63,6 +63,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", diff --git a/web/routes/services/weekly.js b/web/routes/services/weekly.js index 5a12021..181865f 100644 --- a/web/routes/services/weekly.js +++ b/web/routes/services/weekly.js @@ -13,6 +13,15 @@ module.exports = { }; }; + const getDomain = async function (ctx) { + const { domain } = opts; + + ctx.status = 200; + ctx.body = { root: domain }; + }; + + router.get('/_service/weekly', getWeeklyService); + router.get('/domain', getDomain); } };