index.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. <template>
  2. <view class="container">
  3. <view class="media-card">
  4. <view class="media-head">
  5. <view class="media-title">直播</view>
  6. <view class="media-handle">
  7. <view class="handle-card" @click="goToSetLive">
  8. <view class="iconfont iconshezhi"></view>
  9. <view class="handle-card-text">直播设置</view>
  10. </view>
  11. </view>
  12. </view>
  13. <view class="media-content">
  14. <image class="live-card" src="../../static/images/live-card.png" @click="goToLiveDetail"></image>
  15. </view>
  16. </view>
  17. <view class="media-card">
  18. <view class="media-head">
  19. <view class="media-title">短视频</view>
  20. <view class="media-handle">
  21. <view class="handle-text" style="color: #51A539;" @click="manageType = true" v-if="!manageType">管理</view>
  22. <view class="handle-text" style="color: #333333;" @click="manageType = false" v-if="manageType">取消</view>
  23. <view class="handle-text" style="color: #F95151;" @click="deleteVideo()" v-if="manageType">删除</view>
  24. <view class="handle-card" v-if="!manageType" @click="addVideo">
  25. <view class="iconfont iconshangchuan"></view>
  26. <view class="handle-card-text">上传视频</view>
  27. </view>
  28. </view>
  29. </view>
  30. <view class="media-content">
  31. <view class="video-card" v-for="(item, index) in list" :key="index" @click="!manageType&&goToVideo(item)">
  32. <image class="video-img" :src="item.coverUrl"></image>
  33. <view class="video-title-box" @click.stop="setVideoStatue(item)">
  34. <text class="iconfont" :class="item.check ? 'iconqueding' : 'iconfeigouxuan'"
  35. v-if="manageType"></text>
  36. <view class="video-title">
  37. {{item.videoName}}
  38. </view>
  39. </view>
  40. </view>
  41. <u-divider :color="isOver ? '#909399' : '#51A539'" :border-color="isOver ? '#909399' : '#51A539'" @click="handleLoadMore()">
  42. <u-loading mode="circle" v-if="loadingData"></u-loading>{{loadingData ? '加载中' : (isOver ? '没有更多了' : '点击加载更多')}}
  43. </u-divider>
  44. </view>
  45. </view>
  46. <u-top-tips ref="uTips"></u-top-tips>
  47. </view>
  48. </view>
  49. </template>
  50. <script>
  51. const NET = require('@/utils/request')
  52. const API = require('@/config/api')
  53. export default {
  54. data() {
  55. return {
  56. liveId: '',
  57. pageIndex: 1,
  58. isOver: false,
  59. list: [],
  60. manageType: false,
  61. loadingData: false,
  62. }
  63. },
  64. onLoad() {},
  65. onShow() {
  66. this.getBaseData()
  67. },
  68. onPullDownRefresh() {
  69. this.getBaseData('refresh')
  70. },
  71. methods: {
  72. // 取消选中
  73. setVideoStatue(item){
  74. item.check = !item.check
  75. },
  76. // 获取全部数据
  77. getBaseData(refresh) {
  78. this.pageIndex = 1
  79. this.list = []
  80. this.getList()
  81. NET.request(API.getLiveId, {}, 'GET').then(res => {
  82. if (refresh == 'refresh') {
  83. uni.stopPullDownRefresh();
  84. }
  85. if (res.data && res.data != 0) {
  86. this.liveId = res.data
  87. }
  88. }).catch(res => {
  89. this.$refs.uTips.show({
  90. title: '获取直播ID失败',
  91. type: 'warning',
  92. })
  93. })
  94. },
  95. // 直播设置
  96. goToSetLive() {
  97. uni.navigateTo({
  98. url: '/pagesMedia/liveOption'
  99. });
  100. },
  101. // 查看直播详情
  102. goToLiveDetail() {
  103. if (this.liveId) {
  104. uni.navigateTo({
  105. url: '/pagesMedia/liveDetail?liveId=' + this.liveId
  106. });
  107. } else {
  108. this.$refs.uTips.show({
  109. title: '当前无可进行的直播',
  110. type: 'warning',
  111. })
  112. }
  113. },
  114. // 新增短视频
  115. addVideo() {
  116. uni.navigateTo({
  117. url: '/pagesMedia/videoForm?type=add'
  118. });
  119. },
  120. // 懒加载
  121. handleLoadMore() {
  122. if (!this.isOver) {
  123. this.pageIndex++
  124. this.getList()
  125. }
  126. },
  127. // 获取列表数据
  128. getList() {
  129. this.loadingData = true
  130. NET.request(API.getVideoList + this.pageIndex + '/10', {}, 'GET').then(res => {
  131. this.loadingData = false
  132. this.isOver = res.data.list.length != 10
  133. res.data.list.forEach(site => {
  134. site.check = false
  135. })
  136. this.list = this.list.concat(res.data.list)
  137. }).catch(error => {
  138. this.loadingData = false
  139. this.$refs.uTips.show({
  140. title: error.data.msg,
  141. type: 'warning',
  142. })
  143. })
  144. },
  145. // 查看短视频详情
  146. goToVideo(item) {
  147. uni.setStorage({
  148. key: 'videoUrl',
  149. data: item.mediaUrl
  150. })
  151. uni.navigateTo({
  152. url: '/pagesMedia/videoDetail?videoId=' + item.videoId
  153. });
  154. },
  155. // 删除短视频
  156. deleteVideo() {
  157. let postData = ''
  158. this.list.filter(site => site.check).forEach((site, index) => {
  159. postData += (index ? '&' : '?') + 'videoIds=' + site.videoId
  160. })
  161. NET.request(API.deleteVideo + '/' + postData, {}, 'GET').then(res => {
  162. this.$refs.uTips.show({
  163. title: '删除成功',
  164. type: 'success',
  165. })
  166. this.manageType = false
  167. this.pageIndex = 1
  168. this.list = []
  169. this.getList()
  170. }).catch(error => {
  171. this.$refs.uTips.show({
  172. title: error.data.msg,
  173. type: 'warning',
  174. })
  175. })
  176. },
  177. }
  178. }
  179. </script>
  180. <style lang="less" scoped>
  181. page {
  182. width: 100%;
  183. height: 100%;
  184. }
  185. .container {
  186. width: 100%;
  187. height: 100%;
  188. float: left;
  189. background-color: #f7f7f7;
  190. overflow-y: auto;
  191. .media-card {
  192. width: 100%;
  193. float: left;
  194. background: #FFFFFF;
  195. border-radius: 0 0 10px 10px;
  196. margin-bottom: 10px;
  197. .media-head {
  198. width: 100%;
  199. height: 45px;
  200. float: left;
  201. box-sizing: border-box;
  202. padding: 6px 0 6px 15px;
  203. border-bottom: 1px solid #EDEDED;
  204. .media-title {
  205. height: 16px;
  206. float: left;
  207. margin: 8px 0;
  208. padding-left: 6px;
  209. border-left: 2px solid #51A539;
  210. font-size: 15px;
  211. font-family: PingFang SC;
  212. color: #333333;
  213. line-height: 16px;
  214. }
  215. .media-handle {
  216. height: 32px;
  217. float: right;
  218. .handle-text {
  219. height: 32px;
  220. float: left;
  221. padding: 0 10px;
  222. margin: 0 5px;
  223. font-size: 15px;
  224. font-family: PingFang SC;
  225. line-height: 32px;
  226. }
  227. .handle-card {
  228. width: 96px;
  229. height: 32px;
  230. float: left;
  231. background: #51A539;
  232. border-radius: 16px 0px 0px 16px;
  233. font-family: PingFang SC;
  234. color: #FFFFFF;
  235. display: flex;
  236. align-items: center;
  237. justify-content: center;
  238. .iconfont {
  239. font-size: 22px;
  240. }
  241. .handle-card-text {
  242. float: left;
  243. line-height: 32px;
  244. font-size: 12px;
  245. }
  246. }
  247. }
  248. }
  249. .media-content {
  250. width: 100%;
  251. float: left;
  252. padding: 10px 15px;
  253. box-sizing: border-box;
  254. .live-card {
  255. width: 100%;
  256. height: 80px;
  257. float: left;
  258. }
  259. .video-card:nth-child(odd) {
  260. margin: 0 5px 10px 0;
  261. }
  262. .video-card:nth-child(even) {
  263. margin: 0 0 10px 5px;
  264. }
  265. .video-card {
  266. width: calc(50% - 5px);
  267. height: 206px;
  268. float: left;
  269. background: #FFFFFF;
  270. box-shadow: 0px 1px 10px 0px rgba(0, 0, 0, 0.1);
  271. border-radius: 5px;
  272. overflow: hidden;
  273. .video-img {
  274. width: 100%;
  275. height: 170px;
  276. object-fit: cover;
  277. float: left;
  278. }
  279. .video-title-box {
  280. width: 100%;
  281. height: 36px;
  282. float: left;
  283. font-family: PingFang SC;
  284. line-height: 36px;
  285. display: flex;
  286. justify-content: center;
  287. .iconfont {
  288. color: #51A539;
  289. font-size: 36px;
  290. line-height: 36px;
  291. display: flex;
  292. align-items: center;
  293. }
  294. .video-title {
  295. max-width: calc(100% - 36px);
  296. height: 36px;
  297. line-height: 36px;
  298. font-size: 15px;
  299. color: #333333;
  300. overflow: hidden;
  301. text-overflow: ellipsis;
  302. white-space: nowrap;
  303. }
  304. }
  305. }
  306. }
  307. }
  308. }
  309. </style>