HomeView.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <template>
  2. <div class="home">
  3. <div v-show="screenData.state === 1" style="width: 128px; height: 256px">
  4. <img
  5. style="width: 100%; height: 100%"
  6. :src="screenData.url"
  7. alt="大屏图片"
  8. />
  9. </div>
  10. <div v-show="screenData.state === 2" class="video-container">
  11. <video
  12. ref="qq"
  13. class="qq"
  14. :src="screenData.url"
  15. muted
  16. autoplay
  17. controls
  18. loop
  19. />
  20. </div>
  21. </div>
  22. </template>
  23. <script>
  24. import { clientGet } from "@/utils/request";
  25. export default {
  26. name: "HomeView",
  27. async created() {
  28. this.deviceId = this.$route.query.deviceId;
  29. const res = await clientGet("/test/getScreenControl/" + this.deviceId);
  30. if (res.code !== 200) {
  31. alert(res.msg);
  32. }
  33. this.screenData = res.data;
  34. },
  35. mounted() {
  36. let element = this.$el.querySelector(".qq");
  37. if (element) {
  38. setTimeout(() => {
  39. element.play().catch((e) => {
  40. console.log(e);
  41. alert("自动播放失败,请手动播放");
  42. });
  43. }, 1000);
  44. }
  45. },
  46. data() {
  47. return {
  48. text: "",
  49. params: 123,
  50. deviceId: "",
  51. screenData: {
  52. url: "",
  53. state: 1,
  54. deviceId: "",
  55. },
  56. };
  57. },
  58. };
  59. </script>
  60. <style scoped>
  61. .video-container {
  62. width: 128px;
  63. height: 256px;
  64. position: relative;
  65. }
  66. .qq {
  67. width: 100%;
  68. height: 100%;
  69. object-fit: cover; /* 使视频覆盖整个容器 */
  70. }
  71. </style>