gxd-vue-library
Version:
依赖与element Ui插件库,聚福宝福利PC端插件库
53 lines (45 loc) • 1.49 kB
JavaScript
;
import store from './../store'
import NProgress from "nprogress";
class Middleware {
constructor(to, router, next, NProgress){
this.to = to;
this.next = next;
this.router = router;
this.NProgress = NProgress
this.init().then().catch();
}
/**
* @description 对象转url参数
* @param params
*/
jsonToParams(params={}) {
let arr = [];
Object.keys(params).map(key=>{
arr.push(`${key}=${params[key]}`)
});
return arr;
}
async init(){
let query = this.to.query;
if(query['jfb-sidebar'] && query['jfb-sidebar'] === '1') {
// let cachedViews = JSON.parse(JSON.stringify(store.state.tagsView.cachedViews));
// if(cachedViews.includes(this.to.name)) {
// await store.dispatch('tagsView/delCachedView', this.to)
// console.warn(`侧边栏命中.router.name=${this.to.name}`);
// console.warn(`cachedViews=${JSON.stringify(cachedViews)}`);
// }
//console.warn(`侧边栏命中.router.name=${this.to.name}`);
// if(this.to.query && this.to.query['jfb-sidebar'] === '1'){
// delete this.to.query['jfb-sidebar'];
// }
// let url = `${this.to.path}`;
// let arrParams = this.jsonToParams(this.to.query || {});
// if(arrParams.length > 0) url = `${url}?${arrParams}`;
// this.NProgress.done()
}
}
}
export function middleware(to, router, next, NProgress){
return new Middleware(to, router, next, NProgress)
}