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>
<el-row v-for="(episode, episodeIndex) in episodes" class="item">
<el-col :span="6" class="left">
<span class="index">
{{ episodeIndex }}
</span>
</el-col>
<el-col :span="18" class="right">
<p class="title">
{{ episode?.title }}
</p>
<p class="info">
<span class="duration">
<el-icon class="icon">
<clock />
</el-icon>
{{ episode.duration }}
<div class="wrapper">
<el-row
v-for="(episode, episodeIndex) in episodes"
@click="onClick(episode)"
:class="{ item: true, active: episode.id === active }"
>
<el-col :span="6" class="left">
<span class="index">
{{ episodeIndex + 1 }}
</span>
</p>
</el-col>
</el-row>
</el-col>
<el-col :span="18" class="right">
<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>
<script lang="ts">
@@ -37,45 +43,67 @@ export default defineComponent({
default() {
return [];
}
},
active: {
type: Number,
required: true
}
},
mounted() {},
methods: {}
methods: {
onClick(episode: IEpisode) {
this.$emit('choose', episode);
}
}
});
</script>
<style lang="scss">
.item {
height: 60px;
padding-top: 10px;
color: white;
.left {
width: 30px;
color: inherit;
.index {
display: block;
.wrapper {
padding: 0 10px;
.item {
cursor: pointer;
border-radius: 0.934rem;
width: 100%;
height: 60px;
padding-top: 10px;
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;
height: 30px;
text-align: center;
margin: auto;
border-radius: 50%;
font-size: 0.6em;
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 {
color: inherit;
.index {
display: block;
width: 30px;
height: 30px;
text-align: center;
margin: auto;
border-radius: 50%;
font-size: 0.6em;
.icon {
display: inline-block;
margin-top: 5px;
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;
episodes: IEpisode[] | undefined;
loading: boolean;
id: number;
}
export default defineComponent({
name: 'CourseDetail',
data(): IData {
return {
id: parseInt(this.$route.params.id.toString()),
course: undefined,
episodes: [],
loading: false
};
},
computed: {
id() {
return parseInt(this.$route.params.id.toString());
}
},
async mounted() {
this.loading = true;
courseService.get(this.id).then(({ data: data }: { data: ICourseDetailResponse }) => {
+2
View File
@@ -41,6 +41,7 @@
import { courseService } from '@/services/course/service';
import { ICourse, ICourseListResponse } from '@/services/course/types';
import { defineComponent } from 'vue';
interface IData {
courses: ICourse[];
loading: boolean;
@@ -55,6 +56,7 @@ export default defineComponent({
},
async mounted() {
this.loading = true;
console.debug('start to load all courses');
courseService.getAll().then(({ data: data }: { data: ICourseListResponse }) => {
this.courses = data.items;
this.loading = false;
+37 -6
View File
@@ -3,7 +3,8 @@
<el-col :span="6" class="side">
<el-row>
<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-row>
</el-col>
@@ -19,30 +20,42 @@ import { IEpisode, IEpisodeDetailResponse, IEpisodeListResponse } from '@/servic
import { defineComponent } from 'vue';
import EpisodeSideList from '@/components/episode/SideList.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 {
course: ICourse | undefined;
episode: IEpisode | undefined;
episodes: IEpisode[];
loading: boolean;
id: number;
courseId: number;
// id: number;
// courseId: number;
}
export default defineComponent({
name: 'EpisodeDetail',
components: {
EpisodeSideList,
EpisodePlayer
EpisodePlayer,
CoursePreviewCard
},
data(): IData {
return {
id: parseInt(this.$route.params.id.toString()),
courseId: parseInt(this.$route.params.courseId.toString()),
course: undefined,
episode: undefined,
loading: false,
episodes: []
};
},
computed: {
id() {
return parseInt(this.$route.params.id.toString());
},
courseId() {
return parseInt(this.$route.params.courseId.toString());
}
},
async mounted() {
this.loading = true;
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 }) => {
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>
+3 -2
View File
@@ -16,12 +16,13 @@ const routes = [
];
const router = createRouter({
history: createWebHistory(),
// history: createWebHashHistory(),
// history: createWebHistory(),
history: createWebHashHistory(),
routes
});
router.beforeEach((to, from, next) => {
console.log(to);
if (to.matched.some((record) => record.meta.auth)) {
if (!store.getters.authenticated) {
next({
+1 -1
View File
@@ -12,7 +12,7 @@ const store = createStore({
state(): IState {
return {
accessToken:
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNjQ1MzcyNDgzLCJqdGkiOiIyYWFiNDRiOTdjMGE0NDg3OWZiYzI3MTZiYWM2YWY2YyIsInVzZXJfaWQiOjMsInBlcm1pc3Npb25zIjpbInZpZXdfYWNhZGVteV9jb3Vyc2UiXSwiaXNfc3VwZXJ1c2VyIjpmYWxzZX0.LWCZPAHB7Ask-FU_aZUTpCazN08KxBsbTLOsHakhpAY',
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNjQ4ODUxMDc2LCJqdGkiOiI0ZGZkMjEzMzNmODY0MTEzYTRjZWZmMzI5NzAyMWFiZiIsInVzZXJfaWQiOjMsInBlcm1pc3Npb25zIjpbInZpZXdfYWNhZGVteV9jb3Vyc2UiXSwiaXNfc3VwZXJ1c2VyIjpmYWxzZX0.ZVEeeU-vZBGSQf4s-RJhnNItZHUmSw0MnsDp4Bgh9RI',
refreshToken: undefined,
user: undefined
};