Skip to content

Commit

Permalink
feat(pages): migrate pages
Browse files Browse the repository at this point in the history
  • Loading branch information
mryanshenghong committed Jul 27, 2022
1 parent b676923 commit 3c38d52
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/LoginModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
</template>

<script setup lang="ts">
import { ComponentObjectPropsOptions, getCurrentInstance, reactive, ref, watch } from "vue";
import { getCurrentInstance, reactive, ref, watch } from "vue";
import { login, signup } from "../api/login";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
Expand Down
64 changes: 64 additions & 0 deletions src/pages/activate/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<template>
<div class="active">
{{ state.status }}
<i v-if="state.activating" class="el-icon-loading"></i>
<div>
<el-button class="btn" size="small" v-if="state.valid" @click="router.replace('/')"> 返回首页 </el-button>
</div>
</div>
</template>

<script setup lang="ts">
import { onBeforeMount, onMounted, reactive } from "vue";
import { activateAccount } from "@/api/login";
import { useRoute, useRouter } from "vue-router";
const router = useRouter();
const route = useRoute();
const requestId = route.params.id as string;
// State
const state = reactive({
status: "激活中...",
activating: true,
valid: false,
});
// Lifecycle
onBeforeMount(() => {
if (route.params.id) {
router.push("/");
}
});
onMounted(async () => await activateAccoutn());
// Methods
const activateAccoutn = async () => {
try {
const res: any = await activateAccount(requestId);
state.activating = false;
if (!res || res.code === -1) {
state.status = res.msg;
return;
}
state.status = "激活成功!回到首页登陆";
state.activating = false;
state.valid = true;
} catch (err) {
state.status = "网络错误, 请稍后再试.";
}
};
</script>
<style lang="scss" scoped>
.active {
margin-top: 20px;
display: flex;
justify-content: center;
align-items: center;
height: 600px;
.btn {
background: #f2f3f7;
}
}
</style>
30 changes: 30 additions & 0 deletions src/pages/notfound/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<template>
<div class="error">
<div class="title">404</div>
<div class="content">Not Found</div>
<el-button size="small" link @click="router.replace('/')"> 返回主页 </el-button>
</div>
</template>

<script setup lang="ts">
import { useRouter } from "vue-router";
const router = useRouter();
</script>
<style lang="scss" scoped>
.error {
display: flex;
height: 600px;
justify-content: center;
align-items: center;
flex-direction: column;
.title {
font-size: 40px;
margin-bottom: 10px;
}
.content {
font-size: 24px;
margin-bottom: 10px;
}
}
</style>
53 changes: 53 additions & 0 deletions src/pages/staging/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<template>
<div class="staging">
<div class="title">Hi, {{ name }}:</div>
<div class="content">
<p>感谢你注册About Life! 我们发送了激活邮件到你的邮箱: {{ email }}.</p>
<p>请前往你的邮箱激活账户, 激活账户就可以正常登陆About Life啦!</p>
</div>
<div class="footer">--- About Life</div>
</div>
</template>

<script setup lang="ts">
import { onBeforeMount } from "vue";
import { useRouter } from "vue-router";
const props = defineProps({
email: {
type: String,
required: true,
},
name: {
type: String,
required: true,
},
});
const router = useRouter();
onBeforeMount(() => {
if (!props.name || !props.email) {
router.push("/");
}
});
</script>
<style lang="scss" scoped>
.staging {
margin-top: 20px;
.title {
font-size: 18px;
text-align: left;
color: #d9d9d9;
}
.content {
margin-top: 10px;
p {
margin-top: 5px;
}
}
.footer {
text-align: right;
}
}
</style>
22 changes: 21 additions & 1 deletion src/router/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";
import Home from "@/pages/home/Home.vue";
import Staging from "@/pages/staging/index.vue";
const routes: Array<RouteRecordRaw> = [
{
path: "/",
name: "home",
name: "Home",
component: Home,
},
{
path: "/content/:id",
name: "Content",
component: () => import("@/pages/content/Content.vue"),
},
{
path: "/staging",
name: "Staging",
component: Staging,
props: true,
},
// {
// path: "/about",
// name: "about",
Expand All @@ -20,11 +27,24 @@ const routes: Array<RouteRecordRaw> = [
// component: () =>
// import(/* webpackChunkName: "about" */ "../views/AboutView.vue"),
// },
{
path: "/:pathMatch(.*)*",
name: "NotFound",
component: () => import("@/pages/notfound/index.vue"),
},
];

const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes,
});

router.beforeEach((to, from, next) => {
if (to.name === "Media" && localStorage.role !== "0") {
next({ name: "NotFound" });
} else {
next();
}
});

export default router;

0 comments on commit 3c38d52

Please sign in to comment.