submitVideo_renderjs.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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="getFile()">
  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 module="uploadBigFile" lang="renderjs">
  33. export default {
  34. mounted() {
  35. // this.create()
  36. },
  37. methods: {
  38. onFile(file) {
  39. console.log('aaa = ', file)
  40. }
  41. }
  42. }
  43. </script>
  44. <script>
  45. import {
  46. getcheckBigFile_Api,
  47. setUpload_tag_Api,
  48. getMargeTag_Api
  49. } from "@/api/task.js"
  50. import {
  51. getFileMd5,
  52. cutFile
  53. } from "@/utils/tool.js"
  54. import SparkMD5, {
  55. hash
  56. } from 'spark-md5'
  57. import {
  58. uplaodVideo
  59. } from "@/utils/uplaodVideo"
  60. export default {
  61. name: 'submitVideo',
  62. model: {
  63. prop: ['videos'],
  64. event: ['onChange']
  65. },
  66. props: {
  67. checkPage: {
  68. type: Boolean,
  69. default: false
  70. },
  71. num: {
  72. type: Number,
  73. default: 1
  74. },
  75. rule: {
  76. type: Object,
  77. default: null
  78. },
  79. videos: {
  80. type: Array,
  81. default: () => [],
  82. require: true
  83. },
  84. },
  85. data() {
  86. return {
  87. uploadingLoading: false,
  88. Storage_key: 'partUploadData',
  89. File_V: null,
  90. tempFilePath: null,
  91. playVideoUrl: '',
  92. }
  93. },
  94. watch: {
  95. uploadingLoading: {
  96. handler(newL, oldL) {
  97. if (newL) {
  98. uni.showLoading({
  99. title: '上传视频中',
  100. mask: true
  101. })
  102. } else {
  103. uni.hideLoading()
  104. }
  105. },
  106. }
  107. },
  108. mounted() {
  109. },
  110. methods: {
  111. getFile() {
  112. uni.chooseVideo({
  113. sourceType: ['camera', 'album'],
  114. compressed: false, // 压缩
  115. success: res_file => {
  116. console.log('res_file = ', res_file)
  117. this.uploadBigFile.onFile(res_file)
  118. }
  119. })
  120. },
  121. popupChange(e) {
  122. if (!e || !e.show) {
  123. this.playVideoUrl = null;
  124. }
  125. },
  126. // 播放视频
  127. onplay(url) {
  128. try {
  129. this.playVideoUrl = url;
  130. this.$refs.videoPlayRef.open();
  131. this.$nextTick(() => {
  132. try {
  133. this.videoContext = uni.createVideoContext('myVideo');
  134. this.videoContext.play();
  135. } catch (e) {
  136. console.log('onpssssslay = ', e)
  137. //TODO handle the exception
  138. }
  139. })
  140. } catch (e) {
  141. console.log('onplay = ', e)
  142. //TODO handle the exception
  143. }
  144. },
  145. delVldeo(index) {
  146. this.videos.splice(index, 1);
  147. },
  148. onChooseVideo() {
  149. try {
  150. let that = this;
  151. uni.chooseVideo({
  152. sourceType: ['camera', 'album'],
  153. compressed: false, // 压缩
  154. success: res_file => {
  155. console.log('res_file = ', res_file)
  156. const max_size = 200 * 1024 * 1024;
  157. if (res_file.size > max_size) {
  158. uni.showToast({
  159. title: '最大上传200M视频',
  160. icon: 'none'
  161. })
  162. return
  163. };
  164. return
  165. this.uploadingLoading = true
  166. plus.io.resolveLocalFileSystemURL(res_file.tempFilePath, (entry) => {
  167. entry.file((ent) => {
  168. // 获取文件名
  169. plus.io.getFileInfo({
  170. filePath: res_file.tempFilePath,
  171. success: res_ => {
  172. // 获取文件的MD5
  173. try {
  174. // 检查是否上传过
  175. getcheckBigFile_Api({
  176. fileMd5: res_.digest,
  177. originalName: ent.name
  178. }).then(res => {
  179. const data = res.data;
  180. console.log('data = ',
  181. data)
  182. if (!data.bigStatus) {
  183. that.saveFileChunk(
  184. res_file,
  185. res_
  186. .digest,
  187. data
  188. .uploadId);
  189. } else {
  190. that.unloadVideos(
  191. data.url);
  192. }
  193. }).catch(err => {
  194. this.uploadingLoading =
  195. false;
  196. uni.showToast({
  197. title: '上传失败',
  198. icon: 'none'
  199. })
  200. })
  201. } catch (e) {
  202. this.uploadingLoading =
  203. false;
  204. uni.showToast({
  205. title: '上传失败',
  206. icon: 'none'
  207. })
  208. }
  209. }
  210. })
  211. })
  212. })
  213. },
  214. fail: err => {
  215. this.uploadingLoading = false;
  216. }
  217. });
  218. } catch (e) {
  219. console.log('fileMd5 e= ', e)
  220. //TODO handle the exception
  221. }
  222. },
  223. // 保存文件片段到后台
  224. saveFileChunk(File, fileMd5, uploadId) {
  225. uni.uploadFile({
  226. url: this.$mConfig.baseUrl + `/common/upload-all?fileMd5=${fileMd5}&uploadId=${uploadId}`,
  227. filePath: File.tempFilePath,
  228. name: 'file',
  229. success: (uploadFileRes) => {
  230. const JSON_data = uploadFileRes.data;
  231. const data = JSON.parse(JSON_data);
  232. const url = data.data.url;
  233. this.unloadVideos(url)
  234. },
  235. fail: err => {
  236. this.uploadingLoading = false;
  237. uni.showToast({
  238. title: '上传失败',
  239. icon: 'none'
  240. })
  241. }
  242. });
  243. },
  244. unloadVideos(url) {
  245. this.videos.push(url)
  246. this.uploadingLoading = false;
  247. uni.showToast({
  248. title: '上传成功',
  249. icon: 'none'
  250. })
  251. }
  252. }
  253. }
  254. </script>
  255. <style lang="scss" scoped>
  256. @import '~./submint.scss';
  257. </style>