rect.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. /**
  13. * 矩形&圆角矩形
  14. *
  15. * @author 郝洁 <haojie@persagy.com>
  16. */
  17. @Component
  18. export default class RectCanvas extends Vue {
  19. id: string = 'rect' + Date.now();
  20. view: SGraphView | undefined;
  21. item: SGraphRectItem | undefined;
  22. item2: SGraphRectItem | undefined;
  23. R: number = 0;
  24. rectData = {
  25. x: 0,
  26. y: 0,
  27. width: 500,
  28. height: 500,
  29. radius: 0,
  30. style: {
  31. "default": {
  32. "stroke": "#cccccc",
  33. "fill": "SLinearGradient{0,0;0,1000;0,#ff483bff;0.5,#04ff00ff;1,#3d4effff;}",
  34. "lineWidth": 2,
  35. "effect": {}
  36. },
  37. "selected": {
  38. "stroke": "#66ff66",
  39. "fill": "SRadialGradient{500,500,50;500,500,500;0,#ff483bff;0.5,#04ff00ff;1,#3d4effff;}",
  40. "lineWidth": 3,
  41. "effect": {}
  42. },
  43. "disabled": {
  44. "stroke": "#333333",
  45. "fill": "#afafaf",
  46. "lineWidth": 1,
  47. "effect": {}
  48. },
  49. }
  50. };
  51. rectData2 = {
  52. x: 1000,
  53. y: 0,
  54. width: 500,
  55. height: 500,
  56. radius: 0,
  57. style: {
  58. "default": {
  59. "stroke": "#cccccc",
  60. "fill": "#ffccee",
  61. "lineWidth": 2,
  62. "effect": {}
  63. },
  64. "selected": {
  65. "stroke": "#66ff66",
  66. "fill": "#ff33ee",
  67. "lineWidth": 3,
  68. "effect": {}
  69. },
  70. "disabled": {
  71. "stroke": "#333333",
  72. "fill": "#afafaf",
  73. "lineWidth": 1,
  74. "effect": {}
  75. },
  76. }
  77. };
  78. /**
  79. * 页面挂载
  80. */
  81. private mounted(): void {
  82. this.init();
  83. }
  84. init(): void {
  85. this.view = new SGraphView(this.id);
  86. const scene = new SGraphScene();
  87. this.item = new SGraphRectItem(null, this.rectData);
  88. this.item.selectable = true;
  89. this.item._resizeable = false;
  90. scene.addItem(this.item);
  91. this.item2 = new SGraphRectItem(null, this.rectData2);
  92. this.item2.selectable = true;
  93. this.item2._resizeable = false;
  94. scene.addItem(this.item2);
  95. this.view.scene = scene;
  96. this.view.fitSceneToView();
  97. this.view.scalable = false;
  98. }
  99. changeEnable(): void {
  100. if (this.item) {
  101. this.item.enabled = !this.item.enabled;
  102. }
  103. }
  104. // 修改圆角半径
  105. changeY(val: number): void {
  106. if (this.item) {
  107. this.item.radius = val;
  108. }
  109. if (this.item2) {
  110. this.item2.radius = val;
  111. }
  112. }
  113. }
  114. </script>
  115. <style scoped>
  116. </style>