SEditLine.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <template>
  2. <div>
  3. <el-button @click="create">创建</el-button>
  4. <el-button @click="undo">undo</el-button>
  5. <el-button @click="redo">redo</el-button>
  6. <canvas id="editLine" width="740" height="400" tabindex="0"/>
  7. </div>
  8. </template>
  9. <script>
  10. import { SGraphScene, SGraphView } from "@persagy-web/graph/";
  11. import { SItemStatus } from "@persagy-web/big/lib/enums/SItemStatus";
  12. import { SLineItem } from "@persagy-web/big/lib";
  13. /**
  14. * 可编辑直线示例
  15. *
  16. * @author 郝洁 <haojie@persagy.com>
  17. */
  18. export default {
  19. data() {
  20. return {
  21. scene: null,
  22. view: null
  23. };
  24. },
  25. mounted() {
  26. this.view = new SGraphView("editLine");
  27. this.scene = new SGraphScene();
  28. this.view.scene = this.scene;
  29. },
  30. methods: {
  31. create() {
  32. this.scene.root.children = [];
  33. const lineItem = new SLineItem(null, []);
  34. lineItem.status = SItemStatus.Create;
  35. this.scene.addItem(lineItem);
  36. this.scene.grabItem = lineItem;
  37. this.view.fitSceneToView();
  38. },
  39. undo() {
  40. if (this.scene.grabItem) {
  41. this.scene.grabItem.undo();
  42. }
  43. },
  44. redo() {
  45. if (this.scene.grabItem) {
  46. this.scene.grabItem.redo();
  47. }
  48. }
  49. }
  50. };
  51. </script>