UploadVideo.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <!-- -->
  2. <template>
  3. <div class="upload">
  4. <el-upload
  5. :accept="accept"
  6. style="width: 300px"
  7. class="upload-demo"
  8. :action="url"
  9. :on-preview="handlePreview"
  10. :on-remove="handleRemove"
  11. :before-remove="beforeRemove"
  12. multiple
  13. :limit="filleNumber ? filleNumber : 1"
  14. :before-upload="handlebeforeUplaod"
  15. :on-exceed="handleExceed"
  16. :on-success="handleSuccess"
  17. :on-change="handleChange"
  18. :file-list="fileList"
  19. >
  20. <el-button size="mini" type="success">上传{{ fileTypeName }}</el-button>
  21. <div
  22. slot="tip"
  23. style="display: inline; padding-left: 30px"
  24. class="el-upload__tip"
  25. >
  26. {{ uploadName }}
  27. </div>
  28. </el-upload>
  29. <!-- <div class="zhezhao" v-loading.fullscreen.lock="fullscreenLoading"></div> -->
  30. </div>
  31. </template>
  32. <script>
  33. import { getToken } from "../../../utils/auth";
  34. export default {
  35. components: {},
  36. props: [
  37. "uploadType",
  38. "filleNumber",
  39. "datafileList",
  40. "changeFillId",
  41. "deleteImg",
  42. "index",
  43. "uiType",
  44. "handleMp3Base64",
  45. ],
  46. data() {
  47. return {
  48. fileList: [],
  49. accept: "",
  50. fileTypeName: "",
  51. uploadName: "",
  52. loading: false,
  53. };
  54. },
  55. computed: {
  56. url() {
  57. let userInfor = getToken();
  58. let SessionID = "";
  59. let UserCode = "";
  60. let UserType = "";
  61. if (userInfor) {
  62. let user = JSON.parse(getToken());
  63. UserCode = user.user_code;
  64. UserType = user.user_type;
  65. SessionID = user.session_id;
  66. }
  67. return (
  68. process.env.VUE_APP_BASE_API +
  69. "/GCLSFileServer/WebFileUpload?UserCode=" +
  70. UserCode +
  71. "&UserType=" +
  72. UserType +
  73. "&SessionID=" +
  74. SessionID +
  75. "&SecurityLevel=Mid"
  76. );
  77. },
  78. },
  79. watch: {
  80. datafileList: {
  81. handler(val, oldVal) {
  82. this.initUpload();
  83. },
  84. // 深度观察监听
  85. deep: true,
  86. },
  87. },
  88. // 生命周期 - 创建完成(可以访问当前this实例)
  89. created() {},
  90. // 生命周期 - 挂载完成(可以访问DOM元素)
  91. mounted() {
  92. this.initUpload();
  93. },
  94. beforeCreate() {}, // 生命周期 - 创建之前
  95. beforeMount() {}, // 生命周期 - 挂载之前
  96. beforeUpdate() {}, // 生命周期 - 更新之前
  97. updated() {}, // 生命周期 - 更新之后
  98. beforeDestroy() {}, // 生命周期 - 销毁之前
  99. destroyed() {}, // 生命周期 - 销毁完成
  100. activated() {},
  101. // 方法集合
  102. methods: {
  103. handleChange(file, fileList) {},
  104. handleSuccess(response, file, fileList) {
  105. if (response.status == 1) {
  106. if (this.handleMp3Base64) {
  107. this.handleMp3Base64(file);
  108. }
  109. response.duration = response.file_info_list[0].media_duration
  110. ? response.file_info_list[0].media_duration
  111. : 10;
  112. this.$message.success("用户上传成功");
  113. this.changeFillId(fileList, response.duration, this.index);
  114. this.loading.close();
  115. } else {
  116. this.fileList = [];
  117. this.$message.warning(response.msg);
  118. this.loading.close();
  119. }
  120. },
  121. handlebeforeUplaod(file) {
  122. this.loading = this.$loading({
  123. lock: true,
  124. text: "Loading",
  125. spinner: "el-icon-loading",
  126. background: "rgba(0, 0, 0, 0.7)",
  127. });
  128. },
  129. handleRemove(file, fileList) {
  130. this.changeFillId(fileList);
  131. this.$message.success("移除成功");
  132. },
  133. beforeRemove(file, fileList) {
  134. return this.$confirm(`确定移除 ${file.name}?`);
  135. },
  136. handlePreview(file) {},
  137. handleExceed(files, fileList) {
  138. this.$message.warning(
  139. `当前限制选择 ${
  140. this.filleNumber ? this.filleNumber : 1
  141. } 个文件,本次选择了 ${files.length} 个文件,共选择了 ${
  142. files.length + fileList.length
  143. } 个文件`
  144. );
  145. },
  146. initUpload() {
  147. this.fileList = this.datafileList || [];
  148. let name = "只能上传";
  149. switch (this.uploadType) {
  150. case "image":
  151. this.accept = "image/*";
  152. this.fileTypeName = "图片";
  153. this.uploadName = name + "图片";
  154. break;
  155. case "mp3":
  156. this.accept = "audio/*";
  157. this.fileTypeName = "音频";
  158. this.uploadName = name + "音频";
  159. break;
  160. case "pdf":
  161. this.accept = ".pdf";
  162. this.fileTypeName = "pdf";
  163. this.uploadName = name + "pdf";
  164. break;
  165. case "xls":
  166. this.accept = ".xls,.xlsx";
  167. this.fileTypeName = "表格";
  168. this.uploadName = name + "表格";
  169. break;
  170. case "lrc":
  171. this.accept = ".lrc";
  172. this.fileTypeName = "lrc";
  173. this.uploadName = name + "lrc";
  174. break;
  175. default:
  176. this.accept = "*";
  177. this.fileTypeName = "文件";
  178. this.uploadName = "";
  179. break;
  180. }
  181. },
  182. }, // 如果页面有keep-alive缓存功能,这个函数会触发
  183. };
  184. </script>
  185. <style lang="scss" scoped>
  186. .zhezhao {
  187. position: fixed;
  188. top: 0;
  189. left: 0;
  190. width: 100%;
  191. height: 100vh;
  192. background: rgba(0, 0, 0, 0.4);
  193. z-index: 10000;
  194. }
  195. </style>