Crunchy
2025-06-14 7e460156de73171f9660ce48f80703e79f8b478d
src/router/index.js
@@ -1,6 +1,6 @@
import Vue from 'vue'
import Router from 'vue-router'
import store from '@/store/index'
Vue.use(Router)
/* Layout */
@@ -33,6 +33,7 @@
export const constantRoutes = [
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
@@ -49,27 +50,27 @@
    redirect: '/home',
    children: [{
      path: 'home',
      name: 'Home',
      name: '主页',
      component: () => import('@/views/home/index'),
      meta: { title: '首页', icon: 'el-icon-house' }
      meta: { title: '首页', icon: 'icon-shouye' }
    }]
  },
  {
    path: '/add_operation',
    component: Layout,
    redirect: '/add_operation/table',
    meta: { title: '入库操作', icon: 'el-icon-edit-outline' },
    meta: { title: '入库操作', icon: 'icon-warehouse' },
    children: [
      {
        path: 'table',
        name: '入库操作',
        component: () => import('@/views/add_operation/index'),
        meta: { title: '入库操作', icon: 'el-icon-edit-outline' }
        meta: { title: '入库操作', icon: 'icon-warehouse' }
      }
    // ,{
    //   path: 'barcode',
    //   component: () => import('@/views/add_operation/barcode'),
    //   meta: { title: '条码打印', icon: 'el-icon-edit-outline' }
    //   meta: { title: '条码打印', icon: 'icon-warehouse' }
    // }
    ]
  },
@@ -77,39 +78,39 @@
    path: '/out_operation',
    component: Layout,
    redirect: '/out_operation/table',
    meta: { title: '出库操作', icon: 'el-icon-box' },
    meta: { title: '出库操作', icon: 'icon-warehouseOut' },
    children: [
      {
        path: 'table',
        name: 'OutOperation',
        name: '出库操作',
        component: () => import('@/views/out_operation/index'),
        meta: { title: '出库操作', icon: 'el-icon-box' }
        meta: { title: '出库操作', icon: 'icon-warehouseOut' }
      }
      // ,{
      //   path: 'manual',
      //   name: 'manual',
      //   component: () => import('@/views/out_operation/manual'),
      //   meta: { title: '手动出库', icon: 'el-icon-box' }
      // },
      // {
      //   path: 'outboundLedger',
      //   name: 'outboundLedger',
      //   component: () => import('@/views/out_operation/outboundLedger'),
      //   meta: { title: '出库台账', icon: 'el-icon-box' }
      // }
    ]
  },
  {
    path: '/outbound',
    component: Layout,
    redirect: '/outbound/book',
    meta: { title: '库存管理', icon: 'el-icon-box' },
    meta: { title: '库存管理', icon: 'icon-biaogeziduan' },
    children: [
      {
        path: 'book',
        name: '收发存管理',
        component: () => import('@/views/outbound/index.vue'),
        meta: { title: '库存管理', icon: 'el-icon-box' }
        meta: { title: '收发存管理', icon: 'icon-kucunguanli' }
      },
      {
        path: 'outboundLedger',
        name: '出库台账',
        component: () => import('@/views/outbound/outboundLedger'),
        meta: { title: '出库台账', icon: 'icon-taizhangzhangbuxinxichaxun' }
      }
      // ,{
      //   path: 'depositoryManagement',
@@ -122,7 +123,7 @@
    path: '/system',
    component: Layout,
    redirect: '/system/user',
    meta: { title: '系统设置', icon: 'el-icon-box' },
    meta: { title: '系统设置', icon: 'icon-yonghuguanli' },
    children: [
      // {
      //   path: 'index',
@@ -131,8 +132,9 @@
      // },
      {
        path: 'user',
        name: '系统设置',
        component: () => import('@/views/system/user'),
        meta: { title: '用户管理', icon: 'el-icon-box' }
        meta: { title: '用户管理', icon: 'icon-yonghuguanli' }
      }
      // ,{
      //   path: 'dict',
@@ -146,7 +148,7 @@
]
const createRouter = () => new Router({
  // mode: 'history', // require service support
  mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})
@@ -159,4 +161,40 @@
  router.matcher = newRouter.matcher // reset router
}
const getState = ()=> import("@/store/index")
router.beforeEach(async (to, from, next) => {
  // console.log(to,from)
 let state = (await getState()).default.state
  // console.log(state)
  // console.log(to)
  if (to.name === 'login') {
    next()
    return
  }
  // console.log("跳转路由前的判断")
  let flag = false;
  let {openTab} = state.openTab
  // console.log(openTab)
  for (let item of openTab) {
    // console.log(item)
    // console.log("item.name" , item.name)
    // console.log("t0.name",to.name)
    if(item.name === to.name) {
      // console.log('to.path',to.path);
      store.commit('SET_ACTIVE_INDEX',to.path)
      flag = true;
      break;
    }
  }
  if(!flag) {
    // console.log("执行一遍")
    // console.log('to.path',to.path);
    store.commit('ADD_TAB', {route: to.path, name: to.name});
    store.commit('SET_ACTIVE_INDEX', to.path);
  }
  next()
})
export default router