Commit c8d7d320 authored by 邓晓峰's avatar 邓晓峰

fix: 修复topbar样式

parent ca994e24
Pipeline #47278 skipped with stages
{ {
"printWidth": 80, "printWidth": 120,
"tabWidth": 2, "tabWidth": 2,
"useTabs": false, "useTabs": false,
"semi": true, "semi": true,
......
...@@ -65,7 +65,7 @@ module.exports = { ...@@ -65,7 +65,7 @@ module.exports = {
return localName; return localName;
} }
const match = context.resourcePath.match(/src(.*)/); const match = context.resourcePath.match(/(src(.*))/);
if (match && match[1]) { if (match && match[1]) {
const antdProPath = match[1].replace('.less', ''); const antdProPath = match[1].replace('.less', '');
...@@ -73,10 +73,7 @@ module.exports = { ...@@ -73,10 +73,7 @@ module.exports = {
.split('/') .split('/')
.map(a => a.replace(/([A-Z])/g, '-$1')) .map(a => a.replace(/([A-Z])/g, '-$1'))
.map(a => a.toLowerCase()); .map(a => a.toLowerCase());
return `panda-console-base${arr.join('-')}-${localName}`.replace( return `panda-console-base${arr.join('-')}-${localName}`.replace(/--/g, '-');
/--/g,
'-',
);
} }
return localName; return localName;
}, },
......
...@@ -12,7 +12,6 @@ module.exports = { ...@@ -12,7 +12,6 @@ module.exports = {
title: '熊猫智慧城市监控管理解决方案', title: '熊猫智慧城市监控管理解决方案',
iconfontUrl: '', iconfontUrl: '',
primaryColor: '#1890ff', primaryColor: '#1890ff',
logo: logo: 'https://panda-water.cn/web4/assets/images/logo/%E5%8D%95%E7%8B%AC%E5%9B%BE%E6%A1%88-%E7%99%BD%E8%89%B2.svg',
'https://panda-water.cn/web4/assets/images/logo/%E5%8D%95%E7%8B%AC%E5%9B%BE%E6%A1%88-%E7%99%BD%E8%89%B2.svg',
name: '熊猫智慧城市监控管理解决方案', name: '熊猫智慧城市监控管理解决方案',
}; };
This diff is collapsed.
...@@ -15,7 +15,7 @@ module.exports = require('./webpack.base.babel')({ ...@@ -15,7 +15,7 @@ module.exports = require('./webpack.base.babel')({
optimization: { optimization: {
// namedModules: true, // namedModules: true,
// namedChunks: true, // namedChunks: true,
chunkIds: "named", chunkIds: 'named',
runtimeChunk: { runtimeChunk: {
name: 'runtime', name: 'runtime',
}, },
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
"build": "cross-env NODE_ENV=production node --max_old_space_size=4096 internals/webpack/build.js", "build": "cross-env NODE_ENV=production node --max_old_space_size=4096 internals/webpack/build.js",
"build:clean": "rimraf ./build", "build:clean": "rimraf ./build",
"openapi": "cross-env NODE_ENV=development node server/openapi/run.js", "openapi": "cross-env NODE_ENV=development node server/openapi/run.js",
"start": "cross-env REACT_APP_ENV=dev NODE_ENV=development node --max_old_space_size=8192 server --port=$port", "start": "cross-env REACT_APP_ENV=dev NODE_ENV=development node --max_old_space_size=4192 server --port=$port",
"start:tunnel": "cross-env NODE_ENV=development ENABLE_TUNNEL=true node server", "start:tunnel": "cross-env NODE_ENV=development ENABLE_TUNNEL=true node server",
"start:production": "npm run test && npm run build && npm run start:prod", "start:production": "npm run test && npm run build && npm run start:prod",
"start:prod": "cross-env NODE_ENV=production node server", "start:prod": "cross-env NODE_ENV=production node server",
...@@ -110,9 +110,9 @@ ...@@ -110,9 +110,9 @@
"@wisdom-map/Map": "^1.0.12-17", "@wisdom-map/Map": "^1.0.12-17",
"@wisdom-map/arcgismap": "^1.0.79-17", "@wisdom-map/arcgismap": "^1.0.79-17",
"@wisdom-map/util": "^1.0.27-0", "@wisdom-map/util": "^1.0.27-0",
"@wisdom-utils/components": "0.0.37", "@wisdom-utils/components": "0.0.56",
"@wisdom-utils/runtime": "0.0.15", "@wisdom-utils/runtime": "0.0.15",
"@wisdom-utils/utils": "0.0.77", "@wisdom-utils/utils": "0.0.95",
"animate.css": "^4.1.1", "animate.css": "^4.1.1",
"antd": "^4.17.4", "antd": "^4.17.4",
"compression": "1.7.4", "compression": "1.7.4",
...@@ -288,6 +288,7 @@ ...@@ -288,6 +288,7 @@
"svg-url-loader": "^2.3.2", "svg-url-loader": "^2.3.2",
"swagger-ui-react": "^4.0.0-beta.4", "swagger-ui-react": "^4.0.0-beta.4",
"swagger2openapi": "^7.0.5", "swagger2openapi": "^7.0.5",
"swc-loader": "^0.1.15",
"terser-webpack-plugin": "1.2.3", "terser-webpack-plugin": "1.2.3",
"traverse": "^0.6.6", "traverse": "^0.6.6",
"umi-webpack-bundle-analyzer": "3.6.0", "umi-webpack-bundle-analyzer": "3.6.0",
......
...@@ -32,11 +32,7 @@ initLocale(); ...@@ -32,11 +32,7 @@ initLocale();
const unlisten = (function() { const unlisten = (function() {
let prePathname = ''; let prePathname = '';
return history.listen(location => { return history.listen(location => {
if ( if (location.pathname.indexOf('/civbase/user/login') > -1 && location.pathname !== prePathname) {
location.pathname.indexOf('/civbase/user/login') > -1 &&
location.pathname !== prePathname
) {
console.log('init config');
initGlobalConfig(); initGlobalConfig();
} }
prePathname = location.pathname; prePathname = location.pathname;
......
...@@ -5,11 +5,7 @@ import { connect } from 'react-redux'; ...@@ -5,11 +5,7 @@ import { connect } from 'react-redux';
import Icon from '@ant-design/icons'; import Icon from '@ant-design/icons';
import classNames from 'classnames'; import classNames from 'classnames';
import { useHistory } from '@wisdom-utils/runtime'; import { useHistory } from '@wisdom-utils/runtime';
import { import { HeaderSearch, useIntl, AvatarDropdown as Avatar } from '@wisdom-utils/components';
HeaderSearch,
useIntl,
AvatarDropdown as Avatar,
} from '@wisdom-utils/components';
import { actionCreators } from '../../containers/App/store'; import { actionCreators } from '../../containers/App/store';
import styles from './index.less'; import styles from './index.less';
import NoticeIconView from './NoticeIconView'; import NoticeIconView from './NoticeIconView';
......
...@@ -2,20 +2,9 @@ import React, { Component } from 'react'; ...@@ -2,20 +2,9 @@ import React, { Component } from 'react';
import { Button, Form, Input, Modal } from 'antd'; import { Button, Form, Input, Modal } from 'antd';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { import { Notifier, NoticeIcon, FormattedMessage } from '@wisdom-utils/components';
Notifier, import { ERR_OK, MESSAGE_TYPE, NEW_MESSAGE } from '@wisdom-utils/components/lib/AppLayout/notifier/constants';
NoticeIcon, import { findPathByWidget, isJSON } from '@wisdom-utils/components/lib/AppLayout/helpers';
FormattedMessage,
} from '@wisdom-utils/components';
import {
ERR_OK,
MESSAGE_TYPE,
NEW_MESSAGE,
} from '@wisdom-utils/components/lib/AppLayout/notifier/constants';
import {
findPathByWidget,
isJSON,
} from '@wisdom-utils/components/lib/AppLayout/helpers';
import service from '../../api/service/notification'; import service from '../../api/service/notification';
import { actionCreators } from '../../containers/App/store'; import { actionCreators } from '../../containers/App/store';
import isProd from '../../utils/env'; import isProd from '../../utils/env';
......
...@@ -46,22 +46,22 @@ ...@@ -46,22 +46,22 @@
background: #fff; background: #fff;
} }
} }
.account { //.account {
.avatar { // .avatar {
margin: ~'calc((@{layout-header-height} - 24px) / 2)' 0; // margin: ~'calc((@{layout-header-height} - 24px) / 2)' 0;
// margin-right: 8px; // // margin-right: 8px;
color: @primary-color; // color: @primary-color;
vertical-align: top; // vertical-align: top;
background: rgba(255, 255, 255, 0.85); // background: rgba(255, 255, 255, 0.85);
width: 36px; // width: 36px;
height: 36px; // height: 36px;
border-radius: 50%; // border-radius: 50%;
box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.3); // box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.3);
transition: box-shadow 0.1s linear, opacity 0.4s linear; // transition: box-shadow 0.1s linear, opacity 0.4s linear;
background-position: center; // background-position: center;
overflow: hidden; // overflow: hidden;
} // }
} //}
} }
.dark { .dark {
......
...@@ -3,45 +3,28 @@ import React from 'react'; ...@@ -3,45 +3,28 @@ import React from 'react';
import { Helmet } from 'react-helmet'; import { Helmet } from 'react-helmet';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { Router, Switch } from '@wisdom-utils/runtime'; import { Router, Switch } from '@wisdom-utils/runtime';
import { renderRoutes } from '../../utils/routes'; import { helpers } from '@wisdom-utils/utils';
// eslint-disable-next-line import/extensions
import { dyRoutes } from '../../routes/config'; import { dyRoutes } from '../../routes/config';
const pkg = require('../../../package.json'); const pkg = require('../../../package.json');
const config = require('../../../config/config'); const config = require('../../../config/config');
const defaultSetting = config.layout; const defaultSetting = config.layout;
const { renderRoutes } = helpers;
function App(props) { function App(props) {
// //
const metaSecurity = /https/.test(window.location.protocol) ? ( const metaSecurity = /https/.test(window.location.protocol) ? (
<meta <meta httpEquiv="Content-Security-Policy" content="upgrade-insecure-requests" />
httpEquiv="Content-Security-Policy"
content="upgrade-insecure-requests"
/>
) : null; ) : null;
return ( return (
<> <>
<Helmet <Helmet title={`${(props.global && props.global.title) || defaultSetting.title}`}>
title={`${(props.global && props.global.title) || <title>{`${(props.global && props.global.title) || defaultSetting.title}`}</title>
defaultSetting.title}`} <link rel="shortcut icon" href={`https://panda-water.cn/web4/${props.global && props.global.shortcutIcon}`} />
>
<title>{`${(props.global && props.global.title) ||
defaultSetting.title}`}</title>
<link
rel="shortcut icon"
href={`https://panda-water.cn/web4/${props.global &&
props.global.shortcutIcon}`}
/>
{metaSecurity} {metaSecurity}
<meta <meta name="description" content={`${props.global && props.global.title}`} />
name="description"
content={`${props.global && props.global.title}`}
/>
</Helmet> </Helmet>
<Router basename={config.base || pkg.name.toLocaleLowerCase() || ''}> <Router basename={config.base || pkg.name.toLocaleLowerCase() || ''}>
<Switch> <Switch>{renderRoutes('panda-console-base', dyRoutes(props.menu || [], props.global.layout).routes)}</Switch>
{renderRoutes(dyRoutes(props.menu || [], props.global.layout).routes)}
</Switch>
</Router> </Router>
</> </>
); );
......
import { fromJS } from 'immutable'; import { fromJS } from 'immutable';
import Cookies from 'js-cookie'; import Cookies from 'js-cookie';
import { AppConfig, store, event, Storage } from '@wisdom-utils/utils'; import { AppConfig, store, event, Storage, helpers } from '@wisdom-utils/utils';
import { Storeage as Store } from '@wisdom-utils/utils/lib/helpers'; import { Storeage as Store } from '@wisdom-utils/utils/lib/helpers';
import pkg from '../../../../package.json'; import pkg from '../../../../package.json';
import defaultSetting from '../../../../config/defaultSetting'; import defaultSetting from '../../../../config/defaultSetting';
import generRoutes, { // import { transformWidgets } from '../../../utils/routes';
generFlatRoutes, // eslint-disable-next-line import/no-duplicates
transformWidgets,
} from '../../../utils/routes';
import { import {
CLEAR_RCENT_KEYWORD, CLEAR_RCENT_KEYWORD,
COMPLEX_CONFIG, COMPLEX_CONFIG,
...@@ -35,20 +33,14 @@ import { ...@@ -35,20 +33,14 @@ import {
PD_VIEW, PD_VIEW,
} from './constants'; } from './constants';
const { generMainRoutes, generFlatRoutes, transformWidgets } = helpers;
const proxy = require('../../../../config/proxy'); const proxy = require('../../../../config/proxy');
const keywordStorage = new Storage( const keywordStorage = new Storage(`__global_search_keywords__micro_${window.location.hostname}`);
`__global_search_keywords__micro_${window.location.hostname}`, const recentVisitedStorage = new Storage(`__global_recent_visited__micro_${window.location.hostname}`);
); const recentProductStorage = new Storage(`__global__recent_product__micro_${window.location.hostname}`);
const recentVisitedStorage = new Storage( const currentProduct = new Store(`__global__recent_productIndex__micro_${window.location.hostname}`);
`__global_recent_visited__micro_${window.location.hostname}`,
);
const recentProductStorage = new Storage(
`__global__recent_product__micro_${window.location.hostname}`,
);
const currentProduct = new Store(
`__global__recent_productIndex__micro_${window.location.hostname}`,
);
Cookies.set('loginMode', Cookies.get('loginMode') || 'pdw'); Cookies.set('loginMode', Cookies.get('loginMode') || 'pdw');
export const initialState = fromJS({ export const initialState = fromJS({
globalConfig: {}, globalConfig: {},
...@@ -80,12 +72,9 @@ export const initialState = fromJS({ ...@@ -80,12 +72,9 @@ export const initialState = fromJS({
const appReducer = (state = initialState, action) => { const appReducer = (state = initialState, action) => {
switch (action.type) { switch (action.type) {
case GET_CONFIG: case GET_CONFIG:
// eslint-disable-next-line no-debugger /* eslint-disable */
// eslint-disable-next-line no-underscore-dangle
window.__INITIAL_STATE__ = Object.assign( window.__INITIAL_STATE__ = Object.assign(
{}, {},
// eslint-disable-next-line no-underscore-dangle
action.data, action.data,
{ {
assetsRoot: proxy.assetsRoot, assetsRoot: proxy.assetsRoot,
...@@ -93,14 +82,10 @@ const appReducer = (state = initialState, action) => { ...@@ -93,14 +82,10 @@ const appReducer = (state = initialState, action) => {
env: process.env.NODE_ENV === 'development' ? 'daily' : 'prod', env: process.env.NODE_ENV === 'development' ? 'daily' : 'prod',
}, },
); );
window.arcgisAssetsPath = `${ window.arcgisAssetsPath = `${window.location.origin}/${pkg.name.toLocaleLowerCase()}/assets`;
window.location.origin
}/${pkg.name.toLocaleLowerCase()}/assets`;
// eslint-disable-next-line global-require,no-underscore-dangle
window.__INITIAL_STATE__.mdi = 'SDI'; window.__INITIAL_STATE__.mdi = 'SDI';
window.__INITIAL_STATE__.menu = 'banner-left'; window.__INITIAL_STATE__.menu = 'banner-left';
window.globalConfig = AppConfig(window.__INITIAL_STATE__); window.globalConfig = AppConfig(window.__INITIAL_STATE__);
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
createStoreage.set('globalConfig', window.globalConfig); createStoreage.set('globalConfig', window.globalConfig);
// eslint-disable-next-line no-undef,no-case-declarations // eslint-disable-next-line no-undef,no-case-declarations
...@@ -109,14 +94,11 @@ const appReducer = (state = initialState, action) => { ...@@ -109,14 +94,11 @@ const appReducer = (state = initialState, action) => {
// eslint-disable-next-line no-case-declarations // eslint-disable-next-line no-case-declarations
const { homepage } = window.globalConfig; const { homepage } = window.globalConfig;
const modulePkg = {}; const modulePkg = {};
window.globalConfig && window.globalConfig && window.globalConfig.products && Array.isArray(window.globalConfig.products) && window.globalConfig.products.map(item => {
window.globalConfig.products &&
Array.isArray(window.globalConfig.products) &&
window.globalConfig.products.map(item => {
modulePkg[item.PackageName] = item; modulePkg[item.PackageName] = item;
}); });
config.widgets = transformWidgets(config.widgets); config.widgets = transformWidgets(config.widgets);
const generMenu = generRoutes(config.widgets || [], null, 0, modulePkg); const generMenu = generMainRoutes(config.widgets || [], null, 0, modulePkg);
let flatMenu = []; let flatMenu = [];
if (generMenu) { if (generMenu) {
flatMenu = generFlatRoutes(generMenu || [], null, null, modulePkg); flatMenu = generFlatRoutes(generMenu || [], null, null, modulePkg);
...@@ -133,27 +115,14 @@ const appReducer = (state = initialState, action) => { ...@@ -133,27 +115,14 @@ const appReducer = (state = initialState, action) => {
let currentMenuIndex = 0; let currentMenuIndex = 0;
if (home) { if (home) {
const parent = const parent = home.level >= 2 ? home.parent.parent : home.level >= 3 ? home.parent.parent.parent : home.parent;
home.level >= 2
? home.parent.parent
: home.level >= 3
? home.parent.parent.parent
: home.parent;
if (parent) { if (parent) {
currentMenuIndex = generMenu.findIndex( currentMenuIndex = generMenu.findIndex(item => item.name === parent.label);
item => item.name === parent.label,
);
currentProduct.set('currentMenuIndex', currentMenuIndex); currentProduct.set('currentMenuIndex', currentMenuIndex);
store.set('updateMenuIndex', currentMenuIndex); store.set('updateMenuIndex', currentMenuIndex);
} }
} }
// eslint-disable-next-line no-case-declarations
// eslint-disable-next-line no-case-declarations
window.globalConfig.home = home; window.globalConfig.home = home;
Cookies.set('city', Cookies.get('city') || window.globalConfig.client); Cookies.set('city', Cookies.get('city') || window.globalConfig.client);
window.globalConfig = config; window.globalConfig = config;
return state.merge({ return state.merge({
......
...@@ -3,7 +3,7 @@ import { params, Storeage } from '@wisdom-utils/utils/lib/helpers'; ...@@ -3,7 +3,7 @@ import { params, Storeage } from '@wisdom-utils/utils/lib/helpers';
import { appService } from './api'; import { appService } from './api';
import { initMicroApps } from './micro'; import { initMicroApps } from './micro';
import { actionCreators } from './containers/App/store'; import { actionCreators } from './containers/App/store';
import { getToken, isString } from './utils/utils'; import { getToken } from './utils/utils';
import loader, { render } from './render'; import loader, { render } from './render';
import store from './stores'; import store from './stores';
import Login from './pages/user/login/login'; import Login from './pages/user/login/login';
...@@ -11,64 +11,55 @@ import Login from './pages/user/login/login'; ...@@ -11,64 +11,55 @@ import Login from './pages/user/login/login';
const namespace = `__PANDA_STORE__${location.hostname}`; const namespace = `__PANDA_STORE__${location.hostname}`;
window.createStoreage = new Storeage(namespace); window.createStoreage = new Storeage(namespace);
export const initGlobalConfig = () => { export const initGlobalConfig = () => {
/* eslint-disable */
// eslint-disable-next-line no-debugger createStoreage.remove(`__PANDA_STORE__${location.hostname}`);
window.globalConfig = {};
window.__INITIAL_STATE__ = {};
let config = window.globalConfig || {};
// createStoreage.get('globalConfig') || {};
store.dispatch(actionCreators.updateComplexConfig({}));
if (!getToken() || config.token == null) {
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
createStoreage.remove(`__PANDA_STORE__${location.hostname}`); createStoreage.remove(namespace);
window.globalConfig = {}; config = {};
window.__INITIAL_STATE__ = {}; }
let config = window.globalConfig || {}; if (!params.getParams('client', window.location.search) && config) {
//createStoreage.get('globalConfig') || {};
store.dispatch(actionCreators.updateComplexConfig({}));
if (!getToken() || config.token == null) {
// eslint-disable-next-line no-undef
createStoreage.remove(namespace);
config = {};
}
if (!params.getParams('client', window.location.search) && config) {
// eslint-disable-next-line no-undef
createStoreage.remove(namespace);
}
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
if (!createStoreage.get('globalConfig')) { createStoreage.remove(namespace);
window.createStoreage = new Storeage(namespace); }
}
if (!getToken()) {
localStorage.removeItem('loginSite');
}
if (window.globalConfig.token !== null && Object.keys(window.globalConfig).length > 0) { // eslint-disable-next-line no-undef
store.dispatch(actionCreators.getConfig(window.globalConfig)); if (!createStoreage.get('globalConfig')) {
// render({ appContent: '', loading: true }); window.createStoreage = new Storeage(namespace);
initMicroApps(loader, store); }
if (config.isNewYear) { if (!getToken()) {
updateTheme('#ff9600'); localStorage.removeItem('loginSite');
} }
} else { /* eslint-disable */
// eslint-disable-next-line react-hooks/rules-of-hooks if (window.globalConfig.token !== null && Object.keys(window.globalConfig).length > 0) {
let client = params.getParams('client') || Cookies.get('city') store.dispatch(actionCreators.getConfig(window.globalConfig));
client = client && client !== 'undefined' ? client : 'city'; // render({ appContent: '', loading: true });
appService.getWateWayConfig({ 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({
ignoreSite: true, ignoreSite: true,
}).then(res => { })
const hasGateWay = .then(res => {
!res || !res.data ? false : isString(res.data) ? JSON.parse(res.data) : typeof res.data === 'boolean' ? res.data : false; /* eslint-disable */
// if (res.code === 0 && res.data === 'true') { const hasGateWay = !res || !res.data ? false : _.isString(res.data) ? JSON.parse(res.data) : typeof res.data === 'boolean' ? res.data : false;
// store.dispatch(
// actionCreators.getConfig(
// Object.assign({}, window.globalConfig, {
// hasGateWay,
// apiGatewayDomain: `${window.location.origin}/PandaCore`,
// }),
// ),
// );
// }
return { return {
hasGateWay, hasGateWay,
apiGatewayDomain: `${window.location.origin}/PandaCore`, apiGatewayDomain: `${window.location.origin}/PandaCore`,
} };
}).then((gateWayConfig) => { })
.then(gateWayConfig => {
appService appService
.queryConfig({ .queryConfig({
client: client || 'city', client: client || 'city',
...@@ -83,22 +74,26 @@ export const initGlobalConfig = () => { ...@@ -83,22 +74,26 @@ export const initGlobalConfig = () => {
// Cookies.set('city', data.client); // Cookies.set('city', data.client);
store.dispatch( store.dispatch(
actionCreators.getConfig( actionCreators.getConfig(
Object.assign({}, data, { Object.assign(
token: '', {},
access_token: '', data,
userInfo: null {
}, gateWayConfig), token: '',
access_token: '',
userInfo: null,
},
gateWayConfig,
),
), ),
); );
//Cookies.set('city', params.getParams('client')) // Cookies.set('city', params.getParams('client'))
if (data.loginTemplate === '新春 - 智联.html') { if (data.loginTemplate === '新春 - 智联.html') {
updateTheme('#ff9600'); updateTheme('#ff9600');
} }
// eslint-disable-next-line no-new // eslint-disable-next-line no-new
if (getToken()) { if (getToken()) {
// eslint-disable-next-line no-new // eslint-disable-next-line no-new
new Login( new Login(
{ {
...@@ -106,7 +101,8 @@ export const initGlobalConfig = () => { ...@@ -106,7 +101,8 @@ export const initGlobalConfig = () => {
token: getToken(), token: getToken(),
}), }),
// eslint-disable-next-line no-shadow // eslint-disable-next-line no-shadow
updateConfig: data =>store.dispatch(actionCreators.getConfig(data)), updateConfig: data =>
store.dispatch(actionCreators.getConfig(data)),
isInit: false, isInit: false,
logout: () => store.dispatch(actionCreators.logout()), logout: () => store.dispatch(actionCreators.logout()),
}, },
...@@ -114,7 +110,8 @@ export const initGlobalConfig = () => { ...@@ -114,7 +110,8 @@ export const initGlobalConfig = () => {
(async () => { (async () => {
(await (getToken() && (await (getToken() &&
window.globalConfig && window.globalConfig &&
window.globalConfig.token)) && initMicroApps(loader, store); window.globalConfig.token)) &&
initMicroApps(loader, store);
})(); })();
}, },
true, true,
...@@ -138,6 +135,5 @@ export const initGlobalConfig = () => { ...@@ -138,6 +135,5 @@ export const initGlobalConfig = () => {
store.dispatch(actionCreators.getConfigError(error)); store.dispatch(actionCreators.getConfigError(error));
}); });
}); });
}
} };
};
import React, { import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
useCallback,
useEffect,
useMemo,
useRef,
useState,
} from 'react';
import { Anchor, Button, Popover, Radio, Result, Spin } from 'antd'; import { Anchor, Button, Popover, Radio, Result, Spin } from 'antd';
import { store } from '@wisdom-utils/utils'; import { store } from '@wisdom-utils/utils';
...@@ -14,19 +8,16 @@ import { dom } from '@wisdom-utils/utils/lib/helpers'; ...@@ -14,19 +8,16 @@ import { dom } from '@wisdom-utils/utils/lib/helpers';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { useMountedState } from 'react-use'; import { useMountedState } from 'react-use';
import { import { LeftOutlined, LoadingOutlined, MenuFoldOutlined } from '@ant-design/icons';
LeftOutlined,
LoadingOutlined,
MenuFoldOutlined,
} from '@ant-design/icons';
import ProLayout, { getPageTitle } from '@ant-design/pro-layout'; import ProLayout, { getPageTitle } from '@ant-design/pro-layout';
import { getMatchMenu } from '@umijs/route-utils'; import { getMatchMenu } from '@umijs/route-utils';
import { useHistory } from '@wisdom-utils/runtime'; import { useHistory } from '@wisdom-utils/runtime';
import { Panel } from '@wisdom-utils/components'; import { Panel } from '@wisdom-utils/components';
import { findPathByLeafId } from '@wisdom-utils/components/lib/AppLayout/helpers';
import RightContent from '@/components/GlobalHeader/RightContent'; import RightContent from '@/components/GlobalHeader/RightContent';
import { actionCreators } from '@/containers/App/store'; import { actionCreators } from '@/containers/App/store';
import Authorized from '@/utils/Authorized'; import Authorized from '@/utils/Authorized';
import { findPathByLeafId, getBaseName } from '@/utils/utils'; import { getBaseName } from '@/utils/utils';
import pkg from '../../package.json'; import pkg from '../../package.json';
import SecurityLayout from './SecurityLayout'; import SecurityLayout from './SecurityLayout';
import Site from './Site'; import Site from './Site';
...@@ -41,10 +32,7 @@ const antIcon = <LoadingOutlined style={{ fontSize: 12 }} spin />; ...@@ -41,10 +32,7 @@ const antIcon = <LoadingOutlined style={{ fontSize: 12 }} spin />;
// const baseURI = isProd // const baseURI = isProd
// ? window.location.origin // ? window.location.origin
// : `http://${window.location.hostname}:3020`; // : `http://${window.location.hostname}:3020`;
const optionsWith = [ const optionsWith = [{ label: '按站点', value: 'site' }, { label: '按城市', value: 'city' }];
{ label: '按站点', value: 'site' },
{ label: '按城市', value: 'city' },
];
const noMatch = ( const noMatch = (
<Result <Result
status={403} status={403}
...@@ -55,11 +43,7 @@ const noMatch = ( ...@@ -55,11 +43,7 @@ const noMatch = (
); );
const renderIcon = (icon, size, alias) => ( const renderIcon = (icon, size, alias) => (
<img <img src={icon} style={{ width: `${size}px`, height: `${size}px`, opacity: '0.8' }} alt="" />
src={icon}
style={{ width: `${size}px`, height: `${size}px`, opacity: '0.8' }}
alt=""
/>
); );
const menuExtraRender = currentRoutes => { const menuExtraRender = currentRoutes => {
...@@ -68,23 +52,13 @@ const menuExtraRender = currentRoutes => { ...@@ -68,23 +52,13 @@ const menuExtraRender = currentRoutes => {
return { return {
render: ({ collapsed }) => { render: ({ collapsed }) => {
if (currentRoutes) { if (currentRoutes) {
const iconURL = const iconURL = currentRoutes && currentRoutes.extData && currentRoutes.extData.icon;
currentRoutes && currentRoutes.extData && currentRoutes.extData.icon;
return ( return (
<> <>
<Spin <Spin spinning={currentRoutes.extData && !currentRoutes.extData.icon}>
spinning={currentRoutes.extData && !currentRoutes.extData.icon}
>
{iconURL && ( {iconURL && (
<a <a style={{ display: 'flex', alignItems: 'center' }} onClick={() => setToggleSystem(!toggleSystem)}>
style={{ display: 'flex', alignItems: 'center' }} <img src={iconURL} style={{ width: '20px', height: '20px' }} alt="" />
onClick={() => setToggleSystem(!toggleSystem)}
>
<img
src={iconURL}
style={{ width: '20px', height: '20px' }}
alt=""
/>
<span <span
style={{ style={{
...@@ -98,9 +72,7 @@ const menuExtraRender = currentRoutes => { ...@@ -98,9 +72,7 @@ const menuExtraRender = currentRoutes => {
> >
{currentRoutes && currentRoutes.name} {currentRoutes && currentRoutes.name}
</span> </span>
<MenuFoldOutlined <MenuFoldOutlined style={{ color: '#888', marginLeft: '10px' }} />
style={{ color: '#888', marginLeft: '10px' }}
/>
</a> </a>
)} )}
</Spin> </Spin>
...@@ -119,10 +91,7 @@ const StationsItem = (item, action) => { ...@@ -119,10 +91,7 @@ const StationsItem = (item, action) => {
action.changeGroup && action.changeGroup(event, data); action.changeGroup && action.changeGroup(event, data);
}; };
return ( return (
<li <li key={item.groupID} style={{ marginRight: `${item.style.marginRight}px` }}>
key={item.groupID}
style={{ marginRight: `${item.style.marginRight}px` }}
>
<a <a
className={classNames(styles.city_select, styles.showTip)} className={classNames(styles.city_select, styles.showTip)}
title={item.city} title={item.city}
...@@ -131,9 +100,7 @@ const StationsItem = (item, action) => { ...@@ -131,9 +100,7 @@ const StationsItem = (item, action) => {
onClick={event => changeGroup(event, item)} onClick={event => changeGroup(event, item)}
> >
{item.groupName} {item.groupName}
{item.promoteTip && HOT.includes(item.promoteTip) && ( {item.promoteTip && HOT.includes(item.promoteTip) && <div title={`${item.promoteTip}`}>{item.promoteTip}</div>}
<div title={`${item.promoteTip}`}>{item.promoteTip}</div>
)}
</a> </a>
</li> </li>
); );
...@@ -159,11 +126,7 @@ const Stations = props => { ...@@ -159,11 +126,7 @@ const Stations = props => {
return ( return (
<> <>
<div className={styles.focusStations}> <div className={styles.focusStations}>
<ul> <ul>{Array.isArray(data) ? data.map(item => StationsItem(item, props.action)) : null}</ul>
{Array.isArray(data)
? data.map(item => StationsItem(item, props.action))
: null}
</ul>
</div> </div>
<Radio.Group <Radio.Group
options={optionsWith} options={optionsWith}
...@@ -176,36 +139,21 @@ const Stations = props => { ...@@ -176,36 +139,21 @@ const Stations = props => {
/> />
<div style={{ maxWidth: '520px', position: 'relative' }}> <div style={{ maxWidth: '520px', position: 'relative' }}>
{defaultTab === 'site' ? ( {defaultTab === 'site' ? (
<div <div className={classNames(styles.city_pane, styles.station_container)} ref={cityPane}>
className={classNames(styles.city_pane, styles.station_container)}
ref={cityPane}
>
<Anchor <Anchor
affix={false} affix={false}
onClick={handleClick} onClick={handleClick}
targetOffset={targetOffset} targetOffset={targetOffset}
getContainer={() => cityContent.current} getContainer={() => cityContent.current}
> >
<ul className={styles.py}> <ul className={styles.py}>{props.data && props.data.siteCityList && props.data.siteCityList.letters}</ul>
{props.data && <div className={styles.cityContent} style={{ height: '335px' }} ref={cityContent}>
props.data.siteCityList && {props.data && props.data.siteCityList && props.data.siteCityList.content}
props.data.siteCityList.letters}
</ul>
<div
className={styles.cityContent}
style={{ height: '335px' }}
ref={cityContent}
>
{props.data &&
props.data.siteCityList &&
props.data.siteCityList.content}
</div> </div>
</Anchor> </Anchor>
</div> </div>
) : ( ) : (
<div className="city_pane city_container"> <div className="city_pane city_container">{props.data.citySelector}</div>
{props.data.citySelector}
</div>
)} )}
<Spin spinning={props.loading} tip="加载中" /> <Spin spinning={props.loading} tip="加载中" />
</div> </div>
...@@ -213,16 +161,7 @@ const Stations = props => { ...@@ -213,16 +161,7 @@ const Stations = props => {
); );
}; };
const renderTitle = ({ const renderTitle = ({ title, action, data, loading, setLoading, collapsed, fixedHeader, config }) => {
title,
action,
data,
loading,
setLoading,
collapsed,
fixedHeader,
config,
}) => {
// eslint-disable-next-line react-hooks/rules-of-hooks,no-debugger // eslint-disable-next-line react-hooks/rules-of-hooks,no-debugger
// eslint-disable-next-line react-hooks/rules-of-hooks // eslint-disable-next-line react-hooks/rules-of-hooks
const [visible, setVisible] = useState(false); const [visible, setVisible] = useState(false);
......
...@@ -466,7 +466,6 @@ ...@@ -466,7 +466,6 @@
} }
& :global { & :global {
.@{ant-prefix}-dropdown-menu-item { .@{ant-prefix}-dropdown-menu-item {
display: flex; display: flex;
......
import React, { import React, { useEffect, useRef, useState, useContext } from 'react';
useEffect,
useRef, import { Anchor, Popover, Radio, Spin, Tabs, Divider, Dropdown, Menu, Tooltip, ConfigProvider, Skeleton } from 'antd';
useState,
useContext,
} from 'react';
import {
Anchor,
Popover,
Radio,
Spin,
Tabs,
Divider,
Dropdown,
Menu,
Tooltip,
ConfigProvider,
Skeleton,
} from 'antd';
import { PageContainer } from '@ant-design/pro-layout'; import { PageContainer } from '@ant-design/pro-layout';
import Icon, { import Icon, {
// LeftOutlined, // LeftOutlined,
...@@ -25,7 +8,7 @@ import Icon, { ...@@ -25,7 +8,7 @@ import Icon, {
// MenuFoldOutlined, // MenuFoldOutlined,
DownOutlined, DownOutlined,
} from '@ant-design/icons'; } from '@ant-design/icons';
import { store } from '@wisdom-utils/utils'; import { store, helpers } from '@wisdom-utils/utils';
import classNames from 'classnames'; import classNames from 'classnames';
import { ReactSVG } from 'react-svg'; import { ReactSVG } from 'react-svg';
import Cookies from 'js-cookie'; import Cookies from 'js-cookie';
...@@ -33,20 +16,22 @@ import { connect } from 'react-redux'; ...@@ -33,20 +16,22 @@ import { connect } from 'react-redux';
import { useHistory } from '@wisdom-utils/runtime'; import { useHistory } from '@wisdom-utils/runtime';
import KeepAlive from 'react-activation'; import KeepAlive from 'react-activation';
import AMapLoader from '@amap/amap-jsapi-loader'; import AMapLoader from '@amap/amap-jsapi-loader';
import { MinPanel } from '@wisdom-utils/components';
import { findPathByLeafId } from '@wisdom-utils/components/lib/AppLayout/helpers';
import RightContent from '@/components/GlobalHeader/ExtendRightContent'; import RightContent from '@/components/GlobalHeader/ExtendRightContent';
// import Panel from '@/components/SliderPanel/MinPanel';
import { MinPanel as Panel } from '@wisdom-utils/components';
import { actionCreators } from '@/containers/App/store'; import { actionCreators } from '@/containers/App/store';
import { ArcgisMap, AMap, CesiumMap } from '../pages/map'; import { ArcgisMap, AMap, CesiumMap } from '../pages/map';
import { WEB_GIS_TYPE } from '../constants'; import { WEB_GIS_TYPE } from '../constants';
import { findPathByLeafId, getBaseName } from '@/utils/utils'; // import { getBaseName } from '@/utils/utils';
import { renderRoutes, getParams } from '../utils/routes'; // eslint-disable-next-line import/no-duplicates
import SecurityLayout from './SecurityLayout'; import SecurityLayout from './SecurityLayout';
import Site from './Site'; import Site from './Site';
import styles from './UserLayout.less'; import styles from './UserLayout.less';
import layoutStyles from './BasicLayout.less'; import layoutStyles from './BasicLayout.less';
// eslint-disable-next-line import/extensions // eslint-disable-next-line import/extensions
const { TabPane } = Tabs; const { TabPane } = Tabs;
const { renderRoutes, params } = helpers;
const { getParamsV1 } = params;
const { layout: defaultSetting } = require('../../config/config'); const { layout: defaultSetting } = require('../../config/config');
// import Login from '../pages/user/login/login'; // import Login from '../pages/user/login/login';
const antIcon = <LoadingOutlined style={{ fontSize: 12 }} spin />; const antIcon = <LoadingOutlined style={{ fontSize: 12 }} spin />;
...@@ -230,14 +215,12 @@ const renderSite = ({ data, config, loading, setLoading, action }) => { ...@@ -230,14 +215,12 @@ const renderSite = ({ data, config, loading, setLoading, action }) => {
style={{ style={{
borderLeft: borderLeft:
data.stations.length === 0 ? '0px' : '1px solid rgba(256, 256, 256, 0.3)', data.stations.length === 0 ? '0px' : '1px solid rgba(256, 256, 256, 0.3)',
}} }}>
>
<img src={data.weathers && data.weathers.icon} className={layoutStyles.icon} /> <img src={data.weathers && data.weathers.icon} className={layoutStyles.icon} />
<span className={layoutStyles.text}>{data.weathers && data.weathers.text}</span> <span className={layoutStyles.text}>{data.weathers && data.weathers.text}</span>
</span> </span>
) : null} ) : null}
</> </>
) )
} }
...@@ -260,7 +243,7 @@ const BasicLayout = props => { ...@@ -260,7 +243,7 @@ const BasicLayout = props => {
() => new Site(props, setSiteLoading), () => new Site(props, setSiteLoading),
); );
const basename = getBaseName(); // const basename = getBaseName();
const history = useHistory(); const history = useHistory();
// 处理隐藏菜单 // 处理隐藏菜单
...@@ -407,7 +390,7 @@ const BasicLayout = props => { ...@@ -407,7 +390,7 @@ const BasicLayout = props => {
} }
} }
} }
const params = getParams(props.location.pathname); const params = getParamsV1(props.location.pathname);
if(params.hasOwnProperty('mapType') && params.mapType === WEB_GIS_TYPE.AMAP) { if(params.hasOwnProperty('mapType') && params.mapType === WEB_GIS_TYPE.AMAP) {
AMapLoader.reset(); AMapLoader.reset();
setMapMode(WEB_GIS_TYPE.AMAP) setMapMode(WEB_GIS_TYPE.AMAP)
...@@ -417,22 +400,6 @@ const BasicLayout = props => { ...@@ -417,22 +400,6 @@ const BasicLayout = props => {
} }
console.log(props.location, currentRoutes) console.log(props.location, currentRoutes)
}, [props.location]); }, [props.location]);
// window.share.event.on('event:history', params => {
// setTimeout(() => {
// debugger
// const routes = currentRoutes.routes[selectIndex];
// if(routes) {
// const route = routes && routes.routes.find(item => item.path === decodeURI(window.location.pathname.replace('/civbase', '')));
// setTabActiveKey(route.path)
// }
// // window.share.event.removeListener('event:history')
// }, 0)
// })
// window.share && window.share.event.on('event:microError', event => {
// // window.history.pushState({message: '应用服务请求异常,请检查应用配置'}, null, '/civbase/404')
// history.push('/404');
// });
useEffect(() => { useEffect(() => {
window.share.event.on('updateSite', res => setCityData(res)); window.share.event.on('updateSite', res => setCityData(res));
...@@ -645,7 +612,7 @@ const BasicLayout = props => { ...@@ -645,7 +612,7 @@ const BasicLayout = props => {
</div> </div>
</aside> </aside>
<div className={layoutStyles.layout} style={{ width: 'calc(100% - 80px)' }}> <div className={layoutStyles.layout} style={{ width: 'calc(100% - 80px)' }}>
<Panel <MinPanel
visible={toggleSystem} visible={toggleSystem}
keyboard keyboard
onClose={() => setToggleSystem(false)} onClose={() => setToggleSystem(false)}
...@@ -671,18 +638,17 @@ const BasicLayout = props => { ...@@ -671,18 +638,17 @@ const BasicLayout = props => {
<img src={`${logo}`} alt="logo" /> <img src={`${logo}`} alt="logo" />
</a> </a>
<div className={layoutStyles.title}>{props.global.title}</div> <div className={layoutStyles.title}>{props.global.title}</div>
{ {
renderSite({ renderSite({
data: cityData, data: cityData,
config: props.global, config: props.global,
loading: siteLoading, loading: siteLoading,
setLoading: setSiteLoading, setLoading: setSiteLoading,
action: siteAction, action: siteAction,
}) })
} }
<RightContent /> <RightContent />
</div> </div>
</div> </div>
</div> </div>
<div className={layoutStyles['menu-item-children']}> <div className={layoutStyles['menu-item-children']}>
...@@ -718,16 +684,11 @@ const BasicLayout = props => { ...@@ -718,16 +684,11 @@ const BasicLayout = props => {
</div> </div>
<PageContainer style={{paddingTop: '0px', height: '100%'}}> <PageContainer style={{paddingTop: '0px', height: '100%'}}>
{ {
renderRoutes(props.route.routes, props) renderRoutes('panda-console-base', props.route.routes, props)
} }
{ {
window.location.pathname.startsWith('/civbase/civ_3d') ? <KeepAlive><CesiumMap /></KeepAlive> : window.location.pathname.startsWith('/civbase/civ_webgis') ? ((mapMode === 'AMap' ? <AMap/>: <ArcgisMap options={{ type: 'ArcgisMap' }}/>)) : null window.location.pathname.startsWith('/civbase/civ_3d') ? <KeepAlive><CesiumMap /></KeepAlive> : window.location.pathname.startsWith('/civbase/civ_webgis') ? ((mapMode === 'AMap' ? <AMap/>: <ArcgisMap options={{ type: 'ArcgisMap' }}/>)) : null
} }
<div id="micro-container" className="subapp-container"> <div id="micro-container" className="subapp-container">
{props.children} {props.children}
...@@ -742,7 +703,7 @@ const BasicLayout = props => { ...@@ -742,7 +703,7 @@ const BasicLayout = props => {
): ( ): (
<PageContainer style={{paddingTop: '0px', height: '100%'}}> <PageContainer style={{paddingTop: '0px', height: '100%'}}>
{ {
renderRoutes(props.route.routes, props) renderRoutes('panda-console-base', props.route.routes, props)
} }
{ {
......
...@@ -3,10 +3,10 @@ import React from 'react'; ...@@ -3,10 +3,10 @@ import React from 'react';
import { Helmet, HelmetProvider } from 'react-helmet-async'; import { Helmet, HelmetProvider } from 'react-helmet-async';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { getMenuData, getPageTitle } from '@ant-design/pro-layout'; import { getMenuData, getPageTitle } from '@ant-design/pro-layout';
import { renderRoutes } from '../utils/routes'; // import { renderRoutes } from '../utils/routes';
import { helpers } from '@wisdom-utils/utils';
import styles from './UserLayout.less'; import styles from './UserLayout.less';
const { renderRoutes } = helpers;
const UserLayout = props => { const UserLayout = props => {
const { const {
route = { route = {
...@@ -35,7 +35,7 @@ const UserLayout = props => { ...@@ -35,7 +35,7 @@ const UserLayout = props => {
<div className={styles.container}> <div className={styles.container}>
<div className={styles.content}> <div className={styles.content}>
{renderRoutes(route.routes, props)} {renderRoutes('panda-console-base', route.routes, props)}
{props.children} {props.children}
</div> </div>
{/* <DefaultFooter links={[]} copyright="Copyright © 熊猫智慧水务 2020 All Rights Reserved 沪ICP备11036640-1"/> */} {/* <DefaultFooter links={[]} copyright="Copyright © 熊猫智慧水务 2020 All Rights Reserved 沪ICP备11036640-1"/> */}
...@@ -43,7 +43,7 @@ const UserLayout = props => { ...@@ -43,7 +43,7 @@ const UserLayout = props => {
</HelmetProvider> </HelmetProvider>
); );
}; };
// const mapStateToProps = state => ({ const mapStateToProps = state => ({
// global: state.getIn(['global', 'globalConfig']), global: state.getIn(['global', 'globalConfig']),
// }); });
export default UserLayout; export default connect(mapStateToProps)(UserLayout);
This diff is collapsed.
...@@ -51,25 +51,19 @@ export const dyRoutes = (routes, layout) => { ...@@ -51,25 +51,19 @@ export const dyRoutes = (routes, layout) => {
}, },
{ {
path: '/iframe', path: '/iframe',
component: Iframe component: Iframe,
}, },
{ {
path: '/404', path: '/404',
component: dynamic({ component: dynamic({
loader: () => loader: () => import(/* webpackChunkName: 'p__404' */ '../pages/exception/404'),
import(
/* webpackChunkName: 'p__404' */ '../pages/exception/404'
),
loading: LoadingComponent, loading: LoadingComponent,
}), }),
}, },
{ {
path: '/500', path: '/500',
component: dynamic({ component: dynamic({
loader: () => loader: () => import(/* webpackChunkName: 'p__500' */ '../pages/exception/500'),
import(
/* webpackChunkName: 'p__500' */ '../pages/exception/500'
),
loading: LoadingComponent, loading: LoadingComponent,
}), }),
}, },
...@@ -90,24 +84,17 @@ export const dyRoutes = (routes, layout) => { ...@@ -90,24 +84,17 @@ export const dyRoutes = (routes, layout) => {
{ {
path: '/404', path: '/404',
component: dynamic({ component: dynamic({
loader: () => loader: () => import(/* webpackChunkName: 'p__404' */ '../pages/exception/404'),
import(
/* webpackChunkName: 'p__404' */ '../pages/exception/404'
),
loading: LoadingComponent, loading: LoadingComponent,
}), }),
}, },
{ {
path: '/500', path: '/500',
component: dynamic({ component: dynamic({
loader: () => loader: () => import(/* webpackChunkName: 'p__500' */ '../pages/exception/500'),
import(
/* webpackChunkName: 'p__500' */ '../pages/exception/500'
),
loading: LoadingComponent, loading: LoadingComponent,
}), }),
}, },
], ],
}; };
}; };
...@@ -17,9 +17,7 @@ export default ({ key, reducer }) => WrappedComponent => { ...@@ -17,9 +17,7 @@ export default ({ key, reducer }) => WrappedComponent => {
static contextType = ReactReduxContext; static contextType = ReactReduxContext;
static displayName = `withReducer(${WrappedComponent.displayName || static displayName = `withReducer(${WrappedComponent.displayName || WrappedComponent.name || 'Component'})`;
WrappedComponent.name ||
'Component'})`;
constructor(props, context) { constructor(props, context) {
super(props, context); super(props, context);
......
...@@ -2,14 +2,14 @@ import * as React from 'react'; ...@@ -2,14 +2,14 @@ import * as React from 'react';
import * as ReactDOM from 'react-dom'; import * as ReactDOM from 'react-dom';
function registerGlobal(root, deps) { function registerGlobal(root, deps) {
Object.keys(deps).forEach((key) => { Object.keys(deps).forEach(key => {
root[key] = deps[key]; root[key] = deps[key];
}); });
}; }
registerGlobal(window, { registerGlobal(window, {
// 在这里注册暴露给子工程的全局变量 // 在这里注册暴露给子工程的全局变量
React, React,
ReactDOM, ReactDOM,
}); });
export default registerGlobal; export default registerGlobal;
\ No newline at end of file
import React from 'react';
import { guid, params, urlHelpers } from '@wisdom-utils/utils/lib/helpers';
import LoadingComponent from '@ant-design/pro-layout/es/PageLoading';
import { dynamic } from '@wisdom-utils/runtime';
import { matchPath, Route, Switch} from 'react-router';
const { getParamsV1 } = params;
const { isURL, isAbsoluteURL, getURL, transformURL } = urlHelpers
export const getParams = getParamsV1;
const DEFAULT_APPLICATION = 'civweb4';
const level = 0;
const generRotes = (widgets, parent, level = 0) => {
const ret = [];
if(!widgets || widgets.length === 0){
return
};
(widgets).forEach((item, index) => {
if (item.hasOwnProperty('widgets') && item.widgets !== null && Array.isArray(item.widgets) && item.widgets.length > 0) {
const _level_ = level + 1;
const path = `/civweb/${guid('web_console')}`;
const subKey = guid('panda');
const alias = DEFAULT_APPLICATION;
const convertURL = item.icon ? transformURL(item.icon.replace(/\s*/g, '')): '';
const icon = (item && item.icon && item.icon !== null &&
isAbsoluteURL(convertURL) ? convertURL: /(\\|\/)/.test(convertURL) ?
window.globalConfig.transformDevAssetsBaseURL(transformURL(item.icon.replace(/\s*/g, ''))): item.icon
) || '';
ret.push({
name: item.label,
level: _level_,
path,
component: 'BasicLayout',
parent,
alias: alias,
hideInMenu: item.hideInMenu || false,
routes: generRotes(
item.widgets,
Object.assign({}, item, { path, key: subKey }),
_level_,
item.label
),
extData: {
...item,
icon: icon,
},
});
} else {
const baseURL = item.product || DEFAULT_APPLICATION;
if(item.hasOwnProperty('url') && item.url === '') return;
let url = item.hasOwnProperty('url') && item.url !== undefined && item.url !== '' ? `/${baseURL}/${item.url.replace(/\s*/g, '')}`
: !item.hasOwnProperty('url')
? guid('web_console')
: '';
if (url.includes('url=')) {
url = url.split('url=')[1];
url = getURL(url);
}
if(isURL(item.url)) {
url = item.url
}
url = transformURL(url);
//url = url.replace(/[(\\|)|(&)]widget=[0-9]*/, '')
const convertURL = item.icon && transformURL(item.icon.replace(/\s*/g, ''));
const icon = (item && item.icon && item.icon !== null &&
isAbsoluteURL(convertURL) ? convertURL: /(\\|\/)/.test(convertURL) ?
window.globalConfig.transformDevAssetsBaseURL(transformURL(item.icon.replace(/\s*/g, ''))): item.icon
) || '';
const l = level ? level + 1 : -1;
let common = {
name: item.label,
level: l,
component: 'BasicLayout',
path: baseURL !== '' ? transformURL(url) : '',
href: url,
target: isURL(url) ? '_blank' : '',
key: guid('panda'),
hideInMenu: item.label === '系统菜单组' ? true: item.hideInMenu,
//l > 3 ? true: item.hideInMenu || false,
alias: item.product || DEFAULT_APPLICATION,
extData: {
...item,
icon,
},
parent,
params: getParams(url),
};
if(/iframe/.test(url)) {
url = url.replace(/\/report/, '');
common = {
name: item.label,
level: l,
component: dynamic({ loader: () =>
import ( /* webpackChunkName: "p__[request]" */ `@/pages/${component}.js`), loading: LoadingComponent }),
path: baseURL !== '' ? transformURL(url) : '',
href: url,
target: isURL(url) ? '_blank' : '',
key: guid('panda'),
hideInMenu: item.label === '系统菜单组' ? true: item.hideInMenu,
//l > 3 ? true: item.hideInMenu || false,
alias: item.product || DEFAULT_APPLICATION,
extData: {
...item,
icon,
},
params: getParams(url),
parent,
}
}
ret.push(common);
}
});
return ret;
};
export const transformWidgets = (widgets) => {
if(!widgets || widgets.length === 0) {
return []
}
return widgets.map(item => {
const widgets = item.widgets;
const homepage = window.globalConfig.homepage;
const homePageConvertArray = homepage ? homepage.split("/"): [];
const findIndex = widgets && widgets.findIndex(item => item.label === '系统菜单组');
if(findIndex === -1 && homePageConvertArray[0] !== 'civweb4') {
const index = widgets.findIndex(item => item.label === '首页');
if(index === -1) {
widgets.push({
label: "首页",
icon: '',
product: homePageConvertArray[0],
shortName: "首页",
hideInMenu: true,
url: homePageConvertArray.slice(1, homePageConvertArray.length).join("/")
});
}
item.widgets = Array.from(new Set(widgets));
}
return item;
});
}
export function simpleNormalizeChildren(children) {
for (let i = 0; i < children.length; i++) {
if (Array.isArray(children[i])) {
return Array.prototype.concat.apply([], children);
}
}
return children;
}
export const generFlatRoutes = (widgets, parent, subSystem, modulePkg) => {
const treeKeys = [];
const flatMenu = [];
if(!widgets || Array.isArray(widgets) && widgets.length === 0) {
return [];
}
(widgets || []).forEach(item => {
if (item.hasOwnProperty('routes')) {
const route = generFlatRoutes(item.routes, item, item.name, modulePkg);
flatMenu.push(simpleNormalizeChildren(route));
} else {
flatMenu.push({
...item,
origin: item,
moduleName: modulePkg[item.alias],
treeKeys,
subSystem,
parent,
});
}
});
return simpleNormalizeChildren(flatMenu);
};
export function RouteWithSubRoutes(route) {
return (
<Route path={route.path} render={props => (<route.component {...props} route={route} routes={route.routes} params={route.params}/>)}></Route>
)
}
function matchRoutes(routes, pathname, branch) {
if (branch === void 0) {
branch = [];
}
routes.some(function (route) {
var match = route.path ? matchPath(pathname, route) : branch.length ? branch[branch.length - 1].match // use parent match
: Router.computeRootMatch(pathname); // use default "root" match
if (match) {
branch.push({
route: route,
match: match
});
if (route.routes) {
matchRoutes(route.routes, pathname, branch);
}
}
return match;
});
return branch;
}
function renderRoutes(routes, extraProps, switchProps) {
if (extraProps === void 0) {
extraProps = {};
}
if (switchProps === void 0) {
switchProps = {};
}
return routes ? React.createElement(Switch, switchProps, routes.map(function (route, i) {
return React.createElement(Route, {
key: route.key || i,
path: route.path,
exact: route.exact,
strict: route.strict,
render: function render(props) {
return route.render ? route.render(Object.assign({}, props, {}, extraProps, {
routes: route.routes,
params: route.params,
route: route,
rootPrefix: 'panda-console-base'
})) : React.createElement(route.component, Object.assign({}, props, extraProps, {
route: route,
routes: route.routes,
params: route.params,
rootPrefix: 'panda-console-base'
}));
}
});
})) : null;
}
export {
renderRoutes,
matchPath
}
export default generRotes;
...@@ -2,13 +2,9 @@ import Cookies from 'js-cookie'; ...@@ -2,13 +2,9 @@ import Cookies from 'js-cookie';
import pathRegexp from 'path-to-regexp'; import pathRegexp from 'path-to-regexp';
import { parse } from 'querystring'; import { parse } from 'querystring';
import pkg from '../../package.json'; import pkg from '../../package.json';
const { toString } = Object.prototype;
/* eslint no-useless-escape:0 import/prefer-default-export:0 */ /* eslint no-useless-escape:0 import/prefer-default-export:0 */
const reg = /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/; const reg = /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/;
export const isUrl = path => reg.test(path);
export const getPageQuery = () => parse(window.location.href.split('?')[1]); export const getPageQuery = () => parse(window.location.href.split('?')[1]);
export const getAuthorityFromRouter = (router, pathname) => { export const getAuthorityFromRouter = (router, pathname) => {
...@@ -51,86 +47,7 @@ export function isPromise(obj) { ...@@ -51,86 +47,7 @@ export function isPromise(obj) {
export function getBaseName() { export function getBaseName() {
return pkg.name.toLocaleLowerCase(); return pkg.name.toLocaleLowerCase();
} }
let cache = {};
export function findPathByLeafId(leafId, nodes, path, key, clear) {
if (path === undefined) {
path = {};
}
let tmpPath = path;
if(clear) {
cache = {};
}
if (cache[leafId]) {
return cache[leafId];
}
// eslint-disable-next-line no-plusplus
for (let i = 0; i < nodes.length; i++) {
if (nodes[i] && nodes[i][key] && leafId === nodes[i][key]) {
tmpPath = nodes[i];
cache[leafId] = tmpPath;
return tmpPath;
}
if (nodes[i] && nodes[i].routes) {
const findResult = findPathByLeafId(
leafId,
nodes[i].routes,
tmpPath,
key,
);
if (findResult) {
cache[leafId] = findResult;
return findResult;
}
}
}
}
export function findPathByWidget(leafId, nodes, path, key) {
if (path === undefined) {
path = {};
}
let tmpPath = path;
// eslint-disable-next-line no-plusplus
for (let i = 0; i < nodes.length; i++) {
if (nodes[i] && nodes[i][key] && nodes[i][key].indexOf(leafId) > -1) {
tmpPath = nodes[i];
return tmpPath;
}
if (nodes[i] && nodes[i].widgets) {
const findResult = findPathByWidget(
leafId,
nodes[i].widgets,
tmpPath,
key,
// eslint-disable-next-line no-restricted-globals
location,
);
if (findResult) {
return findResult;
}
}
}
return tmpPath;
}
export function isJSON(str) {
if (typeof str === 'string') {
try {
const obj = JSON.parse(str);
if (typeof obj === 'object' && obj) {
return true;
}
return false;
} catch (e) {
return false;
}
}
}
export function isString(str) {
return toString.call(str) === '[object String]';
}
export const getKeyName = path => { export const getKeyName = path => {
const truePath = path.split('?')[0]; const truePath = path.split('?')[0];
......
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