Commit 2ca012c8 by caoyanzhi

update: 客户标签

parent 399544bc
import Router from 'vue-router'; import Router from 'vue-router';
import _import from './_import.js'; import _import from './_import.js';
import delCache from '../utils/del-cache.js';
// import delCache from '@/utils/router-utils.js'; // import delCache from '@/utils/router-utils.js';
const errorPage = r => { const errorPage = r => {
import('view/errorPage/index.vue').then(module => { import('view/errorPage/index.vue').then(module => {
...@@ -203,8 +204,14 @@ const router = new Router({ ...@@ -203,8 +204,14 @@ const router = new Router({
scrollBehavior: () => ({ y: 0 }) scrollBehavior: () => ({ y: 0 })
}) })
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
const { fromPath = [] } = from.meta || {}; const { keepAlive, componentName, fromPath } = to.meta || {};
from.meta.keepAlive = fromPath.includes(to.path); if (keepAlive && fromPath.every(el => el != '/')) {
fromPath.push('/');
}
// 当前路径的keepAlive为true而且from.path不在fromPath中时,将清除to.path的缓存
if (keepAlive && fromPath.every(el => el != from.path)) {
delCache(router.apps, componentName);
}
next(); next();
}) })
export default router; export default router;
/** /**
* 需求分析
* A是列表页,B是详情页,C是另一个列表页
* A=>B=>A A的状态不变
* A=>C=>A A为初始状态
* A=>B=>C=>A A为初始状态
* A=>B=>A=>C=>A A为初始状态
* A=>B=>A=>C=>A=>B=>A A的状态不变(保持A最新的状态)
* A=>B=>A=>C=>A=>B=>C=>A A为初始状态
*/
/**
* 查找指定的组件实例 * 查找指定的组件实例
* @param {array} components 组件树 * @param {array} components 组件树
* @param {string} componentName 指定的组件name * @param {string} componentName 指定的组件name
...@@ -18,6 +7,7 @@ ...@@ -18,6 +7,7 @@
function getComponent(components, componentName) { function getComponent(components, componentName) {
let result = {}; let result = {};
components.some(el => { components.some(el => {
// console.log(el.$options.name);
if (el.$options.name == componentName) { if (el.$options.name == componentName) {
result = el; result = el;
} else if (Array.isArray(el.$children)) { } else if (Array.isArray(el.$children)) {
...@@ -33,13 +23,12 @@ function getComponent(components, componentName) { ...@@ -33,13 +23,12 @@ function getComponent(components, componentName) {
* @param {object} vm 组件实例 * @param {object} vm 组件实例
*/ */
function delCache(vm) { function delCache(vm) {
let { componentOptions, parent = {}, key } = vm.$vnode || {}; if (!vm.$vnode) return;
let { componentOptions, parent, key } = vm.$vnode || {};
let { cache, keys } = parent.componentInstance || {}; let { cache, keys } = parent.componentInstance || {};
cache = cache || {}; cache = cache || {};
keys = Array.isArray(keys) ? keys : []; keys = Array.isArray(keys) ? keys : [];
if (!componentOptions) return;
if (!key) { if (!key) {
const { Ctor, tag } = componentOptions; const { Ctor, tag } = componentOptions;
key = Ctor.cid + (tag ? `::${tag}` : ''); key = Ctor.cid + (tag ? `::${tag}` : '');
...@@ -54,4 +43,4 @@ function delCache(vm) { ...@@ -54,4 +43,4 @@ function delCache(vm) {
export default (components, componentName) => { export default (components, componentName) => {
delCache(getComponent(components, componentName)); delCache(getComponent(components, componentName));
}; };
\ No newline at end of file
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
style="width: 260px;float: left;margin-left: 0" style="width: 260px;float: left;margin-left: 0"
v-model="memberTag" v-model="memberTag"
@keyup.native.enter="searchMemberList" @keyup.native.enter="searchMemberList"
@blur="searchMemberList"
@clear="allTagList" @clear="allTagList"
clearable clearable
></el-input> ></el-input>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment