blog/template/admin/article/index.html

266 lines
10 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Admin Console</title>
<link rel="icon" href="/assets/favicon.ico" type="image/x-icon" />
<link rel="bookmark" href="/assets/favicon.ico" type="image/x-icon" />
<link href="/assets/vuetify-v2.6.9/vuetify-v2.6.9.min.css" rel="stylesheet" />
<link href="/assets/vuetify-v2.6.9/materialdesignicons.min.css" rel="stylesheet">
<script src="/assets/vue/vue.min.js"></script>
<script src="/assets/vuetify-v2.6.9/vuetify-v2.6.9.min.js"></script>
<script src="/assets/axios/axios.min.js"></script>
<script src="/assets/moment/moment.js"></script>
<script src="/assets/qs/qs.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui">
</head>
<body>
<div id="app"></div>
</body>
<script type="text/x-template" id="app-template">
<v-app id="inspire">
#{ render "common/bar-admin.html" . }
<!-- <#include "../../common/drawer-admin.ftl"> -->
<v-dialog v-model="dialog.show" width="500" v-if="dialog.obj">
<v-card>
<v-card-title class="text-h5 grey lighten-2">{{dialog.title}}</v-card-title>
<v-card-text>{{dialog.context}}</v-card-text>
<v-divider></v-divider>
<v-card-actions>
<v-btn text @click="dialog.show = false">取消</v-btn>
<v-spacer></v-spacer>
<v-btn color="primary" text @click="confirm">确认</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
<v-main class="grey lighten-3">
<v-container style="height: 100%">
<v-row style="height: 100%">
<!-- <v-col cols="12" sm="2" class="">
<v-sheet min-height="100%">
</v-sheet>
</v-col> -->
<v-col cols="12" sm="12" md="12">
<v-sheet min-height="100%">
<v-data-table class="elevation-1"
:headers="headers"
:items="articleList"
height="700px"
:page.sync="pageable.page"
:items-per-page="pageable.itemsPerPage"
:loading="loading"
loading-text="数据加载中"
hide-default-footer>
<template #item.createTime="{ item }">
{{item.createTime?moment(item.createTime).format('YYYY/MM/DD HH:mm:ss'):''}}
</template>
<template #item.publishTime="{ item }">
{{ item.publishTime?moment(item.publishTime).format('YYYY/MM/DD HH:mm:ss'):''}}
</template>
<template #item.actions="{ item }">
<v-btn text color="primary" @click="publishArticle(item)"
v-if="item.state === 'draft'">发布
</v-btn>
<v-btn text color="primary" @click="unPublishArticle(item)"
v-if="item.state ==='publish'">取消发布
</v-btn>
<v-btn text link v-if="item.state === 'draft'"
:href="`/admin/article/editor/${item.contentType}/${item.id}`">
修改
</v-btn>
<v-btn text color="error" @click="delArticle(item)" v-if="item.state === 'draft'">删除</v-btn>
</template>
</v-data-table>
<div class="pt-2 float-right" style="display: flex">
<v-pagination v-model="pageable.page" :length="pageable.totalPages" :total-visible="7"
style="min-width: 200px;" @previous="previousPage" @next="nextPage"
@input="goPage"></v-pagination>
<v-select :items="[5,10,20,50,100]" label="分页大小" style="width: 100px"
v-model="pageable.itemsPerPage" outlined dense
@input="pageSizeChange"></v-select>
</div>
</v-sheet>
</v-col>
<!-- <v-col cols="12" sm="2">
<v-sheet min-height="100%">
</v-sheet>
</v-col> -->
</v-row>
</v-container>
</v-main>
</v-app>
</script>
<script>
var qs = Qs
new Vue({
el: '#app',
template: '#app-template',
data: {
drawer: false,
loading: false,
dialog: {
show: false,
title: '',
context: '',
obj: null
},
pageable: {
page: 1,
itemsPerPage: 20,
totalElements: 0,
totalPages: 1
},
param: {
id: null,
title: null,
subTitle: null,
},
headers: [
{ text: '主标题', value: 'title', align: 'start', sortable: false },
{ text: '子标题', value: 'subTitle', align: 'start', sortable: false },
{ text: '作者', value: 'author', align: 'start', sortable: false },
{ text: '点击量', value: 'view', align: 'start', sortable: false },
{ text: '起草时间', value: 'createTime', align: 'start', sortable: false },
{ text: '发表时间', value: 'publishTime', align: 'start', sortable: false },
{ text: '操作', value: 'actions', align: 'center', sortable: false },
],
articleList: [],
},
methods: {
pageSizeChange(size) {
this.pageable.page = 1
this.list()
},
nextPage() {
this.pageable.page = this.pageable.page + 1
// this.list()
},
previousPage() {
this.pageable.page = this.pageable.page - 1
// this.list()
},
goPage(num) {
this.pageable.page = num
this.list()
},
showDialog(item) {
},
list() {
let ths = this;
this.loading = true;
let { page, itemsPerPage } = this.pageable;
let pageQuery = qs.stringify({ page, itemsPerPage, ...this.param }, { skipNulls: true });
// let paramQuery = qs.stringify(this.param, {skipNulls: true});
axios.get('/admin/article/list?' + pageQuery).then(function (response) {
// console.log(response);
let data = response.data;
ths.articleList = data.content;
ths.pageable.totalElements = data.totalElements
ths.pageable.totalPages = data.totalPages
ths.pageable.page = data.number
ths.loading = false;
// console.log(ths.pageable)
// console.log(ths.articleList)
}).catch(function (error) {
console.log(error);
ths.loading = false;
});
},
publishArticle(item) {
let ths = this
this.dialog.obj = item
this.dialog.title = '发布文章'
this.dialog.context = `确认要发布标题为《${item.title}》的文章吗?`
this.dialog.show = true;
this.confirm = () => {
ths.dialog.show = false;
axios.get(`/admin/article/publish/${item.id}`)
.then(res => {
let result = res.data
if (result.code === 200) {
location.reload();
}
console.log(res);
}).catch(err => {
console.log(err);
})
}
},
unPublishArticle(item) {
let ths = this
this.dialog.obj = item
this.dialog.title = '取消发布文章'
this.dialog.context = '确认要撤下标题为《' + item.title + '》的文章吗?'
this.dialog.show = true;
this.confirm = () => {
ths.dialog.show = false;
axios.get(`/admin/article/unPublish/${item.id}`)
.then(res => {
let result = res.data
if (result.code === 200) {
location.reload();
}
console.log(res);
}).catch(err => {
console.log(err);
})
}
},
delArticle(item) {
let ths = this
this.dialog.show = true;
this.dialog.obj = item
this.dialog.title = '删除文章'
this.dialog.context = '该操作会删除标题为《' + item.title + '》的文章'
this.confirm = () => {
ths.dialog.show = false;
axios.delete('/admin/article/del/' + item.id).then(res => {
// console.log(res.data)
// ths.list()
location.reload();
}).catch(err => {
})
}
},
confirm() {
}
},
mounted() {
this.list();
},
vuetify: new Vuetify(),
})
</script>
</html>