@@ -2,11 +2,18 @@ import router from './router'
import store from './store'
import { Message } from 'element-ui'
import { getToken } from '@/utils/auth'
+import { createHash } from '@/utils/tools'
import getPageTitle from '@/utils/get-page-title'
const whiteList = ['/login', '/auth-redirect']
const toSupplier = ['/supplier/list', '/supplier']
+// 重置登录信息和路由信息及标签页信息
+const resetState = () => {
+ store.dispatch('user/logout')
+ store.dispatch('resetState')
+}
+
router.beforeEach(async(to, from, next) => {
// 设置页面名称
document.title = getPageTitle(to.meta.title)
@@ -52,13 +59,16 @@ router.beforeEach(async(to, from, next) => {
next({ ...to, replace: true })
} catch (error) {
- store.dispatch('user/resetToken')
Message.error(error || '未知错误,请重新登录')
+ // 重置登录信息和路由信息及标签页信息
+ resetState()
next(`/login?redirect=${to.path}`)
}
} else {
// token不存在并且访问的路由非拦截路由
if (whiteList.indexOf(to.path) !== -1) {
// 允许访问
@@ -66,7 +76,7 @@ router.beforeEach(async(to, from, next) => {
// 跳转到登录页面
Message({ message: '登录失效,请重新登录!', duration: 1500 })
- next(`/login`)
+ next(`/login?cm=${createHash(6)}`)
return
@@ -123,7 +123,7 @@ export const asyncRoutes = [
hidden: true,
path: 'edit',
component: () => import('@/views/supplier/user/edit'),
- name: 'SupplierAdd',
+ name: 'SupplierEdit',
meta: { title: '修改供应商', icon: 'el-icon-menu', roles: ['admin'], noCache: true }
]
@@ -152,14 +152,14 @@ export const asyncRoutes = [
alwaysShow: true,
redirect: '/product/list',
- name: 'Auth',
+ name: 'Product',
meta: { title: '商品管理', icon: 'el-icon-s-shop', roles: ['admin', 'normal'], noCache: true, proxy: true },
children: [
{
path: 'list',
component: () => import('@/views/supplier/product/index'),
- name: 'Product',
+ name: 'ProductList',
meta: { title: '商品列表', icon: 'el-icon-menu', roles: ['admin', 'normal'], noCache: true, proxy: true }
},
@@ -197,7 +197,7 @@ export const asyncRoutes = [
path: 'auth-list',
component: () => import('@/views/supplier/review/authList'),
- name: 'AuthList',
+ name: 'ReviewAuthList',
meta: { title: '授权机构审核列表', icon: 'el-icon-menu', roles: ['admin'], noCache: true }
@@ -3,7 +3,6 @@ const getters = {
size: state => state.app.size,
countryList: state => state.app.countryList,
device: state => state.app.device,
- isRefresh: state => state.app.isRefresh,
visitedViews: state => state.tagsView.visitedViews,
cachedViews: state => state.tagsView.cachedViews,
token: state => state.user.token,
@@ -22,8 +22,9 @@ const store = new Vuex.Store({
actions: {
// 重置部分state
resetState({ commit }) {
- commit('permission/RESET_STATE')
- commit('tagsView/RESET_STATE')
+ commit('permission/RESET_STATE') // 重置路由
+ commit('tagsView/RESET_STATE') // 重置标签
+ commit('webSocket/CLEAR_MESSAGE') // 重置消息列表
closeWebSocket()
@@ -40,6 +40,9 @@ const mutations = {
return v
})
+ },
+ CLEAR_MESSAGE: (state) => {
+ state.messageList = []
const actions = {
@@ -51,7 +51,7 @@ window.onbeforeunload = function() {
// 关闭连接
export function closeWebSocket() {
- websocket.close()
+ websocket && websocket.close()
// 发送消息
@@ -2,7 +2,7 @@
* 节流
* @param {Function} func 回调函数
* @param {Number} wait 时间限制
- * @returns
+ * @returns 返回函数表达式
*/
export function throttle(func, wait) {
let timeout
@@ -18,8 +18,14 @@ export function throttle(func, wait) {
-// 防抖
-export function debounce(func, wait, immediate) {
+/**
+ * 防抖
+ * @param {Function} func 回调函数
+ * @param {Number} wait 时间限制
+ * @param {Boolean} immediate 是否立即执行回调 true:立即执行,false:等待wait秒后执行
+ */
+export function debounce(func, wait, immediate = false) {
let timeout, result
return function() {
const context = this
@@ -39,3 +45,20 @@ export function debounce(func, wait, immediate) {
return result
+ * 生成hash字符串
+ * @param {Number} hashLength 生成的hash值的字符长度
+ * @returns hash字符串
+export function createHash(hashLength) {
+ if (!hashLength || typeof (Number(hashLength)) !== 'number') { return }
+ var ar = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
+ var hs = []
+ var hl = Number(hashLength)
+ var al = ar.length
+ for (var i = 0; i < hl; i++) {
+ hs.push(ar[Math.floor(Math.random() * al)])
+ }
+ return hs.join('')