play.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <template>
  2. <view style="overflow: hidden;" :style="{ height: height + 'px' }">
  3. <swiper class="swiper" :style="{ height: height + 'px' }" :show-scrollbar="false" vertical :circular="false"
  4. :current="current" @change="onSwiperChange">
  5. <swiper-item v-for="(item, i) in list" :key="i" :style="{ 'height': height - 1 + 'px' }">
  6. <oVideo :ref="el => setItemRef(el, i)" :id="'video' + i" :height="height - 1" :current="current" :item="item"
  7. :index="i" @showPinglun="comment(item)" @play="onPlay" @like="like(item, i)" @collect="collect(item, i)"
  8. @follow="follow(item, i)" />
  9. </swiper-item>
  10. </swiper>
  11. <!-- 评论弹框 -->
  12. <commentDialog ref="dialogRef" :video_id="video_id" />
  13. </view>
  14. </template>
  15. <script setup>
  16. import { ref, onMounted, computed } from "vue";
  17. import oVideo from "@/components/y-video";
  18. import { onShow } from "@dcloudio/uni-app"
  19. import { useVideoStore, useUserStore } from "@/store"
  20. import { VIDEO_VIEWS, VIDEO_COLLECTS, VIDEO_GOODS, DISCOVER_FOLLOW } from "@/api"
  21. import { Toast } from "@/utils"
  22. import commentDialog from '@/components/commentDialog'
  23. const useUser = useUserStore();
  24. const userInfo = computed(() => useUser.getuserInfo)
  25. const dialogRef = ref(null);
  26. const useVideo = useVideoStore();
  27. let systemInfo = uni.getSystemInfoSync();
  28. const top = systemInfo.statusBarHeight + uni.upx2px(30);
  29. const height = systemInfo.screenHeight;
  30. const scrollHeight = systemInfo.screenHeight * 0.8 - uni.upx2px(100);
  31. const current = ref(0);
  32. const newCurrent = ref(0);
  33. const info = {
  34. name: '测试标题',
  35. pic: 'https://img.lzzyimg.com/upload/vod/20240312-1/e3d0aaa1748d757b03fab599abf156d8.jpg'
  36. }
  37. const paging = ref(null)
  38. const video_id = ref(null)
  39. // const newList = ref([]);
  40. // const list = ref([{
  41. // title: "第18集",
  42. // src: "http://vjs.zencdn.net/v/oceans.mp4",
  43. // desc: '测试内容'
  44. // }, {
  45. // title: "第19集",
  46. // src: "https://cloud.video.taobao.com/play/u/3007761989/p/2/e/6/t/1/451969495179.mp4?appKey=38829",
  47. // desc: '测试内容2'
  48. // }, {
  49. // title: "第20集",
  50. // src: "http://vjs.zencdn.net/v/oceans.mp4",
  51. // desc: '测试内容2'
  52. // }, {
  53. // title: "第21集",
  54. // src: "http://vjs.zencdn.net/v/oceans.mp4",
  55. // desc: '测试内容'
  56. // }, {
  57. // title: "第22集",
  58. // src: "https://cloud.video.taobao.com/play/u/3007761989/p/2/e/6/t/1/451969495179.mp4?appKey=38829",
  59. // desc: '测试内容2'
  60. // }, {
  61. // title: "第23集",
  62. // src: "http://vjs.zencdn.net/v/oceans.mp4",
  63. // desc: '测试内容2'
  64. // }, {
  65. // title: "第24集",
  66. // src: "https://cloud.video.taobao.com/play/u/3007761989/p/2/e/6/t/1/451969495179.mp4?appKey=38829",
  67. // desc: '测试内容2'
  68. // }, {
  69. // title: "第25集",
  70. // src: "http://vjs.zencdn.net/v/oceans.mp4",
  71. // desc: '测试内容2'
  72. // }, {
  73. // title: "第26集",
  74. // src: "https://cloud.video.taobao.com/play/u/3007761989/p/2/e/6/t/1/451969495179.mp4?appKey=38829",
  75. // desc: '测试内容2'
  76. // }, {
  77. // title: "第27集",
  78. // src: "http://vjs.zencdn.net/v/oceans.mp4",
  79. // desc: '测试内容2'
  80. // }, {
  81. // title: "第28集",
  82. // src: "https://cloud.video.taobao.com/play/u/3007761989/p/2/e/6/t/1/451969495179.mp4?appKey=38829",
  83. // desc: '测试内容2'
  84. // }, {
  85. // title: "第29集",
  86. // src: "http://vjs.zencdn.net/v/oceans.mp4",
  87. // desc: '测试内容2'
  88. // }, {
  89. // title: "第30集",
  90. // src: "https://cloud.video.taobao.com/play/u/3007761989/p/2/e/6/t/1/451969495179.mp4?appKey=38829",
  91. // desc: '测试内容2'
  92. // }, {
  93. // title: "第31集",
  94. // src: "http://vjs.zencdn.net/v/oceans.mp4",
  95. // desc: '测试内容2'
  96. // }])
  97. const list = computed(() => useVideo.getVideoList)
  98. let pages = 5;
  99. const newList = computed(() => {
  100. let _list = [];
  101. let start = 0;
  102. let end = 0
  103. let half = Math.floor(newCurrent.value / pages)
  104. // console.log(half);
  105. start = half - 1 < 0 ? 0 : start + half;
  106. end = half - 1 < 0 ? pages : half * pages + current.value;
  107. // if (current.value < 4) {
  108. // }
  109. // else {
  110. // start = (newCurrent.value + 1) % pages * pages + current.value
  111. // end = start + pages;
  112. // }
  113. _list = list.value.slice(start, end)
  114. console.log(start, end);
  115. return _list
  116. })
  117. const videoContexts = ref([]);
  118. onMounted(() => {
  119. if (videoContexts.value[current.value]) {
  120. videoContexts.value[current.value].play()
  121. }
  122. })
  123. const setItemRef = (el, index) => {
  124. if (el) {
  125. videoContexts.value[index] = el
  126. }
  127. }
  128. const onPlay = async (item) => {
  129. try {
  130. await VIDEO_VIEWS(item.id)
  131. } catch (error) { }
  132. }
  133. const onSwiperChange = (e) => {
  134. const newIndex = e.detail.current;
  135. if (videoContexts.value[current.value]) {
  136. videoContexts.value[current.value].pause()
  137. }
  138. if (newIndex == list.value.length - 2) {
  139. useVideo.setVideoList(true)
  140. }
  141. current.value = newIndex;
  142. if (videoContexts.value[newIndex]) {
  143. videoContexts.value[newIndex].play()
  144. }
  145. }
  146. const like = async (item, index) => {
  147. let obj = {};
  148. try {
  149. const res = await VIDEO_GOODS(item.id);
  150. obj = { ...item, goods: res.data.goods, is_goods: item.goods == 0 ? 1 : 0 };
  151. useVideo.setList(obj, index);
  152. } catch (error) {
  153. Toast(error.msg)
  154. }
  155. }
  156. const collect = async (item, index) => {
  157. let obj = {};
  158. try {
  159. const res = await VIDEO_COLLECTS(item.id);
  160. obj = { ...item, collects: res.data.collects, is_collect: item.is_collect == 0 ? 1 : 0 };
  161. useVideo.setList(obj, index);
  162. } catch (error) {
  163. Toast(error.msg)
  164. }
  165. }
  166. const follow = async (item, index) => {
  167. let obj = {};
  168. try {
  169. const res = await DISCOVER_FOLLOW(item.userid);
  170. obj = { ...item, is_follow: item.is_follow == 0 ? 1 : 0 };
  171. useVideo.setList(obj, index);
  172. } catch (error) {
  173. Toast(error.msg)
  174. }
  175. }
  176. const comment = (item) => {
  177. video_id.value = item.id;
  178. dialogRef.value && dialogRef.value.open();
  179. }
  180. onShow(() => {
  181. })
  182. </script>
  183. <style lang="scss" scoped>
  184. .pop {
  185. position: fixed;
  186. width: 750rpx;
  187. background-color: #fff;
  188. border-radius: 30rpx 30rpx 0 0;
  189. left: 0;
  190. transition-property: top;
  191. transition-duration: 150ms;
  192. transition-timing-function: ease-in-out;
  193. z-index: 999;
  194. .title {
  195. padding: 30rpx 30rpx 0;
  196. align-items: center;
  197. justify-content: center;
  198. line-height: 40rpx;
  199. }
  200. &--close-btn {
  201. height: 40rpx;
  202. width: 40rpx;
  203. position: absolute;
  204. right: 30rpx;
  205. top: 30rpx;
  206. }
  207. }
  208. .border-bottom {
  209. width: 750rpx;
  210. border-bottom: 1rpx solid #e8e8e8;
  211. transform: scaleY(.5);
  212. margin-top: 30rpx;
  213. }
  214. .pinglun {
  215. flex-direction: row;
  216. align-items: flex-start;
  217. padding: 30rpx;
  218. .touxiang {
  219. height: 60rpx;
  220. width: 60rpx;
  221. border-radius: 50%;
  222. }
  223. }
  224. .list_cont {
  225. uni-view {
  226. position: relative;
  227. }
  228. }
  229. .mulu {
  230. padding-left: 30rpx;
  231. padding-right: 30rpx;
  232. .touxiang {
  233. height: 114.8rpx;
  234. width: 78.4rpx;
  235. border-radius: 10rpx;
  236. }
  237. .title {
  238. color: rgba(0, 0, 0, .85);
  239. padding: 0;
  240. }
  241. .active {
  242. .title {
  243. color: #f85400;
  244. }
  245. }
  246. .tag {
  247. background-color: #f85400;
  248. padding: 7rpx 12rpx;
  249. border-radius: 10rpx;
  250. .text {
  251. color: #fff;
  252. }
  253. }
  254. }
  255. .flex-1 {
  256. flex: 1;
  257. }
  258. .lh-40 {
  259. line-height: 40rpx;
  260. }
  261. @for $i from 20 to 40 {
  262. .fs-#{$i} {
  263. font-size: $i + rpx;
  264. }
  265. }
  266. </style>