FlowExtra.tsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import React from "react";
  2. import { Node } from "@antv/x6";
  3. import { Tooltip } from "antd";
  4. import linkConfig from "@/config/linkConfig";
  5. import { CorrelationType } from "@/enum";
  6. export default function FlowExtra({ node }: { node: Node }) {
  7. const { attrs } = node.getData();
  8. const enterpriseCode = sessionStorage.getItem("enterpriseCode");
  9. const token = localStorage.getItem("token_" + enterpriseCode);
  10. function objectToUrlParams(obj: Record<string, any>) {
  11. const params = new URLSearchParams();
  12. for (const [key, value] of Object.entries(obj)) {
  13. params.append(key, value);
  14. }
  15. return params.toString();
  16. }
  17. const linkTypeMap = {
  18. [CorrelationType.scene]: {
  19. name: "场景",
  20. url: linkConfig.scene,
  21. param: `#/${attrs?.linkValue?.value}`
  22. },
  23. [CorrelationType.flow]: {
  24. name: "流程",
  25. url: linkConfig.flow,
  26. param: `#/${attrs?.linkValue?.value}`
  27. },
  28. [CorrelationType.page]: {
  29. name: "页面",
  30. url: linkConfig.page,
  31. param: objectToUrlParams({
  32. token,
  33. pageId: attrs?.linkValue?.value
  34. })
  35. },
  36. [CorrelationType.table]: {
  37. name: "数据表",
  38. url: linkConfig.table,
  39. param: objectToUrlParams({
  40. id: attrs?.linkValue?.value,
  41. isSvg: true,
  42. type: 16
  43. })
  44. },
  45. [CorrelationType.view]: {
  46. name: "视图",
  47. url: linkConfig.view,
  48. param: objectToUrlParams({
  49. id: attrs?.linkValue?.value,
  50. isSvg: true,
  51. type: 16
  52. })
  53. },
  54. };
  55. const handleOpenLink = () => {
  56. const url = linkTypeMap[attrs.linkType as CorrelationType]?.url;
  57. const param = linkTypeMap[attrs.linkType as CorrelationType]?.param;
  58. if (!url) return;
  59. window.open(url + '?' + param, "_blank");
  60. }
  61. return (
  62. <div className="absolute w-50px h-30px bottom--20px right-0 text-14px">
  63. {attrs?.linkValue?.value && (
  64. <Tooltip
  65. title={`关联${linkTypeMap[attrs.linkType as CorrelationType].name}`}
  66. >
  67. <i className="iconfont icon-lianjie color-#239edd cursor-pointer text-16px absolute right-0px bottom-0px rotate-45deg" onClick={handleOpenLink}/>
  68. </Tooltip>
  69. )}
  70. </div>
  71. );
  72. }