Authored by huangyi

优化结构

1 -import httpService from '../../../../common/httpService' 1 +import httpService from '../../../common/httpService'
2 import config from '../config' 2 import config from '../config'
3 3
4 let collectApi = (param) => httpService.postJson(config.domain + '/api/guochao/addFav', param); 4 let collectApi = (param) => httpService.postJson(config.domain + '/api/guochao/addFav', param);
  1 +import Loadable from "react-loadable";
  2 +import React from 'react';
  3 +
  4 +const guochaoHome = Loadable({
  5 + loader: () => import(/* webpackChunkName: "guochaoHome" */'./view/guochaoHome'),
  6 + loading(){
  7 + return <div></div>
  8 + },
  9 +})
  10 +
  11 +const top40 = Loadable({
  12 + loader: () => import(/* webpackChunkName: "top40" */'./view/top40'),
  13 + loading(){
  14 + return <div></div>
  15 + },
  16 +})
  17 +module.exports = {
  18 + guochaoHome,
  19 + top40
  20 +}
1 -import React from 'react';  
2 -import {render} from 'react-dom';  
3 -import config from './config';  
4 -  
5 -import {BrowserRouter, Route,Switch,HashRouter,hashHistory,browserHistory} from 'react-router-dom';  
6 -  
7 -// import guochaoHome from './view/guochaoHome';  
8 -// import top40 from './view/top40';  
9 -  
10 -import Loadable from 'react-loadable';  
11 -  
12 -const guochaoHome = Loadable({  
13 - loader: () => import(/* webpackChunkName: "guochaoHome" */'./view/guochaoHome'),  
14 - loading(){  
15 - return <div></div>  
16 - },  
17 -});  
18 -const top40 = Loadable({  
19 - loader: () => import(/* webpackChunkName: "top40" */'./view/top40'),  
20 - loading(){  
21 - return <div></div>  
22 - },  
23 -});  
24 -  
25 -const SliderComponent = () => (  
26 - <Switch>  
27 - <Route exact path={config.routerPath+'/guochao.html'} component={guochaoHome} />  
28 - <Route path={config.routerPath+'/top40.html'} component={top40} />  
29 - </Switch>  
30 -);  
31 -  
32 -render(  
33 - <BrowserRouter history={browserHistory}>  
34 - <SliderComponent/>  
35 - </BrowserRouter>,  
36 - document.querySelector("#root")  
37 -);  
  1 +module.exports = {
  2 + guochaoHome:'中西碰撞 潮流无界',
  3 + top40:'中西碰撞 潮流无界'
  4 +}
1 import React, {PureComponent} from 'react'; 1 import React, {PureComponent} from 'react';
2 import './index.scss' 2 import './index.scss'
3 import {collectApi, checkFavApi} from '../../api/guochaoApi' 3 import {collectApi, checkFavApi} from '../../api/guochaoApi'
4 -import {getQueryObj, linkToMiniApp, invokeMethod, parseUrl} from '../../../../../common/utils';  
5 -import wxshare from '../../../../../common/wxshare' 4 +import {getQueryObj, linkToMiniApp, invokeMethod, parseUrl} from '../../../../common/utils';
  5 +import wxshare from '../../../../common/wxshare'
6 import wx from 'weixin-js-sdk'; 6 import wx from 'weixin-js-sdk';
7 import config from '../../config'; 7 import config from '../../config';
8 import cookie from 'react-cookies'; 8 import cookie from 'react-cookies';
1 import React, {PureComponent} from 'react'; 1 import React, {PureComponent} from 'react';
2 import './index.scss' 2 import './index.scss'
3 import {guochaoListApi} from '../../api/guochaoApi' 3 import {guochaoListApi} from '../../api/guochaoApi'
4 -import {getEnv, linkToMiniApp, invokeMethod} from "../../../../../common/utils";  
5 -import { Link } from 'react-router-dom' 4 +import {linkToMiniApp, invokeMethod} from "../../../../common/utils";
6 import wx from "weixin-js-sdk"; 5 import wx from "weixin-js-sdk";
7 -import config from "../../config";  
8 -import wxshare from "../../../../../common/wxshare"; 6 +import wxshare from "../../../../common/wxshare";
9 7
10 8
11 export default class top40 extends PureComponent { 9 export default class top40 extends PureComponent {
1 -import webpack, {DefinePlugin} from 'webpack';  
2 -import merge from 'webpack-merge';  
3 -import baseConfig from '../../webpack.public.config';  
4 -import HtmlWebpackPlugin from 'html-webpack-plugin';  
5 -import config from './src/config';  
6 -  
7 -export default merge(baseConfig, {  
8 - //项目入口js文件  
9 - entry: ['./app/guoChao/src/index.js'],  
10 - devServer:{  
11 - publicPath: config.routerPath  
12 - },  
13 - plugins: [  
14 - // new HtmlWebpackPlugin({  
15 - // filename: 'index.html',  
16 - // template: './app/guoChao/index.html',  
17 - // }),  
18 - new HtmlWebpackPlugin({  
19 - filename: 'top40.html',  
20 - template: './app/guoChao/index.ejs',  
21 - title:"中西碰撞 潮流无界",  
22 - inject: true,  
23 - minify: {  
24 - removeComments: true,  
25 - collapseWhitespace: true,  
26 - removeAttributeQuotes: true  
27 - }  
28 - }),  
29 - new HtmlWebpackPlugin({  
30 - filename: 'guochao.html',  
31 - template: './app/guoChao/index.ejs',  
32 - title:"中西碰撞 潮流无界",  
33 - inject: true,  
34 - minify: {  
35 - removeComments: true,  
36 - collapseWhitespace: true,  
37 - removeAttributeQuotes: true  
38 - }  
39 - }),  
40 - ]  
41 -});  
  1 +import React from 'react';
  2 +import {render} from 'react-dom';
  3 +import config from '../config';
  4 +
  5 +import {BrowserRouter, Route, Switch, HashRouter, hashHistory, browserHistory} from 'react-router-dom';
  6 +
  7 +const router = require('./' + config.currentApp +'/router');
  8 +
  9 +const routers = () => {
  10 + let arr = [];
  11 + Object.keys(router).forEach((key,index)=> {
  12 + if(index === 0){
  13 + arr.push(<Route key={index} exact path={config.routerPath[config.currentApp] + '/'+key+'.html'} component={router[key]}/>)
  14 + }else{
  15 + arr.push(<Route key={index} path={config.routerPath[config.currentApp] + '/'+key+'.html'} component={ router[key]}/>)
  16 + }
  17 + })
  18 + return arr;
  19 +}
  20 +
  21 +const SliderComponent = () => (
  22 + <Switch>
  23 + {routers()}
  24 + </Switch>
  25 +);
  26 +render(
  27 + <BrowserRouter history={browserHistory}>
  28 + <Switch>
  29 + <SliderComponent/>
  30 + </Switch>
  31 + </BrowserRouter>,
  32 + document.querySelector("#root")
  33 +);