Msg.js 629 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. export const errObj = {
  2. "102": {
  3. errMsg: '上传图片错误',
  4. code: 102
  5. },
  6. "101": {
  7. errMsg: '未找到该name对应的数据',
  8. code: 101
  9. },
  10. "ok": {
  11. errMsg: 'ok',
  12. code: 1
  13. }
  14. }
  15. function filterStatus(s) {
  16. let t = '未知';
  17. switch (s){
  18. case 1:
  19. t = 'success';
  20. break;
  21. case 2:
  22. t = 'warn';
  23. case 3:
  24. t = 'error';
  25. default:
  26. break;
  27. }
  28. return t;
  29. }
  30. export default function Msg(obj) {
  31. const { s, c, v } = obj;
  32. const returnObj = {
  33. status: filterStatus(s)
  34. };
  35. if(c) {
  36. returnObj.result = {...errObj[c], data: null};
  37. }else{
  38. returnObj.result = {...errObj.ok, data: v};
  39. }
  40. return returnObj;
  41. }