RequireLogin.ts 618 B

1234567891011121314151617181920212223242526
  1. import { useAuthStore } from "@/store/auth";
  2. import { confirm } from "../utils/DialogAction";
  3. import { navTo } from "../utils/PageAction";
  4. export function useReqireLogin() {
  5. const authStore = useAuthStore();
  6. return {
  7. requireLogin(cb: () => void, message: string = '登录后查看') {
  8. if (!authStore.isLogged) {
  9. confirm({
  10. title: '提示',
  11. content: message,
  12. confirmText: '去登录'
  13. }).then((res) => {
  14. if (res) {
  15. navTo('/pages/user/login');
  16. return;
  17. }
  18. })
  19. } else {
  20. cb();
  21. }
  22. }
  23. }
  24. }