ImageItem.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 */
  31. id: string = uuid();
  32. /** 图片地址 */
  33. url: string = require('./1.jpg');
  34. /**
  35. * 页面挂载
  36. */
  37. mounted() {
  38. const view = new SGraphView(this.id);
  39. const scene = new SGraphScene();
  40. const item = new Img(null, {url: this.url, x: 0, y: 0, width: 100, height: 100});
  41. item.selectable = true;
  42. view.scene = scene;
  43. scene.addItem(item);
  44. view.fitSceneToView();
  45. };
  46. Full() {
  47. // this.scene.imageItem.showType = SImageShowType.Full;
  48. };
  49. Equivalency() {
  50. // this.scene.imageItem.showType = SImageShowType.Equivalency;
  51. };
  52. AutoFit() {
  53. // this.scene.imageItem.showType = SImageShowType.AutoFit;
  54. };
  55. }
  56. </script>
  57. <style scoped>
  58. </style>