index.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. import React, { useState, useEffect } from 'react';
  2. import { message } from 'antd';
  3. import menuStyle from './moduleMenuStyle.less';
  4. import { connect } from 'umi';
  5. // import {
  6. // UnityAction,
  7. // getGlobalData,
  8. // setGlobalData,
  9. // } from '@/utils/utils';
  10. // import router from 'umi/router';
  11. // import {
  12. // platformPageConfig,
  13. // BuildNodeCode,
  14. // OpsNodeCode,
  15. // } from '@/utils/constants';
  16. const noIcon = require('@/Project/assets/platformMenu/noIcon.png');
  17. const newIcon = require('@/Project/assets/platformMenu/ICON/newModel.png');
  18. function PlatformMenu(props) {
  19. const {
  20. dispatch,
  21. access,
  22. initState,
  23. // location: { query = {} },
  24. } = props;
  25. console.log(props);
  26. let query = {};
  27. const [curMenu, setCurMenu] = useState([]);
  28. useEffect(() => {
  29. dispatch({
  30. type: 'menu/getPlatformMenu',
  31. callback: (menus) => {
  32. initMenu(menus);
  33. },
  34. payload: { version: 2 },
  35. });
  36. // dispatch({
  37. // type: 'user/fetchCurrent',
  38. // });
  39. }, []);
  40. const getIcon = (item) => {
  41. if (item.active && item.Icon) return item.Icon;
  42. let current = find((icon) => icon.code === item.Code)?.iconPath;
  43. if (current) return current;
  44. return newIcon;
  45. };
  46. const initMenu = (menus) => {
  47. console.log(access);
  48. let newMenus = menus.filter((item) => {
  49. if (item.Type == 1 && access[item.Code]) {
  50. item.name = item.Name;
  51. item.active =
  52. item.children != undefined ||
  53. item.WebPath != '' ||
  54. item.UnityPath != '';
  55. item.iconPath = getIcon(item);
  56. return item;
  57. }
  58. });
  59. newMenus.push({
  60. name: '新增功能',
  61. ID: '新增功能',
  62. Code: '',
  63. Type: 1,
  64. iconPath: require('@/Project/assets/platformMenu/ICON/newModel.png'),
  65. WebPath: '',
  66. UnityPath: '',
  67. active: false,
  68. });
  69. setCurMenu(newMenus);
  70. };
  71. const initMenu1 = (parent, permission) => {
  72. console.log(parent, permission);
  73. if (parent?.children) {
  74. let menu = parent.children;
  75. for (let i = 0; i < menu.length; i++) {
  76. let element = menu[i];
  77. if (element.Type != 1 || !permission[element.Code]) {
  78. menu.splice(i, 1);
  79. i--; //i
  80. continue;
  81. }
  82. element.name = element.Name;
  83. element.iconPath = element.Icon || noIcon;
  84. element.active =
  85. element.children != undefined ||
  86. element.WebPath != '' ||
  87. element.UnityPath != '';
  88. if (!element.active) continue;
  89. }
  90. menu = menu.concat([
  91. {
  92. name: '新增功能',
  93. ID: '新增功能',
  94. Code: '',
  95. Type: 1,
  96. iconPath: require('@/Project/assets/platformMenu/newModel.png'),
  97. WebPath: '',
  98. UnityPath: '',
  99. active: false,
  100. },
  101. ]);
  102. setCurMenu(menu);
  103. }
  104. };
  105. const handleMenuClick = (element) => {
  106. if (element.Name == '运营平台' || element.Name == '建设平台') {
  107. if (query.unity == undefined) {
  108. message.error('请使用客户端进入');
  109. return;
  110. }
  111. const subModule = element.Name == '运营平台' ? 2 : 1;
  112. // const forbiddenModel = getGlobalData('forbiddenModel');
  113. // 设置全局变量
  114. // setGlobalData('curApp', subModule);
  115. // UnityAction.sendMsg('EnterApp', element.Code);
  116. // PageAction.sendMsg('HTML_changePage', {
  117. // code: 'projectSelect',
  118. // urlParams: {
  119. // subModule,
  120. // forbiddenModel,
  121. // },
  122. // });
  123. // PageAction.sendMsg('HTML_changeState', {
  124. // curMenu: null,
  125. // });
  126. } else {
  127. //网页端跳转页面
  128. if (query.unity == undefined) {
  129. let curHref = window.location.href;
  130. let sign = '?';
  131. if (curHref.indexOf('?') != -1) {
  132. sign = '&';
  133. }
  134. if (element.WebPath == undefined) return;
  135. let isUrl =
  136. element.WebPath.indexOf('http') != -1 ||
  137. element.WebPath.indexOf('https') != -1;
  138. // console.log(isUrl);
  139. if (isUrl)
  140. window.location.href =
  141. element.WebPath + sign + 'JWT-TOKEN=' + localStorage['JWT-TOKEN'];
  142. } else {
  143. // UnityAction.sendMsg('EnterApp', element.Code);
  144. }
  145. }
  146. };
  147. const grayIcon = [
  148. {
  149. code: 'func-01-point-bom',
  150. iconPath: require('@/Project/assets/platformMenu/ICON/func-01-point-bom.png'),
  151. name: 'BOM清单',
  152. },
  153. {
  154. code: 'func-01-build',
  155. iconPath: require('@/Project/assets/platformMenu/ICON/func-01-build.png'),
  156. name: '建设平台',
  157. },
  158. {
  159. code: 'func-01-ops',
  160. iconPath: require('@/Project/assets/platformMenu/ICON/func-01-ops.png'),
  161. name: '运营平台',
  162. },
  163. {
  164. code: 'func-06-ManDay',
  165. iconPath: require('@/Project/assets/platformMenu/ICON/func-06-ManDay.png'),
  166. name: '人日系统',
  167. },
  168. {
  169. code: 'func-06-globalCockpit',
  170. iconPath: require('@/Project/assets/platformMenu/ICON/func-06-globalCockpit.png'),
  171. name: '全局驾驶舱',
  172. },
  173. {
  174. code: 'func-01-DirectDrinking',
  175. iconPath: require('@/Project/assets/platformMenu/ICON/func-01-DirectDrinking.png'),
  176. name: '直饮水平台',
  177. },
  178. {
  179. code: '',
  180. iconPath: require('@/Project/assets/platformMenu/ICON/newModel.png'),
  181. name: '新增功能',
  182. },
  183. ];
  184. const getProjectSelectionUrl = (subModule) => {
  185. // TODO 获取全局变量forbiddenModel
  186. // const forbiddenModel = getGlobalData('forbiddenModel');
  187. // return `#/smart-water/platform/projectSelect?subModule=${subModule}&forbiddenModel=${forbiddenModel}`;
  188. };
  189. // return <Menu onClickMenu={menu => handleMenuClick(menu)} menuData={curMenu}></Menu>;
  190. return (
  191. <div className={menuStyle.background}>
  192. <div className={menuStyle.menuContent}>
  193. <div className={menuStyle.wrap}>
  194. {curMenu.map((item) => (
  195. <div className={menuStyle.item}>
  196. <div
  197. onClick={() => handleMenuClick(item)}
  198. className={menuStyle.menu}
  199. style={item.active ? null : { cursor: 'not-allowed' }}
  200. >
  201. <img
  202. className={menuStyle.pic}
  203. src={item.iconPath}
  204. style={item.active ? {} : { cursor: 'not-allowed' }}
  205. />
  206. </div>
  207. <div
  208. style={{
  209. marginTop: '22px',
  210. width: '152px',
  211. textAlign: 'center',
  212. }}
  213. >
  214. <span
  215. onClick={() => item.click?.(item)}
  216. className={menuStyle.menuFriName}
  217. style={
  218. item.active
  219. ? {}
  220. : { color: '#6081B2', cursor: 'not-allowed' }
  221. }
  222. >
  223. {item.name}
  224. </span>
  225. </div>
  226. </div>
  227. ))}
  228. </div>
  229. </div>
  230. </div>
  231. );
  232. }
  233. export default connect(({ loading }) => ({
  234. // waterMenuData: menu.waterMenuData,
  235. // loading: loading.models.menu,
  236. // currentUser: user.currentUser,
  237. // Permission: user.currentUser.Permission,
  238. }))(PlatformMenu);