import { confirm } from "@/components/utils/DialogAction"; import { navTo } from "@/components/utils/PageAction"; import { useAuthStore } from "@/store/auth"; /** * 说明: * * 登录校验组合式代码。 */ export function useReqireLogin() { const authStore = useAuthStore(); return { /** * 校验登录状态 * @param cb 登录成功回调 * @param message 登录提示信息 */ requireLogin(cb: () => void, message: string = '登录后查看') { if (!authStore.isLogged) { confirm({ title: '提示', content: message, confirmText: '去登录' }).then((res) => { if (res) { navTo('/pages/user/login'); return; } }) } else { cb(); } } } }