api.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. export const ossUrl = process.env.OSS_URL;
  2. export const apiServer = process.env.API_BASE_URL;
  3. export const token = '';
  4. // export const token = '96ba3c924394934f7d30fa869a94ce0d';
  5. // export const token = '8f929ad2fcd37d2eff5c54967dd7c899';
  6. // 根据游戏id查询卡片信息
  7. export const apiCardUrlQuery = apiServer + 'CardUrlQuery';
  8. // 查询赛事结束显示信息
  9. export const apiMatchFininshInfoQuery = apiServer + 'MatchFininshInfoQuery';
  10. import tools from '/common/tools';
  11. // 检测request的返回值
  12. export function checkResCode(res) {
  13. if (res.data.code == 0) {
  14. return true;
  15. } else if (res.statusCode == 401) { // 未登录
  16. uni.showToast({
  17. title: `您尚未登录`,
  18. icon: 'none',
  19. duration: 3000
  20. });
  21. const url = `action://to_login/`;
  22. tools.appAction(url);
  23. return false;
  24. } else {
  25. uni.showToast({
  26. title: `${res.data.message}`,
  27. icon: 'none',
  28. duration: 3000
  29. });
  30. return false;
  31. }
  32. };
  33. // 检测token
  34. export function checkToken(token) {
  35. const regex = /^[0-9A-Za-f]{32}$/;
  36. if (regex.test(token)) {
  37. return true;
  38. } else { // 未登录
  39. console.log('checkToken err: ', token);
  40. uni.showToast({
  41. title: `您尚未登录`,
  42. icon: 'none',
  43. duration: 3000
  44. });
  45. const url = `action://to_login/`;
  46. tools.appAction(url);
  47. return false;
  48. }
  49. };