whychw
2021-04-17 308336582cec4a2ed610eec5b9799f2497a4e4af
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
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 './assets/css/custom.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;
// 未授权
const mixin = {
  data () {
    return {
      authorization: this.$store.state.login.unote > 0
    }
  },
  methods: {
    notAllow () {
      this.$message({
        type: 'error',
        message: '该用户未授权'
      });
    }
    ,doNothing () {}
    // 手动更新authorization
    ,upDateAuth () {
      this.authorization = this.$store.state.login.unote > 0;
    }
  }
};
// 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;
    }
    // 如果没有写权限 就不让进入用户的相关页面
    if (common.getSession('unote') <= 0 && ('/user/info' == to.path || '/user/power' == 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({
  mixins: [mixin],
  router,
  store,
  render: h => h(App),
}).$mount('#app')