index.ts 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
  1. import config from '@/config/axios/config'
  2. import { MockMethod } from 'vite-plugin-mock'
  3. import Mock from 'mockjs'
  4. import { toAnyString } from '@/utils'
  5. const { code } = config
  6. const timeout = 1
  7. const adminList = [
  8. {
  9. path: '/dashboard',
  10. component: '#',
  11. redirect: '/dashboard/analysis',
  12. name: 'Dashboard',
  13. meta: {
  14. title: 'router.dashboard',
  15. icon: 'ant-design:dashboard-filled',
  16. alwaysShow: true
  17. },
  18. children: [
  19. {
  20. path: 'analysis',
  21. component: 'views/Dashboard/Analysis',
  22. name: 'Analysis',
  23. meta: {
  24. title: 'router.analysis',
  25. noCache: true
  26. }
  27. },
  28. {
  29. path: 'workplace',
  30. component: 'views/Dashboard/Workplace',
  31. name: 'Workplace',
  32. meta: {
  33. title: 'router.workplace',
  34. noCache: true
  35. }
  36. }
  37. ]
  38. },
  39. {
  40. path: '/manage',
  41. component: '#',
  42. redirect: '/manage/news-page',
  43. name: 'Manage',
  44. meta: {
  45. title: '模块管理',
  46. icon: 'ep:menu',
  47. alwaysShow: true
  48. },
  49. children: [
  50. {
  51. path: 'news-page',
  52. component: 'views/Manage/News/NewsPage',
  53. name: 'NewsPage',
  54. meta: {
  55. title: '新闻管理'
  56. }
  57. },
  58. {
  59. path: 'news-add',
  60. component: 'views/Manage/News/NewsAdd',
  61. name: 'NewsAdd',
  62. meta: {
  63. title: '新增新闻',
  64. noTagsView: true,
  65. noCache: true,
  66. hidden: true,
  67. canTo: true,
  68. activeMenu: '/manage/news-page'
  69. }
  70. },
  71. {
  72. path: 'news-edit',
  73. component: 'views/Manage/News/NewsEdit',
  74. name: 'NewsEdit',
  75. meta: {
  76. title: '编辑新闻',
  77. noTagsView: true,
  78. noCache: true,
  79. hidden: true,
  80. canTo: true,
  81. activeMenu: '/manage/news-page'
  82. }
  83. },
  84. {
  85. path: 'news-detail',
  86. component: 'views/Manage/News/NewsDetail',
  87. name: 'NewsDetail',
  88. meta: {
  89. title: '新闻详情',
  90. noTagsView: true,
  91. noCache: true,
  92. hidden: true,
  93. canTo: true,
  94. activeMenu: '/manage/news-page'
  95. }
  96. },
  97. {
  98. path: 'product-page',
  99. component: 'views/Manage/Product/ProductPage',
  100. name: 'ProductPage',
  101. meta: {
  102. title: '产品管理'
  103. }
  104. },
  105. {
  106. path: 'product-add',
  107. component: 'views/Manage/Product/ProductAdd',
  108. name: 'ProductAdd',
  109. meta: {
  110. title: '新增产品',
  111. noTagsView: true,
  112. noCache: true,
  113. hidden: true,
  114. canTo: true,
  115. activeMenu: '/manage/product-page'
  116. }
  117. },
  118. {
  119. path: 'product-edit',
  120. component: 'views/Manage/Product/ProductEdit',
  121. name: 'ProductEdit',
  122. meta: {
  123. title: '编辑产品',
  124. noTagsView: true,
  125. noCache: true,
  126. hidden: true,
  127. canTo: true,
  128. activeMenu: '/manage/product-page'
  129. }
  130. },
  131. {
  132. path: 'product-detail',
  133. component: 'views/Manage/Product/ProductDetail',
  134. name: 'ProductDetail',
  135. meta: {
  136. title: '产品详情',
  137. noTagsView: true,
  138. noCache: true,
  139. hidden: true,
  140. canTo: true,
  141. activeMenu: '/manage/product-page'
  142. }
  143. }
  144. ]
  145. },
  146. {
  147. path: '/example',
  148. component: '#',
  149. redirect: '/example/example-page',
  150. name: 'Example',
  151. meta: {
  152. title: 'router.example',
  153. icon: 'ep:management',
  154. alwaysShow: true
  155. },
  156. children: [
  157. {
  158. path: 'example-page',
  159. component: 'views/Example/Page/ExamplePage',
  160. name: 'ExamplePage',
  161. meta: {
  162. title: 'router.examplePage'
  163. }
  164. },
  165. {
  166. path: 'example-add',
  167. component: 'views/Example/Page/ExampleAdd',
  168. name: 'ExampleAdd',
  169. meta: {
  170. title: 'router.exampleAdd',
  171. noTagsView: true,
  172. noCache: true,
  173. hidden: true,
  174. canTo: true,
  175. activeMenu: '/example/example-page'
  176. }
  177. },
  178. {
  179. path: 'example-edit',
  180. component: 'views/Example/Page/ExampleEdit',
  181. name: 'ExampleEdit',
  182. meta: {
  183. title: 'router.exampleEdit',
  184. noTagsView: true,
  185. noCache: true,
  186. hidden: true,
  187. canTo: true,
  188. activeMenu: '/example/example-page'
  189. }
  190. },
  191. {
  192. path: 'example-detail',
  193. component: 'views/Example/Page/ExampleDetail',
  194. name: 'ExampleDetail',
  195. meta: {
  196. title: 'router.exampleDetail',
  197. noTagsView: true,
  198. noCache: true,
  199. hidden: true,
  200. canTo: true,
  201. activeMenu: '/example/example-page'
  202. }
  203. }
  204. ]
  205. },
  206. {
  207. path: '/authorization',
  208. component: '#',
  209. redirect: '/authorization/user',
  210. name: 'Authorization',
  211. meta: {
  212. title: 'router.authorization',
  213. icon: 'eos-icons:role-binding',
  214. alwaysShow: true
  215. },
  216. children: [
  217. {
  218. path: 'department',
  219. component: 'views/Authorization/Department/Department',
  220. name: 'Department',
  221. meta: {
  222. title: 'router.department'
  223. }
  224. },
  225. {
  226. path: 'user',
  227. component: 'views/Authorization/User/User',
  228. name: 'User',
  229. meta: {
  230. title: 'router.user'
  231. }
  232. },
  233. {
  234. path: 'menu',
  235. component: 'views/Authorization/Menu/Menu',
  236. name: 'Menu',
  237. meta: {
  238. title: 'router.menuManagement'
  239. }
  240. },
  241. {
  242. path: 'role',
  243. component: 'views/Authorization/Role/Role',
  244. name: 'Role',
  245. meta: {
  246. title: 'router.role'
  247. }
  248. },
  249. {
  250. path: 'test',
  251. component: 'views/Authorization/Test/Test',
  252. name: 'Test',
  253. meta: {
  254. title: 'router.permission',
  255. permission: ['add', 'edit', 'delete']
  256. }
  257. }
  258. ]
  259. }
  260. ]
  261. const testList: string[] = [
  262. '/dashboard',
  263. '/dashboard/analysis',
  264. '/dashboard/workplace',
  265. 'external-link',
  266. 'https://element-plus-admin-doc.cn/',
  267. '/guide',
  268. '/guide/index',
  269. '/components',
  270. '/components/form',
  271. '/components/form/default-form',
  272. '/components/form/use-form',
  273. '/components/form/ref-form',
  274. '/components/table',
  275. '/components/table/default-table',
  276. '/components/table/use-table',
  277. '/components/table/tree-table',
  278. '/components/table/table-image-preview',
  279. '/components/table/ref-table',
  280. '/components/editor-demo',
  281. '/components/editor-demo/editor',
  282. '/components/search',
  283. '/components/descriptions',
  284. '/components/image-viewer',
  285. '/components/dialog',
  286. '/components/icon',
  287. '/components/echart',
  288. '/components/count-to',
  289. '/components/qrcode',
  290. '/components/highlight',
  291. '/components/infotip',
  292. '/Components/InputPassword',
  293. '/Components/Sticky',
  294. 'function',
  295. '/function/multiple-tabs',
  296. '/function/multiple-tabs-demo/:id',
  297. '/hooks',
  298. '/hooks/useWatermark',
  299. '/hooks/useTagsView',
  300. // '/hooks/useCrudSchemas',
  301. '/level',
  302. '/level/menu1',
  303. '/level/menu1/menu1-1',
  304. '/level/menu1/menu1-1/menu1-1-1',
  305. '/level/menu1/menu1-2',
  306. '/level/menu2',
  307. '/example',
  308. '/example/example-dialog',
  309. '/example/example-page',
  310. '/example/example-add',
  311. '/example/example-edit',
  312. '/example/example-detail',
  313. '/authorization',
  314. '/authorization/department',
  315. '/authorization/user',
  316. '/authorization/role',
  317. '/authorization/menu',
  318. '/authorization/test',
  319. '/error',
  320. '/error/404-demo',
  321. '/error/403-demo',
  322. '/error/500-demo'
  323. ]
  324. const List: any[] = []
  325. const roleNames = ['超级管理员', '管理员', '普通用户', '游客']
  326. const menus = [
  327. [
  328. {
  329. path: '/dashboard',
  330. component: '#',
  331. redirect: '/dashboard/analysis',
  332. name: 'Dashboard',
  333. status: Mock.Random.integer(0, 1),
  334. id: 1,
  335. meta: {
  336. title: '首页',
  337. icon: 'ant-design:dashboard-filled',
  338. alwaysShow: true
  339. },
  340. children: [
  341. {
  342. path: 'analysis',
  343. component: 'views/Dashboard/Analysis',
  344. name: 'Analysis',
  345. status: Mock.Random.integer(0, 1),
  346. id: 2,
  347. meta: {
  348. title: '分析页',
  349. noCache: true
  350. }
  351. },
  352. {
  353. path: 'workplace',
  354. component: 'views/Dashboard/Workplace',
  355. name: 'Workplace',
  356. status: Mock.Random.integer(0, 1),
  357. id: 3,
  358. meta: {
  359. title: '工作台',
  360. noCache: true
  361. }
  362. }
  363. ]
  364. },
  365. {
  366. path: '/external-link',
  367. component: '#',
  368. meta: {
  369. title: '文档',
  370. icon: 'clarity:document-solid'
  371. },
  372. name: 'ExternalLink',
  373. status: Mock.Random.integer(0, 1),
  374. id: 4,
  375. children: [
  376. {
  377. path: 'https://element-plus-admin-doc.cn/',
  378. name: 'DocumentLink',
  379. status: Mock.Random.integer(0, 1),
  380. id: 5,
  381. meta: {
  382. title: '文档'
  383. }
  384. }
  385. ]
  386. },
  387. {
  388. path: '/level',
  389. component: '#',
  390. redirect: '/level/menu1/menu1-1/menu1-1-1',
  391. name: 'Level',
  392. status: Mock.Random.integer(0, 1),
  393. id: 6,
  394. meta: {
  395. title: '菜单',
  396. icon: 'carbon:skill-level-advanced'
  397. },
  398. children: [
  399. {
  400. path: 'menu1',
  401. name: 'Menu1',
  402. component: '##',
  403. status: Mock.Random.integer(0, 1),
  404. id: 7,
  405. redirect: '/level/menu1/menu1-1/menu1-1-1',
  406. meta: {
  407. title: '菜单1'
  408. },
  409. children: [
  410. {
  411. path: 'menu1-1',
  412. name: 'Menu11',
  413. component: '##',
  414. status: Mock.Random.integer(0, 1),
  415. id: 8,
  416. redirect: '/level/menu1/menu1-1/menu1-1-1',
  417. meta: {
  418. title: '菜单1-1',
  419. alwaysShow: true
  420. },
  421. children: [
  422. {
  423. path: 'menu1-1-1',
  424. name: 'Menu111',
  425. component: 'views/Level/Menu111',
  426. status: Mock.Random.integer(0, 1),
  427. id: 9,
  428. permission: ['edit', 'add', 'delete'],
  429. meta: {
  430. title: '菜单1-1-1',
  431. permission: ['edit', 'add', 'delete']
  432. }
  433. }
  434. ]
  435. },
  436. {
  437. path: 'menu1-2',
  438. name: 'Menu12',
  439. component: 'views/Level/Menu12',
  440. status: Mock.Random.integer(0, 1),
  441. id: 10,
  442. permission: ['edit', 'add', 'delete'],
  443. meta: {
  444. title: '菜单1-2',
  445. permission: ['edit', 'add', 'delete']
  446. }
  447. }
  448. ]
  449. },
  450. {
  451. path: 'menu2',
  452. name: 'Menu2Demo',
  453. component: 'views/Level/Menu2',
  454. status: Mock.Random.integer(0, 1),
  455. id: 11,
  456. permission: ['edit', 'add', 'delete'],
  457. meta: {
  458. title: '菜单2',
  459. permission: ['edit', 'add', 'delete']
  460. }
  461. }
  462. ]
  463. },
  464. {
  465. path: '/example',
  466. component: '#',
  467. redirect: '/example/example-dialog',
  468. name: 'Example',
  469. status: Mock.Random.integer(0, 1),
  470. id: 12,
  471. meta: {
  472. title: '综合示例',
  473. icon: 'ep:management',
  474. alwaysShow: true
  475. },
  476. children: [
  477. {
  478. path: 'example-dialog',
  479. component: 'views/Example/Dialog/ExampleDialog',
  480. name: 'ExampleDialog',
  481. status: Mock.Random.integer(0, 1),
  482. id: 13,
  483. permission: ['edit', 'add', 'delete'],
  484. meta: {
  485. title: '综合示例-弹窗',
  486. permission: ['edit', 'add', 'delete']
  487. }
  488. },
  489. {
  490. path: 'example-page',
  491. component: 'views/Example/Page/ExamplePage',
  492. name: 'ExamplePage',
  493. status: Mock.Random.integer(0, 1),
  494. id: 14,
  495. permission: ['edit', 'add', 'delete'],
  496. meta: {
  497. title: '综合示例-页面',
  498. permission: ['edit', 'add', 'delete']
  499. }
  500. },
  501. {
  502. path: 'example-add',
  503. component: 'views/Example/Page/ExampleAdd',
  504. name: 'ExampleAdd',
  505. status: Mock.Random.integer(0, 1),
  506. id: 15,
  507. permission: ['edit', 'add', 'delete'],
  508. meta: {
  509. title: '综合示例-新增',
  510. noTagsView: true,
  511. noCache: true,
  512. hidden: true,
  513. canTo: true,
  514. activeMenu: '/example/example-page',
  515. permission: ['edit', 'add', 'delete']
  516. }
  517. },
  518. {
  519. path: 'example-edit',
  520. component: 'views/Example/Page/ExampleEdit',
  521. name: 'ExampleEdit',
  522. status: Mock.Random.integer(0, 1),
  523. id: 16,
  524. permission: ['edit', 'add', 'delete'],
  525. meta: {
  526. title: '综合示例-编辑',
  527. noTagsView: true,
  528. noCache: true,
  529. hidden: true,
  530. canTo: true,
  531. activeMenu: '/example/example-page',
  532. permission: ['edit', 'add', 'delete']
  533. }
  534. },
  535. {
  536. path: 'example-detail',
  537. component: 'views/Example/Page/ExampleDetail',
  538. name: 'ExampleDetail',
  539. status: Mock.Random.integer(0, 1),
  540. id: 17,
  541. permission: ['edit', 'add', 'delete'],
  542. meta: {
  543. title: '综合示例-详情',
  544. noTagsView: true,
  545. noCache: true,
  546. hidden: true,
  547. canTo: true,
  548. activeMenu: '/example/example-page',
  549. permission: ['edit', 'add', 'delete']
  550. }
  551. }
  552. ]
  553. }
  554. ],
  555. [
  556. {
  557. path: '/dashboard',
  558. component: '#',
  559. redirect: '/dashboard/analysis',
  560. name: 'Dashboard',
  561. status: Mock.Random.integer(0, 1),
  562. id: 1,
  563. meta: {
  564. title: '首页',
  565. icon: 'ant-design:dashboard-filled',
  566. alwaysShow: true
  567. },
  568. children: [
  569. {
  570. path: 'analysis',
  571. component: 'views/Dashboard/Analysis',
  572. name: 'Analysis',
  573. status: Mock.Random.integer(0, 1),
  574. id: 2,
  575. meta: {
  576. title: '分析页',
  577. noCache: true
  578. }
  579. },
  580. {
  581. path: 'workplace',
  582. component: 'views/Dashboard/Workplace',
  583. name: 'Workplace',
  584. status: Mock.Random.integer(0, 1),
  585. id: 3,
  586. meta: {
  587. title: '工作台',
  588. noCache: true
  589. }
  590. }
  591. ]
  592. }
  593. ],
  594. [
  595. {
  596. path: '/external-link',
  597. component: '#',
  598. meta: {
  599. title: '文档',
  600. icon: 'clarity:document-solid'
  601. },
  602. name: 'ExternalLink',
  603. status: Mock.Random.integer(0, 1),
  604. id: 4,
  605. children: [
  606. {
  607. path: 'https://element-plus-admin-doc.cn/',
  608. name: 'DocumentLink',
  609. status: Mock.Random.integer(0, 1),
  610. id: 5,
  611. meta: {
  612. title: '文档'
  613. }
  614. }
  615. ]
  616. },
  617. {
  618. path: '/level',
  619. component: '#',
  620. redirect: '/level/menu1/menu1-1/menu1-1-1',
  621. name: 'Level',
  622. status: Mock.Random.integer(0, 1),
  623. id: 6,
  624. meta: {
  625. title: '菜单',
  626. icon: 'carbon:skill-level-advanced'
  627. },
  628. children: [
  629. {
  630. path: 'menu1',
  631. name: 'Menu1',
  632. component: '##',
  633. status: Mock.Random.integer(0, 1),
  634. id: 7,
  635. redirect: '/level/menu1/menu1-1/menu1-1-1',
  636. meta: {
  637. title: '菜单1'
  638. },
  639. children: [
  640. {
  641. path: 'menu1-1',
  642. name: 'Menu11',
  643. component: '##',
  644. status: Mock.Random.integer(0, 1),
  645. id: 8,
  646. redirect: '/level/menu1/menu1-1/menu1-1-1',
  647. meta: {
  648. title: '菜单1-1',
  649. alwaysShow: true
  650. },
  651. children: [
  652. {
  653. path: 'menu1-1-1',
  654. name: 'Menu111',
  655. component: 'views/Level/Menu111',
  656. status: Mock.Random.integer(0, 1),
  657. id: 9,
  658. permission: ['edit', 'add', 'delete'],
  659. meta: {
  660. title: '菜单1-1-1',
  661. permission: ['edit', 'add', 'delete']
  662. }
  663. }
  664. ]
  665. },
  666. {
  667. path: 'menu1-2',
  668. name: 'Menu12',
  669. component: 'views/Level/Menu12',
  670. status: Mock.Random.integer(0, 1),
  671. id: 10,
  672. permission: ['edit', 'add', 'delete'],
  673. meta: {
  674. title: '菜单1-2',
  675. permission: ['edit', 'add', 'delete']
  676. }
  677. }
  678. ]
  679. },
  680. {
  681. path: 'menu2',
  682. name: 'Menu2Demo',
  683. component: 'views/Level/Menu2',
  684. status: Mock.Random.integer(0, 1),
  685. id: 11,
  686. permission: ['edit', 'add', 'delete'],
  687. meta: {
  688. title: '菜单2',
  689. permission: ['edit', 'add', 'delete']
  690. }
  691. }
  692. ]
  693. }
  694. ],
  695. [
  696. {
  697. path: '/example',
  698. component: '#',
  699. redirect: '/example/example-dialog',
  700. name: 'Example',
  701. status: Mock.Random.integer(0, 1),
  702. id: 12,
  703. meta: {
  704. title: '综合示例',
  705. icon: 'ep:management',
  706. alwaysShow: true
  707. },
  708. children: [
  709. {
  710. path: 'example-detail',
  711. component: 'views/Example/Page/ExampleDetail',
  712. name: 'ExampleDetail',
  713. status: Mock.Random.integer(0, 1),
  714. id: 17,
  715. permission: ['edit', 'add', 'delete'],
  716. meta: {
  717. title: '综合示例-详情',
  718. noTagsView: true,
  719. noCache: true,
  720. hidden: true,
  721. canTo: true,
  722. activeMenu: '/example/example-page',
  723. permission: ['edit', 'add', 'delete']
  724. }
  725. }
  726. ]
  727. }
  728. ]
  729. ]
  730. for (let i = 0; i < 4; i++) {
  731. List.push(
  732. Mock.mock({
  733. id: toAnyString(),
  734. // timestamp: +Mock.Random.date('T'),
  735. roleName: roleNames[i],
  736. role: '@first',
  737. status: Mock.Random.integer(0, 1),
  738. createTime: '@datetime',
  739. remark: '@cword(10, 15)',
  740. menu: menus[i]
  741. })
  742. )
  743. }
  744. export default [
  745. // 列表接口
  746. {
  747. url: '/role/list',
  748. method: 'get',
  749. timeout,
  750. response: ({ query }) => {
  751. const { roleName } = query
  752. return {
  753. data: {
  754. code: code,
  755. data: roleName === 'admin' ? adminList : testList
  756. }
  757. }
  758. }
  759. },
  760. {
  761. url: '/role/table',
  762. method: 'get',
  763. timeout,
  764. response: () => {
  765. return {
  766. data: {
  767. code: code,
  768. data: {
  769. list: List,
  770. total: 4
  771. }
  772. }
  773. }
  774. }
  775. }
  776. ] as MockMethod[]