add tenant permission

master
Aaron Yu 2022-09-04 17:06:49 +08:00
parent 7e44a00d30
commit 9a52b3dd47
3 changed files with 29 additions and 11 deletions

View File

@ -42,3 +42,7 @@
.MuiFormControlLabel-label {
font-size: 13px !important;
}
.MuiDialog-root {
background-color: white;
}

View File

@ -1,6 +1,7 @@
import "./App.css";
import * as ProjectApi from "./apis/projectApi";
import * as LoginApi from "./apis/loginApi";
import * as utils from "./utils";
import Pane from "./Components/pane";
import DeviceFrame from "./Components/deviceFrame";
import waterMarkPng from "./images/water-mark.png";
@ -34,7 +35,7 @@ class App extends React.Component {
dataUrl: "",
loading: false,
loginOpen: false,
showLoginError: false,
loginErrorMessage: "",
loginForm: {
account: "",
password: "",
@ -44,18 +45,23 @@ class App extends React.Component {
}
componentDidMount() {
const loginInfo = getLoginInfo();
if (loginInfo) {
var tenant = utils.getTenant();
if (loginInfo && loginInfo.permissionPages.includes(tenant)) {
this.fetchData();
this.refreshQrCode();
} else {
this.setState({ loginOpen: true });
loginInfo &&
this.setState({ loginErrorMessage: "无权限访问,请切换账号" });
}
}
login = async () => {
var { account, password, keepLogin } = this.state.loginForm;
var user = await LoginApi.UserLogin({ account, password });
if (user) {
var tenant = utils.getTenant();
if (user && user.permissionPages.includes(tenant)) {
this.setState({
loginOpen: false,
});
@ -66,7 +72,9 @@ class App extends React.Component {
this.refreshQrCode();
} else {
this.setState({
showLoginError: true,
loginErrorMessage: user
? `无权限访问${tenant},请切换账号`
: "账号或密码错误",
});
}
};
@ -205,9 +213,15 @@ class App extends React.Component {
/>
</DialogContent>
<DialogActions>
{this.state.showLoginError && (
<span style={{ color: "red", margin: "0 auto 0 10px" }}>
账号或密码错误
{this.state.loginErrorMessage && (
<span
style={{
color: "red",
fontSize: "12px",
margin: "0 auto 0 10px",
}}
>
{this.state.loginErrorMessage}
</span>
)}
<FormControlLabel

View File

@ -1,6 +1,6 @@
import queryString from 'query-string'
import queryString from "query-string";
export function getTenant() {
const tenant = queryString.parseUrl(window.location.href)?.query?.tenant
return tenant || "funplus"
}
const tenant = queryString.parseUrl(window.location.href)?.query?.tenant;
return tenant?.toLowerCase() || "funplus";
}