index.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. import Vue from "vue";
  2. import Router from "vue-router";
  3. import module from "./module";
  4. import Index from "@views/home/Index";
  5. import Search from "@views/shop/GoodSearch";
  6. import Category from "@views/shop/GoodsClass";
  7. import ShoppingCart from "@views/shop/ShoppingCart";
  8. import GoodsList from "@views/shop/GoodsList";
  9. import NotDefined from "@views/NotDefined";
  10. import $store from "../store";
  11. import toLogin from "@libs/login";
  12. import Loading from "@views/Loading";
  13. Vue.use(Router);
  14. const router = new Router({
  15. mode: "history",
  16. routes: [
  17. {
  18. path: "/",
  19. name: "Index",
  20. meta: {
  21. title: "首页",
  22. keepAlive: true,
  23. footer: true,
  24. backgroundColor: "#fff"
  25. },
  26. component: Index
  27. },
  28. {
  29. path: "/customer/chat/:id/:productId?",
  30. name: "CustomerService",
  31. meta: {
  32. title: "客服聊天",
  33. keepAlive: false,
  34. auth: true
  35. },
  36. component: () => import("@views/user/CustomerService.vue")
  37. },
  38. {
  39. path: "/category/:pid?",
  40. name: "GoodsClass",
  41. meta: {
  42. title: "产品分类",
  43. keepAlive: true,
  44. footer: true,
  45. backgroundColor: "#fff"
  46. },
  47. component: Category
  48. },
  49. {
  50. path: "/collection",
  51. name: "GoodsCollection",
  52. meta: {
  53. title: "收藏商品",
  54. keepAlive: false,
  55. auth: true
  56. },
  57. component: () => import("@views/shop/GoodsCollection.vue")
  58. },
  59. {
  60. path: "/search",
  61. name: "GoodSearch",
  62. meta: {
  63. title: "搜索商品",
  64. keepAlive: true,
  65. backgroundColor: "#fff"
  66. },
  67. component: Search
  68. },
  69. {
  70. path: "/news_detail/:id",
  71. name: "NewsDetail",
  72. meta: {
  73. title: "新闻详情",
  74. keepAlive: true,
  75. backgroundColor: "#fff"
  76. },
  77. component: () => import("@views/shop/news/NewsDetail.vue")
  78. },
  79. {
  80. path: "/news_list",
  81. name: "NewsList",
  82. meta: {
  83. title: "新闻",
  84. keepAlive: true,
  85. backgroundColor: "#fff"
  86. },
  87. component: () => import("@views/shop/news/NewsList.vue")
  88. },
  89. {
  90. path: "/evaluate_list/:id",
  91. name: "EvaluateList",
  92. meta: {
  93. title: "商品评分",
  94. keepAlive: true,
  95. auth: true
  96. },
  97. component: () => import("@views/shop/EvaluateList.vue")
  98. },
  99. {
  100. path: "/goods_evaluate/:id",
  101. name: "GoodsEvaluate",
  102. meta: {
  103. title: "商品评价",
  104. keepAlive: true,
  105. auth: true
  106. },
  107. component: () => import("@views/shop/GoodsEvaluate.vue")
  108. },
  109. {
  110. path: "/promotion",
  111. name: "GoodsPromotion",
  112. meta: {
  113. title: "促销单品",
  114. keepAlive: false
  115. },
  116. component: () => import("@views/shop/GoodsPromotion.vue")
  117. },
  118. {
  119. path: "/hot_new_goods/:type",
  120. name: "HotNewGoods",
  121. meta: {
  122. title: "热门榜单",
  123. keepAlive: false
  124. },
  125. component: () => import("@views/shop/HotNewGoods.vue")
  126. },
  127. {
  128. path: "/detail/:id",
  129. name: "GoodsCon",
  130. meta: {
  131. title: "商品详情",
  132. keepAlive: false
  133. },
  134. component: () => import("@views/shop/GoodsCon.vue")
  135. },
  136. {
  137. path: "/shop/storeList/:gonames?",
  138. name: "StoreList",
  139. meta: {
  140. title: "门店列表",
  141. keepAlive: false
  142. },
  143. component: () => import("@views/shop/StoreList.vue")
  144. },
  145. {
  146. path: "/cart",
  147. name: "ShoppingCart",
  148. meta: {
  149. title: "购物车",
  150. keepAlive: true,
  151. footer: true,
  152. auth: true
  153. },
  154. component: ShoppingCart
  155. },
  156. {
  157. path: "/goods_list",
  158. name: "GoodsList",
  159. meta: {
  160. title: "商品列表",
  161. keepAlive: true
  162. },
  163. component: GoodsList
  164. },
  165. {
  166. path: "/register",
  167. name: "Register",
  168. meta: {
  169. title: "注册",
  170. keepAlive: true
  171. },
  172. component: () =>
  173. import(/* webpackChunkName: "login" */ "@views/user/Register.vue")
  174. },
  175. {
  176. path: "/change_password",
  177. name: "ChangePassword",
  178. meta: {
  179. title: "修改密码",
  180. keepAlive: true,
  181. backgroundColor: "#fff",
  182. auth: true
  183. },
  184. component: () =>
  185. import(/* webpackChunkName: "login" */ "@views/user/ChangePassword.vue")
  186. },
  187. {
  188. path: "/retrieve_password",
  189. name: "RetrievePassword",
  190. meta: {
  191. title: "找回密码",
  192. keepAlive: true
  193. },
  194. component: () =>
  195. import(/* webpackChunkName: "login" */ "@views/user/RetrievePassword.vue")
  196. },
  197. {
  198. path: "/login",
  199. name: "Login",
  200. meta: {
  201. title: "登录",
  202. keepAlive: true
  203. },
  204. component: () =>
  205. import(/* webpackChunkName: "login" */ "@views/user/Login.vue")
  206. },
  207. ...module,
  208. {
  209. path: "/auth/:url",
  210. name: "Loading",
  211. meta: {
  212. title: " 加载中",
  213. keepAlive: true
  214. },
  215. component: Loading
  216. },
  217. {
  218. path: "*",
  219. name: "NotDefined",
  220. meta: {
  221. title: "页面找不到",
  222. keepAlive: true,
  223. home: false,
  224. backgroundColor: "#F4F6FB"
  225. },
  226. component: NotDefined
  227. }
  228. ],
  229. scrollBehavior(to, from) {
  230. from.meta.scrollTop = window.scrollY;
  231. return { x: 0, y: to.meta.scrollTop || 0 };
  232. }
  233. });
  234. const { back, replace } = router;
  235. router.back = function() {
  236. this.isBack = true;
  237. back.call(router);
  238. };
  239. router.replace = function(...args) {
  240. this.isReplace = true;
  241. replace.call(router, ...args);
  242. };
  243. router.beforeEach((to, form, next) => {
  244. const { title, backgroundColor, footer, home, auth } = to.meta;
  245. console.log(to.name, form.name);
  246. if (auth === true && !$store.state.app.token) {
  247. if (form.name === "Login") return;
  248. return toLogin(true, to.fullPath);
  249. }
  250. document.title = title || process.env.VUE_APP_NAME || "crmeb商城";
  251. //判断是否显示底部导航
  252. footer === true ? $store.commit("SHOW_FOOTER") : $store.commit("HIDE_FOOTER");
  253. //控制悬浮按钮是否显示
  254. home === false ? $store.commit("HIDE_HOME") : $store.commit("SHOW_HOME");
  255. $store.commit("BACKGROUND_COLOR", backgroundColor || "#F5F5F5");
  256. if (auth) {
  257. $store.dispatch("USERINFO").then(() => {
  258. next();
  259. });
  260. } else next();
  261. });
  262. export default router;