Browse Source

(*)修复401和导出

master
周沫沫历险记 2 years ago
parent
commit
d9f7063f27
  1. 20
      .vscode/launch.json
  2. 2
      api/app/lib/controllers/auth/index.js
  3. 6
      web/client/src/layout/actions/webSocket.js
  4. 10
      web/client/src/sections/auth/actions/auth.js
  5. 2
      web/client/src/sections/auth/containers/login.jsx
  6. 20
      web/client/src/sections/business/containers/reserveItemsPeriodicStatistics.jsx
  7. 2
      web/client/src/utils/func.js

20
.vscode/launch.json

@ -4,6 +4,26 @@
// 访: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "启动 web",
"program": "${workspaceRoot}/web/server.js",
"env": {
"NODE_ENV": "development"
},
"args": [
"-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",
"--wkys", "http://10.8.30.109:14000"
]
},
{
"type": "node",
"request": "launch",

2
api/app/lib/controllers/auth/index.js

@ -19,7 +19,7 @@ async function login (ctx, next) {
emisLoginRes.authorized = true
emisLoginRes.expired = moment().add(1, 'day')
emisLoginRes.hrUserInfo = undefined
emisLoginRes.dcUserInfo = undefined
await ctx.redis.hmset(emisLoginRes.token, {
expired: moment().add(1, 'day'),

6
web/client/src/layout/actions/webSocket.js

@ -2,19 +2,19 @@
import io from 'socket.io-client';
export const INIT_WEB_SOCKET = 'INIT_WEB_SOCKET'
export function initWebSocket ({ ioUrl, token, hrUserId }) {
export function initWebSocket ({ ioUrl, token, dcUserId }) {
if (!ioUrl) {
ioUrl = localStorage.getItem('apiRoot')
ioUrl = JSON.parse(ioUrl).root
}
if (!token) {
let user = sessionStorage.getItem('hrUser')
let user = sessionStorage.getItem('dcUser')
if (user) {
user = JSON.parse(user)
token = user.token
}
}
if (!ioUrl || !token || !hrUserId) {
if (!ioUrl || !token || !dcUserId) {
return {
type: '',
}

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

@ -5,10 +5,10 @@ import { Request } from '@peace/utils';
export const INIT_AUTH = 'INIT_AUTH';
export function initAuth(userData) {
const sessionUser = JSON.parse(sessionStorage.getItem('hrUser'))
const sessionUser = JSON.parse(sessionStorage.getItem('dcUser'))
const user = userData || sessionUser || {};
if (user.authorized && !sessionUser) {
sessionStorage.setItem('hrUser', JSON.stringify(user))
sessionStorage.setItem('dcUser', JSON.stringify(user))
}
return {
type: INIT_AUTH,
@ -45,7 +45,7 @@ export function login(username, password) {
return Request.post(ApiTable.login, { username, password, code: 'HR' })
.then(user => {
sessionStorage.setItem('hrUser', JSON.stringify(user));
sessionStorage.setItem('dcUser', JSON.stringify(user));
return dispatch({
type: LOGIN_SUCCESS,
payload: { user: user },
@ -64,13 +64,13 @@ export function login(username, password) {
export const LOGOUT = 'LOGOUT';
export function logout() {
const user = JSON.parse(sessionStorage.getItem('hrUser'))
const user = JSON.parse(sessionStorage.getItem('dcUser'))
user && user.token ?
Request.put(ApiTable.logout, {
token: user.token,
code: 'POMS'
}) : null;
sessionStorage.removeItem('hrUser');
sessionStorage.removeItem('dcUser');
localStorage.removeItem('poms_selected_sider');
localStorage.removeItem('poms_open_sider');

2
web/client/src/sections/auth/containers/login.jsx

@ -67,7 +67,7 @@ const Login = props => {
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(actions.layout.initWebSocket({ ioUrl: apiRoot, token: data.token, dcUserId: data.dcUserInfo && dcUserInfo.id }))
})
}}
getFormApi={formApi => form.current = formApi}

20
web/client/src/sections/business/containers/reserveItemsPeriodicStatistics.jsx

@ -8,17 +8,15 @@ import '../style.less'
const ReserveItemsPeriodicStatistics = (props) => {
const { dispatch, actions, isRequesting, reserveItemReport } = props;
const [downloadUrl, setDownloadUrl] = useState(null);
const [downloadKey, setDownloadKey] = useState(null);
useEffect(() => {
dispatch(actions.businessManagement.getReserveItemReport(RESERVEITEM_TYPE.periodicStatistics));
}, []);
const exportReport = () => {
RouteRequest.get(RouteTable.qnDownload).then(res => {
debugger;
console.log(res);
// setDownloadUrl(`members/export?token=${user.token}&state=${typeChoose}&keywordTarget=${keywordTarget}&keyword=${keyword}&keys=overtimeStatistic,vacateStatistic`)
})
const exportReport = (url) => {
setDownloadUrl(`/_file-server${url}`);
setDownloadKey(Math.random());
}
const columns = [
@ -38,7 +36,7 @@ const ReserveItemsPeriodicStatistics = (props) => {
{
title: '操作',
dataIndex: 'action',
render: (text, record, indexe) => (<Button theme='solid' type='secondary' onClick={() => exportReport()} > 导出</Button >)
render: (text, record, indexe) => (<Button theme='solid' type='secondary' onClick={() => exportReport(record.path)} > 导出</Button >)
},
];
@ -61,9 +59,9 @@ const ReserveItemsPeriodicStatistics = (props) => {
</div>
</div>
<div style={{ borderBottom: '1px solid #F2F3F5', marginLeft: '-20px', marginBottom: 16 }}></div>
{/* {
downloadUrl ? <iframe src={`/_api/${downloadUrl}`} style={{ display: 'none' }} /> : ''
} */}
{
downloadUrl ? <iframe key={downloadKey} src={downloadUrl} style={{ display: 'none' }} /> : ''
}
<div style={{ marginBottom: 22 }}>
<Spin spinning={isRequesting}>
<Table

2
web/client/src/utils/func.js

@ -2,7 +2,7 @@
export const isAuthorized = (authcode) => {
if (JSON.parse(sessionStorage.getItem('user'))) {
const { resources } = JSON.parse(sessionStorage.getItem('hrUser'));
const { resources } = JSON.parse(sessionStorage.getItem('dcUser'));
return resources.includes(authcode);
} else {
return false;

Loading…
Cancel
Save