update pagination

This commit is contained in:
AceDataCloud committed 2023-01-02 02:51:47 +08:00
1 parent 89461c8b1a
commit f3fb5ba6fd
12 files changed
+155 -30

No files matched your search

+13 -1
View File
@@ -1,11 +1,23 @@
<template> <template>
<router-view /> <el-config-provider :locale="locale">
<router-view />
</el-config-provider>
</template> </template>
<script lang="ts"> <script lang="ts">
import { defineComponent } from 'vue'; import { defineComponent } from 'vue';
import { ElConfigProvider } from 'element-plus';
import zhCn from 'element-plus/dist/locale/zh-cn.mjs';
export default defineComponent({ export default defineComponent({
components: {
ElConfigProvider
},
data() {
return {
locale: zhCn
};
},
mounted() { mounted() {
this.$store.dispatch('getMe'); this.$store.dispatch('getMe');
} }
+1 -1
View File
@@ -2,7 +2,7 @@
<el-card v-if="application && service" shadow="hover" class="card"> <el-card v-if="application && service" shadow="hover" class="card">
<div class="item"> <div class="item">
<div class="icon"> <div class="icon">
<font-awesome-icon :icon="'fa-regular fa-' + service.icon" /> <font-awesome-icon v-if="service.icon" :icon="service.icon" />
</div> </div>
<div class="main"> <div class="main">
<div class="title"> <div class="title">
+2 -2
View File
@@ -6,8 +6,8 @@
<el-col :span="12" :offset="6" class="p-t text-center"> <el-col :span="12" :offset="6" class="p-t text-center">
<p> <p>
<span <span
><a href="https://academy.zhishuyun.com">{{ $t('common.entity.website') }}</a> © ><a href="https://zhishuyun.com">{{ $t('common.entity.website') }}</a> © {{ new Date().getFullYear() }}
{{ new Date().getFullYear() }} {{ $t('common.entity.copyright') }} {{ $t('common.entity.copyright') }}
</span> </span>
<span class="ml-2"> <span class="ml-2">
<a href="https://beian.miit.gov.cn/">京ICP备18021371号-2 </a> <a href="https://beian.miit.gov.cn/">京ICP备18021371号-2 </a>
+7 -1
View File
@@ -7,7 +7,7 @@
<el-row> <el-row>
<el-col :span="20"> <el-col :span="20">
<el-menu :default-active="active" class="el-menu-demo" mode="horizontal" @select="onSelect"> <el-menu :default-active="active" class="el-menu-demo" mode="horizontal" @select="onSelect">
<el-menu-item v-t="'common.nav.course'" index="/courses"></el-menu-item> <el-menu-item v-t="'common.nav.service'" index="/services"></el-menu-item>
<!-- <el-menu-item v-t="'common.nav.category'" index="/categories"></el-menu-item> --> <!-- <el-menu-item v-t="'common.nav.category'" index="/categories"></el-menu-item> -->
</el-menu> </el-menu>
</el-col> </el-col>
@@ -22,6 +22,7 @@
<img :src="user?.avatar || defaultAvatar" class="avatar" /> <img :src="user?.avatar || defaultAvatar" class="avatar" />
<template #dropdown> <template #dropdown>
<el-dropdown-menu> <el-dropdown-menu>
<el-dropdown-item @click="onConsole">{{ $t('common.button.console') }}</el-dropdown-item>
<el-dropdown-item @click="onProfile">{{ $t('common.button.profile') }}</el-dropdown-item> <el-dropdown-item @click="onProfile">{{ $t('common.button.profile') }}</el-dropdown-item>
<el-dropdown-item @click="onVerify">{{ $t('common.button.verify') }}</el-dropdown-item> <el-dropdown-item @click="onVerify">{{ $t('common.button.verify') }}</el-dropdown-item>
<el-dropdown-item @click="onLogout">{{ $t('common.button.logout') }}</el-dropdown-item> <el-dropdown-item @click="onLogout">{{ $t('common.button.logout') }}</el-dropdown-item>
@@ -74,6 +75,11 @@ export default defineComponent({
onVerify() { onVerify() {
window.location.href = 'https://auth.test.zhishuyun.com/user/verify'; window.location.href = 'https://auth.test.zhishuyun.com/user/verify';
}, },
onConsole() {
this.$router.push({
name: 'console-application-list'
});
},
onLogout() { onLogout() {
this.$store.dispatch('resetAuth'); this.$store.dispatch('resetAuth');
this.$router.push('/'); this.$router.push('/');
+3
View File
@@ -1,5 +1,8 @@
/// <reference types="vite/client" /> /// <reference types="vite/client" />
declare module 'element-ui/*';
declare module '*.mjs';
declare module '*.vue' { declare module '*.vue' {
import { DefineComponent } from 'vue'; import { DefineComponent } from 'vue';
const component: DefineComponent<{}, {}, {}>; const component: DefineComponent<{}, {}, {}>;
+1
View File
@@ -13,6 +13,7 @@ export default {
watch: '观看', watch: '观看',
verify: '实名认证', verify: '实名认证',
profile: '个人信息', profile: '个人信息',
console: '控制台',
learn: '学习', learn: '学习',
buy: '购买' buy: '购买'
}; };
+2 -1
View File
@@ -6,5 +6,6 @@ export default {
article: '文章', article: '文章',
publication: '发布', publication: '发布',
course: '课程', course: '课程',
category: '分类' category: '分类',
service: '服务'
}; };
+10 -7
View File
@@ -1,10 +1,10 @@
<template> <template>
<el-container> <el-container class="wrapper">
<el-header> <el-header class="header">
<top-header /> <top-header />
</el-header> </el-header>
<el-main> <router-view /> </el-main> <el-main class="main"> <router-view /> </el-main>
<el-footer> <el-footer class="footer">
<bottom-footer /> <bottom-footer />
</el-footer> </el-footer>
</el-container> </el-container>
@@ -22,9 +22,12 @@ export default {
}; };
</script> </script>
<style lang="scss"> <style lang="scss" scoped>
.el-header, .wrapper {
.el-footer { min-height: 100vh;
}
.header {
padding: 0; padding: 0;
} }
</style> </style>
+10 -2
View File
@@ -1,12 +1,20 @@
import { AxiosResponse } from 'axios'; import { AxiosResponse } from 'axios';
import { decamelizeKeys } from 'humps';
import { httpClient } from '../instance'; import { httpClient } from '../instance';
import { IService, IServiceDetailResponse, IServiceListResponse } from './models'; import { IService, IServiceDetailResponse, IServiceListResponse } from './models';
export interface IServiceQuery {
limit: number;
offset: number;
}
class ServiceOperator { class ServiceOperator {
key = 'services'; key = 'services';
async getAll(): Promise<AxiosResponse<IServiceListResponse>> { async getAll(query: IServiceQuery): Promise<AxiosResponse<IServiceListResponse>> {
return await httpClient.get(`/${this.key}/`); return await httpClient.get(`/${this.key}/`, {
params: decamelizeKeys(query)
});
} }
async get(id: string): Promise<AxiosResponse<IServiceDetailResponse>> { async get(id: string): Promise<AxiosResponse<IServiceDetailResponse>> {
+5
View File
@@ -124,6 +124,11 @@ export default defineComponent({
.catch((error) => { .catch((error) => {
if (error?.response?.data?.code === ERROR_CODE_DUPLICATION) { if (error?.response?.data?.code === ERROR_CODE_DUPLICATION) {
ElMessage.error(this.$t('application.message.alreadyApplied')); ElMessage.error(this.$t('application.message.alreadyApplied'));
setTimeout(() => {
this.$router.push({
name: 'console-application-list'
});
}, 2000);
} }
}); });
} }
+91 -12
View File
@@ -1,11 +1,24 @@
<template> <template>
<el-row> <el-row>
<el-col :span="20" :offset="2"> <el-col :span="20" :offset="2">
<el-row :gutter="15" class="services"> <el-row v-if="loading" :gutter="15" class="services">
<el-col v-for="(service, serviceIndex) in services" :key="serviceIndex" :md="6" :xs="24"> <el-col v-for="_ in 8" :key="_" :lg="6" :md="8" :sm="12" :xs="24">
<el-card shadow="hover" class="service">
<el-skeleton>
<template #template>
<el-skeleton-item variant="image" class="icon-placeholder" />
<el-skeleton-item variant="p" class="title-placeholder" />
<el-skeleton-item variant="p" class="price-placeholder" />
</template>
</el-skeleton>
</el-card>
</el-col>
</el-row>
<el-row v-else :gutter="15" class="services">
<el-col v-for="(service, serviceIndex) in services" :key="serviceIndex" :lg="6" :md="8" :sm="12" :xs="24">
<el-card shadow="hover" class="service"> <el-card shadow="hover" class="service">
<div class="icon"> <div class="icon">
<font-awesome-icon :icon="'fa-regular fa-' + service.icon" /> <font-awesome-icon v-if="service.icon" :icon="service.icon" />
</div> </div>
<div class="title">{{ service.title }}</div> <div class="title">{{ service.title }}</div>
<div class="price"> <div class="price">
@@ -38,6 +51,21 @@
</el-card> </el-card>
</el-col> </el-col>
</el-row> </el-row>
<el-row>
<el-col :span="10" :offset="14">
<div class="pagination m-v-lg">
<el-pagination
v-model:current-page="page"
background
:page-size="limit"
layout="total, prev, pager, next"
:total="total"
@current-change="onPageChange"
>
</el-pagination>
</div>
</el-col>
</el-row>
</el-col> </el-col>
</el-row> </el-row>
</template> </template>
@@ -46,11 +74,13 @@
import { serviceOperator, IService, IServiceListResponse } from '@/operators'; import { serviceOperator, IService, IServiceListResponse } from '@/operators';
import { defineComponent } from 'vue'; import { defineComponent } from 'vue';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'; import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import { ElForm, ElMessage } from 'element-plus';
interface IData { interface IData {
services: IService[]; services: IService[];
loading: boolean; loading: boolean;
total: number | undefined;
limit: number;
page: number;
} }
export default defineComponent({ export default defineComponent({
name: 'ServiceList', name: 'ServiceList',
@@ -60,16 +90,39 @@ export default defineComponent({
data(): IData { data(): IData {
return { return {
services: [], services: [],
loading: false loading: true,
total: undefined,
limit: 8,
page: parseInt(this.$route.query.page?.toString() || '1')
}; };
}, },
async mounted() { async mounted() {
this.loading = true; this.onFetchData();
console.debug('start to load all services'); },
serviceOperator.getAll().then(({ data: data }: { data: IServiceListResponse }) => { methods: {
this.services = data.items; onPageChange(page: number) {
this.loading = false; this.$router.push({
}); name: this.$route.name?.toString(),
query: {
page: page
}
});
this.onFetchData();
},
onFetchData() {
this.loading = true;
console.debug('start to load all services');
serviceOperator
.getAll({
limit: this.limit,
offset: (this.page - 1) * this.limit
})
.then(({ data: data }: { data: IServiceListResponse }) => {
this.services = data.items;
this.total = data.count;
this.loading = false;
});
}
} }
}); });
</script> </script>
@@ -77,7 +130,7 @@ export default defineComponent({
<style lang="scss" scoped> <style lang="scss" scoped>
$transition-duration: 0.5s; $transition-duration: 0.5s;
.services { .services {
padding: 50px; padding: 50px 0;
.service { .service {
width: 100%; width: 100%;
height: 280px; height: 280px;
@@ -87,6 +140,28 @@ $transition-duration: 0.5s;
position: relative; position: relative;
transition: all $transition-duration; transition: all $transition-duration;
.icon-placeholder {
display: flex;
width: 80px;
height: 80px;
margin: 0 auto 15px auto;
text-align: center;
}
.title-placeholder {
display: block;
width: 80px;
height: 20px;
margin: 0 auto 10px auto;
}
.price-placeholder {
display: block;
width: 100px;
height: 16px;
margin: 0 auto 10px auto;
}
.icon { .icon {
font-size: 60px; font-size: 60px;
text-align: center; text-align: center;
@@ -154,4 +229,8 @@ $transition-duration: 0.5s;
} }
} }
} }
.pagination {
padding-bottom: 50px;
float: right;
}
</style> </style>
+10 -3
View File
@@ -1,9 +1,16 @@
import { library } from '@fortawesome/fontawesome-svg-core'; import { library } from '@fortawesome/fontawesome-svg-core';
import * as icons from '@fortawesome/free-regular-svg-icons'; import * as iconsRegular from '@fortawesome/free-regular-svg-icons';
import * as iconsSolid from '@fortawesome/free-solid-svg-icons';
// register all icons from font awesome // register all icons from font awesome
for (const key in icons) { for (const key in iconsRegular) {
//@ts-ignore //@ts-ignore
const icon = icons[key]; const icon = iconsRegular[key];
if (icon?.iconName) library.add(icon);
}
for (const key in iconsSolid) {
//@ts-ignore
const icon = iconsSolid[key];
if (icon?.iconName) library.add(icon); if (icon?.iconName) library.add(icon);
} }