|
|
@@ -0,0 +1,244 @@
|
|
|
+<template>
|
|
|
+ <div v-loading="loading">
|
|
|
+ <div class="white-box">
|
|
|
+ <el-table :data="tableData" stripe style="width: 100%;" @selection-change="handleSelectionChange">
|
|
|
+ <el-table-column type="selection" width="55" />
|
|
|
+ <el-table-column label="ID" prop="ID">
|
|
|
+ <template slot-scope="scope">
|
|
|
+ <router-link :to="`/article/detail/${scope.row.ID}`" target="_blank" class="islide">
|
|
|
+ <span>{{ scope.row.ID }}</span>
|
|
|
+ </router-link>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column label="Title" prop="TITLE">
|
|
|
+ <template slot-scope="scope">
|
|
|
+ <router-link :to="`/article/detail/${scope.row.ID}`" target="_blank" class="islide">
|
|
|
+ <span>{{ scope.row.TITLE }}</span>
|
|
|
+ </router-link>
|
|
|
+ </template>
|
|
|
+ </el-table-column><!--标题-->
|
|
|
+ <el-table-column label="Category"><!--分类-->
|
|
|
+ <template slot-scope="scope">
|
|
|
+ {{ allData.allCategory[scope.row.CID].CATE_NAME }}
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column label="Sort" width="100"> <!-- 排序 -->
|
|
|
+ <template slot-scope="scope">
|
|
|
+ <el-input v-model="scope.row.SORT" min="0" max="99" @change="handleChangeSort(scope.row, scope.row.SORT)" />
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column label="Creation Time"><!--创建时间-->
|
|
|
+ <template slot-scope="scope">
|
|
|
+ {{ tool.formatDate(scope.row.CREATED_AT) }}
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column label="Status"> <!-- 状态 -->
|
|
|
+ <template slot-scope="scope">
|
|
|
+ <div v-if="scope.row.STATUS === '1'">Show</div>
|
|
|
+ <div v-else>Hide</div>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+
|
|
|
+ <el-table-column fixed="right" label="Action" width="180"><!--操作-->
|
|
|
+ <template slot-scope="scope">
|
|
|
+ <el-dropdown size="small" trigger="click">
|
|
|
+ <el-button type="primary" size="small" @click.stop="">
|
|
|
+ Action<i class="el-icon-arrow-down el-icon--right" />
|
|
|
+ </el-button>
|
|
|
+ <el-dropdown-menu slot="dropdown">
|
|
|
+ <el-dropdown-item command="edit" @click.native="handleEdit(scope.row)">Edit</el-dropdown-item>
|
|
|
+ <el-dropdown-item command="delete" @click.native="handleDelete(scope.row)">Delete</el-dropdown-item>
|
|
|
+ <el-dropdown-item command="hide" @click.native="handleHide(scope.row)">Hide</el-dropdown-item>
|
|
|
+ <el-dropdown-item command="un-hide" @click.native="handleUnHide(scope.row)">Unhide</el-dropdown-item>
|
|
|
+ </el-dropdown-menu>
|
|
|
+ </el-dropdown>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ </el-table>
|
|
|
+ <div class="white-box-footer">
|
|
|
+ <el-dropdown size="small" trigger="click">
|
|
|
+ <el-button type="primary" size="small">
|
|
|
+ Selected data<!--所选数据--><i class="el-icon-arrow-down el-icon--right" />
|
|
|
+ </el-button>
|
|
|
+ <el-dropdown-menu slot="dropdown">
|
|
|
+ <el-dropdown-item command="delete" @click.native="handleMuliDel()">Delete</el-dropdown-item>
|
|
|
+ <el-dropdown-item command="hide" @click.native="handleMultiHide()">Hide</el-dropdown-item>
|
|
|
+ <el-dropdown-item command="un-hide" @click.native="handleMultiUnHide()">Unhide</el-dropdown-item>
|
|
|
+ </el-dropdown-menu>
|
|
|
+ </el-dropdown>
|
|
|
+ <el-button type="primary" size="small" @click="handleAdd">New article</el-button><!--添加文章-->
|
|
|
+ <el-pagination
|
|
|
+ :current-page="currentPage"
|
|
|
+ :page-sizes="[20, 50, 100, 200]"
|
|
|
+ :page-size="pageSize"
|
|
|
+ layout="total, sizes, prev, pager, next, jumper"
|
|
|
+ :total="totalCount"
|
|
|
+ @size-change="handleSizeChange"
|
|
|
+ @current-change="handleCurrentChange"
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import { fetchArticleIndex, fetchChangeArticleSort, fetchArticleHide, fetchArticleUnhide, fetchArticleDel } from '@/api/article'
|
|
|
+import tool from '@/utils/tool'
|
|
|
+
|
|
|
+export default {
|
|
|
+ name: 'ArticleIndex',
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ allData: null,
|
|
|
+ tableData: null,
|
|
|
+ loading: true,
|
|
|
+ multipleSelection: [],
|
|
|
+ currentPage: 1,
|
|
|
+ totalPages: 1,
|
|
|
+ totalCount: 1,
|
|
|
+ pageSize: 20,
|
|
|
+ tool: tool
|
|
|
+ }
|
|
|
+ },
|
|
|
+ mounted() {
|
|
|
+ this.getData()
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ handleSelectionChange(val) {
|
|
|
+ this.multipleSelection = val
|
|
|
+ },
|
|
|
+ handleCurrentChange(page) {
|
|
|
+ this.getData(page, this.pageSize)
|
|
|
+ },
|
|
|
+ handleSizeChange(pageSize) {
|
|
|
+ this.getData(this.currentPage, pageSize)
|
|
|
+ },
|
|
|
+ handleAdd() {
|
|
|
+ this.$router.push({ path: `/article/add` })
|
|
|
+ },
|
|
|
+ handleEdit(row) {
|
|
|
+ this.$router.push({ path: `/article/edit/${row.ID}` })
|
|
|
+ },
|
|
|
+ handleDelete(row) {
|
|
|
+ this.delData(row.ID)
|
|
|
+ },
|
|
|
+ handleHide(row) {
|
|
|
+ this.hideData(row.ID)
|
|
|
+ },
|
|
|
+ handleUnHide(row) {
|
|
|
+ this.unHideData(row.ID)
|
|
|
+ },
|
|
|
+ handleMuliDel() {
|
|
|
+ this.delData()
|
|
|
+ },
|
|
|
+ handleMultiHide() {
|
|
|
+ this.hideData()
|
|
|
+ },
|
|
|
+ handleMultiUnHide() {
|
|
|
+ this.unHideData()
|
|
|
+ },
|
|
|
+ handleChangeSort(row, sort) {
|
|
|
+ fetchChangeArticleSort({ id: row.ID, sort: sort }).then(response => {
|
|
|
+ this.getData({ page: this.currentPage, pageSize: this.pageSize })
|
|
|
+ // Just to simulate the time of the request
|
|
|
+ })
|
|
|
+ },
|
|
|
+ getData(page, pageSize) {
|
|
|
+ this.loading = true
|
|
|
+ if (page === undefined) page = 1
|
|
|
+ if (pageSize === undefined) pageSize = 20
|
|
|
+ fetchArticleIndex({ page: page, pageSize: pageSize }).then(response => {
|
|
|
+ this.allData = response.data
|
|
|
+ this.tableData = response.data.list
|
|
|
+ // Just to simulate the time of the request
|
|
|
+ })
|
|
|
+ setTimeout(() => {
|
|
|
+ this.loading = false
|
|
|
+ }, 1.5 * 1000)
|
|
|
+ },
|
|
|
+ delData(id = null) {
|
|
|
+ const obj = this
|
|
|
+ obj.$confirm('Are you sure to delete the selected data?', 'Hint', { // 确定删除选定的数据
|
|
|
+ confirmButtonText: 'confirm', // 确定
|
|
|
+ cancelButtonText: 'cancel', // 取消
|
|
|
+ type: 'warning'
|
|
|
+ }).then(() => {
|
|
|
+ const selectedIds = []
|
|
|
+ if (id === null) {
|
|
|
+ for (const val of obj.multipleSelection) {
|
|
|
+ selectedIds.push(val.ID)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ selectedIds.push(id)
|
|
|
+ }
|
|
|
+ fetchArticleDel({ selected: selectedIds }).then(response => {
|
|
|
+ this.$message({
|
|
|
+ message: response.data,
|
|
|
+ type: 'success'
|
|
|
+ })
|
|
|
+ obj.getData(obj.currentPage, obj.pageSize)
|
|
|
+ }).catch(response => {
|
|
|
+
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+ hideData(id = null) {
|
|
|
+ const obj = this
|
|
|
+ obj.$confirm('Are you sure to hide the selected data?', 'Notice', { // 确定删除选定的数据?
|
|
|
+ confirmButtonText: 'confirm', // 确定
|
|
|
+ cancelButtonText: 'cancel', // 取消
|
|
|
+ type: 'warning'
|
|
|
+ }).then(() => {
|
|
|
+ const selectedIds = []
|
|
|
+ if (id === null) {
|
|
|
+ for (const val of obj.multipleSelection) {
|
|
|
+ selectedIds.push(val.ID)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ selectedIds.push(id)
|
|
|
+ }
|
|
|
+ fetchArticleHide({ selected: selectedIds }).then(response => {
|
|
|
+ this.$message({
|
|
|
+ message: response.data,
|
|
|
+ type: 'success'
|
|
|
+ })
|
|
|
+ obj.getData(obj.currentPage, obj.pageSize)
|
|
|
+ }).catch(response => {
|
|
|
+
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+ unHideData(id = null) {
|
|
|
+ const obj = this
|
|
|
+ obj.$confirm('Are you sure to un-hide the selected data?', 'Notice', { // 确定删除选定的数据?
|
|
|
+ confirmButtonText: 'confirm', // 确定
|
|
|
+ cancelButtonText: 'cancel', // 取消
|
|
|
+ type: 'warning'
|
|
|
+ }).then(() => {
|
|
|
+ const selectedIds = []
|
|
|
+ if (id === null) {
|
|
|
+ for (const val of obj.multipleSelection) {
|
|
|
+ selectedIds.push(val.ID)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ selectedIds.push(id)
|
|
|
+ }
|
|
|
+ fetchArticleUnhide({ selected: selectedIds }).then(response => {
|
|
|
+ this.$message({
|
|
|
+ message: response.data,
|
|
|
+ type: 'success'
|
|
|
+ })
|
|
|
+ obj.getData(obj.currentPage, obj.pageSize)
|
|
|
+ }).catch(response => {
|
|
|
+
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+</script>
|
|
|
+
|
|
|
+<style scoped>
|
|
|
+
|
|
|
+</style>
|