index.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <template>
  2. <el-dialog :title="dialogtitle" :visible.sync="dialogVisible" width="500px" :before-close="handleClose" center>
  3. <div class="upload">
  4. <div class="upload-left">导入文件</div>
  5. <el-upload class="upload-right" ref="upload" accept=".xls,.xlsx" :action="fileApi" :file-list="fileList" :data="fileData" :auto-upload="false" :on-success="onSuccess" :limit="1">
  6. <el-button slot="trigger" style="margin-right: 30px" size="small" type="primary">选择文件</el-button>
  7. <el-button size="small" type="success" @click="submitUpload">导入数据</el-button>
  8. <div slot="tip" class="el-upload__tip" style="margin-left: 10px; margin-top: 10px; font-size: 14px">只能导入 xls / xlsx 文件</div>
  9. </el-upload>
  10. </div>
  11. </el-dialog>
  12. </template>
  13. <script>
  14. import { useMessage } from '@/utils/element-ui'
  15. export default {
  16. data() {
  17. return {
  18. dialogtitle: '导入定检任务信息',
  19. dialogVisible: false,
  20. fileApi: process.env.VUE_APP_BASE_API + '/als/smTask/importData',
  21. fileList: [],
  22. fileData: {
  23. userName: ''
  24. }
  25. }
  26. },
  27. methods: {
  28. triggerDialog() {
  29. this.dialogVisible = true
  30. },
  31. handleClose() {
  32. this.dialogVisible = false
  33. },
  34. // 上传
  35. submitUpload() {
  36. const userInfo = this.$store.state.user.userInfo.user
  37. this.fileData.userName = userInfo.userName
  38. this.$refs.upload.submit()
  39. },
  40. // 上传完成后
  41. onSuccess(result) {
  42. this.$refs.upload.clearFiles()
  43. this.fileList = []
  44. const { msg, code } = result
  45. useMessage(code == 200 ? 'success' : 'warning', msg, 2000)
  46. if (code !== 200) return
  47. this.handleClose()
  48. this.$emit('submitCallBack')
  49. }
  50. }
  51. }
  52. </script>
  53. <style lang="scss" scoped>
  54. .el-dialog__wrapper {
  55. width: 100%;
  56. }
  57. .upload {
  58. height: 106px;
  59. padding-top: 30px;
  60. display: flex;
  61. &-left {
  62. margin-right: 40px;
  63. }
  64. }
  65. </style>