Commit 29aac24f authored by 曾婧's avatar 曾婧

合并更改

parents 75c5134c 67d9eabc
......@@ -4,7 +4,7 @@ const defaultSetting = require('./defaultSetting');
const cesiumBuild = '../node_modules/cesium/Build/Cesium';
const pkgName = require('../package.json').name;
// eslint-disable-next-line import/order
const { REACT_APP_ENV } = process.env;
const { NODE_ENV } = process.env;
// eslint-disable-next-line import/order
const path = require('path');
const CESIUM_BASE_URL = `/${pkgName}`;
......@@ -45,7 +45,7 @@ module.exports = {
'Cesium',
],
},
proxy: proxy[REACT_APP_ENV || 'dev'],
proxy: proxy[NODE_ENV],
// openAPI: {
// requestLibPath: "import { request } from '@wisdom-utils/utils'",
// schemaPath: 'http://192.168.10.150:8777/Publish/OMS/swagger/v1/swagger.json',
......
......@@ -23,7 +23,7 @@ export default {
// },
{
name: 'civ_water',
entry: `//${window.location.hostname}:8080/civ_water`,
entry: `//${window.location.hostname}:8081/civ_water`,
container: '#micro-container',
activeRule: '/civbase/civ_water',
},
......
......@@ -4,10 +4,9 @@
// const proxyURL = 'http://192.168.12.47:8082';
const proxyURL = 'http://localhost:8086';
module.exports = {
assetsRoot: process.env.NODE_ENV !== 'production' ? proxyURL : './',
dev: {
development: {
'/PandaOMS':{
target: proxyURL,
changeOrigin: true,
......
......@@ -487,10 +487,6 @@ module.exports = options => {
.end();
}
rule
.use('babel-loader')
.loader(require.resolve('babel-loader'))
.options({});
if ((isProd && defineConfig.analyze) || process.env.ANALYZE) {
const mergeAnalyze = Object.assign(
......
This diff is collapsed.
......@@ -3,7 +3,7 @@ const { writeFileSync, mkdirSync, existsSync } = require('fs');
const rimraf = require('rimraf');
const serveStatic = require('serve-static');
const { resolve } = require('path');
const { portfinder, chalk, delay } = require('@umijs/utils');
const { portfinder, chalk, delay, createDebug, chokidar, signale, glob } = require('@umijs/utils');
const argv = require('./argv');
const setup = require('./middlewares/frontendMiddleware');
const pkg = require('../package.json');
......@@ -11,20 +11,19 @@ const config = require('../config/config');
const mockMiddewares = require('./mock');
const emitter = require('./event');
const Server = require('./server');
const debug = createDebug('preset-build-in:proxy:createMiddleware');
// const proxyConfig = require('../config/proxy');
const loadDotEnv = require('./utils/loadDotEnv');
const { getSchema } = require('./openapi');
const cleanRequireCache = require('./utils/cleanRequireCache');
(async () => {
const defaultPort =
process.env.PORT ||
argv.port ||
(config && config.devServer && config.devServer.port);
const defaultPort = process.env.PORT || argv.port || (config && config.devServer && config.devServer.port);
const port = await portfinder.getPortPromise({
port: defaultPort ? parseInt(String(defaultPort), 10) : 8080,
});
const homename =
process.env.HOST ||
(config && config.devServer && config.devServer.host) ||
'127.0.0.1';
const homename = process.env.HOST || (config && config.devServer && config.devServer.host) || '127.0.0.1';
console.log(chalk.cyan('Starting the development server...'));
// process.send && process.send({ type: 'UPDATE_PORT', port });
const isHTTPS = process.env.HTTPS || (argv && argv.https);
......@@ -81,6 +80,54 @@ const { getSchema } = require('./openapi');
},
);
// proxy config 热更新
const ignore = [
// ignore mock files under node_modules
'node_modules/**'
];
const cwd = process.cwd();
const proxyWatcherPaths = [
...(glob.sync('config/proxy.js', {
cwd,
ignore,
}) || []),
...(glob.sync('**/proxy.js', {
cwd,
ignore,
}) || []),
...(glob.sync('.env', {
cwd,
ignore,
}) || []),
...(glob.sync('.env.local', {
cwd,
ignore,
}) || [])
];
const watcher = chokidar.watch(proxyWatcherPaths, {
ignoreInitial: true,
});
const errors = [];
watcher.on('ready', () => debug('Initial scan complete. Ready for changes')).on('all', async (event, file) => {
debug(`[${event}] ${file}, reload proxy config`);``
errors.splice(0, errors.length);
cleanRequireCache(Array.from(new Set(proxyWatcherPaths)));
if (!errors.length) {
const hotProxy = require('../config/proxy');
server.setupProxy && server.setupProxy(hotProxy[process.env.NODE_ENV], true);
signale.success(`Proxy config parse success`);
}
});
process.once('SIGINT', async () => {
await watcher.close();
});
emitter.on('onDevCompileDone', async () => {
try {
const openAPIConfig = config.openAPI;
......@@ -96,6 +143,7 @@ const { getSchema } = require('./openapi');
}
});
await server.listen({
port,
homename,
......
......@@ -4,6 +4,7 @@ const webpackDevMiddleware = require('webpack-dev-middleware');
const webpackHotMiddleware = require('webpack-hot-middleware');
const DevCompileDonePlugin = require('../../internals/webpack/plugins/DevCompileDonePlugin');
const emitter = require('../event');
function getIgnoredWatchRegExp() {
// const absOutputPath = winPath(path.join(process.cwd(), outputPath));
return process.env.WATCH_IGNORED === 'none'
......@@ -29,6 +30,7 @@ module.exports = function addDevMiddlewares(
config,
{ port = 8080, hostname = '127.0.0.1' },
) {
if (!config.mfsu) {
webpackConfig.plugins.push(
new DevCompileDonePlugin({
......@@ -63,8 +65,15 @@ module.exports = function addDevMiddlewares(
app.use(middleware);
app.use(webpackHotMiddleware(compiler));
const fs = middleware.context.outputFileSystem;
app.get('*', (req, res) => {
fs.readFile(path.join(compiler.outputPath, 'index.html'), (err, file) => {
if (err) {
......
......@@ -134,7 +134,7 @@ class Server {
);
}
setupProxy(proxyOpts, isWatch = true) {
setupProxy(proxyOpts, isWatch = false) {
let proxy = proxyOpts || this.opts.proxy;
if (!Array.isArray(proxy)) {
if (proxy && 'target' in proxy) {
......@@ -181,6 +181,7 @@ class Server {
},
});
}
return;
};
let startIndex = null;
......
const { winPath } = require('@umijs/utils')
function cleanRequireCache(paths) {
Object.keys(require.cache).forEach(file => {
if (paths.some(p => winPath(file).indexOf(p) > -1)) {
delete require.cache[file];
}
});
};
module.exports = cleanRequireCache;
\ No newline at end of file
import 'whatwg-fetch';
// import 'whatwg-fetch';
import './public-path';
import '!file-loader?name=[name].[ext]!./images/favicon.ico';
import './global.less';
......@@ -7,11 +7,7 @@ import 'antd/dist/antd.less';
import 'file-loader?name=.htaccess!./.htaccess'; // eslint-disable-line import/extensions
import '@wisdom-utils/utils/lib/helpers/format';
import 'sanitize.css/sanitize.css';
// import { event } from '@wisdom-utils/utils';
import { ConfigProvider } from 'antd';
import { Storeage } from '@wisdom-utils/utils/lib/helpers';
// import { history } from '@wisdom-utils/runtime';
// import { actionCreators } from './containers/App/store';
import { initGlobalConfig } from './initConfig';
import './utils/event';
......@@ -19,9 +15,7 @@ import './utils/event';
// eslint-disable-next-line no-restricted-globals
const namespace = `__PANDA_STORE__${location.hostname}`;
window.createStoreage = new Storeage(namespace);
ConfigProvider.config({
prefixCls: 'panda-console-base',
});
const initLocale = () => {
localStorage.setItem('umi_locale', 'zh-CN');
};
......@@ -29,15 +23,6 @@ const initLocale = () => {
initGlobalConfig();
initLocale();
// const unlisten = (function() {
// let prePathname = '';
// return history.listen(location => {
// if (location.pathname.indexOf('/civbase/user/login') > -1 && location.pathname !== prePathname) {
// initGlobalConfig();
// }
// prePathname = location.pathname;
// });
// })();
// event.on('event:logout', () => {
// store.dispatch(actionCreators.logout());
......
......@@ -11,7 +11,6 @@ const pkg = require('../../../package.json');
const { renderRoutes } = helpers;
const config = require('../../../config/config');
function App(props) {
//
const metaSecurity = /https/.test(window.location.protocol) ? (
<meta httpEquiv="Content-Security-Policy" content="upgrade-insecure-requests" />
) : null;
......
......@@ -25,7 +25,7 @@ import {
AMAP_VIEW,
PD_VIEW,
} from './constants';
import { store } from '@wisdom-utils/utils';
export function getConfig(data) {
return {
type: GET_CONFIG,
......@@ -222,6 +222,17 @@ export function logout(data) {
// eslint-disable-next-line no-undef,no-restricted-globals
createStoreage.remove(`__PANDA_STORE__MICRO_${location.hostname}`);
localStorage.removeItem('JmReport-Access-Token');
const products = (window.globalConfig.products || []).map(item => {
if (item.PackageName === 'civweb4') {
return 'web4_console'
}
return `${item.PackageName}-main`;
});
Object.keys(products).forEach(item => {
window[products[item]] && window[products[item]] && window[products[item]].unmount && window[products[item]].unmount({ store: store });
});
return {
type: LOGINOUT,
data: {
......
......@@ -36,16 +36,18 @@ export const initGlobalConfig = () => {
localStorage.removeItem('loginSite');
}
/* eslint-disable */
if (window.globalConfig.token !== null && Object.keys(window.globalConfig).length > 0) {
store.dispatch(actionCreators.getConfig(window.globalConfig));
// render({ appContent: '', loading: true });
initMicroApps(loader, store);
if (config.isNewYear) {
updateTheme('#ff9600');
}
} else {
// eslint-disable-next-line react-hooks/rules-of-hooks
let client = params.getParams('client') || Cookies.get('city');
// if (window.globalConfig.token !== null && Object.keys(window.globalConfig).length > 0) {
// store.dispatch(actionCreators.getConfig(window.globalConfig));
// // render({ appContent: '', loading: true });
// initMicroApps(loader, store);
// if (config.isNewYear) {
// updateTheme('#ff9600');
// }
// } else {
// // eslint-disable-next-line react-hooks/rules-of-hooks
// }
let client = params.getParams('client') || Cookies.get('city');
client = client && client !== 'undefined' ? client : 'city';
appService
.getWateWayConfig({
......@@ -97,12 +99,14 @@ export const initGlobalConfig = () => {
// eslint-disable-next-line no-new
new Login(
{
global: Object.assign({}, data, {
token: getToken(),
}),
global: Object.assign({}, data,
{
token: getToken(),
},
gateWayConfig,
),
// eslint-disable-next-line no-shadow
updateConfig: data =>
store.dispatch(actionCreators.getConfig(data)),
updateConfig: data => store.dispatch(actionCreators.getConfig(data)),
isInit: false,
logout: () => store.dispatch(actionCreators.logout()),
},
......@@ -117,23 +121,14 @@ export const initGlobalConfig = () => {
true,
);
}
// eslint-disable-next-line no-shadow
}
return res;
})
// eslint-disable-next-line no-shadow
.then(res => {
// eslint-disable-next-line no-use-before-define
// initSensorType();
// eslint-disable-next-line no-use-before-define
// initIsMock();
render({ appContent: '', loading: true });
})
.catch(error => {
console.log(error);
store.dispatch(actionCreators.getConfigError(error));
});
});
}
};
......@@ -223,6 +223,10 @@ const Layout = props => {
props.logout();
return;
}
}, [props.global]);
useEffect(() => {
if (
props.global &&
props.global.userInfo &&
......@@ -234,7 +238,7 @@ const Layout = props => {
setCityData(res);
});
}
}, [props.global]);
}, [props.global.userInfo])
const handlerPageChange = () => {
......@@ -252,7 +256,11 @@ const Layout = props => {
useEffect(() => {
window.share.event.on('updateSite', res => setCityData(res));
window.share.event.on('updateSite', res => {
debugger
setCityData(res)
});
return () => {
window.share.event.removeAllListeners('updateSite');
};
......
import React from 'react';
import Cookies from 'js-cookie';
import { connect } from 'react-redux';
import { Redirect } from '@wisdom-utils/runtime';
import { Redirect, history } from '@wisdom-utils/runtime';
import { PageLoading } from '@ant-design/pro-layout';
import _ from 'lodash';
import { stringify } from 'querystring';
import { store, helpers } from '@wisdom-utils/utils';
class SecurityLayout extends React.Component {
state = {
......@@ -19,7 +20,7 @@ class SecurityLayout extends React.Component {
componentWillReceiveProps(nextProps) {
const products = (this.props.global.products || []).map(item => {
if(item.PackageName === 'civweb4') {
if (item.PackageName === 'civweb4') {
return 'web4_console'
}
return `${item.PackageName}-main`;
......@@ -30,35 +31,36 @@ class SecurityLayout extends React.Component {
const nextPathname = nextProps.location.pathname;
const nextArgv = nextPathname.split('/');
if(argv[1] !== nextArgv[1]) {
if (argv[2] !== nextArgv[2]) {
Object.keys(products).forEach(item => {
window[products[item]] && window[products[item]] && window[products[item]].unmount && window[products[item]].unmount({store: store});
window[products[item]] && window[products[item]] && window[products[item]].unmount && window[products[item]].unmount({ store: store });
});
}
if(this.props.location.pathname !== nextProps.location.pathname) {
store.set('event:globalConfig', {globalConfig: nextProps.global});
if (this.props.location.pathname !== nextProps.location.pathname) {
store.set('event:globalConfig', { globalConfig: nextProps.global });
}
}
render() {
const { isReady } = this.state;
const { children, global, loading } = this.props;
const isLogin = Cookies.get('token') !== null && global.token !== null;
// const queryString = stringify({
// redirect: window.location.href,
// });
if (!Cookies.get('token')) {
if (!isLogin && window.location.pathname !== '/civbase/user/login') {
const { query = {}, search, pathname } = history.location;
const { redirect } = query;
const queryString = stringify({
redirect: pathname + search,
});
this.props.updateCurrentIndex && this.props.updateCurrentIndex(0);
let client = global.client || Cookies.get('city');
client = client !== 'undefined' && !_.isNull(client) && !_.isUndefined(client) ? client : 'city';
// event.emit(?'event:initConfig');
let { generateType } = global;
generateType = !_.isNull(generateType) && !_.isUndefined(generateType) && generateType !== 'undefined' ? `&generateType=${generateType}` : '';
generateType = !_.isNull(generateType) && !_.isUndefined(generateType) && generateType !== 'undefined' ? `&generateType=${generateType}` : '';
return (
<Redirect
to={`/user/login?client=${client}${generateType}`}
to={`/user/login?client=${client}${generateType}&${queryString}`}
/>
);
}
......
......@@ -337,13 +337,13 @@ class Site {
self.props.updateCurrentIndex && self.props.updateCurrentIndex(-1);
const login = new Login(this.props, () => {
self.setLoading(false);
self.getCityStationsForUser().then(res => {
window.share.event.emit('updateSite', res);
});
// eslint-disable-next-line no-unused-expressions
self.props.updateCurrentIndex && self.props.updateCurrentIndex(0);
// debugger
// initMicroApps();
// 切换站点后,重置掉三级菜单
const homeType = self.globalConfig.homeType || 'civweb4';
const homePath = self.globalConfig.homepage ? self.globalConfig.homepage.startsWith(homeType) ? self.globalConfig.homepage: `/${homeType}/${self.globalConfig.homepage}`: `/${homeType}`;
......@@ -355,17 +355,10 @@ class Site {
// 重新加载订阅消息铃铛
window.share && window.share.event && window.share.event.emit('reloadNotice');
const config = self.globalConfig;
let url = !config.home ? ((config.homepage === '' || _.isNull(config.homepage)) ? `/civweb4`: `/civweb4/${config.homepage.replace(/^\//, '').replace(/^civweb4\//, '')}`) : `/${config.homepage.replace(/^\//, '')}`;
self.props.history && self.props.history.push(url)
self.getCityStationsForUser().then(res => {
window.share.event.emit('updateSite', res);
});
self.props &&
self.props.updateCollapsed &&
self.props.updateCollapsed(false);
const config = self.globalConfig;
let url = !config.home ? ((config.homepage === '' || _.isNull(config.homepage)) ? `/civweb4`: `/civweb4/${config.homepage.replace(/^\//, '').replace(/^civweb4\//, '')}`) : `/${config.homepage.replace(/^\//, '')}`;
self.props.history && self.props.history.push(url);
self.props && self.props.updateCollapsed && self.props.updateCollapsed(false);
window.share.event.emit('triggerMicro', this.props.global);
onChangeVisible && onChangeVisible(false);
});
......
......@@ -106,7 +106,7 @@ export const initMicroApps = () => {
// createStoreage.remove(`__PANDA_STORE__${location.hostname}`)
},
],
afterUnmount: [app => {
afterUnmount: [app => {
actions.offGlobalStateChange();
Logger.info(`[LifeCycle] after unmount %c%s ${app.name}`, app);
}],
......@@ -174,7 +174,10 @@ export const initMicroApps = () => {
url.indexOf('https://maponline1.bdimg.com') !== -1 ||
url.indexOf('https://maponline2.bdimg.com') !== -1 ||
url.indexOf('https://maponline3.bdimg.com') !== -1 ||
url.indexOf('https://api.map.baidu.com/getscript') !== -1,
url.indexOf('https://api.map.baidu.com/getscript') !== -1 ||
url.indexOf('dlswbr.baidu.com') !== -1 ||
url.indexOf('maponline0.bdimg.com') !== -1 ||
url.indexOf('miao.baidu.com') !== -1,
});
runAfterFirstMounted(() => {
Logger.info('[MainApp] first app mounted');
......@@ -189,12 +192,13 @@ export const initMicroApps = () => {
};
export const defaultApp = () => {
// eslint-disable-next-line no-undef
const config = window.globalConfig;
if (config && config.token) {
let url = !config.home ? ((config.homepage === '' || _.isNull(config.homepage)) ? `/civbase/civweb4`: `/civbase/civweb4/${config.homepage.replace(/^\//, '').replace(/^civweb4\//, '')}`) : `/civbase/${config.homepage.replace(/^\//, '')}`;
let url = !config.home ?
((config.homepage === '' || _.isNull(config.homepage)) ? `/civbase/civweb4`: (`/civbase/${config.homepage.replace(/^\//, '')}`)) : `/civbase/${config.homepage.replace(/^\//, '')}`;
setDefaultMountApp(url);
}
};
......@@ -302,7 +306,8 @@ window.app.define('kit_global_config', require.context('../node_modules/kit_glob
window.app.define('@wisdom-utils/utils', require.context('../node_modules/@wisdom-utils/utils/lib', true, /^.\/(lib\/)?[^\/]+\.js$/), 'index.js');
window.app.define('@wisdom-utils/runtime', require.context('../node_modules/@wisdom-utils/runtime/lib', true, /^.\/(lib\/)?[^\/]+\.js$/), 'index.js');
window.app.define('@wisdom-utils/components', require.context('../node_modules/@wisdom-utils/components/lib', true, /^.\/(lib\/)?[^\/]+\.js$/), 'index.js');
window.app.define('axios', require.context('../node_modules/axios/lib', true, /^.\/(lib\/)?[^\/]+\.js$/), 'axios.js');
window.app.define('js-base64', require.context('../node_modules/js-base64', true, /[^\/]+\.js$/), 'base64.js');
/**
* arcgismap
*/
......@@ -495,6 +500,10 @@ window.app.define('@wisdom-utils/components', require.context('../node_modules/@
window.app.define('@ant-design/pro-list', require.context('../node_modules/@ant-design/pro-list/lib', true, /^.\/(lib\/)?[^\/]+\.js$/), 'index.js');
window.app.define('antd', require.context('../node_modules/antd/es', true, /^.\/(es\/)?[^\/]+\.js$/), 'index.js');
// window.app.define('antd-es-button-style', require.context('../node_modules/antd/es/button/style', true, /\.js/));
// window.app.define('antd-es-input-style', require.context('../node_modules/antd/es/input/style', true, /\.js/));
// window.app.define('style-button', require.context('../node_modules/antd/es/button/style', /^.\/(style\/)?[^\/]+\.js$/), 'index.js');
window.app.define('classnames', require.context('classnames', true, /^.\/index\.js$/), 'index.js');
window.app.define('@ant-design/icons', require.context('../node_modules/@ant-design/icons/lib', true, /^.\/(lib\/)?[^\/]+\.js$/), 'index.js');
window.app.define('@ant-design/pro-utils', require.context('../node_modules/@ant-design/pro-utils/lib', true, /^.\/(lib\/)?[^\/]+\.js$/), 'index.js');
......
import React from 'react';
import React, { useEffect } from 'react';
import BaseLogin from './template/baseLogin';
import NewYear from './template/newYear';
import InfoLogin from './template/infoLogin';
import Yulin from './template/yulin';
import { getParams } from '@wisdom-utils/utils/lib/helpers/params';
// import { useParams } from '@wisdom-utils/runtime';
import { initGlobalConfig } from '../../../initConfig';
const LoginTemplate = {
'新春 - 智联.html': NewYear,
'Dark - IOTMultiLogin.html': BaseLogin,
'Dark.html': BaseLogin,
'DarkCloud.html': BaseLogin,
'信息化.html': InfoLogin,
'项目 - 榆林.html': Yulin,
'default': BaseLogin
};
/* eslint-disable */
export default () => {
React.useEffect(() => {
export default (props) => {
const redirect = getParams('redirect');
useEffect(() => {
if(getParams('loginName') && getParams('password')) return
initGlobalConfig();
}, []);
const loginTemplate = window.globalConfig && window.globalConfig.loginTemplate;
switch(loginTemplate) {
case '新春 - 智联.html':
return <NewYear/>
case 'Dark - IOTMultiLogin.html':
case 'Dark.html':
return <BaseLogin/>
case '信息化.html':
return <InfoLogin />
case '项目 - 榆林.html':
return <Yulin />
default:
return <BaseLogin/>;
}
}, [redirect]);
const template = window.globalConfig && window.globalConfig.loginTemplate;
const RenderComponent = LoginTemplate[template] ? LoginTemplate[template]: LoginTemplate['default'];
return <RenderComponent {...props}/>
};
......@@ -114,18 +114,27 @@ class Login {
}).then(response => {
if (response && !response.errMsg) {
self.globalConfig.userInfo = {};
if (
response.Groups &&
response.Groups instanceof Array &&
response.Groups.length
) {
self.globalConfig.userInfo.Groups = response.Groups;
if(response.hasOwnProperty('data')) {
self.globalConfig.userInfo = {
// ... self.globalConfig.userInfo,
...response.data
}
} else {
if (
response.Groups &&
response.Groups instanceof Array &&
response.Groups.length
) {
self.globalConfig.userInfo.Groups = response.Groups;
}
self.globalConfig.userInfo = Object.assign(
{},
response,
self.globalConfig.userInfo,
);
}
self.globalConfig.userInfo = Object.assign(
{},
response,
self.globalConfig.userInfo,
);
self.updateConfig && self.updateConfig(self.globalConfig);
self.getUserInfoAndConfig();
} else {
......
......@@ -2,20 +2,34 @@ import React from 'react';
import ReactDOM from 'react-dom';
import { history } from '@wisdom-utils/runtime';
import { Provider } from 'react-redux';
import { ConfigProvider } from 'antd';
import { ConfigProvider, message, Modal, notification } from 'antd';
import { ConnectedRouter } from 'connected-react-router/immutable';
import { ErrorBoundary, LocaleContainer } from '@wisdom-utils/components';
import store from './stores';
import Container from './components/Container';
import App from './containers/App';
const MOUNT_NODE = document.getElementById('root');
const customPrefixCls = 'panda-console-base';
Modal.config({
rootPrefixCls: customPrefixCls
});
message.config({
rootPrefixCls: customPrefixCls
});
notification.config({
rootPrefixCls: customPrefixCls
});
ConfigProvider.config({
prefixCls: customPrefixCls,
});
export const render = () => {
// eslint-disable-next-line react-hooks/rules-of-hooks
ReactDOM.render(
<Provider store={store}>
<ConnectedRouter history={history}>
<LocaleContainer>
<ConfigProvider prefixCls="panda-console-base">
<ConfigProvider prefixCls={customPrefixCls}>
<ErrorBoundary>
<Container>
<App />
......
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