Files
foton-laws-system-front/src/main.js
T
2024-01-08 09:55:46 +08:00

162 lines
4.3 KiB
JavaScript

import '@babel/polyfill'
require('es6-promise').polyfill()
require('es6-promise/auto')
import Vue from 'vue'
import App from './App'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
// jQuery
import $ from 'jquery'
// vuex
import store from './store'
// 复制
import VueClipboard from 'vue-clipboard2'
// 全局样式文件
import '@/assets/styles/common.less'
// 样式重置
import '@/assets/styles/reset.css'
// iconfont字体库
import '@/assets/styles/iconfont.css'
import '@/assets/styles/shangqi-iconfont/iconfont.css'
import '@/assets/styles/shangqi-iconfont-replace/iconfont.css' // 可直接替换此文件夹
import '@/assets/styles/shangqi-iconfont-2021/iconfont.css'
// axios
import axios from 'axios'
import $axios from '@/common/axios'
// 自定义全局组件
import components from '@/components'
// 自定义插件
import common from '@/common'
import dragDialogWidth from '@/common/dragDialogWidth'
// 自定义按钮显示指令
import btnPermission from '@/common/btnPermission' // eslint-disable-line
import VueI18n from 'vue-i18n' // 国际化
import { simpleUploadPath } from '@/sysConfig'
// 时间转换
import moment from 'moment'
moment.suppressDeprecationWarnings = true
// 右键菜单
import Contextmenu from 'vue-contextmenujs'
// vant
import vant from 'vant'
import 'vant/lib/index.css'
import animate from 'animate.css'
import tool from './utils/tool'
Vue.use(tool)
// 引入路由器
import router from './router'
import { webLoginType } from '@/sysConfig'
import VConsole from 'vuex'
import isMobile from './store/isMobile'
import { getCode, toIdmLoginPage, loginInIdm, loginInPhone, close } from '@/utils/login'
router.beforeEach((to, from, next) => {
const token = store.state.token
if (to.query.taskIds && to.query.taskIds !== '' && to.query.prcId && to.query.prcId !== '') {
const fullPath = to.fullPath.slice(1)
if (isMobile()) {
if (fullPath.indexOf('phone') !== 0) {
let path = fullPath.replace(fullPath.charAt(0), fullPath.charAt(0).toUpperCase())
if (path.indexOf('BussLibraryProduct/') !== -1) {
// 产品标准流程-pc端重构,pc端路由改变而手机端路由未改变,此处让手机端跳转到正确路由
path = path.replace('BussLibraryProduct/', 'BussLibraryProduct')
}
path = '/phone' + path
next({ path: path })
}
if (!to.name) {
// 不存在路由
next('/blankPage')
}
}
}
if (token && token !== '') {
if (to.path === '/') {
if (isMobile()) {
next('/phoneHome')
} else {
next('/home2')
}
}
next()
} else {
if (to.path === '/login') {
if (webLoginType === 'idm') {
// webLoginType === "idm"时不会进入login路由
// let href = window.location.href.replace('code=' + getCode(), '')
// toIdmLoginPage(href)
}
if (webLoginType === 'dev') {
next()
}
} else {
if (webLoginType === 'idm') {
if (isMobile()) {
loginInPhone().then(() => {
next()
})
} else {
if (getCode()) {
loginInIdm(getCode()).then(() => {
const path = to.fullPath.replace('code=' + getCode(), '')
next({ path })
})
} else {
toIdmLoginPage(window.location.href)
}
}
}
if (webLoginType === 'dev') {
if (isMobile()) {
next('/login')
} else {
next('/login')
}
}
}
}
})
Vue.config.productionTip = false
// jquery
Vue.prototype.$ = $
Vue.use(ElementUI)
Vue.use(common)
Vue.use(dragDialogWidth)
Vue.use(components)
Vue.use(VueI18n)
Vue.use(VueClipboard)
Vue.use(Contextmenu)
Vue.use(animate)
Vue.use(vant)
Vue.prototype.$close = close
// 原生axios
Vue.prototype.axios = axios
// 封装后的axios
Vue.prototype.$http = $axios
Vue.prototype.simpleUploadPath = simpleUploadPath
Vue.prototype.$moment = moment
// 国际化
const i18n = new VueI18n({
locale: store.getters.getLanguage || 'cn', // 定义默认语言为中文
messages: {
cn: require('@/assets/languages/cn'),
en: require('@/assets/languages/en')
}
})
/* eslint-disable no-new */
window.vm = new Vue({
VConsole,
router,
store,
i18n,
render: h => h(App)
}).$mount('#app')