submitVideo - 副本 (3).vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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>视频{{showVideo}}:</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 videos">
  13. <view class="video-cover">
  14. <video :show-center-play-btn="false" :show-loading="false" :controls="false" class="img-video"
  15. :src="item" v-if="!checkPage && showVideo" @click.stop="onplay(item)">
  16. <cover-view class="video-cover-view" @click.stop="onplay(item)"></cover-view>
  17. <!-- <cover-view class="video-cover-view">
  18. <cover-view class="del-img-video" @click.stop="delVldeo(index)">
  19. <cover-image class="cover-image" src="../static/close.png"></cover-image>
  20. </cover-view>
  21. </cover-view> -->
  22. </video>
  23. </view>
  24. </view>
  25. </view>
  26. <uni-popup ref="videoPlayRef" maskBg="rgba(0, 0, 0,.7)" @change="popupChange">
  27. <view class="video-play" style="width: 100vw;">
  28. <video autoplay v-if="playVideoUrl" style="width: 100%;max-height: 60vh;" :src="playVideoUrl" />
  29. </view>
  30. </uni-popup>
  31. </view>
  32. </template>
  33. <script>
  34. import {
  35. getcheckBigFile_Api,
  36. setUpload_tag_Api,
  37. getMargeTag_Api
  38. } from "@/api/task.js"
  39. import {
  40. getFileMd5,
  41. cutFile
  42. } from "@/utils/tool.js"
  43. import {
  44. uplaodVideo
  45. } from "@/utils/uplaodVideo"
  46. export default {
  47. name: 'submitVideo',
  48. model: {
  49. prop: ['videos'],
  50. event: ['onChange']
  51. },
  52. props: {
  53. checkPage: {
  54. type: Boolean,
  55. default: false
  56. },
  57. num: {
  58. type: Number,
  59. default: 1
  60. },
  61. rule: {
  62. type: Object,
  63. default: null
  64. },
  65. videos: {
  66. type: Array,
  67. default: () => [],
  68. require: true
  69. },
  70. },
  71. data() {
  72. return {
  73. showVideo: true,
  74. uploadingLoading: false,
  75. Storage_key: 'partUploadData',
  76. File_V: null,
  77. tempFilePath: null,
  78. playVideoUrl: '',
  79. }
  80. },
  81. watch: {
  82. uploadingLoading: {
  83. handler(newL, oldL) {
  84. if (newL) {
  85. uni.showLoading({
  86. title: '上传视频中',
  87. mask: true
  88. })
  89. } else {
  90. uni.hideLoading()
  91. }
  92. },
  93. }
  94. },
  95. mounted() {
  96. },
  97. methods: {
  98. popupChange(e) {
  99. if (!e || !e.show) {
  100. this.playVideoUrl = null;
  101. }
  102. this.showVideo = !e.show;
  103. },
  104. // 播放视频
  105. onplay(url) {
  106. console.log('url = ', url)
  107. try {
  108. this.playVideoUrl = url;
  109. this.$refs.videoPlayRef.open();
  110. this.$nextTick(() => {
  111. try {
  112. this.videoContext = uni.createVideoContext('myVideo');
  113. this.videoContext.play()
  114. this.showVideo = false;
  115. } catch (e) {
  116. console.log('onpssssslay = ', e)
  117. //TODO handle the exception
  118. }
  119. })
  120. } catch (e) {
  121. console.log('onplay = ', e)
  122. //TODO handle the exception
  123. }
  124. },
  125. delVldeo(index) {
  126. this.videos.splice(index, 1);
  127. },
  128. onChooseVideo() {
  129. try {
  130. uni.removeStorageSync(this.Storage_key);
  131. } catch (e) {
  132. // error
  133. }
  134. try {
  135. let that = this;
  136. uni.chooseVideo({
  137. sourceType: ['camera', 'album'],
  138. compressed: false, // 压缩
  139. success: res_file => {
  140. this.uploadingLoading = true
  141. plus.io.resolveLocalFileSystemURL(res_file.tempFilePath, (entry) => {
  142. entry.file((ent) => {
  143. // 获取文件名
  144. plus.io.getFileInfo({
  145. filePath: res_file.tempFilePath,
  146. success: res_ => {
  147. // 获取文件的MD5
  148. try {
  149. // 检查是否上传过
  150. getcheckBigFile_Api({
  151. fileMd5: res_.digest,
  152. originalName: ent.name
  153. }).then(res => {
  154. const data = res.data;
  155. console.log('data = ',
  156. data)
  157. if (!data.bigStatus) {
  158. that.saveFileChunk(
  159. res_file,
  160. res_
  161. .digest,
  162. data
  163. .uploadId);
  164. } else {
  165. that.unloadVideos(
  166. data.url);
  167. }
  168. }).catch(err => {
  169. this.uploadingLoading =
  170. false;
  171. })
  172. } catch (e) {
  173. this.uploadingLoading =
  174. false;
  175. }
  176. }
  177. })
  178. })
  179. })
  180. },
  181. fail: err => {
  182. this.uploadingLoading = false;
  183. }
  184. });
  185. } catch (e) {
  186. console.log('fileMd5 e= ', e)
  187. //TODO handle the exception
  188. }
  189. },
  190. // 保存文件片段到后台
  191. saveFileChunk(File, fileMd5, uploadId) {
  192. uni.uploadFile({
  193. url: this.$mConfig.baseUrl + `/common/upload-all?fileMd5=${fileMd5}&uploadId=${uploadId}`,
  194. filePath: File.tempFilePath,
  195. name: 'file',
  196. success: (uploadFileRes) => {
  197. const JSON_data = uploadFileRes.data;
  198. const data = JSON.parse(JSON_data);
  199. const tag = data.data.tag;
  200. this.unloadVideos()
  201. },
  202. fail: err => {
  203. this.uploadingLoading = false;
  204. }
  205. });
  206. },
  207. unloadVideos(url) {
  208. this.videos.push(url)
  209. this.uploadingLoading = false;
  210. uni.showToast({
  211. title: '上传成功',
  212. icon: 'none'
  213. })
  214. }
  215. }
  216. }
  217. </script>
  218. <style lang="scss" scoped>
  219. @import '~./submint.scss';
  220. .video-cover {
  221. position: absolute;
  222. left: 0;
  223. right: 0;
  224. top: 0;
  225. bottom: 0;
  226. z-index: 2;
  227. }
  228. .img-video-box {
  229. position: relative;
  230. .video-cover-view {
  231. width: 100%;
  232. height: 100%;
  233. background-color: red;
  234. .del-img-video {
  235. position: absolute;
  236. right: -23rpx;
  237. top: -23rpx;
  238. width: 66rpx;
  239. // width: 46rpx;
  240. height: 46rpx;
  241. background-color: #E5404F;
  242. border-radius: 50%;
  243. text-align: center;
  244. line-height: 46rpx;
  245. color: #fff;
  246. font-size: 24rpx;
  247. display: flex;
  248. flex-direction: row;
  249. justify-content: center;
  250. align-items: center;
  251. .cover-image {
  252. width: 30rpx;
  253. height: 30rpx;
  254. }
  255. }
  256. }
  257. }
  258. </style>