update publications list
This commit is contained in:
1 parent
672b5559a2
commit
4cc866a4ce
8 files changed
+129
-17
No files matched your search
@@ -44,7 +44,7 @@ export default defineComponent({
|
|||||||
}, 1000);
|
}, 1000);
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
onPageChange(val: number, oldVal: number) {
|
onPageChange(val: number, oldVal: number): void {
|
||||||
// if not finshed loading, ignore the wrong emit event
|
// if not finshed loading, ignore the wrong emit event
|
||||||
if (!this.loaded) {
|
if (!this.loaded) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<el-menu class="h-full" :default-active="$route.name" @select="onSelect">
|
<el-menu class="h-full" :default-active="$route.name?.toString()" @select="onSelect">
|
||||||
<el-menu-item index="article-index">
|
<el-menu-item index="article-index">
|
||||||
<el-icon class="mr-2">
|
<el-icon class="mr-2">
|
||||||
<document />
|
<document />
|
||||||
|
|||||||
@@ -6,5 +6,8 @@ export default {
|
|||||||
operation: '操作',
|
operation: '操作',
|
||||||
description: '描述',
|
description: '描述',
|
||||||
createdAt: '创建时间',
|
createdAt: '创建时间',
|
||||||
updatedAt: '更新时间'
|
publishedAt: '发布时间',
|
||||||
|
publishAt: '开始发布时间',
|
||||||
|
updatedAt: '更新时间',
|
||||||
|
article: '文章'
|
||||||
};
|
};
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
export default {
|
export default {
|
||||||
pending: '等待发布',
|
pending: '等候发布',
|
||||||
running: '发布中',
|
running: '发布中',
|
||||||
finished: '发布成功'
|
finished: '发布成功'
|
||||||
};
|
};
|
||||||
@@ -1,42 +1,149 @@
|
|||||||
<template>
|
<template>
|
||||||
<el-row :gutter="20">
|
<el-row :gutter="20">
|
||||||
|
<el-col :span="24">
|
||||||
|
<div class="px-4 pt-4">
|
||||||
|
<el-card shadow="hover">
|
||||||
|
<div class="mb-5">
|
||||||
|
<breadcrumb />
|
||||||
|
</div>
|
||||||
|
<el-table :data="items" v-loading="loading">
|
||||||
|
<el-table-column prop="icon" :label="$t('common.entity.icon')" width="150px">
|
||||||
|
<template #default="scope">
|
||||||
|
<img :src="scope.row.platform.icon" class="w-10" />
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column :label="$t('common.entity.platform')" width="300px">
|
||||||
|
<template #default="scope">
|
||||||
|
{{ scope.row.platform.name }}
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column prop="article" :label="$t('common.entity.article')">
|
||||||
|
<template #default="scope">
|
||||||
|
<router-link :to="{ name: 'article-detail', params: { id: scope.row.article.id } }">
|
||||||
|
{{ scope.row.article.title }}
|
||||||
|
</router-link>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column :label="$t('common.entity.publishAt')">
|
||||||
|
<template #default="scope">
|
||||||
|
{{ $dayjs.format(scope.row.created_at) }}
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
|
||||||
|
<el-table-column :label="$t('common.entity.status')">
|
||||||
|
<template #default="scope">
|
||||||
|
<el-button
|
||||||
|
type="info"
|
||||||
|
size="small"
|
||||||
|
round
|
||||||
|
v-if="isEqual(getPublicationState(scope.row), PUBLICATION_STATE_PENDING)"
|
||||||
|
>
|
||||||
|
{{ $t('publication.state.' + getPublicationState(scope.row)) }}</el-button
|
||||||
|
>
|
||||||
|
<el-button
|
||||||
|
type="primary"
|
||||||
|
size="small"
|
||||||
|
round
|
||||||
|
v-if="isEqual(getPublicationState(scope.row), PUBLICATION_STATE_RUNNING)"
|
||||||
|
>
|
||||||
|
{{ $t('publication.state.' + getPublicationState(scope.row)) }}</el-button
|
||||||
|
>
|
||||||
|
<el-button
|
||||||
|
type="success"
|
||||||
|
size="small"
|
||||||
|
round
|
||||||
|
v-if="isEqual(getPublicationState(scope.row), PUBLICATION_STATE_FINISHED)"
|
||||||
|
>
|
||||||
|
{{ $t('publication.state.' + getPublicationState(scope.row)) }}</el-button
|
||||||
|
>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
<pagination
|
||||||
|
class="float-right"
|
||||||
|
@change="onPageChange"
|
||||||
|
:total="total"
|
||||||
|
:current-page="currentPage"
|
||||||
|
></pagination>
|
||||||
|
</el-card>
|
||||||
|
</div>
|
||||||
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Breadcrumb } from '@/components/common/index';
|
import { Breadcrumb, Pagination } from '@/components/common/index';
|
||||||
import PublicationService from '@/services/content/Publication/service';
|
import PublicationService from '@/services/content/Publication/service';
|
||||||
import { IPublication, IPublicationListResponse } from '@/services/content/Publication/types';
|
import { IPublication, IPublicationListResponse } from '@/services/content/Publication/types';
|
||||||
import { defineComponent } from 'vue';
|
import { defineComponent } from 'vue';
|
||||||
import { Check, Close } from '@element-plus/icons';
|
import { Check, Close } from '@element-plus/icons';
|
||||||
|
import { PUBLICATION_STATE_MAP } from '@/services/content/publication/constants';
|
||||||
|
import { Constants, Methods } from '@/mixins/index';
|
||||||
|
import { DEFAULT_LIMIT } from '@/settings/article';
|
||||||
|
import { RouteQueryAndHash } from 'vue-router';
|
||||||
|
|
||||||
interface IData {
|
interface IData {
|
||||||
items: IPublication[];
|
items: IPublication[];
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
|
total: number;
|
||||||
|
limit: number;
|
||||||
|
offset: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
|
mixins: [Constants, Methods],
|
||||||
components: {
|
components: {
|
||||||
Breadcrumb,
|
Breadcrumb,
|
||||||
Check,
|
Check,
|
||||||
Close
|
Close,
|
||||||
|
Pagination
|
||||||
},
|
},
|
||||||
data(): IData {
|
data(): IData {
|
||||||
return {
|
return {
|
||||||
items: [],
|
items: [],
|
||||||
|
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,
|
||||||
|
total: 0,
|
||||||
loading: false
|
loading: false
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {},
|
computed: {
|
||||||
async mounted() {
|
currentPage(): number {
|
||||||
this.loading = true;
|
return this.offset / this.limit + 1;
|
||||||
PublicationService.getAll().then(({ data: data }: { data: IPublicationListResponse }): void => {
|
}
|
||||||
this.items = data.results;
|
|
||||||
this.loading = false;
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
methods: {}
|
async mounted() {
|
||||||
|
this.onLoadData();
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
onLoadData() {
|
||||||
|
this.loading = true;
|
||||||
|
PublicationService.getAll(this.offset, this.limit).then(
|
||||||
|
({ data: data }: { data: IPublicationListResponse }): void => {
|
||||||
|
this.total = data.count;
|
||||||
|
this.items = data.results;
|
||||||
|
this.loading = false;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
},
|
||||||
|
getPublicationState(publication: IPublication) {
|
||||||
|
return PUBLICATION_STATE_MAP[publication.state];
|
||||||
|
},
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { DEFAULT_LIMIT } from '@/settings/article';
|
||||||
import { AxiosResponse } from 'axios';
|
import { AxiosResponse } from 'axios';
|
||||||
import httpClient from '../../instance';
|
import httpClient from '../../instance';
|
||||||
import { IArticle, IArticleDetailResponse, IArticleListResponse } from './types';
|
import { IArticle, IArticleDetailResponse, IArticleListResponse } from './types';
|
||||||
@@ -5,7 +6,7 @@ import { IArticle, IArticleDetailResponse, IArticleListResponse } from './types'
|
|||||||
class ArticleService {
|
class ArticleService {
|
||||||
key = 'articles';
|
key = 'articles';
|
||||||
|
|
||||||
async getAll(offset: number = 0, limit: number = 10): Promise<AxiosResponse<IArticleListResponse>> {
|
async getAll(offset: number = 0, limit: number = DEFAULT_LIMIT): Promise<AxiosResponse<IArticleListResponse>> {
|
||||||
return await httpClient.get(`/${this.key}/?limit=${limit}&offset=${offset}`);
|
return await httpClient.get(`/${this.key}/?limit=${limit}&offset=${offset}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { DEFAULT_LIMIT } from '@/settings/article';
|
||||||
import { AxiosResponse } from 'axios';
|
import { AxiosResponse } from 'axios';
|
||||||
import httpClient from '../../instance';
|
import httpClient from '../../instance';
|
||||||
import { IPublication, IPublicationDetailResponse, IPublicationListResponse, IPublicationCreateRequest } from './types';
|
import { IPublication, IPublicationDetailResponse, IPublicationListResponse, IPublicationCreateRequest } from './types';
|
||||||
@@ -5,8 +6,8 @@ import { IPublication, IPublicationDetailResponse, IPublicationListResponse, IPu
|
|||||||
class PublicationService {
|
class PublicationService {
|
||||||
key = 'publications';
|
key = 'publications';
|
||||||
|
|
||||||
async getAll(): Promise<AxiosResponse<IPublicationListResponse>> {
|
async getAll(offset: number = 0, limit: number = DEFAULT_LIMIT): Promise<AxiosResponse<IPublicationListResponse>> {
|
||||||
return await httpClient.get(`/${this.key}/`);
|
return await httpClient.get(`/${this.key}/?limit=${limit}&offset=${offset}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async get(id: number): Promise<AxiosResponse<IPublicationDetailResponse>> {
|
async get(id: number): Promise<AxiosResponse<IPublicationDetailResponse>> {
|
||||||
|
|||||||
Whitespace-only changes.
Reference in new issue
Block a user