index.ts 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router";
  2. import Layout from "../layout/index.vue";
  3. import { storageSession } from "../utils/storage";
  4. const routes: Array<RouteRecordRaw> = [
  5. {
  6. path: "/",
  7. name: "home",
  8. component: Layout,
  9. redirect: "/welcome",
  10. children: [
  11. {
  12. path: "/welcome",
  13. name: "welcome",
  14. component: () =>
  15. import(/* webpackChunkName: "home" */ "../views/welcome.vue"),
  16. meta: {
  17. title: "message.hshome",
  18. showLink: true,
  19. savedPosition: false,
  20. },
  21. },
  22. ],
  23. meta: {
  24. icon: "el-icon-s-home",
  25. showLink: true,
  26. savedPosition: false,
  27. },
  28. },
  29. {
  30. path: "/components",
  31. name: "components",
  32. component: Layout,
  33. redirect: "/components/split-pane",
  34. children: [
  35. {
  36. path: "/components/video",
  37. component: () =>
  38. import(
  39. /* webpackChunkName: "components" */ "../views/components/video/index.vue"
  40. ),
  41. meta: {
  42. title: "message.hsvideo",
  43. showLink: false,
  44. savedPosition: true,
  45. },
  46. },
  47. {
  48. path: "/components/map",
  49. component: () =>
  50. import(
  51. /* webpackChunkName: "components" */ "../views/components/map/index.vue"
  52. ),
  53. meta: {
  54. title: "message.hsmap",
  55. showLink: false,
  56. savedPosition: true,
  57. },
  58. },
  59. {
  60. path: "/components/draggable",
  61. component: () =>
  62. import(
  63. /* webpackChunkName: "components" */ "../views/components/draggable/index.vue"
  64. ),
  65. meta: {
  66. title: "message.hsdraggable",
  67. showLink: false,
  68. savedPosition: true,
  69. },
  70. },
  71. {
  72. path: "/components/split-pane",
  73. component: () =>
  74. import(
  75. /* webpackChunkName: "components" */ "../views/components/split-pane/index.vue"
  76. ),
  77. meta: {
  78. title: "message.hssplitPane",
  79. showLink: false,
  80. savedPosition: true,
  81. },
  82. },
  83. {
  84. path: "/components/button",
  85. component: () =>
  86. import(
  87. /* webpackChunkName: "components" */ "../views/components/button/index.vue"
  88. ),
  89. meta: {
  90. title: "message.hsbutton",
  91. showLink: false,
  92. savedPosition: true,
  93. },
  94. },
  95. {
  96. path: "/components/cropping",
  97. component: () =>
  98. import(
  99. /* webpackChunkName: "components" */ "../views/components/cropping/index.vue"
  100. ),
  101. meta: {
  102. title: "message.hscropping",
  103. showLink: false,
  104. savedPosition: true,
  105. },
  106. },
  107. {
  108. path: "/components/countTo",
  109. component: () =>
  110. import(
  111. /* webpackChunkName: "components" */ "../views/components/count-to/index.vue"
  112. ),
  113. meta: {
  114. title: "message.hscountTo",
  115. showLink: false,
  116. savedPosition: true,
  117. },
  118. },
  119. {
  120. path: "/components/selector",
  121. component: () =>
  122. import(
  123. /* webpackChunkName: "components" */ "../views/components/selector/index.vue"
  124. ),
  125. meta: {
  126. title: "message.hsselector",
  127. showLink: false,
  128. savedPosition: true,
  129. },
  130. },
  131. {
  132. path: "/components/seamlessScroll",
  133. component: () =>
  134. import(
  135. /* webpackChunkName: "components" */ "../views/components/seamless-scroll/index.vue"
  136. ),
  137. meta: {
  138. title: "message.hsseamless",
  139. showLink: false,
  140. savedPosition: true,
  141. },
  142. },
  143. // {
  144. // path: '/components/flowChart',
  145. // component: () => import(/* webpackChunkName: "components" */ '../views/components/flow-chart/index.vue'),
  146. // meta: {
  147. // title: 'message.hsflowChart',
  148. // showLink: false,
  149. // savedPosition: true
  150. // }
  151. // }
  152. ],
  153. meta: {
  154. icon: "el-icon-menu",
  155. title: "message.hscomponents",
  156. showLink: true,
  157. savedPosition: true,
  158. },
  159. },
  160. {
  161. path: "/flowChart",
  162. name: "flowChart",
  163. component: Layout,
  164. redirect: "/flowChart/index",
  165. children: [
  166. {
  167. path: "/flowChart/index",
  168. component: () =>
  169. import(
  170. /* webpackChunkName: "user" */ "../views/flow-chart/index.vue"
  171. ),
  172. meta: {
  173. title: "message.hsflowChart",
  174. showLink: false,
  175. savedPosition: true,
  176. },
  177. },
  178. ],
  179. meta: {
  180. icon: "el-icon-set-up",
  181. title: "message.hsflowChart",
  182. showLink: true,
  183. savedPosition: true,
  184. },
  185. },
  186. {
  187. path: "/editor",
  188. name: "editor",
  189. component: Layout,
  190. redirect: "/editor/index",
  191. children: [
  192. {
  193. path: "/editor/index",
  194. component: () =>
  195. import(/* webpackChunkName: "user" */ "../views/editor/index.vue"),
  196. meta: {
  197. // icon: 'el-icon-edit-outline',
  198. title: "message.hseditor",
  199. showLink: false,
  200. savedPosition: true,
  201. },
  202. },
  203. ],
  204. meta: {
  205. icon: "el-icon-edit-outline",
  206. title: "message.hseditor",
  207. showLink: true,
  208. savedPosition: true,
  209. },
  210. },
  211. {
  212. path: "/system",
  213. name: "system",
  214. component: Layout,
  215. redirect: "/system/base",
  216. children: [
  217. {
  218. path: "/system/base",
  219. component: () =>
  220. import(/* webpackChunkName: "system" */ "../views/system/user.vue"),
  221. meta: {
  222. // icon: '',
  223. title: "message.hsBaseinfo",
  224. showLink: false,
  225. savedPosition: true,
  226. },
  227. },
  228. {
  229. path: "/system/dict",
  230. component: () =>
  231. import(/* webpackChunkName: "system" */ "../views/system/dict.vue"),
  232. meta: {
  233. // icon: '',
  234. title: "message.hsDict",
  235. showLink: false,
  236. savedPosition: true,
  237. },
  238. },
  239. ],
  240. meta: {
  241. icon: "el-icon-setting",
  242. title: "message.hssysManagement",
  243. showLink: true,
  244. savedPosition: true,
  245. },
  246. },
  247. {
  248. path: "/error",
  249. name: "error",
  250. component: Layout,
  251. redirect: "/error/401",
  252. children: [
  253. {
  254. path: "/error/401",
  255. component: () =>
  256. import(/* webpackChunkName: "error" */ "../views/error/401.vue"),
  257. meta: {
  258. title: "message.hsfourZeroOne",
  259. showLink: false,
  260. savedPosition: true,
  261. },
  262. },
  263. {
  264. path: "/error/404",
  265. component: () =>
  266. import(/* webpackChunkName: "error" */ "../views/error/404.vue"),
  267. meta: {
  268. title: "message.hsfourZeroFour",
  269. showLink: false,
  270. savedPosition: true,
  271. },
  272. },
  273. ],
  274. meta: {
  275. icon: "el-icon-position",
  276. title: "message.hserror",
  277. showLink: true,
  278. savedPosition: true,
  279. },
  280. },
  281. {
  282. path: "/login",
  283. name: "login",
  284. component: () =>
  285. import(/* webpackChunkName: "login" */ "../views/login.vue"),
  286. meta: {
  287. title: "message.hslogin",
  288. showLink: false,
  289. },
  290. },
  291. {
  292. path: "/register",
  293. name: "register",
  294. component: () =>
  295. import(/* webpackChunkName: "register" */ "../views/register.vue"),
  296. meta: {
  297. title: "message.hsregister",
  298. showLink: false,
  299. },
  300. },
  301. {
  302. // 找不到路由重定向到404页面
  303. path: "/:pathMatch(.*)",
  304. component: Layout,
  305. redirect: "/error/404",
  306. meta: {
  307. icon: "el-icon-s-home",
  308. title: "message.hshome",
  309. showLink: false,
  310. savedPosition: false,
  311. },
  312. },
  313. {
  314. path: "/redirect",
  315. component: Layout,
  316. children: [
  317. {
  318. path: "/redirect/:path(.*)",
  319. component: () => import("../views/redirect.vue"),
  320. },
  321. ],
  322. },
  323. ];
  324. const router = createRouter({
  325. history: createWebHashHistory(),
  326. routes,
  327. scrollBehavior(to, from, savedPosition) {
  328. return new Promise((resolve, reject) => {
  329. if (savedPosition) {
  330. return savedPosition;
  331. } else {
  332. if (from.meta.saveSrollTop) {
  333. const top: number =
  334. document.documentElement.scrollTop || document.body.scrollTop;
  335. resolve({ left: 0, top });
  336. }
  337. }
  338. });
  339. },
  340. });
  341. import NProgress from "../utils/progress";
  342. const whiteList = ["/login", "/register"];
  343. router.beforeEach((to, _from, next) => {
  344. NProgress.start();
  345. // @ts-ignore
  346. // document.title = $t(to.meta.title); // 动态title
  347. whiteList.indexOf(to.path) !== -1 || storageSession.getItem("info")
  348. ? next()
  349. : next("/login"); // 全部重定向到登录页
  350. });
  351. router.afterEach(() => {
  352. NProgress.done();
  353. });
  354. export default router;