Files
KnowStreaming/km-console/packages/layout-clusters-fe/src/app.tsx
爱喝药的大郎 59e8a416b5 [Bugfix]修复未勾选系统管理查看权限,但是依然可以查看系统管理的问题 (#1105)
请不要在没有先创建Issue的情况下创建Pull Request。

## 变更的目的是什么
修复未勾选系统管理查看权限,但是依然可以查看系统管理的问题
## 简短的更新日志
修复未勾选系统管理查看权限,但是依然可以查看系统管理的问题
## 验证这一变化
### 权限表
<img width="587" alt="image"
src="https://github.com/didi/KnowStreaming/assets/43955116/497fea54-3216-4ae7-8dab-304a07e81209">

### 效果
<img width="1500" alt="image"
src="https://github.com/didi/KnowStreaming/assets/43955116/1e4a8260-336e-4c15-a244-5f768107a990">

请遵循此清单,以帮助我们快速轻松地整合您的贡献:

* [x] 一个 PR(Pull Request的简写)只解决一个问题,禁止一个 PR 解决多个问题;
* [x] 确保 PR 有对应的 Issue(通常在您开始处理之前创建),除非是书写错误之类的琐碎更改不需要 Issue ;
* [x] 格式化 PR 及 Commit-Log 的标题及内容,例如 #861 。PS:Commit-Log 需要在 Git Commit
代码时进行填写,在 GitHub 上修改不了;
* [x] 编写足够详细的 PR 描述,以了解 PR 的作用、方式和原因;
* [x] 编写必要的单元测试来验证您的逻辑更正。如果提交了新功能或重大更改,请记住在 test 模块中添加 integration-test;
* [x] 确保编译通过,集成测试通过;

Co-authored-by: suzj <hzsuzj@qq.com>
2023-10-20 09:32:31 +08:00

252 lines
7.3 KiB
TypeScript
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* eslint-disable no-constant-condition */
import '@babel/polyfill';
import React, { useState, useEffect, useLayoutEffect } from 'react';
import { BrowserRouter, Switch, Route, useLocation, useHistory } from 'react-router-dom';
import { get as lodashGet } from 'lodash';
import { DProLayout, AppContainer, Menu, Utils, Page500, Modal } from 'knowdesign';
import { IconFont } from '@knowdesign/icons';
import dantdZhCN from 'knowdesign/es/locale/zh_CN';
import dantdEnUS from 'knowdesign/es/locale/en_US';
import { DotChartOutlined } from '@ant-design/icons';
import { licenseEventBus } from './constants/axiosConfig';
import { Page403, Page404, NoLicense } from './pages/ErrorPages';
import intlZhCN from './locales/zh';
import intlEnUS from './locales/en';
import registerApps from '../config/registerApps';
import feSystemsConfig from '../config/systemsConfig';
import './index.less';
import { Login } from './pages/Login';
import { getLicenseInfo } from './constants/common';
import api from './api';
import ClusterContainer from './pages/index';
import ksLogo from './assets/ks-logo.png';
import {ClustersPermissionMap} from "./pages/CommonConfig";
interface ILocaleMap {
[index: string]: any;
}
interface VersionInfo {
'git.branch': string;
'git.build.itme': string;
'git.build.version': string;
'git.commit.id': string;
'git.commit.id.abbrev': string;
'git.commit.time': string;
}
const localeMap: ILocaleMap = {
'zh-CN': {
dantd: dantdZhCN,
intl: 'zh-CN',
intlMessages: intlZhCN,
},
en: {
dantd: dantdEnUS,
intl: 'en',
intlMessages: intlEnUS,
},
};
const primaryFeConf = feSystemsConfig.feConfig;
const systemsConfig = feSystemsConfig.systemsConfig as any;
const defaultLanguage = 'zh-CN';
export const { Provider, Consumer } = React.createContext('zh');
const judgePage404 = () => {
const { pathname } = window.location;
const paths = pathname.split('/');
const exceptionLocationPaths = ['/404', '/500', '/403'];
const row = systemsConfig.filter((item: any) => item.ident === paths?.[1]);
if (exceptionLocationPaths.indexOf(pathname) < -1 && paths?.[1] && !row.length) {
window.location.href = '/404';
}
};
const logout = () => {
Utils.request(api.logout, {
method: 'POST',
}).then((res) => {
window.location.href = '/login';
});
localStorage.removeItem('userInfo');
};
const LicenseLimitModal = () => {
const [visible, setVisible] = useState<boolean>(false);
const [msg, setMsg] = useState<string>('');
useLayoutEffect(() => {
licenseEventBus.on('licenseError', (desc: string) => {
!visible && setVisible(true);
setMsg(desc);
});
return () => {
licenseEventBus.removeAll('licenseError');
};
}, []);
return (
<Modal
visible={visible}
centered={true}
width={400}
zIndex={10001}
title={
<>
<IconFont type="icon-yichang" style={{ marginRight: 10, fontSize: 18 }} />
</>
}
footer={null}
onCancel={() => setVisible(false)}
>
<div style={{ margin: '0 28px', lineHeight: '24px' }}>
<div>
{msg}<a></a>
</div>
</div>
</Modal>
);
};
const AppContent = (props: { setlanguage: (language: string) => void }) => {
const { pathname } = useLocation();
const history = useHistory();
const userInfo = localStorage.getItem('userInfo');
const [curActiveAppName, setCurActiveAppName] = useState('');
const [versionInfo, setVersionInfo] = useState<VersionInfo>();
const [global] = AppContainer.useGlobalValue();
const quickEntries=[];
useEffect(() => {
if (pathname.startsWith('/config')) {
setCurActiveAppName('config');
} else {
setCurActiveAppName('cluster');
}
}, [pathname]);
// 获取版本信息
useEffect(() => {
Utils.request(api.getVersionInfo()).then((res: VersionInfo) => {
setVersionInfo(res);
});
}, []);
if (global.hasPermission && global.hasPermission(ClustersPermissionMap.CLUSTERS_MANAGE_VIEW)){
quickEntries.push({
icon: <IconFont type="icon-duojiqunguanli"/>,
txt: '多集群管理',
ident: '',
active: curActiveAppName === 'cluster',
});
}
if (global.hasPermission && global.hasPermission(ClustersPermissionMap.SYS_MANAGE_VIEW)){
quickEntries.push({
icon: <IconFont type="icon-xitongguanli" />,
txt: '系统管理',
ident: 'config',
active: curActiveAppName === 'config',
});
}
return (
<DProLayout.Container
headerProps={{
title: (
<div style={{ cursor: 'pointer' }}>
<img className="header-logo" src={ksLogo} />
</div>
),
username: userInfo ? JSON.parse(userInfo)?.userName : '',
icon: <DotChartOutlined />,
quickEntries: quickEntries,
isFixed: false,
userDropMenuItems: [
<Menu.Item key={0}>
<a href="https://github.com/didi/KnowStreaming/releases" rel="noreferrer" target="_blank">
: {versionInfo?.['git.build.version']}
</a>
</Menu.Item>,
<Menu.Item key={1} onClick={logout}>
</Menu.Item>,
],
onChangeLanguage: props.setlanguage,
onClickQuickEntry: (qe) => {
history.push({
pathname: '/' + (qe.ident || ''),
});
},
onClickMain: () => {
history.push('/');
},
}}
onMount={(customProps: any) => {
judgePage404();
registerApps(systemsConfig, { ...customProps, getLicenseInfo, licenseEventBus }, () => {
// postMessage();
});
}}
>
<>
<Switch>
<Route path="/403" exact component={Page403} />
<Route path="/404" exact component={Page404} />
<Route path="/500" exact component={Page500} />
<Route
render={() => {
return (
<>
{curActiveAppName === 'cluster' && <ClusterContainer />}
<div id="ks-layout-container" />
</>
);
}}
/>
</Switch>
<LicenseLimitModal />
</>
</DProLayout.Container>
);
};
export default function App(): JSX.Element {
const [language, setlanguage] = useState(navigator.language.substr(0, 2));
const intlMessages = lodashGet(localeMap[language], 'intlMessages', intlZhCN);
const [feConf] = useState(primaryFeConf || {});
const locale = lodashGet(localeMap[defaultLanguage], 'intl', 'zh-CN');
const antdLocale = lodashGet(localeMap[defaultLanguage], 'dantd', dantdZhCN);
const pageTitle = lodashGet(feConf, 'title');
if (pageTitle) {
document.title = pageTitle;
}
useEffect(() => {
window.postMessage(
{
type: 'language',
value: language,
},
window.location.origin
);
}, [language]);
return (
<>
<AppContainer intlProvider={{ locale, messages: intlMessages }} antdProvider={{ locale: antdLocale }} store>
<BrowserRouter basename="">
<Switch>
<Route path="/login" component={Login} />
<Route path="/no-license" exact component={NoLicense} />
<Route render={() => <AppContent setlanguage={setlanguage} />} />
</Switch>
</BrowserRouter>
</AppContainer>
</>
);
}