From 9a52b3dd47f29e3400e6ce30d939bc4446d93232 Mon Sep 17 00:00:00 2001 From: Aaron Yu Date: Sun, 4 Sep 2022 17:06:49 +0800 Subject: [PATCH] add tenant permission --- src/App.css | 4 ++++ src/App.js | 28 +++++++++++++++++++++------- src/utils.js | 8 ++++---- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/App.css b/src/App.css index ca11d2b..82de5b8 100644 --- a/src/App.css +++ b/src/App.css @@ -42,3 +42,7 @@ .MuiFormControlLabel-label { font-size: 13px !important; } + +.MuiDialog-root { + background-color: white; +} \ No newline at end of file diff --git a/src/App.js b/src/App.js index 9c14595..bee96bb 100644 --- a/src/App.js +++ b/src/App.js @@ -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 { /> - {this.state.showLoginError && ( - - 账号或密码错误 + {this.state.loginErrorMessage && ( + + {this.state.loginErrorMessage} )}