index.vue 7.4 KB

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