videoList.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <template>
  2. <view class="caseList">
  3. <uni-menubar title="视频管理" />
  4. <tm-search v-model="videoParams.keyword" color="blue" @confirm="getVideos"></tm-search>
  5. <tm-tabs color="blue" @change="tabClick" v-model="activeIndex" :list="allCateList" range-key="name"
  6. align="left">
  7. </tm-tabs>
  8. <tm-row>
  9. <tm-col v-for="(item,index) in videoList" :padding="10" :grid="6" :key="index" @click="videoDetail(item)">
  10. <tm-sheet :padding="[0,0]" :margin="[10,10]">
  11. <view class="" style="position: relative;">
  12. <image :src="item.thumb" style="width: 100%;height: 260rpx;"></image>
  13. <view class="pa-10 text-size-xs"
  14. style="color: #fff;position: absolute;top: 0;right: 0rpx;background-color: #0000006b;">
  15. 共{{item.views}}次播放</view>
  16. <view class="px-15">
  17. <view class="mt-20" style="font-size: 26rpx;">
  18. <text>{{item.name}}</text>
  19. </view>
  20. <view class="mt-20" style="font-size: 24rpx;">
  21. <text style="color: #9E9E9E;">{{item.create_time}}</text>
  22. </view>
  23. <view class="pt-20 pb-20 flex flex-between" style="font-size: 24rpx;">
  24. <view v-if="item.is_edit">
  25. <tm-button theme="blue" size="s" @click="addVideoForm = item,videoShow = true">编辑
  26. </tm-button>
  27. <tm-button theme="red" size="s" @click="delVideo(item)">删除</tm-button>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. </tm-sheet>
  33. </tm-col>
  34. </tm-row>
  35. <tm-poup v-if="videoShow" v-model="videoShow" position="bottom" height="70%" :round="0">
  36. <view class="pa-20">
  37. <view class="text-xl text-bold">视频编辑</view>
  38. <tm-input name="name" required title="视频名称" v-model="addVideoForm.name"></tm-input>
  39. <picker @change="bindVideoPickerChange" :value="addVideoForm.cate_id" range-key="name"
  40. :range="cateList">
  41. <tm-input required title="选择分类" placeholder="请选择分类" disabled
  42. :value="addVideoForm.cate_id ? cateList.find(v=>v.id == addVideoForm.cate_id)['name'] : '请选择分类'">
  43. </tm-input>
  44. </picker>
  45. <view class="py-12 px-24 mx-12 round-3 border-b-1 grey text">
  46. <text class="text-size-n text-weight-b ">上传视频</text>
  47. <text class="text-grey text-size-xs px-10">(最多可以上传1个)</text>
  48. </view>
  49. <view class="py-32 mx-12">
  50. <video v-if="addVideoForm.path" style="width: 100%;" :src="addVideoForm.path" controls></video>
  51. <tm-button theme="light-green" size="n" @click="addVideo">点击选择视频</tm-button>
  52. </view>
  53. <view class="px-24">
  54. <tm-button block @click="saveAlbum">确定提交</tm-button>
  55. </view>
  56. </view>
  57. </tm-poup>
  58. <tm-flotbutton v-if="user.card_id>0" @click="videoShow = true" label="添加" :show-text="true"
  59. color="bg-gradient-blue-accent">
  60. </tm-flotbutton>
  61. </view>
  62. </template>
  63. <script>
  64. export default {
  65. data() {
  66. return {
  67. title: "",
  68. activeIndex: 0,
  69. videoList: [],
  70. videoParams: {
  71. cate_id: 0, //分类id
  72. keyword: "",
  73. page: 1 //分页页码,数字类型
  74. },
  75. videoFinish: false,
  76. videoLoding: false,
  77. isShow: 0,
  78. header: {
  79. 'Authorization': uni.getStorageSync('token'),
  80. 'Content-Type': 'multipart/form-data'
  81. },
  82. cateList: [],
  83. allCateList: [{
  84. 'name': '全部',
  85. 'id': 0
  86. }],
  87. videoShow: false,
  88. addVideoForm: {
  89. name: '',
  90. cate_id: '',
  91. path: ''
  92. }
  93. }
  94. },
  95. computed: {
  96. user() {
  97. return this.$tm.vx.state().user.userInfo || {}
  98. }
  99. },
  100. onLoad() {
  101. this.getVideoCatList()
  102. this.getVideos()
  103. },
  104. onReachBottom(e) {
  105. this.videoScroll()
  106. },
  107. methods: {
  108. videoDetail(item) {
  109. uni.navigateTo({
  110. url: "/pages/list/videoDetail?detail=" + JSON.stringify(item) + "&card_id=" + uni
  111. .getStorageSync('card_id')
  112. })
  113. },
  114. getVideoCatList(id) {
  115. this.$tm.request.post('video/cate').then(res => {
  116. this.cateList = res.data
  117. this.allCateList = [...this.allCateList, ...this.cateList]
  118. })
  119. },
  120. tabClick(e) {
  121. this.activeIndex = e
  122. this.videoParams.cate_id = this.allCateList[e].id
  123. this.getVideos()
  124. },
  125. getVideos() {
  126. this.$tm.request.post('video/list', this.videoParams).then(res => {
  127. this.videoList = res.data
  128. })
  129. },
  130. addVideo() {
  131. let that = this
  132. uni.chooseMedia({
  133. count: 1,
  134. mediaType: ['video'],
  135. sourceType: ['album'],
  136. maxDuration: 60,
  137. success(res) {
  138. let item = res.tempFiles[0]
  139. uni.showToast({
  140. title: '上传中',
  141. icon: "none"
  142. });
  143. uni.uploadFile({
  144. url: 'https://cardoa.platomix.net/api/upload', //仅为示例,非真实的接口地址
  145. filePath: item.tempFilePath,
  146. name: 'file',
  147. header: that.header,
  148. success: (uploadFileRes) => {
  149. let video = JSON.parse(uploadFileRes.data)
  150. uni.uploadFile({
  151. url: 'https://cardoa.platomix.net/api/upload', //仅为示例,非真实的接口地址
  152. filePath: item.thumbTempFilePath,
  153. name: 'file',
  154. header: that.header,
  155. success: (imgdata) => {
  156. imgdata = JSON.parse(imgdata.data)
  157. uni.hideToast();
  158. that.addVideoForm.path = video.data
  159. that.addVideoForm.thumb = imgdata.data
  160. that.addVideoForm.duration = item.duration
  161. that.addVideoForm.height = item.height
  162. that.addVideoForm.width = item.width
  163. that.addVideoForm.size = item.size
  164. }
  165. });
  166. }
  167. });
  168. }
  169. })
  170. },
  171. delVideo(item) {
  172. let that = this
  173. uni.showModal({
  174. title: '提示',
  175. content: '是否永久删除',
  176. success(res) {
  177. if (res.confirm) {
  178. that.$tm.request.post('video/update', {
  179. id: item.id,
  180. isdel: true,
  181. }).then(res => {
  182. that.getVideos()
  183. })
  184. } else if (res.cancel) {}
  185. }
  186. });
  187. },
  188. videoScroll(etype) {
  189. this.videoParams.page++
  190. this.$tm.request.post('video/list', this.videoParams).then(res => {
  191. this.videoLoding = false
  192. if (res.data.length > 0) {
  193. res.data.forEach(val => {
  194. this.videoList.push(val)
  195. })
  196. }
  197. })
  198. },
  199. bindVideoPickerChange(o) {
  200. this.addVideoForm.cate_id = this.cateList[o.detail.value].id
  201. },
  202. saveAlbum() {
  203. this.$tm.request.post('video/update', this.addVideoForm).then(res => {
  204. this.getVideos()
  205. })
  206. }
  207. }
  208. }
  209. </script>
  210. <style scoped lang="scss">
  211. .caseList {
  212. // background-color: #f5f5f5;
  213. }
  214. </style>