VideoList.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <template>
  2. <div>
  3. <el-row class="movie-list">
  4. <el-checkbox v-model="checkAll" :indeterminate="isIndeterminate" @change="handleCheckAllChange">全选</el-checkbox>
  5. <el-button style="float: right; padding: 3px 0" type="text" @click="onSubmit">发布</el-button>
  6. </el-row>
  7. <!--电影列表,与推荐列表-->
  8. <el-row class="movie-list">
  9. <!--电影列表-->
  10. <el-col>
  11. <el-checkbox-group v-model="checkedVideos" @change="handleCheckedChange">
  12. <el-checkbox v-for="video in dataList" :key="video.videoId" :label="video.videoId">
  13. <div style="cursor: pointer" :title="video.title">
  14. <el-image
  15. lazy
  16. fit="cover"
  17. class="coverImg"
  18. :src="video.coverUrl"
  19. />
  20. <span style="position: absolute; top: 0; left: 60%; color:red"> {{ video.duration }} </span>
  21. <div style="padding: 14px">
  22. <router-link style="text-decoration-line: none" target="_blank" :to="`/video/${video.videoId}`">
  23. <span style="left: 0;margin-bottom: 0px;color: black;">
  24. {{ video.title | ellipsis }}
  25. </span>
  26. </router-link>
  27. </div>
  28. </div>
  29. </el-checkbox>
  30. </el-checkbox-group>
  31. <el-col :span="24" class="pagination">
  32. <el-pagination
  33. :small="screenWidth <= 768"
  34. layout="prev, pager, next"
  35. :page-size="pageSize"
  36. :current-page="currentPage"
  37. :total="totalSize"
  38. @current-change="handleCurrentChange"
  39. />
  40. </el-col>
  41. </el-col>
  42. </el-row>
  43. <el-dialog :visible.sync="showDialog" width="30%" center>
  44. <el-card class="box-card" style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  45. <div slot="header" class="clearfix">
  46. <span>修改视频所有者</span>
  47. <el-button style="float: right; padding: 10px" type="text" @click="onUpdate">保存修改</el-button>
  48. </div>
  49. <div class="text item">
  50. <el-input
  51. v-model="jsonData.newUserId"
  52. placeholder="新用户 ID"
  53. style="margin-left: 5px;width: 220px"
  54. prefix-icon="el-icon-search"
  55. />
  56. </div>
  57. </el-card>
  58. </el-dialog>
  59. </div>
  60. </template>
  61. <script>
  62. import { getUserVideos } from '@/api/video'
  63. import { updateVideoOwner } from '@/api/video_edit'
  64. import { getUserInfo } from '@/api/user'
  65. export default {
  66. name: 'VideoList',
  67. filters: {
  68. ellipsis(value) {
  69. if (!value) return ''
  70. const max = 20
  71. if (value.length > max) {
  72. return value.slice(0, max) + '...'
  73. }
  74. return value
  75. }
  76. },
  77. data() {
  78. return {
  79. // 屏幕宽度, 为了控制分页条的大小
  80. screenWidth: document.body.clientWidth,
  81. currentPage: 1,
  82. pageSize: 120,
  83. totalSize: 0,
  84. dataList: [],
  85. checkAll: false,
  86. checkedVideos: [],
  87. cityOptions: [],
  88. isIndeterminate: true,
  89. showDialog: false,
  90. jsonData: {
  91. oldUserId: null,
  92. newUserId: null,
  93. videoIds: null
  94. }
  95. }
  96. },
  97. created() {
  98. document.title = 'VideoList'
  99. this.userId = this.$route.params.userId
  100. var pnStr = this.$route.query.pn
  101. if (pnStr === null || pnStr === undefined) {
  102. pnStr = 1
  103. }
  104. getUserInfo(this.userId).then(resp => {
  105. if (resp.code === 0) {
  106. this.user = resp.data
  107. document.title = this.user.screenName + '的视频'
  108. }
  109. })
  110. this.currentPage = parseInt(pnStr)
  111. this.userVideoListWrapper(this.currentPage, this.userId)
  112. },
  113. mounted() {
  114. // 当窗口宽度改变时获取屏幕宽度
  115. window.onresize = () => {
  116. return () => {
  117. window.screenWidth = document.body.clientWidth
  118. this.screenWidth = window.screenWidth
  119. }
  120. }
  121. },
  122. methods: {
  123. handleCurrentChange(currentPage) {
  124. this.currentPage = currentPage
  125. this.$router.push({
  126. path: '/edit/videolist/' + this.userId,
  127. query: {
  128. pn: this.currentPage
  129. }
  130. })
  131. this.$router.go(0)
  132. },
  133. userVideoListWrapper(pageNumber, userId) {
  134. this.dataList = []
  135. this.totalSize = 0
  136. getUserVideos(userId, pageNumber).then(resp => {
  137. if (resp.code === 0) {
  138. const respData = resp.data
  139. this.dataList = respData.list
  140. this.totalSize = respData.totalSize
  141. this.showEmpty = this.dataList.length === 0
  142. for (const item of this.dataList) {
  143. // 使用 videoId 作为 checked 的值
  144. this.cityOptions.push(item.videoId)
  145. }
  146. }
  147. })
  148. },
  149. handleCheckAllChange(val) {
  150. this.checkedVideos = val ? this.cityOptions : []
  151. this.isIndeterminate = false
  152. },
  153. handleCheckedChange(value) {
  154. const checkedCount = value.length
  155. this.checkAll = checkedCount === this.cityOptions.length
  156. this.isIndeterminate = checkedCount > 0 && checkedCount < this.cityOptions.length
  157. // console.log(value)
  158. },
  159. onSubmit() {
  160. this.jsonData.oldUserIdStr = this.userId
  161. // this.jsonData.newUserId = 10196
  162. this.jsonData.videoIds = this.checkedVideos
  163. this.showDialog = true
  164. },
  165. onUpdate() {
  166. updateVideoOwner(this.jsonData).then(resp => {
  167. if (resp.code !== 0) {
  168. this.$message.error(resp.msg)
  169. } else {
  170. this.checkedVideos = []
  171. this.checkAll = false
  172. this.$router.go(0)
  173. }
  174. }).finally(e => {
  175. this.showDialog = false
  176. this.jsonData.oldUserIdStr = this.userId
  177. this.jsonData.newUserId = null
  178. this.jsonData.videoIds = []
  179. })
  180. }
  181. }
  182. }
  183. </script>
  184. <style scoped>
  185. .movie-list {
  186. padding-top: 5px;
  187. padding-left: 1%;
  188. padding-right: 1%;
  189. }
  190. .pagination {
  191. text-align: center;
  192. padding: 10px;
  193. }
  194. .imgs {
  195. position: relative;
  196. }
  197. .coverImg {
  198. width: 100%;
  199. height: 175px;
  200. display: block;
  201. }
  202. </style>