user.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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 /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. success: true,
  38. data: {
  39. name: 'Serati Ma',
  40. avatar: 'https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png',
  41. userid: '00000001',
  42. email: 'antdesign@alipay.com',
  43. signature: '海纳百川,有容乃大',
  44. title: '交互专家',
  45. group: '蚂蚁金服-某某某事业群-某某平台部-某某技术部-UED',
  46. tags: [
  47. {
  48. key: '0',
  49. label: '很有想法的',
  50. },
  51. {
  52. key: '1',
  53. label: '专注设计',
  54. },
  55. {
  56. key: '2',
  57. label: '辣~',
  58. },
  59. {
  60. key: '3',
  61. label: '大长腿',
  62. },
  63. {
  64. key: '4',
  65. label: '川妹子',
  66. },
  67. {
  68. key: '5',
  69. label: '海纳百川',
  70. },
  71. ],
  72. notifyCount: 12,
  73. unreadCount: 11,
  74. country: 'China',
  75. access: getAccess(),
  76. geographic: {
  77. province: {
  78. label: '浙江省',
  79. key: '330000',
  80. },
  81. city: {
  82. label: '杭州市',
  83. key: '330100',
  84. },
  85. },
  86. address: '西湖区工专路 77 号',
  87. phone: '0752-268888888',
  88. },
  89. });
  90. },
  91. // GET POST 可省略
  92. 'GET /api/users': [
  93. {
  94. key: '1',
  95. name: 'John Brown',
  96. age: 32,
  97. address: 'New York No. 1 Lake Park',
  98. },
  99. {
  100. key: '2',
  101. name: 'Jim Green',
  102. age: 42,
  103. address: 'London No. 1 Lake Park',
  104. },
  105. {
  106. key: '3',
  107. name: 'Joe Black',
  108. age: 32,
  109. address: 'Sidney No. 1 Lake Park',
  110. },
  111. ],
  112. 'POST /api/costAccount/login': async (req, res) => {
  113. const { password, account, type } = req.body;
  114. await waitTime(2000);
  115. console.log({password, account, type});
  116. if (password == '123456' && account === 'admin') {
  117. res.send({
  118. status:200,
  119. type,
  120. data:{
  121. currentAuthority: 'admin',
  122. name: 'Serati Ma',
  123. avatar: 'https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png',
  124. access: getAccess(),
  125. token:'token'
  126. }
  127. });
  128. access = 'admin';
  129. return;
  130. }
  131. if (password == '123456' && account === 'user') {
  132. res.send({
  133. status:200,
  134. type,
  135. data:{
  136. currentAuthority: 'user',
  137. name: 'Serata',
  138. avatar: 'https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png',
  139. access: getAccess(),
  140. token:'token'
  141. }
  142. });
  143. access = 'user';
  144. return;
  145. }
  146. if (type === 'mobile') {
  147. res.send({
  148. status: 'ok',
  149. type,
  150. currentAuthority: 'admin',
  151. });
  152. access = 'admin';
  153. return;
  154. }
  155. res.send({
  156. status: 'error',
  157. type,
  158. data:{
  159. currentAuthority: 'guest',
  160. }
  161. });
  162. access = 'guest';
  163. },
  164. 'POST /api/login/outLogin': (req, res) => {
  165. access = '';
  166. res.send({
  167. data: {},
  168. success: true,
  169. });
  170. },
  171. 'POST /api/register': (req, res) => {
  172. res.send({
  173. status: 'ok',
  174. currentAuthority: 'user',
  175. success: true,
  176. });
  177. },
  178. //获取分院列表
  179. 'GET /api/costAccount/menu/nav':(req, res)=>{
  180. const data = [
  181. ]
  182. res.send({
  183. data:data,
  184. status:200,
  185. msg:''
  186. });
  187. },
  188. //获取用户对应的菜单
  189. 'GET /api/costAccount/getHospArea':[
  190. {
  191. id:1,
  192. name:'分院名1'
  193. },
  194. {
  195. id:2,
  196. name:'分院名2'
  197. }
  198. ],
  199. 'GET /api/500': (req, res) => {
  200. res.status(500).send({
  201. timestamp: 1513932555104,
  202. status: 500,
  203. error: 'error',
  204. message: 'error',
  205. path: '/base/category/list',
  206. });
  207. },
  208. 'GET /api/404': (req, res) => {
  209. res.status(404).send({
  210. timestamp: 1513932643431,
  211. status: 404,
  212. error: 'Not Found',
  213. message: 'No message available',
  214. path: '/base/category/list/2121212',
  215. });
  216. },
  217. 'GET /api/403': (req, res) => {
  218. res.status(403).send({
  219. timestamp: 1513932555104,
  220. status: 403,
  221. error: 'Unauthorized',
  222. message: 'Unauthorized',
  223. path: '/base/category/list',
  224. });
  225. },
  226. 'GET /api/401': (req, res) => {
  227. res.status(401).send({
  228. timestamp: 1513932555104,
  229. status: 401,
  230. error: 'Unauthorized',
  231. message: 'Unauthorized',
  232. path: '/base/category/list',
  233. });
  234. },
  235. 'GET /api/login/captcha': getFakeCaptcha,
  236. };