index_back.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <view class="body">
  3. <image class="imgStryle" :style=" item.style ? 'width:'+ item.style.w +'px;height:' + item.style.h + 'px' : '' "
  4. @load="v=>loadIndex(v,i)" @click="() => tonext(item)" v-for="(item,i) in list" :key="i" :src="item.cover"
  5. mode="scaleToFill"></image>
  6. <video @loadedmetadata="startPlay" v-if="urlVideo" class="video"
  7. :style="{width: videoInfo.width + 'px',height: videoInfo.height + 'px', left: videoInfo.left +'px', top: videoInfo.top + 'px'}"
  8. :src="urlVideo" autoplay :controls="false" :show-play-btn="false" :show-center-play-btn="false"
  9. :show-fullscreen-btn="false" :show-loading="false" :enable-progress-gesture="false"
  10. :vslide-gesture-in-fullscreen="false" @ended="ended" @error="ended"></video>
  11. <view v-if="urlVideo" class="tg" @click="ended">
  12. 跳过
  13. </view>
  14. </view>
  15. </template>
  16. <script setup>
  17. import {
  18. ref
  19. } from "vue";
  20. import config from "../../config/index.js";
  21. const info = uni.getSystemInfoSync();
  22. const list = ref([]);
  23. const urlVideo = ref("");
  24. const videoInfo = ref({
  25. width: 0,
  26. height: 0,
  27. left: 0,
  28. top: 0
  29. })
  30. uni.request({
  31. url: config.base + "home.json?" + Date.now(),
  32. success: r => {
  33. if (r.statusCode !== 200) return
  34. list.value = r.data.list || [];
  35. urlVideo.value = r.data.video || "";
  36. }
  37. })
  38. function loadIndex(v, i) {
  39. const w = info.windowWidth - 16;
  40. const h = v.detail.height / v.detail.width * w;
  41. list.value[i].style = {
  42. w,
  43. h
  44. };
  45. }
  46. function tonext(T) {
  47. T.pageType === "detail" && uni.navigateTo({
  48. url: "/pages/brief/brief?title=" + T.subTitle + "&page=" + T.page
  49. });
  50. T.pageType === "single_row" && uni.navigateTo({
  51. url: "/pages/single_row/single_row?title=" + T.title + "&url=" + T.headCover + "&page=" + T.page
  52. })
  53. T.pageType === "single_list" && uni.navigateTo({
  54. url: "/pages/single_list/single_list?title=" + T.title + "&url=" + T.headCover + "&page=" + T.page
  55. })
  56. }
  57. function ended() {
  58. urlVideo.value = "";
  59. }
  60. function startPlay(res) {
  61. const videoInfoFun = res.detail || {};
  62. let width = 0, height= 0;
  63. if(videoInfoFun.width < videoInfoFun.height){
  64. // 宽为短边
  65. width = info.windowWidth;
  66. height = info.windowWidth / videoInfoFun.width * videoInfoFun.height
  67. }else {
  68. // 高为短边
  69. height = info.windowHeight;
  70. width = info.windowHeight / videoInfoFun.height * videoInfoFun.width
  71. }
  72. // 修改之后在做判断宽高是否小于屏幕
  73. if (width < info.windowWidth){
  74. // 宽度不够的话再次伸缩一次
  75. height = info.windowWidth / width * height;
  76. width = info.windowWidth;
  77. }
  78. if (height < info.windowHeight){
  79. // 高度不够的话再次伸缩一次
  80. width = info.windowHeight / height * width;
  81. height = info.windowHeight
  82. }
  83. videoInfo.value.width = width;
  84. videoInfo.value.height = height;
  85. if (width > info.windowWidth) videoInfo.value.left = (info.windowWidth - width) / 2;
  86. if (height > info.windowHeight) videoInfo.value.top = (info.windowHeight - height) / 2;
  87. }
  88. </script>
  89. <style lang="scss">
  90. .body {
  91. padding: 1em 0;
  92. .imgStryle {
  93. margin: 2px 8px;
  94. border-radius: 10px;
  95. }
  96. .video {
  97. position: fixed;
  98. z-index: 9998;
  99. }
  100. .tg {
  101. position: fixed;
  102. z-index: 9999;
  103. border-radius: 2em;
  104. width: 3em;
  105. height: 1.5em;
  106. line-height: 1.5em;
  107. border: 1px solid #fff;
  108. color: #fff;
  109. text-align: center;
  110. top: 3em;
  111. right: 2em;
  112. font-size: 16px;
  113. padding: 2px 4px;
  114. }
  115. }
  116. </style>