main.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // The Vue build version to load with the `import` command
  2. // (runtime-only or standalone) has been set in webpack.base.conf with an alias.
  3. import Vue from 'vue';
  4. //import Vuex from 'vuex'
  5. //import promise from 'es6-promise';
  6. import App from './App';
  7. import router from './router';
  8. import axios from './components/common/axios'// 'axios';
  9. import moment from 'moment';
  10. import ElementUI from 'element-ui';
  11. import 'element-ui/lib/theme-chalk/index.css'; // 默认主题
  12. // import '../static/css/theme-green/index.css'; // 浅绿色主题
  13. //import './assets/css/icon.css';
  14. import './components/common/directives';
  15. import 'babel-polyfill';
  16. import './core/directives/action'
  17. //promise.polyfill();
  18. // import VCharts from 'v-charts-v2'
  19. import VeLine from 'v-charts/lib/line'
  20. import VeHistogram from 'v-charts/lib/histogram'
  21. import moneyConverter from './components/common/tool.js'
  22. import isMobile from './components/common/isMobile'
  23. Vue.prototype.$isMobile = isMobile // 用$与组件内自定义的函数区分,其他符号也可以
  24. Vue.config.productionTip = false
  25. //axios.defaults.baseURL = "http://localhost:8080";
  26. //Vue.use(Vuex)
  27. axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
  28. Vue.prototype.$axios = axios;
  29. Vue.prototype.$moment = moment;
  30. Vue.prototype.moneyConverter = moneyConverter;
  31. Vue._watchers = Vue.prototype._watchers = [];
  32. moment.locale('zh-cn');
  33. Vue.use(ElementUI, {
  34. size: 'small'
  35. });
  36. // Vue.use(VCharts)
  37. Vue.component(VeLine.name, VeLine)
  38. Vue.component(VeHistogram.name, VeHistogram)
  39. String.prototype.startsWith = function(str){
  40. if (str == null || str == "" || this.length == 0 || str.length > this.length)
  41. return false;
  42. if (this.substr(0, str.length) == str)
  43. return true;
  44. else
  45. return false;
  46. }
  47. router.beforeEach((to, from, next) => {
  48. let token = localStorage.getItem('token');
  49. console.log('==============路由拦截===============');
  50. if (to.path.indexOf('/login') != -1) {
  51. next();
  52. } else if (to.path.startsWith('/admin')) {
  53. let user = localStorage.getItem('am_username');
  54. if (token == null || user == null) {
  55. next('/admin/login');
  56. }
  57. next();
  58. } else if (to.path.startsWith('/third')) {
  59. let user = localStorage.getItem('th_username');
  60. if (token == null || user == null) {
  61. next('/third/login');
  62. }
  63. next();
  64. } else {
  65. if (token === null || token === '') {
  66. next('/admin/login');
  67. } else {
  68. next();
  69. }
  70. }
  71. });
  72. /* eslint-disable no-new */
  73. new Vue({
  74. router,
  75. render: h => h(App)
  76. }).$mount('#app')