submitVideo.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <template>
  2. <view class="task-form-item form-item-media">
  3. <view class="form-lable">
  4. <text><text class="form-must" v-if="rule && rule.required">* </text>视频:</text>
  5. <text class="form-media-num">({{videos.length}}/{{num}})</text>
  6. </view>
  7. <view class="form-img-video">
  8. <view v-if="videos.length < num " class="updata-btn img-video-item" @click.stop="onChooseVideo()">
  9. <text class="iconfont_yige">&#xe69f;</text>
  10. <text>请上传视频</text>
  11. </view>
  12. <!-- <view class="img-video-box img-video-item" v-for="(item , index) in photos_list"
  13. @click.stop="onBigImg(index)">
  14. <view class="del-img-video iconfont_yige" @click.stop="delphotos(index)" v-if="!checkPage">&#xe867;
  15. </view>
  16. <image class="img-video" :src="item" mode="aspectFit"></image>
  17. </view> -->
  18. <view class="img-video-box img-video-item" v-for="(item,index) in videos" :key="`video_${index}`"
  19. @click.stop="onplay(item)">
  20. <view class="del-img-video iconfont_yige" v-if="!checkPage" @click.stop="delVldeo(index)">&#xe867;
  21. </view>
  22. <image class="img-video" :src="item + '?x-oss-process=video/snapshot,t_0,f_jpg'" mode="aspectFit" />
  23. </view>
  24. </view>
  25. <uni-popup ref="videoPlayRef" maskBg="rgba(0, 0, 0,.7)" @change="popupChange">
  26. <view class="video-play" style="width: 100vw;">
  27. <video autoplay v-if="playVideoUrl" style="width: 100%;max-height: 60vh;" :src="playVideoUrl" />
  28. </view>
  29. </uni-popup>
  30. </view>
  31. </template>
  32. <script>
  33. import {
  34. getcheckBigFile_Api,
  35. setUpload_tag_Api,
  36. getMargeTag_Api
  37. } from "@/api/task.js"
  38. export default {
  39. name: 'submitVideo',
  40. model: {
  41. prop: ['videos'],
  42. event: ['onChange']
  43. },
  44. props: {
  45. checkPage: {
  46. type: Boolean,
  47. default: false
  48. },
  49. num: {
  50. type: Number,
  51. default: 1
  52. },
  53. rule: {
  54. type: Object,
  55. default: null
  56. },
  57. videos: {
  58. type: Array,
  59. default: () => [],
  60. require: true
  61. },
  62. },
  63. data() {
  64. return {
  65. uploadingLoading: false,
  66. Storage_key: 'partUploadData',
  67. File_V: null,
  68. tempFilePath: null,
  69. playVideoUrl: '',
  70. }
  71. },
  72. watch: {
  73. uploadingLoading: {
  74. handler(newL, oldL) {
  75. if (newL) {
  76. uni.showLoading({
  77. title: '上传视频中',
  78. mask: true
  79. })
  80. } else {
  81. uni.hideLoading()
  82. }
  83. },
  84. }
  85. },
  86. mounted() {
  87. },
  88. methods: {
  89. popupChange(e) {
  90. if (!e || !e.show) {
  91. this.playVideoUrl = null;
  92. }
  93. },
  94. // 播放视频
  95. onplay(url) {
  96. try {
  97. this.playVideoUrl = url;
  98. this.$refs.videoPlayRef.open();
  99. this.$nextTick(() => {
  100. try {
  101. this.videoContext = uni.createVideoContext('myVideo');
  102. this.videoContext.play();
  103. } catch (e) {
  104. console.log('onpssssslay = ', e)
  105. //TODO handle the exception
  106. }
  107. })
  108. } catch (e) {
  109. console.log('onplay = ', e)
  110. //TODO handle the exception
  111. }
  112. },
  113. delVldeo(index) {
  114. this.videos.splice(index, 1);
  115. },
  116. onChooseVideo() {
  117. try {
  118. let that = this;
  119. uni.chooseVideo({
  120. sourceType: ['camera', 'album'],
  121. compressed: false, // 压缩
  122. success: res_file => {
  123. const max_size = 200 * 1024 * 1024;
  124. console.log('max_size', res_file)
  125. if (res_file.size > max_size) {
  126. uni.showToast({
  127. title: '最大上传200M视频',
  128. icon: 'none'
  129. })
  130. return
  131. };
  132. return
  133. this.uploadingLoading = true
  134. plus.io.resolveLocalFileSystemURL(res_file.tempFilePath, (entry) => {
  135. entry.file((ent) => {
  136. // 获取文件名
  137. plus.io.getFileInfo({
  138. filePath: res_file.tempFilePath,
  139. success: res_ => {
  140. // 获取文件的MD5
  141. try {
  142. // 检查是否上传过
  143. getcheckBigFile_Api({
  144. fileMd5: res_.digest,
  145. originalName: ent.name
  146. }).then(res => {
  147. const data = res.data;
  148. console.log('data = ',
  149. data)
  150. if (!data.bigStatus) {
  151. that.saveFileChunk(
  152. res_file,
  153. res_
  154. .digest,
  155. data
  156. .uploadId);
  157. } else {
  158. that.unloadVideos(
  159. data.url);
  160. }
  161. }).catch(err => {
  162. this.uploadingLoading =
  163. false;
  164. uni.showToast({
  165. title: '上传失败',
  166. icon: 'none'
  167. })
  168. })
  169. } catch (e) {
  170. this.uploadingLoading =
  171. false;
  172. uni.showToast({
  173. title: '上传失败',
  174. icon: 'none'
  175. })
  176. }
  177. }
  178. })
  179. })
  180. }, err => {
  181. console.log('alert( "Resolve file URL failed: " + e.message );', err)
  182. this.uploadingLoading = false;
  183. uni.showToast({
  184. title: '上传失败',
  185. icon: 'none'
  186. })
  187. })
  188. },
  189. fail: err => {
  190. this.uploadingLoading = false;
  191. }
  192. });
  193. } catch (e) {
  194. console.log('fileMd5 e= ', e)
  195. //TODO handle the exception
  196. }
  197. },
  198. // 保存文件片段到后台
  199. saveFileChunk(File, fileMd5, uploadId) {
  200. uni.uploadFile({
  201. url: this.$mConfig.baseUrl + `/common/upload-all?fileMd5=${fileMd5}&uploadId=${uploadId}`,
  202. filePath: File.tempFilePath,
  203. name: 'file',
  204. success: (uploadFileRes) => {
  205. const JSON_data = uploadFileRes.data;
  206. const data = JSON.parse(JSON_data);
  207. const url = data.data.url;
  208. this.unloadVideos(url)
  209. },
  210. fail: err => {
  211. this.uploadingLoading = false;
  212. uni.showToast({
  213. title: '上传失败',
  214. icon: 'none'
  215. })
  216. }
  217. });
  218. },
  219. unloadVideos(url) {
  220. this.videos.push(url)
  221. this.uploadingLoading = false;
  222. uni.showToast({
  223. title: '上传成功',
  224. icon: 'none'
  225. })
  226. }
  227. }
  228. }
  229. </script>
  230. <style lang="scss" scoped>
  231. @import '~./submint.scss';
  232. </style>