unloadVideo.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. <template>
  2. <view class="w-100 imgupload">
  3. <view class="w-100 flex_wrap">
  4. <view class="imgs-view" v-if="videoUrl">
  5. <video :src="videoUrl" style="height: 200rpx;
  6. width: 100%;"></video>
  7. <view class="del-btn" @click="delVideo()">
  8. <image
  9. :src="
  10. config.delIcon ||
  11. 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAA5UlEQVQ4T2NkQAP3fTXs//1njPvP8N+BkYFBCST9n4HhHiMD4wEmxv+LFDffOIishRGZc89HY9Z/BoZUdEPRNMxW2nIjDSYGN+COj8YORgYGd3yaYXL/GRh2qmy54QHigw0gxmZ0gxkZGMAuYYT4meEAMTajq2FiZHBgvOujOZeB4X8SOQYwMDDOY7zjo3EXFtqkGgKOnbs+Gv9hGsVKexm4jG3xmvPt7GGGV93FcDUoBvD7xTGwyijiNeD3k/sMHzctQhhABS9QGIgURyPFCQkWGhQlZZghxCRpWBLGyEwwAVKzMwB5V2gPAYXmLgAAAABJRU5ErkJggg=='
  12. "
  13. ></image>
  14. </view>
  15. </view>
  16. <view v-else class="upload-img-view flex_xy_center" @click="upPhoto">
  17. <image
  18. src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAYAAAA7MK6iAAAArklEQVRIS2NkGCDAOED2Mgw9i9vb2xVAoVVZWfmAnFAj28ddXV33QRaWlZUp0tvi/1CLyXI8WZpAFnZ1dY1aTFJUjwY10cE1mriIDiqoQpTEBSoGmZmZ9zMwMICLQyqC08zMzDHFxcW3YGYODotJ8eFo4iIltEBqR0suokNsNHERHVTYSi5SNA9kUJ+CtrnMSHEw1iKTFAN6e3vVQOqRy19S9JOdj0mxBJvakWcxAFpiZB+QSLWnAAAAAElFTkSuQmCC"
  19. ></image>
  20. </view>
  21. </view>
  22. </view>
  23. </template>
  24. <script>
  25. export default {
  26. name: "VideoUpload",
  27. props: {
  28. videoSrc: {
  29. //视频文件
  30. type: String,
  31. default: null,
  32. },
  33. videoSize: {
  34. //图片大小 单位M
  35. type: Number,
  36. default: 10,
  37. },
  38. formData: {
  39. type: Object,
  40. default: function () {
  41. return {};
  42. },
  43. },
  44. imgType: {
  45. //如果是小程序,这个值则没用作用
  46. type: [Array],
  47. default: function () {
  48. return ["MP4", "mp4"];
  49. },
  50. },
  51. loading: {
  52. type: Boolean,
  53. default: true,
  54. },
  55. url: {
  56. //上传图片Url
  57. type: String,
  58. },
  59. async: {
  60. type: Boolean,
  61. default: false,
  62. },
  63. header: {
  64. type: Array,
  65. default: function () {
  66. return [];
  67. },
  68. },
  69. previewMany: {
  70. type: Boolean,
  71. default: false,
  72. },
  73. config: {
  74. type: Object,
  75. default: function () {
  76. return {
  77. delIcon: "", //删除图片icon
  78. resultTip: true, //结果提示
  79. resultType: "1", //结果展示类型
  80. loadIcon: "", //加载时的图标
  81. loadText: "", //加载时的文字
  82. };
  83. },
  84. },
  85. },
  86. data() {
  87. return {
  88. videoUrl: null,
  89. startUpload: false,
  90. tipObj: {
  91. prompt: "",
  92. typeColor: "#009100",
  93. must: false, //必须要存在的时候
  94. success: "#009100", //成功-#009100; 可自定义修改
  95. warning: "#bb9300", // 警告 -#bb9300; 可自定义修改
  96. error: "#FF0000", // 失败--#FF0000; 可自定义修改
  97. },
  98. headers: {},
  99. curPlatform: "",
  100. currIndex: null,
  101. ossData: {}, //oss参数
  102. duration: null,
  103. size: null,
  104. VideoSize: 100,
  105. };
  106. },
  107. created() {
  108. this.formDataGet();
  109. },
  110. watch: {
  111. videoSrc(n, o) {
  112. this.videoUrl = n;
  113. },
  114. },
  115. methods: {
  116. delVideo(){ uni.showModal({
  117. title: "提示",
  118. content: "是否删除?",
  119. success: (res)=> {
  120. if (res.confirm) {
  121. this.videoUrl=null,
  122. this.duration=null,
  123. this.size= null,
  124. this.$emit("resultVideo", {
  125. url: this.videoUrl,
  126. size: this.size,
  127. duration: this.duration,
  128. });
  129. }}})
  130. },
  131. //上传凭证
  132. formDataGet() {
  133. let that = this;
  134. uni.request({
  135. //url: 'https://pm.lidashine.com/get-oss-sign', //oss获取参数接口地址。
  136. url: "http://47.97.79.225:9020/fileMgr/v1/oss/getOssSign",
  137. complete: (result) => {
  138. let res = JSON.parse(result.data.data);
  139. that.ossData = res;
  140. },
  141. });
  142. },
  143. // 随机生成文件名
  144. random_string(len) {
  145. len = len || 32;
  146. var chars = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz123456789";
  147. var maxPos = chars.length;
  148. var pwd = "";
  149. for (let i = 0; i < len; i++) {
  150. pwd += chars.charAt(Math.floor(Math.random() * maxPos));
  151. }
  152. return pwd;
  153. },
  154. //上传图片
  155. upPhoto() {
  156. let that = this;
  157. uni.chooseVideo({
  158. count: 1,
  159. sourceType: ["camera", "album"],
  160. success: function (res) {
  161. console.log(res, JSON.stringify(res));
  162. if (res.tempFile.size > that.VideoSize * 1024 * 1024) {
  163. uni.showToast({
  164. title: `图片不能大于${that.VideoSize}M`,
  165. icon: "none",
  166. });
  167. return false;
  168. }
  169. (that.duration = res.duration),
  170. (that.size = res.size);
  171. that.updataImg(res.tempFile, res.tempFilePath);
  172. },
  173. });
  174. },
  175. updataImg(file, filePath) {
  176. let imgname = this.random_string(8) + "." + file.name.split(".").pop();
  177. let dir = "media/" + imgname;
  178. let ossData = this.ossData;
  179. uni.showLoading();
  180. uni.uploadFile({
  181. url: ossData.host,
  182. filePath: filePath,
  183. fileType: "video",
  184. name: "file",
  185. formData: {
  186. name: imgname,
  187. key: dir,
  188. policy: ossData.policy,
  189. OSSAccessKeyId: ossData.accessid,
  190. success_action_status: "200",
  191. signature: ossData.signature,
  192. },
  193. success: (res) => {
  194. uni.hideLoading();
  195. if (res.statusCode != 200) {
  196. return;
  197. }
  198. this.videoUrl = ossData.host + "/" + dir;
  199. console.log(this.videoUrl);
  200. this.$emit("resultVideo", {
  201. url: this.videoUrl,
  202. size: this.size,
  203. duration: this.duration,
  204. });
  205. uni.showToast({
  206. title: "上传成功",
  207. icon: "success",
  208. duration: 1000,
  209. });
  210. // alert(ossRes.host+"/"+encodeURIComponent(fileName));
  211. },
  212. fail: (err) => {
  213. uni.hideLoading();
  214. console.log("uploadImage fail", err);
  215. uni.showModal({
  216. content: err.errMsg,
  217. showCancel: false,
  218. });
  219. },
  220. });
  221. },
  222. },
  223. };
  224. </script>
  225. <style scoped>
  226. .w-100 {
  227. width: 100%;
  228. }
  229. .flex {
  230. /* 转为弹性盒模型*/
  231. display: flex;
  232. }
  233. .flex_bet {
  234. /* 两端左右*/
  235. display: flex;
  236. justify-content: space-between;
  237. }
  238. .flex_wrap {
  239. /* 转为弹性盒模型并自动换行*/
  240. display: flex;
  241. flex-wrap: wrap;
  242. }
  243. .flex_xy_center {
  244. display: flex;
  245. justify-content: center;
  246. align-items: center;
  247. }
  248. .upload-img-view {
  249. height: 200rpx;
  250. width: 32%;
  251. border-radius: 10rpx;
  252. border: 4rpx dotted #f1f1f1;
  253. /* background-color: #F1F1F1; */
  254. }
  255. .upload-img-view > image {
  256. width: 70rpx;
  257. height: 70rpx;
  258. }
  259. .upload-txt {
  260. font-size: 24rpx;
  261. color: #ffffff;
  262. }
  263. .imgs-view {
  264. height: 200rpx;
  265. width: 31.5%;
  266. border-radius: 10rpx;
  267. margin-right: 1.8%;
  268. margin-bottom: 16rpx;
  269. border: 1rpx solid #f1f1f1;
  270. box-sizing: border-box;
  271. position: relative;
  272. }
  273. .result {
  274. position: absolute;
  275. bottom: 0;
  276. width: 100%;
  277. height: 45rpx;
  278. font-size: 26rpx;
  279. left: 0;
  280. background-color: rgba(0, 0, 0, 0.6);
  281. text-align: center;
  282. line-height: 45rpx;
  283. border-bottom-left-radius: 10rpx;
  284. border-bottom-right-radius: 10rpx;
  285. }
  286. .result > .success {
  287. color: #00b900;
  288. }
  289. .result > .error {
  290. color: #b52e25;
  291. }
  292. .uploading {
  293. position: absolute;
  294. background-color: rgba(0, 0, 0, 0.5);
  295. left: 0;
  296. top: 0;
  297. width: 100%;
  298. height: 100%;
  299. text-align: center;
  300. line-height: 100%;
  301. z-index: 999;
  302. }
  303. .uploading image {
  304. width: 60rpx;
  305. height: 60rpx;
  306. z-index: 1000;
  307. animation: rotation 0.6s linear infinite;
  308. -moz-animation: rotation 0.6s linear infinite;
  309. -webkit-animation: rotation 0.6s linear infinite;
  310. -o-animation: rotation 0.6s linear infinite;
  311. }
  312. @keyframes rotation {
  313. from {
  314. -webkit-transform: rotate(0deg);
  315. transform: rotate(0deg);
  316. -moz-transform: rotate(0deg);
  317. -o-transform: rotate(0deg);
  318. }
  319. to {
  320. -webkit-transform: rotate(360deg);
  321. transform: rotate(360deg);
  322. -moz-transform: rotate(360deg);
  323. -o-transform: rotate(360deg);
  324. }
  325. }
  326. .imgs-view > image {
  327. width: 100%;
  328. height: 100%;
  329. border-radius: 10rpx;
  330. }
  331. .imgupload__tip {
  332. font-size: 24rpx;
  333. color: #ff0000;
  334. margin: 10rpx auto;
  335. }
  336. .imgupload__tip > label {
  337. color: #009100;
  338. }
  339. .del-btn {
  340. position: absolute;
  341. top: 0;
  342. right: 0;
  343. width: 32rpx;
  344. height: 32rpx;
  345. z-index: 999;
  346. }
  347. .del-btn > image {
  348. width: 100%;
  349. height: 100%;
  350. display: flex;
  351. }
  352. .css2 {
  353. border-style: solid;
  354. border-width: 0px 0px 100px 100px;
  355. border-color: transparent transparent blue transparent;
  356. width: 0px;
  357. height: 0px;
  358. }
  359. </style>