videoList.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. <template>
  2. <view class="container">
  3. <view class="search-box">
  4. <uni-search-bar ref="searchBar" radius="5" placeholder="搜索" clearButton="auto" cancelButton="none" bgColor="#F8F8F8"
  5. @confirm="search" class="search-bar" />
  6. </view>
  7. <scroll-view class="video-box" scroll-y="true" @scrolltolower="handleLoadMore()">
  8. <view style="padding-top: 20px;background-color: #FFFFFF;" v-if="!videoList.length">
  9. <u-divider color="#909399" border-color="#909399">没有更多了</u-divider>
  10. </view>
  11. <view class="video-col" v-for="(item, index) in videoList" :key="index" @click="goToVideoDetail(item)">
  12. <image class="video-img" :src="videoType == 1 ? item.imgUrl : item.coverUrl" mode="aspectFill"></image>
  13. <view class="video-title">{{videoType == 1 ? item.liveName : item.videoName}}</view>
  14. <view class="video-date" v-if="videoType == 1">直播时间:{{item.liveStartTime}}-{{item.liveEndTime}}</view>
  15. <view class="video-mask" v-if="videoType == 1 && item.liveStatus == 2">
  16. <view class="video-mask-horn"></view>
  17. <view class="video-mask-text">未开播</view>
  18. </view>
  19. </view>
  20. </scroll-view>
  21. <u-top-tips ref="uTips"></u-top-tips>
  22. <view class="uni-popup-dialog" :hidden="show_qx">
  23. <view class="uni-dialog-title">
  24. <text class="uni-dialog-title-text">提示</text>
  25. </view>
  26. <view class="uni-dialog-content">
  27. <text class="uni-dialog-content-text">请在设置中开启摄像头权限和麦克风权限</text>
  28. </view>
  29. <view class="uni-dialog-button-group">
  30. <button class="uni-dialog-button uni-border-left" open-type="openSetting" @click="closeSetting">
  31. 设置权限
  32. </button>
  33. </view>
  34. </view>
  35. <view class="qx_bg" :hidden="show_qx">
  36. </view>
  37. </view>
  38. </template>
  39. <script>
  40. const NET = require('@/utils/request')
  41. const API = require('@/config/api')
  42. export default {
  43. data() {
  44. return {
  45. show_qx:true,
  46. videoType: 1,
  47. pageIndex: 1,
  48. isOver: false,
  49. videoName: '',
  50. videoList: [],
  51. }
  52. },
  53. onLoad(options) {
  54. this.videoType = options.videoType
  55. if (this.videoType == 2) {
  56. uni.setNavigationBarTitle({
  57. title: '短视频'
  58. });
  59. }
  60. this.getVideoList()
  61. },
  62. onPullDownRefresh() {
  63. this.pageIndex = 1
  64. this.videoList = []
  65. this.getVideoList('refresh')
  66. },
  67. methods: {
  68. closeSetting:function(){
  69. this.show_qx=true;
  70. },
  71. // 搜索直播
  72. search(data) {
  73. this.videoName = data.value
  74. this.videoList = []
  75. this.pageIndex = 1
  76. this.getVideoList()
  77. },
  78. // 懒加载
  79. handleLoadMore() {
  80. if (!this.isOver) {
  81. this.pageIndex++
  82. this.getVideoList()
  83. }
  84. },
  85. // 获取直播列表
  86. getVideoList(type) {
  87. NET.request((this.videoType == 1 ? API.getLiveTelecastList : API.getShortVideo) + '/' + this.pageIndex + '/10', {
  88. liveName: this.videoName,
  89. videoName: this.videoName,
  90. }, 'GET').then(res => {
  91. if (type == 'refresh') {
  92. uni.stopPullDownRefresh();
  93. }
  94. this.isOver = res.data.list.length != 10
  95. this.videoList = this.videoList.concat(res.data.list)
  96. }).catch(res => {
  97. this.$refs.uTips.show({
  98. title: '获取直播列表失败',
  99. type: 'warning',
  100. })
  101. })
  102. },
  103. // 跳转直播详情
  104. goToVideoDetail(item) {
  105. if (this.videoType != 1) {
  106. uni.setStorage({
  107. key: 'videoUrl',
  108. data: item.mediaUrl
  109. })
  110. }else{
  111. uni.setStorage({
  112. key: 'liveImgUrl',
  113. data: item.imgUrl
  114. })
  115. uni.setStorage({
  116. key: 'liveName',
  117. data: item.liveName
  118. })
  119. }
  120. if(this.videoType == 1){
  121. var that=this;
  122. if(item.liveStatus==2){
  123. this.$refs.uTips.show({
  124. title: '直播未开始',
  125. type: 'warning',
  126. })
  127. wx.requestSubscribeMessage({
  128. tmplIds: ['y0X1cZfbEMg7HdTGN_bW8v7TKeI3M0CHSVTY1zStIXM'],
  129. success(res) {
  130. if(res.y0X1cZfbEMg7HdTGN_bW8v7TKeI3M0CHSVTY1zStIXM=="accept"){
  131. var post_data={liveId:item.liveId,mid:uni.getStorageSync("userData").userId}
  132. post_data.isDelete=0;
  133. NET.request(API.subscribeLive, post_data, 'POST').then(res => {
  134. //this.goodsList = res.data
  135. }).catch(res => {
  136. })
  137. }else{
  138. console.log('444', res);
  139. }
  140. //console.log('1111', res);
  141. },
  142. fail(res) {
  143. console.log('2222', res);
  144. }
  145. })
  146. return false;
  147. }
  148. if(uni.getStorageSync("firstTimeLiveUser")==""){
  149. uni.setStorage({
  150. key: 'firstTimeLiveUser',
  151. data: 1
  152. })
  153. uni.navigateTo({
  154. url: '/pagesGood/' + (that.videoType == 1 ? ('liveDetail?liveId=' + item.liveId + '&roomId=' + item.roomId) :
  155. ('videoDetail?videoId=' + item.videoId))
  156. });
  157. }else{
  158. wx.getSetting({
  159. success(res) {
  160. /*if (!res.authSetting['scope.camera']){
  161. that.show_qx=false;
  162. }else*/
  163. if (!res.authSetting['scope.record']){
  164. that.show_qx=false;
  165. }else{
  166. uni.navigateTo({
  167. url: '/pagesGood/' + (that.videoType == 1 ? ('liveDetail?liveId=' + item.liveId + '&roomId=' + item.roomId) :
  168. ('videoDetail?videoId=' + item.videoId))
  169. });
  170. }
  171. }
  172. })
  173. }
  174. }else{
  175. uni.navigateTo({
  176. url: '/pagesGood/' + (this.videoType == 1 ? ('liveDetail?liveId=' + item.liveId + '&roomId=' + item.roomId) :
  177. ('videoDetail?videoId=' + item.videoId))
  178. });
  179. }
  180. }
  181. },
  182. }
  183. </script>
  184. <style lang="less" scoped>
  185. page {
  186. width: 100%;
  187. height: 100%;
  188. }
  189. .container {
  190. width: 100%;
  191. height: 100%;
  192. .search-box {
  193. width: 100%;
  194. height: 58px;
  195. box-sizing: border-box;
  196. padding: 2px 8px 1px 8px;
  197. }
  198. .video-box {
  199. width: 100%;
  200. height: calc(100% - 58px) !important;
  201. overflow-y: auto;
  202. .video-col {
  203. float: left;
  204. background: #FFFFFF;
  205. box-shadow: 0px 3px 6px 0px rgba(0, 0, 0, 0.15);
  206. border-radius: 5px;
  207. width: calc(50% - 18px);
  208. margin-top: 4px;
  209. margin-bottom: 6px;
  210. padding-bottom: 10px;
  211. position: relative;
  212. .video-img {
  213. width: 100%;
  214. height: 170px;
  215. object-fit: cover;
  216. float: left;
  217. }
  218. .video-title {
  219. width: 100%;
  220. height: 18px;
  221. box-sizing: border-box;
  222. padding-left: 8px;
  223. float: left;
  224. font-size: 15px;
  225. font-family: PingFang SC;
  226. color: #333333;
  227. line-height: 18px;
  228. overflow: hidden;
  229. white-space: nowrap;
  230. text-overflow: ellipsis;
  231. margin: 6px 0 2px 0;
  232. }
  233. .video-date {
  234. width: 100%;
  235. box-sizing: border-box;
  236. padding-left: 8px;
  237. height: 16px;
  238. float: left;
  239. font-size: 12px;
  240. font-family: PingFang SC;
  241. color: #52A63A;
  242. line-height: 16px;
  243. overflow: hidden;
  244. white-space: nowrap;
  245. text-overflow: ellipsis;
  246. }
  247. .video-mask {
  248. width: 100%;
  249. height: 100%;
  250. position: absolute;
  251. background-color: rgba(0, 0, 0, 0.3);
  252. border-radius: 5px;
  253. .video-mask-horn {
  254. width: 0;
  255. height: 0;
  256. border-bottom: 4px solid #52A63A;
  257. border-right: 4px solid transparent;
  258. position: absolute;
  259. right: -4px;
  260. top: 8px;
  261. }
  262. .video-mask-text {
  263. position: absolute;
  264. right: -4px;
  265. top: 12px;
  266. width: 52px;
  267. height: 18px;
  268. border-radius: 9px 0 0 9px;
  269. background: #52A63A;
  270. line-height: 18px;
  271. font-size: 10px;
  272. font-family: PingFang SC;
  273. color: #FFFFFF;
  274. text-align: center;
  275. }
  276. }
  277. }
  278. .video-col:nth-child(odd) {
  279. margin-left: 16px;
  280. margin-right: 2px;
  281. }
  282. .video-col:nth-child(even) {
  283. margin-left: 2px;
  284. margin-right: 16px;
  285. }
  286. }
  287. }
  288. .uni-popup-dialog {
  289. width: 80vw;
  290. border-radius: 15px;
  291. background-color: #fff;
  292. position: fixed;
  293. margin-left: 10vw;
  294. top: 34vh;
  295. z-index: 11;
  296. }
  297. .uni-dialog-title {
  298. /* #ifndef APP-NVUE */
  299. display: flex;
  300. /* #endif */
  301. flex-direction: row;
  302. justify-content: center;
  303. padding-top: 15px;
  304. padding-bottom: 5px;
  305. }
  306. .uni-dialog-title-text {
  307. font-size: 16px;
  308. font-weight: 500;
  309. }
  310. .uni-dialog-content {
  311. /* #ifndef APP-NVUE */
  312. display: flex;
  313. /* #endif */
  314. flex-direction: row;
  315. justify-content: center;
  316. align-items: center;
  317. padding: 5px 15px 15px 15px;
  318. text-align: center;
  319. }
  320. .uni-dialog-content-text {
  321. font-size: 14px;
  322. color: #6e6e6e;
  323. }
  324. .uni-dialog-button-group {
  325. /* #ifndef APP-NVUE */
  326. display: flex;
  327. /* #endif */
  328. flex-direction: row;
  329. border-top-color: #f5f5f5;
  330. border-top-style: solid;
  331. border-top-width: 1px;
  332. }
  333. .uni-dialog-button {
  334. /* #ifndef APP-NVUE */
  335. display: flex;
  336. /* #endif */
  337. background: rgba(0, 0, 0, 0);
  338. border: none;
  339. flex: 1;
  340. flex-direction: row;
  341. justify-content: center;
  342. align-items: center;
  343. height: 45px;
  344. }
  345. .uni-border-left {
  346. border-left-color: #f0f0f0;
  347. border-left-style: solid;
  348. border-left-width: 0px;
  349. }
  350. .uni-dialog-button-text {
  351. font-size: 14px;
  352. }
  353. .uni-button-color {
  354. color: #007aff;
  355. }
  356. .uni-dialog-input {
  357. flex: 1;
  358. font-size: 14px;
  359. }
  360. .uni-popup__success {
  361. color: #4cd964;
  362. }
  363. .uni-popup__warn {
  364. color: #f0ad4e;
  365. }
  366. .uni-popup__error {
  367. color: #dd524d;
  368. }
  369. .uni-popup__info {
  370. color: #909399;
  371. }
  372. .qx_bg{
  373. width: 100vw;
  374. height: 100vh;
  375. background: rgba(0, 0, 0, 0.25);
  376. position: fixed;
  377. top: 0px;
  378. left: 0px;
  379. z-index: 10;
  380. }
  381. </style>