gifItem.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <template>
  2. <div>
  3. <canvas id="gifItem" width="400" height="400" tabindex="0"/>
  4. </div>
  5. </template>
  6. <script lang="ts">
  7. import { SGraphItem, SGraphScene, SGraphView, SGraphSvgItem, SImageItem } from "@persagy-web/graph";
  8. import { Component, Vue } from "vue-property-decorator";
  9. import { SColor, SLineCapStyle, SPainter, SRect, SSize } from "@persagy-web/draw";
  10. class SGifItem extends SImageItem {
  11. onDraw(painter: SPainter) {
  12. super.onDraw(painter);
  13. this.update()
  14. }
  15. } // Class SGraphClockItem
  16. @Component
  17. export default class GIFCanvas extends Vue {
  18. /**
  19. * 页面挂载
  20. */
  21. mounted(): void {
  22. const view = new SGraphView('gifItem');
  23. const scene = new SGraphScene()
  24. // const item = new SGifItem(null, {url:'http://f.sinaimg.cn/tech/transform/301/w193h108/20210128/7d28-kicwvzr2403640.gif'});
  25. const item = new SGifItem(null, 'http://f.sinaimg.cn/tech/transform/301/w193h108/20210128/7d28-kicwvzr2403640.gif');
  26. scene.addItem(item);
  27. view.scene = scene;
  28. view.fitItemToView([item]);
  29. // 方式2 直接使用 SImageItem, 增加以下代码
  30. // setInterval(() => {
  31. // view.update()
  32. // }, 60);
  33. }
  34. }
  35. </script>
  36. <style scoped>
  37. </style>