{"remainingRequest":"D:\\jenkins\\workspace\\artfess-module\\node_modules\\vue-loader\\lib\\index.js??vue-loader-options!D:\\jenkins\\workspace\\artfess-module\\src\\components\\common\\FileUpload.vue?vue&type=script&lang=js&","dependencies":[{"path":"D:\\jenkins\\workspace\\artfess-module\\src\\components\\common\\FileUpload.vue","mtime":1675232038590},{"path":"D:\\jenkins\\workspace\\artfess-module\\node_modules\\babel-loader\\lib\\index.js","mtime":315532800000},{"path":"D:\\jenkins\\workspace\\artfess-module\\node_modules\\cache-loader\\dist\\cjs.js","mtime":499162500000},{"path":"D:\\jenkins\\workspace\\artfess-module\\node_modules\\vue-loader\\lib\\index.js","mtime":499162500000}],"contextDependencies":[],"result":["//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n\r\nimport utils from \"@/utils.js\";\r\nimport { setTimeout } from \"timers\";\r\nexport default {\r\n  name: \"file-upload\",\r\n  props: {\r\n    withCredentials: {\r\n      type: Boolean,\r\n      default: false\r\n    },\r\n    value: {\r\n      type: Array,\r\n      required: true\r\n    },\r\n    actionUrl: {\r\n      type: String,\r\n      required: true\r\n    },\r\n    multiple: {\r\n      type: Boolean\r\n    },\r\n    accept: {\r\n      type: String\r\n    },\r\n    limit: {\r\n      type: Number,\r\n      default: 5\r\n    },\r\n    header: {\r\n      type: Object\r\n    },\r\n    size: {\r\n      type: Number,\r\n      default: 50\r\n    },\r\n    readonly: {\r\n      type: Boolean,\r\n      default: false\r\n    },\r\n    beforeUpload: {\r\n      type: Function\r\n    },\r\n    onSuccess: {\r\n      type: Function\r\n    },\r\n    onError: {\r\n      type: Function\r\n    }\r\n  },\r\n  data() {\r\n    return {\r\n      files: []\r\n    };\r\n  },\r\n  watch: {\r\n    files: function(newVal) {\r\n      if (newVal && newVal.constructor === Array) {\r\n        let ary = [];\r\n        newVal.forEach(m => {\r\n          if (m && m.constructor === Object) {\r\n            ary.push(m);\r\n          } else if (m && m.constructor === File) {\r\n            var name = m.name;\r\n            var index = name.lastIndexOf(\".\");\r\n            var type = name.substring(index + 1, name.length);\r\n            ary.push({\r\n              name: name,\r\n              size: m.size,\r\n              percentage: m.percentage,\r\n              status: m.status,\r\n              state: m.state,\r\n              response: m.response,\r\n              type: type,\r\n              uid: m.uid\r\n            });\r\n          }\r\n        });\r\n        this.$emit(\"input\", ary);\r\n      }\r\n    }\r\n  },\r\n  computed: {\r\n    acceptLabel: function() {\r\n      return this.accept ? this.accept : \"所有格式\";\r\n    }\r\n  },\r\n  created() {\r\n    this.files = this.value || [];\r\n  },\r\n  methods: {\r\n    // 附件是否超过最大尺寸\r\n    exceedFileSize(file) {\r\n      return file.size > this.size * 1024 * 1024;\r\n    },\r\n    handleBeforeUpload(file) {\r\n      let resultVal = false;\r\n      if (this.exceedFileSize(file)) {\r\n        let computerSize = this.$options.filters[\"computerSize\"](file.size);\r\n        this.$message({\r\n          message: `附件的大小为${computerSize}，超过了允许的最大尺寸${this.size}MB.`,\r\n          type: \"warning\"\r\n        });\r\n        resultVal = false;\r\n      } else {\r\n        resultVal = true;\r\n      }\r\n\r\n      if (\r\n        this.beforeUpload &&\r\n        this.beforeUpload.constructor == Function &&\r\n        resultVal\r\n      ) {\r\n        resultVal = this.beforeUpload(file);\r\n      }\r\n\r\n      if (resultVal) {\r\n        this.files.push(file);\r\n      }\r\n\r\n      return resultVal;\r\n    },\r\n    handleProgress(event, file, fileList) {\r\n      const index = this.files.findIndex(m => m === file);\r\n      index > -1 && this.$set(this.files, index, file);\r\n      this.$emit('on-progress',event,file,fileList)\r\n    },\r\n    handleExceed(files, fileList) {\r\n      this.$message({\r\n        message: `最多允许上传${this.limit}个附件.`,\r\n        type: \"warning\"\r\n      });\r\n    },\r\n    handleSuccess(response, file, fileList) {\r\n      if (this.onSuccess && this.onSuccess.constructor == Function) {\r\n        this.onSuccess(response, file, fileList);\r\n      }\r\n      const index = this.files.findIndex(m => m === file);\r\n      file.state = \"success\";\r\n      index > -1 && this.$set(this.files, index, file);\r\n    },\r\n    handleError(err, file, fileList) {\r\n      if (this.onError && this.onError.constructor == Function) {\r\n        this.onError(err, file, fileList);\r\n      }\r\n      this.$emit('handle-error')\r\n      const index = this.files.findIndex(m => m === file);\r\n      file.state = \"exception\";\r\n      index > -1 && this.$set(this.files, index, file);\r\n      this.$message({\r\n        message: `附件${file.name}上传失败.`,\r\n        type: \"error\",\r\n        onClose: () => {\r\n          this.files.remove(file);\r\n        }\r\n      });\r\n    },\r\n    handleClear() {\r\n      this.$confirm(\"确定清空所有附件?\").then(() => {\r\n        this.files.forEach(m => {\r\n          this.abort(m);\r\n        });\r\n        this.$refs.elUploadEl.clearFiles();\r\n        this.files = [];\r\n      });\r\n    },\r\n    abort(file) {\r\n      // 附件还在上传中，则中止上传。\r\n      if (file && file.status === \"uploading\") {\r\n        this.$refs.elUploadEl.abort(file);\r\n      }\r\n    },\r\n    remove(file) {\r\n      this.abort(file);\r\n      this.files.remove(file);\r\n      for (var i = 0; i < this.files.length; i++) {\r\n        if (this.files[i].uid == file.uid) {\r\n          this.files.splice(i, 1); //删除数组某一项\r\n        }\r\n      }\r\n    }\r\n  }\r\n};\r\n",null]}