baseMixin.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { getToken } from '@/api/token'
  2. import bus from '@/assets/js/event.js'
  3. export default {
  4. data () {
  5. return {
  6. token: null,
  7. }
  8. },
  9. props: {
  10. },
  11. mounted () {
  12. },
  13. methods: {
  14. submitHandler: function (func, checkToken) {
  15. if (this.token == null || checkToken == false) {
  16. getToken().then((res) => {
  17. this.token = res.data;
  18. func(this.token);
  19. }).catch((error) => {
  20. if (error && error.status == 404) {
  21. return;
  22. }
  23. console.log(error)
  24. msg('网络错误');
  25. this.resetToken();
  26. });
  27. }
  28. },
  29. resetToken: function () {
  30. this.token = null;
  31. },
  32. backListView: function(isDestoryListView, listViewName, params, func) {
  33. },
  34. reset: function(backUp) {
  35. },
  36. toClick: function (ref, func) {
  37. },
  38. download: function (data, fileName) {
  39. if (!data || !data.data) {
  40. msg("文件下载失败(文件或已被删除)");
  41. return
  42. }
  43. let url = window.URL.createObjectURL(new Blob([data.data]))
  44. let link = document.createElement('a')
  45. link.style.display = 'none'
  46. link.href = url
  47. link.setAttribute('download', fileName || decodeURIComponent(data.fileName))
  48. document.body.appendChild(link)
  49. link.click()
  50. },
  51. }
  52. }