main.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 YDUI from 'vue-ydui'; /* 相当于import YDUI from 'vue-ydui/ydui.rem.js' */
  7. import 'vue-ydui/dist/ydui.base.css';
  8. import 'vue-ydui/dist/ydui.rem.css';
  9. import 'vant/lib/index.css';
  10. import 'vue-slider-component/theme/default.css'
  11. import './assets/icon/iconfont.css'
  12. import axios from 'axios'
  13. import apiUrl from './global'
  14. Vue.prototype.GLOBAL = apiUrl;
  15. axios.defaults.baseURL=apiUrl.BASE_URL;
  16. Vue.prototype.$http=axios;
  17. /* 使用px:import 'vue-ydui/dist/ydui.px.css'; */
  18. import { Confirm, Alert, Toast, Notify, Loading } from 'vue-ydui/dist/lib.rem/dialog';
  19. /* 使用px:import { Confirm, Alert, Toast, Notify, Loading } from 'vue-ydui/dist/lib.px/dialog'; */
  20. Vue.prototype.$dialog = {
  21. confirm: Confirm,
  22. alert: Alert,
  23. toast: Toast,
  24. notify: Notify,
  25. loading: Loading,
  26. };
  27. Vue.use(YDUI);
  28. Vue.config.productionTip = false
  29. /**
  30. * 客户、运营可同时登录
  31. *
  32. * 默认跳转到对应角色首页
  33. * - 客户:location
  34. * - 运营:yys
  35. * 如未登录,跳转到:
  36. * - 客户:first
  37. * - 运营:yys_login
  38. */
  39. router.beforeEach((to,from,next)=>{
  40. // console.log('to.....',to);
  41. //车牌扫码校验临时
  42. if(to.name == 'vehicle' || to.name == 'vehicledecode'){
  43. console.log('ddddddddddddddddd')
  44. next()
  45. return
  46. }
  47. localStorage.setItem('openid', '2222222');
  48. let query = to.query || {};
  49. if (query.openid) {
  50. localStorage.setItem('openid', query.openid);
  51. }
  52. let openid = localStorage.getItem("openid");
  53. let loginFlag = false; // 登录标记
  54. // 运营商,本地保存 yys_userid
  55. if (to.meta.role === 'yys') {
  56. let yysUserid = localStorage.getItem('yysUserid');
  57. loginFlag = (openid && yysUserid);
  58. if (to.name === 'yys_login') {
  59. next();
  60. } else {
  61. if (loginFlag) {
  62. next();
  63. } else {
  64. next('/yys_login');
  65. }
  66. }
  67. } else {
  68. // 用户,本地保存 userid, userType, deviceType
  69. let userid = localStorage.getItem('userid');
  70. // openid =222222;//测试用
  71. loginFlag = (openid && userid );
  72. if (to.name === 'login') {
  73. next();
  74. } else if ( to.name === 'register' || to.name === 'reset_pwd') {
  75. // if (userType) {
  76. next();
  77. // } else {
  78. // next('/');
  79. // }
  80. } else {
  81. if (!loginFlag) {
  82. next('/login');
  83. } else {
  84. next();
  85. }
  86. }
  87. }
  88. });
  89. // 保存用户设备标识
  90. var u = navigator.userAgent;
  91. var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
  92. var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
  93. if (isAndroid) {
  94. localStorage.setItem('userAgent', 'android');
  95. } else if (isiOS) {
  96. localStorage.setItem('userAgent', 'ios');
  97. } else {
  98. localStorage.setItem('userAgent', 'other');
  99. }
  100. // 保存首次登录地址(IOS 微信 JS-SDK 需要用到)
  101. localStorage.setItem('mainUrl', location.href.split('#')[0]);
  102. /* eslint-disable no-new */
  103. new Vue({
  104. el: '#app',
  105. router,
  106. components: { App },
  107. template: '<App/>'
  108. })