增加文章管理

This commit is contained in:
不做码农 2022-04-17 14:20:56 +08:00
parent 03bdccd2a0
commit 8728ce15d9

View File

@ -0,0 +1,145 @@
<template>
<div class="app-container">
<el-row :gutter="24">
<!-- :model属性用于表单验证使用 比如下面的el-form-item prop属性用于对表单值进行验证操作 -->
<el-form :model="queryParams" label-position="left" inline ref="queryForm" label-width="100px" v-show="showSearch" @submit.prevent>
<el-form-item label="文章标题" prop="title">
<el-input v-model="queryParams.title" placeholder="请输入文章标题" />
</el-form-item>
<el-form-item label="文章状态" prop="status">
<el-select v-model="queryParams.status">
<el-option v-for="item in statusOptions" :key="item.dictValue" :label="item.dictLabel" :value="item.dictValue"></el-option>
</el-select>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="search" @click="handleQuery">搜索</el-button>
<el-button icon="refresh" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
</el-row>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<!-- <el-button type="primary" plain icon="plus" v-hasPermi="['system:article:add']" @click="handleAdd">发布文章</el-button> -->
</el-col>
<right-toolbar :showSearch="showSearch"></right-toolbar>
</el-row>
<el-table :data="dataList" ref="table" border>
<el-table-column prop="cid" label="id" width="60" sortable> </el-table-column>
<el-table-column prop="title" label="文章标题" width="180" :show-overflow-tooltip="true"> </el-table-column>
<el-table-column prop="authorName" label="作者" width="80"> </el-table-column>
<el-table-column prop="fmt_type" label="编辑器类型" width="100"> </el-table-column>
<el-table-column prop="tags" label="标签" width="100" :show-overflow-tooltip="true"> </el-table-column>
<el-table-column prop="hits" label="点击量" width="80" align="center"> </el-table-column>
<el-table-column prop="content" label="文章内容" :show-overflow-tooltip="true"> </el-table-column>
<el-table-column sortable prop="status" align="center" label="状态" width="90">
<template #default="scope">
<el-tag :type="scope.row.status == '2' ? 'danger' : 'success'" disable-transitions>{{ scope.row.status == '2' ? "草稿":"已发布" }}
</el-tag>
</template>
</el-table-column>
<el-table-column prop="createTime" label="创建时间" width="128" :show-overflow-tooltip="true"> </el-table-column>
<el-table-column label="操作" align="center" width="190">
<template #default="scope">
<el-button type="text" icon="view" @click="handleView(scope.row)">查看</el-button>
<!-- <el-button type="text" icon="edit" @click="handleUpdate(scope.row)" v-hasPermi="['system:article:update']">编辑</el-button> -->
<el-popconfirm title="确定删除吗?" @onConfirm="handleDelete(scope.row)" style="margin-left:10px">
<template #reference>
<el-button type="text" icon="delete" v-hasPermi="['system:article:delete']">删除</el-button>
</template>
</el-popconfirm>
</template>
</el-table-column>
</el-table>
<pagination :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
</div>
</template>
<script setup name="articleindex">
import { listArticle, delArticle } from '@/api/system/article.js'
import { getCurrentInstance, reactive, toRefs } from 'vue-demi'
import { useRoute, useRouter } from 'vue-router'
const { proxy } = getCurrentInstance()
const router = useRouter()
//
const loading = ref(true)
//
const showSearch = ref(true)
//
const title = ref('')
//
const open = ref(false)
//
const statusOptions = ref([])
//
const dataList = ref([])
//
const total = ref(0)
//
const btnSubmitVisible = ref(true)
//
const previewUrl = ref('')
const data = reactive({
form: {},
queryParams: {},
})
const { form, queryParams } = toRefs(data)
proxy.getDicts('sys_article_status').then((response) => {
statusOptions.value = response.data
})
proxy.getConfigKey('sys.article.preview.url').then((response) => {
previewUrl.value = response.data
})
//
function getList() {
listArticle(queryParams.value).then((res) => {
if (res.code == 200) {
dataList.value = res.data.result
total.value = res.data.totalNum
}
})
}
/** 重置查询操作 */
function resetQuery() {
proxy.resetForm('queryForm')
handleQuery()
}
/** 搜索按钮操作 */
function handleQuery() {
getList()
}
/** 新增按钮操作 */
function handleAdd() {
router.replace({ path: '/article/publish' })
}
/** 删除按钮操作 */
function handleDelete(row) {
delArticle(row.cid).then((res) => {
if (res.code == 200) {
proxy.$modal.msgSuccess('删除成功')
handleQuery()
}
})
}
/** 修改按钮操作 */
function handleUpdate(row) {
router.push({ path: '/article/publish', query: { cid: row.cid } })
}
//
function handleView(row) {
var link = `${previewUrl.value}${row.cid}`
window.open(link)
}
handleQuery()
</script>