yangfeng
2023-09-22 fbdb1d15b6cf692d27598806eee6be6f16e1f36d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import Vue from "vue"
import Router from "vue-router"
// import type from "@/router/deployCode"
 
import productRouter from "./product/index.js" // 产品
import operateRouter from "./operate/index.js" // 操作
import warehouseManageRouter from "./warehouseManage/index.js" // 仓库管理
 
Vue.use(Router)
const login = (resolve) => require(["@/views/other/login/index"], resolve)
const overview = (resolve) => require(["@/views/overview/index"], resolve) // 概述
const productManage = (resolve) => require(["@/views/productManage/index"], resolve) // 产品
const operate = (resolve) => require(["@/views/operate/index"], resolve) // 操作
const warehouseManage = (resolve) => require(["@/views/warehouseManage/index"], resolve) // 仓库管理
 
export const routes = [
  {
    path: "overview", // 概述
    name: "overview",
    component: overview,
    meta: {
      title: "概述",
      isAllways: true
    }
  },
  {
    path: "productManage", // 产品
    name: "productManage",
    component: productManage,
    children: productRouter,
    meta: {
      title: "产品",
      isAllways: true
    }
  },
  {
    path: "operate", // 操作
    name: "operate",
    component: operate,
    children: operateRouter,
    meta: {
      title: "操作",
      isAllways: true
    }
  },
  {
    path: "warehouseManage", // 仓库管理
    name: "warehouseManage",
    component: warehouseManage,
    children: warehouseManageRouter,
    meta: {
      title: "仓库管理",
      isAllways: true
    }
  }
]
export const constantRoutes = [
  {
    path: "/",
    component: () => import("@/components/layout/index"),
    name: "Index",
    meta: {
      title: "概述",
      isAllways: true,
      insIndex: true
    },
    redirect: {
      name: "overview"
    },
    children: routes
  },
  {
    path: "/login",
    component: login,
    meta: {
      isLogin: true,
      title: "登录"
    }
  },
  {
    path: "*",
    component: () => import("@/views/other/error/404"),
    meta: {
      title: "404"
    }
  }
]
// 导出路由 在 main.js 里使用
const createRouter = () =>
  new Router({
    mode: "history",
    // base: window.getServerJson.context,
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  })
 
const router = createRouter()
 
router.afterEach((to, from, next) => {
  if ((to.path === "/overview/overviewList" || to.path === "/productManage/productList") && to.params.name) {
    console.log(from, next)
    to.meta.title = to.params.name
    document.title = to.meta.title
  }
})
// router.beforeEach((to, from, next) => {
// must call `next`
// console.log(to, from)
// if (to.path === "/custom/salesLead") {
//   next()
// } else {
// if (to.meta.requireAuth) {
//   next({
//     path: "/login",
//     query: { redirect: to.fullPath }
//   })
// } else {
//   next()
// }
// }
// })
 
export default router