Browse Source

免密登录

master
wenlele 2 years ago
parent
commit
69903c2105
  1. 2
      .vscode/launch.json
  2. 59
      web/client/src/layout/containers/layout/index.jsx
  3. 4
      web/client/src/sections/auth/actions/auth.js
  4. 4
      web/client/src/utils/webapi.js
  5. 6
      web/config.js
  6. 3
      web/package.json

2
.vscode/launch.json

@ -43,7 +43,7 @@
// //
// //
"-g postgres://FashionAdmin:123456@10.8.30.36:5432/data_center", "-g postgres://FashionAdmin:123456@10.8.30.36:5432/data_center",
"--redisHost localhost", "--redisHost 10.8.30.112",
"--redisPort 6379", "--redisPort 6379",
"--apiEmisUrl http://10.8.30.161:1111", "--apiEmisUrl http://10.8.30.161:1111",
// //

59
web/client/src/layout/containers/layout/index.jsx

@ -10,6 +10,10 @@ import { resize } from '../../actions/global';
import * as NProgress from 'nprogress'; import * as NProgress from 'nprogress';
import PerfectScrollbar from 'perfect-scrollbar'; import PerfectScrollbar from 'perfect-scrollbar';
import { useLocation } from "react-router"; 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({ NProgress.configure({
template: ` template: `
@ -23,11 +27,14 @@ NProgress.configure({
}); });
let scrollbar let scrollbar
let requestUser = true
let requestlogout = false;
// const location111 = useLocation(); // const location111 = useLocation();
const LayoutContainer = props => { const LayoutContainer = props => {
const { const {
dispatch, msg, user, copyright, children, sections, clientWidth, clientHeight, dispatch, msg, user, copyright, children, sections, clientWidth, clientHeight,
location, match, routes, history, socket, location, match, routes, history, socket, apiRoot
} = props } = props
const [collapsed, setCollapsed] = useState(false) const [collapsed, setCollapsed] = useState(false)
@ -165,7 +172,8 @@ const LayoutContainer = props => {
useEffect(() => { useEffect(() => {
NProgress.done(); NProgress.done();
if ((!user || !user.authorized)) { if ((!user || !user.authorized)) {
history.push('/signin'); // history.push('/signin');
getUserInfoByToken()
} }
if (msg) { if (msg) {
if (msg.done) { if (msg.done) {
@ -195,6 +203,50 @@ const LayoutContainer = props => {
} }
}) })
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);
})
}
}
const redirectToLogin = (toLogin = false) => {
//
if (!requestlogout) {
requestlogout = true;//退redirectToLoginwindow.location.hrefmessage.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`;
}
}
});
}
}
// websocket 使 // websocket 使
useEffect(() => { useEffect(() => {
@ -318,7 +370,8 @@ function mapStateToProps(state) {
clientHeight: global.clientHeight, clientHeight: global.clientHeight,
msg: ajaxResponse.msg, msg: ajaxResponse.msg,
user: auth.user, user: auth.user,
socket: webSocket.socket socket: webSocket.socket,
apiRoot: global.apiRoot,
}; };
} }

4
web/client/src/sections/auth/actions/auth.js

@ -21,7 +21,7 @@ export function initAuth(userData) {
export const REQUEST_LOGIN = 'REQUEST_LOGIN'; export const REQUEST_LOGIN = 'REQUEST_LOGIN';
export const LOGIN_SUCCESS = 'LOGIN_SUCCESS'; export const LOGIN_SUCCESS = 'LOGIN_SUCCESS';
export const LOGIN_ERROR = 'LOGIN_ERROR'; export const LOGIN_ERROR = 'LOGIN_ERROR';
export function login(username, password) { export function login ({ username, password, token }) {
return dispatch => { return dispatch => {
dispatch({ type: REQUEST_LOGIN }); 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 => { .then(user => {
sessionStorage.setItem('dcUser', JSON.stringify(user)); sessionStorage.setItem('dcUser', JSON.stringify(user));
return dispatch({ return dispatch({

4
web/client/src/utils/webapi.js

@ -28,5 +28,7 @@ export const RouteTable = {
apiRoot: "/api/root", apiRoot: "/api/root",
fileUpload: "/_upload/new", fileUpload: "/_upload/new",
cleanUpUploadTrash: "/_upload/cleanup", cleanUpUploadTrash: "/_upload/cleanup",
getServiceUrl: '/_service/url' getServiceUrl: '/_service/url',
getDomain: '/domain',
}; };

6
web/config.js

@ -12,6 +12,8 @@ dev && console.log('\x1B[33m%s\x1b[0m', '请遵循并及时更新 readme.md,
args.option(['p', 'port'], '启动端口'); args.option(['p', 'port'], '启动端口');
args.option(['u', 'api-url'], 'webapi的URL'); args.option(['u', 'api-url'], 'webapi的URL');
args.option('apiHrUrl', 'webapi的URL 外网可访问'); args.option('apiHrUrl', 'webapi的URL 外网可访问');
args.option(['d', 'domain'], 'web domain');
// 七牛 // 七牛
args.option('qnak', 'qiniuAccessKey'); 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_URL = process.env.API_URL || flags.apiUrl;
const API_DC_URL = process.env.API_DC_URL || flags.apiHrUrl; 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; const ANXINCLOUD_QINIU_AK = process.env.ANXINCLOUD_QINIU_ACCESSKEY || flags.qnak;
@ -76,7 +79,8 @@ const product = {
}, },
service: { service: {
url: ANXINCLOUD_PM_SERVICES url: ANXINCLOUD_PM_SERVICES
} },
domain: FS_REPORT_DOMAIN
} }
}, { }, {
entry: require('./client').entry,// 静态信息 entry: require('./client').entry,// 静态信息

3
web/package.json

@ -7,7 +7,7 @@
"test": "mocha", "test": "mocha",
"start-vite": "cross-env NODE_ENV=developmentVite npm run start-params", "start-vite": "cross-env NODE_ENV=developmentVite npm run start-params",
"start": "cross-env NODE_ENV=development 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", "deploy": "export NODE_ENV=production&& npm run build && node server",
"build-dev": "cross-env NODE_ENV=development&&webpack --config webpack.config.js", "build-dev": "cross-env NODE_ENV=development&&webpack --config webpack.config.js",
"build": "cross-env NODE_ENV=production&&webpack --config webpack.config.prod.js" "build": "cross-env NODE_ENV=production&&webpack --config webpack.config.prod.js"
@ -60,6 +60,7 @@
"ezuikit-js": "^0.6.1", "ezuikit-js": "^0.6.1",
"fs-attachment": "^1.0.0", "fs-attachment": "^1.0.0",
"fs-web-server-scaffold": "^1.0.6", "fs-web-server-scaffold": "^1.0.6",
"js-cookie": "^3.0.1",
"js-export-excel": "^1.1.4", "js-export-excel": "^1.1.4",
"koa-better-http-proxy": "^0.2.5", "koa-better-http-proxy": "^0.2.5",
"koa-proxy": "^1.0.0-alpha.3", "koa-proxy": "^1.0.0-alpha.3",

Loading…
Cancel
Save