ImageItem.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <template>
  2. <div>
  3. <el-row>
  4. <el-button @click="Full">铺满</el-button>
  5. <el-button @click="Equivalency">等比缩放</el-button>
  6. <el-button @click="AutoFit">自适应</el-button>
  7. </el-row>
  8. <canvas :id="id" width="740" height="400"/>
  9. </div>
  10. </template>
  11. <script lang="ts">
  12. import { SGraphScene, SGraphView } from "@persagy-web/graph";
  13. import { SGraphSvgItem } from "@persagy-web/graph/lib";
  14. import { Component, Vue } from "vue-property-decorator";
  15. import { SSize } from "@persagy-web/draw/lib";
  16. import { v1 as uuid } from "uuid";
  17. /**
  18. * 图片实例
  19. *
  20. * @author 郝洁 <haojie@persagy.com>
  21. */
  22. class Img extends SGraphSvgItem {
  23. resize(oldSize: SSize, newSize: SSize): void {
  24. this.width = newSize.width;
  25. this.height = newSize.height;
  26. }
  27. }
  28. @Component
  29. export default class imageCanvas extends Vue {
  30. id: string = uuid();
  31. url: string = require('./1.jpg');
  32. mounted() {
  33. const view = new SGraphView(this.id);
  34. const scene = new SGraphScene();
  35. const item = new Img(null, {url: this.url, x: 0, y: 0, width: 100, height: 100});
  36. item.selectable = true;
  37. view.scene = scene;
  38. scene.addItem(item);
  39. view.fitSceneToView();
  40. };
  41. Full() {
  42. // this.scene.imageItem.showType = SImageShowType.Full;
  43. };
  44. Equivalency() {
  45. // this.scene.imageItem.showType = SImageShowType.Equivalency;
  46. };
  47. AutoFit() {
  48. // this.scene.imageItem.showType = SImageShowType.AutoFit;
  49. };
  50. }
  51. </script>
  52. <style scoped>
  53. </style>