Generate routes from tabs that are kept in localStorage

This commit is contained in:
Angelina Filippova 2021-01-27 20:52:10 +03:00
parent 18d20efc5f
commit ccaeaf9ee1
4 changed files with 29 additions and 16 deletions

View file

@ -69,7 +69,7 @@
"vue": "^2.6.8", "vue": "^2.6.8",
"vue-count-to": "1.0.13", "vue-count-to": "1.0.13",
"vue-i18n": "^8.9.0", "vue-i18n": "^8.9.0",
"vue-router": "3.0.2", "vue-router": "^3.5.1",
"vue-splitpane": "1.0.2", "vue-splitpane": "1.0.2",
"vuedraggable": "^2.16.0", "vuedraggable": "^2.16.0",
"vuex": "3.0.1", "vuex": "3.0.1",

View file

@ -8,14 +8,25 @@ import Layout from '@/views/layout/Layout'
const disabledFeatures = process.env.DISABLED_FEATURES || [] const disabledFeatures = process.env.DISABLED_FEATURES || []
const settingsDisabled = disabledFeatures.includes('settings') const settingsDisabled = disabledFeatures.includes('settings')
const settingsChildren = () => {
const items = localStorage.getItem('settingsTabs') || []
return JSON.parse(items).map(({ label, value }) => {
return {
path: value,
component: () => import(`@/views/settings/components/${label}`),
name: label,
meta: { title: label }
}
})
}
const settings = { const settings = {
path: '/settings', path: '/settings',
component: Layout, component: Layout,
name: 'Settings', name: 'Settings',
hasSubmenu: true, hasSubmenu: true,
meta: { title: 'settings', icon: 'settings', noCache: true } meta: { title: 'settings', icon: 'settings', noCache: true },
children: settingsChildren()
} }
const statusesDisabled = disabledFeatures.includes('statuses') const statusesDisabled = disabledFeatures.includes('statuses')
const statuses = { const statuses = {
path: '/statuses', path: '/statuses',

View file

@ -1,6 +1,7 @@
<template> <template>
<div v-if="!item.hidden && item.children && invitesEnabled" class="menu-wrapper"> <div v-if="!item.hidden && invitesEnabled" class="menu-wrapper">
<template v-if="hasOneShowingChild(item.children,item) && (!onlyOneChild.children||onlyOneChild.noShowingChildren)&&!item.alwaysShow"> <template
v-if="item.children && hasOneShowingChild(item.children, item) && (!onlyOneChild.children || onlyOneChild.noShowingChildren) && !item.alwaysShow">
<app-link :to="resolvePath(onlyOneChild.path)"> <app-link :to="resolvePath(onlyOneChild.path)">
<el-menu-item :index="resolvePath(onlyOneChild.path)" :class="{'submenu-title-noDropdown':!isNest}"> <el-menu-item :index="resolvePath(onlyOneChild.path)" :class="{'submenu-title-noDropdown':!isNest}">
<item <item
@ -89,14 +90,15 @@ export default {
}, },
methods: { methods: {
hasOneShowingChild(children, parent) { hasOneShowingChild(children, parent) {
const showingChildren = children.filter(item => { if (parent.hasSubmenu) {
if (item.hidden) { console.log(children)
return false return false
} else { }
const showingChildren = children.filter(item => {
// Temp set(will be used if only has one showing child) // Temp set(will be used if only has one showing child)
this.onlyOneChild = item this.onlyOneChild = item
return true return true
}
}) })
// When there is only one child router, the child router is displayed by default // When there is only one child router, the child router is displayed by default

View file

@ -11258,10 +11258,10 @@ vue-loader@15.3.0:
vue-hot-reload-api "^2.3.0" vue-hot-reload-api "^2.3.0"
vue-style-loader "^4.1.0" vue-style-loader "^4.1.0"
vue-router@3.0.2: vue-router@^3.5.1:
version "3.0.2" version "3.5.1"
resolved "https://registry.yarnpkg.com/vue-router/-/vue-router-3.0.2.tgz#dedc67afe6c4e2bc25682c8b1c2a8c0d7c7e56be" resolved "https://registry.yarnpkg.com/vue-router/-/vue-router-3.5.1.tgz#edf3cf4907952d1e0583e079237220c5ff6eb6c9"
integrity sha512-opKtsxjp9eOcFWdp6xLQPLmRGgfM932Tl56U9chYTnoWqKxQ8M20N7AkdEbM5beUh6wICoFGYugAX9vQjyJLFg== integrity sha512-RRQNLT8Mzr8z7eL4p7BtKvRaTSGdCbTy2+Mm5HTJvLGYSSeG9gDzNasJPP/yOYKLy+/cLG/ftrqq5fvkFwBJEw==
vue-splitpane@1.0.2: vue-splitpane@1.0.2:
version "1.0.2" version "1.0.2"