421 lines
15 KiB
TypeScript
421 lines
15 KiB
TypeScript
import { createRouter, createWebHistory, type RouteRecordRaw } from 'vue-router';
|
|
import { useAuth } from '../modules/auth/composables/useAuth';
|
|
|
|
// Importar vistas
|
|
import Login from '../modules/auth/components/Login.vue';
|
|
import MainLayout from '../MainLayout.vue';
|
|
import WarehouseIndex from '../modules/warehouse/components/WarehouseIndex.vue';
|
|
import WarehouseForm from '../modules/warehouse/components/WarehouseForm.vue';
|
|
import WarehouseDetails from '../modules/warehouse/components/WarehouseDetails.vue';
|
|
import WarehouseClassification from '../modules/warehouse/components/WarehouseClassification.vue';
|
|
import Units from '../modules/catalog/components/units/Units.vue';
|
|
import ProductsIndex from '../modules/products/components/ProductsIndex.vue';
|
|
import ProductForm from '../modules/products/components/ProductForm.vue';
|
|
import StoresIndex from '../modules/stores/components/StoresIndex.vue';
|
|
|
|
import RolesIndex from '../modules/users/components/RoleIndex.vue';
|
|
import RoleForm from '../modules/users/components/RoleForm.vue';
|
|
import UserIndex from '../modules/users/components/UserIndex.vue';
|
|
import StoreDetails from '../modules/stores/components/StoreDetails.vue';
|
|
import Positions from '../modules/rh/components/positions/Positions.vue';
|
|
import Departments from '../modules/rh/components/departments/Departments.vue';
|
|
|
|
import Companies from '../modules/catalog/components/companies/Companies.vue';
|
|
import '../modules/catalog/components/suppliers/Suppliers.vue';
|
|
import Suppliers from '../modules/catalog/components/suppliers/Suppliers.vue';
|
|
import Purchases from '../modules/purchases/components/Purchases.vue';
|
|
import PurchaseDetails from '../modules/purchases/components/PurchaseDetails.vue';
|
|
import PurchaseForm from '../modules/purchases/components/PurchaseForm.vue';
|
|
import WarehouseAddInventory from '../modules/warehouse/components/WarehouseAddInventory.vue';
|
|
import ModelDocuments from '../modules/catalog/components/ModelDocuments.vue';
|
|
import Requisitions from '../modules/requisitions/Requisitions.vue';
|
|
import CreateRequisition from '../modules/requisitions/CreateRequisition.vue';
|
|
import ClassificationsComercial from '../modules/catalog/components/comercial-classification/ClassificationsComercial.vue';
|
|
import WarehouseOutInventory from '../modules/warehouse/components/WarehouseOutInventory.vue';
|
|
import companiesRouter from '@/modules/catalog/components/companies/companies.router';
|
|
|
|
const routes: RouteRecordRaw[] = [
|
|
{
|
|
path: '/login',
|
|
name: 'Login',
|
|
component: Login,
|
|
meta: {
|
|
requiresAuth: false,
|
|
title: 'Iniciar Sesión'
|
|
}
|
|
},
|
|
{
|
|
path: '/',
|
|
component: MainLayout,
|
|
meta: {
|
|
requiresAuth: true
|
|
},
|
|
children: [
|
|
{
|
|
path: '',
|
|
name: 'Dashboard',
|
|
component: WarehouseIndex,
|
|
meta: {
|
|
title: 'Dashboard',
|
|
requiresAuth: true
|
|
}
|
|
},
|
|
{
|
|
path: 'warehouse',
|
|
name: 'Warehouse',
|
|
meta: {
|
|
title: 'Almacén',
|
|
requiresAuth: true
|
|
},
|
|
children: [
|
|
{
|
|
path: '',
|
|
name: 'WarehouseHome',
|
|
component: WarehouseIndex,
|
|
meta: {
|
|
title: 'Almacén - Dashboard',
|
|
requiresAuth: true
|
|
}
|
|
},
|
|
{
|
|
path: 'create',
|
|
name: 'WarehouseCreate',
|
|
component: WarehouseForm,
|
|
meta: {
|
|
title: 'Crear Almacén',
|
|
requiresAuth: true
|
|
}
|
|
},
|
|
{
|
|
path: ':id',
|
|
name: 'WarehouseDetails',
|
|
component: WarehouseDetails,
|
|
meta: {
|
|
title: 'Detalles del Almacén',
|
|
requiresAuth: true
|
|
}
|
|
},
|
|
{
|
|
path: 'classifications',
|
|
name: 'WarehouseClassifications',
|
|
component: WarehouseClassification,
|
|
meta: {
|
|
title: 'Clasificaciones de Almacén',
|
|
requiresAuth: true
|
|
}
|
|
},
|
|
{
|
|
path: 'batch-add',
|
|
name: 'WarehouseAddInventory',
|
|
component: WarehouseAddInventory,
|
|
meta: {
|
|
title: 'Agregar Items al Inventario',
|
|
requiresAuth: true
|
|
}
|
|
},
|
|
{
|
|
path: 'out-of-stock',
|
|
name: 'WarehouseOutOfStock',
|
|
component: WarehouseOutInventory,
|
|
meta: {
|
|
title: 'Salida de Inventario',
|
|
requiresAuth: true
|
|
}
|
|
},
|
|
{
|
|
path: 'inventory',
|
|
name: 'WarehouseInventory',
|
|
component: WarehouseIndex,
|
|
meta: {
|
|
title: 'Inventario - Almacén',
|
|
requiresAuth: true
|
|
}
|
|
},
|
|
{
|
|
path: 'movements',
|
|
name: 'WarehouseMovements',
|
|
component: WarehouseIndex,
|
|
meta: {
|
|
title: 'Movimientos - Almacén',
|
|
requiresAuth: true
|
|
}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
path: 'catalog',
|
|
name: 'Catalog',
|
|
meta: {
|
|
title: 'Catálogo',
|
|
requiresAuth: true
|
|
},
|
|
children: [
|
|
{
|
|
path: 'units-of-measure',
|
|
name: 'UnitsOfMeasure',
|
|
component: Units,
|
|
meta: {
|
|
title: 'Unidades de Medida',
|
|
requiresAuth: true
|
|
}
|
|
},
|
|
{
|
|
path: 'classifications-comercial',
|
|
name: 'ClassificationsComercial',
|
|
component: ClassificationsComercial,
|
|
meta: {
|
|
title: 'Clasificaciones Comerciales',
|
|
requiresAuth: true
|
|
}
|
|
},
|
|
{
|
|
path: 'companies',
|
|
name: 'Companies',
|
|
component: Companies,
|
|
meta: {
|
|
title: 'Empresas',
|
|
requiresAuth: true
|
|
}
|
|
},
|
|
{
|
|
path: 'suppliers',
|
|
name: 'Suppliers',
|
|
component: Suppliers,
|
|
meta: {
|
|
title: 'Proveedores',
|
|
requiresAuth: true
|
|
}
|
|
},
|
|
{
|
|
path: 'model-documents',
|
|
name: 'ModelDocuments',
|
|
component: ModelDocuments,
|
|
meta: {
|
|
title: 'Documentos del Modelo',
|
|
requiresAuth: true
|
|
}
|
|
},
|
|
companiesRouter
|
|
]
|
|
},
|
|
{
|
|
path: 'purchases',
|
|
name: 'Purchases',
|
|
meta: {
|
|
title: 'Compras',
|
|
requiresAuth: true
|
|
},
|
|
children: [
|
|
{
|
|
path: 'requests',
|
|
name: 'PurchaseRequests',
|
|
component: Purchases,
|
|
},
|
|
{
|
|
path: ':id',
|
|
name: 'PurchaseDetails',
|
|
component: PurchaseDetails,
|
|
},
|
|
{
|
|
path: 'create',
|
|
name: 'PurchaseCreate',
|
|
component: PurchaseForm,
|
|
},
|
|
]
|
|
},
|
|
{
|
|
path: 'products',
|
|
name: 'Products',
|
|
component: ProductsIndex,
|
|
meta: {
|
|
title: 'Productos',
|
|
requiresAuth: true
|
|
},
|
|
children: [
|
|
{
|
|
path: 'create',
|
|
name: 'ProductCreate',
|
|
component: ProductForm,
|
|
meta: {
|
|
title: 'Crear Producto',
|
|
requiresAuth: true
|
|
}
|
|
},
|
|
]
|
|
},
|
|
{
|
|
path: 'stores',
|
|
name: 'Stores',
|
|
component: StoresIndex,
|
|
meta: {
|
|
title: 'Tiendas',
|
|
requiresAuth: true
|
|
}
|
|
},
|
|
{
|
|
path: 'stores/:id',
|
|
name: 'StoreDetails',
|
|
component: StoreDetails,
|
|
meta: {
|
|
title: 'Detalles de la Tienda',
|
|
requiresAuth: true
|
|
}
|
|
},
|
|
{
|
|
path: 'users',
|
|
name: 'Usuarios',
|
|
|
|
meta: {
|
|
title: 'Roles',
|
|
requiresAuth: true
|
|
},
|
|
children: [
|
|
{
|
|
path: '',
|
|
name: 'UserIndex',
|
|
component: UserIndex,
|
|
},
|
|
]
|
|
},
|
|
{
|
|
path: 'roles',
|
|
name: 'Roles',
|
|
|
|
meta: {
|
|
title: 'Roles',
|
|
requiresAuth: true
|
|
},
|
|
children: [
|
|
{
|
|
path: '',
|
|
name: 'RoleIndex',
|
|
component: RolesIndex,
|
|
meta: {
|
|
title: 'Roles',
|
|
requiresAuth: true
|
|
}
|
|
},
|
|
{
|
|
path: 'permissions/:id',
|
|
name: 'RolePermissions',
|
|
component: RoleForm,
|
|
meta: {
|
|
title: 'Administrar Permisos',
|
|
requiresAuth: true
|
|
}
|
|
},
|
|
]
|
|
},
|
|
{
|
|
path: 'rh',
|
|
name: 'RH',
|
|
meta: {
|
|
title: 'Recursos Humanos',
|
|
requiresAuth: true
|
|
},
|
|
children: [
|
|
{
|
|
path: 'departments',
|
|
name: 'Departments',
|
|
component: Departments,
|
|
meta: {
|
|
title: 'Gestión de Departamentos',
|
|
requiresAuth: true
|
|
}
|
|
},
|
|
{
|
|
path: 'positions',
|
|
name: 'Positions',
|
|
component: Positions,
|
|
meta: {
|
|
title: 'Gestión de Puestos',
|
|
requiresAuth: true
|
|
}
|
|
},
|
|
]
|
|
},
|
|
{
|
|
path: 'requisitions',
|
|
name: 'RequisitionsModule',
|
|
meta: {
|
|
title: 'Requisiciones',
|
|
requiresAuth: true
|
|
},
|
|
children: [
|
|
{
|
|
path: '',
|
|
name: 'Requisitions',
|
|
component: Requisitions,
|
|
meta: {
|
|
title: 'Gestión de Requisiciones',
|
|
requiresAuth: true
|
|
}
|
|
},
|
|
{
|
|
path: 'create',
|
|
name: 'RequisitionCreate',
|
|
component: CreateRequisition,
|
|
meta: {
|
|
title: 'Crear Requisición',
|
|
requiresAuth: true
|
|
}
|
|
},
|
|
{
|
|
path: 'edit/:id',
|
|
name: 'RequisitionEdit',
|
|
component: CreateRequisition,
|
|
meta: {
|
|
title: 'Editar Requisición',
|
|
requiresAuth: true
|
|
}
|
|
},
|
|
{
|
|
path: ':id',
|
|
name: 'RequisitionView',
|
|
component: CreateRequisition,
|
|
meta: {
|
|
title: 'Ver Requisición',
|
|
requiresAuth: true
|
|
}
|
|
}
|
|
]
|
|
}
|
|
]
|
|
},
|
|
{
|
|
path: '/:pathMatch(.*)*',
|
|
redirect: '/'
|
|
}
|
|
];
|
|
|
|
const router = createRouter({
|
|
history: createWebHistory(),
|
|
routes
|
|
});
|
|
|
|
// Navigation Guard
|
|
router.beforeEach((to, _from, next) => {
|
|
const { isAuthenticated } = useAuth();
|
|
|
|
// Actualizar título de la página
|
|
document.title = to.meta.title
|
|
? `${to.meta.title} - GOLS Control`
|
|
: 'GOLS Control';
|
|
|
|
// Verificar si la ruta requiere autenticación
|
|
if (to.meta.requiresAuth && !isAuthenticated.value) {
|
|
// Redirigir al login si no está autenticado
|
|
next({
|
|
name: 'Login',
|
|
query: { redirect: to.fullPath } // Guardar ruta para redireccionar después del login
|
|
});
|
|
} else if (to.name === 'Login' && isAuthenticated.value) {
|
|
// Si ya está autenticado y va al login, redirigir al dashboard
|
|
next({ name: 'Dashboard' });
|
|
} else {
|
|
next();
|
|
}
|
|
});
|
|
|
|
export default router;
|