动态菜单和动态路由的 antd pro

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. import mockjs from 'mockjs';
  2. import { getRule, postRule } from './mock/rule';
  3. import { getActivities, getNotice, getFakeList } from './mock/api';
  4. import { getFakeChartData } from './mock/chart';
  5. import { getProfileBasicData } from './mock/profile';
  6. import { getProfileAdvancedData } from './mock/profile';
  7. import { getNotices } from './mock/notices';
  8. import { format, delay } from 'roadhog-api-doc';
  9. // 是否禁用代理
  10. const noProxy = process.env.NO_PROXY === 'true';
  11. // 代码中会兼容本地 service mock 以及部署站点的静态数据
  12. const proxy = {
  13. // 支持值为 Object 和 Array
  14. 'GET /api/currentUser': {
  15. $desc: '获取当前用户接口',
  16. $params: {
  17. pageSize: {
  18. desc: '分页',
  19. exp: 2,
  20. },
  21. },
  22. $body: {
  23. name: 'Serati Ma',
  24. avatar: 'https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png',
  25. userid: '00000001',
  26. notifyCount: 12,
  27. },
  28. },
  29. // GET POST 可省略
  30. 'GET /api/users': [
  31. {
  32. key: '1',
  33. name: 'John Brown',
  34. age: 32,
  35. address: 'New York No. 1 Lake Park',
  36. },
  37. {
  38. key: '2',
  39. name: 'Jim Green',
  40. age: 42,
  41. address: 'London No. 1 Lake Park',
  42. },
  43. {
  44. key: '3',
  45. name: 'Joe Black',
  46. age: 32,
  47. address: 'Sidney No. 1 Lake Park',
  48. },
  49. ],
  50. 'GET /api/project/notice': getNotice,
  51. 'GET /api/activities': getActivities,
  52. 'GET /api/rule': getRule,
  53. 'POST /api/rule': {
  54. $params: {
  55. pageSize: {
  56. desc: '分页',
  57. exp: 2,
  58. },
  59. },
  60. $body: postRule,
  61. },
  62. 'POST /api/forms': (req, res) => {
  63. res.send({ message: 'Ok' });
  64. },
  65. 'GET /api/tags': mockjs.mock({
  66. 'list|100': [{ name: '@city', 'value|1-100': 150, 'type|0-2': 1 }],
  67. }),
  68. 'GET /api/fake_list': getFakeList,
  69. 'GET /api/fake_chart_data': getFakeChartData,
  70. 'GET /api/profile/basic': getProfileBasicData,
  71. 'GET /api/profile/advanced': getProfileAdvancedData,
  72. 'POST /api/login/account': (req, res) => {
  73. const { password, userName, type } = req.body;
  74. if (password === '888888' && userName === 'admin') {
  75. res.send({
  76. status: 'ok',
  77. type,
  78. currentAuthority: 'admin',
  79. });
  80. return;
  81. }
  82. if (password === '123456' && userName === 'user') {
  83. res.send({
  84. status: 'ok',
  85. type,
  86. currentAuthority: 'user',
  87. });
  88. return;
  89. }
  90. res.send({
  91. status: 'error',
  92. type,
  93. currentAuthority: 'guest',
  94. });
  95. },
  96. 'POST /api/register': (req, res) => {
  97. res.send({ status: 'ok', currentAuthority: 'user' });
  98. },
  99. 'GET /api/notices': getNotices,
  100. 'GET /api/500': (req, res) => {
  101. res.status(500).send({
  102. timestamp: 1513932555104,
  103. status: 500,
  104. error: 'error',
  105. message: 'error',
  106. path: '/base/category/list',
  107. });
  108. },
  109. 'GET /api/404': (req, res) => {
  110. res.status(404).send({
  111. timestamp: 1513932643431,
  112. status: 404,
  113. error: 'Not Found',
  114. message: 'No message available',
  115. path: '/base/category/list/2121212',
  116. });
  117. },
  118. 'GET /api/403': (req, res) => {
  119. res.status(403).send({
  120. timestamp: 1513932555104,
  121. status: 403,
  122. error: 'Unauthorized',
  123. message: 'Unauthorized',
  124. path: '/base/category/list',
  125. });
  126. },
  127. 'GET /api/401': (req, res) => {
  128. res.status(401).send({
  129. timestamp: 1513932555104,
  130. status: 401,
  131. error: 'Unauthorized',
  132. message: 'Unauthorized',
  133. path: '/base/category/list',
  134. });
  135. },
  136. 'GET /api/menus': [
  137. {
  138. name: 'dashboard',
  139. icon: 'dashboard',
  140. path: 'dashboard',
  141. children: [
  142. {
  143. name: '分析页',
  144. path: 'analysis',
  145. },
  146. {
  147. name: '监控页',
  148. path: 'monitor',
  149. },
  150. {
  151. name: '工作台',
  152. path: 'workplace',
  153. // hideInBreadcrumb: true,
  154. // hideInMenu: true,
  155. },
  156. ],
  157. },
  158. {
  159. name: '表单页',
  160. icon: 'form',
  161. path: 'form',
  162. children: [
  163. {
  164. name: '基础表单',
  165. path: 'basic-form',
  166. },
  167. {
  168. name: '分步表单',
  169. path: 'step-form',
  170. },
  171. {
  172. name: '高级表单',
  173. authority: 'admin',
  174. path: 'advanced-form',
  175. },
  176. ],
  177. },
  178. {
  179. name: '列表页',
  180. icon: 'table',
  181. path: 'list',
  182. children: [
  183. {
  184. name: '查询表格',
  185. path: 'table-list',
  186. },
  187. {
  188. name: '标准列表',
  189. path: 'basic-list',
  190. },
  191. {
  192. name: '卡片列表',
  193. path: 'card-list',
  194. },
  195. {
  196. name: '搜索列表',
  197. path: 'search',
  198. children: [
  199. {
  200. name: '搜索列表(文章)',
  201. path: 'articles',
  202. },
  203. {
  204. name: '搜索列表(项目)',
  205. path: 'projects',
  206. },
  207. {
  208. name: '搜索列表(应用)',
  209. path: 'applications',
  210. },
  211. ],
  212. },
  213. ],
  214. },
  215. {
  216. name: '详情页',
  217. icon: 'profile',
  218. path: 'profile',
  219. children: [
  220. {
  221. name: '基础详情页',
  222. path: 'basic',
  223. },
  224. {
  225. name: '高级详情页',
  226. path: 'advanced',
  227. authority: 'admin',
  228. },
  229. ],
  230. },
  231. {
  232. name: '结果页',
  233. icon: 'check-circle-o',
  234. path: 'result',
  235. children: [
  236. {
  237. name: '成功',
  238. path: 'success',
  239. },
  240. {
  241. name: '失败',
  242. path: 'fail',
  243. },
  244. ],
  245. },
  246. {
  247. name: '异常页',
  248. icon: 'warning',
  249. path: 'exception',
  250. children: [
  251. {
  252. name: '403',
  253. path: '403',
  254. },
  255. {
  256. name: '404',
  257. path: '404',
  258. },
  259. {
  260. name: '500',
  261. path: '500',
  262. },
  263. {
  264. name: '触发异常',
  265. path: 'trigger',
  266. hideInMenu: true,
  267. },
  268. ],
  269. },
  270. {
  271. name: '账户',
  272. icon: 'user',
  273. path: 'user',
  274. authority: 'guest',
  275. children: [
  276. {
  277. name: '登录',
  278. path: 'login',
  279. },
  280. {
  281. name: '注册',
  282. path: 'register',
  283. },
  284. {
  285. name: '注册结果',
  286. path: 'register-result',
  287. },
  288. ],
  289. },
  290. {
  291. name: 'iframe',
  292. icon: 'desktop',
  293. path: 'iframe',
  294. children: [
  295. {
  296. name: 'Note',
  297. path: 'note', // https://team.links123.com/Note
  298. },
  299. {
  300. name: 'Project',
  301. path: 'project', // https://team.links123.com/Note
  302. },
  303. {
  304. name: 'Member',
  305. path: 'member', // https://team.links123.com/Member
  306. },
  307. ],
  308. },
  309. ],
  310. };
  311. export default (noProxy ? {} : delay(proxy, 1000));