rect.vue 3.6 KB

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