index.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /**
  2. * 全站路由配置
  3. *
  4. * 建议:
  5. * 1. 代码中路由统一使用name属性跳转(不使用path属性)
  6. */
  7. import Vue from 'vue'
  8. import Router from 'vue-router'
  9. import { clearLoginInfo } from '@/utils'
  10. Vue.use(Router)
  11. // 开发环境不使用懒加载, 因为懒加载页面太多的话会造成webpack热更新太慢, 所以只有生产环境使用懒加载
  12. const _import = require('./import-' + process.env.NODE_ENV)
  13. // 全局路由(无需嵌套上左右整体布局)
  14. const globalRoutes = [
  15. { path: '/404', component: _import('common/404'), name: '404', meta: { title: '404未找到' } }
  16. ]
  17. // 参猫
  18. export const toolsNav0 = [
  19. {
  20. path: '/tools-analyze',
  21. component: _import('modules/tools/tools-analyze'),
  22. name: 'toolsAnalyze',
  23. meta: { title: '任意竞品透析' }
  24. },
  25. {
  26. path: '/tools-online',
  27. component: _import('modules/tools/tools-online'),
  28. name: 'toolsOnline',
  29. meta: { title: '在线指数还原' }
  30. }
  31. ]
  32. export const toolsNav1 = [
  33. {
  34. path: '/tools-credit',
  35. component: _import('modules/tools/tools-credit'),
  36. name: 'toolsCredit',
  37. meta: { title: '淘宝极速验号' }
  38. },
  39. {
  40. path: '/tools-ordersearch',
  41. component: _import('modules/tools/tools-ordersearch'),
  42. name: 'toolsOrdersearch',
  43. meta: { title: '淘客订单查询' }
  44. }
  45. ]
  46. export const toolsNav2 = [
  47. {
  48. path: '/tools-starkeysearch',
  49. component: _import('modules/tools/tools-starkeysearch'),
  50. name: 'toolsStarkeysearch',
  51. meta: { title: '淘宝下拉框选词' }
  52. },
  53. {
  54. path: '/tools-shopinfo',
  55. component: _import('modules/tools/tools-shopinfo'),
  56. name: 'toolsShopinfo',
  57. meta: { title: '店铺信息查询' }
  58. },
  59. {
  60. path: '/tools-promote',
  61. component: _import('modules/tools/tools-promote'),
  62. name: 'toolsPromote',
  63. meta: { title: '淘宝卡首屏' }
  64. }
  65. ]
  66. export const toolsNav3 = [
  67. {
  68. path: '/tools-pricetrend',
  69. component: _import('modules/tools/tools-pricetrend'),
  70. name: 'toolsPricetrend',
  71. meta: { title: '价格走势' }
  72. }
  73. ]
  74. export const toolsRoutes = [
  75. {
  76. path: '/tools-feedback',
  77. component: _import('modules/tools/tools-feedback'),
  78. name: 'toolsFeedback',
  79. meta: { title: '商品评论查询' }
  80. },
  81. {
  82. path: '/tools-productinfo',
  83. component: _import('modules/tools/tools-productinfo'),
  84. name: 'toolsProductinfo',
  85. meta: { title: '商品信息查询' }
  86. },
  87. {
  88. path: '/tools-productaskinfo',
  89. component: _import('modules/tools/tools-productaskinfo'),
  90. name: 'toolsProductaskinfo',
  91. meta: { title: '商品问大家' }
  92. }
  93. ]
  94. // 个人中心
  95. const mineRoutes = [
  96. {
  97. path: '/mine',
  98. component: _import('modules/mine/index'),
  99. children: [
  100. {
  101. path: '',
  102. component: _import('modules/mine/user'),
  103. name: 'mine',
  104. meta: {
  105. title: '个人中心',
  106. isTab: true,
  107. isAuth: true
  108. }
  109. },
  110. {
  111. path: '/order-check-order',
  112. component: _import('modules/mine/order/order-check-order'),
  113. name: 'orderCheckOrder',
  114. meta: {
  115. title: '订单查询',
  116. isTab: true,
  117. isAuth: true
  118. }
  119. },
  120. {
  121. path: '/order-check-package',
  122. component: _import('modules/mine/order/order-check-package'),
  123. name: 'orderCheckPackage',
  124. meta: {
  125. title: '包裹查询',
  126. isTab: true,
  127. isAuth: true
  128. }
  129. },
  130. {
  131. path: '/pay-check',
  132. component: _import('modules/mine/pay/pay-check'),
  133. name: 'payCheck',
  134. meta: {
  135. title: '充值',
  136. isTab: true,
  137. isUseCache: false,
  138. keepAlive: true,
  139. isAuth: true
  140. }
  141. },
  142. {
  143. path: '/pay-wallet',
  144. component: _import('modules/mine/pay/pay-wallet'),
  145. name: 'payWallet',
  146. meta: {
  147. title: '我的钱包',
  148. isTab: true,
  149. isUseCache: false,
  150. keepAlive: true,
  151. isAuth: true
  152. }
  153. }
  154. ]
  155. }
  156. ]
  157. // 礼品商城
  158. const mallRoutes = [
  159. {
  160. path: '/mall',
  161. component: _import('modules/mall/index'),
  162. name: 'mall',
  163. meta: {
  164. title: '礼品商城',
  165. isUseCache: false,
  166. keepAlive: true
  167. }
  168. },
  169. {
  170. path: '/goods-detail',
  171. component: _import('modules/mall/goods-detail'),
  172. name: 'goodsDetail',
  173. meta: {
  174. title: '商品详情',
  175. isUseCache: false
  176. },
  177. props: (route) => ({
  178. id: route.query.id
  179. })
  180. },
  181. {
  182. path: '/goods-create-order',
  183. component: _import('modules/mall/goods-create-order'),
  184. name: 'goodsCreateOrder',
  185. meta: {
  186. title: '创建订单',
  187. isUseCache: false
  188. },
  189. props: (route) => ({
  190. id: route.query.id
  191. })
  192. },
  193. {
  194. path: '/goods-order-detail',
  195. component: _import('modules/mall/goods-order-detail'),
  196. name: 'goodsOrderDetail',
  197. meta: {
  198. title: '订单详情',
  199. isUseCache: false
  200. },
  201. props: (route) => ({
  202. id: route.query.id
  203. })
  204. }
  205. ]
  206. // 主入口路由(需嵌套上左右整体布局)
  207. const mainRoutes = {
  208. path: '/',
  209. component: _import('main'),
  210. name: 'main',
  211. redirect: { name: 'home' },
  212. meta: { title: '主入口整体布局' },
  213. children: [
  214. // 通过meta对象设置路由展示方式
  215. // 1. isTab: 是否通过tab展示内容, true: 是, false: 否
  216. // 2. iframeUrl: 是否通过iframe嵌套展示内容, '以http[s]://开头': 是, '': 否
  217. // 提示: 如需要通过iframe嵌套展示内容, 但不通过tab打开, 请自行创建组件使用iframe处理!
  218. { path: '/login', component: _import('modules/account/login'), name: 'login', meta: { title: '登录' } },
  219. { path: '/register', component: _import('modules/account/register'), name: 'register', meta: { title: '注册' } },
  220. { path: '/home', component: _import('common/home'), name: 'home', meta: { title: '首页', isTab: true } },
  221. ...toolsNav0,
  222. ...toolsNav1,
  223. ...toolsNav2,
  224. ...toolsNav3,
  225. ...toolsRoutes,
  226. ...mineRoutes,
  227. ...mallRoutes
  228. ]
  229. }
  230. const router = new Router({
  231. mode: 'history',
  232. scrollBehavior (to, from, savedPosition) {
  233. if (to.hash) {
  234. return {
  235. selector: to.hash
  236. }
  237. }
  238. // keep-alive 返回缓存页面后记录浏览位置
  239. if (savedPosition && to.meta.keepAlive) {
  240. return savedPosition
  241. }
  242. // 异步滚动操作
  243. return new Promise((resolve) => {
  244. setTimeout(() => {
  245. resolve({ x: 0, y: 1 })
  246. }, 0)
  247. })
  248. },
  249. isAddDynamicMenuRoutes: false, // 是否已经添加动态(菜单)路由
  250. routes: globalRoutes.concat(mainRoutes)
  251. })
  252. router.beforeEach((to, from, next) => {
  253. let token = Vue.cookie.get('token')
  254. if ((!token || !/\S/.test(token)) && to.meta.isAuth) {
  255. clearLoginInfo()
  256. next({ name: 'login' })
  257. } else {
  258. next()
  259. }
  260. })
  261. export default router