view.jsx 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. import React, { useState, useEffect, useCallback, useRef } from "react";
  2. import { useHistory } from "react-router-dom";
  3. import PropTypes from "prop-types";
  4. import styles from "./style.less";
  5. import Navigator from "./component/navigator/view.jsx";
  6. import Top from "./component/top/view.jsx";
  7. import ModelMsg from "./component/modelMsg/view.jsx";
  8. import BreadcrumbView from "./component/breadcrumb/view";
  9. import TipMsg from "./component/tipMsg/view.jsx";
  10. import $store from "@store/";
  11. import {
  12. Dropdown,
  13. Menu,
  14. message,
  15. Button,
  16. Form,
  17. Modal,
  18. Tabs,
  19. Input,
  20. } from "antd";
  21. import DefaultImg from "@components/defaultImg/view.jsx";
  22. import {
  23. MenuUnfoldOutlined,
  24. MenuFoldOutlined,
  25. AreaChartOutlined,
  26. PieChartOutlined,
  27. BarChartOutlined,
  28. DotChartOutlined,
  29. LineChartOutlined,
  30. RadarChartOutlined,
  31. HeatMapOutlined,
  32. FallOutlined,
  33. RiseOutlined,
  34. StockOutlined,
  35. BoxPlotOutlined,
  36. FundOutlined,
  37. SlidersOutlined,
  38. DatabaseOutlined,
  39. DollarOutlined,
  40. ControlOutlined,
  41. CodeOutlined,
  42. BarsOutlined,
  43. AppstoreAddOutlined,
  44. ApartmentOutlined,
  45. InfoCircleOutlined,
  46. StarOutlined,
  47. StarFilled,
  48. } from "@ant-design/icons";
  49. import {
  50. getDmpAccessUrl,
  51. getFineBiToken,
  52. getValueByDictCode,
  53. getPreFineBiUrl,
  54. getSunwayAccessUrl,
  55. } from "./component/top/api";
  56. import { dealDiffSheetType, crossMenuClick } from "@utils/util";
  57. import utils from "@utils/index";
  58. import "@themes/themes.less";
  59. import { saveMenu } from "@apis/enter.js";
  60. import { careOrCancelResource, getUserResourceTree } from "./api";
  61. import { observer, observable } from "mobx-react";
  62. import { toJS } from "mobx";
  63. const { SubMenu } = Menu;
  64. const { TabPane } = Tabs;
  65. // Frame.propTypes = {
  66. // child: PropTypes.object,
  67. // };
  68. let keys = [];
  69. let attrs = {
  70. style: { color: "#c7c7c7", fontSize: 13 },
  71. };
  72. const iconObj = {
  73. AreaChartOutlined: <AreaChartOutlined {...attrs} />,
  74. PieChartOutlined: <PieChartOutlined {...attrs} />,
  75. BarChartOutlined: <BarChartOutlined {...attrs} />,
  76. DotChartOutlined: <DotChartOutlined {...attrs} />,
  77. LineChartOutlined: <DotChartOutlined {...attrs} />,
  78. RadarChartOutlined: <RadarChartOutlined {...attrs} />,
  79. HeatMapOutlined: <HeatMapOutlined {...attrs} />,
  80. FallOutlined: <FallOutlined {...attrs} />,
  81. RiseOutlined: <RiseOutlined {...attrs} />,
  82. StockOutlined: <StockOutlined {...attrs} />,
  83. BoxPlotOutlined: <BoxPlotOutlined {...attrs} />,
  84. FundOutlined: <FundOutlined {...attrs} />,
  85. SlidersOutlined: <SlidersOutlined {...attrs} />,
  86. DatabaseOutlined: <DatabaseOutlined {...attrs} />,
  87. DollarOutlined: <DollarOutlined {...attrs} />,
  88. ControlOutlined: <ControlOutlined {...attrs} />,
  89. CodeOutlined: <CodeOutlined {...attrs} />,
  90. BarsOutlined: <BarsOutlined {...attrs} />,
  91. AppstoreAddOutlined: <AppstoreAddOutlined {...attrs} />,
  92. ApartmentOutlined: <ApartmentOutlined {...attrs} />,
  93. };
  94. const layout = {
  95. labelCol: { span: 4 },
  96. wrapperCol: { span: 16 },
  97. };
  98. const formItemLayout = {
  99. labelCol: {
  100. span: 5,
  101. },
  102. wrapperCol: {
  103. span: 18,
  104. },
  105. };
  106. let leafNode = {
  107. // nodeId: {num, parentIds}
  108. };
  109. const findLeaves = (tree = []) => {
  110. function loop(list, parentIds = []) {
  111. list.map((item) => {
  112. // 新建当前ID的键值对
  113. if ((item.resourceList || []).length > 0) {
  114. loop(item.resourceList, parentIds.concat([item.resourceId]));
  115. } else {
  116. leafNode[item.resourceId] = {
  117. name: item.resourceName,
  118. id: item.resourceId,
  119. parentIds,
  120. };
  121. }
  122. });
  123. }
  124. loop(tree, []);
  125. };
  126. let sVal = "";
  127. export default observer(function Frame(props) {
  128. const [searchVal, setSearchVal] = useState(""); /**搜索关键词内容 */
  129. const [collapsed, setCollapsed] = useState(false);
  130. const [leftMenuHeight, setleftMenuHeight] = useState("100%");
  131. const [leftMenuWidth, setleftMenuWidth] = useState(220);
  132. const [modelMsgs, setModelMsgs] = useState({});
  133. const [tipMsgs, setTipMsgs] = useState({});
  134. const history = useHistory();
  135. const [curKey, setKey] = useState("1");
  136. const moveBar = useRef();
  137. const $search = useRef();
  138. const leftMenu = useRef();
  139. const [isMove, setisMove] = useState(false);
  140. const { Search } = Input;
  141. let showIds = $store.app.showIds;
  142. function calcValue(str) {
  143. if (str === "sysToken") {
  144. return `${sessionStorage.getItem("token")}$`;
  145. }
  146. }
  147. document.onmousemove = function (e) {
  148. //是否为可移动状态
  149. if (isMove) {
  150. let e = e || window.event;
  151. let moveX = e.clientX; //得到距离左边移动距离
  152. if (moveX < 44) {
  153. moveX = 44;
  154. } else if (moveX > 800) {
  155. moveX = 800;
  156. }
  157. setleftMenuWidth(moveX);
  158. } else {
  159. return;
  160. }
  161. };
  162. document.onmouseup = () => {
  163. setisMove(false);
  164. };
  165. const stopLeftMenu = () => {
  166. setisMove(false);
  167. };
  168. const moveLeftMenu = () => {
  169. setisMove(true);
  170. };
  171. const handleClick = (data) => {
  172. let { key } = data;
  173. let item = JSON.parse(key || "{}");
  174. if (item.openType === "close") {
  175. message.destroy();
  176. return message.warning("该菜单暂未开放");
  177. }
  178. modelMsgs.isShow(item.resourceId, item.resourceName,item);
  179. $store.app.setNavList({
  180. name: item.resourceName,
  181. path: item.resourceUrl,
  182. type: item.resourceType,
  183. openType: item.openType,
  184. id: item.resourceId,
  185. });
  186. $store.app.setCurNav(item.resourceUrl);
  187. sessionStorage.setItem("curNodeId", item.resourceId);
  188. // sessionStorage.setItem("jumpType", item.props.type);
  189. dealDiffSheetType(item).then((response) => {
  190. if (response.type === "sys") {
  191. history.push(response.link);
  192. } else {
  193. history.push(`/home/outer/${response.activeItem.resourceId}`);
  194. }
  195. });
  196. saveMenu(item);
  197. };
  198. /**打开 报表目录 */
  199. const openReportDire = (key) => {
  200. let activePath = `/home/directory/${key}`;
  201. let navObj = {
  202. name: sessionStorage.getItem("resourceName"),
  203. path: activePath,
  204. type: "sys",
  205. openType: "self",
  206. id: key,
  207. };
  208. // $store.app.setNavList(navObj);
  209. // $store.app.setCurNav(activePath);
  210. // history.push(activePath);
  211. };
  212. function callback(key) {
  213. return setKey(key);
  214. }
  215. const onResize = useCallback(() => {
  216. setleftMenuHeight(document.documentElement.clientHeight - 82 + "px");
  217. }, []);
  218. const onResize_pop = useCallback(() => {
  219. }, []);
  220. useEffect(() => {
  221. setSearchVal("");
  222. leafNode = {};
  223. $store.app.setShowIds([]);
  224. // showIds = [];
  225. setleftMenuHeight(document.documentElement.clientHeight - 82 + "px");
  226. window.addEventListener("resize", onResize);
  227. findLeaves($store.sysMenu.submenuList);
  228. return () => {
  229. window.removeEventListener("resize", onResize);
  230. window.removeEventListener("popstate", onResize_pop);
  231. };
  232. }, [$store.app.refresh]);
  233. function loopMenu(list) {
  234. if(!$store.app.curNav){$store.app.curNav = ""}
  235. return list.map((menu, index) => {
  236. if (menu.resourceType !== "module_menu" && menu.resourceList.length > 0) {
  237. return (
  238. <SubMenu
  239. key={`${menu.resourceId}Sub`}
  240. title={menu.resourceName}
  241. icon={iconObj[menu.resourceIcon]}
  242. className={`normal_menu ${menu.resourceUrl === $store.app.curNav || $store.app.curNav.indexOf('/'+menu.resourceId) > -1 ? "click_active" : ""
  243. }`}
  244. onTitleClick={(val, domEvent) => {
  245. let titleKey = val.key.slice(
  246. 0,
  247. val.key.length - 3
  248. ); /**侧边父级id */
  249. let activeUrl = $store.app.activedUrl;
  250. sessionStorage.setItem("resourceName", menu.resourceName);
  251. if (
  252. activeUrl.indexOf("/home/outer") > -1 ||
  253. activeUrl === "/home/report" ||
  254. activeUrl === "/home/write"
  255. ) {
  256. openReportDire(titleKey);
  257. }
  258. }}
  259. // style={{ backgroundColor: "#031646" }}
  260. >
  261. {loopMenu(menu.resourceList)}
  262. </SubMenu>
  263. );
  264. } else {
  265. return (
  266. <>
  267. <Menu.Item
  268. key={JSON.stringify(menu)}
  269. icon={iconObj[menu.resourceIcon]}
  270. className={`${menu.resourceUrl === $store.app.curNav || $store.app.curNav.indexOf('/'+menu.resourceId) > -1
  271. ? "click_active"
  272. : "normal_menu"
  273. }`}
  274. // style={{ backgroundColor: "#031646" }}
  275. >
  276. <span>
  277. <span className="text_over" title={menu.resourceName}>
  278. {menu.resourceName}
  279. </span>
  280. {menu.resourceType.match(/fine_bi|dmpReport|report|yonghong/) && (
  281. <>
  282. {/* <span
  283. style={{ paddingLeft: 5 }}
  284. onClick={(e) => {
  285. e.stopPropagation();
  286. getMenuDesc({
  287. resourceId: menu.resourceId,
  288. }).then(({ data, resultCode }) => {
  289. if (+resultCode === 0) {
  290. $store.app.setMetaData({
  291. data,
  292. visible: true,
  293. });
  294. }
  295. });
  296. }}
  297. >
  298. <InfoCircleOutlined />
  299. </span> */}
  300. <span
  301. className={menu.isCare ? "care_color" : "emptystar"}
  302. twotonecolor ="#FFBF00"
  303. style={{ paddingLeft: 5 }}
  304. onClick={(e) => {
  305. menu.isCare = !menu.isCare;
  306. $store.sysMenu.setSubmenuList(
  307. $store.sysMenu.submenuList
  308. );
  309. sessionStorage.setItem(
  310. "subMenuList",
  311. JSON.stringify($store.sysMenu.submenuList)
  312. );
  313. const config = {
  314. isCare: menu.isCare,
  315. resourceId: menu.resourceId,
  316. };
  317. careOrCancelResource(config).then(
  318. ({ data, resultCode }) => {
  319. if (+resultCode === 0) {
  320. message.success(
  321. menu.isCare ? "关注成功" : "取消关注成功"
  322. );
  323. //重新发送请求
  324. let subMenuList = JSON.parse(
  325. sessionStorage.getItem("subMenuList")
  326. );
  327. subMenuList.filter((item) => {
  328. if (item.resourceId === menu.resourceId) {
  329. }
  330. });
  331. }
  332. }
  333. );
  334. e.stopPropagation();
  335. }}
  336. >
  337. {menu.isCare ? <StarFilled /> : <StarOutlined />}
  338. </span>
  339. </>
  340. )}
  341. </span>
  342. </Menu.Item>
  343. </>
  344. );
  345. }
  346. });
  347. }
  348. function loopMenu2(list) {
  349. // console.log("showIds==", [...showIds]);
  350. return list.map((menu, index) => {
  351. if (showIds.indexOf(menu.resourceId) === -1) {
  352. return null;
  353. }
  354. if (menu.resourceList.length > 0) {
  355. return (
  356. <SubMenu
  357. key={`${menu.resourceId}Sub`}
  358. title={menu.resourceName}
  359. icon={iconObj[menu.resourceIcon]}
  360. className={`normal_menu ${menu.resourceUrl === $store.app.curNav ? "click_active" : ""
  361. }`}
  362. onTitleClick={(val, domEvent) => {
  363. let titleKey = val.key.slice(
  364. 0,
  365. val.key.length - 3
  366. ); /**侧边父级id */
  367. let activeUrl = $store.app.activedUrl;
  368. sessionStorage.setItem("resourceName", menu.resourceName);
  369. if (
  370. activeUrl.indexOf("/home/outer") > -1 ||
  371. activeUrl === "/home/report" ||
  372. activeUrl === "/home/write"
  373. ) {
  374. openReportDire(titleKey);
  375. }
  376. }}
  377. // style={{ backgroundColor: "#031646" }}
  378. >
  379. {loopMenu2(menu.resourceList)}
  380. </SubMenu>
  381. );
  382. } else {
  383. return (
  384. <>
  385. <Menu.Item
  386. key={JSON.stringify(menu)}
  387. icon={iconObj[menu.resourceIcon]}
  388. className={`${menu.resourceUrl === $store.app.curNav
  389. ? "click_active"
  390. : "normal_menu"
  391. }`}
  392. // style={{ backgroundColor: "#031646" }}
  393. >
  394. <span>
  395. <span className="text_over" title={menu.resourceName}>
  396. {menu.resourceName}
  397. </span>
  398. </span>
  399. </Menu.Item>
  400. </>
  401. );
  402. }
  403. });
  404. }
  405. const onRef = (ref) => {
  406. setModelMsgs(ref);
  407. };
  408. const getTips = () => {
  409. tipMsgs.getTip()
  410. };
  411. const cleatTips = () => {
  412. tipMsgs.cleatTips()
  413. };
  414. const onRef2 = (ref) => {
  415. setTipMsgs(ref);
  416. console.log(tipMsgs,"tipMsgs")
  417. };
  418. return (
  419. <div className={styles.frame}>
  420. <Top />
  421. <ModelMsg onRef={onRef} getTips={getTips} cleatTips={cleatTips}/>
  422. {/* 断网或超时显示提示 */}
  423. {/* <div className="nowifi-tip">当前网络状态不佳</div> */}
  424. {/* 正文 */}
  425. <div style={{ display: "flex", height: '100%' }}>
  426. {$store.sysMenu.submenuList.length > 0 && !collapsed && (
  427. <div
  428. className="movebar"
  429. style={{ left: leftMenuWidth }}
  430. ref={moveBar}
  431. onMouseDown={moveLeftMenu}
  432. onMouseUp={stopLeftMenu}
  433. ></div>
  434. )}
  435. {isMove && <div className="markmore"></div>}
  436. <div
  437. className={"body_box homePage"}
  438. >
  439. <Navigator
  440. style={{
  441. display:"none",
  442. }}
  443. />
  444. <TipMsg onRef={onRef2}></TipMsg>
  445. {$store.app.navList.length === 0 && false &&
  446. !history.location.pathname.match(/index|work|center|clush/) ? (
  447. <DefaultImg />
  448. ) : (
  449. props.child && props.child
  450. )}
  451. </div>
  452. </div>
  453. {/* 元数据展示 */}
  454. <Modal
  455. title="报表元数据"
  456. visible={$store.app.metaData.visible}
  457. width="665px"
  458. onCancel={() => {
  459. $store.app.setMetaData({
  460. visible: false,
  461. });
  462. }}
  463. footer={null}
  464. >
  465. <Form {...layout}>
  466. <Tabs defaultActiveKey="0" onChange={callback}>
  467. <TabPane tab="基础信息" key="0">
  468. <Form.Item name="remark" label="报表描述" {...formItemLayout}>
  469. <span>{$store.app.metaData.data.remark}</span>
  470. </Form.Item>
  471. <Form.Item name="department" label="责任部门" {...formItemLayout}>
  472. <span>{$store.app.metaData.data.departmentInfo}</span>
  473. </Form.Item>
  474. <Form.Item name="charger" label="资产责任人" {...formItemLayout}>
  475. <span>{$store.app.metaData.data.charger}</span>
  476. </Form.Item>
  477. <Form.Item name="itManager" label="IT经理" {...formItemLayout}>
  478. <span>{$store.app.metaData.data.itManager}</span>
  479. </Form.Item>
  480. <Form.Item name="itDeveloper" label="IT研发" {...formItemLayout}>
  481. <span>{$store.app.metaData.data.itDeveloper}</span>
  482. </Form.Item>
  483. </TabPane>
  484. <TabPane tab="资产信息" key="1">
  485. <Form.Item name="dataFrom" label="数据来源" {...formItemLayout}>
  486. <span>{$store.app.metaData.data.dataFrom}</span>
  487. </Form.Item>
  488. <Form.Item
  489. name="updateFrequency"
  490. label="数据更新频率"
  491. {...formItemLayout}
  492. >
  493. <span>{$store.app.metaData.data.updateFrequency}</span>
  494. </Form.Item>
  495. <Form.Item name="businessFormat" label="业态" {...formItemLayout}>
  496. <span>{$store.app.metaData.data.businessFormat}</span>
  497. </Form.Item>
  498. <Form.Item name="module" label="业务模块" {...formItemLayout}>
  499. <span>{$store.app.metaData.data.module}</span>
  500. </Form.Item>
  501. <Form.Item
  502. name="sonModule"
  503. label="业务子模块"
  504. {...formItemLayout}
  505. >
  506. <span>{$store.app.metaData.data.sonModule}</span>
  507. </Form.Item>
  508. <Form.Item name="assetType" label="资产类型" {...formItemLayout}>
  509. <span>{$store.app.metaData.data.assetType}</span>
  510. </Form.Item>
  511. <Form.Item name="assetLevel" label="资产密级" {...formItemLayout}>
  512. <span>{$store.app.metaData.data.assetLevel}</span>
  513. </Form.Item>
  514. </TabPane>
  515. </Tabs>
  516. </Form>
  517. </Modal>
  518. </div>
  519. );
  520. });