update sidebar and episode router

This commit is contained in:
AceDataCloud committed 2022-04-02 00:17:17 +08:00
1 parent f418ed47da
commit 1eb713aaf4
7 files changed
+174 -60

No files matched your search

+49
View File
@@ -0,0 +1,49 @@
<template>
<div class="card">
<div class="left">
<img :src="course.thumbnail" class="thumbnail" />
</div>
<div class="right">
<h2>{{ course.title }}</h2>
</div>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { ICourse } from '@/services/course/types';
export default defineComponent({
name: 'CoursePreviewCard',
props: {
course: {
type: Object as () => ICourse,
required: true
}
}
});
</script>
<style lang="scss" scoped>
.card {
width: 100%;
padding: 10px 30px;
height: 84px;
overflow: hidden;
.left {
width: 100px;
float: left;
.thumbnail {
text-align: center;
width: 64px;
height: 64px;
}
}
.right {
padding: 10px 0;
color: white;
float: left;
width: calc(100% - 100px);
}
}
</style>
+77 -49
View File
@@ -1,24 +1,30 @@
<template> <template>
<el-row v-for="(episode, episodeIndex) in episodes" class="item"> <div class="wrapper">
<el-col :span="6" class="left"> <el-row
<span class="index"> v-for="(episode, episodeIndex) in episodes"
{{ episodeIndex }} @click="onClick(episode)"
</span> :class="{ item: true, active: episode.id === active }"
</el-col> >
<el-col :span="18" class="right"> <el-col :span="6" class="left">
<p class="title"> <span class="index">
{{ episode?.title }} {{ episodeIndex + 1 }}
</p>
<p class="info">
<span class="duration">
<el-icon class="icon">
<clock />
</el-icon>
{{ episode.duration }}
</span> </span>
</p> </el-col>
</el-col> <el-col :span="18" class="right">
</el-row> <p class="title">
{{ episode?.title }}
</p>
<p class="info">
<span class="duration">
<el-icon class="icon">
<clock />
</el-icon>
{{ episode.duration }}
</span>
</p>
</el-col>
</el-row>
</div>
</template> </template>
<script lang="ts"> <script lang="ts">
@@ -37,45 +43,67 @@ export default defineComponent({
default() { default() {
return []; return [];
} }
},
active: {
type: Number,
required: true
} }
}, },
mounted() {}, mounted() {},
methods: {} methods: {
onClick(episode: IEpisode) {
this.$emit('choose', episode);
}
}
}); });
</script> </script>
<style lang="scss"> <style lang="scss">
.item { .wrapper {
height: 60px; padding: 0 10px;
padding-top: 10px; .item {
color: white; cursor: pointer;
.left { border-radius: 0.934rem;
width: 30px; width: 100%;
color: inherit; height: 60px;
.index { padding-top: 10px;
display: block; color: white;
margin: 10px 0;
border: 1px solid #0d131d;
&.active,
&:hover {
background-color: rgba(50, 138, 241, 0.05);
border: 1px solid rgba(50, 138, 241, 0.25);
}
.left {
width: 30px; width: 30px;
height: 30px; color: inherit;
text-align: center; .index {
margin: auto; display: block;
border-radius: 50%; width: 30px;
font-size: 0.6em; height: 30px;
line-height: 30px; text-align: center;
background-image: linear-gradient(rgb(244, 72, 129), rgb(236, 69, 79)); margin: auto;
} border-radius: 50%;
}
.right {
width: calc(100% - 30px);
.title {
color: white;
font-size: 0.8em;
text-align: left;
}
.info {
.duration {
font-size: 0.6em; font-size: 0.6em;
.icon { margin-top: 5px;
display: inline-block; line-height: 30px;
background-image: linear-gradient(rgb(244, 72, 129), rgb(236, 69, 79));
}
}
.right {
width: calc(100% - 30px);
.title {
color: white;
font-size: 0.8em;
text-align: left;
}
.info {
.duration {
font-size: 0.6em;
.icon {
display: inline-block;
}
} }
} }
} }
+5 -2
View File
@@ -70,19 +70,22 @@ interface IData {
course: ICourse | undefined; course: ICourse | undefined;
episodes: IEpisode[] | undefined; episodes: IEpisode[] | undefined;
loading: boolean; loading: boolean;
id: number;
} }
export default defineComponent({ export default defineComponent({
name: 'CourseDetail', name: 'CourseDetail',
data(): IData { data(): IData {
return { return {
id: parseInt(this.$route.params.id.toString()),
course: undefined, course: undefined,
episodes: [], episodes: [],
loading: false loading: false
}; };
}, },
computed: {
id() {
return parseInt(this.$route.params.id.toString());
}
},
async mounted() { async mounted() {
this.loading = true; this.loading = true;
courseService.get(this.id).then(({ data: data }: { data: ICourseDetailResponse }) => { courseService.get(this.id).then(({ data: data }: { data: ICourseDetailResponse }) => {
+2
View File
@@ -41,6 +41,7 @@
import { courseService } from '@/services/course/service'; import { courseService } from '@/services/course/service';
import { ICourse, ICourseListResponse } from '@/services/course/types'; import { ICourse, ICourseListResponse } from '@/services/course/types';
import { defineComponent } from 'vue'; import { defineComponent } from 'vue';
interface IData { interface IData {
courses: ICourse[]; courses: ICourse[];
loading: boolean; loading: boolean;
@@ -55,6 +56,7 @@ export default defineComponent({
}, },
async mounted() { async mounted() {
this.loading = true; this.loading = true;
console.debug('start to load all courses');
courseService.getAll().then(({ data: data }: { data: ICourseListResponse }) => { courseService.getAll().then(({ data: data }: { data: ICourseListResponse }) => {
this.courses = data.items; this.courses = data.items;
this.loading = false; this.loading = false;
+37 -6
View File
@@ -3,7 +3,8 @@
<el-col :span="6" class="side"> <el-col :span="6" class="side">
<el-row> <el-row>
<el-col :span="24"> <el-col :span="24">
<episode-side-list :episodes="episodes"></episode-side-list> <course-preview-card :course="course" v-if="course" />
<episode-side-list :episodes="episodes" :active="id" @choose="onChoose($event)" />
</el-col> </el-col>
</el-row> </el-row>
</el-col> </el-col>
@@ -19,30 +20,42 @@ import { IEpisode, IEpisodeDetailResponse, IEpisodeListResponse } from '@/servic
import { defineComponent } from 'vue'; import { defineComponent } from 'vue';
import EpisodeSideList from '@/components/episode/SideList.vue'; import EpisodeSideList from '@/components/episode/SideList.vue';
import EpisodePlayer from '@/components/episode/Player.vue'; import EpisodePlayer from '@/components/episode/Player.vue';
import CoursePreviewCard from '@/components/course/PreviewCard.vue';
import { courseService } from '@/services/course/service';
import { ICourse, ICourseDetailResponse } from '@/services/course/types';
interface IData { interface IData {
course: ICourse | undefined;
episode: IEpisode | undefined; episode: IEpisode | undefined;
episodes: IEpisode[]; episodes: IEpisode[];
loading: boolean; loading: boolean;
id: number; // id: number;
courseId: number; // courseId: number;
} }
export default defineComponent({ export default defineComponent({
name: 'EpisodeDetail', name: 'EpisodeDetail',
components: { components: {
EpisodeSideList, EpisodeSideList,
EpisodePlayer EpisodePlayer,
CoursePreviewCard
}, },
data(): IData { data(): IData {
return { return {
id: parseInt(this.$route.params.id.toString()), course: undefined,
courseId: parseInt(this.$route.params.courseId.toString()),
episode: undefined, episode: undefined,
loading: false, loading: false,
episodes: [] episodes: []
}; };
}, },
computed: {
id() {
return parseInt(this.$route.params.id.toString());
},
courseId() {
return parseInt(this.$route.params.courseId.toString());
}
},
async mounted() { async mounted() {
this.loading = true; this.loading = true;
episodeService.get(this.id).then(({ data: data }: { data: IEpisodeDetailResponse }) => { episodeService.get(this.id).then(({ data: data }: { data: IEpisodeDetailResponse }) => {
@@ -52,6 +65,24 @@ export default defineComponent({
episodeService.getAllForCourse(this.courseId).then(({ data: data }: { data: IEpisodeListResponse }) => { episodeService.getAllForCourse(this.courseId).then(({ data: data }: { data: IEpisodeListResponse }) => {
this.episodes = data.items; this.episodes = data.items;
}); });
courseService.get(this.courseId).then(({ data: data }: { data: ICourseDetailResponse }) => {
this.course = data;
});
},
methods: {
onChoose(episode: IEpisode) {
console.log('e', episode);
this.$router.push({
...this.$route,
params: {
id: episode.id,
courseId: this.courseId
}
});
episodeService.get(this.id).then(({ data: data }: { data: IEpisodeDetailResponse }) => {
this.episode = data;
});
}
} }
}); });
</script> </script>
+3 -2
View File
@@ -16,12 +16,13 @@ const routes = [
]; ];
const router = createRouter({ const router = createRouter({
history: createWebHistory(), // history: createWebHistory(),
// history: createWebHashHistory(), history: createWebHashHistory(),
routes routes
}); });
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
console.log(to);
if (to.matched.some((record) => record.meta.auth)) { if (to.matched.some((record) => record.meta.auth)) {
if (!store.getters.authenticated) { if (!store.getters.authenticated) {
next({ next({
+1 -1
View File
@@ -12,7 +12,7 @@ const store = createStore({
state(): IState { state(): IState {
return { return {
accessToken: accessToken:
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNjQ1MzcyNDgzLCJqdGkiOiIyYWFiNDRiOTdjMGE0NDg3OWZiYzI3MTZiYWM2YWY2YyIsInVzZXJfaWQiOjMsInBlcm1pc3Npb25zIjpbInZpZXdfYWNhZGVteV9jb3Vyc2UiXSwiaXNfc3VwZXJ1c2VyIjpmYWxzZX0.LWCZPAHB7Ask-FU_aZUTpCazN08KxBsbTLOsHakhpAY', 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNjQ4ODUxMDc2LCJqdGkiOiI0ZGZkMjEzMzNmODY0MTEzYTRjZWZmMzI5NzAyMWFiZiIsInVzZXJfaWQiOjMsInBlcm1pc3Npb25zIjpbInZpZXdfYWNhZGVteV9jb3Vyc2UiXSwiaXNfc3VwZXJ1c2VyIjpmYWxzZX0.ZVEeeU-vZBGSQf4s-RJhnNItZHUmSw0MnsDp4Bgh9RI',
refreshToken: undefined, refreshToken: undefined,
user: undefined user: undefined
}; };