feat:ssr改造
This commit is contained in:
parent
648669f859
commit
b87232dcb6
12
.umirc.ts
12
.umirc.ts
|
@ -8,17 +8,11 @@ export default defineConfig({
|
|||
type: "none",
|
||||
},
|
||||
fastRefresh: {},
|
||||
ssr: {
|
||||
// 更多配置
|
||||
// forceInitial: false,
|
||||
removeWindowInitialProps: true,
|
||||
devServerRender: false, // 默认为true
|
||||
mode: "string",
|
||||
staticMarkup: false,
|
||||
},
|
||||
ssr: {},
|
||||
exportStatic: {},
|
||||
proxy: {
|
||||
"/api/": {
|
||||
target: "http://127.0.0.1:8081", //转发接口地址
|
||||
target: "http://127.0.0.1:8000", //转发接口地址
|
||||
changeOrigin: true,
|
||||
pathRewrite: { "^": "" },
|
||||
},
|
||||
|
|
13
package.json
13
package.json
|
@ -1,8 +1,8 @@
|
|||
{
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"start": "SET NODE_OPTIONS=--openssl-legacy-provider&&umi dev",
|
||||
"build": "SET NODE_OPTIONS=--openssl-legacy-provider&&umi build",
|
||||
"start": "SET NODE_OPTIONS=--openssl-legacy-provider && umi dev",
|
||||
"build": "SET NODE_OPTIONS=--openssl-legacy-provider && umi build",
|
||||
"postinstall": "umi generate tmp",
|
||||
"prettier": "prettier --write '**/*.{js,jsx,tsx,ts,less,md,json}'",
|
||||
"test": "umi-test",
|
||||
|
@ -21,9 +21,14 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@ant-design/pro-layout": "^6.5.0",
|
||||
"@umijs/preset-react": "1.x",
|
||||
"@umijs/preset-react": "^2.1.7",
|
||||
"antd": "^4.14.0",
|
||||
"umi": "^3.3.9"
|
||||
"compression": "^1.7.4",
|
||||
"express": "^4.17.1",
|
||||
"helmet": "^3.21.2",
|
||||
"umi": "^3.3.9",
|
||||
"umi-request": "^1.2.4",
|
||||
"umi-server": "^1.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react": "^17.0.0",
|
||||
|
|
|
@ -1,19 +1,14 @@
|
|||
import React from "react";
|
||||
import { isBrowser } from "umi";
|
||||
import { ConfigProvider, Layout, message, Menu, Dropdown } from "antd";
|
||||
import { router } from "umi";
|
||||
import zhCN from "antd/es/locale/zh_CN";
|
||||
import enUS from "antd/es/locale/en_US";
|
||||
import BaseHeader from "./components/BaseHeader";
|
||||
import TopMenu from "./components/TopMenu";
|
||||
import Footer from "./components/Footer";
|
||||
// import headMenuData from "./menuData";
|
||||
import yuyanImg from "../assets/icon_yuyan@3x.png";
|
||||
import { getLocale } from "../utils";
|
||||
import styles from "./BaseLayout.less";
|
||||
import locale from "antd/lib/date-picker/locale/en_US";
|
||||
// import zhCNConfig from "../locales/zh_CN";
|
||||
// import enUSConfig from "../locales/en_US ";
|
||||
|
||||
const { Header, Content } = Layout;
|
||||
|
||||
const findPrefixSelectedKey = (topMenu, key = "") => {
|
||||
|
@ -26,13 +21,54 @@ const findPrefixSelectedKey = (topMenu, key = "") => {
|
|||
return key;
|
||||
};
|
||||
|
||||
const localeConfig = getLocale();
|
||||
class BaseLayout extends React.Component {
|
||||
state = {
|
||||
locale: localStorage.getItem("language") || "中文",
|
||||
locale: "",
|
||||
localeConfig: {},
|
||||
headMenuData: [],
|
||||
};
|
||||
|
||||
headMenuData = [
|
||||
handleLocaleChange = (val) => {
|
||||
if (val !== this.state.locale) {
|
||||
this.setState({ locale: val });
|
||||
if (!isBrowser()) {
|
||||
localStorage.setItem("language", val);
|
||||
}
|
||||
window.location.reload();
|
||||
}
|
||||
};
|
||||
|
||||
localeMenu = (
|
||||
<Menu>
|
||||
<Menu.Item
|
||||
onClick={() => {
|
||||
this.handleLocaleChange("中文");
|
||||
}}
|
||||
>
|
||||
<span style={{ padding: "26px 50px" }}>中文</span>
|
||||
</Menu.Item>
|
||||
<Menu.Item
|
||||
onClick={() => {
|
||||
this.handleLocaleChange("English");
|
||||
}}
|
||||
>
|
||||
<span style={{ padding: "16px 50px" }}>English</span>
|
||||
</Menu.Item>
|
||||
</Menu>
|
||||
);
|
||||
handleSideMenuClick = (item) => {
|
||||
const { history } = this.props;
|
||||
if (item.key) {
|
||||
history.push(item.key);
|
||||
}
|
||||
};
|
||||
componentDidMount() {
|
||||
const val = localStorage.getItem("language") || "中文";
|
||||
const localeConfig = getLocale(val);
|
||||
this.setState({
|
||||
locale: val,
|
||||
localeConfig: localeConfig,
|
||||
headMenuData: [
|
||||
{
|
||||
key: "/home",
|
||||
text: localeConfig.sy,
|
||||
|
@ -75,40 +111,9 @@ class BaseLayout extends React.Component {
|
|||
key: "/contact-us",
|
||||
text: localeConfig.footerMenu4,
|
||||
},
|
||||
];
|
||||
|
||||
handleLocaleChange = (val) => {
|
||||
if (val !== this.state.locale) {
|
||||
this.setState({ locale: val });
|
||||
localStorage.setItem("language", val);
|
||||
window.location.reload();
|
||||
],
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
localeMenu = (
|
||||
<Menu>
|
||||
<Menu.Item
|
||||
onClick={() => {
|
||||
this.handleLocaleChange("中文");
|
||||
}}
|
||||
>
|
||||
<span style={{ padding: "26px 50px" }}>中文</span>
|
||||
</Menu.Item>
|
||||
<Menu.Item
|
||||
onClick={() => {
|
||||
this.handleLocaleChange("English");
|
||||
}}
|
||||
>
|
||||
<span style={{ padding: "16px 50px" }}>English</span>
|
||||
</Menu.Item>
|
||||
</Menu>
|
||||
);
|
||||
handleSideMenuClick = (item) => {
|
||||
const { history } = this.props;
|
||||
if (item.key) {
|
||||
history.push(item.key);
|
||||
}
|
||||
};
|
||||
|
||||
componentDidCatch(error) {
|
||||
if (process.env.NODE_ENV !== "development") {
|
||||
|
@ -118,13 +123,14 @@ class BaseLayout extends React.Component {
|
|||
duration: 2,
|
||||
key: "error",
|
||||
});
|
||||
router.replace("/exception/500");
|
||||
// router.replace("/exception/500");
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
const { localeConfig, headMenuData = [] } = this.state;
|
||||
const { children, location = {} } = this.props;
|
||||
const { pathname = "" } = location;
|
||||
const arr = ["/home"];
|
||||
|
@ -160,9 +166,9 @@ class BaseLayout extends React.Component {
|
|||
</div>
|
||||
<TopMenu
|
||||
selectedKeys={[
|
||||
findPrefixSelectedKey(this.headMenuData, location.pathname),
|
||||
findPrefixSelectedKey(headMenuData, location.pathname),
|
||||
]}
|
||||
data={this.headMenuData}
|
||||
data={headMenuData}
|
||||
onClick={this.handleSideMenuClick}
|
||||
isInherit={isInherit}
|
||||
/>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import React, { useEffect } from "react";
|
||||
import React, { useState, useEffect } from "react";
|
||||
import { Button, Carousel, Image } from "antd";
|
||||
import GreenLine from "../../components/GreenLine";
|
||||
import bg1 from "../../assets/img_guanyu@3x.png";
|
||||
|
@ -22,10 +22,12 @@ import styles from "./index.less";
|
|||
|
||||
const IndexPage = (props) => {
|
||||
console.log(props);
|
||||
const locale = getLocale();
|
||||
const [locale, setLocale] = useState({});
|
||||
|
||||
// 测试接口
|
||||
useEffect(() => {
|
||||
const val = localStorage.getItem("language") || "中文";
|
||||
setLocale(getLocale(val));
|
||||
getData();
|
||||
}, []);
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
import React, { useState } from "react";
|
||||
import { Row, Col } from "antd";
|
||||
|
||||
import React, { useState, useEffect } from "react";
|
||||
import { getLocale } from "../../../utils";
|
||||
import styles from "./index.less";
|
||||
import CusBreadcrumb from "../../../components/CusBreadcrumb";
|
||||
|
@ -8,7 +6,6 @@ import CusBreadcrumb from "../../../components/CusBreadcrumb";
|
|||
import img1 from "../../../assets/img_zhengshu@3x.png";
|
||||
|
||||
const FullCertificate = (props) => {
|
||||
const locale = getLocale();
|
||||
const [certificateList, setCertificateList] = useState([
|
||||
{ url: img1, name: "xxxxxxxxxxxxxxxxxxx CE证书" },
|
||||
{ url: img1, name: "xxxxx CE证书" },
|
||||
|
@ -19,6 +16,13 @@ const FullCertificate = (props) => {
|
|||
{ url: img1, name: "xxxxxxxxxxxxxxxxxxx CE证书" },
|
||||
{ url: img1, name: "xxxxxxxxxxxxxxxxxxx CE证书" },
|
||||
]);
|
||||
|
||||
const [locale, setLocale] = useState({});
|
||||
useEffect(() => {
|
||||
const val = localStorage.getItem("language") || "中文";
|
||||
setLocale(getLocale(val));
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className={styles.root}>
|
||||
<CusBreadcrumb
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import React from "react";
|
||||
import React, { useState, useEffect } from "react";
|
||||
import { Divider, Button } from "antd";
|
||||
import { getLocale } from "../../utils";
|
||||
import styles from "./index.less";
|
||||
|
@ -11,8 +11,12 @@ import img1 from "../../assets/img_guanyuwomen@3x.png";
|
|||
import img2 from "../../assets/img_zhengshu@3x.png";
|
||||
|
||||
const IndexPage = (props) => {
|
||||
const locale = getLocale();
|
||||
const { history } = props;
|
||||
const [locale, setLocale] = useState({});
|
||||
useEffect(() => {
|
||||
const val = localStorage.getItem("language") || "中文";
|
||||
setLocale(getLocale(val));
|
||||
}, []);
|
||||
|
||||
const renderItem = ({ imgUrl, name, year, info }, index) => (
|
||||
<div
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
import React from "react";
|
||||
import { Divider, Button } from "antd";
|
||||
import React, { useState, useEffect } from "react";
|
||||
import { getLocale } from "../../utils";
|
||||
import styles from "./index.less";
|
||||
import GreenLine from "../../components/GreenLine";
|
||||
import CusBreadcrumb from "../../components/CusBreadcrumb";
|
||||
import PageHeaderInfo from "../../components/PageHeaderInfo";
|
||||
|
||||
import img1 from "../../assets/img_guanyuwomen@3x.png";
|
||||
|
||||
const IndexPage = (props) => {
|
||||
const locale = getLocale();
|
||||
const { history } = props;
|
||||
const [locale, setLocale] = useState({});
|
||||
useEffect(() => {
|
||||
const val = localStorage.getItem("language") || "中文";
|
||||
setLocale(getLocale(val));
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className={styles.root}>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import React from "react";
|
||||
import React, { useState, useEffect } from "react";
|
||||
import { Form, Button, Input } from "antd";
|
||||
import { getLocale } from "../../utils";
|
||||
import styles from "./index.less";
|
||||
|
@ -15,7 +15,11 @@ import img6 from "../../assets/img_ditu@3x.png";
|
|||
|
||||
const IndexPage = (props) => {
|
||||
const { history } = props;
|
||||
const locale = getLocale();
|
||||
const [locale, setLocale] = useState({});
|
||||
useEffect(() => {
|
||||
const val = localStorage.getItem("language") || "中文";
|
||||
setLocale(getLocale(val));
|
||||
}, []);
|
||||
|
||||
const jstdImgList = [
|
||||
{
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
import React from 'react';
|
||||
import { Redirect } from 'umi'
|
||||
|
||||
const index = () => <Redirect to="/home" />;
|
||||
|
||||
export default index;
|
|
@ -1,4 +1,4 @@
|
|||
import React, { useState } from "react";
|
||||
import React, { useState, useEffect } from "react";
|
||||
import { Image } from "antd";
|
||||
|
||||
import { getLocale } from "../../../utils";
|
||||
|
@ -13,8 +13,13 @@ import img4 from "../../../assets/img_chanpin_4@3x.png";
|
|||
const FullCertificate = (props) => {
|
||||
const { location = {} } = props; // activeTab
|
||||
const { id, tabName, tabValue } = location?.query || {}; // activeTab
|
||||
const locale = getLocale();
|
||||
const [visible, setVisible] = useState(false);
|
||||
const [locale, setLocale] = useState({});
|
||||
useEffect(() => {
|
||||
const val = localStorage.getItem("language") || "中文";
|
||||
setLocale(getLocale(val));
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className={styles.product_detail_root}>
|
||||
<CusBreadcrumb
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import React, { useState, useEffect } from "react";
|
||||
import styles from "./index.less";
|
||||
import { Tabs, Empty, Pagination, Divider } from "antd";
|
||||
import { getLocale } from "../../utils";
|
||||
|
@ -8,12 +9,14 @@ import img1 from "../../assets/img_chanpinzhongxin@3x.png";
|
|||
import img2 from "../../assets/img_chnapin@3x.png";
|
||||
import img3 from "../../assets/img_shangbiao@3x.png";
|
||||
|
||||
import React, { useEffect, useState } from "react";
|
||||
|
||||
const IndexPage = (props) => {
|
||||
const { history, location = {} } = props; // activeTab
|
||||
const { tabCode = "" } = location?.query || {}; // activeTab
|
||||
const locale = getLocale();
|
||||
const [locale, setLocale] = useState({});
|
||||
useEffect(() => {
|
||||
const val = localStorage.getItem("language") || "中文";
|
||||
setLocale(getLocale(val));
|
||||
}, []);
|
||||
const [activeTab, setActiveTab] = useState({});
|
||||
const [productList, setProductList] = useState([
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import React from "react";
|
||||
import React, { useState, useEffect } from "react";
|
||||
import { Divider, Button } from "antd";
|
||||
import { getLocale } from "../../utils";
|
||||
import styles from "./index.less";
|
||||
|
@ -16,7 +16,11 @@ import img6 from "../../assets/img_jishu_guanli@3x.png";
|
|||
|
||||
const IndexPage = (props) => {
|
||||
const { history } = props;
|
||||
const locale = getLocale();
|
||||
const [locale, setLocale] = useState({});
|
||||
useEffect(() => {
|
||||
const val = localStorage.getItem("language") || "中文";
|
||||
setLocale(getLocale(val));
|
||||
}, []);
|
||||
|
||||
const jstdImgList = [
|
||||
{
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import zhCNConfig from "./locales/zh_CN";
|
||||
import enUSConfig from "./locales/en_US ";
|
||||
|
||||
export const getLocale = () => {
|
||||
const local = localStorage.getItem("language") || "中文";
|
||||
return local === "中文" ? zhCNConfig : enUSConfig;
|
||||
export const getLocale = (language) => {
|
||||
return language === "中文" ? zhCNConfig : enUSConfig;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue