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

feat: 优化子应用注册

parent 3edb22c5
Pipeline #48651 passed with stages
in 5 minutes 23 seconds
/* eslint-disable */
// const proxyURL = process.env.NODE_ENV !== 'production' ? 'http://192.168.10.150:8777' : window.location.origin;
// const proxyURL = 'https://work.panda-water.cn';
const proxyURL = 'http://192.168.12.3:8082';
// const proxyURL = 'https://panda-water.cn';
// const proxyURL = 'http://192.168.12.3:8082';
const proxyURL = 'https://panda-water.cn';
module.exports = {
assetsRoot: process.env.NODE_ENV !== 'production' ? proxyURL : './',
......
......@@ -8,9 +8,11 @@ import 'file-loader?name=.htaccess!./.htaccess'; // eslint-disable-line import/e
import '@wisdom-utils/utils/lib/helpers/format';
import 'sanitize.css/sanitize.css';
import { Storeage } from '@wisdom-utils/utils/lib/helpers';
import { initGlobalConfig } from './initConfig';
import { initGlobalConfig } from './initConfig'
import './utils/event';
import { render } from './render';
// import store from './stores';
// eslint-disable-next-line no-restricted-globals
const namespace = `__PANDA_STORE__${location.hostname}`;
......@@ -19,11 +21,6 @@ window.createStoreage = new Storeage(namespace);
const initLocale = () => {
localStorage.setItem('umi_locale', 'zh-CN');
};
// const PRODUCT_NAME = ['civ_water', 'civ_monitor'];
initGlobalConfig();
render({ appContent: '', loading: true });
initLocale();
// event.on('event:logout', () => {
// store.dispatch(actionCreators.logout());
// });
......@@ -37,6 +37,7 @@ class NoticeIconView extends Component {
window.share && window.share.event && window.share.event.removeAllListeners('reloadNotice');
} catch (error) {
}
debugger
this.notifier = new Notifier(
this.props.global.userInfo,
this.renderVideo,
......
......@@ -26,7 +26,7 @@ function App(props) {
<Switch>
{renderRoutes(
'panda-console-base',
dyRoutes(props.menu || [], props.global.layout, props.global.theme).routes,
dyRoutes(props.menu || [], props.global && props.global.layout, props.global && props.global.theme || 'dark').routes,
)}
</Switch>
</Router>
......
import Cookies from 'js-cookie';
import { store } from '@wisdom-utils/utils';
import {
CLEAR_RCENT_KEYWORD,
COMPLEX_CONFIG,
......@@ -25,7 +26,6 @@ import {
AMAP_VIEW,
PD_VIEW,
} from './constants';
import { store } from '@wisdom-utils/utils';
export function getConfig(data) {
return {
type: GET_CONFIG,
......@@ -164,7 +164,6 @@ export function updateMicroMounted(data) {
};
}
export function updageAMapView(data) {
return {
type: AMAP_VIEW,
......@@ -223,16 +222,23 @@ export function logout(data) {
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`;
});
const products =
window.globalConfig &&
(window.globalConfig.products || []).map(item => {
if (item.PackageName === 'civweb4') {
return 'web4_console';
}
return `${item.PackageName}-main`;
});
if (products) {
Object.keys(products).forEach(item => {
window[products[item]] &&
window[products[item]] &&
window[products[item]].unmount &&
window[products[item]].unmount({ store });
});
}
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: {
......
......@@ -45,7 +45,7 @@ export const initGlobalConfig = () => {
// }
// } else {
// // eslint-disable-next-line react-hooks/rules-of-hooks
// }
let client = params.getParams('client') || Cookies.get('client');
client = client && client !== 'undefined' ? client : 'city';
......@@ -80,8 +80,20 @@ export const initGlobalConfig = () => {
// Cookies.set('client', params.getParams('client'))
if (data.loginTemplate === '新春 - 智联.html') {
updateTheme('#ff9600');
// if (data.loginTemplate === '新春 - 智联.html') {
// updateTheme('#ff9600');
// }
const products = (data.products || []).map(item => {
if (item.PackageName === 'civweb4') {
return 'web4_console'
}
return `${item.PackageName}-main`;
});
if(products && products.length > 0) {
Object.keys(products).forEach(item => {
window[products[item]] && window[products[item]] && window[products[item]].unmount && window[products[item]].unmount({ store: store });
});
initMicroApps();
}
// eslint-disable-next-line no-new
if (getToken()) {
......
......@@ -43,11 +43,12 @@ class SecurityLayout extends React.Component {
}
render() {
const { isReady } = this.state;
const { children, global, loading } = this.props;
const tk = Cookies.get('token') || global.token;
const isLogin = tk !== null && tk !== 'undefined' && tk !== (void 0);
if (!isLogin && window.location.pathname !== '/civbase/user/login') {
if (!isLogin && window.location.pathname !== '/civbase/user/login' || (global.hasOwnProperty('size') && global.size === 0)) {
const { query = {}, search, pathname } = history.location;
const { redirect } = query;
// const queryString = stringify({
......@@ -63,7 +64,7 @@ class SecurityLayout extends React.Component {
to={`/user/login?client=${client}${generateType}`}
/>
);
}
};
if ((!isLogin && loading) || !isReady) {
return <PageLoading />;
......
......@@ -183,7 +183,7 @@ export const initMicroApps = () => {
Logger.info('[MainApp] first app mounted');
});
// eslint-disable-next-line no-use-before-define
defaultApp();
// defaultApp();
addGlobalUncaughtErrorHandler(event => {
console.log(event);
......
......@@ -13,7 +13,7 @@ import { actionCreators } from '../../containers/App/store';
import SecurityLayout from '../../layouts/SecurityLayout';
import LoginAction from '../user/login/login';
import styles from './index.less';
import { initMicroApps } from '@/micro';
import { defaultApp } from '@/micro';
import usingIcon from '@/assets/bootPage/using-icon.png';
import { appService } from '@/api';
......@@ -102,7 +102,7 @@ const BootPage = props => {
const handleToggleIndustry = event => {
setLoadding(false);
props.history.push(`/?client=${props.global.client}`);
initMicroApps();
defaultApp();
window.share.event.emit('triggerMicro', props.global);
props.updateCurrentIndex(0);
};
......
......@@ -22,10 +22,10 @@ const LoginTemplate = {
/* eslint-disable */
export default (props) => {
// const redirect = getParams('redirect');
// useEffect(() => {
// if(getParams('loginName') && getParams('password')) return
// initGlobalConfig();
// }, [redirect]);
useEffect(() => {
// if(getParams('loginName') && getParams('password')) return
initGlobalConfig();
}, []);
const template = window.globalConfig && window.globalConfig.loginTemplate;
const RenderComponent = LoginTemplate[template] ? LoginTemplate[template]: LoginTemplate['default'];
return <RenderComponent {...props}/>
......
......@@ -15,7 +15,7 @@ import styles from '../style.less';
import useRenderQcode from '../js/useRenderQcode';
import Account from '../js/useAccount';
import IotComponent from '../js/useIOTComponent';
import { initMicroApps } from '../../../../micro';
import { defaultApp } from '../../../../micro';
const Login = forwardRef((props, _ref) => {
const videoRef = useRef();
const loginRef = useRef();
......@@ -34,7 +34,7 @@ const Login = forwardRef((props, _ref) => {
const history = useHistory();
const [action, setAction] = useState(
() =>
new LoginAction(Object.assign({}, props, { history }), setVisible, true),
new LoginAction(Object.assign({}, props, { history }), setVisible, false),
);
// useEffect(() => {
......@@ -68,7 +68,9 @@ const Login = forwardRef((props, _ref) => {
props.updateCurrentIndex && props.updateCurrentIndex(0);
props.history.push(`/?client=${props.global.client}`);
// window.share.event.emit('triggerMicro', props.global);
initMicroApps();
// initMicroApps();
debugger
defaultApp();
});
action &&
action.events.on('loginError', event => {
......@@ -203,7 +205,7 @@ const Login = forwardRef((props, _ref) => {
>
<span className={styles.title}>{props.global.title}</span>
<span className={styles.subtitle}>
{window.globalConfig.subtitle}
{window.globalConfig && window.globalConfig.subtitle}
</span>
</div>
</div>
......
......@@ -24,7 +24,7 @@ import UnSelected from '@/assets/oa/login/unselected.jpg'
import LoginAction from '../login';
import { actionCreators } from '@/containers/App/store';
import Cookies from 'js-cookie';
import { initMicroApps } from '../../../../micro';
import { defaultApp } from '../../../../micro';
const Logger = logger('login');
// 、登录页
class InfoLogin extends React.Component{
......@@ -100,7 +100,7 @@ changeQrCode=(item)=>{
let action=new LoginAction(this.props,false,true)
action.loginHandler(loginName,passWord,null,isRember,false)
this.loginEvent(action)
}
// 登录成功事件
loginEvent(action){
......@@ -110,13 +110,13 @@ changeQrCode=(item)=>{
this.props.updateCurrentIndex && this.props.updateCurrentIndex(0);
this.props.history.push(`/?client=${this.props.global.client}`);
// window.share.event.emit('triggerMicro', this.props.global);
initMicroApps();
defaultApp();
});
action && action.events.on('loginError', event => {
});
action && action.events.on('loginVisible', status => {
});
}
render(){
......@@ -184,4 +184,4 @@ export default connect(
mapStateToProps,
mapDispatchToProps,
)(withRouter(InfoLogin));
......@@ -20,7 +20,7 @@ import LoginAction from '../login';
import { actionCreators } from '@/containers/App/store';
import Cookies from 'js-cookie';
import QRCode from 'qrcode.react';
import { initMicroApps } from '../../../../micro';
import { defaultApp } from '../../../../micro';
const Logger = logger('login');
// 、登录页
class InfoLogin extends React.Component {
......@@ -141,7 +141,7 @@ class InfoLogin extends React.Component {
this.props.updateCurrentIndex && this.props.updateCurrentIndex(0);
this.props.history.push(`/?client=${this.props.global.client}`);
// window.share.event.emit('triggerMicro', this.props.global);
initMicroApps();
defaultApp();
});
action && action.events.on('loginError', event => {
......
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