PolylineItem.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. /** 命令所属的场景类 */
  22. scene: null,
  23. /** 实例化 view */
  24. view: null,
  25. item: null,
  26. };
  27. },
  28. /**
  29. * 页面挂载
  30. */
  31. mounted() {
  32. this.view = new SGraphView("editPolyline");
  33. this.scene = new SGraphScene();
  34. this.view.scene = this.scene;
  35. this.init()
  36. },
  37. methods: {
  38. /**
  39. * 初始化加载
  40. */
  41. init() {
  42. this.scene.root.children = [];
  43. this.item = new SPolylineItem(null, []);
  44. this.item.status = SItemStatus.Create;
  45. this.scene.addItem(this.item);
  46. this.scene.grabItem = this.item;
  47. this.view.update();
  48. },
  49. undo() {
  50. if (this.scene.grabItem) {
  51. this.scene.grabItem.undo()
  52. }
  53. },
  54. redo() {
  55. if (this.scene.grabItem) {
  56. this.scene.grabItem.redo()
  57. }
  58. }
  59. }
  60. }
  61. </script>
  62. <style scoped>
  63. canvas {
  64. border: 1px solid #eeeeee;
  65. outline: none;
  66. }
  67. </style>