whychw
2020-11-20 640034fb4f659cbcecbd23df75016d97231ad7bd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import Vue from 'vue'
import App from './App.vue'
// import './registerServiceWorker'
import router from './router/index.js'
import store from './store/index.js'
// 禁止缩放
import './script/unCtrl.js'
// import axios from 'axios'
import './assets/iconfont/iconfont.css'
import 'element-ui/lib/theme-chalk/index.css'
import './assets/css/m-element-ui.css'
import './assets/css/common.css'
 
import G from './global'
import common from './script/common.js'
import config from './script/config.js'
import user from './script/user.js'
import filters from './script/filter.js'
import event from './script/event.js'
 
 
import './api'
 
import ElementUI from 'element-ui'
 
import layer from 'vue-layer'
import 'vue-layer/lib/vue-layer.css';
Vue.prototype.$layer = layer(Vue);
 
import './script/directive.js';
 
Vue.use(ElementUI);
import './assets/css/theme.css';
 
// Vue.prototype.$message = Message;
Vue.prototype.$common = common;
Vue.prototype.$config = config;
Vue.prototype.$user = user;
Vue.prototype.$G = G;
Vue.prototype.$event = event;
// Vue.prototype.$api = api;
 
// 注册自定义过滤器
for(const key in filters){
    // console.log(key, filters[key]);
    Vue.filter(key, filters[key]);
}
//格式化时间
Date.prototype.format = function (format) {
    var o = {
      "M+" : this.getMonth()+1, //month
      "d+" : this.getDate(),    //day
      "h+" : this.getHours(),   //hour
      "m+" : this.getMinutes(), //minute
      "s+" : this.getSeconds(), //second
      "q+" : Math.floor((this.getMonth()+3)/3),  //quarter
      "S" : this.getMilliseconds() //millisecond
    };
    if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
    (this.getFullYear()+"").substr(4- RegExp.$1.length));
    for(var k in o)if(new RegExp("("+ k +")").test(format))
    format = format.replace(RegExp.$1,
    RegExp.$1.length==1? o[k] :
    ("00"+ o[k]).substr((""+ o[k]).length));
    return format;
};
// Vue.config.productionTip = false;
 
 
 
const setHtmlFontSize = () => {
  const htmlDom = document.getElementsByTagName('html')[0];
  let htmlWidth = document.documentElement.clientWidth || document.body.clientWidth;
  if (htmlWidth >= 750) {
    htmlWidth = 750;
  }
  if (htmlWidth <= 320) {
    htmlWidth = 320;
  }
  htmlDom.style.fontSize = `${htmlWidth / 7.5}px`;
};
 
// 进入路由前
router.beforeEach((to, from, next) => {
  // console.log(to, '----to------from----', from);
  // 用户是否已登录
  let isLogin = common.getSession('login') && common.getSession('login') != 'false';
  // console.log(isLogin, 'isLogin..', typeof isLogin);
  if (isLogin) {
    if ('/' == to.path) {
      next({path:'/general/index'});
      return false;
    }
  } else {
    if ('/login' != to.path) {
      next({path:'/login'});
      return false;
    }
  }
  // debugger;
 
  // 修改主导航的激活状态
  store.dispatch('changeNavName', to.name);
  // 修改面包屑导航内容
  store.dispatch('changeCrumb', to.meta.crumb);
  next();
});
 
// window.onresize = setHtmlFontSize;
window.addEventListener('resize', setHtmlFontSize);
 
setHtmlFontSize();
 
new Vue({
  router,
  store,
  render: h => h(App),
}).$mount('#app')