main.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import Vue from 'vue';
  2. import App from './App.vue';
  3. import axios from 'axios';
  4. import store from './store';
  5. import router from './router/index.js';
  6. import ElementUI from 'element-ui';
  7. import 'element-ui/lib/theme-chalk/index.css';
  8. import '@/utils/smc-directives';
  9. import htmlToPdf from '@/utils/htmlToPdf'
  10. Vue.use(ElementUI);
  11. Vue.use(htmlToPdf);
  12. import { debug } from '@/services/constant';
  13. axios.defaults.withCredentials = true;
  14. Vue.prototype.$http = axios;
  15. const path = require('path');
  16. let myPath = path.resolve(__dirname,'/img/so');
  17. let myPath2 = path.resolve(__dirname,'./img/so');
  18. let myPath3 = path.resolve('ee','foo/bar', './baz');
  19. let myPath4 = path.resolve('/foo/bar', '/tmp/file/');
  20. console.log(__dirname);
  21. console.log(myPath);
  22. console.log(myPath2);
  23. console.log(myPath3);
  24. console.log(myPath4);
  25. //请求拦截
  26. axios.interceptors.request.use((config) => {
  27. //请求之前重新拼装url
  28. if(!debug){
  29. config.url = '/rest/diagnosis' + config.url;
  30. }
  31. return config;
  32. });
  33. // 添加响应拦截器
  34. axios.interceptors.response.use(function(response) {
  35. // 对响应数据做些事
  36. return response;
  37. }, function (error) {
  38. // 请求错误时做些事
  39. if (error.response.status == '401' || error.response.status == '403') { // 未登录重定向值登录页面
  40. router.replace({path: '/index'});
  41. }
  42. return Promise.reject(error);
  43. });
  44. router.onError((err) => {
  45. console.log(err);
  46. });
  47. Vue.filter('removeIndex',function(val){
  48. let str = ''
  49. if(!Number.isNaN(Number.parseInt(val[0]))){
  50. str = val.replace(val[0],'');
  51. }
  52. if(!Number.isNaN(Number.parseInt(str[0]))){
  53. str = str.replace(val[0],'');
  54. }
  55. return str;
  56. });
  57. new Vue({
  58. el: '#app',
  59. router,
  60. store,
  61. render: h => h(App)
  62. })