main.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 App from './App'
  5. import router from './router'
  6. import store from './config/config'
  7. import ajax from './common/axios.config'
  8. import { Message } from 'element-ui'
  9. Vue.config.productionTip = false
  10. import { Form } from 'element-ui'
  11. Vue.prototype.$store = store;// 将store实例挂在vue原型上
  12. Vue.prototype.ajax = ajax
  13. Vue.prototype.$message = Message
  14. /* eslint-disable no-new */
  15. new Vue({
  16. el: '#app',
  17. router,
  18. components: { App },
  19. template: '<App/>'
  20. })
  21. router.beforeEach((to, from, next) => {
  22. console.log('1');
  23. ajax
  24. .get(`${store.state.server}getcookieuserid`)
  25. .then((res) => {
  26. var userid = res.data[0][0].userid
  27. store.commit("update", ["userId", userid]);
  28. ajax
  29. .get(
  30. `${store.state.edu}admin/userinfo/userinfoById/${userid}/`
  31. )
  32. .then((r) => {
  33. let data = r.data[0][0];
  34. console.log(data);
  35. store.commit("update", ["userName", data.alias || data.username]);
  36. });
  37. })
  38. .catch((err) => {
  39. // window.location.href = "https://edu.cocorobo.cn/course/login?type=1";
  40. var type = localStorage.getItem("type")
  41. window.location.href = "https://edu.cocorobo.cn/course/login?type=1&UnityType=" + type;
  42. });
  43. next();
  44. })