SEditLine.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. /** 命令所属的场景类 */
  22. scene: null,
  23. /** 实例化 view */
  24. view: null
  25. };
  26. },
  27. /**
  28. * 页面挂载
  29. */
  30. mounted() {
  31. this.view = new SGraphView("editLine");
  32. this.scene = new SGraphScene();
  33. this.view.scene = this.scene;
  34. },
  35. methods: {
  36. create() {
  37. this.scene.root.children = [];
  38. const lineItem = new SLineItem(null, []);
  39. lineItem.status = SItemStatus.Create;
  40. this.scene.addItem(lineItem);
  41. this.scene.grabItem = lineItem;
  42. this.view.fitSceneToView();
  43. },
  44. undo() {
  45. if (this.scene.grabItem) {
  46. this.scene.grabItem.undo();
  47. }
  48. },
  49. redo() {
  50. if (this.scene.grabItem) {
  51. this.scene.grabItem.redo();
  52. }
  53. }
  54. }
  55. };
  56. </script>