index.ts 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  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. '/hooks',
  295. '/hooks/useWatermark',
  296. '/hooks/useOpenTab',
  297. // '/hooks/useCrudSchemas',
  298. '/level',
  299. '/level/menu1',
  300. '/level/menu1/menu1-1',
  301. '/level/menu1/menu1-1/menu1-1-1',
  302. '/level/menu1/menu1-2',
  303. '/level/menu2',
  304. '/example',
  305. '/example/example-dialog',
  306. '/example/example-page',
  307. '/example/example-add',
  308. '/example/example-edit',
  309. '/example/example-detail',
  310. '/authorization',
  311. '/authorization/department',
  312. '/authorization/user',
  313. '/authorization/role',
  314. '/authorization/menu',
  315. '/authorization/test',
  316. '/error',
  317. '/error/404-demo',
  318. '/error/403-demo',
  319. '/error/500-demo'
  320. ]
  321. const List: any[] = []
  322. const roleNames = ['超级管理员', '管理员', '普通用户', '游客']
  323. const menus = [
  324. [
  325. {
  326. path: '/dashboard',
  327. component: '#',
  328. redirect: '/dashboard/analysis',
  329. name: 'Dashboard',
  330. status: Mock.Random.integer(0, 1),
  331. id: 1,
  332. meta: {
  333. title: '首页',
  334. icon: 'ant-design:dashboard-filled',
  335. alwaysShow: true
  336. },
  337. children: [
  338. {
  339. path: 'analysis',
  340. component: 'views/Dashboard/Analysis',
  341. name: 'Analysis',
  342. status: Mock.Random.integer(0, 1),
  343. id: 2,
  344. meta: {
  345. title: '分析页',
  346. noCache: true
  347. }
  348. },
  349. {
  350. path: 'workplace',
  351. component: 'views/Dashboard/Workplace',
  352. name: 'Workplace',
  353. status: Mock.Random.integer(0, 1),
  354. id: 3,
  355. meta: {
  356. title: '工作台',
  357. noCache: true
  358. }
  359. }
  360. ]
  361. },
  362. {
  363. path: '/external-link',
  364. component: '#',
  365. meta: {
  366. title: '文档',
  367. icon: 'clarity:document-solid'
  368. },
  369. name: 'ExternalLink',
  370. status: Mock.Random.integer(0, 1),
  371. id: 4,
  372. children: [
  373. {
  374. path: 'https://element-plus-admin-doc.cn/',
  375. name: 'DocumentLink',
  376. status: Mock.Random.integer(0, 1),
  377. id: 5,
  378. meta: {
  379. title: '文档'
  380. }
  381. }
  382. ]
  383. },
  384. {
  385. path: '/level',
  386. component: '#',
  387. redirect: '/level/menu1/menu1-1/menu1-1-1',
  388. name: 'Level',
  389. status: Mock.Random.integer(0, 1),
  390. id: 6,
  391. meta: {
  392. title: '菜单',
  393. icon: 'carbon:skill-level-advanced'
  394. },
  395. children: [
  396. {
  397. path: 'menu1',
  398. name: 'Menu1',
  399. component: '##',
  400. status: Mock.Random.integer(0, 1),
  401. id: 7,
  402. redirect: '/level/menu1/menu1-1/menu1-1-1',
  403. meta: {
  404. title: '菜单1'
  405. },
  406. children: [
  407. {
  408. path: 'menu1-1',
  409. name: 'Menu11',
  410. component: '##',
  411. status: Mock.Random.integer(0, 1),
  412. id: 8,
  413. redirect: '/level/menu1/menu1-1/menu1-1-1',
  414. meta: {
  415. title: '菜单1-1',
  416. alwaysShow: true
  417. },
  418. children: [
  419. {
  420. path: 'menu1-1-1',
  421. name: 'Menu111',
  422. component: 'views/Level/Menu111',
  423. status: Mock.Random.integer(0, 1),
  424. id: 9,
  425. permission: ['edit', 'add', 'delete'],
  426. meta: {
  427. title: '菜单1-1-1',
  428. permission: ['edit', 'add', 'delete']
  429. }
  430. }
  431. ]
  432. },
  433. {
  434. path: 'menu1-2',
  435. name: 'Menu12',
  436. component: 'views/Level/Menu12',
  437. status: Mock.Random.integer(0, 1),
  438. id: 10,
  439. permission: ['edit', 'add', 'delete'],
  440. meta: {
  441. title: '菜单1-2',
  442. permission: ['edit', 'add', 'delete']
  443. }
  444. }
  445. ]
  446. },
  447. {
  448. path: 'menu2',
  449. name: 'Menu2Demo',
  450. component: 'views/Level/Menu2',
  451. status: Mock.Random.integer(0, 1),
  452. id: 11,
  453. permission: ['edit', 'add', 'delete'],
  454. meta: {
  455. title: '菜单2',
  456. permission: ['edit', 'add', 'delete']
  457. }
  458. }
  459. ]
  460. },
  461. {
  462. path: '/example',
  463. component: '#',
  464. redirect: '/example/example-dialog',
  465. name: 'Example',
  466. status: Mock.Random.integer(0, 1),
  467. id: 12,
  468. meta: {
  469. title: '综合示例',
  470. icon: 'ep:management',
  471. alwaysShow: true
  472. },
  473. children: [
  474. {
  475. path: 'example-dialog',
  476. component: 'views/Example/Dialog/ExampleDialog',
  477. name: 'ExampleDialog',
  478. status: Mock.Random.integer(0, 1),
  479. id: 13,
  480. permission: ['edit', 'add', 'delete'],
  481. meta: {
  482. title: '综合示例-弹窗',
  483. permission: ['edit', 'add', 'delete']
  484. }
  485. },
  486. {
  487. path: 'example-page',
  488. component: 'views/Example/Page/ExamplePage',
  489. name: 'ExamplePage',
  490. status: Mock.Random.integer(0, 1),
  491. id: 14,
  492. permission: ['edit', 'add', 'delete'],
  493. meta: {
  494. title: '综合示例-页面',
  495. permission: ['edit', 'add', 'delete']
  496. }
  497. },
  498. {
  499. path: 'example-add',
  500. component: 'views/Example/Page/ExampleAdd',
  501. name: 'ExampleAdd',
  502. status: Mock.Random.integer(0, 1),
  503. id: 15,
  504. permission: ['edit', 'add', 'delete'],
  505. meta: {
  506. title: '综合示例-新增',
  507. noTagsView: true,
  508. noCache: true,
  509. hidden: true,
  510. canTo: true,
  511. activeMenu: '/example/example-page',
  512. permission: ['edit', 'add', 'delete']
  513. }
  514. },
  515. {
  516. path: 'example-edit',
  517. component: 'views/Example/Page/ExampleEdit',
  518. name: 'ExampleEdit',
  519. status: Mock.Random.integer(0, 1),
  520. id: 16,
  521. permission: ['edit', 'add', 'delete'],
  522. meta: {
  523. title: '综合示例-编辑',
  524. noTagsView: true,
  525. noCache: true,
  526. hidden: true,
  527. canTo: true,
  528. activeMenu: '/example/example-page',
  529. permission: ['edit', 'add', 'delete']
  530. }
  531. },
  532. {
  533. path: 'example-detail',
  534. component: 'views/Example/Page/ExampleDetail',
  535. name: 'ExampleDetail',
  536. status: Mock.Random.integer(0, 1),
  537. id: 17,
  538. permission: ['edit', 'add', 'delete'],
  539. meta: {
  540. title: '综合示例-详情',
  541. noTagsView: true,
  542. noCache: true,
  543. hidden: true,
  544. canTo: true,
  545. activeMenu: '/example/example-page',
  546. permission: ['edit', 'add', 'delete']
  547. }
  548. }
  549. ]
  550. }
  551. ],
  552. [
  553. {
  554. path: '/dashboard',
  555. component: '#',
  556. redirect: '/dashboard/analysis',
  557. name: 'Dashboard',
  558. status: Mock.Random.integer(0, 1),
  559. id: 1,
  560. meta: {
  561. title: '首页',
  562. icon: 'ant-design:dashboard-filled',
  563. alwaysShow: true
  564. },
  565. children: [
  566. {
  567. path: 'analysis',
  568. component: 'views/Dashboard/Analysis',
  569. name: 'Analysis',
  570. status: Mock.Random.integer(0, 1),
  571. id: 2,
  572. meta: {
  573. title: '分析页',
  574. noCache: true
  575. }
  576. },
  577. {
  578. path: 'workplace',
  579. component: 'views/Dashboard/Workplace',
  580. name: 'Workplace',
  581. status: Mock.Random.integer(0, 1),
  582. id: 3,
  583. meta: {
  584. title: '工作台',
  585. noCache: true
  586. }
  587. }
  588. ]
  589. }
  590. ],
  591. [
  592. {
  593. path: '/external-link',
  594. component: '#',
  595. meta: {
  596. title: '文档',
  597. icon: 'clarity:document-solid'
  598. },
  599. name: 'ExternalLink',
  600. status: Mock.Random.integer(0, 1),
  601. id: 4,
  602. children: [
  603. {
  604. path: 'https://element-plus-admin-doc.cn/',
  605. name: 'DocumentLink',
  606. status: Mock.Random.integer(0, 1),
  607. id: 5,
  608. meta: {
  609. title: '文档'
  610. }
  611. }
  612. ]
  613. },
  614. {
  615. path: '/level',
  616. component: '#',
  617. redirect: '/level/menu1/menu1-1/menu1-1-1',
  618. name: 'Level',
  619. status: Mock.Random.integer(0, 1),
  620. id: 6,
  621. meta: {
  622. title: '菜单',
  623. icon: 'carbon:skill-level-advanced'
  624. },
  625. children: [
  626. {
  627. path: 'menu1',
  628. name: 'Menu1',
  629. component: '##',
  630. status: Mock.Random.integer(0, 1),
  631. id: 7,
  632. redirect: '/level/menu1/menu1-1/menu1-1-1',
  633. meta: {
  634. title: '菜单1'
  635. },
  636. children: [
  637. {
  638. path: 'menu1-1',
  639. name: 'Menu11',
  640. component: '##',
  641. status: Mock.Random.integer(0, 1),
  642. id: 8,
  643. redirect: '/level/menu1/menu1-1/menu1-1-1',
  644. meta: {
  645. title: '菜单1-1',
  646. alwaysShow: true
  647. },
  648. children: [
  649. {
  650. path: 'menu1-1-1',
  651. name: 'Menu111',
  652. component: 'views/Level/Menu111',
  653. status: Mock.Random.integer(0, 1),
  654. id: 9,
  655. permission: ['edit', 'add', 'delete'],
  656. meta: {
  657. title: '菜单1-1-1',
  658. permission: ['edit', 'add', 'delete']
  659. }
  660. }
  661. ]
  662. },
  663. {
  664. path: 'menu1-2',
  665. name: 'Menu12',
  666. component: 'views/Level/Menu12',
  667. status: Mock.Random.integer(0, 1),
  668. id: 10,
  669. permission: ['edit', 'add', 'delete'],
  670. meta: {
  671. title: '菜单1-2',
  672. permission: ['edit', 'add', 'delete']
  673. }
  674. }
  675. ]
  676. },
  677. {
  678. path: 'menu2',
  679. name: 'Menu2Demo',
  680. component: 'views/Level/Menu2',
  681. status: Mock.Random.integer(0, 1),
  682. id: 11,
  683. permission: ['edit', 'add', 'delete'],
  684. meta: {
  685. title: '菜单2',
  686. permission: ['edit', 'add', 'delete']
  687. }
  688. }
  689. ]
  690. }
  691. ],
  692. [
  693. {
  694. path: '/example',
  695. component: '#',
  696. redirect: '/example/example-dialog',
  697. name: 'Example',
  698. status: Mock.Random.integer(0, 1),
  699. id: 12,
  700. meta: {
  701. title: '综合示例',
  702. icon: 'ep:management',
  703. alwaysShow: true
  704. },
  705. children: [
  706. {
  707. path: 'example-detail',
  708. component: 'views/Example/Page/ExampleDetail',
  709. name: 'ExampleDetail',
  710. status: Mock.Random.integer(0, 1),
  711. id: 17,
  712. permission: ['edit', 'add', 'delete'],
  713. meta: {
  714. title: '综合示例-详情',
  715. noTagsView: true,
  716. noCache: true,
  717. hidden: true,
  718. canTo: true,
  719. activeMenu: '/example/example-page',
  720. permission: ['edit', 'add', 'delete']
  721. }
  722. }
  723. ]
  724. }
  725. ]
  726. ]
  727. for (let i = 0; i < 4; i++) {
  728. List.push(
  729. Mock.mock({
  730. id: toAnyString(),
  731. // timestamp: +Mock.Random.date('T'),
  732. roleName: roleNames[i],
  733. role: '@first',
  734. status: Mock.Random.integer(0, 1),
  735. createTime: '@datetime',
  736. remark: '@cword(10, 15)',
  737. menu: menus[i]
  738. })
  739. )
  740. }
  741. export default [
  742. // 列表接口
  743. {
  744. url: '/role/list',
  745. method: 'get',
  746. timeout,
  747. response: ({ query }) => {
  748. const { roleName } = query
  749. return {
  750. data: {
  751. code: code,
  752. data: roleName === 'admin' ? adminList : testList
  753. }
  754. }
  755. }
  756. },
  757. {
  758. url: '/role/table',
  759. method: 'get',
  760. timeout,
  761. response: () => {
  762. return {
  763. data: {
  764. code: code,
  765. data: {
  766. list: List,
  767. total: 4
  768. }
  769. }
  770. }
  771. }
  772. }
  773. ] as MockMethod[]