import_mixin.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. export default {
  2. methods: {
  3. //导入按钮
  4. importButton(func, name = '导入', params, fun1, fun2) {
  5. return (
  6. <el-upload
  7. action={'_'}
  8. show-file-list={false}
  9. http-request={data => {
  10. const loading = this.$loading({
  11. lock: true,
  12. text: '正在导入',
  13. spinner: 'el-icon-loading',
  14. background: 'rgba(0, 0, 0, 0.7)'
  15. })
  16. fun1 && fun1()
  17. var formdata = new FormData()
  18. formdata.append('file', data.file)
  19. if (!!params) {
  20. for (const key in params) {
  21. if (Object.hasOwnProperty.call(params, key)) {
  22. formdata.append(key, params[key])
  23. }
  24. }
  25. }
  26. func({ formdata })
  27. .then(res => {
  28. fun2 && fun2(res)
  29. this.$refs.pageRef.refreshList()
  30. loading.close()
  31. this.$message({
  32. type: 'success',
  33. message: '导入成功!'
  34. })
  35. })
  36. .catch(err => {
  37. fun2 && fun2()
  38. loading.close()
  39. this.$message({
  40. type: 'error',
  41. message: err.message || '导入失败'
  42. })
  43. })
  44. }}
  45. >
  46. <span class="teshudeshangchuananniu">{name}</span>
  47. </el-upload>
  48. )
  49. }
  50. }
  51. }