import { Router } from "vue-router";
import store from "@/store";
import dayjs from "dayjs";
import { Toast } from "vant";
const guard = (router: Router) => {
  router.beforeEach(async (to, from, next) => {
    const userTime = dayjs(store.getters.getUserData.expireTime).valueOf();
    const currentTime = dayjs().valueOf();
    switch (to.path) {
      case "/exercise":
        if (userTime - currentTime > 0) {
          next();
        } else {
          Toast.fail("会员到期");
        }
        break;
      case "/mockTest":
        if (userTime - currentTime > 0) {
          next();
        } else {
          Toast.fail("会员到期");
        }
        break;
      default:
        next();
        break;
    }
  });
};
export default guard;
