error.ts 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { router } from '@/router';
  2. import { LOGIN_URL, PHONE_LOGIN_URL } from '@/common/constants';
  3. import Store, { types } from '@/common/store/index.ts';
  4. const error_handle = function(err: any): void {
  5. let retcode = parseInt(err.status);
  6. if (retcode === 5001001 || retcode === 2000002 || retcode === 2000001) {
  7. toLogin();
  8. // Store.commit(types.LOGOUT);
  9. } else if (retcode === 5012004) {
  10. toLogin();
  11. // Store.commit(types.LOGOUT);
  12. } else if (retcode === 5001002) {
  13. toLogin();
  14. // Store.commit(types.LOGOUT);
  15. } else if (retcode >= 3001001 && retcode <= 3002000) {
  16. // window.location.href = '/'
  17. } else if (retcode >= 3002001 && retcode <= 3002999) {
  18. // window.location.href = '/user';
  19. }
  20. // uni.showModal({
  21. // content: err.msg,
  22. // confirmText: '知道了',
  23. // });
  24. setTimeout(() => {
  25. uni.showToast({ title: err.msg, duration: 2000, icon: 'none' });
  26. }, 100);
  27. };
  28. const toLogin = function(){
  29. Store.commit(`base/${types.LOGOUT}`);
  30. router.push({
  31. path: LOGIN_URL
  32. });
  33. }
  34. export default error_handle;