NotFound.vue 1.87 KB
<script setup lang="ts">
import { useRouter } from "vue-router";

const router = useRouter();

const goHome = () => {
	// router.push("/home");
	console.log("goHome");
	
	// 检查 localStorage 中是否存在 token
	const TOKEN_KEY = "scrm_access_token";
	const token = localStorage.getItem(TOKEN_KEY);

	if (!token) {
		// 如果没有 token,跳转到登录页面
		// 登录页是基座应用的页面,直接使用绝对路径
		window.location.href = "/login";
	} else {
		// 有 token,跳转到首页
		router.push("/");
	}
};
</script>

<template>
    <div class="not-found-page">
        <div class="not-found-content">
            <div class="error-code">
                404
            </div>
            <h2 class="error-title">
                页面未找到
            </h2>
            <p class="error-desc">
                抱歉,您访问的页面不存在
            </p>
            <button class="back-button" @click="goHome">
                返回首页
            </button>
        </div>
    </div>
</template>

<style scoped>
.not-found-page {
	display: flex;
	align-items: center;
	justify-content: center;
	height: 100%;
	padding: 60px 20px;
	background: #fff;
}

.not-found-content {
	color: #383838;
	text-align: center;
}

.error-code {
	margin-bottom: 24px;
	font-size: 120px;
	font-weight: 700;
	line-height: 1;
	text-shadow: 0 4px 8px rgb(0 0 0 / 20%);
}

.error-title {
	margin-bottom: 16px;
	font-size: 32px;
	font-weight: 600;
}

.error-desc {
	margin-bottom: 32px;
	font-size: 16px;
	opacity: 0.9;
}

.back-button {
	padding: 12px 32px;
	font-size: 16px;
	font-weight: 500;
	color: #fff;
	cursor: pointer;
	background: #1956fe;
	border: none;
	border-radius: 24px;
	box-shadow: 0 4px 12px rgb(31 86 254 / 25%);
	transition: all 0.3s;
}

.back-button:hover {
	background: #1443d8;
	box-shadow: 0 6px 16px rgb(31 86 254 / 35%);
	transform: translateY(-2px);
}
</style>