selectContainer.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <template>
  2. <div>
  3. <canvas :id="id" width="740" height="400" tabindex="0"/>
  4. </div>
  5. </template>
  6. <script lang="ts">
  7. import { Component, Vue } from "vue-property-decorator";
  8. import { v1 as uuid } from "uuid";
  9. import { SGraphRectItem, SGraphScene, SGraphView } from "@persagy-web/graph/lib";
  10. import { SRect } from "@persagy-web/draw/lib";
  11. /**
  12. * 选择容器
  13. *
  14. * @author 郝洁 <haojie@persagy.com>
  15. */
  16. class ResizeRect extends SGraphRectItem {
  17. resize(oldSize: SRect, newSize: SRect): void {
  18. this.width = newSize.width;
  19. this.height = newSize.height;
  20. }
  21. }
  22. @Component
  23. export default class SelectContainerCanvas extends Vue {
  24. id: string = uuid();
  25. view: SGraphView | undefined;
  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. /**
  54. * 页面挂载
  55. */
  56. mounted(): void {
  57. this.init()
  58. };
  59. init(): void {
  60. this.view = new SGraphView(this.id);
  61. const scene = new SGraphScene();
  62. const item = new ResizeRect(null, this.rectData);
  63. scene.addItem(item);
  64. item.selectable = true;
  65. item.moveable = true;
  66. this.view.scene = scene;
  67. this.view.fitSceneToView();
  68. this.view.scalable = false;
  69. };
  70. }
  71. </script>
  72. <style scoped>
  73. </style>