rect.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <template>
  2. <div style="margin-top: 10px;">
  3. <el-button size="small" @click="changeEnable">切换item1禁用状态</el-button>
  4. 圆角半径 :
  5. <el-input-number @change="changeY" v-model="R" size="mini" style="width: 100px"></el-input-number>
  6. <canvas :id="id" width="740" height="400"/>
  7. </div>
  8. </template>
  9. <script lang="ts">
  10. import { SGraphRectItem, SGraphScene, SGraphView } from "@persagy-web/graph/lib";
  11. import { Component, Vue } from "vue-property-decorator";
  12. @Component
  13. export default class RectCanvas extends Vue {
  14. id: string = 'rect' + Date.now();
  15. view: SGraphView | undefined;
  16. item: SGraphRectItem | undefined;
  17. item2: SGraphRectItem | undefined;
  18. R: number = 0;
  19. rectData = {
  20. x: 0,
  21. y: 0,
  22. width: 500,
  23. height: 500,
  24. radius: 0,
  25. style: {
  26. "default": {
  27. "stroke": "#cccccc",
  28. "fill": "SLinearGradient{0,0;0,1000;0,#ff483bff;0.5,#04ff00ff;1,#3d4effff;}",
  29. "lineWidth": 2,
  30. "effect": {}
  31. },
  32. "selected": {
  33. "stroke": "#66ff66",
  34. "fill": "SRadialGradient{500,500,50;500,500,500;0,#ff483bff;0.5,#04ff00ff;1,#3d4effff;}",
  35. "lineWidth": 3,
  36. "effect": {}
  37. },
  38. "disabled": {
  39. "stroke": "#333333",
  40. "fill": "#afafaf",
  41. "lineWidth": 1,
  42. "effect": {}
  43. },
  44. }
  45. };
  46. rectData2 = {
  47. x: 1000,
  48. y: 0,
  49. width: 500,
  50. height: 500,
  51. radius: 0,
  52. style: {
  53. "default": {
  54. "stroke": "#cccccc",
  55. "fill": "#ffccee",
  56. "lineWidth": 2,
  57. "effect": {}
  58. },
  59. "selected": {
  60. "stroke": "#66ff66",
  61. "fill": "#ff33ee",
  62. "lineWidth": 3,
  63. "effect": {}
  64. },
  65. "disabled": {
  66. "stroke": "#333333",
  67. "fill": "#afafaf",
  68. "lineWidth": 1,
  69. "effect": {}
  70. },
  71. }
  72. };
  73. private mounted(): void {
  74. this.init();
  75. }
  76. init(): void {
  77. this.view = new SGraphView(this.id);
  78. const scene = new SGraphScene();
  79. this.item = new SGraphRectItem(null, this.rectData);
  80. this.item.selectable = true;
  81. this.item._resizeable = false;
  82. scene.addItem(this.item);
  83. this.item2 = new SGraphRectItem(null, this.rectData2);
  84. this.item2.selectable = true;
  85. this.item2._resizeable = false;
  86. scene.addItem(this.item2);
  87. this.view.scene = scene;
  88. this.view.fitSceneToView();
  89. this.view.scalable = false;
  90. }
  91. changeEnable(): void {
  92. if (this.item) {
  93. this.item.enabled = !this.item.enabled;
  94. }
  95. }
  96. // 修改圆角半径
  97. changeY(val: number): void {
  98. if (this.item) {
  99. this.item.radius = val;
  100. }
  101. if (this.item2) {
  102. this.item2.radius = val;
  103. }
  104. }
  105. }
  106. </script>
  107. <style scoped>
  108. </style>