import_mixin.js 1.2 KB

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