PolylineItem.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <template>
  2. <div>
  3. <el-button size="mini" @click="init">清空画布,并初始化折线item</el-button>
  4. <el-button size="mini" @click="undo">undo</el-button>
  5. <el-button size="mini" @click="redo">redo</el-button>
  6. <canvas id="editPolyline" width="740" height="400" tabindex="0"></canvas>
  7. </div>
  8. </template>
  9. <script>
  10. import { SGraphScene, SGraphView } from "@persagy-web/graph/lib";
  11. import { SItemStatus, SPolylineItem } from "@persagy-web/big/lib";
  12. /**
  13. * 可编辑折线示例
  14. *
  15. * @author 郝洁 <haojie@persagy.com>
  16. */
  17. export default {
  18. name: "editPolyline",
  19. data() {
  20. return {
  21. scene: null,
  22. view: null,
  23. item: null,
  24. };
  25. },
  26. mounted() {
  27. this.view = new SGraphView("editPolyline");
  28. this.scene = new SGraphScene();
  29. this.view.scene = this.scene;
  30. this.init()
  31. },
  32. methods: {
  33. init() {
  34. this.scene.root.children = [];
  35. this.item = new SPolylineItem(null, []);
  36. this.item.status = SItemStatus.Create;
  37. this.scene.addItem(this.item);
  38. this.scene.grabItem = this.item;
  39. this.view.update();
  40. },
  41. undo() {
  42. if (this.scene.grabItem) {
  43. this.scene.grabItem.undo()
  44. }
  45. },
  46. redo() {
  47. if (this.scene.grabItem) {
  48. this.scene.grabItem.redo()
  49. }
  50. }
  51. }
  52. }
  53. </script>
  54. <style scoped>
  55. canvas {
  56. border: 1px solid #eeeeee;
  57. outline: none;
  58. }
  59. </style>