包含后厨 团餐 门店分支
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 

208 righe
4.6 KiB

  1. const waitTime = (time = 100) => {
  2. return new Promise((resolve) => {
  3. setTimeout(() => {
  4. resolve(true);
  5. }, time);
  6. });
  7. };
  8. async function getFakeCaptcha(req, res) {
  9. await waitTime(2000);
  10. return res.json('captcha-xxx');
  11. }
  12. const { ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION } = process.env;
  13. /**
  14. * 当前用户的权限,如果为空代表没登录
  15. * current user access, if is '', user need login
  16. * 如果是 pro 的预览,默认是有权限的
  17. */
  18. let access = ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site' ? 'admin' : '';
  19. const getAccess = () => {
  20. return access;
  21. }; // 代码中会兼容本地 service mock 以及部署站点的静态数据
  22. export default {
  23. // 支持值为 Object 和 Array
  24. 'GET /kitchen/api/currentUser': (req, res) => {
  25. if (!getAccess()) {
  26. res.status(401).send({
  27. data: {
  28. isLogin: false,
  29. },
  30. errorCode: '401',
  31. errorMessage: '请先登录!',
  32. success: true,
  33. });
  34. return;
  35. }
  36. res.send({
  37. name: 'Serati Ma',
  38. avatar: 'https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png',
  39. userid: '00000001',
  40. email: 'antdesign@alipay.com',
  41. signature: '海纳百川,有容乃大',
  42. title: '交互专家',
  43. group: '蚂蚁金服-某某某事业群-某某平台部-某某技术部-UED',
  44. tags: [
  45. {
  46. key: '0',
  47. label: '很有想法的',
  48. },
  49. {
  50. key: '1',
  51. label: '专注设计',
  52. },
  53. {
  54. key: '2',
  55. label: '辣~',
  56. },
  57. {
  58. key: '3',
  59. label: '大长腿',
  60. },
  61. {
  62. key: '4',
  63. label: '川妹子',
  64. },
  65. {
  66. key: '5',
  67. label: '海纳百川',
  68. },
  69. ],
  70. notifyCount: 12,
  71. unreadCount: 11,
  72. country: 'China',
  73. access: getAccess(),
  74. geographic: {
  75. province: {
  76. label: '浙江省',
  77. key: '330000',
  78. },
  79. city: {
  80. label: '杭州市',
  81. key: '330100',
  82. },
  83. },
  84. address: '西湖区工专路 77 号',
  85. phone: '0752-268888888',
  86. });
  87. },
  88. // GET POST 可省略
  89. 'GET /kitchen/api/users': [
  90. {
  91. key: '1',
  92. name: 'John Brown',
  93. age: 32,
  94. address: 'New York No. 1 Lake Park',
  95. },
  96. {
  97. key: '2',
  98. name: 'Jim Green',
  99. age: 42,
  100. address: 'London No. 1 Lake Park',
  101. },
  102. {
  103. key: '3',
  104. name: 'Joe Black',
  105. age: 32,
  106. address: 'Sidney No. 1 Lake Park',
  107. },
  108. ],
  109. 'POST /kitchen/api/login/account': async (req, res) => {
  110. const { password, username, type } = req.body;
  111. await waitTime(2000);
  112. if (password === 'ant.design' && username === 'admin') {
  113. res.send({
  114. status: 'ok',
  115. type,
  116. currentAuthority: 'admin',
  117. });
  118. access = 'admin';
  119. return;
  120. }
  121. if (password === 'ant.design' && username === 'user') {
  122. res.send({
  123. status: 'ok',
  124. type,
  125. currentAuthority: 'user',
  126. });
  127. access = 'user';
  128. return;
  129. }
  130. if (type === 'mobile') {
  131. res.send({
  132. status: 'ok',
  133. type,
  134. currentAuthority: 'admin',
  135. });
  136. access = 'admin';
  137. return;
  138. }
  139. res.send({
  140. status: 'error',
  141. type,
  142. currentAuthority: 'guest',
  143. });
  144. access = 'guest';
  145. },
  146. 'POST /kitchen/api/login/outLogin': (req, res) => {
  147. access = '';
  148. res.send({
  149. data: {},
  150. success: true,
  151. });
  152. },
  153. 'POST /kitchen/api/register': (req, res) => {
  154. res.send({
  155. status: 'ok',
  156. currentAuthority: 'user',
  157. success: true,
  158. });
  159. },
  160. 'GET /kitchen/api/500': (req, res) => {
  161. res.status(500).send({
  162. timestamp: 1513932555104,
  163. status: 500,
  164. error: 'error',
  165. message: 'error',
  166. path: '/base/category/list',
  167. });
  168. },
  169. 'GET /kitchen/api/404': (req, res) => {
  170. res.status(404).send({
  171. timestamp: 1513932643431,
  172. status: 404,
  173. error: 'Not Found',
  174. message: 'No message available',
  175. path: '/base/category/list/2121212',
  176. });
  177. },
  178. 'GET /kitchen/api/403': (req, res) => {
  179. res.status(403).send({
  180. timestamp: 1513932555104,
  181. status: 403,
  182. error: 'Unauthorized',
  183. message: 'Unauthorized',
  184. path: '/base/category/list',
  185. });
  186. },
  187. 'GET /kitchen/api/401': (req, res) => {
  188. res.status(401).send({
  189. timestamp: 1513932555104,
  190. status: 401,
  191. error: 'Unauthorized',
  192. message: 'Unauthorized',
  193. path: '/base/category/list',
  194. });
  195. },
  196. 'GET /kitchen/api/login/captcha': getFakeCaptcha,
  197. };