UploadArt.vue 4.6 KB

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