You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.4 KiB

6 months ago
  1. <template>
  2. <div>
  3. <!-- 弹窗, 上传文件 -->
  4. <el-upload
  5. :action="url"
  6. :before-upload="beforeUploadHandle"
  7. :on-success="successHandle"
  8. multiple
  9. :show-file-list="false"
  10. style="text-align: center;">
  11. <el-button type="primary">点击上传</el-button>
  12. </el-upload>
  13. </div>
  14. </template>
  15. <script>
  16. export default {
  17. data () {
  18. return {
  19. url: '',
  20. num: 0,
  21. successNum: 0,
  22. fileList: [],
  23. rollList: {}
  24. }
  25. },
  26. methods: {
  27. init (id) {
  28. this.url = this.$http.adornUrl(`/file/excel/upload?token=${this.$cookie.get('token')}`)
  29. this.visible = true
  30. },
  31. // 上传之前
  32. beforeUploadHandle (file) {
  33. if (file.type !== "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" && file.type !== "application/vnd.ms-excel" ) {
  34. this.$message.error('只支持xls、xlsx、格式的文件!')
  35. return false
  36. }
  37. this.num++
  38. },
  39. // 上传成功
  40. successHandle (response, file, fileList) {
  41. if (response && response.code === 0) {
  42. this.rollList = response
  43. this.childClick()
  44. } else {
  45. this.$message.error(response.msg)
  46. }
  47. },
  48. childClick () {
  49. this.$emit('excelUploadChild', this.rollList)
  50. }
  51. },
  52. created() {
  53. this.init()
  54. }
  55. }
  56. </script>
  57. <style scoped>
  58. </style>