85b46240424a82a8c3aa661b75c95b9ec0e616ca.svn-base 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <!--
  2. <upload ref="uploadFile" url="/biz/hzz/basic/file/upload?bizId=" @uploadOver="uploadOver"></upload>
  3. if (this.$refs.uploadFile.submitUpload(id)) {
  4. // true上传列表为空,直接执行结束操作
  5. this.insertOver()
  6. }
  7. -->
  8. <template>
  9. <div style="width: 420px;margin: 20px auto;">
  10. <el-upload
  11. ref="upload"
  12. :action="allurl"
  13. :headers="header"
  14. multiple
  15. :auto-upload="false"
  16. :on-preview="handlePictureCardPreview"
  17. :on-remove="handleRemove"
  18. :on-change="changeFileList"
  19. :on-success="uploadSuccess"
  20. :on-error="upError"
  21. >
  22. <i class="el-icon-upload" style="font-size: 200px"></i>
  23. </el-upload>
  24. <!-- <el-dialog :visible.sync="dialogVisible" append-to-body>-->
  25. <!-- <img width="100%" :src="dialogImageUrl" alt="">-->
  26. <!-- </el-dialog>-->
  27. <!-- <el-form ref="form" label-width="80px" style="margin-top: 20px;">-->
  28. <!-- <el-form-item label="描述信息">-->
  29. <!-- <el-input v-model="description" type="textarea" rows="3"></el-input>-->
  30. <!-- </el-form-item>-->
  31. <!-- </el-form>-->
  32. </div>
  33. </template>
  34. <script>
  35. export default {
  36. props: ["url"], // 上传基础路径
  37. data() {
  38. return {
  39. fileList: [],
  40. resList: [],
  41. length: 0, // 上传列表长度
  42. sum: 0, // 上传成功次数
  43. allurl: "", // 上传完整路径
  44. header: {
  45. 'persId': localStorage.getItem('userid'),
  46. 'accessToken' : localStorage.getItem('accessToken')
  47. },
  48. dialogImageUrl: '',
  49. dialogVisible: false,
  50. description: ''
  51. };
  52. },
  53. computed:{
  54. userid(){
  55. return localStorage.getItem('userid') ? localStorage.getItem('userid') : ''
  56. }
  57. },
  58. methods: {
  59. // 初始化,
  60. init() {
  61. this.$refs.upload.clearFiles();
  62. this.length = 0;
  63. this.sum = 0;
  64. this.allurl = "";
  65. this.resList = [];
  66. },
  67. // 开始上传,文件列表为空直接返回turn表示结束,不为空触发上传并返回false,由uploadOver判断结束时间
  68. submitUpload(id,type) {
  69. this.allurl = `${this.url}${id}&bizType=${type}`;
  70. if (this.length) {
  71. this.$nextTick(() => {
  72. this.$refs.upload.submit();
  73. this.description = ''
  74. });
  75. return false;
  76. } else {
  77. return true;
  78. }
  79. },
  80. // 上传出错,向上触发结束
  81. upError(err, file, fileList) {
  82. this.$message.error("上传出错,请修改文件!");
  83. this.$emit("uploadOver");
  84. this.init();
  85. },
  86. // 全部上传成功,向上触发结束
  87. uploadSuccess(response, file, fileList) {
  88. this.resList.push(response.data);
  89. console.log(this.resList);
  90. this.sum = this.sum + 1;
  91. if (this.sum == this.length) {
  92. this.$emit("uploadOver", this.resList);
  93. this.init();
  94. }
  95. },
  96. // 及时更新列表长度
  97. changeFileList(file, fileList) {
  98. this.length = fileList.length;
  99. },
  100. handleRemove(file, fileList) {
  101. console.log(file, fileList);
  102. },
  103. handlePictureCardPreview(file) {
  104. this.dialogImageUrl = file.url;
  105. this.dialogVisible = true;
  106. }
  107. }
  108. };
  109. </script>