play.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. <template>
  2. <view class="video">
  3. <view class="empty position-center align-center justify-center"
  4. v-if="videoList.length === 0 && status !== 'loading'">
  5. <view> </view>
  6. </view>
  7. <swiper vertical acceleration :current="videoIndex" :style="{ width: width + 'px', height: height + 'px' }"
  8. @change="changeCurrent" @animationfinish="animationFinish">
  9. <swiper-item v-for="(item, index) in videoList" :key="index">
  10. <!-- 视频预渲染 +1 -->
  11. <block v-if="Math.abs(videoIndex - index) <= 1">
  12. <!-- <block v-if="videoIndex === index"> -->
  13. <view @click="handleClicked">
  14. <!-- 播放界面 -->
  15. <wanl-find-video :ref="'wanlVideo'+item.id" :width="width" :height="height"
  16. :src="static_url + item.video" :play="item.play" :videoId="item.id"
  17. :coverUrl="static_url + item.gif" objectFit="cover" :initialTime="0" @pause="pauseVideo" />
  18. <!-- 组件 -->
  19. <view class="position-bottom-center" :style="{ bottom: `${safeBottom}px`,width:width+'px' }">
  20. <view class="
  21. flex-row
  22. padding-lr-bj padding-bottom-xl
  23. align-end
  24. " :style="{width:width+'px','flex-direction':'row'}" @click="handleClicked">
  25. <view class="flex-sub padding-right-bj ">
  26. <view class="left-title" @click.stop="handleUser(item.user_id)">
  27. <text
  28. class="text-white margin-bottom-s text-lg">@{{ item.user_info.nickname }}</text>
  29. </view>
  30. <view class="left-describe flex-direction">
  31. <text class="text-lines-3 flex-sub text-df text-white-8">{{ item.title}}</text>
  32. </view>
  33. </view>
  34. <view class="main-right align-center ">
  35. <view class="
  36. main-right-user
  37. position-relative
  38. margin-bottom-xs
  39. align-center
  40. ">
  41. <view class="
  42. main-right-image
  43. justify-center
  44. bg-white
  45. round
  46. align-center
  47. " @click.stop="handleUser(item.user_id)">
  48. <image class="main-right-img round"
  49. :src="static_photo + item.user_info.face" />
  50. </view>
  51. <view v-if="item.is_follow == 0" class="
  52. main-right-user-follow
  53. bg-red
  54. round
  55. position-absolute
  56. justify-center
  57. align-center
  58. " @click.stop="handleFollow(item)">
  59. <text class="text-min icon">&#xe644;</text>
  60. </view>
  61. <view v-if="item.is_follow == 1" class="
  62. main-right-user-follow
  63. bg-red
  64. round
  65. position-absolute
  66. justify-center
  67. align-center
  68. " @click.stop="handleFollow(item)">
  69. <text class="text-min icon">&#xe66c;</text>
  70. </view>
  71. </view>
  72. <view class="margin-top align-center" @click.stop="handleLike(item)">
  73. <text :class="{ 'text-red': item.is_fabulous == 1 }"
  74. class="icon text-xxxxl">&#xe635;</text>
  75. <text class="text-white text-min">{{ item.fabulous }}</text>
  76. </view>
  77. <view class="margin-top align-center" @click.stop="handleComment(item)">
  78. <text class="icon text-xxxxl">&#xe68c;</text>
  79. <text class="text-white text-min">{{ item.comment }}</text>
  80. </view>
  81. </view>
  82. </view>
  83. </view>
  84. </view>
  85. </block>
  86. </swiper-item>
  87. </swiper>
  88. <!-- 弹出层 -->
  89. <uni-popup ref="wanlCommentPopup" type="bottom">
  90. <view class="comment padding-bj">
  91. <view class="flex-direction justify-between align-center margin-bottom-bj">
  92. <text></text>
  93. <text class="text-white text-30">全部评论({{ commentData.count }})</text>
  94. <text class="icon text-30" @tap="handleCommentClose">&#xe66b;</text>
  95. </view>
  96. <wanl-comment v-if="commentData.find_id" :findId="commentData.find_id" :commentList="commentData.list"
  97. :commenCount="commentData.count" @complete="handleComplete" />
  98. <view :style="{ height: `${bottom}px` }" />
  99. </view>
  100. </uni-popup>
  101. </view>
  102. </template>
  103. <script>
  104. import wanlFindVideo from "./video.vue";
  105. import wanlComment from "./comment.vue";
  106. import _data from "@/common/_data";
  107. import _mixins from '@/common/_mixins';
  108. let timer = null;
  109. export default {
  110. components: {
  111. wanlFindVideo,
  112. wanlComment,
  113. },
  114. props: {
  115. find_id: {
  116. type: String,
  117. default: "",
  118. },
  119. height: {
  120. type: Number,
  121. default: 0,
  122. },
  123. width: {
  124. type: Number,
  125. default: 0,
  126. },
  127. bottom: {
  128. type: Number,
  129. default: 0,
  130. },
  131. safeBottom: {
  132. type: Number,
  133. default: 40,
  134. },
  135. },
  136. data() {
  137. return {
  138. preload: 2, //当前页剩余个数换页
  139. videoList: [],
  140. current_page: 1, //当前页码
  141. last_page: 1, //总页码
  142. status: "loading",
  143. videoIndex: 0,
  144. oldVideoIndex: 0,
  145. commentData: {},
  146. providerList: [],
  147. static_url: "",
  148. static_photo: _data.staticPhoto(),
  149. };
  150. },
  151. mounted() {
  152. this.static_url = getApp().globalData.static_url;
  153. console.log("this.static_url", this.static_url);
  154. this.loadData();
  155. },
  156. methods: {
  157. async loadData(type) {
  158. this.status = "loading";
  159. if (type === "update") {
  160. if (this.current_page >= this.last_page) {
  161. this.status = "noMore";
  162. return false;
  163. } else {
  164. this.current_page += 1;
  165. }
  166. }
  167. if (this.find_id) {
  168. console.log("this.find_id", this.find_id);
  169. _mixins.methods.$httpSend({
  170. path: "/im/video.Share/video_list",
  171. data: {
  172. type: "1",
  173. id: this.find_id,
  174. },
  175. success: (data) => {
  176. this.last_page = data.last_page;
  177. if (this.current_page <= data.last_page) {
  178. this.current_page++;
  179. this.videoList = this.videoList.concat(data.data);
  180. this.videoList.map((item) => {
  181. item.play = false;
  182. });
  183. this.$nextTick(() => {
  184. this.videoPlay(this.videoIndex)
  185. })
  186. }
  187. console.log("this.videoList", this.videoList);
  188. },
  189. fail: (err) => {
  190. console.log("err", err);
  191. }
  192. });
  193. } else {
  194. _mixins.methods.$httpSend({
  195. path: "/im/video.Share/video_list",
  196. data: {
  197. type: "1",
  198. page: this.current_page
  199. },
  200. success: (data) => {
  201. console.log("视频列表", data);
  202. this.last_page = data.last_page;
  203. if (this.current_page <= data.last_page) {
  204. this.current_page++;
  205. this.videoList = this.videoList.concat(data.data);
  206. this.videoList.map((item) => {
  207. item.play = false;
  208. });
  209. this.$nextTick(() => {
  210. this.videoPlay(this.videoIndex)
  211. })
  212. }
  213. console.log("this.videoList", this.videoList);
  214. },
  215. fail: (err) => {
  216. console.log("err", err);
  217. }
  218. });
  219. }
  220. },
  221. async handleFollow(item) {
  222. _mixins.methods.$httpSend({
  223. path: "/im/video.Share/follow",
  224. data: {
  225. user_id: item.user_id,
  226. },
  227. success(data) {
  228. console.log("data", data);
  229. if (data.code == 0) {
  230. item.is_follow = !item.is_follow;
  231. } else {
  232. uni.showToast({
  233. icon: "none",
  234. title: data.msg,
  235. });
  236. }
  237. },
  238. });
  239. },
  240. async handleLike(item) {
  241. _mixins.methods.$httpSend({
  242. path: "/im/video.Share/fabulous",
  243. data: {
  244. id: item.id,
  245. },
  246. success: (data) => {
  247. if (data.code == 0) {
  248. item.is_fabulous = !item.is_fabulous;
  249. if (item.is_fabulous) {
  250. item.fabulous++;
  251. } else {
  252. item.fabulous--;
  253. }
  254. } else {
  255. uni.showToast({
  256. icon: "none",
  257. title: data.msg,
  258. });
  259. }
  260. },
  261. });
  262. },
  263. async handleComment(item) {
  264. _mixins.methods.$httpSend({
  265. path: "/im/video.Share/getComment",
  266. data: {
  267. id: item.id,
  268. type: "1",
  269. },
  270. success: (res) => {
  271. console.log("res", res);
  272. this.commentData.list = res.data;
  273. this.commentData.find_id = item.id;
  274. this.commentData.count = item.comment;
  275. console.log("this.commentData", this.commentData);
  276. this.$forceUpdate();
  277. setTimeout(() => {
  278. this.$refs.wanlCommentPopup.open();
  279. }, 100)
  280. },
  281. });
  282. },
  283. handleComplete(e) {
  284. if (e.type === "add") {
  285. this.commentData.count++;
  286. this.videoList.map(item => {
  287. if (item.id == e.id) {
  288. item.comment++;
  289. }
  290. })
  291. this.$forceUpdate();
  292. // this.handleComment(e);
  293. }
  294. },
  295. handleUser(user_no) {
  296. uni.navigateTo({
  297. url: `/pages/video/user?id=${user_no}`,
  298. });
  299. },
  300. handleCommentClose() {
  301. this.$refs.wanlCommentPopup.close();
  302. },
  303. // 点击视频事件
  304. handleClicked() {
  305. console.log("点击视频事件")
  306. if (timer) {
  307. clearTimeout(timer);
  308. }
  309. timer = setTimeout(() => {
  310. this.videoList.map(item => {
  311. item.play = false;
  312. })
  313. this.videoList[this.videoIndex].play = !this.videoList[this.videoIndex].play;
  314. this.$forceUpdate();
  315. }, 300);
  316. },
  317. // 播放当前视频
  318. videoPlay(index) {
  319. this.videoList[index].play = !this.videoList[index].play;
  320. },
  321. handleVideoPlay() {
  322. if (this.videoList.length > 0)
  323. this.$nextTick(() => {
  324. this.videoList[this.videoIndex].play = true;
  325. });
  326. },
  327. handleVideoPause() {
  328. this.videoList.map(item => {
  329. item.play = false;
  330. })
  331. this.$forceUpdate();
  332. console.log("视频停止")
  333. },
  334. // 时间打标
  335. pauseVideo(val) {
  336. console.log("时间打标", val);
  337. // 1.0.9临时
  338. // if (typeof this.videoList[this.oldVideoIndex].initialTime != 'undefined') {
  339. // this.videoList[this.oldVideoIndex].initialTime = val
  340. // }
  341. },
  342. animationFinish(e) {
  343. //#ifdef APP-PLUS
  344. this.changeCurrent(e);
  345. //#endif
  346. },
  347. changeCurrent(e) {
  348. this.videoIndex = e.detail.current;
  349. console.log("this.videoIndex", this.videoIndex);
  350. this.$nextTick(() => {
  351. this.videoList.map(item => {
  352. item.play = false;
  353. })
  354. this.videoList[this.videoIndex].play = true;
  355. this.$forceUpdate();
  356. });
  357. },
  358. },
  359. watch: {
  360. // 加载新的视频
  361. videoIndex(newVal, oldVal) {
  362. if (this.videoList.length - this.videoIndex - 1 <= this.preload) {
  363. this.loadData("update");
  364. }
  365. this.oldVideoIndex = oldVal;
  366. },
  367. },
  368. };
  369. </script>
  370. <style scoped>
  371. @import "@/static/css/common.css";
  372. .main-right {
  373. margin-bottom: 100px;
  374. }
  375. .bg-red {
  376. background: red;
  377. }
  378. .flex-row {
  379. display: flex;
  380. flex-direction: row;
  381. }
  382. .flex-sub {
  383. flex: 1;
  384. /* flex-shrink: 0;*/
  385. }
  386. .share {
  387. border-top-left-radius: 26rpx;
  388. border-top-right-radius: 26rpx;
  389. }
  390. .share-scroll-view {
  391. /* #ifndef APP-PLUS */
  392. white-space: nowrap;
  393. /* #endif */
  394. }
  395. .share-scroll-view-item {
  396. /* #ifndef APP-PLUS */
  397. display: inline-flex;
  398. /* #endif */
  399. margin-right: 36rpx;
  400. }
  401. .share-scroll-view-item-button {
  402. background-color: rgba(0, 0, 0, 0);
  403. border: 0;
  404. padding: 0;
  405. flex-direction: column;
  406. }
  407. .share-scroll-view-item-button-icon {
  408. width: 100rpx;
  409. height: 100rpx;
  410. border-radius: 5000rpx;
  411. }
  412. /* #ifndef APP-PLUS */
  413. button:after {
  414. border: 0;
  415. }
  416. /* #endif */
  417. .video {
  418. background-color: #000000;
  419. }
  420. .left-describe {
  421. /* #ifndef APP-PLUS */
  422. display: inline;
  423. /* #endif */
  424. }
  425. .main-right {
  426. width: 98rpx;
  427. }
  428. .main-right-user {
  429. height: 116rpx;
  430. width: 98rpx;
  431. }
  432. .main-right-user-follow {
  433. width: 40rpx;
  434. height: 40rpx;
  435. bottom: 0;
  436. z-index: 999;
  437. }
  438. .main-right-image {
  439. width: 98rpx;
  440. height: 98rpx;
  441. }
  442. .main-right-img {
  443. width: 90rpx;
  444. height: 90rpx;
  445. }
  446. .goods {
  447. /* #ifndef APP-PLUS */
  448. white-space: nowrap;
  449. /* #endif */
  450. height: 174rpx;
  451. }
  452. .goods-item {
  453. /* #ifndef APP-PLUS */
  454. display: inline-block;
  455. /* #endif */
  456. background-color: rgba(255, 255, 255, 0.9);
  457. border-radius: 18rpx;
  458. margin-left: 14rpx;
  459. padding: 14rpx;
  460. height: 154rpx;
  461. }
  462. .goods-item-img {
  463. height: 126rpx;
  464. width: 126rpx;
  465. margin-right: 14rpx;
  466. border-radius: 4rpx;
  467. }
  468. .comment {
  469. background-color: rgba(10, 10, 10, 0.9);
  470. border-top: 2rpx solid rgba(255, 255, 255, 0.1);
  471. border-top-left-radius: 26rpx;
  472. border-top-right-radius: 26rpx;
  473. }
  474. </style>