school_website/ruoyi-ui/src/views/cms/content/contentList.vue

341 lines
10 KiB
Vue
Raw Normal View History

2024-07-22 17:30:34 +08:00
<template>
<div class="cms-content-list">
<el-row :gutter="10" class="mb12">
<el-col :span="1.5">
<el-button
plain
type="primary"
icon="el-icon-plus"
size="mini"
@click="handleAdd">新增
</el-button>
</el-col>
<el-col :span="1.5">
<el-button
plain
type="danger"
icon="el-icon-delete"
size="mini"
:disabled="multiple"
@click="handleDelete">删除
</el-button>
</el-col>
<el-col :span="1.5">
<el-button
plain
type="success"
icon="el-icon-s-promotion"
size="mini"
:disabled="multiple"
@click="handlePublish">发布
</el-button>
</el-col>
<el-col :span="1.5">
<el-button
plain
type="warning"
icon="el-icon-download"
size="mini"
:disabled="multiple"
@click="handleOffline">下线
</el-button>
</el-col>
</el-row>
<el-row>
2024-07-24 17:24:35 +08:00
<el-form :model="queryParams" ref="queryForm" size="small" class="el-form-search" style="text-align:left;"
:inline="true">
2024-07-22 17:30:34 +08:00
<div class="mb12">
<el-form-item prop="contentTitle">
<el-input
v-model="queryParams.contentTitle"
2024-07-25 20:56:17 +08:00
placeholder="请输入内容标题"
2024-07-22 17:30:34 +08:00
clearable
style="width: 200px"
2024-07-24 17:24:35 +08:00
@keyup.enter.native="handleQuery"/>
2024-07-22 17:30:34 +08:00
</el-form-item>
<el-form-item prop="contentType">
<el-select
v-model="queryParams.contentType"
2024-07-25 20:56:17 +08:00
placeholder="内容类型"
2024-07-22 17:30:34 +08:00
clearable
style="width: 125px">
<el-option
v-for="dict in dict.type.cms_content_type"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</el-form-item>
<el-form-item prop="status">
<el-select
v-model="queryParams.status"
placeholder="状态"
clearable
style="width: 110px">
<el-option
v-for="dict in dict.type.cms_content_status"
:key="dict.value"
:label="dict.label"
2024-07-24 17:24:35 +08:00
:value="dict.value"/>
2024-07-22 17:30:34 +08:00
</el-select>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
2024-07-30 09:25:39 +08:00
<el-button icon="el-icon-refresh" @click="resetQuery">重置刷新</el-button>
2024-07-22 17:30:34 +08:00
</el-form-item>
</div>
</el-form>
</el-row>
<el-table
v-loading="loading"
ref="tableContentList"
2024-07-24 17:24:35 +08:00
:data="contentList"
2024-07-22 17:30:34 +08:00
size="small"
@cell-dblclick="handleEdit"
@selection-change="handleSelectionChange">
2024-07-24 17:24:35 +08:00
<el-table-column type="selection" width="50" align="center"/>
2024-07-25 20:56:17 +08:00
<el-table-column label="内容标题" align="center" prop="contentTitle"/>
<el-table-column label="内容类型" align="center" prop="contentType">
2024-07-24 17:24:35 +08:00
<template slot-scope="scope">
<dict-tag :options="dict.type.cms_content_type" :value="scope.row.contentType"/>
</template>
</el-table-column>
<el-table-column label="状态" align="center" prop="status">
<template slot-scope="scope">
<dict-tag :options="dict.type.cms_content_status" :value="scope.row.status"/>
</template>
</el-table-column>
2024-07-22 17:30:34 +08:00
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
<template slot-scope="scope">
2024-07-27 18:02:04 +08:00
<span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
</template>
</el-table-column>
<el-table-column label="发布时间" align="center" prop="publishDate" width="180">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.publishDate, '{y}-{m}-{d}') }}</span>
</template>
</el-table-column>
<el-table-column label="下线时间" align="center" prop="offlineDate" width="180">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.offlineDate, '{y}-{m}-{d}') }}</span>
2024-07-22 17:30:34 +08:00
</template>
</el-table-column>
<el-table-column
label="操作"
align="center"
width="180"
class-name="small-padding fixed-width">
<template slot-scope="scope">
<span class="btn-cell-wrap">
<el-button
size="small"
type="text"
icon="el-icon-s-promotion"
2024-07-24 17:24:35 +08:00
:disabled="scope.row.status === '1'"
2024-07-22 17:30:34 +08:00
@click="handlePublish(scope.row)">发布</el-button>
</span>
<span class="btn-cell-wrap">
<el-button
size="small"
type="text"
icon="el-icon-download"
2024-07-24 17:24:35 +08:00
:disabled="scope.row.status !== '1'"
2024-07-22 17:30:34 +08:00
@click="handleOffline(scope.row)">下线</el-button>
</span>
<el-dropdown size="small">
<el-link :underline="false" class="row-more-btn" icon="el-icon-more"></el-link>
<el-dropdown-menu slot="dropdown">
<!-- 修改-->
2024-07-24 17:24:35 +08:00
<el-dropdown-item icon="el-icon-edit" @click.native="handleEdit(scope.row)">修改</el-dropdown-item>
2024-07-22 17:30:34 +08:00
<!-- 删除-->
2024-07-24 17:24:35 +08:00
<el-dropdown-item icon="el-icon-delete" @click.native="handleDelete(scope.row)">删除</el-dropdown-item>
2024-07-22 17:30:34 +08:00
<!-- 下线-->
</el-dropdown-menu>
</el-dropdown>
</template>
</el-table-column>
</el-table>
<pagination
v-show="total>0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
2024-07-24 17:24:35 +08:00
@pagination="getList"/>
2024-07-22 17:30:34 +08:00
</div>
</template>
<script>
2024-07-24 17:24:35 +08:00
import {changeContentByIds, delContent, getContent, listContent} from "@/api/cms/content";
2024-07-22 17:30:34 +08:00
export default {
name: "CMSContentList",
dicts: ['cms_content_type', 'cms_content_status'],
2024-07-24 17:24:35 +08:00
props: {
cid: {
type: String,
defaultValue: undefined,
required: false
2024-08-01 19:21:05 +08:00
},
2024-07-24 17:24:35 +08:00
},
2024-07-22 17:30:34 +08:00
data() {
return {
// 遮罩层
loading: false,
contentList: null,
multiple: true,
queryParams: {
pageNum: 1,
pageSize: 10,
contentTitle: undefined,
contentType: undefined,
status: undefined,
2024-07-24 17:24:35 +08:00
categoryId: "0",
delFlag: "0",
2024-07-22 17:30:34 +08:00
},
total: 0,
}
},
2024-07-24 17:24:35 +08:00
watch: {
cid(newVal) {
this.queryParams = {
pageNum: 1,
pageSize: 10,
categoryId: newVal,
2024-08-01 19:21:05 +08:00
delFlag: "0",
2024-07-24 17:24:35 +08:00
}
this.getList()
2024-08-01 19:21:05 +08:00
},
2024-07-24 17:24:35 +08:00
},
created() {
if (this.cid === "") {
this.queryParams.categoryId = "0"
} else {
this.queryParams.categoryId = this.cid.toString()
}
this.getList();
},
2024-07-22 17:30:34 +08:00
methods: {
/** 新增按钮操作 */
handleAdd() {
2024-08-02 16:40:13 +08:00
this.$router.push({path: '/content/editor', query: {"categoryId": this.queryParams.categoryId}})
2024-07-22 17:30:34 +08:00
},
/** 删除按钮操作 */
handleDelete(row) {
2024-07-24 17:24:35 +08:00
const ids = row.id ? [row.id] : this.selectedRows.map(row => row.id);
2024-07-25 20:56:17 +08:00
this.$modal.confirm('是否确认删除所选内容?').then(function () {
2024-07-22 17:30:34 +08:00
return delContent(ids);
}).then(() => {
this.getList();
this.$modal.msgSuccess("删除成功");
}).catch(() => {
});
},
2024-07-24 17:24:35 +08:00
handleSelectionChange(selection) {
2024-07-22 17:30:34 +08:00
this.selectedRows = selection;
this.single = selection.length != 1;
this.multiple = !selection.length;
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const id = row.id || this.ids
getContent(id).then(response => {
this.form = response.data;
this.open = true;
2024-07-25 20:56:17 +08:00
this.title = "修改内容";
2024-07-22 17:30:34 +08:00
});
},
// 发布
handlePublish(row) {
2024-07-24 17:24:35 +08:00
const statues = row.status ? [row.status] : this.selectedRows.map(row => row.status)
if (statues.includes("1")) {
2024-07-25 20:56:17 +08:00
this.$modal.msgError("所选内容已发布!!!");
2024-07-24 17:24:35 +08:00
} else {
const ids = row.id ? [row.id] : this.selectedRows.map(row => row.id);
2024-07-25 20:56:17 +08:00
this.$modal.confirm('是否确认发布所选内容?').then(function () {
2024-07-24 17:24:35 +08:00
return changeContentByIds(ids);
}).then(() => {
this.getList();
2024-07-25 20:56:17 +08:00
this.$modal.msgSuccess("发布成功");
2024-07-24 17:24:35 +08:00
}).catch(() => {
});
}
2024-07-22 17:30:34 +08:00
},
// 下线
handleOffline(row) {
2024-07-24 17:24:35 +08:00
const statues = row.status ? [row.status] : this.selectedRows.map(row => row.status)
if (!statues.includes("1")) {
2024-07-25 20:56:17 +08:00
this.$modal.msgError("所选内容为初稿或已下线内容,不能下线!!!");
2024-07-24 17:24:35 +08:00
} else {
const ids = row.id ? [row.id] : this.selectedRows.map(row => row.id);
2024-07-25 20:56:17 +08:00
this.$modal.confirm('是否确认下线所选内容?').then(function () {
2024-07-24 17:24:35 +08:00
return changeContentByIds(ids);
}).then(() => {
this.getList();
this.$modal.msgSuccess("下线成功");
}).catch(() => {
});
}
2024-07-22 17:30:34 +08:00
},
// 查询
2024-07-24 17:24:35 +08:00
handleQuery() {
2024-07-22 17:30:34 +08:00
this.queryParams.page = 1;
this.getList();
},
2024-07-25 20:56:17 +08:00
/** 查询内容列表 */
2024-07-22 17:30:34 +08:00
getList() {
this.loading = true;
listContent(this.queryParams).then(response => {
this.contentList = response.rows;
this.total = response.total;
this.loading = false;
});
},
// 表单重置
2024-07-24 17:24:35 +08:00
resetQuery() {
2024-07-22 17:30:34 +08:00
this.resetForm("queryForm");
this.handleQuery();
},
// 双击数据
2024-07-24 17:24:35 +08:00
handleEdit(row) {
2024-07-25 20:56:17 +08:00
this.$router.push({path: '/content/editor', query: {"contentId": row.id}})
2024-07-22 17:30:34 +08:00
},
}
};
</script>
<style scoped>
.cms-content-list .head-container .el-select .el-input {
width: 110px;
}
2024-07-24 17:24:35 +08:00
2024-07-22 17:30:34 +08:00
.cms-content-list .el-divider {
margin-top: 10px;
}
2024-07-24 17:24:35 +08:00
2024-07-22 17:30:34 +08:00
.cms-content-list .el-tabs__header {
margin-bottom: 10px;
}
2024-07-24 17:24:35 +08:00
2024-07-22 17:30:34 +08:00
.cms-content-list .pagination-container {
height: 30px;
}
2024-07-24 17:24:35 +08:00
2024-07-22 17:30:34 +08:00
.cms-content-list .row-more-btn {
padding-left: 10px;
}
2024-07-24 17:24:35 +08:00
2024-07-22 17:30:34 +08:00
.cms-content-list .top-icon {
font-weight: bold;
font-size: 12px;
2024-07-24 17:24:35 +08:00
color: green;
2024-07-22 17:30:34 +08:00
}
2024-07-24 17:24:35 +08:00
2024-07-22 17:30:34 +08:00
.cms-content-list .content_attr {
margin-left: 2px;
}
2024-07-24 17:24:35 +08:00
.mb12 {
2024-07-22 17:30:34 +08:00
margin-bottom: 12px;
}
</style>