add order page
This commit is contained in:
1 parent
d237e201e8
commit
19facac317
10 files changed
+311
-2
No files matched your search
@@ -9,6 +9,7 @@
|
|||||||
"prettier": "npx prettier --write ."
|
"prettier": "npx prettier --write ."
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@types/uuid": "^8.3.4",
|
||||||
"axios": "^0.21.1",
|
"axios": "^0.21.1",
|
||||||
"dayjs": "^1.10.7",
|
"dayjs": "^1.10.7",
|
||||||
"element-plus": "^1.3.0-beta.10",
|
"element-plus": "^1.3.0-beta.10",
|
||||||
@@ -16,6 +17,7 @@
|
|||||||
"humps": "^2.0.1",
|
"humps": "^2.0.1",
|
||||||
"qrcode.vue": "3.3.0",
|
"qrcode.vue": "3.3.0",
|
||||||
"typescript-cookie": "^1.0.3",
|
"typescript-cookie": "^1.0.3",
|
||||||
|
"uuid": "^8.3.2",
|
||||||
"vue": "^3.2.6",
|
"vue": "^3.2.6",
|
||||||
"vue-i18n": "^9.1.7",
|
"vue-i18n": "^9.1.7",
|
||||||
"vue-plyr": "^7.0.0",
|
"vue-plyr": "^7.0.0",
|
||||||
|
|||||||
@@ -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: 'LayoutOrder',
|
||||||
|
components: {
|
||||||
|
TopHeader,
|
||||||
|
BottomFooter
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
.el-header,
|
||||||
|
.el-footer {
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -83,12 +83,16 @@ import { courseService } from '@/services/course/service';
|
|||||||
import { ICourse, ICourseDetailResponse } from '@/services/course/types';
|
import { ICourse, ICourseDetailResponse } from '@/services/course/types';
|
||||||
import { episodeService } from '@/services/episode/service';
|
import { episodeService } from '@/services/episode/service';
|
||||||
import { IEpisode, IEpisodeListResponse } from '@/services/episode/types';
|
import { IEpisode, IEpisodeListResponse } from '@/services/episode/types';
|
||||||
|
import { orderService } from '@/services/order/service';
|
||||||
import { defineComponent } from 'vue';
|
import { defineComponent } from 'vue';
|
||||||
import { Clock } from '@element-plus/icons-vue';
|
import { Clock } from '@element-plus/icons-vue';
|
||||||
import VerificationAlert from '@/components/common/VerificationAlert.vue';
|
import VerificationAlert from '@/components/common/VerificationAlert.vue';
|
||||||
|
import { IOrder, IOrderDetailResponse } from '@/services/order/types';
|
||||||
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
|
|
||||||
interface IData {
|
interface IData {
|
||||||
course: ICourse | undefined;
|
course: ICourse | undefined;
|
||||||
|
order: IOrder | undefined;
|
||||||
episodes: IEpisode[] | undefined;
|
episodes: IEpisode[] | undefined;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
}
|
}
|
||||||
@@ -102,6 +106,7 @@ export default defineComponent({
|
|||||||
data(): IData {
|
data(): IData {
|
||||||
return {
|
return {
|
||||||
course: undefined,
|
course: undefined,
|
||||||
|
order: undefined,
|
||||||
episodes: [],
|
episodes: [],
|
||||||
loading: false
|
loading: false
|
||||||
};
|
};
|
||||||
@@ -126,7 +131,21 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
onBuy() {
|
onBuy() {
|
||||||
// courseService.buy(this.id)
|
orderService
|
||||||
|
.create({
|
||||||
|
id: uuidv4(),
|
||||||
|
courses: [this.id]
|
||||||
|
})
|
||||||
|
.then(({ data: data }: { data: IOrderDetailResponse }) => {
|
||||||
|
this.loading = false;
|
||||||
|
this.order = data;
|
||||||
|
this.$router.push({
|
||||||
|
name: 'order-detail',
|
||||||
|
params: {
|
||||||
|
id: this.order.id
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,178 @@
|
|||||||
|
<template>
|
||||||
|
<el-row>
|
||||||
|
<el-col :span="24">
|
||||||
|
<div class="wrapper">
|
||||||
|
<div class="container">
|
||||||
|
<el-row v-if="order">
|
||||||
|
<el-col :span="24">
|
||||||
|
<div class="courses">
|
||||||
|
<div v-for="(course, courseIndex) in courses" :key="courseIndex">
|
||||||
|
<div class="title">
|
||||||
|
{{ course.title }}
|
||||||
|
</div>
|
||||||
|
<div class="price">
|
||||||
|
{{ course.price }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</el-col>
|
||||||
|
</el-row>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</el-col>
|
||||||
|
</el-row>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts">
|
||||||
|
import { ICourse, ICourseDetailResponse } from '@/services/course/types';
|
||||||
|
import { orderService } from '@/services/order/service';
|
||||||
|
import { courseService } from '@/services/course/service';
|
||||||
|
import { IOrder, IOrderDetailResponse } from '@/services/order/types';
|
||||||
|
import { defineComponent } from 'vue';
|
||||||
|
|
||||||
|
interface IData {
|
||||||
|
order: IOrder | undefined;
|
||||||
|
courses: ICourse[] | undefined;
|
||||||
|
loading: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default defineComponent({
|
||||||
|
name: 'OrderDetail',
|
||||||
|
components: {},
|
||||||
|
data(): IData {
|
||||||
|
return {
|
||||||
|
order: undefined,
|
||||||
|
courses: [],
|
||||||
|
loading: false
|
||||||
|
};
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
verified() {
|
||||||
|
return this.$store.getters.user.isVerified;
|
||||||
|
},
|
||||||
|
id() {
|
||||||
|
return this.$route.params.id.toString();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async mounted() {
|
||||||
|
this.loading = true;
|
||||||
|
orderService.get(this.id).then(({ data: data }: { data: IOrderDetailResponse }) => {
|
||||||
|
this.loading = false;
|
||||||
|
this.order = data;
|
||||||
|
this.order.courses?.forEach((courseId: number) => {
|
||||||
|
console.log('course', courseId);
|
||||||
|
courseService.get(courseId).then(({ data: data2 }: { data: ICourseDetailResponse }) => {
|
||||||
|
this.courses?.push(data2);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
methods: {}
|
||||||
|
});
|
||||||
|
</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;
|
||||||
|
}
|
||||||
|
|
||||||
|
.verification-alert {
|
||||||
|
padding-top: 50px;
|
||||||
|
.go {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.episodes {
|
||||||
|
padding: 50px 0;
|
||||||
|
&.disabled {
|
||||||
|
opacity: 0.2;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
.episode {
|
||||||
|
cursor: pointer;
|
||||||
|
margin-bottom: 2rem;
|
||||||
|
height: 100px;
|
||||||
|
border-radius: 0.934rem !important;
|
||||||
|
.left {
|
||||||
|
.index {
|
||||||
|
width: 50px;
|
||||||
|
height: 50px;
|
||||||
|
background: #f8fafe;
|
||||||
|
display: block;
|
||||||
|
border-radius: 50%;
|
||||||
|
line-height: 50px;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 20px;
|
||||||
|
border: 2px solid #e5e5e5;
|
||||||
|
position: absolute;
|
||||||
|
top: 5px;
|
||||||
|
left: 35px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.title {
|
||||||
|
p {
|
||||||
|
font-size: 1.2rem;
|
||||||
|
font-weight: bold;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.introduction {
|
||||||
|
p {
|
||||||
|
font-size: 0.8rem;
|
||||||
|
color: rgb(161, 161, 161);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.info {
|
||||||
|
font-size: 12px;
|
||||||
|
color: #666;
|
||||||
|
.icon {
|
||||||
|
position: relative;
|
||||||
|
top: 1px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
+3
-1
@@ -3,6 +3,7 @@ import auth from './auth';
|
|||||||
import course from './course';
|
import course from './course';
|
||||||
import category from './category';
|
import category from './category';
|
||||||
import episode from './episode';
|
import episode from './episode';
|
||||||
|
import order from './order';
|
||||||
import store from '@/store';
|
import store from '@/store';
|
||||||
|
|
||||||
const routes = [
|
const routes = [
|
||||||
@@ -14,7 +15,8 @@ const routes = [
|
|||||||
auth,
|
auth,
|
||||||
course,
|
course,
|
||||||
episode,
|
episode,
|
||||||
category
|
category,
|
||||||
|
order
|
||||||
];
|
];
|
||||||
|
|
||||||
const router = createRouter({
|
const router = createRouter({
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
export default {
|
||||||
|
path: '/orders',
|
||||||
|
name: 'orders',
|
||||||
|
meta: {
|
||||||
|
auth: true
|
||||||
|
},
|
||||||
|
component: () => import('@/layouts/Order.vue'),
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
path: '',
|
||||||
|
name: 'order-list',
|
||||||
|
component: () => import('@/pages/order/List.vue')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: ':id',
|
||||||
|
name: 'order-detail',
|
||||||
|
component: () => import('@/pages/order/Detail.vue')
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
@@ -4,6 +4,8 @@ export interface ICourse {
|
|||||||
title?: string;
|
title?: string;
|
||||||
cover?: string;
|
cover?: string;
|
||||||
thumbnail?: string;
|
thumbnail?: string;
|
||||||
|
discount?: number;
|
||||||
|
price?: number;
|
||||||
duration?: number;
|
duration?: number;
|
||||||
introduction?: string;
|
introduction?: string;
|
||||||
createdAt?: string;
|
createdAt?: string;
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import { AxiosResponse } from 'axios';
|
||||||
|
import httpClient from '../instance';
|
||||||
|
import { IOrder, IOrderDetailResponse, IOrderListResponse } from './types';
|
||||||
|
|
||||||
|
class OrderService {
|
||||||
|
key = 'orders';
|
||||||
|
|
||||||
|
async getAll(): Promise<AxiosResponse<IOrderListResponse>> {
|
||||||
|
return await httpClient.get(`/${this.key}/`);
|
||||||
|
}
|
||||||
|
|
||||||
|
async get(id: string): Promise<AxiosResponse<IOrderDetailResponse>> {
|
||||||
|
return await httpClient.get(`/${this.key}/${id}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
async create(data: IOrder): Promise<AxiosResponse<IOrderDetailResponse>> {
|
||||||
|
return await httpClient.post(`/${this.key}/`, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
async update(id: string, data: IOrder): Promise<AxiosResponse<IOrderDetailResponse>> {
|
||||||
|
return await httpClient.put(`/${this.key}/${id}`, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
async delete(id: string): Promise<AxiosResponse<null>> {
|
||||||
|
return await httpClient.delete(`/${this.key}/${id}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const orderService = new OrderService();
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
export interface IOrder {
|
||||||
|
id?: string;
|
||||||
|
description?: string;
|
||||||
|
state?: 'Pending' | 'Expired' | 'Paied' | 'Failed';
|
||||||
|
price?: number;
|
||||||
|
creatorId?: number;
|
||||||
|
createdAt?: string;
|
||||||
|
updatedAt?: string;
|
||||||
|
courses?: number[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IOrderListResponse {
|
||||||
|
count: number;
|
||||||
|
items: IOrder[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export type IOrderDetailResponse = IOrder;
|
||||||
@@ -242,6 +242,11 @@
|
|||||||
resolved "https://registry.yarnpkg.com/@types/parse-json/-/parse-json-4.0.0.tgz#2f8bb441434d163b35fb8ffdccd7138927ffb8c0"
|
resolved "https://registry.yarnpkg.com/@types/parse-json/-/parse-json-4.0.0.tgz#2f8bb441434d163b35fb8ffdccd7138927ffb8c0"
|
||||||
integrity sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA==
|
integrity sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA==
|
||||||
|
|
||||||
|
"@types/uuid@^8.3.4":
|
||||||
|
version "8.3.4"
|
||||||
|
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-8.3.4.tgz#bd86a43617df0594787d38b735f55c805becf1bc"
|
||||||
|
integrity sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw==
|
||||||
|
|
||||||
"@typescript-eslint/eslint-plugin@^5.17.0":
|
"@typescript-eslint/eslint-plugin@^5.17.0":
|
||||||
version "5.17.0"
|
version "5.17.0"
|
||||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.17.0.tgz#704eb4e75039000531255672bf1c85ee85cf1d67"
|
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.17.0.tgz#704eb4e75039000531255672bf1c85ee85cf1d67"
|
||||||
@@ -3000,6 +3005,11 @@ util-deprecate@^1.0.2:
|
|||||||
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
|
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
|
||||||
integrity sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=
|
integrity sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=
|
||||||
|
|
||||||
|
uuid@^8.3.2:
|
||||||
|
version "8.3.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
|
||||||
|
integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==
|
||||||
|
|
||||||
v8-compile-cache@^2.0.3:
|
v8-compile-cache@^2.0.3:
|
||||||
version "2.3.0"
|
version "2.3.0"
|
||||||
resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz#2de19618c66dc247dcfb6f99338035d8245a2cee"
|
resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz#2de19618c66dc247dcfb6f99338035d8245a2cee"
|
||||||
|
|||||||
Reference in new issue
Block a user