/**
 * URL参数转换为对象
 */
Location.prototype.searchObj = function (url) {
    var obj = {};
    var arr = (url || this.search).match(/[?&][^?&]+=[^?&]+/g);
    if (arr) {
        arr
            .forEach(function (item) {
                var tempArr = item
                    .substring(1)
                    .split('=');
                obj[decodeURIComponent(tempArr[0])] = decodeURIComponent(tempArr[1]);
                length++;
            });
    }
    return obj;
}
//全局随机数重写
const random = Math.random;
Math.random = (a = 0, b = 1, c = 6) => {
	return (random() * (b - a) + a).toFixed(c) - 0;
};
import "@babel/polyfill";
import './css/common.css';
import React from 'react';
import ReactDom from "react-dom";
import {HashRouter,Switch,Route,Redirect} from "react-router-dom";
/**
 * 数据持久化
 */
import {Provider} from 'react-redux';
import store from './store/index';
import {setSuperiorHref} from './store/action';

/**
 * 编辑模式下 全局监听父窗口传入的消息
 */
window.addEventListener('message', function (e) {
    const {data} = e;
    data.type == 'href' && data.href && store.dispatch(setSuperiorHref(data));
});
import Home from "./Layout/Home/index.jsx";
import Detail from "./Layout/Detail/index.jsx";
ReactDom.render(
    <Provider store={store}>
    <HashRouter>
        <Switch>
            <Route path="/home/:mapId?/:pId?/:page?" component={Home}></Route>
            <Route path="/detail/:mapId?/:pId?/:page?" component={Detail}></Route>
        </Switch>
    </HashRouter>
</Provider>, document.querySelector("#root"));


