Files
fabric_trade_admin/src/router/index.ts
T
safavimohadeseh78andCursor 1c3c494a43 Improve order detail UX, confirm check actions, and fix notification deep links.
Normalize inbox /orders/:id links, open related admin pages on click, and keep Jalali dates consistent.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-09 14:32:09 +02:00

144 lines
4.2 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: '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: 'catalogs',
name: 'catalogs',
component: () => import('@/views/catalogs/CatalogsView.vue'),
meta: { title: 'کالیته‌ها' },
},
{
path: 'checks',
name: 'checks',
redirect: { name: 'order-checks', params: { id: 'ord-1' } },
},
{
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