diff --git a/src/libs/util.js b/src/libs/util.js index 4a2a2c07..9860226a 100644 --- a/src/libs/util.js +++ b/src/libs/util.js @@ -48,7 +48,6 @@ util.exitFullScreen = function () { * @param {object} query query object */ util.openNewPage = function (vm, name, argu, query) { - console.log('vm.$store', vm.$store) // 已经打开的页面 let pageOpenedList = vm.$store.state.d2admin.pageOpenedList // 判断此页面是否已经打开 并且记录位置 @@ -59,22 +58,34 @@ util.openNewPage = function (vm, name, argu, query) { return same }) if (pageOpend) { - // 页面以前打开过 - console.group('page opend') - console.log('pageOpendIndex: ', pageOpendIndex) - console.groupEnd() - // 虽然页面以前打开过 - // 但是新的页面可能 name 一样,参数不一样 + // 页面以前打开过 但是新的页面可能 name 一样,参数不一样 vm.$store.commit('d2adminpageOpenedListUpdateItem', { index: pageOpendIndex, - argu: argu, - query: query + argu, + query }) } else { // 页面以前没有打开过 - console.group('page not opend') - console.log('pageOpendIndex: ', pageOpendIndex) - console.groupEnd() + const tagPool = vm.$store.state.d2admin.tagPool + let tag = tagPool.find(t => t.name === name) + if (tag) { + vm.$store.commit('d2adminTagIncreate', { + tag, argu, query + }) + } + } +} + +/** + * 判断是否在其内 + * @param {*} ele element + * @param {array} targetArr array + */ +util.oneOf = function (ele, targetArr) { + if (targetArr.indexOf(ele) >= 0) { + return true + } else { + return false } } diff --git a/src/main.js b/src/main.js index dfbb3489..8d142afa 100755 --- a/src/main.js +++ b/src/main.js @@ -92,19 +92,18 @@ new Vue({ * 处理路由 得到每一级的路由设置 */ getAllTagFromRoutes () { - console.log('routes', frameInRoutes) - const tags = [] + const tagPool = [] const push = function (routes) { routes.forEach(route => { if (route.children) { push(route.children) } else { - tags.push(route) + tagPool.push(route) } }) } push(frameInRoutes) - console.log('tags', tags) + this.$store.commit('d2admintagPoolSet', tagPool) } } }) diff --git a/src/store/modules/d2admin.js b/src/store/modules/d2admin.js index 44b6f9e2..6164bb42 100644 --- a/src/store/modules/d2admin.js +++ b/src/store/modules/d2admin.js @@ -11,13 +11,15 @@ export default { // 主题 themeList, themeActive: themeList[1], - // 多页 + // 当前显示的多页面列表 pageOpenedList: [ { name: 'index', title: '首页' } - ] + ], + // 可以在多页 tab 模式下显示的页面 + tagPool: [] }, mutations: { /** @@ -48,6 +50,28 @@ export default { }).write() } }, + /** + * 保存 tagPool (候选池) + * @param {state} state vuex state + * @param {Array} tagPool tags + */ + d2admintagPoolSet (state, tagPool) { + state.tagPool = tagPool + }, + /** + * 新增一个 tag + * @param {state} state vuex state + * @param {object} param1 new tag info + */ + d2adminTagIncreate (state, { tag, argu, query }) { + // if (!Util.oneOf(tagObj.name, state.dontCache)) { + // state.cachePage.push(tagObj.name); + // localStorage.cachePage = JSON.stringify(state.cachePage); + // } + // state.pageOpenedList.push(tagObj); + // localStorage.pageOpenedList = JSON.stringify(state.pageOpenedList); + console.log('d2adminTagIncreate') + }, /** * 切换全屏 * @param {state} state vuex state