Browse Source

登录及其配置

release_0.0.1
巴林闲侠 2 years ago
parent
commit
b9b0b28645
  1. 27
      web/client/src/sections/auth/actions/auth.js
  2. 4
      web/client/src/utils/index.js
  3. 4
      web/client/src/utils/webapi.js
  4. 9
      web/config.js
  5. 2
      web/package.json

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

@ -1,6 +1,6 @@
'use strict'; 'use strict';
import { ApiTable, AxyRequest } from '$utils' import { ApiTable, AxyRequest, EmisRequest } from '$utils'
export const INIT_AUTH = 'INIT_AUTH'; export const INIT_AUTH = 'INIT_AUTH';
export function initAuth (userData) { export function initAuth (userData) {
@ -32,17 +32,17 @@ export function login (username, password) {
return Promise.resolve(); return Promise.resolve();
} }
return dispatch({ // return dispatch({
type: LOGIN_SUCCESS, // type: LOGIN_SUCCESS,
payload: { // payload: {
user: { // user: {
authorized: true, // authorized: true,
namePresent: 'TEST' // namePresent: 'TEST'
} // }
}, // },
}); // });
return AxyRequest.post(ApiTable.login, { username, password, domain: 'anxinyun' }) return EmisRequest.post(ApiTable.login, { username, password, code: 'POMS' })
.then(user => { .then(user => {
sessionStorage.setItem('pomsUser', JSON.stringify(user)); sessionStorage.setItem('pomsUser', JSON.stringify(user));
return dispatch({ return dispatch({
@ -65,8 +65,9 @@ export const LOGOUT = 'LOGOUT';
export function logout () { export function logout () {
const user = JSON.parse(sessionStorage.getItem('pomsUser')) const user = JSON.parse(sessionStorage.getItem('pomsUser'))
user && user.token ? user && user.token ?
AxyRequest.post(ApiTable.logout, { EmisRequest.post(ApiTable.logout, {
token: user.token token: user.token,
code: 'POMS'
}) : null; }) : null;
sessionStorage.removeItem('pomsUser'); sessionStorage.removeItem('pomsUser');
return { return {

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

@ -3,7 +3,7 @@ import { isAuthorized } from './func';
import { AuthorizationCode } from './authCode'; import { AuthorizationCode } from './authCode';
import { import {
ApiTable, RouteTable, ApiTable, RouteTable,
AxyRequest, AxyRequest, EmisRequest,
basicAction, RouteRequest basicAction, RouteRequest
} from './webapi' } from './webapi'
@ -14,7 +14,7 @@ export {
RouteTable, RouteTable,
ApiTable, ApiTable,
AxyRequest, AxyRequest,
EmisRequest,
basicAction, basicAction,
RouteRequest, RouteRequest,
} }

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

@ -2,6 +2,7 @@
import { ProxyRequest, customWebUtils } from "@peace/utils"; import { ProxyRequest, customWebUtils } from "@peace/utils";
export const AxyRequest = new ProxyRequest("_axy"); export const AxyRequest = new ProxyRequest("_axy");
export const EmisRequest = new ProxyRequest("_emis")
export const webUtils = new customWebUtils({ export const webUtils = new customWebUtils({
userKey: 'pomsUser' userKey: 'pomsUser'
@ -19,5 +20,4 @@ export const RouteTable = {
apiRoot: "/api/root", apiRoot: "/api/root",
fileUpload: "/_upload/new", fileUpload: "/_upload/new",
cleanUpUploadTrash: "/_upload/cleanup", cleanUpUploadTrash: "/_upload/cleanup",
}; };

9
web/config.js

@ -14,13 +14,16 @@ args.option(['p', 'port'], '启动端口');
args.option(['u', 'api-url'], 'webapi的URL'); args.option(['u', 'api-url'], 'webapi的URL');
args.option('apiPomsUrl', 'webapi的URL 外网可访问'); args.option('apiPomsUrl', 'webapi的URL 外网可访问');
args.option('apiAnxinyunUrl', '安心云 api'); args.option('apiAnxinyunUrl', '安心云 api');
args.option('apiEmisUrl', '企业管理 api');
const flags = args.parse(process.argv); 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_POMS_URL = process.env.API_POMS_URL || flags.apiPomsUrl; const API_POMS_URL = process.env.API_POMS_URL || flags.apiPomsUrl;
const API_EMIS_URL = process.env.API_EMIS_URL || flags.apiEmisUrl;
const API_ANXINYUN_URL = process.env.API_ANXINYUN_URL || flags.apiAnxinyunUrl; const API_ANXINYUN_URL = process.env.API_ANXINYUN_URL || flags.apiAnxinyunUrl;
if (!API_URL || !API_ANXINYUN_URL) { if (!API_URL || !API_ANXINYUN_URL) {
console.log('缺少启动参数,异常退出'); console.log('缺少启动参数,异常退出');
args.showHelp(); args.showHelp();
@ -42,6 +45,12 @@ const product = {
host: API_ANXINYUN_URL, host: API_ANXINYUN_URL,
match: /^\/_axy\//, match: /^\/_axy\//,
} }
}, {
entry: require('./middlewares/proxy').entry,
opts: {
host: API_EMIS_URL,
match: /^\/_emis\//,
}
}, { }, {
entry: require('./routes').entry, entry: require('./routes').entry,
opts: { opts: {

2
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 5600 -u http://localhost:4600 --apiPomsUrl http://localhost:4600 --apiAnxinyunUrl http://localhost:4100", "start-params": "node server -p 5600 -u http://localhost:4600 --apiPomsUrl http://localhost:4600 --apiAnxinyunUrl http://10.8.30.112:4100 --apiEmisUrl http://10.8.30.112: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"

Loading…
Cancel
Save