Files
newfreeplanet_OLD/src/layouts/menuone/menuOne.ts

108 lines
2.8 KiB
TypeScript
Raw Normal View History

2021-08-31 18:09:59 +02:00
import { IListRoutes } from '@src/model'
import { useGlobalStore } from '@store/globalStore'
import { tools } from '@store/Modules/tools'
import { computed, defineComponent, ref, watch } from 'vue'
2021-08-31 18:09:59 +02:00
import { useRoute } from 'vue-router'
2021-09-16 21:08:02 +02:00
import { static_data } from '@/db/static_data'
import { useUserStore } from '@store/UserStore'
2021-08-31 18:09:59 +02:00
export default defineComponent({
name: 'MenuOne',
props: {
clBase: {
type: String,
required: false,
default: 'my-menu',
},
},
setup(props) {
const route = useRoute()
const userStore = useUserStore()
2021-09-16 21:08:02 +02:00
const globalStore = useGlobalStore()
2021-08-31 18:09:59 +02:00
2021-10-01 03:08:43 +02:00
const finishLoading = computed(() => globalStore.finishLoading)
2021-08-31 18:09:59 +02:00
const path = computed(() => route.path)
const getroutes = computed(() => static_data.routes)
const myroutes = ref(<IListRoutes[]>[])
2021-08-31 18:09:59 +02:00
function getmenu(): any {
// console.log('getmenu menuOne!')
2021-08-31 18:09:59 +02:00
return globalStore.getmenu
}
function setParentVisibilityBasedOnRoute(parent: any) {
parent.routes.forEach((item: any) => {
if (path.value === item.path) {
parent.show = true
}
})
}
watch(() => userStore.isLogged || finishLoading.value,(to, from) => {
myroutes.value = []
myroutes.value = static_data.routes
})
watch(() => path, (to, from) => {
2021-09-16 21:08:02 +02:00
const mymenu = globalStore.getmenu
2021-10-02 02:03:10 +02:00
// console.log('watch:', mymenu)
2021-09-16 21:08:02 +02:00
Object.keys(mymenu).forEach((parentName: any) => {
// console.log('parentName', parentName)
2021-08-31 18:09:59 +02:00
// @ts-ignore
2021-09-16 21:08:02 +02:00
setParentVisibilityBasedOnRoute(mymenu[parentName])
2021-08-31 18:09:59 +02:00
})
})
/* function replaceUnderlineToSpace(text: string) {
while (text.indexOf('_') !== -1) {
text = text.replace('_', ' ')
}
return text
} */
function getroute(elem: IListRoutes) {
if (elem.idelem) {
return tools.getUrlByTipoProj(elem.urlroute ? elem.urlroute : '') + elem.idelem
}
return elem.path
}
function getmymenuclass(elem: IListRoutes) {
let menu: string = props.clBase
if (elem.color) {
menu += ` ${elem.color}`
} else {
if (elem.onlyAdmin) menu += ' isAdmin'
if (elem.onlyManager) menu += ' isManager'
if (elem.onlySocioResidente) menu += ' isSocioResidente'
if (elem.onlyConsiglio) menu += ' isConsiglio'
if (elem.onlyDepartment) menu += ' isDepartment'
if (elem.onlyFacilitatore) menu += ' isTutor'
2021-08-31 18:09:59 +02:00
if (elem.onlyEditor) menu += ' isEditor'
}
if (elem.extraclass) menu += ` ${elem.extraclass}`
return menu
}
myroutes.value = static_data.routes
2021-08-31 18:09:59 +02:00
return {
getmenu,
2021-10-01 03:08:43 +02:00
finishLoading,
2021-08-31 18:09:59 +02:00
getmymenuclass,
getroute,
2021-09-16 21:08:02 +02:00
static_data,
tools,
getroutes,
myroutes,
2021-08-31 18:09:59 +02:00
}
},
})