finished paginition
This commit is contained in:
1 parent
a05249329e
commit
57b44f1d28
7 files changed
+138
-16
No files matched your search
@@ -1,2 +1,3 @@
|
||||
// $--color-primary: #5e72e4;
|
||||
@import 'element-plus/packages/theme-chalk/src/index';
|
||||
// @import 'element-plus/packages/theme-chalk/src/index';
|
||||
@import 'element-plus/dist/index.css';
|
||||
@@ -0,0 +1,68 @@
|
||||
<template>
|
||||
<el-pagination
|
||||
class="mt-3 mb-3"
|
||||
background
|
||||
@currentChange="onPageChange"
|
||||
layout="prev, pager, next"
|
||||
:current-page="currentPage"
|
||||
:total="total"
|
||||
:page-size="pageSize"
|
||||
>
|
||||
</el-pagination>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { DEFAULT_LIMIT } from '@/settings/article';
|
||||
|
||||
interface IData {
|
||||
pageSize: number;
|
||||
loaded: boolean;
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
name: 'Pagination',
|
||||
props: {
|
||||
total: {
|
||||
type: Number
|
||||
},
|
||||
currentPage: {
|
||||
type: Number
|
||||
}
|
||||
},
|
||||
data(): IData {
|
||||
return {
|
||||
pageSize: DEFAULT_LIMIT,
|
||||
loaded: false
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
setTimeout(() => {
|
||||
// use this flag to fix the bug of el-paginition,
|
||||
// always emit page 1 when load first time.
|
||||
this.loaded = true;
|
||||
}, 1000);
|
||||
},
|
||||
methods: {
|
||||
onPageChange(val: number, oldVal: number) {
|
||||
// if not finshed loading, ignore the wrong emit event
|
||||
if (!this.loaded) {
|
||||
return;
|
||||
}
|
||||
this.$emit('change', val);
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
.el-pagination {
|
||||
button {
|
||||
border-radius: 50% !important;
|
||||
}
|
||||
li {
|
||||
border-radius: 50% !important;
|
||||
outline: none !important;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -2,4 +2,5 @@ import TopHeader from './TopHeader.vue';
|
||||
import Breadcrumb from './Breadcrumb.vue';
|
||||
import Loading from './Loading.vue';
|
||||
import SuccessInfo from './SuccessInfo.vue';
|
||||
export { TopHeader, Breadcrumb, Loading, SuccessInfo };
|
||||
import Pagination from './Pagination.vue';
|
||||
export { TopHeader, Breadcrumb, Loading, SuccessInfo, Pagination };
|
||||
@@ -150,6 +150,7 @@ export default defineComponent({
|
||||
}
|
||||
|
||||
.vditor-reset {
|
||||
min-height: 100vh;
|
||||
padding-top: 80px !important;
|
||||
padding-bottom: 80px !important;
|
||||
&:focus {
|
||||
|
||||
@@ -6,18 +6,26 @@
|
||||
<div class="mb-5">
|
||||
<breadcrumb />
|
||||
</div>
|
||||
<el-button size="mini" round type="primary" @click="onCreate" class="btn-create">
|
||||
{{ $t('common.button.new') }}</el-button
|
||||
>
|
||||
<el-table :data="items" v-loading="loading">
|
||||
<el-table-column prop="title" :label="$t('common.entity.title')"> </el-table-column>
|
||||
<el-table-column prop="updated_at" :label="$t('common.entity.updatedAt')"> </el-table-column>
|
||||
<el-table-column :label="$t('common.entity.operation')">
|
||||
<template #default="scope">
|
||||
<el-button @click="onEdit(scope.row)" round type="primary" size="small">
|
||||
<el-button @click="onEdit(scope.row)" round type="primary" size="mini">
|
||||
{{ $t('common.button.edit') }}
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-button @click="onCreate"> {{ $t('common.button.new') }}</el-button>
|
||||
<pagination
|
||||
class="float-right"
|
||||
@change="onPageChange"
|
||||
:total="total"
|
||||
:current-page="currentPage"
|
||||
></pagination>
|
||||
</el-card>
|
||||
</div>
|
||||
</el-col>
|
||||
@@ -25,35 +33,51 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { Breadcrumb } from '@/components/common/index';
|
||||
import { Breadcrumb, Pagination } from '@/components/common/index';
|
||||
import ArticleService from '@/services/content/article/service';
|
||||
import { IArticle, IArticleListResponse, IArticleDetailResponse } from '@/services/content/article/types';
|
||||
import { defineComponent } from 'vue';
|
||||
|
||||
import { RouteQueryAndHash } from 'vue-router';
|
||||
import { DEFAULT_LIMIT } from '@/settings/article';
|
||||
interface IData {
|
||||
items: IArticle[];
|
||||
loading: boolean;
|
||||
total: number;
|
||||
limit: number;
|
||||
offset: number;
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
components: {
|
||||
Breadcrumb
|
||||
Breadcrumb,
|
||||
Pagination
|
||||
},
|
||||
data(): IData {
|
||||
return {
|
||||
total: 0,
|
||||
limit: this.$route.query.limit ? parseInt(this.$route.query.limit.toString()) : DEFAULT_LIMIT,
|
||||
offset: this.$route.query.offset ? parseInt(this.$route.query.offset.toString()) : 0,
|
||||
items: [],
|
||||
loading: false
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
currentPage(): number {
|
||||
return this.offset / this.limit + 1;
|
||||
}
|
||||
},
|
||||
async mounted() {
|
||||
this.loading = true;
|
||||
ArticleService.getAll().then(({ data: data }: { data: IArticleListResponse }): void => {
|
||||
console.log('data', data);
|
||||
this.items = data.results;
|
||||
this.loading = false;
|
||||
});
|
||||
this.onLoadData();
|
||||
},
|
||||
methods: {
|
||||
onLoadData() {
|
||||
this.loading = true;
|
||||
ArticleService.getAll(this.offset, this.limit).then(({ data: data }: { data: IArticleListResponse }): void => {
|
||||
this.total = data.count;
|
||||
this.items = data.results;
|
||||
this.loading = false;
|
||||
});
|
||||
},
|
||||
onEdit(row: IArticle) {
|
||||
this.$router.push({
|
||||
name: 'article-detail',
|
||||
@@ -65,7 +89,27 @@ export default defineComponent({
|
||||
onCreate() {
|
||||
ArticleService.create({}).then(({ data: data }: { data: IArticleDetailResponse }): void => {
|
||||
console.log('data', data);
|
||||
this.$router.push({
|
||||
name: 'article-detail',
|
||||
params: {
|
||||
id: data.id
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
onPageChange(val: number) {
|
||||
this.limit = DEFAULT_LIMIT;
|
||||
this.offset = (val - 1) * this.limit;
|
||||
const route = {
|
||||
name: this.$route.name,
|
||||
query: {
|
||||
...this.$route.query,
|
||||
offset: this.offset,
|
||||
limit: this.limit
|
||||
}
|
||||
};
|
||||
this.$router.push(route as RouteQueryAndHash);
|
||||
this.onLoadData();
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -73,6 +117,12 @@ export default defineComponent({
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.el-card {
|
||||
height: calc(100vh - 100px);
|
||||
// height: calc(100vh - 100px);
|
||||
position: relative;
|
||||
.btn-create {
|
||||
position: absolute;
|
||||
right: 20px;
|
||||
top: 20px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -5,8 +5,8 @@ import { IArticle, IArticleDetailResponse, IArticleListResponse } from './types'
|
||||
class ArticleService {
|
||||
key = 'articles';
|
||||
|
||||
async getAll(): Promise<AxiosResponse<IArticleListResponse>> {
|
||||
return await httpClient.get(`/${this.key}/`);
|
||||
async getAll(offset: number = 0, limit: number = 10): Promise<AxiosResponse<IArticleListResponse>> {
|
||||
return await httpClient.get(`/${this.key}/?limit=${limit}&offset=${offset}`);
|
||||
}
|
||||
|
||||
async get(id: string | string[]): Promise<AxiosResponse<IArticleDetailResponse>> {
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export const DEFAULT_LIMIT = 10;
|
||||
Reference in new issue
Block a user