Commit 068dea78 by liimin

优化部分代码

1 parent ef1a8385
...@@ -9,12 +9,17 @@ ...@@ -9,12 +9,17 @@
*/ */
import { push } from './history' import { push } from './history'
import { Subject } from 'rxjs' import { Subject } from 'rxjs'
/**
* Messenger类扩展了Subject类,用于发送和接收消息。
*/
class Messenger extends Subject { class Messenger extends Subject {
constructor() { /**
super() * send方法用于发送消息,并将消息推送到浏览器历史记录中。
} * @param {Object} msg - 要发送的消息对象。
* @param {string} msg.route - 要推送到浏览器历史记录中的路由。
*/
send(msg) { send(msg) {
if (!msg) return
const { route } = msg const { route } = msg
if (route) { if (route) {
push(route) push(route)
......
import Vue from 'vue' import Vue from 'vue'
import { Message, Button, ButtonGroup, Container, Aside, Menu, MenuItem, Submenu, MenuItemGroup, Header, Main, Footer, Avatar, Badge, Dropdown, DropdownMenu, DropdownItem, Scrollbar, Carousel, CarouselItem, Form, FormItem, Input, Image, Tabs, TabPane, Loading, Dialog, Alert, Popover, Tooltip } from 'element-ui' import { Message, Button, ButtonGroup, Container, Aside, Menu, MenuItem, Submenu, MenuItemGroup, Header, Main, Footer, Avatar, Badge, Dropdown, DropdownMenu, DropdownItem, Scrollbar, Carousel, CarouselItem, Form, FormItem, Input, Image, Tabs, TabPane, Loading, Dialog, Alert, Popover, Tooltip } from 'element-ui'
Vue.use(Button) ;[Button, ButtonGroup, Container, Aside, Menu, MenuItem, Submenu, MenuItemGroup, Header, Main, Footer, Avatar, Badge, Dropdown, DropdownMenu, DropdownItem, Scrollbar, Carousel, CarouselItem, Form, FormItem, Input, Image, Tabs, TabPane, Loading, Dialog, Alert, Popover, Tooltip].forEach(component => Vue.use(component))
Vue.use(ButtonGroup)
Vue.use(Container)
Vue.use(Aside)
Vue.use(Menu)
Vue.use(MenuItem)
Vue.use(Submenu)
Vue.use(MenuItemGroup)
Vue.use(Header)
Vue.use(Main)
Vue.use(Footer)
Vue.use(Avatar)
Vue.use(Badge)
Vue.use(Dropdown)
Vue.use(DropdownMenu)
Vue.use(DropdownItem)
Vue.use(Scrollbar)
Vue.use(Carousel)
Vue.use(CarouselItem)
Vue.use(Form)
Vue.use(FormItem)
Vue.use(Input)
Vue.use(Image)
Vue.use(Tabs)
Vue.use(TabPane)
Vue.use(Loading)
Vue.use(Dialog)
Vue.use(Alert)
Vue.use(Popover)
Vue.use(Tooltip)
export { Message } export { Message }
...@@ -91,26 +91,47 @@ router.onError(err => { ...@@ -91,26 +91,47 @@ router.onError(err => {
console.log(err) console.log(err)
}) })
router.beforeEach(async (to, from, next) => { router.beforeEach(async (to, from, next) => {
if (Object.values(Path).includes(to.path)) return next() const isPathIncluded = Object.values(Path).includes(to.path)
if (isPathIncluded) {
return next()
}
const session = store.getters.auth.session const session = store.getters.auth.session
const storeSession = utils.storage.getSession(constants.SCRM_BASE_SESSION) const storeSession = utils.storage.getSession(constants.SCRM_BASE_SESSION)
if (storeSession) { if (storeSession && from === VueRouter.START_LOCATION && session === null) {
if (from === VueRouter.START_LOCATION && session === null) {
await store.dispatch('init/init') await store.dispatch('init/init')
return next({ ...to, replace: true }) return next({ ...to, replace: true })
} }
// if (router.hasRoute(to.path)) { if (storeSession) {
const { $title } = to.query const { $title } = to.query
$title && (to.meta.title = $title) $title && (to.meta.title = $title)
store.dispatch('app/setCurrentPage', to.meta) store.dispatch('app/setCurrentPage', to.meta)
return next() return next()
// }
// return next({ path: Path.E404, replace: true })
} }
if (!session) { if (!session) {
next({ path: Path.LOGIN }) return next({ path: Path.LOGIN })
} }
// next({ path: Path.LOGIN })
}) })
// router.beforeEach(async (to, from, next) => {
// if (Object.values(Path).includes(to.path)) return next()
// const session = store.getters.auth.session
// const storeSession = utils.storage.getSession(constants.SCRM_BASE_SESSION)
// if (storeSession) {
// if (from === VueRouter.START_LOCATION && session === null) {
// await store.dispatch('init/init')
// return next({ ...to, replace: true })
// }
// // if (router.hasRoute(to.path)) {
// const { $title } = to.query
// $title && (to.meta.title = $title)
// store.dispatch('app/setCurrentPage', to.meta)
// return next()
// // }
// // return next({ path: Path.E404, replace: true })
// }
// if (!session) {
// next({ path: Path.LOGIN })
// }
// // next({ path: Path.LOGIN })
// })
export default router export default router
import { utils } from 'glsx-common' import { utils } from 'glsx-common'
import { constants } from '@/common' import { constants } from '@/common'
const modulesFiles = require const modulesFiles = require.context('.', true, /^(?!.*\/init\.js$).*\.js$/)
.context('.', true, /\.js$/)
.keys()
.filter(key => key !== './init.js')
const init = { const init = {
namespaced: true, namespaced: true,
actions: { actions: {
......
<template> <template>
<div class="about"> <div class="not-found">
<router-link :to="{ path: auth.session.defaultPath }">404</router-link> <h1 class="title">404 - 页面未找到</h1>
<p class="message">很抱歉,我们无法找到您要访问的页面。</p>
<router-link :to="{ path: auth.session.defaultPath }" class="link">返回首页</router-link>
</div> </div>
</template> </template>
<script> <script>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!