187 lines
5.7 KiB
TypeScript
187 lines
5.7 KiB
TypeScript
import { createRouter, createWebHistory } from 'vue-router'
|
|
import AdminShell from '@/layouts/AdminShell.vue'
|
|
import { useAuthStore } from '@/stores/auth'
|
|
|
|
const router = createRouter({
|
|
history: createWebHistory(import.meta.env.BASE_URL),
|
|
routes: [
|
|
{
|
|
path: '/login',
|
|
name: 'login',
|
|
component: () => import('@/views/auth/LoginView.vue'),
|
|
meta: { public: true, title: 'ورود به پنل مدیریت' },
|
|
},
|
|
{
|
|
path: '/',
|
|
component: AdminShell,
|
|
meta: { requiresAuth: true },
|
|
children: [
|
|
{
|
|
path: '',
|
|
name: 'dashboard',
|
|
component: () => import('@/views/dashboard/DashboardView.vue'),
|
|
meta: { title: 'داشبورد مدیریتی' },
|
|
},
|
|
{
|
|
path: 'orders',
|
|
name: 'orders',
|
|
component: () => import('@/views/orders/OrdersView.vue'),
|
|
meta: { title: 'سفارشها' },
|
|
},
|
|
{
|
|
path: 'orders/:id/pricing',
|
|
name: 'order-pricing',
|
|
component: () => import('@/views/orders/OrderPricingView.vue'),
|
|
meta: { title: 'قیمتگذاری سفارش' },
|
|
},
|
|
{
|
|
path: 'checks',
|
|
name: 'checks',
|
|
component: () => import('@/views/checks/ChecksListView.vue'),
|
|
meta: { title: 'چکها' },
|
|
},
|
|
{
|
|
path: 'orders/:id/checks',
|
|
name: 'order-checks',
|
|
component: () => import('@/views/checks/CheckManagementView.vue'),
|
|
meta: { title: 'مدیریت چکهای سفارش' },
|
|
},
|
|
{
|
|
/* API links often use /orders/:id — open list + detail via query */
|
|
path: 'orders/:id',
|
|
name: 'order-detail',
|
|
redirect: (to) => ({
|
|
name: 'orders',
|
|
query: { order: String(to.params.id) },
|
|
}),
|
|
},
|
|
{
|
|
path: 'companies',
|
|
name: 'companies',
|
|
component: () => import('@/views/companies/CompaniesView.vue'),
|
|
meta: { title: 'مدیریت شرکتها' },
|
|
},
|
|
{
|
|
path: 'companies/:companyId/accounts',
|
|
name: 'bank-accounts',
|
|
component: () => import('@/views/companies/BankAccountsView.vue'),
|
|
meta: { title: 'حسابهای بانکی' },
|
|
},
|
|
{
|
|
path: 'customers',
|
|
name: 'customers',
|
|
component: () => import('@/views/customers/CustomersView.vue'),
|
|
meta: { title: 'مشتریان و واسطهها' },
|
|
},
|
|
{
|
|
path: 'products',
|
|
name: 'products',
|
|
component: () => import('@/views/products/ProductsView.vue'),
|
|
meta: { title: 'محصولات' },
|
|
},
|
|
{
|
|
path: 'categories',
|
|
name: 'categories',
|
|
component: () => import('@/views/categories/CategoriesView.vue'),
|
|
meta: { title: 'دستهبندیها' },
|
|
},
|
|
{
|
|
path: 'banners',
|
|
name: 'banners',
|
|
component: () => import('@/views/banners/BannersView.vue'),
|
|
meta: { title: 'بنرها' },
|
|
},
|
|
{
|
|
path: 'catalogs',
|
|
name: 'catalogs',
|
|
component: () => import('@/views/catalogs/CatalogsView.vue'),
|
|
meta: { title: 'کالیتهها' },
|
|
},
|
|
{
|
|
path: 'catalog-requests',
|
|
name: 'catalog-requests',
|
|
component: () => import('@/views/catalog-requests/CatalogRequestsView.vue'),
|
|
meta: { title: 'درخواست کالیته فیزیکی' },
|
|
},
|
|
{
|
|
path: 'brands',
|
|
name: 'brands',
|
|
component: () => import('@/views/brands/BrandsView.vue'),
|
|
meta: { title: 'برندها' },
|
|
},
|
|
{
|
|
path: 'suggestions',
|
|
name: 'suggestions',
|
|
component: () => import('@/views/suggestions/SuggestionsView.vue'),
|
|
meta: { title: 'پیشنهاد محصول' },
|
|
},
|
|
{
|
|
path: 'stock-alerts',
|
|
name: 'stock-alerts',
|
|
component: () => import('@/views/stock-alerts/StockAlertsView.vue'),
|
|
meta: { title: 'خبر موجودی' },
|
|
},
|
|
{
|
|
path: 'levels',
|
|
name: 'levels',
|
|
component: () => import('@/views/levels/LevelsView.vue'),
|
|
meta: { title: 'سطوح مشتری' },
|
|
},
|
|
{
|
|
path: 'cash-payments',
|
|
name: 'cash-payments',
|
|
component: () => import('@/views/cash-payments/CashPaymentsView.vue'),
|
|
meta: { title: 'پرداختهای نقدی' },
|
|
},
|
|
{
|
|
path: 'shipping',
|
|
name: 'shipping',
|
|
component: () => import('@/views/shipping/ShippingView.vue'),
|
|
meta: { title: 'ارسال و باربری' },
|
|
},
|
|
{
|
|
path: 'reports',
|
|
name: 'reports',
|
|
component: () => import('@/views/reports/ReportsView.vue'),
|
|
meta: { title: 'گزارشها' },
|
|
},
|
|
{
|
|
path: 'settings',
|
|
name: 'settings',
|
|
component: () => import('@/views/settings/SettingsView.vue'),
|
|
meta: { title: 'تنظیمات' },
|
|
},
|
|
{
|
|
path: 'users',
|
|
name: 'users',
|
|
component: () => import('@/views/users/UsersView.vue'),
|
|
meta: { title: 'کاربران و دسترسیها' },
|
|
},
|
|
],
|
|
},
|
|
],
|
|
})
|
|
|
|
router.beforeEach((to) => {
|
|
const auth = useAuthStore()
|
|
auth.hydrate()
|
|
|
|
if (to.meta.public) {
|
|
if (auth.isAuthenticated && to.name === 'login') {
|
|
return { name: 'dashboard' }
|
|
}
|
|
return true
|
|
}
|
|
|
|
if (to.matched.some((record) => record.meta.requiresAuth) && !auth.isAuthenticated) {
|
|
return {
|
|
name: 'login',
|
|
query: { redirect: to.fullPath },
|
|
}
|
|
}
|
|
|
|
return true
|
|
})
|
|
|
|
export default router
|