UploadView.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <!-- -->
  2. <template>
  3. <div class="upload">
  4. <el-upload
  5. :accept="accept"
  6. class="upload-demo"
  7. :action="url"
  8. :on-preview="handlePreview"
  9. :on-remove="handleRemove"
  10. :before-remove="beforeRemove"
  11. multiple
  12. :before-upload="handlebeforeUplaod"
  13. :on-exceed="handleExceed"
  14. :on-success="handleSuccess"
  15. :on-change="handleChange"
  16. :file-list="currentfileList"
  17. :show-file-list="showList"
  18. :limit="filleNumber"
  19. >
  20. <div class="uploadBtn">
  21. <img
  22. style="width: 24px; height: 24px"
  23. src="../../../assets/adult/uploadview.png"
  24. alt=""
  25. />
  26. 上传文件
  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. "fileList",
  45. "accept",
  46. ],
  47. data() {
  48. return {
  49. currentfileList: [],
  50. fileTypeName: "",
  51. loading: false,
  52. showList: false,
  53. };
  54. },
  55. computed: {
  56. url() {
  57. let userInfor = getToken();
  58. let UserCode = "",
  59. UserType = "",
  60. SessionID = "";
  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: function (val, oldVal) {
  82. this.initUpload();
  83. },
  84. // 深度观察监听
  85. deep: true,
  86. },
  87. fileList(newval, oldval) {
  88. this.currentfileList = newval||[];
  89. },
  90. },
  91. // 生命周期 - 创建完成(可以访问当前this实例)
  92. created() {
  93. this.currentfileList = this.fileList || [];
  94. this.showList = this.fileList ? true : false;
  95. },
  96. // 生命周期 - 挂载完成(可以访问DOM元素)
  97. mounted() {
  98. this.initUpload();
  99. },
  100. beforeCreate() {}, // 生命周期 - 创建之前
  101. beforeMount() {}, // 生命周期 - 挂载之前
  102. beforeUpdate() {}, // 生命周期 - 更新之前
  103. updated() {}, // 生命周期 - 更新之后
  104. beforeDestroy() {}, // 生命周期 - 销毁之前
  105. destroyed() {}, // 生命周期 - 销毁完成
  106. activated() {},
  107. // 方法集合
  108. methods: {
  109. handleChange(file, fileList) {},
  110. handleSuccess(response, file, fileList) {
  111. if (response.status == 1) {
  112. response.duration = response.file_info_list[0].media_duration
  113. ? response.file_info_list[0].media_duration
  114. : 10;
  115. this.$message.success("用户上传成功");
  116. this.changeFillId(fileList, response.duration, this.index);
  117. this.loading.close();
  118. } else {
  119. this.fileList = [];
  120. this.$message.warning(response.msg);
  121. this.loading.close();
  122. }
  123. },
  124. handlebeforeUplaod(file) {
  125. this.loading = this.$loading({
  126. lock: true,
  127. text: "Loading",
  128. spinner: "el-icon-loading",
  129. background: "rgba(0, 0, 0, 0.7)",
  130. });
  131. },
  132. handleRemove(file, fileList) {
  133. console.log(fileList);
  134. this.changeFillId(fileList);
  135. this.$message.success("移除成功");
  136. },
  137. beforeRemove(file, fileList) {
  138. return this.$confirm(`确定移除 ${file.name}?`);
  139. },
  140. handlePreview(file) {},
  141. handleExceed(files, fileList) {
  142. this.$message.warning(
  143. `当前限制选择 ${
  144. this.filleNumber ? this.filleNumber : 1
  145. } 个文件,本次选择了 ${files.length} 个文件,共选择了 ${
  146. files.length + fileList.length
  147. } 个文件`
  148. );
  149. },
  150. initUpload() {},
  151. }, // 如果页面有keep-alive缓存功能,这个函数会触发
  152. };
  153. </script>
  154. <style lang='scss' scoped>
  155. //@import url(); 引入公共css类;
  156. .uploadBtn {
  157. width: 141px;
  158. height: 39px;
  159. background: #ffffff;
  160. border: 1px solid rgba(0, 0, 0, 0.1);
  161. box-sizing: border-box;
  162. box-shadow: 0px 2px 6px rgba(0, 0, 0, 0.1);
  163. border-radius: 4px;
  164. display: flex;
  165. justify-content: center;
  166. align-items: center;
  167. font-size: 16px;
  168. line-height: 150%;
  169. color: #000000;
  170. img {
  171. margin-right: 13px;
  172. }
  173. }
  174. </style>
  175. <style lang="scss">
  176. </style>