index.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197
  1. 'use strict';
  2. var _extends =
  3. Object.assign ||
  4. function(target) {
  5. for (var i = 1; i < arguments.length; i++) {
  6. var source = arguments[i];
  7. for (var key in source) {
  8. if (Object.prototype.hasOwnProperty.call(source, key)) {
  9. target[key] = source[key];
  10. }
  11. }
  12. }
  13. return target;
  14. };
  15. var _typeof =
  16. typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol'
  17. ? function(obj) {
  18. return typeof obj;
  19. }
  20. : function(obj) {
  21. return obj &&
  22. typeof Symbol === 'function' &&
  23. obj.constructor === Symbol &&
  24. obj !== Symbol.prototype
  25. ? 'symbol'
  26. : typeof obj;
  27. };
  28. function _objectWithoutProperties(obj, keys) {
  29. var target = {};
  30. for (var i in obj) {
  31. if (keys.indexOf(i) >= 0) continue;
  32. if (!Object.prototype.hasOwnProperty.call(obj, i)) continue;
  33. target[i] = obj[i];
  34. }
  35. return target;
  36. }
  37. function _toConsumableArray(arr) {
  38. if (Array.isArray(arr)) {
  39. for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) {
  40. arr2[i] = arr[i];
  41. }
  42. return arr2;
  43. } else {
  44. return Array.from(arr);
  45. }
  46. }
  47. (function(global, factory) {
  48. (typeof exports === 'undefined' ? 'undefined' : _typeof(exports)) === 'object' &&
  49. typeof module !== 'undefined'
  50. ? (module.exports = factory(require('url'), require('moment'), require('mockjs')))
  51. : typeof define === 'function' && define.amd
  52. ? define(['url', 'moment', 'mockjs'], factory)
  53. : (global.mock = factory(global.url, global.moment, global.mockjs, global.roadhogApiDoc));
  54. })(undefined, function(url, moment, mockjs) {
  55. 'use strict';
  56. moment = moment && moment.hasOwnProperty('default') ? moment['default'] : moment;
  57. mockjs = mockjs && mockjs.hasOwnProperty('default') ? mockjs['default'] : mockjs;
  58. // mock tableListDataSource
  59. var tableListDataSource = [];
  60. for (var i = 0; i < 46; i += 1) {
  61. tableListDataSource.push({
  62. key: i,
  63. disabled: i % 6 === 0,
  64. href: 'https://ant.design',
  65. avatar: [
  66. 'https://gw.alipayobjects.com/zos/rmsportal/eeHMaZBwmTvLdIwMfBpg.png',
  67. 'https://gw.alipayobjects.com/zos/rmsportal/udxAbMEhpwthVVcjLXik.png',
  68. ][i % 2],
  69. name: 'TradeCode ' + i,
  70. title: '\u4E00\u4E2A\u4EFB\u52A1\u540D\u79F0 ' + i,
  71. owner: '曲丽丽',
  72. desc: '这是一段描述',
  73. callNo: Math.floor(Math.random() * 1000),
  74. status: Math.floor(Math.random() * 10) % 4,
  75. updatedAt: new Date('2017-07-' + (Math.floor(i / 2) + 1)),
  76. createdAt: new Date('2017-07-' + (Math.floor(i / 2) + 1)),
  77. progress: Math.ceil(Math.random() * 100),
  78. });
  79. }
  80. function getRule(req, res, u) {
  81. var url$$1 = u;
  82. if (!url$$1 || Object.prototype.toString.call(url$$1) !== '[object String]') {
  83. url$$1 = req.url; // eslint-disable-line
  84. }
  85. var params = url.parse(url$$1, true).query;
  86. var dataSource = [].concat(_toConsumableArray(tableListDataSource));
  87. if (params.sorter) {
  88. var s = params.sorter.split('_');
  89. dataSource = dataSource.sort(function(prev, next) {
  90. if (s[1] === 'descend') {
  91. return next[s[0]] - prev[s[0]];
  92. }
  93. return prev[s[0]] - next[s[0]];
  94. });
  95. }
  96. if (params.status) {
  97. var status = params.status.split(',');
  98. var filterDataSource = [];
  99. status.forEach(function(s) {
  100. filterDataSource = filterDataSource.concat(
  101. [].concat(_toConsumableArray(dataSource)).filter(function(data) {
  102. return parseInt(data.status, 10) === parseInt(s[0], 10);
  103. })
  104. );
  105. });
  106. dataSource = filterDataSource;
  107. }
  108. if (params.name) {
  109. dataSource = dataSource.filter(function(data) {
  110. return data.name.indexOf(params.name) > -1;
  111. });
  112. }
  113. var pageSize = 10;
  114. if (params.pageSize) {
  115. pageSize = params.pageSize * 1;
  116. }
  117. var result = {
  118. list: dataSource,
  119. pagination: {
  120. total: dataSource.length,
  121. pageSize: pageSize,
  122. current: parseInt(params.currentPage, 10) || 1,
  123. },
  124. };
  125. if (res && res.json) {
  126. res.json(result);
  127. } else {
  128. return result;
  129. }
  130. }
  131. function postRule(req, res, u, b) {
  132. var url$$1 = u;
  133. if (!url$$1 || Object.prototype.toString.call(url$$1) !== '[object String]') {
  134. url$$1 = req.url; // eslint-disable-line
  135. }
  136. var body = (b && b.body) || req.body;
  137. var method = body.method,
  138. name = body.name,
  139. desc = body.desc,
  140. key = body.key;
  141. switch (method) {
  142. /* eslint no-case-declarations:0 */
  143. case 'delete':
  144. tableListDataSource = tableListDataSource.filter(function(item) {
  145. return key.indexOf(item.key) === -1;
  146. });
  147. break;
  148. case 'post':
  149. var _i = Math.ceil(Math.random() * 10000);
  150. tableListDataSource.unshift({
  151. key: _i,
  152. href: 'https://ant.design',
  153. avatar: [
  154. 'https://gw.alipayobjects.com/zos/rmsportal/eeHMaZBwmTvLdIwMfBpg.png',
  155. 'https://gw.alipayobjects.com/zos/rmsportal/udxAbMEhpwthVVcjLXik.png',
  156. ][_i % 2],
  157. name: 'TradeCode ' + _i,
  158. title: '\u4E00\u4E2A\u4EFB\u52A1\u540D\u79F0 ' + _i,
  159. owner: '曲丽丽',
  160. desc: desc,
  161. callNo: Math.floor(Math.random() * 1000),
  162. status: Math.floor(Math.random() * 10) % 2,
  163. updatedAt: new Date(),
  164. createdAt: new Date(),
  165. progress: Math.ceil(Math.random() * 100),
  166. });
  167. break;
  168. case 'update':
  169. tableListDataSource = tableListDataSource.map(function(item) {
  170. if (item.key === key) {
  171. return _extends({}, item, { desc: desc, name: name });
  172. }
  173. return item;
  174. });
  175. break;
  176. default:
  177. break;
  178. }
  179. var result = {
  180. list: tableListDataSource,
  181. pagination: {
  182. total: tableListDataSource.length,
  183. },
  184. };
  185. if (res && res.json) {
  186. res.json(result);
  187. } else {
  188. return result;
  189. }
  190. }
  191. var titles = [
  192. 'Alipay',
  193. 'Angular',
  194. 'Ant Design',
  195. 'Ant Design Pro',
  196. 'Bootstrap',
  197. 'React',
  198. 'Vue',
  199. 'Webpack',
  200. ];
  201. var avatars = [
  202. 'https://gw.alipayobjects.com/zos/rmsportal/WdGqmHpayyMjiEhcKoVE.png', // Alipay
  203. 'https://gw.alipayobjects.com/zos/rmsportal/zOsKZmFRdUtvpqCImOVY.png', // Angular
  204. 'https://gw.alipayobjects.com/zos/rmsportal/dURIMkkrRFpPgTuzkwnB.png', // Ant Design
  205. 'https://gw.alipayobjects.com/zos/rmsportal/sfjbOqnsXXJgNCjCzDBL.png', // Ant Design Pro
  206. 'https://gw.alipayobjects.com/zos/rmsportal/siCrBXXhmvTQGWPNLBow.png', // Bootstrap
  207. 'https://gw.alipayobjects.com/zos/rmsportal/kZzEzemZyKLKFsojXItE.png', // React
  208. 'https://gw.alipayobjects.com/zos/rmsportal/ComBAopevLwENQdKWiIn.png', // Vue
  209. 'https://gw.alipayobjects.com/zos/rmsportal/nxkuOJlFJuAUhzlMTCEe.png',
  210. ];
  211. var avatars2 = [
  212. 'https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png',
  213. 'https://gw.alipayobjects.com/zos/rmsportal/cnrhVkzwxjPwAaCfPbdc.png',
  214. 'https://gw.alipayobjects.com/zos/rmsportal/gaOngJwsRYRaVAuXXcmB.png',
  215. 'https://gw.alipayobjects.com/zos/rmsportal/ubnKSIfAJTxIgXOKlciN.png',
  216. 'https://gw.alipayobjects.com/zos/rmsportal/WhxKECPNujWoWEFNdnJE.png',
  217. 'https://gw.alipayobjects.com/zos/rmsportal/jZUIxmJycoymBprLOUbT.png',
  218. 'https://gw.alipayobjects.com/zos/rmsportal/psOgztMplJMGpVEqfcgF.png',
  219. 'https://gw.alipayobjects.com/zos/rmsportal/ZpBqSxLxVEXfcUNoPKrz.png',
  220. 'https://gw.alipayobjects.com/zos/rmsportal/laiEnJdGHVOhJrUShBaJ.png',
  221. 'https://gw.alipayobjects.com/zos/rmsportal/UrQsqscbKEpNuJcvBZBu.png',
  222. ];
  223. var covers = [
  224. 'https://gw.alipayobjects.com/zos/rmsportal/uMfMFlvUuceEyPpotzlq.png',
  225. 'https://gw.alipayobjects.com/zos/rmsportal/iZBVOIhGJiAnhplqjvZW.png',
  226. 'https://gw.alipayobjects.com/zos/rmsportal/iXjVmWVHbCJAyqvDxdtx.png',
  227. 'https://gw.alipayobjects.com/zos/rmsportal/gLaIAoVWTtLbBWZNYEMg.png',
  228. ];
  229. var desc = [
  230. '那是一种内在的东西, 他们到达不了,也无法触及的',
  231. '希望是一个好东西,也许是最好的,好东西是不会消亡的',
  232. '生命就像一盒巧克力,结果往往出人意料',
  233. '城镇中有那么多的酒馆,她却偏偏走进了我的酒馆',
  234. '那时候我只会想自己想要什么,从不想自己拥有什么',
  235. ];
  236. var user = [
  237. '付小小',
  238. '曲丽丽',
  239. '林东东',
  240. '周星星',
  241. '吴加好',
  242. '朱偏右',
  243. '鱼酱',
  244. '乐哥',
  245. '谭小仪',
  246. '仲尼',
  247. ];
  248. function fakeList(count) {
  249. var list = [];
  250. for (var _i2 = 0; _i2 < count; _i2 += 1) {
  251. list.push({
  252. id: 'fake-list-' + _i2,
  253. owner: user[_i2 % 10],
  254. title: titles[_i2 % 8],
  255. avatar: avatars[_i2 % 8],
  256. cover: parseInt(_i2 / 4, 10) % 2 === 0 ? covers[_i2 % 4] : covers[3 - (_i2 % 4)],
  257. status: ['active', 'exception', 'normal'][_i2 % 3],
  258. percent: Math.ceil(Math.random() * 50) + 50,
  259. logo: avatars[_i2 % 8],
  260. href: 'https://ant.design',
  261. updatedAt: new Date(new Date().getTime() - 1000 * 60 * 60 * 2 * _i2),
  262. createdAt: new Date(new Date().getTime() - 1000 * 60 * 60 * 2 * _i2),
  263. subDescription: desc[_i2 % 5],
  264. description:
  265. '在中台产品的研发过程中,会出现不同的设计规范和实现方式,但其中往往存在很多类似的页面和组件,这些类似的组件会被抽离成一套标准规范。',
  266. activeUser: Math.ceil(Math.random() * 100000) + 100000,
  267. newUser: Math.ceil(Math.random() * 1000) + 1000,
  268. star: Math.ceil(Math.random() * 100) + 100,
  269. like: Math.ceil(Math.random() * 100) + 100,
  270. message: Math.ceil(Math.random() * 10) + 10,
  271. content:
  272. '段落示意:蚂蚁金服设计平台 ant.design,用最小的工作量,无缝接入蚂蚁金服生态,提供跨越设计与开发的体验解决方案。蚂蚁金服设计平台 ant.design,用最小的工作量,无缝接入蚂蚁金服生态,提供跨越设计与开发的体验解决方案。',
  273. members: [
  274. {
  275. avatar: 'https://gw.alipayobjects.com/zos/rmsportal/ZiESqWwCXBRQoaPONSJe.png',
  276. name: '曲丽丽',
  277. id: 'member1',
  278. },
  279. {
  280. avatar: 'https://gw.alipayobjects.com/zos/rmsportal/tBOxZPlITHqwlGjsJWaF.png',
  281. name: '王昭君',
  282. id: 'member2',
  283. },
  284. {
  285. avatar: 'https://gw.alipayobjects.com/zos/rmsportal/sBxjgqiuHMGRkIjqlQCd.png',
  286. name: '董娜娜',
  287. id: 'member3',
  288. },
  289. ],
  290. });
  291. }
  292. return list;
  293. }
  294. var sourceData = void 0;
  295. function getFakeList(req, res) {
  296. var params = req.query;
  297. var count = params.count * 1 || 20;
  298. var result = fakeList(count);
  299. sourceData = result;
  300. if (res && res.json) {
  301. res.json(result);
  302. } else {
  303. return result;
  304. }
  305. }
  306. function postFakeList(req, res) {
  307. var body = req.body;
  308. // const params = getUrlParams(url);
  309. var method = body.method,
  310. id = body.id,
  311. restParams = _objectWithoutProperties(body, ['method', 'id']);
  312. // const count = (params.count * 1) || 20;
  313. var result = sourceData;
  314. switch (method) {
  315. case 'delete':
  316. result = result.filter(function(item) {
  317. return item.id !== id;
  318. });
  319. break;
  320. case 'update':
  321. result.forEach(function(item, i) {
  322. if (item.id === id) {
  323. result[i] = Object.assign(item, restParams);
  324. }
  325. });
  326. break;
  327. case 'post':
  328. result.unshift(
  329. _extends({}, restParams, {
  330. id: 'fake-list-' + result.length,
  331. createdAt: new Date().getTime(),
  332. })
  333. );
  334. break;
  335. default:
  336. break;
  337. }
  338. if (res && res.json) {
  339. res.json(result);
  340. } else {
  341. return result;
  342. }
  343. }
  344. var getNotice = [
  345. {
  346. id: 'xxx1',
  347. title: titles[0],
  348. logo: avatars[0],
  349. description: '那是一种内在的东西,他们到达不了,也无法触及的',
  350. updatedAt: new Date(),
  351. member: '科学搬砖组',
  352. href: '',
  353. memberLink: '',
  354. },
  355. {
  356. id: 'xxx2',
  357. title: titles[1],
  358. logo: avatars[1],
  359. description: '希望是一个好东西,也许是最好的,好东西是不会消亡的',
  360. updatedAt: new Date('2017-07-24'),
  361. member: '全组都是吴彦祖',
  362. href: '',
  363. memberLink: '',
  364. },
  365. {
  366. id: 'xxx3',
  367. title: titles[2],
  368. logo: avatars[2],
  369. description: '城镇中有那么多的酒馆,她却偏偏走进了我的酒馆',
  370. updatedAt: new Date(),
  371. member: '中二少女团',
  372. href: '',
  373. memberLink: '',
  374. },
  375. {
  376. id: 'xxx4',
  377. title: titles[3],
  378. logo: avatars[3],
  379. description: '那时候我只会想自己想要什么,从不想自己拥有什么',
  380. updatedAt: new Date('2017-07-23'),
  381. member: '程序员日常',
  382. href: '',
  383. memberLink: '',
  384. },
  385. {
  386. id: 'xxx5',
  387. title: titles[4],
  388. logo: avatars[4],
  389. description: '凛冬将至',
  390. updatedAt: new Date('2017-07-23'),
  391. member: '高逼格设计天团',
  392. href: '',
  393. memberLink: '',
  394. },
  395. {
  396. id: 'xxx6',
  397. title: titles[5],
  398. logo: avatars[5],
  399. description: '生命就像一盒巧克力,结果往往出人意料',
  400. updatedAt: new Date('2017-07-23'),
  401. member: '骗你来学计算机',
  402. href: '',
  403. memberLink: '',
  404. },
  405. ];
  406. var getActivities = [
  407. {
  408. id: 'trend-1',
  409. updatedAt: new Date(),
  410. user: {
  411. name: '曲丽丽',
  412. avatar: avatars2[0],
  413. },
  414. group: {
  415. name: '高逼格设计天团',
  416. link: 'http://github.com/',
  417. },
  418. project: {
  419. name: '六月迭代',
  420. link: 'http://github.com/',
  421. },
  422. template: '在 @{group} 新建项目 @{project}',
  423. },
  424. {
  425. id: 'trend-2',
  426. updatedAt: new Date(),
  427. user: {
  428. name: '付小小',
  429. avatar: avatars2[1],
  430. },
  431. group: {
  432. name: '高逼格设计天团',
  433. link: 'http://github.com/',
  434. },
  435. project: {
  436. name: '六月迭代',
  437. link: 'http://github.com/',
  438. },
  439. template: '在 @{group} 新建项目 @{project}',
  440. },
  441. {
  442. id: 'trend-3',
  443. updatedAt: new Date(),
  444. user: {
  445. name: '林东东',
  446. avatar: avatars2[2],
  447. },
  448. group: {
  449. name: '中二少女团',
  450. link: 'http://github.com/',
  451. },
  452. project: {
  453. name: '六月迭代',
  454. link: 'http://github.com/',
  455. },
  456. template: '在 @{group} 新建项目 @{project}',
  457. },
  458. {
  459. id: 'trend-4',
  460. updatedAt: new Date(),
  461. user: {
  462. name: '周星星',
  463. avatar: avatars2[4],
  464. },
  465. project: {
  466. name: '5 月日常迭代',
  467. link: 'http://github.com/',
  468. },
  469. template: '将 @{project} 更新至已发布状态',
  470. },
  471. {
  472. id: 'trend-5',
  473. updatedAt: new Date(),
  474. user: {
  475. name: '朱偏右',
  476. avatar: avatars2[3],
  477. },
  478. project: {
  479. name: '工程效能',
  480. link: 'http://github.com/',
  481. },
  482. comment: {
  483. name: '留言',
  484. link: 'http://github.com/',
  485. },
  486. template: '在 @{project} 发布了 @{comment}',
  487. },
  488. {
  489. id: 'trend-6',
  490. updatedAt: new Date(),
  491. user: {
  492. name: '乐哥',
  493. avatar: avatars2[5],
  494. },
  495. group: {
  496. name: '程序员日常',
  497. link: 'http://github.com/',
  498. },
  499. project: {
  500. name: '品牌迭代',
  501. link: 'http://github.com/',
  502. },
  503. template: '在 @{group} 新建项目 @{project}',
  504. },
  505. ];
  506. function getFakeCaptcha(req, res) {
  507. if (res && res.json) {
  508. res.json('captcha-xxx');
  509. } else {
  510. return 'captcha-xxx';
  511. }
  512. }
  513. // mock data
  514. var visitData = [];
  515. var beginDay = new Date().getTime();
  516. var fakeY = [7, 5, 4, 2, 4, 7, 5, 6, 5, 9, 6, 3, 1, 5, 3, 6, 5];
  517. for (var _i3 = 0; _i3 < fakeY.length; _i3 += 1) {
  518. visitData.push({
  519. x: moment(new Date(beginDay + 1000 * 60 * 60 * 24 * _i3)).format('YYYY-MM-DD'),
  520. y: fakeY[_i3],
  521. });
  522. }
  523. var visitData2 = [];
  524. var fakeY2 = [1, 6, 4, 8, 3, 7, 2];
  525. for (var _i4 = 0; _i4 < fakeY2.length; _i4 += 1) {
  526. visitData2.push({
  527. x: moment(new Date(beginDay + 1000 * 60 * 60 * 24 * _i4)).format('YYYY-MM-DD'),
  528. y: fakeY2[_i4],
  529. });
  530. }
  531. var salesData = [];
  532. for (var _i5 = 0; _i5 < 12; _i5 += 1) {
  533. salesData.push({
  534. x: _i5 + 1 + '\u6708',
  535. y: Math.floor(Math.random() * 1000) + 200,
  536. });
  537. }
  538. var searchData = [];
  539. for (var _i6 = 0; _i6 < 50; _i6 += 1) {
  540. searchData.push({
  541. index: _i6 + 1,
  542. keyword: '\u641C\u7D22\u5173\u952E\u8BCD-' + _i6,
  543. count: Math.floor(Math.random() * 1000),
  544. range: Math.floor(Math.random() * 100),
  545. status: Math.floor((Math.random() * 10) % 2),
  546. });
  547. }
  548. var salesTypeData = [
  549. {
  550. x: '家用电器',
  551. y: 4544,
  552. },
  553. {
  554. x: '食用酒水',
  555. y: 3321,
  556. },
  557. {
  558. x: '个护健康',
  559. y: 3113,
  560. },
  561. {
  562. x: '服饰箱包',
  563. y: 2341,
  564. },
  565. {
  566. x: '母婴产品',
  567. y: 1231,
  568. },
  569. {
  570. x: '其他',
  571. y: 1231,
  572. },
  573. ];
  574. var salesTypeDataOnline = [
  575. {
  576. x: '家用电器',
  577. y: 244,
  578. },
  579. {
  580. x: '食用酒水',
  581. y: 321,
  582. },
  583. {
  584. x: '个护健康',
  585. y: 311,
  586. },
  587. {
  588. x: '服饰箱包',
  589. y: 41,
  590. },
  591. {
  592. x: '母婴产品',
  593. y: 121,
  594. },
  595. {
  596. x: '其他',
  597. y: 111,
  598. },
  599. ];
  600. var salesTypeDataOffline = [
  601. {
  602. x: '家用电器',
  603. y: 99,
  604. },
  605. {
  606. x: '个护健康',
  607. y: 188,
  608. },
  609. {
  610. x: '服饰箱包',
  611. y: 344,
  612. },
  613. {
  614. x: '母婴产品',
  615. y: 255,
  616. },
  617. {
  618. x: '其他',
  619. y: 65,
  620. },
  621. ];
  622. var offlineData = [];
  623. for (var _i7 = 0; _i7 < 10; _i7 += 1) {
  624. offlineData.push({
  625. name: '\u95E8\u5E97' + _i7,
  626. cvr: Math.ceil(Math.random() * 9) / 10,
  627. });
  628. }
  629. var offlineChartData = [];
  630. for (var _i8 = 0; _i8 < 20; _i8 += 1) {
  631. offlineChartData.push({
  632. x: new Date().getTime() + 1000 * 60 * 30 * _i8,
  633. y1: Math.floor(Math.random() * 100) + 10,
  634. y2: Math.floor(Math.random() * 100) + 10,
  635. });
  636. }
  637. var radarOriginData = [
  638. {
  639. name: '个人',
  640. ref: 10,
  641. koubei: 8,
  642. output: 4,
  643. contribute: 5,
  644. hot: 7,
  645. },
  646. {
  647. name: '团队',
  648. ref: 3,
  649. koubei: 9,
  650. output: 6,
  651. contribute: 3,
  652. hot: 1,
  653. },
  654. {
  655. name: '部门',
  656. ref: 4,
  657. koubei: 1,
  658. output: 6,
  659. contribute: 5,
  660. hot: 7,
  661. },
  662. ];
  663. //
  664. var radarData = [];
  665. var radarTitleMap = {
  666. ref: '引用',
  667. koubei: '口碑',
  668. output: '产量',
  669. contribute: '贡献',
  670. hot: '热度',
  671. };
  672. radarOriginData.forEach(function(item) {
  673. Object.keys(item).forEach(function(key) {
  674. if (key !== 'name') {
  675. radarData.push({
  676. name: item.name,
  677. label: radarTitleMap[key],
  678. value: item[key],
  679. });
  680. }
  681. });
  682. });
  683. var getFakeChartData = {
  684. visitData: visitData,
  685. visitData2: visitData2,
  686. salesData: salesData,
  687. searchData: searchData,
  688. offlineData: offlineData,
  689. offlineChartData: offlineChartData,
  690. salesTypeData: salesTypeData,
  691. salesTypeDataOnline: salesTypeDataOnline,
  692. salesTypeDataOffline: salesTypeDataOffline,
  693. radarData: radarData,
  694. };
  695. var basicGoods = [
  696. {
  697. id: '1234561',
  698. name: '矿泉水 550ml',
  699. barcode: '12421432143214321',
  700. price: '2.00',
  701. num: '1',
  702. amount: '2.00',
  703. },
  704. {
  705. id: '1234562',
  706. name: '凉茶 300ml',
  707. barcode: '12421432143214322',
  708. price: '3.00',
  709. num: '2',
  710. amount: '6.00',
  711. },
  712. {
  713. id: '1234563',
  714. name: '好吃的薯片',
  715. barcode: '12421432143214323',
  716. price: '7.00',
  717. num: '4',
  718. amount: '28.00',
  719. },
  720. {
  721. id: '1234564',
  722. name: '特别好吃的蛋卷',
  723. barcode: '12421432143214324',
  724. price: '8.50',
  725. num: '3',
  726. amount: '25.50',
  727. },
  728. ];
  729. var basicProgress = [
  730. {
  731. key: '1',
  732. time: '2017-10-01 14:10',
  733. rate: '联系客户',
  734. status: 'processing',
  735. operator: '取货员 ID1234',
  736. cost: '5mins',
  737. },
  738. {
  739. key: '2',
  740. time: '2017-10-01 14:05',
  741. rate: '取货员出发',
  742. status: 'success',
  743. operator: '取货员 ID1234',
  744. cost: '1h',
  745. },
  746. {
  747. key: '3',
  748. time: '2017-10-01 13:05',
  749. rate: '取货员接单',
  750. status: 'success',
  751. operator: '取货员 ID1234',
  752. cost: '5mins',
  753. },
  754. {
  755. key: '4',
  756. time: '2017-10-01 13:00',
  757. rate: '申请审批通过',
  758. status: 'success',
  759. operator: '系统',
  760. cost: '1h',
  761. },
  762. {
  763. key: '5',
  764. time: '2017-10-01 12:00',
  765. rate: '发起退货申请',
  766. status: 'success',
  767. operator: '用户',
  768. cost: '5mins',
  769. },
  770. ];
  771. var advancedOperation1 = [
  772. {
  773. key: 'op1',
  774. type: '订购关系生效',
  775. name: '曲丽丽',
  776. status: 'agree',
  777. updatedAt: '2017-10-03 19:23:12',
  778. memo: '-',
  779. },
  780. {
  781. key: 'op2',
  782. type: '财务复审',
  783. name: '付小小',
  784. status: 'reject',
  785. updatedAt: '2017-10-03 19:23:12',
  786. memo: '不通过原因',
  787. },
  788. {
  789. key: 'op3',
  790. type: '部门初审',
  791. name: '周毛毛',
  792. status: 'agree',
  793. updatedAt: '2017-10-03 19:23:12',
  794. memo: '-',
  795. },
  796. {
  797. key: 'op4',
  798. type: '提交订单',
  799. name: '林东东',
  800. status: 'agree',
  801. updatedAt: '2017-10-03 19:23:12',
  802. memo: '很棒',
  803. },
  804. {
  805. key: 'op5',
  806. type: '创建订单',
  807. name: '汗牙牙',
  808. status: 'agree',
  809. updatedAt: '2017-10-03 19:23:12',
  810. memo: '-',
  811. },
  812. ];
  813. var advancedOperation2 = [
  814. {
  815. key: 'op1',
  816. type: '订购关系生效',
  817. name: '曲丽丽',
  818. status: 'agree',
  819. updatedAt: '2017-10-03 19:23:12',
  820. memo: '-',
  821. },
  822. ];
  823. var advancedOperation3 = [
  824. {
  825. key: 'op1',
  826. type: '创建订单',
  827. name: '汗牙牙',
  828. status: 'agree',
  829. updatedAt: '2017-10-03 19:23:12',
  830. memo: '-',
  831. },
  832. ];
  833. var getProfileBasicData = {
  834. basicGoods: basicGoods,
  835. basicProgress: basicProgress,
  836. };
  837. var getProfileAdvancedData = {
  838. advancedOperation1: advancedOperation1,
  839. advancedOperation2: advancedOperation2,
  840. advancedOperation3: advancedOperation3,
  841. };
  842. var getNotices = function getNotices(req, res) {
  843. res.json([
  844. {
  845. id: '000000001',
  846. avatar: 'https://gw.alipayobjects.com/zos/rmsportal/ThXAXghbEsBCCSDihZxY.png',
  847. title: '你收到了 14 份新周报',
  848. datetime: '2017-08-09',
  849. type: '通知',
  850. },
  851. {
  852. id: '000000002',
  853. avatar: 'https://gw.alipayobjects.com/zos/rmsportal/OKJXDXrmkNshAMvwtvhu.png',
  854. title: '你推荐的 曲妮妮 已通过第三轮面试',
  855. datetime: '2017-08-08',
  856. type: '通知',
  857. },
  858. {
  859. id: '000000003',
  860. avatar: 'https://gw.alipayobjects.com/zos/rmsportal/kISTdvpyTAhtGxpovNWd.png',
  861. title: '这种模板可以区分多种通知类型',
  862. datetime: '2017-08-07',
  863. read: true,
  864. type: '通知',
  865. },
  866. {
  867. id: '000000004',
  868. avatar: 'https://gw.alipayobjects.com/zos/rmsportal/GvqBnKhFgObvnSGkDsje.png',
  869. title: '左侧图标用于区分不同的类型',
  870. datetime: '2017-08-07',
  871. type: '通知',
  872. },
  873. {
  874. id: '000000005',
  875. avatar: 'https://gw.alipayobjects.com/zos/rmsportal/ThXAXghbEsBCCSDihZxY.png',
  876. title: '内容不要超过两行字,超出时自动截断',
  877. datetime: '2017-08-07',
  878. type: '通知',
  879. },
  880. {
  881. id: '000000006',
  882. avatar: 'https://gw.alipayobjects.com/zos/rmsportal/fcHMVNCjPOsbUGdEduuv.jpeg',
  883. title: '曲丽丽 评论了你',
  884. description: '描述信息描述信息描述信息',
  885. datetime: '2017-08-07',
  886. type: '消息',
  887. },
  888. {
  889. id: '000000007',
  890. avatar: 'https://gw.alipayobjects.com/zos/rmsportal/fcHMVNCjPOsbUGdEduuv.jpeg',
  891. title: '朱偏右 回复了你',
  892. description: '这种模板用于提醒谁与你发生了互动,左侧放『谁』的头像',
  893. datetime: '2017-08-07',
  894. type: '消息',
  895. },
  896. {
  897. id: '000000008',
  898. avatar: 'https://gw.alipayobjects.com/zos/rmsportal/fcHMVNCjPOsbUGdEduuv.jpeg',
  899. title: '标题',
  900. description: '这种模板用于提醒谁与你发生了互动,左侧放『谁』的头像',
  901. datetime: '2017-08-07',
  902. type: '消息',
  903. },
  904. {
  905. id: '000000009',
  906. title: '任务名称',
  907. description: '任务需要在 2017-01-12 20:00 前启动',
  908. extra: '未开始',
  909. status: 'todo',
  910. type: '待办',
  911. },
  912. {
  913. id: '000000010',
  914. title: '第三方紧急代码变更',
  915. description: '冠霖提交于 2017-01-06,需在 2017-01-07 前完成代码变更任务',
  916. extra: '马上到期',
  917. status: 'urgent',
  918. type: '待办',
  919. },
  920. {
  921. id: '000000011',
  922. title: '信息安全考试',
  923. description: '指派竹尔于 2017-01-09 前完成更新并发布',
  924. extra: '已耗时 8 天',
  925. status: 'doing',
  926. type: '待办',
  927. },
  928. {
  929. id: '000000012',
  930. title: 'ABCD 版本发布',
  931. description: '冠霖提交于 2017-01-06,需在 2017-01-07 前完成代码变更任务',
  932. extra: '进行中',
  933. status: 'processing',
  934. type: '待办',
  935. },
  936. ]);
  937. };
  938. var fs = require('fs');
  939. function getJson(infoType) {
  940. var json = fs.readFileSync(__dirname + '/geographic/' + infoType + '.json', 'utf8');
  941. return JSON.parse(json);
  942. }
  943. function getProvince(req, res) {
  944. res.json(getJson('province'));
  945. }
  946. function getCity(req, res) {
  947. res.json(getJson('city')[req.params.province]);
  948. }
  949. // 是否禁用代理
  950. var noProxy = process.env.NO_PROXY === 'true';
  951. // 代码中会兼容本地 service mock 以及部署站点的静态数据
  952. var proxy = {
  953. // 支持值为 Object 和 Array
  954. 'GET /api/currentUser': {
  955. $desc: '获取当前用户接口',
  956. $params: {
  957. pageSize: {
  958. desc: '分页',
  959. exp: 2,
  960. },
  961. },
  962. $body: {
  963. name: 'Serati Ma',
  964. avatar: 'https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png',
  965. userid: '00000001',
  966. email: 'antdesign@alipay.com',
  967. signature: '海纳百川,有容乃大',
  968. title: '交互专家',
  969. group: '蚂蚁金服-某某某事业群-某某平台部-某某技术部-UED',
  970. tags: [
  971. {
  972. key: '0',
  973. label: '很有想法的',
  974. },
  975. {
  976. key: '1',
  977. label: '专注设计',
  978. },
  979. {
  980. key: '2',
  981. label: '辣~',
  982. },
  983. {
  984. key: '3',
  985. label: '大长腿',
  986. },
  987. {
  988. key: '4',
  989. label: '川妹子',
  990. },
  991. {
  992. key: '5',
  993. label: '海纳百川',
  994. },
  995. ],
  996. notifyCount: 12,
  997. country: 'China',
  998. geographic: {
  999. province: {
  1000. label: '浙江省',
  1001. key: '330000',
  1002. },
  1003. city: {
  1004. label: '杭州市',
  1005. key: '330100',
  1006. },
  1007. },
  1008. address: '西湖区工专路 77 号',
  1009. phone: '0752-268888888',
  1010. },
  1011. },
  1012. // GET POST 可省略
  1013. 'GET /api/users': [
  1014. {
  1015. key: '1',
  1016. name: 'John Brown',
  1017. age: 32,
  1018. address: 'New York No. 1 Lake Park',
  1019. },
  1020. {
  1021. key: '2',
  1022. name: 'Jim Green',
  1023. age: 42,
  1024. address: 'London No. 1 Lake Park',
  1025. },
  1026. {
  1027. key: '3',
  1028. name: 'Joe Black',
  1029. age: 32,
  1030. address: 'Sidney No. 1 Lake Park',
  1031. },
  1032. ],
  1033. 'GET /api/project/notice': getNotice,
  1034. 'GET /api/activities': getActivities,
  1035. 'GET /api/rule': getRule,
  1036. 'POST /api/rule': {
  1037. $params: {
  1038. pageSize: {
  1039. desc: '分页',
  1040. exp: 2,
  1041. },
  1042. },
  1043. $body: postRule,
  1044. },
  1045. 'POST /api/forms': function POSTApiForms(req, res) {
  1046. res.send({ message: 'Ok' });
  1047. },
  1048. 'GET /api/tags': mockjs.mock({
  1049. 'list|100': [{ name: '@city', 'value|1-100': 150, 'type|0-2': 1 }],
  1050. }),
  1051. 'GET /api/fake_list': getFakeList,
  1052. 'POST /api/fake_list': postFakeList,
  1053. 'GET /api/fake_chart_data': getFakeChartData,
  1054. 'GET /api/profile/basic': getProfileBasicData,
  1055. 'GET /api/profile/advanced': getProfileAdvancedData,
  1056. 'POST /api/login/account': function POSTApiLoginAccount(req, res) {
  1057. var _req$body = req.body,
  1058. password = _req$body.password,
  1059. userName = _req$body.userName,
  1060. type = _req$body.type;
  1061. if (password === '888888' && userName === 'admin') {
  1062. res.send({
  1063. status: 'ok',
  1064. type: type,
  1065. currentAuthority: 'admin',
  1066. });
  1067. return;
  1068. }
  1069. if (password === '123456' && userName === 'user') {
  1070. res.send({
  1071. status: 'ok',
  1072. type: type,
  1073. currentAuthority: 'user',
  1074. });
  1075. return;
  1076. }
  1077. res.send({
  1078. status: 'error',
  1079. type: type,
  1080. currentAuthority: 'guest',
  1081. });
  1082. },
  1083. 'POST /api/register': function POSTApiRegister(req, res) {
  1084. res.send({ status: 'ok', currentAuthority: 'user' });
  1085. },
  1086. 'GET /api/notices': getNotices,
  1087. 'GET /api/500': function GETApi500(req, res) {
  1088. res.status(500).send({
  1089. timestamp: 1513932555104,
  1090. status: 500,
  1091. error: 'error',
  1092. message: 'error',
  1093. path: '/base/category/list',
  1094. });
  1095. },
  1096. 'GET /api/404': function GETApi404(req, res) {
  1097. res.status(404).send({
  1098. timestamp: 1513932643431,
  1099. status: 404,
  1100. error: 'Not Found',
  1101. message: 'No message available',
  1102. path: '/base/category/list/2121212',
  1103. });
  1104. },
  1105. 'GET /api/403': function GETApi403(req, res) {
  1106. res.status(403).send({
  1107. timestamp: 1513932555104,
  1108. status: 403,
  1109. error: 'Unauthorized',
  1110. message: 'Unauthorized',
  1111. path: '/base/category/list',
  1112. });
  1113. },
  1114. 'GET /api/401': function GETApi401(req, res) {
  1115. res.status(401).send({
  1116. timestamp: 1513932555104,
  1117. status: 401,
  1118. error: 'Unauthorized',
  1119. message: 'Unauthorized',
  1120. path: '/base/category/list',
  1121. });
  1122. },
  1123. 'GET /api/geographic/province': getProvince,
  1124. 'GET /api/geographic/city/:province': getCity,
  1125. 'GET /api/captcha': getFakeCaptcha,
  1126. };
  1127. var _roadhogrc_mock = noProxy ? {} : proxy;
  1128. return _roadhogrc_mock;
  1129. });