7ccc3d2a015aefcdc8b10084fea7afa59b80d9cb.svn-base 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <template>
  2. <div style="width: 200px;height:28px;" class="upMain">
  3. <el-upload
  4. ref="upload"
  5. :action="'/pdcApi/bis/insp/pblm/plist/upload'"
  6. :multiple="false"
  7. :headers="header"
  8. accept=".xls,.xlsx"
  9. :limit='1'
  10. :auto-upload="true"
  11. :on-success="uploadSuccess"
  12. :on-error="Error"
  13. >
  14. <el-button type="primary">点击上传</el-button>
  15. <div slot="tip" class="el-upload__tip">只能上传xls/xlsx文件</div>
  16. </el-upload>
  17. </div>
  18. </template>
  19. <script>
  20. export default {
  21. data() {
  22. return {
  23. header: {
  24. 'persId': localStorage.getItem('userid'),
  25. 'accessToken' : localStorage.getItem('accessToken'),
  26. 'orgId': localStorage.getItem('currentOrgId')
  27. },
  28. };
  29. },
  30. computed:{
  31. userid(){
  32. return localStorage.getItem('userid') ? localStorage.getItem('userid') : ''
  33. }
  34. },
  35. methods: {
  36. // 初始化,
  37. init() {
  38. this.$refs.upload.clearFiles();
  39. },
  40. // 上传出错,向上触发结束
  41. upError(err, file, fileList) {
  42. this.$message.error("上传失败,请修改文件!");
  43. this.init();
  44. },
  45. // 全部上传成功,向上触发结束
  46. uploadSuccess(response, file, fileList) {
  47. if(response.success){
  48. this.$message.success("上传成功");
  49. this.init();
  50. }else{
  51. this.$message.error("上传失败,请修改文件!");
  52. this.init();
  53. }
  54. }
  55. }
  56. };
  57. </script>
  58. <style scoped>
  59. .upMain div{
  60. display: flex;
  61. }
  62. /deep/ .el-upload__tip{
  63. margin-top: 0;
  64. }
  65. </style>