Support language param.

This commit is contained in:
Gucheng Wang
2022-02-28 21:33:10 +08:00
parent 4915963c52
commit a5d166c35f

View File

@ -146,16 +146,14 @@ class App extends Component {
}
}
getAccessTokenParam() {
getAccessTokenParam(params) {
// "/page?access_token=123"
const params = new URLSearchParams(this.props.location.search);
const accessToken = params.get("access_token");
return accessToken === null ? "" : `?accessToken=${accessToken}`;
}
getCredentialParams() {
getCredentialParams(params) {
// "/page?username=abc&password=123"
const params = new URLSearchParams(this.props.location.search);
if (params.get("username") === null || params.get("password") === null) {
return "";
}
@ -163,8 +161,17 @@ class App extends Component {
}
getUrlWithoutQuery() {
// eslint-disable-next-line no-restricted-globals
return location.toString().replace(location.search, "");
return window.location.toString().replace(window.location.search, "");
}
getLanguageParam(params) {
// "/page?language=en"
const language = params.get("language");
if (language !== null) {
Setting.setLanguage(language);
return `language=${language}`;
}
return "";
}
setLanguage(account) {
@ -175,13 +182,23 @@ class App extends Component {
}
getAccount() {
let query = this.getAccessTokenParam();
const params = new URLSearchParams(this.props.location.search);
let query = this.getAccessTokenParam(params);
if (query === "") {
query = this.getCredentialParams();
query = this.getCredentialParams(params);
}
const query2 = this.getLanguageParam(params);
if (query2 !== "") {
const url = window.location.toString().replace(new RegExp(`[?&]${query2}`), "");
window.history.replaceState({}, document.title, url);
}
if (query !== "") {
window.history.replaceState({}, document.title, this.getUrlWithoutQuery());
}
AuthBackend.getAccount(query)
.then((res) => {
let account = null;
@ -417,20 +434,20 @@ class App extends Component {
</Link>
</Menu.Item>
);
// res.push(
// <Menu.Item key="/products">
// <Link to="/products">
// {i18next.t("general:Products")}
// </Link>
// </Menu.Item>
// );
// res.push(
// <Menu.Item key="/payments">
// <Link to="/payments">
// {i18next.t("general:Payments")}
// </Link>
// </Menu.Item>
// );
res.push(
<Menu.Item key="/products">
<Link to="/products">
{i18next.t("general:Products")}
</Link>
</Menu.Item>
);
res.push(
<Menu.Item key="/payments">
<Link to="/payments">
{i18next.t("general:Payments")}
</Link>
</Menu.Item>
);
res.push(
<Menu.Item key="/swagger">
<a target="_blank" rel="noreferrer" href={Setting.isLocalhost() ? `${Setting.ServerUrl}/swagger` : "/swagger"}>