ScreenShot.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <template>
  2. <div class="l-flex--col c-runtime">
  3. <div class="l-flex__none l-flex--row has-bottom-padding">
  4. <i class="l-flex__none c-runtime__icon screenshot" />
  5. <span class="l-flex__fill c-runtime__title u-ellipsis">截屏</span>
  6. <i
  7. v-if="asking"
  8. class="l-flex__none el-icon-loading u-color--black"
  9. />
  10. <i
  11. v-else
  12. class="l-flex__none o-invoke u-pointer"
  13. @click="invoke"
  14. />
  15. </div>
  16. <div
  17. class="l-flex__fill o-preview"
  18. :style="styles"
  19. />
  20. </div>
  21. </template>
  22. <script>
  23. import { ScreenshotCache } from '@/utils/cache'
  24. export default {
  25. name: 'DeviceScreenShot',
  26. props: {
  27. device: {
  28. type: Object,
  29. default: null
  30. }
  31. },
  32. data () {
  33. return {
  34. asking: false,
  35. styles: null
  36. }
  37. },
  38. activated () {
  39. ScreenshotCache.watch(this.device, this.onScreenshotUpdate, 10000)
  40. },
  41. created () {
  42. ScreenshotCache.watch(this.device, this.onScreenshotUpdate, 10000)
  43. },
  44. beforeDestroy () {
  45. ScreenshotCache.unwatch(this.device.id)
  46. },
  47. methods: {
  48. onScreenshotUpdate ({ waiting, base64 }) {
  49. this.asking = waiting
  50. this.styles = !waiting && base64 ? {
  51. backgroundImage: `url("${base64}")`
  52. } : null
  53. },
  54. invoke () {
  55. ScreenshotCache.screenshot(this.device.id)
  56. }
  57. }
  58. }
  59. </script>
  60. <style lang="scss" scoped>
  61. .o-invoke {
  62. display: inline-block;
  63. width: 24px;
  64. height: 24px;
  65. background: url("~@/assets/icon_screenshot.png") 0 0 / 100% 100% no-repeat;
  66. }
  67. .o-preview {
  68. background-position: center center;
  69. background-size: contain;
  70. background-repeat: no-repeat;
  71. }
  72. </style>