提交 644f5e59 authored 作者: fit2cloud-chenyw's avatar fit2cloud-chenyw

fix: BS/MS多端统一入口

上级 6f9eb29c
...@@ -3,19 +3,34 @@ import store from './store' ...@@ -3,19 +3,34 @@ import store from './store'
// import { Message } from 'element-ui' // import { Message } from 'element-ui'
import NProgress from 'nprogress' // progress bar import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css' // progress bar style import 'nprogress/nprogress.css' // progress bar style
import { getToken } from '@/utils/auth' // get token from cookie import {
getToken
} from '@/utils/auth' // get token from cookie
import getPageTitle from '@/utils/get-page-title' import getPageTitle from '@/utils/get-page-title'
import { buildMenus } from '@/api/system/menu' import {
import { filterAsyncRouter } from '@/store/modules/permission' buildMenus
} from '@/api/system/menu'
import {
filterAsyncRouter
} from '@/store/modules/permission'
import {
isMobile
} from '@/utils/index'
// import bus from './utils/bus' // import bus from './utils/bus'
NProgress.configure({ showSpinner: false }) // NProgress Configuration NProgress.configure({
showSpinner: false
}) // NProgress Configuration
const whiteList = ['/login', '/401', '/404', '/delink', '/nolic'] // no redirect whitelist const whiteList = ['/login', '/401', '/404', '/delink', '/nolic'] // no redirect whitelist
router.beforeEach(async(to, from, next) => { router.beforeEach(async(to, from, next) => {
// start progress bar // start progress bar
NProgress.start() NProgress.start()
if (isMobile()) {
window.location.href = window.origin + '/app.html'
NProgress.done()
}
// set page title // set page title
document.title = getPageTitle(to.meta.title) document.title = getPageTitle(to.meta.title)
...@@ -25,7 +40,9 @@ router.beforeEach(async(to, from, next) => { ...@@ -25,7 +40,9 @@ router.beforeEach(async(to, from, next) => {
if (hasToken) { if (hasToken) {
if (to.path === '/login') { if (to.path === '/login') {
// if is logged in, redirect to the home page // if is logged in, redirect to the home page
next({ path: '/' }) next({
path: '/'
})
NProgress.done() NProgress.done()
} else { } else {
const hasGetUserInfo = store.getters.name const hasGetUserInfo = store.getters.name
...@@ -77,11 +94,18 @@ export const loadMenus = (next, to) => { ...@@ -77,11 +94,18 @@ export const loadMenus = (next, to) => {
const datas = res.data const datas = res.data
const filterDatas = filterRouter(datas) const filterDatas = filterRouter(datas)
const asyncRouter = filterAsyncRouter(filterDatas) const asyncRouter = filterAsyncRouter(filterDatas)
asyncRouter.push({ path: '*', redirect: '/404', hidden: true }) asyncRouter.push({
path: '*',
redirect: '/404',
hidden: true
})
store.dispatch('permission/GenerateRoutes', asyncRouter).then(() => { // 存储路由 store.dispatch('permission/GenerateRoutes', asyncRouter).then(() => { // 存储路由
router.addRoutes(asyncRouter) router.addRoutes(asyncRouter)
if (pathValid(to.path, asyncRouter)) { if (pathValid(to.path, asyncRouter)) {
next({ ...to, replace: true }) next({
...to,
replace: true
})
} else { } else {
next('/') next('/')
} }
......
import Cookies from 'js-cookie' import Cookies from 'js-cookie'
export function timeSection(date, type) { export function timeSection(date, type) {
if (!date) { if (!date) {
...@@ -98,7 +97,9 @@ export function parseTime(time, cFormat) { ...@@ -98,7 +97,9 @@ export function parseTime(time, cFormat) {
const time_str = format.replace(/{([ymdhisa])+}/g, (result, key) => { const time_str = format.replace(/{([ymdhisa])+}/g, (result, key) => {
const value = formatObj[key] const value = formatObj[key]
// Note: getDay() returns 0 on Sunday // Note: getDay() returns 0 on Sunday
if (key === 'a') { return ['日', '一', '二', '三', '四', '五', '六'][value ] } if (key === 'a') {
return ['日', '一', '二', '三', '四', '五', '六'][value]
}
return value.toString().padStart(2, '0') return value.toString().padStart(2, '0')
}) })
return time_str return time_str
...@@ -115,19 +116,19 @@ export function hasClass(ele, cls) { ...@@ -115,19 +116,19 @@ export function hasClass(ele, cls) {
} }
/** /**
* Add class to element * Add class to element
* @param {HTMLElement} elm * @param {HTMLElement} elm
* @param {string} cls * @param {string} cls
*/ */
export function addClass(ele, cls) { export function addClass(ele, cls) {
if (!hasClass(ele, cls)) ele.className += ' ' + cls if (!hasClass(ele, cls)) ele.className += ' ' + cls
} }
/** /**
* Remove class from element * Remove class from element
* @param {HTMLElement} elm * @param {HTMLElement} elm
* @param {string} cls * @param {string} cls
*/ */
export function removeClass(ele, cls) { export function removeClass(ele, cls) {
if (hasClass(ele, cls)) { if (hasClass(ele, cls)) {
const reg = new RegExp('(\\s|^)' + cls + '(\\s|$)') const reg = new RegExp('(\\s|^)' + cls + '(\\s|$)')
...@@ -189,12 +190,12 @@ export function param2Obj(url) { ...@@ -189,12 +190,12 @@ export function param2Obj(url) {
} }
return JSON.parse( return JSON.parse(
'{"' + '{"' +
decodeURIComponent(search) decodeURIComponent(search)
.replace(/"/g, '\\"') .replace(/"/g, '\\"')
.replace(/&/g, '","') .replace(/&/g, '","')
.replace(/=/g, '":"') .replace(/=/g, '":"')
.replace(/\+/g, ' ') + .replace(/\+/g, ' ') +
'"}' '"}'
) )
} }
...@@ -216,7 +217,9 @@ export function formatCondition(param) { ...@@ -216,7 +217,9 @@ export function formatCondition(param) {
if (!param) { if (!param) {
return null return null
} }
const result = { conditions: [] } const result = {
conditions: []
}
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
for (const [key, value] of Object.entries(param)) { for (const [key, value] of Object.entries(param)) {
result.conditions.push(value) result.conditions.push(value)
...@@ -273,13 +276,19 @@ export function getQueryVariable(variable) { ...@@ -273,13 +276,19 @@ export function getQueryVariable(variable) {
if (!query) { if (!query) {
query = Cookies.get(variable) query = Cookies.get(variable)
} }
if (query !== undefined){ if (query !== undefined) {
const vars = query.split('&') const vars = query.split('&')
for (var i = 0; i < vars.length; i++) { for (var i = 0; i < vars.length; i++) {
const pair = vars[i].split('=') const pair = vars[i].split('=')
if (pair[0] === variable) { return pair[1] } if (pair[0] === variable) {
return pair[1]
}
} }
} }
return (false) return (false)
} }
export function isMobile() {
const flag = navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)
return flag
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论