_layout.tsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. /*
  2. * @Author: your name
  3. * @Date: 2022-01-06 15:25:39
  4. * @LastEditTime: 2023-06-02 18:14:47
  5. * @LastEditors: code4eat awesomedema@gmail.com
  6. * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  7. * @FilePath: /KC-MiddlePlatform/src/pages/platform/_layout.tsx
  8. */
  9. import { IRouteComponentProps, useModel, Helmet } from 'umi';
  10. // import { CrownOutlined, UserOutlined, SmileOutlined } from '@ant-design/icons';
  11. import ProLayout, { PageContainer } from '@ant-design/pro-layout';
  12. import { getPlatformMenu, getSpecifyMenuDetail } from '@/service/menu';
  13. import './index.less';
  14. import { TreeItemType } from '@/utils';
  15. import { Iframe, SpacicalPageParamsType } from '@/typings';
  16. import { Key, useEffect, useState } from 'react';
  17. import IconFont from '@ant-design/icons/lib/components/IconFont';
  18. import { FileOutlined, FolderOutlined, SmileOutlined } from '@ant-design/icons';
  19. import { getParamsManaTableData } from './setting/paramsMana/service';
  20. import { getAllParams } from '@/service';
  21. export default function Layout({ children, location, route, history, match, ...rest }: IRouteComponentProps) {
  22. const { initialState, setInitialState } = useModel('@@initialState');
  23. const [openKeys, set_openKeys] = useState<string[]>([]);
  24. const [selectedKeys, set_selectedKeys] = useState<string[]>([]);
  25. const [emptyPageContent, set_emptyPageContent] = useState('');
  26. const [isShowPageMenu, set_isShowPageMenu] = useState(true);
  27. const [isEmpty, set_isEmpty] = useState(false);
  28. const [pageUrl, set_pageUrl] = useState<string | undefined>(undefined);
  29. const { pathname } = location;
  30. const setEmptyPageContent = async (menuId: Key) => {
  31. const menuItem = await getSpecifyMenuDetail(menuId);
  32. if (menuItem.isSetupMenu) {
  33. set_isShowPageMenu(false);
  34. }
  35. set_emptyPageContent(menuItem.description);
  36. }
  37. useEffect(() => {
  38. const isShowMenu = localStorage.getItem('isChildShowMenu');
  39. set_isShowPageMenu(isShowMenu == 'true')
  40. });
  41. useEffect(() => {
  42. if (location.query.menuId) {
  43. setEmptyPageContent(location.query.menuId as string);
  44. }
  45. set_isEmpty(location.query.isEmpty == 'true');
  46. }, [location]);
  47. const adjustIframe = () => {
  48. // var ifm:any = document.getElementById("bi_iframe");
  49. // if(ifm){
  50. // ifm.height=document.documentElement.clientHeight;
  51. // ifm.width=document.documentElement.clientWidth;
  52. // }
  53. }
  54. //临时演示处理
  55. console.log('location.pathname',location.pathname);
  56. if (location.pathname == '/platform/costMana') {
  57. //临时解决未嵌入成本核算,而实现访问的效果
  58. const getToken = async () => {
  59. const resp = await getAllParams();
  60. if (resp) {
  61. const needItem = resp.filter((a: any) => a.code == '1647777324889935872');
  62. if (needItem.length > 0) {
  63. set_pageUrl(`http://47.96.149.190:8000/platformMana/roleManage?hospSign=dOBHdoPmJgPGnMSH&token=${needItem[0].value}`)
  64. }
  65. }
  66. }
  67. getToken();
  68. return (
  69. <>
  70. {pageUrl && <iframe id={'bi_iframe'} style={{ width: '100%', height: '100%', border: 'none' }} src={pageUrl} onLoad={() => adjustIframe()} ></iframe>};
  71. </>
  72. )
  73. }
  74. if (location.pathname == '/platform/KcimDairlyLog') {
  75. //临时解决未嵌入成本核算,而实现访问的效果
  76. // const getToken = async () => {
  77. // // const resp = await getAllParams();
  78. // // if (resp) {
  79. // // const needItem = resp.filter((a: any) => a.code == '1647777324889935872');
  80. // // if (needItem.length > 0) {
  81. // // set_pageUrl(`http://47.96.149.190:8000/platformMana/roleManage?hospSign=dOBHdoPmJgPGnMSH&token=${needItem[0].value}`)
  82. // // }
  83. // // }
  84. // set_pageUrl(`http://www.baidu.com`)
  85. // }
  86. // getToken();
  87. const pageUrl = `http://118.31.50.255:8080/`;
  88. return (
  89. <>
  90. {pageUrl && <iframe id={'bi_iframe'} style={{ width: '100%', height: '100%', border: 'none' }} src={pageUrl} onLoad={() => adjustIframe()} ></iframe>};
  91. </>
  92. )
  93. }
  94. return (
  95. <ProLayout
  96. style={{
  97. height: 'calc(100vh - 50px)',
  98. }}
  99. iconfontUrl="//at.alicdn.com/t/font_8d5l8fzk5b87iudi.js"
  100. logoStyle={{
  101. display: 'none',
  102. }}
  103. location={{
  104. }}
  105. headerContentRender={false}
  106. headerRender={false}
  107. siderWidth={isShowPageMenu ? 220 : 0}
  108. pageTitleRender={false}
  109. disableContentMargin
  110. menuItemRender={(item, dom) => {
  111. return (
  112. <a
  113. onClick={() => {
  114. history.push(`${item.path}${item.contentType == '4' ? `?isEmpty=true&menuId=${item.key}` : ''}` || '/');
  115. }}
  116. >
  117. {dom}
  118. </a>
  119. )
  120. }}
  121. menuProps={{
  122. openKeys: [...openKeys],
  123. selectedKeys: [...selectedKeys],
  124. onSelect: ({ key, keyPath, selectedKeys, domEvent }) => {
  125. set_selectedKeys(selectedKeys);
  126. localStorage.setItem('selectedKeys', JSON.stringify(selectedKeys));
  127. },
  128. onOpenChange: (keys: string[]) => {
  129. set_openKeys([...keys]);
  130. localStorage.setItem('openKeys', JSON.stringify(keys));
  131. },
  132. }}
  133. menu={{
  134. autoClose: false,
  135. params: {
  136. initialState
  137. },
  138. request: async () => {
  139. if (initialState && initialState.currentSelectedSys) {
  140. const { systemId, menuId, path } = initialState.currentSelectedSys;
  141. if (systemId || menuId) {
  142. //只有当存在systemId
  143. const menuData = await getPlatformMenu(systemId || menuId);
  144. let homePage: TreeItemType | undefined;
  145. const getVFromTree = (data: TreeItemType[], key: string) => {
  146. let result: SpacicalPageParamsType[] = [];
  147. function looper(data: TreeItemType[], key: string) {
  148. data.forEach((t) => {
  149. if (t.isHomepage) {
  150. homePage = t;
  151. }
  152. if (t[key] == 1 || t[key] == 2 || t[key] == 3) {
  153. //网易有数页面
  154. result.push({
  155. contentType: t[key],
  156. path: t['path'],
  157. reportId: t['reportId'],
  158. url: t['youshuUrl'],
  159. });
  160. }
  161. if (t[key] == 5) {
  162. //蓝湖静态展示页面
  163. result.push({
  164. contentType: t[key],
  165. path: t['path'],
  166. reportId: t['reportId'],
  167. url: t['softUrl'],
  168. });
  169. }
  170. if (t.children && t.children.length > 0) {
  171. looper(t.children, key);
  172. }
  173. });
  174. }
  175. looper(data, key);
  176. return result;
  177. };
  178. const _menu = getVFromTree(menuData, 'contentType');
  179. setInitialState((t) => ({ ...t, spacicalPageParamsType: _menu }));
  180. if (homePage) {
  181. // console.log({homePage});
  182. set_openKeys([homePage.key]);
  183. set_selectedKeys([homePage.key]);
  184. history.push(homePage.path);
  185. } else {
  186. if (path == '/platform') {
  187. const selectedKeys = localStorage.getItem('selectedKeys');
  188. const openKeys = localStorage.getItem('openKeys');
  189. if (selectedKeys && openKeys) {
  190. const _selectedKeys = JSON.parse(selectedKeys);
  191. const _openKeys = JSON.parse(openKeys);
  192. set_openKeys(_openKeys);
  193. set_selectedKeys(_selectedKeys);
  194. } else {
  195. if (menuData[0].children && menuData[0].children.length > 0) {
  196. const childs = menuData[0].children;
  197. set_openKeys([menuData[0].key]);
  198. set_selectedKeys([childs[0].key]);
  199. localStorage.setItem('openKeys', JSON.stringify([menuData[0].key]));
  200. localStorage.setItem('selectedKeys', JSON.stringify([childs[0].key]));
  201. history.push(`${childs[0].path}`);
  202. }else{
  203. if(menuData[0]){
  204. set_openKeys([menuData[0].key]);
  205. set_selectedKeys([menuData[0].key]);
  206. localStorage.setItem('openKeys', JSON.stringify([menuData[0].key]));
  207. localStorage.setItem('selectedKeys', JSON.stringify([menuData[0].key]));
  208. history.push(`${menuData[0].path}`);
  209. }
  210. }
  211. }
  212. }
  213. }
  214. // console.log({homePage})
  215. // return [...menuData, {
  216. // name: 'SQL编辑器',
  217. // path: '/platform/sqlEditer'
  218. // }];
  219. const addIcon = (arr: any) => arr.map((item: any) => (item.children ? {
  220. ...item,
  221. icon: <FolderOutlined />,
  222. children: addIcon(item.children)
  223. } : {
  224. ...item,
  225. icon: <FileOutlined />,
  226. }))
  227. const result = addIcon(menuData);
  228. return [...result];
  229. }
  230. return [];
  231. }
  232. return [];
  233. },
  234. }}
  235. onPageChange={(location) => { }}
  236. layout="side"
  237. navTheme="light"
  238. >
  239. {
  240. isEmpty && (
  241. <div className='emptyContainer' style={{ textAlign: 'center', paddingTop: 100 }}>
  242. <h1>{emptyPageContent}</h1>
  243. </div>
  244. )
  245. }
  246. {
  247. !isEmpty && (
  248. <PageContainer
  249. className="kcmpPageContainer"
  250. header={{
  251. title: false,
  252. }}
  253. style={{
  254. margin: 0,
  255. }}
  256. >
  257. <Helmet>
  258. <title>精益管理中台</title>
  259. </Helmet>
  260. <div className="page" style={{ height: 'calc(100vh - 80px)', overflowY: 'scroll' }}>
  261. {children}
  262. </div>
  263. </PageContainer>
  264. )
  265. }
  266. </ProLayout>
  267. );
  268. }