store 3
This commit is contained in:
+83
-53
@@ -3,9 +3,72 @@
|
||||
import { useRouterStore } from '@core/stores/router'
|
||||
import type { Router, RouteRecordRaw } from 'vue-router'
|
||||
import { getConfigApp, isStoreApp } from '@/utils/config'
|
||||
import { cloneDeep } from 'lodash'
|
||||
//const _router = useRouter()
|
||||
//import { cloneDeep } from 'lodash'
|
||||
|
||||
function applyAppModeMeta(route: RouteRecordRaw, appName: string | null) {
|
||||
const store = isStoreApp()
|
||||
|
||||
if (!route.children?.length) return
|
||||
|
||||
for (const child of route.children) {
|
||||
if (child.name === 'giftCardMain' && child.meta) {
|
||||
child.meta.title = store ? 'کارت هدیه و تخفیف' : 'کارت هدیه'
|
||||
child.meta.hideMenu = !store && appName !== 'garoosi'
|
||||
}
|
||||
if (child.name === 'discounts' && child.meta) {
|
||||
child.meta.hideMenu = store || appName !== 'goldsun'
|
||||
}
|
||||
if (child.name === 'banners' && child.meta) {
|
||||
child.meta.hideMenu = appName !== 'garoosi'
|
||||
}
|
||||
if (child.name === 'productsMain_categories' && child.meta) {
|
||||
child.meta.hideMenu = !store
|
||||
}
|
||||
applyAppModeMeta(child, appName)
|
||||
}
|
||||
}
|
||||
|
||||
function filterRoutesByApp(routes: RouteRecordRaw, appName: string | null) {
|
||||
if (!routes.children) return
|
||||
|
||||
routes.children = routes.children.filter((item) => {
|
||||
if (item.name === 'discounts' && (isStoreApp() || appName !== 'goldsun')) return false
|
||||
if (item.name === 'banners' && appName !== 'garoosi') return false
|
||||
if (item.name === 'authentication' && appName !== 'garoosi') return false
|
||||
if (item.name === 'giftCardMain' && !isStoreApp() && appName !== 'garoosi') return false
|
||||
|
||||
return true
|
||||
})
|
||||
|
||||
routes.children.forEach((child) => filterRoutesByApp(child, appName))
|
||||
}
|
||||
|
||||
/** بعد از تغییر is_store — منو را از روتهای تازه (clone) دوباره میسازد */
|
||||
export function refreshAppModeMenu() {
|
||||
const routerStore = useRouterStore()
|
||||
const modules = import.meta.glob<any>('./routes/*.ts', { eager: true })
|
||||
const appName = getConfigApp('name')
|
||||
|
||||
const preserved = routerStore.routes.filter(
|
||||
(route) => route.name === 'notFound' || route.name === 'factor'
|
||||
)
|
||||
|
||||
const dynamicRoutes: RouteRecordRaw[] = []
|
||||
for (const modulesKey in modules) {
|
||||
const sourceRoute: RouteRecordRaw | undefined = modules[modulesKey].default ?? undefined
|
||||
if (!sourceRoute) continue
|
||||
|
||||
const route = cloneDeep(sourceRoute)
|
||||
applyAppModeMeta(route, appName)
|
||||
filterRoutesByApp(route, appName)
|
||||
dynamicRoutes.push(route)
|
||||
}
|
||||
|
||||
routerStore.routes = [...preserved, ...dynamicRoutes]
|
||||
}
|
||||
|
||||
export function setupRoutes(permissionsKeys: string[], router?: Router) {
|
||||
//console.log('this is permission', permissionsKeys)
|
||||
//console.log('this is use router', _router)
|
||||
@@ -23,42 +86,11 @@ export function setupRoutes(permissionsKeys: string[], router?: Router) {
|
||||
(item.meta?.permissionsKey && permissionsKeys.includes(item.meta?.permissionsKey))
|
||||
)
|
||||
for (const route of routes.children) {
|
||||
/*if (!route.children || (route.children && route.children.length == 0)) {
|
||||
//path.push(route.name)
|
||||
//return
|
||||
continue
|
||||
}*/
|
||||
/*if (routes.children) {
|
||||
}*/
|
||||
walkInRoutes(route)
|
||||
/*if (route.children && route.children.length > 0) {
|
||||
path.push(route.name)
|
||||
const res = walkInRoutes(route.children)
|
||||
if (!res) {
|
||||
path.pop()
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
}*/
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
function filterRoutesByApp(routes: RouteRecordRaw) {
|
||||
if (!routes.children) return
|
||||
routes.children = routes.children.filter((item) => {
|
||||
|
||||
if (item.name === 'discounts' && (isStoreApp() || appName !== 'goldsun')) return false
|
||||
if (item.name === 'banners' && appName !== 'garoosi') return false
|
||||
if (item.name === 'authentication' && appName !== 'garoosi') return false
|
||||
if (item.name === 'giftCardMain' && !isStoreApp() && appName !== 'garoosi') return false
|
||||
|
||||
|
||||
return true
|
||||
})
|
||||
routes.children.forEach((child) => filterRoutesByApp(child))
|
||||
}
|
||||
|
||||
routerStore.routes = [
|
||||
{
|
||||
path: '/:pathMatch(.*)*',
|
||||
@@ -79,33 +111,31 @@ export function setupRoutes(permissionsKeys: string[], router?: Router) {
|
||||
},
|
||||
]
|
||||
for (const modulesKey in modules) {
|
||||
// console.log(modulesKey)
|
||||
const route: RouteRecordRaw | undefined = modules[modulesKey].default ?? undefined
|
||||
if (route) {
|
||||
if (permissionsKeys.length && permissionsKeys[0] == '*') {
|
||||
filterRoutesByApp(route)
|
||||
const sourceRoute: RouteRecordRaw | undefined = modules[modulesKey].default ?? undefined
|
||||
if (!sourceRoute) continue
|
||||
|
||||
const route = cloneDeep(sourceRoute)
|
||||
|
||||
if (permissionsKeys.length && permissionsKeys[0] == '*') {
|
||||
applyAppModeMeta(route, appName)
|
||||
filterRoutesByApp(route, appName)
|
||||
routerStore.routes.push(route)
|
||||
if (router) {
|
||||
router.addRoute(route)
|
||||
}
|
||||
} else {
|
||||
if (
|
||||
!route?.meta?.permissionsKey ||
|
||||
(route.meta.permissionsKey && permissionsKeys.includes(route.meta.permissionsKey))
|
||||
) {
|
||||
walkInRoutes(route)
|
||||
applyAppModeMeta(route, appName)
|
||||
filterRoutesByApp(route, appName)
|
||||
routerStore.routes.push(route)
|
||||
if (router) {
|
||||
router.addRoute(route)
|
||||
}
|
||||
} else {
|
||||
if (
|
||||
!route?.meta?.permissionsKey ||
|
||||
(route.meta.permissionsKey && permissionsKeys.includes(route.meta.permissionsKey))
|
||||
) {
|
||||
walkInRoutes(route)
|
||||
filterRoutesByApp(route)
|
||||
routerStore.routes.push(route)
|
||||
if (router) {
|
||||
router.addRoute(route)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// console.log(router)
|
||||
//console.log('this is store', routerStore.routes)
|
||||
/* if (router) {
|
||||
console.log('this is router routes', router.getRoutes())
|
||||
}*/
|
||||
}
|
||||
|
||||
@@ -1,36 +1,13 @@
|
||||
import type { RouteRecordRaw } from 'vue-router'
|
||||
import { getConfigApp, isStoreApp } from '@/utils/config'
|
||||
|
||||
const Orders: RouteRecordRaw = {
|
||||
/** ریدایرکت آدرس قدیمی — منو زیر پیکربندی است */
|
||||
const GiftCard: RouteRecordRaw = {
|
||||
name: 'giftCard',
|
||||
path: '/giftCard',
|
||||
component: () => import('@core/layouts/BasicLayout.vue'),
|
||||
redirect: { name: 'giftCardMain' },
|
||||
meta: {
|
||||
icon: 'vuesax-linear:gift',
|
||||
permissionsKey: 'giftCard',
|
||||
title: isStoreApp() ? 'کارت هدیه و تخفیف' : 'کارت هدیه',
|
||||
disabled: false,
|
||||
hideMenu: !isStoreApp() && getConfigApp('name') != 'garoosi',
|
||||
hideChildren: true,
|
||||
order: 7
|
||||
},
|
||||
children: [
|
||||
{
|
||||
name: 'giftCardMain',
|
||||
path: '',
|
||||
component: () => import('@/pages/menuPages/giftCards/index.vue'),
|
||||
meta: {
|
||||
permissionsKey: 'project',
|
||||
icon: 'vuesax-linear:empty-wallet-time',
|
||||
order: 3,
|
||||
title: isStoreApp() ? 'کارت هدیه و تخفیف' : 'کارت هدیه',
|
||||
disabled: false,
|
||||
hideMenu: false
|
||||
//hideChildren: false
|
||||
}
|
||||
}
|
||||
]
|
||||
hideMenu: true
|
||||
}
|
||||
}
|
||||
|
||||
export default Orders
|
||||
export default GiftCard
|
||||
|
||||
@@ -47,6 +47,16 @@ const Products: RouteRecordRaw = {
|
||||
icon: 'vuesax-linear:save-2',
|
||||
title: 'بایگانی'
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'productsMain_categories',
|
||||
path: 'categories',
|
||||
component: () => import('@/pages/menuPages/products/categories/index.vue'),
|
||||
meta: {
|
||||
icon: 'vuesax-linear:category',
|
||||
title: 'دستهبندیها',
|
||||
hideMenu: true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import type { RouteRecordRaw } from 'vue-router'
|
||||
import { getConfigApp, isStoreApp } from '@/utils/config'
|
||||
const Setting: RouteRecordRaw = {
|
||||
name: 'settings',
|
||||
path: '/settings',
|
||||
@@ -62,6 +61,27 @@ const Setting: RouteRecordRaw = {
|
||||
title: 'هشدار قیمت'
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'smsMain',
|
||||
path: 'sms',
|
||||
component: () => import('@/pages/menuPages/sms/index.vue'),
|
||||
meta: {
|
||||
permissionsKey: 'sms',
|
||||
icon: 'vuesax-linear:sms',
|
||||
title: 'پیامکها'
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'giftCardMain',
|
||||
path: 'giftCard',
|
||||
component: () => import('@/pages/menuPages/giftCards/index.vue'),
|
||||
meta: {
|
||||
permissionsKey: 'project',
|
||||
icon: 'vuesax-linear:gift',
|
||||
title: 'کارت هدیه',
|
||||
hideMenu: true
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'discounts',
|
||||
path: 'discounts',
|
||||
@@ -70,7 +90,7 @@ const Setting: RouteRecordRaw = {
|
||||
permissionsKey: 'discounts',
|
||||
icon: 'vuesax-linear:discount-shape',
|
||||
title: 'تخفیفات',
|
||||
hideMenu: isStoreApp() || getConfigApp('name') !== 'goldsun'
|
||||
hideMenu: true
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -90,7 +110,7 @@ const Setting: RouteRecordRaw = {
|
||||
meta: {
|
||||
icon: 'vuesax-linear:image',
|
||||
title: 'بنرها',
|
||||
hideMenu: getConfigApp('name') !== "garoosi"
|
||||
hideMenu: true
|
||||
}
|
||||
},
|
||||
]
|
||||
|
||||
@@ -1,35 +1,13 @@
|
||||
import type { RouteRecordRaw } from 'vue-router'
|
||||
|
||||
const Orders: RouteRecordRaw = {
|
||||
/** ریدایرکت آدرس قدیمی — منو زیر پیکربندی است */
|
||||
const Sms: RouteRecordRaw = {
|
||||
name: 'sms',
|
||||
path: '/sms',
|
||||
component: () => import('@core/layouts/BasicLayout.vue'),
|
||||
redirect: { name: 'smsMain' },
|
||||
meta: {
|
||||
icon: 'vuesax-linear:sms',
|
||||
permissionsKey: 'sms',
|
||||
title: 'پیامک ها',
|
||||
disabled: false,
|
||||
hideMenu: false,
|
||||
hideChildren: true,
|
||||
order: 9
|
||||
},
|
||||
children: [
|
||||
{
|
||||
name: 'smsMain',
|
||||
path: '',
|
||||
component: () => import('@/pages/menuPages/sms/index.vue'),
|
||||
meta: {
|
||||
permissionsKey: 'sms',
|
||||
icon: 'vuesax-linear:setting',
|
||||
order: 3,
|
||||
title: 'پیامک ها',
|
||||
disabled: false,
|
||||
hideMenu: false
|
||||
//hideChildren: false
|
||||
}
|
||||
}
|
||||
]
|
||||
hideMenu: true
|
||||
}
|
||||
}
|
||||
|
||||
export default Orders
|
||||
export default Sms
|
||||
|
||||
Reference in New Issue
Block a user