Commit c1694388 authored by 张烨's avatar 张烨

feat: compile with ts files and update login authority

parent d491d4d4
...@@ -17,11 +17,14 @@ module.exports = options => ({ ...@@ -17,11 +17,14 @@ module.exports = options => ({
module: { module: {
rules: [ rules: [
{ {
test: /\.jsx?$/, test: /\.[jt]sx?$/,
exclude: /node_modules/, exclude: /node_modules/,
use: { use: {
loader: 'babel-loader', loader: 'babel-loader',
options: options.babelQuery, // options: options.babelQuery,
options: {
presets: ['@babel/preset-typescript'],
},
}, },
}, },
...@@ -169,7 +172,7 @@ module.exports = options => ({ ...@@ -169,7 +172,7 @@ module.exports = options => ({
]), ]),
resolve: { resolve: {
modules: ['node_modules', 'src'], modules: ['node_modules', 'src'],
extensions: ['.js', '.jsx', '.react.js'], extensions: ['.js', '.jsx', '.react.js', '.ts', '.tsx'],
mainFields: ['browser', 'jsnext:main', 'main'], mainFields: ['browser', 'jsnext:main', 'main'],
alias: { alias: {
'@': path.resolve(process.cwd(), './src'), '@': path.resolve(process.cwd(), './src'),
......
...@@ -83,6 +83,7 @@ ...@@ -83,6 +83,7 @@
}, },
"dependencies": { "dependencies": {
"@babel/polyfill": "7.4.3", "@babel/polyfill": "7.4.3",
"@babel/preset-typescript": "^7.12.1",
"@babel/runtime": "^7.10.5", "@babel/runtime": "^7.10.5",
"antd-img-crop": "^3.13.2", "antd-img-crop": "^3.13.2",
"chalk": "2.4.2", "chalk": "2.4.2",
......
...@@ -2,12 +2,16 @@ import React from 'react'; ...@@ -2,12 +2,16 @@ import React from 'react';
import { Helmet } from 'react-helmet'; import { Helmet } from 'react-helmet';
import { renderRoutes } from 'react-router-config'; import { renderRoutes } from 'react-router-config';
import { BrowserRouter as Router, Switch } from 'react-router-dom'; import { BrowserRouter as Router, Switch } from 'react-router-dom';
import { connect } from 'react-redux';
import config from '../../routes/config'; import config from '../../routes/config';
import Authozed from '@/utils/authority'; import Authozed from '@/utils/authority';
import UserLogin from '@/pages/user/login'; import UserLogin from '@/pages/user/login';
import UserLayout from '@/layouts/UserLayout'; import UserLayout from '@/layouts/UserLayout';
import { AUTHORITY, BASENAME } from '@/utils/constants'; import { AUTHORITY, BASENAME } from '@/utils/constants';
export default function App() { export default connect(store => ({
auth: store,
}))(function App() {
console.log('reRender');
return ( return (
<> <>
<Helmet titleTemplate="%s - 运维平台" defaultTitle="运维平台"> <Helmet titleTemplate="%s - 运维平台" defaultTitle="运维平台">
...@@ -27,4 +31,4 @@ export default function App() { ...@@ -27,4 +31,4 @@ export default function App() {
</Authozed> </Authozed>
</> </>
); );
} });
import { LOAD_REPOS, LOAD_REPOS_ERROR, LOAD_REPOS_SUCCESS } from './constants'; import {
LOAD_REPOS,
LOAD_REPOS_ERROR,
LOAD_REPOS_SUCCESS,
SET_AUTHORITY,
} from './constants';
export function loadRepos() { export function loadRepos() {
return { return {
...@@ -20,3 +25,10 @@ export function repoLoadingError(error) { ...@@ -20,3 +25,10 @@ export function repoLoadingError(error) {
error, error,
}; };
} }
export function setAuth(auth) {
return {
type: SET_AUTHORITY,
auth,
};
}
export const LOAD_REPOS = 'App/LOAD_REPOS'; export const LOAD_REPOS = 'App/LOAD_REPOS';
export const LOAD_REPOS_SUCCESS = 'App/LOAD_REPOS_SUCCESS'; export const LOAD_REPOS_SUCCESS = 'App/LOAD_REPOS_SUCCESS';
export const LOAD_REPOS_ERROR = 'App/LOAD_REPOS_ERROR'; export const LOAD_REPOS_ERROR = 'App/LOAD_REPOS_ERROR';
export const SET_AUTHORITY = 'App/SET_AUTHORITY';
import { fromJS } from 'immutable'; import { fromJS } from 'immutable';
import { LOAD_REPOS, LOAD_REPOS_ERROR, LOAD_REPOS_SUCCESS } from './constants'; import {
LOAD_REPOS,
LOAD_REPOS_ERROR,
LOAD_REPOS_SUCCESS,
SET_AUTHORITY,
} from './constants';
export const initialState = fromJS({ export const initialState = fromJS({
loading: false, loading: false,
error: false, error: false,
currentUser: false, currentUser: false,
auth: [],
userData: { userData: {
repositories: false, repositories: false,
}, },
...@@ -36,6 +42,10 @@ const appReducer = (state = initialState, action) => { ...@@ -36,6 +42,10 @@ const appReducer = (state = initialState, action) => {
error: action.error, error: action.error,
loading: false, loading: false,
}); });
case SET_AUTHORITY:
return state.merge({
auth: action.auth,
});
default: default:
return state; return state;
} }
......
import React from 'react'; import React, { useEffect } from 'react';
import { Helmet, HelmetProvider } from 'react-helmet-async'; import { Helmet, HelmetProvider } from 'react-helmet-async';
import { renderRoutes } from 'react-router-config'; import { renderRoutes } from 'react-router-config';
...@@ -11,6 +11,7 @@ import { ...@@ -11,6 +11,7 @@ import {
import logo from '../assets/images/logo/panda-logo.svg'; import logo from '../assets/images/logo/panda-logo.svg';
import styles from './UserLayout.less'; import styles from './UserLayout.less';
import { BASENAME } from '@/utils/constants';
const UserLayout = props => { const UserLayout = props => {
const { const {
...@@ -28,6 +29,10 @@ const UserLayout = props => { ...@@ -28,6 +29,10 @@ const UserLayout = props => {
...props, ...props,
}); });
// useEffect(() => {
// window.location.href = `/${BASENAME}/user/login`;
// });
return ( return (
<HelmetProvider> <HelmetProvider>
<Helmet> <Helmet>
......
import React, { useState } from 'react'; import React, { useState } from 'react';
import { Alert, Checkbox } from 'antd'; import { Alert, notification } from 'antd';
import { login } from '@/services/user/api'; import { login } from '@/services/user/api';
import { AUTHORITY, BASENAME, USER_MODE } from '@/utils/constants'; import { AUTHORITY, BASENAME, USER_MODE } from '@/utils/constants';
import { connect } from 'react-redux';
import { actionCreators } from '@/containers/App/store';
import LoginForm from './components/Login'; import LoginForm from './components/Login';
import styles from './style.less'; import styles from './style.less';
import { setAuthority } from '@/utils/authority'; import { setAuthority } from '@/utils/authority';
import history from '@/utils/history';
const { UserName, Password, Submit } = LoginForm; const { UserName, Password, Submit } = LoginForm;
const LoginMessage = ({ content }) => ( const LoginMessage = ({ content }) => (
...@@ -19,9 +22,9 @@ const LoginMessage = ({ content }) => ( ...@@ -19,9 +22,9 @@ const LoginMessage = ({ content }) => (
); );
const Login = props => { const Login = props => {
const { userLogin = {}, submitting } = props; const { userLogin = {}, submitting, setAuth } = props;
const { status, type: loginType } = userLogin; const { status, type: loginType } = userLogin;
const [autoLogin, setAutoLogin] = useState(true); // const [autoLogin, setAutoLogin] = useState(true);
const [type, setType] = useState('account'); const [type, setType] = useState('account');
const handleSubmit = values => { const handleSubmit = values => {
/* eslint-disable no-console */ /* eslint-disable no-console */
...@@ -33,15 +36,21 @@ const Login = props => { ...@@ -33,15 +36,21 @@ const Login = props => {
const { userMode } = result; const { userMode } = result;
localStorage.setItem('userMode', userMode); localStorage.setItem('userMode', userMode);
if (userMode === USER_MODE.ADMIN || userMode === USER_MODE.SUPER) { if (userMode === USER_MODE.ADMIN || userMode === USER_MODE.SUPER) {
setAuthority([AUTHORITY.LOGIN, AUTHORITY[userMode]]); const authority = [AUTHORITY.LOGIN, AUTHORITY[userMode]];
window.location.href = `/${BASENAME}/dbm/dbInit/`; setAuthority(authority);
setAuth(authority);
history.push(`/${BASENAME}/dbm/dbInit/`);
} }
if (userMode === USER_MODE.COMMON) { if (userMode === USER_MODE.COMMON) {
setAuthority([AUTHORITY.LOGIN, AUTHORITY.COMMON]); const authority = [AUTHORITY.LOGIN, AUTHORITY.COMMON];
window.location.href = `/${BASENAME}/ou/orgList/`; setAuthority(authority);
setAuth(authority);
history.push(`/${BASENAME}/ou/orgList/`);
} }
} else { } else {
alert('错误,没有权限'); notification.warning({
message: '没有权限!',
});
} }
}); });
}; };
...@@ -73,12 +82,12 @@ const Login = props => { ...@@ -73,12 +82,12 @@ const Login = props => {
]} ]}
/> />
<div> <div>
<Checkbox {/* <Checkbox
checked={autoLogin} checked={autoLogin}
onChange={e => setAutoLogin(e.target.checked)} onChange={e => setAutoLogin(e.target.checked)}
> >
自动登录 自动登录
</Checkbox> </Checkbox> */}
{/* <a {/* <a
style={{ style={{
float: 'right', float: 'right',
...@@ -93,4 +102,11 @@ const Login = props => { ...@@ -93,4 +102,11 @@ const Login = props => {
); );
}; };
export default Login; const mapState = () => ({});
const mapDispatch = dispatch => ({
setAuth: auth => dispatch(actionCreators.setAuth(auth)),
});
export default connect(
mapState,
mapDispatch,
)(Login);
import RenderAuthorize from '@/components/Authorized'; import RenderAuthorize from '@/components/Authorized';
import { isDev } from './tools.ts';
let auth = [];
/* eslint-disable eslint-comments/disable-enable-pair */ /* eslint-disable eslint-comments/disable-enable-pair */
/* eslint-disable import/no-mutable-exports */ /* eslint-disable import/no-mutable-exports */
let Authorized = RenderAuthorize(getAuthority()); let Authorized = RenderAuthorize(getAuthority());
...@@ -19,6 +21,7 @@ export default Authorized; ...@@ -19,6 +21,7 @@ export default Authorized;
// use localStorage to store the authority info, which might be sent from server in actual project. // use localStorage to store the authority info, which might be sent from server in actual project.
export function getAuthority(str) { export function getAuthority(str) {
if (!isDev) return [...auth];
const authorityString = const authorityString =
typeof str === 'undefined' && localStorage typeof str === 'undefined' && localStorage
? localStorage.getItem('panda-oms-authority') ? localStorage.getItem('panda-oms-authority')
...@@ -41,7 +44,11 @@ export function getAuthority(str) { ...@@ -41,7 +44,11 @@ export function getAuthority(str) {
export function setAuthority(authority) { export function setAuthority(authority) {
const proAuthority = typeof authority === 'string' ? [authority] : authority; const proAuthority = typeof authority === 'string' ? [authority] : authority;
localStorage.setItem('panda-oms-authority', JSON.stringify(proAuthority)); if (isDev) {
localStorage.setItem('panda-oms-authority', JSON.stringify(proAuthority));
} else {
auth = auth.concat(proAuthority);
}
// auto reload // auto reload
reloadAuthorized(); reloadAuthorized();
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment