物管理前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

289 lines
10 KiB

  1. import { useFetch } from '@/hooks/fetch';
  2. import { IObject } from '@/types/interface';
  3. import moment from 'moment';
  4. import dragStretchService from '@/service/dragStretchService';
  5. export const pathStyle = {
  6. show: 'cursor:pointer;fill:#2a9bdd;stroke:#2a9bdd;stroke-width:0.26458333;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-dasharray:none;fill-opacity:0.38039216',
  7. hide: 'cursor:pointer;opacity: 0;',
  8. };
  9. const reset = (state: IObject) => {
  10. if (state.dragStretch) {
  11. state.dragStretch.reset();
  12. }
  13. };
  14. const pathMap: IObject = {
  15. path4830: {
  16. data: [
  17. { code: 'G06', key: 'A29' },
  18. { code: 'B_V0000151_27', key: 'B2' },
  19. ],
  20. },
  21. path4770: {
  22. data: [
  23. { code: 'A_016', key: 'A29' },
  24. { code: 'B_V0000151_21', key: 'B2' },
  25. { code: 'E_V0000151_5', key: 'E3' },
  26. { code: 'D_V0000151_2', key: 'D2' },
  27. ],
  28. },
  29. path4766: {},
  30. path7032: {
  31. data: [{ code: 'B_V0000151_11', key: 'B2' }],
  32. },
  33. path4666: {},
  34. path3938: {},
  35. path3936: {
  36. data: [{ code: 'B_V0000151_15', key: 'B2' }],
  37. },
  38. path3102: {
  39. data: [
  40. { code: 'A_009', key: 'A29' },
  41. { code: 'B_V0000151_16', key: 'B2' },
  42. { code: 'E_V0000151_6', key: 'E3' },
  43. { code: 'D_V0000151_4', key: 'D2' },
  44. ],
  45. },
  46. path3934: {
  47. data: [
  48. { code: 'G04', key: 'A29' },
  49. { code: 'B_V0000151_23', key: 'B2' },
  50. ],
  51. },
  52. path3932: {
  53. data: [
  54. { code: 'A_019', key: 'A29' },
  55. { code: 'E_11004151_1', key: 'E3' },
  56. ],
  57. },
  58. path3100: {
  59. data: [
  60. { code: 'A_010', key: 'A29' },
  61. { code: 'B_V0000151_26', key: 'B2' },
  62. { code: 'E_V0000151_7', key: 'E3' },
  63. { code: 'D_V0000151_3', key: 'D2' },
  64. ],
  65. },
  66. path7030: {
  67. data: [{ code: 'B_V0000151_12', key: 'B2' }],
  68. },
  69. path4768: {
  70. data: [
  71. { code: 'A_005', key: 'A29' },
  72. { code: 'B_V0000151_25', key: 'B2' },
  73. ],
  74. },
  75. path7028: {
  76. data: [{ code: 'B_V0000151_17', key: 'B2' }],
  77. },
  78. path6300: {
  79. data: [
  80. { code: 'A_021', key: 'A29' },
  81. { code: 'E_11004154_1', key: 'E3' },
  82. ],
  83. codes: ['A_021', 'E_11004154_1'],
  84. },
  85. path6298: {
  86. data: [
  87. { code: 'G05', key: 'A29' },
  88. { code: 'B_V0000151_19', key: 'B2' },
  89. ],
  90. },
  91. path6296: {},
  92. path6294: {
  93. data: [{ code: 'A_007', key: 'A29' }],
  94. },
  95. path6292: {
  96. data: [
  97. { code: 'B_V0000151_13', key: 'B2' },
  98. { code: 'E_11004154_2', key: 'E3' },
  99. ],
  100. },
  101. path5564: {
  102. data: [{ code: 'A_020', key: 'A29' }],
  103. },
  104. path5558: {},
  105. path5562: {},
  106. };
  107. const animateMap: IObject = {
  108. 'layer-d-animate': `<animate href="#path7592" attributeName="stroke-dashoffset" dur="15s" to="0" fill="freeze"></animate>
  109. <animate href="#path7592-3" attributeName="stroke-dashoffset" dur="15s" to="0" fill="freeze"></animate> <animate href="#path9046" attributeName="stroke-dashoffset" begin="0.6s" dur="15s" to="0" fill="freeze"></animate>
  110. <animate href="#path9046-1" attributeName="stroke-dashoffset" begin="0.6s" dur="15s" to="0" fill="freeze"></animate><animate href="#path18869" attributeName="stroke-dashoffset" begin="0.5s" dur="15s" to="0" fill="freeze"></animate>
  111. <animate href="#path18869-1" attributeName="stroke-dashoffset" begin="0.5s" dur="15s" to="0" fill="freeze"></animate>
  112. <animate href="#path9046-5" attributeName="stroke-dashoffset" begin="2s" dur="15s" to="0" fill="freeze"></animate>
  113. <animate href="#path9046-1-0" attributeName="stroke-dashoffset" begin="2s" dur="15s" to="0" fill="freeze"></animate><animate href="#path23350-62" attributeName="stroke-dashoffset" begin="1.22s" dur="15s" to="0" fill="freeze"></animate>
  114. <animate href="#path23350-6-2" attributeName="stroke-dashoffset" begin="1.22s" dur="15s" to="0" fill="freeze"></animate>
  115. <animate href="#path23326" attributeName="stroke-dashoffset" dur="3.8s" to="0" fill="freeze"></animate>
  116. <animate href="#path23326-1" attributeName="stroke-dashoffset" dur="3.8s" to="0" fill="freeze"></animate>
  117. <animate href="#path23350" attributeName="stroke-dashoffset" begin="1.42s" dur="25s" to="0" fill="freeze"></animate>
  118. <animate href="#path23350-6" attributeName="stroke-dashoffset" begin="1.42s" dur="25s" to="0" fill="freeze"></animate>
  119. <animate href="#path23374" attributeName="stroke-dashoffset" begin="2.8s" dur="15s" to="0" fill="freeze"></animate>
  120. <animate href="#path23374-0" attributeName="stroke-dashoffset" begin="2.8s" dur="15s" to="0" fill="freeze"></animate>
  121. <animate href="#path26736" attributeName="stroke-dashoffset" dur="2s" to="0" fill="freeze"></animate>
  122. <animate href="#path26736-9" attributeName="stroke-dashoffset" dur="2s" to="0" fill="freeze"></animate>
  123. <animate href="#path28441-0" attributeName="stroke-dashoffset" dur="2s" to="0" fill="freeze"></animate>
  124. <animate href="#path28441-8-9" attributeName="stroke-dashoffset" dur="2s" to="0" fill="freeze"></animate>
  125. <animate href="#path30063" attributeName="stroke-dashoffset" begin="0.5s" dur="2s" to="0" fill="freeze"></animate>
  126. <animate href="#path30063-0" attributeName="stroke-dashoffset" begin="0.5s" dur="2s" to="0" fill="freeze"></animate>
  127. <animate href="#path28441" attributeName="stroke-dashoffset" begin="0.5s" dur="2s" to="0" fill="freeze"></animate>
  128. <animate href="#path28441-8-9-2" attributeName="stroke-dashoffset" begin="0.5s" dur="2s" to="0" fill="freeze"></animate>
  129. <animate href="#path23264" attributeName="stroke-dashoffset" dur="15s" to="0" fill="freeze"></animate><animate href="#path23264-3" attributeName="stroke-dashoffset" dur="15s" to="0" fill="freeze"></animate>
  130. <animate href="#image31036-69" attributeName="display" dur="3.2s" from="none" to="block" fill="freeze"></animate>
  131. <animate href="#image31036-6" attributeName="display" dur="7.8s" from="none" to="block" fill="freeze"></animate>
  132. <animate href="#image31036-8" attributeName="display" dur="5s" from="none" to="block" fill="freeze"></animate>
  133. <animate href="#image31036-3" attributeName="display" dur="5s" from="none" to="block" fill="freeze"></animate>
  134. <animate href="#image31036-69-9" attributeName="display" dur="2.3s" from="none" to="block" fill="freeze"></animate>
  135. <animate href="#image31036-69-5" attributeName="display" dur="2.8s" from="none" to="block" fill="freeze"></animate>
  136. <animate href="#image31036-1" attributeName="display" dur="2s" from="none" to="block" fill="freeze"></animate>
  137. <animate href="#image31036-5112" attributeName="display" dur="3.4s" from="none" to="block" fill="freeze"></animate>
  138. <animate href="#image31036-5" attributeName="display" dur="2.4s" from="none" to="block" fill="freeze"></animate>
  139. `,
  140. };
  141. const pointerElec = { lineId: 'njhl-svg-elec' };
  142. const pointerWater = { lineId: 'njhl-svg-water' };
  143. const pointerGas = { lineId: 'njhl-svg-gas' };
  144. const pointerSteam = { lineId: 'njhl-svg-steam' };
  145. const pointerMap: IObject = {
  146. 'image31024-4': pointerElec,
  147. image31024: pointerElec, //电
  148. image4433: pointerWater,
  149. 'image4433-8': pointerWater,
  150. image8135: pointerSteam,
  151. 'image8135-9': pointerSteam,
  152. image12904: pointerGas,
  153. };
  154. const initToolTip = (state: IObject): any => {
  155. for (const key in pathMap) {
  156. const val = pathMap[key];
  157. if (!val.data) {
  158. continue;
  159. }
  160. const path = document.getElementById(key);
  161. if (path) {
  162. path.onmouseenter = () => {
  163. path.setAttribute('style', pathStyle.show);
  164. };
  165. path.onmouseleave = () => {
  166. path.setAttribute('style', pathStyle.hide);
  167. };
  168. path.onclick = (event: IObject) => {
  169. setToolTipStatus('flex');
  170. const { screenX, screenY } = event;
  171. const target = document.querySelector('.njhl-tool-tip');
  172. if (target) {
  173. useFetch('/board/build/data', {
  174. method: 'post',
  175. data: {
  176. datas: val.data,
  177. month: moment().format('YYYY-MM'),
  178. },
  179. cb: (res: any) => {
  180. state.toolTipData = res;
  181. },
  182. });
  183. target.style.left = screenX - 100 + 'px';
  184. target.style.top = screenY - 100 + 'px';
  185. }
  186. };
  187. }
  188. }
  189. };
  190. const pointerLineMap: IObject = { 'layer-d-animate': ['image31024-4', 'image31024'] };
  191. const setPointerLineStatus = (target: HTMLElement, status: string): void => {
  192. if (target) {
  193. target.style.display = status;
  194. }
  195. };
  196. export const setPointerLineStatusAll = (status: string): void => {
  197. for (const key in pointerMap) {
  198. const item = pointerMap[key];
  199. const target = document.getElementById(item.lineId) as HTMLElement;
  200. setPointerLineStatus(target, status);
  201. }
  202. };
  203. const initLine = (): any => {
  204. // for (const key in pointerLineMap) {
  205. // const ids = pointerLineMap[key];
  206. // for (const item of ids) {
  207. // const pointer = document.getElementById(item);
  208. // if (pointer) {
  209. // pointer.onclick = () => {
  210. // const v = animateMap[key];
  211. // const target = document.getElementById(key);
  212. // if (target) {
  213. // target.innerHTML = v;
  214. // const center = document.getElementById(".center");
  215. // if (center) {
  216. // const content = center.innerHTML;
  217. // center.innerHTML = "";
  218. // center.innerHTML = content;
  219. // }
  220. // }
  221. // };
  222. // }
  223. // }
  224. // }
  225. setPointerLineStatusAll('none');
  226. for (const key in pointerMap) {
  227. const target = document.getElementById(key);
  228. const item = pointerMap[key];
  229. if (target) {
  230. target.onclick = () => {
  231. setPointerLineStatusAll('none');
  232. const t = document.getElementById(item.lineId) as HTMLElement;
  233. setPointerLineStatus(t, 'block');
  234. };
  235. }
  236. }
  237. };
  238. const getToolTipCloseElement = (): HTMLElement => {
  239. return document.querySelector('.njhl-tool-tip .title .close');
  240. };
  241. const getToolTipElement = (): HTMLElement => {
  242. return document.querySelector('.njhl-tool-tip');
  243. };
  244. const setToolTipStatus = (status: string): void => {
  245. const target = getToolTipElement();
  246. if (target) {
  247. target.style.display = status;
  248. }
  249. };
  250. const initCloseToolTip = (): void => {
  251. const target = getToolTipCloseElement();
  252. if (target) {
  253. target.onclick = () => {
  254. setToolTipStatus('none');
  255. };
  256. }
  257. };
  258. export const init = (state: IObject, target: HTMLElement): void => {
  259. initToolTip(state);
  260. initLine();
  261. initCloseToolTip();
  262. state.dragStretch = new dragStretchService(target, state.opt);
  263. };