index.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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. isUseCache: false,
  108. keepAlive: true,
  109. isAuth: true
  110. }
  111. },
  112. {
  113. path: '/order-check-order',
  114. component: _import('modules/mine/order/order-check-order'),
  115. name: 'orderCheckOrder',
  116. meta: {
  117. title: '订单查询',
  118. isTab: true,
  119. isUseCache: false,
  120. keepAlive: true,
  121. isAuth: true
  122. }
  123. },
  124. {
  125. path: '/order-check-package',
  126. component: _import('modules/mine/order/order-check-package'),
  127. name: 'orderCheckPackage',
  128. meta: {
  129. title: '包裹查询',
  130. isTab: true,
  131. isUseCache: false,
  132. keepAlive: true,
  133. isAuth: true
  134. },
  135. props: (route) => ({
  136. orderNumber: route.query.orderNumber
  137. })
  138. },
  139. {
  140. path: '/pay-check',
  141. component: _import('modules/mine/pay/pay-check'),
  142. name: 'payCheck',
  143. meta: {
  144. title: '充值',
  145. isTab: true,
  146. isUseCache: false,
  147. keepAlive: true,
  148. isAuth: true
  149. }
  150. },
  151. {
  152. path: '/pay-wallet',
  153. component: _import('modules/mine/pay/pay-wallet'),
  154. name: 'payWallet',
  155. meta: {
  156. title: '我的钱包',
  157. isTab: true,
  158. isUseCache: false,
  159. keepAlive: true,
  160. isAuth: true
  161. }
  162. }
  163. ]
  164. }
  165. ]
  166. // 礼品商城
  167. const mallRoutes = [
  168. {
  169. path: '/mall',
  170. component: _import('modules/mall/index'),
  171. name: 'mall',
  172. meta: {
  173. title: '礼品商城',
  174. isUseCache: false,
  175. keepAlive: true
  176. }
  177. },
  178. {
  179. path: '/goods-detail',
  180. component: _import('modules/mall/goods-detail'),
  181. name: 'goodsDetail',
  182. meta: {
  183. title: '商品详情',
  184. isUseCache: false,
  185. keepAlive: true
  186. },
  187. props: (route) => ({
  188. id: route.query.id
  189. })
  190. },
  191. {
  192. path: '/goods-create-order',
  193. component: _import('modules/mall/goods-create-order'),
  194. name: 'goodsCreateOrder',
  195. meta: {
  196. title: '创建订单',
  197. isUseCache: false
  198. },
  199. props: (route) => ({
  200. id: route.query.id
  201. })
  202. },
  203. {
  204. path: '/goods-order-detail',
  205. component: _import('modules/mall/goods-order-detail'),
  206. name: 'goodsOrderDetail',
  207. meta: {
  208. title: '订单详情',
  209. isUseCache: false
  210. },
  211. props: (route) => ({
  212. id: route.query.id
  213. })
  214. }
  215. ]
  216. // 主入口路由(需嵌套上左右整体布局)
  217. const mainRoutes = {
  218. path: '/',
  219. component: _import('main'),
  220. name: 'main',
  221. redirect: { name: 'home' },
  222. meta: { title: '主入口整体布局' },
  223. children: [
  224. // 通过meta对象设置路由展示方式
  225. // 1. isTab: 是否通过tab展示内容, true: 是, false: 否
  226. // 2. iframeUrl: 是否通过iframe嵌套展示内容, '以http[s]://开头': 是, '': 否
  227. // 提示: 如需要通过iframe嵌套展示内容, 但不通过tab打开, 请自行创建组件使用iframe处理!
  228. {
  229. path: '/login',
  230. component: _import('modules/account/login'),
  231. name: 'login',
  232. meta: {
  233. title: '登录'
  234. }
  235. },
  236. {
  237. path: '/register',
  238. component: _import('modules/account/register'),
  239. name: 'register',
  240. meta: {
  241. title: '注册'
  242. }
  243. },
  244. {
  245. path: '/home',
  246. component: _import('common/home'),
  247. name: 'home',
  248. meta: {
  249. title: '首页',
  250. isTab: true
  251. }
  252. },
  253. ...toolsNav0,
  254. ...toolsNav1,
  255. ...toolsNav2,
  256. ...toolsNav3,
  257. ...toolsRoutes,
  258. ...mineRoutes,
  259. ...mallRoutes
  260. ]
  261. }
  262. const router = new Router({
  263. mode: 'history',
  264. scrollBehavior (to, from, savedPosition) {
  265. if (to.hash) {
  266. return {
  267. selector: to.hash
  268. }
  269. }
  270. // keep-alive 返回缓存页面后记录浏览位置
  271. if (savedPosition && to.meta.keepAlive) {
  272. return savedPosition
  273. }
  274. // 异步滚动操作
  275. return new Promise((resolve) => {
  276. setTimeout(() => {
  277. resolve({ x: 0, y: 1 })
  278. }, 0)
  279. })
  280. },
  281. isAddDynamicMenuRoutes: false, // 是否已经添加动态(菜单)路由
  282. routes: globalRoutes.concat(mainRoutes)
  283. })
  284. router.beforeEach((to, from, next) => {
  285. let token = Vue.cookie.get('token')
  286. if ((!token || !/\S/.test(token)) && to.meta.isAuth) {
  287. clearLoginInfo()
  288. next({ name: 'login' })
  289. } else {
  290. next()
  291. }
  292. })
  293. export default router