ScreenShot.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 {
  24. getAndCheck,
  25. screenshot,
  26. stop
  27. } from '@/utils/screenshot'
  28. export default {
  29. name: 'DeviceScreenShot',
  30. props: {
  31. device: {
  32. type: Object,
  33. default: null
  34. }
  35. },
  36. data () {
  37. return {
  38. asking: false,
  39. styles: null
  40. }
  41. },
  42. activated () {
  43. getAndCheck(this.device, this.onScreenshotUpdate, 10000)
  44. },
  45. created () {
  46. getAndCheck(this.device, this.onScreenshotUpdate, 10000)
  47. },
  48. beforeDestroy () {
  49. stop()
  50. },
  51. methods: {
  52. onScreenshotUpdate ({ waiting, base64 }) {
  53. this.asking = waiting
  54. this.styles = !waiting && base64 ? {
  55. backgroundImage: `url("${base64}")`
  56. } : null
  57. },
  58. invoke () {
  59. screenshot(this.device.id, true)
  60. }
  61. }
  62. }
  63. </script>
  64. <style lang="scss" scoped>
  65. .o-invoke {
  66. display: inline-block;
  67. width: 24px;
  68. height: 24px;
  69. background: url("~@/assets/icon_screenshot.png") 0 0 / 100% 100% no-repeat;
  70. }
  71. .o-preview {
  72. background-position: center center;
  73. background-size: contain;
  74. background-repeat: no-repeat;
  75. }
  76. </style>