zj
2024-06-03 a1e25849cf08c5580fe139b39d5b58c9d958b455
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
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui'
import store from './store'
import axios from './axios/index' // 这里这里
import preview from 'vue-photo-preview' // 查看大图
import 'vue-photo-preview/dist/skin.css' // 查看大图样式
import echarts from "echarts";
import dayjs from 'dayjs';
import VueI18n from 'vue-i18n'
// import i18n from './locales'
import i18n from '@/locales'
import 'element-ui/lib/theme-chalk/index.css'
// import locale from 'element-ui/lib/locale/lang/en' // lang i18n
 
import locale from 'element-ui/lib/locale';
import enLocale from 'element-ui/lib/locale/lang/en'
import zhLocale from 'element-ui/lib/locale/lang/zh-CN'
// import axios from 'axios'
import * as filters from './utils/utils'
import VueClipboard from 'vue-clipboard2' // 复制
import md5 from 'js-md5'
import animated from 'animate.css' // 动画
// import enLocale from 'element-ui/lib/locale/lang/en'
// import i18n from './lang'
 
 
 
Vue.prototype.dayjs = dayjs;
Vue.prototype.$echarts = echarts
Vue.prototype.$md5 = md5
Vue.config.productionTip = false
Vue.use(animated)
Vue.use(preview)
Vue.use(VueClipboard)
Vue.use(ElementUI)
Vue.use(VueI18n); //通过插件的形式挂载
Vue.use(ElementUI, { locale })
 
Vue.use(ElementUI, {
  size: 'medium', // set element-ui default size
  i18n: (key, value) => i18n.t(key, value)
})
locale.i18n((key, value) => i18n.t(key, value)) //兼容element
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})
// Vue.http.options.emulateJSON = true;
// Vue.http.options.headers = {
//   // 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
//   'Content-Type': 'application/json;charset=UTF-8'
// };
Vue.prototype.getCookie = function(name) {
  var arr
  var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)')
  console.log(document.cookie, 'document.cookie')
  if (arr === document.cookie.match(reg)) {
    return unescape(arr[2])
  } else {
    return null
    // document.cookie = name + "=" + escape(value);
  }
}
Vue.prototype.setCookie = function(name, value, day) {
  if (day !== 0) { // 当设置的时间等于0时,不设置expires属性,cookie在浏览器关闭后删除
    var curDate = new Date()
    var curTamp = curDate.getTime()
    var curWeeHours = new Date(curDate.toLocaleDateString()).getTime() - 1
    var passedTamp = curTamp - curWeeHours
    var leftTamp = 24 * 60 * 60 * 1000 - passedTamp
    var leftTime = new Date()
    leftTime.setTime(leftTamp + curTamp)
    document.cookie = name + '=' + escape(value) + ';expires=' + leftTime.toGMTString()
  } else {
    document.cookie = name + '=' + escape(value)
  }
}
Vue.prototype.clearCookie = function() {
  this.setCookie('USER_TOKEN', '', -1)
}
// 设置title
router.beforeEach((to, from, next) => {
  if (to.meta.title) { // 如果设置标题,拦截后设置标题
    if (store.state && store.state.siteInfo && store.state.siteInfo.siteName) {
      document.title = store.state.siteInfo.siteName + '-' + to.meta.title
    } else {
      document.title = to.meta.title
    }
  }
  next()
})
 
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  axios,
  i18n, //挂载到实例,一定得在这个位置,而不是comonents中
  render: h => h(App)
}).$mount('#app')