add episode list

This commit is contained in:
AceDataCloud committed 2022-02-08 00:03:09 +08:00
1 parent 344fd73833
commit 36a338b631
15 files changed
+326 -47

No files matched your search

+2 -1
View File
@@ -9,5 +9,6 @@ export default {
cancel: '取消',
alert: '警告',
info: '提示',
publish: '发布'
publish: '发布',
watch: '观看'
};
+1 -1
View File
@@ -15,6 +15,6 @@ export default {
components: {
TopHeader
},
name: 'LayoutHome'
name: 'LayoutCourse'
};
</script>
+20
View File
@@ -0,0 +1,20 @@
<template>
<el-container>
<el-header>
<top-header />
</el-header>
<el-container>
<el-main> <router-view /> </el-main>
</el-container>
</el-container>
</template>
<script lang="ts">
import { TopHeader } from '@/components/common/index';
export default {
components: {
TopHeader
},
name: 'LayoutEpisode'
};
</script>
+62 -4
View File
@@ -9,7 +9,7 @@
<img :src="course.thumbnail" />
</div>
</el-col>
<el-col :span="10">
<el-col :span="18">
<div class="title mb-5">
<p>{{ course.title }}</p>
</div>
@@ -17,7 +17,6 @@
<p>{{ course.introduction }}</p>
</div>
</el-col>
<el-col :span="8"> </el-col>
</el-row>
</div>
</div>
@@ -28,23 +27,59 @@
<div class="banner"></div>
</el-col>
</el-row>
<el-row class="episodes">
<el-col :span="14" :offset="5">
<el-card shadow="hover" v-for="(episode, episodeIndex) in episodes" class="episode">
<el-row>
<el-col :span="3"> {{ episodeIndex + 1 }}</el-col>
<el-col :span="21">
<div class="title">
<p>{{ episode.title }}</p>
</div>
<div class="introduction">
<p>{{ episode.introduction }}</p>
</div>
<div class="introduction">
<router-link
:to="{
name: 'episode-detail',
params: {
courseId: course?.id,
id: episode.id
}
}"
>
<el-button>{{ $t('common.button.watch') }}</el-button>
</router-link>
</div>
</el-col>
</el-row>
</el-card>
</el-col>
</el-row>
</template>
<script lang="ts">
import { courseService } from '@/services/course/service';
import { ICourse, ICourseDetailResponse } from '@/services/course/types';
import { episodeService } from '@/services/episode/service';
import { IEpisode, IEpisodeListResponse } from '@/services/episode/types';
import { defineComponent } from 'vue';
interface IData {
course: ICourse | undefined;
episodes: IEpisode[] | undefined;
loading: boolean;
id: number;
}
export default defineComponent({
name: 'CourseList',
name: 'CourseDetail',
data(): IData {
return {
id: parseInt(this.$route.params.id.toString()),
course: undefined,
episodes: [],
loading: false
};
},
@@ -54,6 +89,9 @@ export default defineComponent({
this.loading = false;
this.course = data;
});
episodeService.getAllForCourse(this.id).then(({ data: data }: { data: IEpisodeListResponse }) => {
this.episodes = data.items;
});
}
});
</script>
@@ -61,7 +99,7 @@ export default defineComponent({
<style lang="scss" scoped>
.wrapper {
width: 100%;
height: 500px;
height: 400px;
background-image: radial-gradient(circle at 0 2%, #283e63, #172337 99%);
.container {
width: 1200px;
@@ -104,4 +142,24 @@ export default defineComponent({
width: 100%;
height: 55px;
}
.episodes {
.episode {
margin-top: 2rem;
height: 160px;
border-radius: 0.934rem !important;
.title {
p {
font-size: 1.5rem;
font-weight: bold;
}
}
.introduction {
p {
font-size: 0.8rem;
color: rgb(161, 161, 161);
}
}
}
}
</style>
+158
View File
@@ -0,0 +1,158 @@
<template>
<el-row>
<el-col :span="24">
<div class="wrapper">
<div class="container">
<el-row v-if="episode">
<el-col :span="6"
><div class="thumbnail">
<img :src="episode.thumbnail" />
</div>
</el-col>
<el-col :span="18">
<div class="title mb-5">
<p>{{ episode.title }}</p>
</div>
<div class="introduction mb-5">
<p>{{ episode.introduction }}</p>
</div>
</el-col>
</el-row>
</div>
</div>
</el-col>
</el-row>
<el-row>
<el-col :span="24">
<div class="banner"></div>
</el-col>
</el-row>
<el-row class="episodes">
<el-col :span="14" :offset="5">
<el-card shadow="hover" v-for="(episode, episodeIndex) in episodes" class="episode">
<el-row>
<el-col :span="3"> {{ episodeIndex + 1 }}</el-col>
<el-col :span="21">
<div class="title">
<p>{{ episode.title }}</p>
</div>
<div class="introduction">
<p>{{ episode.introduction }}</p>
</div>
<div class="introduction">
<router-link
:to="{
name: 'eposide-detail',
params: {
episodeId: episode?.id,
id: episode.id
}
}"
>
<el-button>{{ $t('common.button.watch') }}</el-button>
</router-link>
</div>
</el-col>
</el-row>
</el-card>
</el-col>
</el-row>
</template>
<script lang="ts">
import { episodeService } from '@/services/episode/service';
import { IEpisode, IEpisodeDetailResponse } from '@/services/episode/types';
import { defineComponent } from 'vue';
interface IData {
episode: IEpisode | undefined;
loading: boolean;
id: number;
}
export default defineComponent({
name: 'EpisodeDetail',
data(): IData {
return {
id: parseInt(this.$route.params.id.toString()),
episode: undefined,
loading: false
};
},
async mounted() {
this.loading = true;
episodeService.get(this.id).then(({ data: data }: { data: IEpisodeDetailResponse }) => {
this.loading = false;
this.episode = data;
});
}
});
</script>
<style lang="scss" scoped>
.wrapper {
width: 100%;
height: 400px;
background-image: radial-gradient(circle at 0 2%, #283e63, #172337 99%);
.container {
width: 1200px;
margin: auto;
padding-top: 50px;
.title {
p {
font-weight: bold;
color: white;
font-size: 2.4rem;
}
}
.introduction {
p {
color: white;
font-size: 1rem;
}
}
.thumbnail {
text-align: center;
img {
pointer-events: none;
width: 200px;
height: 200px;
margin-top: 50px;
margin-left: auto;
margin-right: auto;
}
}
}
}
.banner {
border-bottom-left-radius: 28px;
border-bottom-right-radius: 28px;
background: linear-gradient(270deg, #f44881, #ec454f);
margin-left: auto;
margin-right: auto;
width: 100%;
height: 55px;
}
.episodes {
.episode {
margin-top: 2rem;
height: 160px;
border-radius: 0.934rem !important;
.title {
p {
font-size: 1.5rem;
font-weight: bold;
}
}
.introduction {
p {
font-size: 0.8rem;
color: rgb(161, 161, 161);
}
}
}
}
</style>
+15
View File
@@ -0,0 +1,15 @@
export default {
path: '/courses/:courseId/episodes/',
name: 'episodes',
meta: {
auth: true
},
component: () => import('@/layouts/Episode.vue'),
children: [
{
path: ':id',
name: 'episode-detail',
component: () => import('@/pages/episode/Detail.vue')
}
]
};
+3 -1
View File
@@ -1,6 +1,7 @@
import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router';
import auth from './auth';
import course from './course';
import episode from './episode';
import store from '@/store';
const routes = [
@@ -10,7 +11,8 @@ const routes = [
redirect: '/courses'
},
auth,
course
course,
episode
];
const router = createRouter({
-21
View File
@@ -1,21 +0,0 @@
import { AxiosResponse } from 'axios';
import httpClient from '../../instance';
import { IWechatQRCodeResponse, IWechatLoginStatusResponse } from './types';
class WechatService {
key = 'wechat';
async createQRCode4Login(): Promise<AxiosResponse<IWechatQRCodeResponse>> {
return await httpClient.post(`/${this.key}/qrcode`, {
scene: 'login'
});
}
async getLoginStatus(ticket: string): Promise<AxiosResponse<IWechatLoginStatusResponse>> {
return httpClient.post(`/${this.key}/authenticate`, {
ticket: ticket
});
}
}
export default new WechatService();
-14
View File
@@ -1,14 +0,0 @@
import { IUser } from '../user/types';
export interface IWechatQRCode {
ticket: string;
url: string;
}
export interface IWechatQRCodeResponse extends IWechatQRCode {}
export interface IWechatLoginStatusResponse {
refreshToken: string;
accessToken: string;
user: IUser;
}
+37
View File
@@ -0,0 +1,37 @@
import { AxiosResponse } from 'axios';
import httpClient from '../instance';
import { IEpisode, IEpisodeDetailResponse, IEpisodeListResponse } from './types';
class EpisodeService {
key = 'episodes';
async getAll(): Promise<AxiosResponse<IEpisodeListResponse>> {
return await httpClient.get(`/${this.key}/`);
}
async get(id: number): Promise<AxiosResponse<IEpisodeDetailResponse>> {
return await httpClient.get(`/${this.key}/${id}`);
}
async create(data: IEpisode): Promise<AxiosResponse<IEpisodeDetailResponse>> {
return await httpClient.post(`/${this.key}/`, data);
}
async update(id: number, data: IEpisode): Promise<AxiosResponse<IEpisodeDetailResponse>> {
return await httpClient.put(`/${this.key}/${id}`, data);
}
async delete(id: number): Promise<AxiosResponse<null>> {
return await httpClient.delete(`/${this.key}/${id}`);
}
async createForCourse(courseId: number, data: IEpisode): Promise<AxiosResponse<IEpisodeDetailResponse>> {
return await httpClient.post(`/courses/${courseId}/${this.key}/`, data);
}
async getAllForCourse(courseId: number): Promise<AxiosResponse<IEpisodeListResponse>> {
return await httpClient.get(`/courses/${courseId}/${this.key}/`);
}
}
export const episodeService = new EpisodeService();
+25
View File
@@ -0,0 +1,25 @@
export interface IEpisode {
id: number;
tags?: string[];
title?: string;
cover?: string;
thumbnail?: string;
duration?: number;
introduction?: string;
state?: 'Pending' | 'Running' | 'Ready';
type?: 'Video' | 'Document';
isFree?: boolean;
index?: number;
viewCount?: number;
resourceUrl?: string;
createdAt?: string;
updatedAt?: string;
publisherId?: number;
}
export interface IEpisodeListResponse {
count: number;
items: IEpisode[];
}
export type IEpisodeDetailResponse = IEpisode;
-2
View File
@@ -13,7 +13,6 @@ const httpClient: AxiosInstance = axios.create({
httpClient.interceptors.request.use((config) => {
const accessToken = store.getters.accessToken;
console.log('accesstoken', accessToken);
if (accessToken) {
config.headers['Authorization'] = `Bearer ${accessToken}`;
}
@@ -31,7 +30,6 @@ httpClient.interceptors.response.use(
return response;
},
(error) => {
console.log('error', error);
if (error.response.status === 401) {
store.dispatch('resetAuth');
router.push('/');
@@ -1,5 +1,5 @@
import { AxiosResponse } from 'axios';
import httpClient from '../../instance';
import httpClient from '../instance';
import { IUserDetailResponse, IUser } from './types';
class UserService {
File renamed without changes.
+2 -2
View File
@@ -1,5 +1,5 @@
import { createStore, ActionContext } from 'vuex';
import { IUser } from '@/services/common/user/types';
import { IUser } from '@/services/user/types';
import createPersistedState from 'vuex-persistedstate';
export interface IState {
@@ -12,7 +12,7 @@ const store = createStore({
state(): IState {
return {
accessToken:
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNjQ0MTk0ODIwLCJqdGkiOiIwMmVjMjRkMDQ0ZDU0NGI0OTcwNzdiMTM3MWNjYTM2OCIsInVzZXJfaWQiOjMsInBlcm1pc3Npb25zIjpbInZpZXdfYWNhZGVteV9jb3Vyc2UiXSwiaXNfc3VwZXJ1c2VyIjpmYWxzZX0.4dqI9QGplnPn2LqPDpJcKzlDlX6wzUibA1GHi8rNXts',
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNjQ0MjczMTExLCJqdGkiOiJiZDZjZWFlYTAwMDA0NDU2YmIwMWQ1MmYzYTI0YTA2NiIsInVzZXJfaWQiOjMsInBlcm1pc3Npb25zIjpbInZpZXdfYWNhZGVteV9jb3Vyc2UiXSwiaXNfc3VwZXJ1c2VyIjpmYWxzZX0.Eq_tlW9y4fJp_zNfBaCPUlUfEY96pvMHYVrcfSDPsk8',
refreshToken: undefined,
user: undefined
};