bind.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. import VillageApi from "@/api/inhert/VillageApi";
  2. import { confirm } from "@/components/dialog/CommonRoot";
  3. import type { RequestApiError } from "@imengyu/imengyu-utils";
  4. export function checkIsNotVolunteerError(e: unknown) {
  5. return (e as RequestApiError).errorMessage.includes('请认领')
  6. }
  7. export async function checkAndGoBindVolunteer() {
  8. //检查是否有志愿者信息,跳转至不同的页面
  9. //已认领志愿者,跳转至首页
  10. //未认领志愿者,跳转至绑定账号页面
  11. try {
  12. await VillageApi.getVolunteerInfo();
  13. } catch(e) {
  14. //已登录但是没绑定志愿者信息,提示用户绑定
  15. if (checkIsNotVolunteerError(e)) {
  16. const goBind = await confirm({
  17. title: '提示',
  18. content: '欢迎进入平台,您的账号未绑定志愿者账号,目前不能提交信息,是否前往绑定?',
  19. confirmText: '前往绑定',
  20. cancelText: '先看看,稍后绑定',
  21. width: 580,
  22. });
  23. if (goBind) {
  24. uni.redirectTo({ url: '/pages/dig/sharereg/bind' });
  25. return true;
  26. }
  27. }
  28. throw e;
  29. }
  30. return false;
  31. }