add categories page
This commit is contained in:
1 parent
2bae7e0d0a
commit
8f0e1bd3b3
8 files changed
+202
-3
No files matched your search
@@ -12,5 +12,6 @@ export default {
|
||||
publishAt: '开始发布时间',
|
||||
updatedAt: '更新时间',
|
||||
article: '文章',
|
||||
course: '课程',
|
||||
minute: '分钟'
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
<template>
|
||||
<el-container>
|
||||
<el-header>
|
||||
<top-header />
|
||||
</el-header>
|
||||
<el-main> <router-view /> </el-main>
|
||||
<el-footer>
|
||||
<bottom-footer />
|
||||
</el-footer>
|
||||
</el-container>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { TopHeader } from '@/components/common/index';
|
||||
import BottomFooter from '@/components/common/BottomFooter.vue';
|
||||
export default {
|
||||
name: 'LayoutCategory',
|
||||
components: {
|
||||
TopHeader,
|
||||
BottomFooter
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
.el-header,
|
||||
.el-footer {
|
||||
padding: 0;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,104 @@
|
||||
<template>
|
||||
<el-row class="categories">
|
||||
<el-col :span="24">
|
||||
<el-row>
|
||||
<el-col :span="18" :offset="3">
|
||||
<el-row :gutter="20">
|
||||
<el-col v-for="(category, categoryIndex) in categories" :key="categoryIndex" :span="6">
|
||||
<div class="category" @click="onDetail(category.alias)">
|
||||
<div class="left">
|
||||
<img :src="category.logo" />
|
||||
</div>
|
||||
<div class="right">
|
||||
<h2 class="name">{{ category.name }}</h2>
|
||||
<p class="info">{{ category.courses?.length }} {{ $t('common.entity.course') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { categoryService } from '@/services/category/service';
|
||||
import { ICategory, ICategoryListResponse } from '@/services/category/types';
|
||||
import { defineComponent } from 'vue';
|
||||
|
||||
interface IData {
|
||||
categories: ICategory[];
|
||||
loading: boolean;
|
||||
}
|
||||
export default defineComponent({
|
||||
name: 'CategoryList',
|
||||
data(): IData {
|
||||
return {
|
||||
categories: [],
|
||||
loading: false
|
||||
};
|
||||
},
|
||||
async mounted() {
|
||||
this.loading = true;
|
||||
console.debug('start to load all categories');
|
||||
categoryService.getAll().then(({ data: data }: { data: ICategoryListResponse }) => {
|
||||
this.categories = data.items;
|
||||
this.loading = false;
|
||||
});
|
||||
},
|
||||
methods: {
|
||||
onDetail(alias?: string) {
|
||||
this.$router.push({
|
||||
name: 'course-list',
|
||||
query: {
|
||||
category: alias
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.categories {
|
||||
background-color: #0f1725;
|
||||
padding: 40px 0;
|
||||
.category {
|
||||
width: 100%;
|
||||
background-color: #13233c;
|
||||
height: 90px;
|
||||
color: white;
|
||||
border-radius: 10px;
|
||||
margin: 15px 0;
|
||||
border-width: 2px;
|
||||
border-style: solid;
|
||||
border-color: #13233c;
|
||||
cursor: pointer;
|
||||
.left,
|
||||
.right {
|
||||
float: left;
|
||||
}
|
||||
&:hover {
|
||||
border-color: rgba(50, 138, 241, 0.2);
|
||||
}
|
||||
|
||||
.left {
|
||||
width: 80px;
|
||||
img {
|
||||
width: 60px;
|
||||
margin: 10px;
|
||||
}
|
||||
margin-right: 10px;
|
||||
}
|
||||
.right {
|
||||
width: calc(100% - 90px);
|
||||
margin-top: 15px;
|
||||
.name {
|
||||
font-size: 20px;
|
||||
font-weight: bold;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,15 @@
|
||||
export default {
|
||||
path: '/categories',
|
||||
name: 'categories',
|
||||
meta: {
|
||||
auth: true
|
||||
},
|
||||
component: () => import('@/layouts/Category.vue'),
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
name: 'category-list',
|
||||
component: () => import('@/pages/category/List.vue')
|
||||
}
|
||||
]
|
||||
};
|
||||
+3
-2
@@ -1,6 +1,7 @@
|
||||
import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router';
|
||||
import auth from './auth';
|
||||
import course from './course';
|
||||
import category from './category';
|
||||
import episode from './episode';
|
||||
import store from '@/store';
|
||||
|
||||
@@ -12,7 +13,8 @@ const routes = [
|
||||
},
|
||||
auth,
|
||||
course,
|
||||
episode
|
||||
episode,
|
||||
category
|
||||
];
|
||||
|
||||
const router = createRouter({
|
||||
@@ -22,7 +24,6 @@ const router = createRouter({
|
||||
});
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
console.log(to);
|
||||
if (to.matched.some((record) => record.meta.auth)) {
|
||||
if (!store.getters.authenticated) {
|
||||
next({
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import { AxiosResponse } from 'axios';
|
||||
import httpClient from '../instance';
|
||||
import { ICategory, ICategoryDetailResponse, ICategoryListResponse } from './types';
|
||||
|
||||
class CategoryService {
|
||||
key = 'categories';
|
||||
|
||||
async getAll(): Promise<AxiosResponse<ICategoryListResponse>> {
|
||||
return await httpClient.get(`/${this.key}/`);
|
||||
}
|
||||
|
||||
async get(id: number): Promise<AxiosResponse<ICategoryDetailResponse>> {
|
||||
return await httpClient.get(`/${this.key}/${id}`);
|
||||
}
|
||||
|
||||
async create(data: ICategory): Promise<AxiosResponse<ICategoryDetailResponse>> {
|
||||
return await httpClient.post(`/${this.key}/`, data);
|
||||
}
|
||||
|
||||
async update(id: number, data: ICategory): Promise<AxiosResponse<ICategoryDetailResponse>> {
|
||||
return await httpClient.put(`/${this.key}/${id}`, data);
|
||||
}
|
||||
|
||||
async delete(id: number): Promise<AxiosResponse<null>> {
|
||||
return await httpClient.delete(`/${this.key}/${id}`);
|
||||
}
|
||||
}
|
||||
|
||||
export const categoryService = new CategoryService();
|
||||
@@ -0,0 +1,18 @@
|
||||
import { ICourse } from '../course/types';
|
||||
|
||||
export interface ICategory {
|
||||
id: number;
|
||||
name?: string;
|
||||
alias?: string;
|
||||
logo?: string;
|
||||
courses?: ICourse[];
|
||||
createdAt?: string;
|
||||
updatedAt?: string;
|
||||
}
|
||||
|
||||
export interface ICategoryListResponse {
|
||||
count: number;
|
||||
items: ICategory[];
|
||||
}
|
||||
|
||||
export type ICategoryDetailResponse = ICategory;
|
||||
+2
-1
@@ -12,7 +12,8 @@ export interface IState {
|
||||
const store = createStore({
|
||||
state(): IState {
|
||||
return {
|
||||
accessToken: undefined,
|
||||
accessToken:
|
||||
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNjUxOTI2OTk2LCJqdGkiOiJmM2RhOTFlYTM1MTU0Yzg4OGViM2U5MWMxNTY4ZmRhYSIsInVzZXJfaWQiOjQsInBlcm1pc3Npb25zIjpbInZpZXdfYWNhZGVteV9jb3Vyc2UiXSwiaXNfc3VwZXJ1c2VyIjpmYWxzZSwiaXNfdmVyaWZpZWQiOnRydWUsInJlYWxuYW1lIjoiXHU1ZDE0XHU1ZTg2XHU2MjRkIiwicGhvbmUiOiIxNzYwMDE1NTU2NyIsImlkY2FyZCI6IjM3MDc4MTE5OTQwNjI5MzI3MSJ9.SSGZtOwkKkIW2WD2CP0GljTWYLbpd9EiYJ89brtbOwQ',
|
||||
refreshToken: undefined,
|
||||
user: undefined
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user