Files
43ef7d02015c496186437118e05…/apps/child-coding-miniapp/src/App.vue
2026-01-05 06:44:05 +00:00

53 lines
1.6 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<script setup lang="ts">
import { onLaunch, onShow, onHide } from "@dcloudio/uni-app";
import { auth } from "@/lib/nvwa";
import { AUTH_REQUIRED } from "@/lib/config";
import redirectToLogin from "@/custom/redirect-to-login";
import { setupIframeHoverInspector, setupIframeSourceLocationListener } from "@nvwa-app/sdk-uniapp";
// 如果页面被嵌入 iframe设置跨域通信监听器
if (typeof window !== 'undefined') {
setupIframeHoverInspector();
setupIframeSourceLocationListener();
}
onLaunch(async () => {
console.log("App Launch");
// 如果需要认证,检查登录状态
if (AUTH_REQUIRED) {
try {
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
const currentRoute = currentPage?.route || "";
// 如果当前不在登录页或注册页,检查登录状态
if (!currentRoute.includes("user/login") && !currentRoute.includes("user/register")) {
const user = await auth.currentUser();
if (!user) {
// 未登录,重定向到登录页
await redirectToLogin();
}
}
} catch (error) {
// 获取用户信息失败,重定向到登录页
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
const currentRoute = currentPage?.route || "";
if (!currentRoute.includes("user/login") && !currentRoute.includes("user/register")) {
await redirectToLogin();
}
}
}
});
onShow(() => {
console.log("App Show");
});
onHide(() => {
console.log("App Hide");
});
</script>
<style>
@import './main.css';
</style>