123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- import axios from 'axios'
- import router, { resetRouter } from './router'
- import store from './store'
- import storage from 'store'
- import NProgress from 'nprogress'
- import '@/components/NProgress/nprogress.less'
- import notification from 'ant-design-vue/es/notification'
- import { setDocumentTitle, domTitle } from '@/utils/domUtil'
- import { userInfo } from '@/api/headerInfo/index.js'
- import { fileBimView } from '@/api/document/index.js'
- import { ACCESS_TOKEN } from '@/store/mutation-types'
- import { i18nRender } from '@/locales'
- NProgress.configure({ showSpinner: false })
- const allowList = ['login', 'register', 'registerResult', 'download', 'forget', 'oldRegister']
- const loginRoutePath = '/user/login'
- const defaultRoutePath = '/'
- router.beforeEach(async (to, from, next) => {
- console.log('to',to);
- console.log('from', from);
- NProgress.start()
- to.meta && typeof to.meta.title !== 'undefined' && setDocumentTitle(`${i18nRender(to.meta.title)} - ${domTitle}`)
-
- const token = storage.get(ACCESS_TOKEN)
- if (token) {
- if (to.path === loginRoutePath) {
- next({ path: defaultRoutePath })
- NProgress.done()
- } else {
-
- if (store.getters.roles.length === 0) {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- store
- .dispatch('getPermissions')
- .then((res) => {
-
- store.dispatch('GenerateRoutes', { token, ...res }).then(() => {
-
-
- resetRouter()
- store.getters.addRouters.forEach((r) => {
- router.addRoute(r)
- })
-
- const redirect = decodeURIComponent(from.query.redirect || to.path)
- if (to.path === redirect) {
-
- next({ ...to, replace: true })
- } else {
-
- next({ path: redirect })
- }
- })
- })
- .catch(() => {
- notification.error({
- message: '错误',
- description: '请求用户信息失败,请重试',
- })
-
- store.dispatch('Logout').then(() => {
- next({ path: loginRoutePath, query: { redirect: to.fullPath } })
- })
- })
- } else {
- if (to.path === '/4S') {
- const {
- data: { name, fs_password },
- } = await userInfo()
- axios
- .post(`http://newlinker.net:18001/login/pc?username=${name}&password=${fs_password}`)
- .then(({ data }) => {
- if (data.code === 200) {
- window.open('https://www.newlinker.net:8090?token=' + data.data.token)
- } else {
- return
- }
- })
- }
- if(to.path === '/IOT') {
- let {
- data: { bim_view },
- } = await fileBimView('1207')
- localStorage.setItem(bim_view.lightweightName, JSON.stringify([bim_view]))
- window.open(`/modelViewIOT?id=${bim_view.lightweightName}`, '_blank')
- }
- next()
- }
- }
- } else {
- if (allowList.includes(to.name)) {
-
- next()
- } else {
- next({ path: loginRoutePath, query: { redirect: to.fullPath } })
- NProgress.done()
- }
- }
- })
- router.afterEach(() => {
- NProgress.done()
- })
|