branch_lyj
Liuyujie 7 months ago
parent aa13a6a04d
commit 8e314e8961

@ -1,9 +1,14 @@
<template> 
<template>
<!-- 整个页面的容器用于包裹内部的各个组件 -->
<div class="app-container">
<!-- el-card组件作为筛选搜索区域的容器设置阴影效果为"never"即无阴影 -->
<el-card class="filter-container" shadow="never">
<div>
<!-- 使用el-icon-search图标用于表示搜索相关的视觉元素 -->
<i class="el-icon-search"></i>
<!-- 显示"筛选搜索"的文字提示 -->
<span>筛选搜索</span>
<!-- el-button按钮组件样式设置为右浮动按钮类型为"primary"主要按钮样式通常为主题色等突出显示点击时调用handleSearchList方法按钮大小为"small" -->
<el-button
style="float:right"
type="primary"
@ -11,6 +16,7 @@
size="small">
查询搜索
</el-button>
<!-- el-button按钮组件样式设置为右浮动且距离右边距15px点击时调用handleResetSearch方法按钮大小为"small"用于重置相关操作 -->
<el-button
style="float:right;margin-right: 15px"
@click="handleResetSearch()"
@ -19,12 +25,18 @@
</el-button>
</div>
<div style="margin-top: 15px">
<!-- el-form表单组件设置为行内表单形式绑定的数据模型是listQuery表单尺寸为"small"标签宽度为140px -->
<el-form :inline="true" :model="listQuery" size="small" label-width="140px">
<!-- el-form-item表单项目组件用于输入框的包裹此处对应的标签文本为"专题名称:" -->
<el-form-item label="专题名称:">
<!-- el-input输入框组件双向绑定数据到listQuery.subjectName设置输入框的类名为"input-width"有相应的占位提示文字 -->
<el-input v-model="listQuery.subjectName" class="input-width" placeholder="专题名称"></el-input>
</el-form-item>
<!-- el-form-item表单项目组件用于下拉选择框的包裹对应的标签文本为"推荐状态:" -->
<el-form-item label="推荐状态:">
<!-- el-select下拉选择框组件双向绑定数据到listQuery.recommendStatus有相应的占位提示文字可清空选择设置类名为"input-width" -->
<el-select v-model="listQuery.recommendStatus" placeholder="全部" clearable class="input-width">
<!-- 通过v-for循环遍历recommendOptions数组生成el-option下拉选项每个选项根据item中的属性设置相应的键显示标签和值 -->
<el-option v-for="item in recommendOptions"
:key="item.value"
:label="item.label"
@ -35,24 +47,34 @@
</el-form>
</div>
</el-card>
<!-- el-card组件作为操作相关区域的容器设置阴影效果为"never"即无阴影 -->
<el-card class="operate-container" shadow="never">
<!-- 使用el-icon-tickets图标用于表示相关操作的视觉元素 -->
<i class="el-icon-tickets"></i>
<!-- 显示"数据列表"的文字提示 -->
<span>数据列表</span>
<!-- el-button按钮组件按钮尺寸为"mini"点击时调用handleSelectSubject方法按钮样式类名为"btn-add"用于选择专题操作 -->
<el-button size="mini" class="btn-add" @click="handleSelectSubject()"></el-button>
</el-card>
<!-- 作为表格显示区域的容器 -->
<div class="table-container">
<!-- el-table表格组件引用了ref为"newSubjectTable"绑定的数据为list设置宽度为100%监听行选择变化事件绑定加载状态到listLoading变量显示表格边框 -->
<el-table ref="newSubjectTable"
:data="list"
style="width: 100%;"
@selection-change="handleSelectionChange"
v-loading="listLoading" border>
<!-- el-table-column表格列组件设置列类型为"selection"用于行选择的复选框列宽度为60px内容居中对齐 -->
<el-table-column type="selection" width="60" align="center"></el-table-column>
<!-- el-table-column表格列组件对应的标签为"编号"宽度为120px内容居中对齐通过插槽作用域展示对应行数据中的id属性 -->
<el-table-column label="编号" width="120" align="center">
<template slot-scope="scope">{{scope.row.id}}</template>
</el-table-column>
<!-- el-table-column表格列组件对应的标签为"专题名称"内容居中对齐通过插槽作用域展示对应行数据中的subjectName属性 -->
<el-table-column label="专题名称" align="center">
<template slot-scope="scope">{{scope.row.subjectName}}</template>
</el-table-column>
<!-- el-table-column表格列组件对应的标签为"是否推荐"宽度为200px内容居中对齐内部包含一个el-switch开关组件用于切换推荐状态绑定相应的事件和值 -->
<el-table-column label="是否推荐" width="200" align="center">
<template slot-scope="scope">
<el-switch
@ -63,12 +85,15 @@
</el-switch>
</template>
</el-table-column>
<!-- el-table-column表格列组件对应的标签为"排序"宽度为160px内容居中对齐通过插槽作用域展示对应行数据中的sort属性 -->
<el-table-column label="排序" width="160" align="center">
<template slot-scope="scope">{{scope.row.sort}}</template>
</el-table-column>
<!-- el-table-column表格列组件对应的标签为"状态"宽度为160px内容居中对齐通过过滤器formatRecommendStatus对推荐状态数据进行格式化展示 -->
<el-table-column label="状态" width="160" align="center">
<template slot-scope="scope">{{scope.row.recommendStatus | formatRecommendStatus}}</template>
</el-table-column>
<!-- el-table-column表格列组件对应的标签为"操作"宽度为180px内容居中对齐内部包含两个el-button按钮组件分别用于设置排序和删除操作绑定对应的点击事件 -->
<el-table-column label="操作" width="180" align="center">
<template slot-scope="scope">
<el-button size="mini"
@ -83,10 +108,13 @@
</el-table-column>
</el-table>
</div>
<!-- 作为批量操作区域的容器 -->
<div class="batch-operate-container">
<!-- el-select下拉选择框组件尺寸为"small"双向绑定数据到operateType有相应的占位提示文字 -->
<el-select
size="small"
v-model="operateType" placeholder="批量操作">
<!-- 通过v-for循环遍历operates数组生成el-option下拉选项每个选项根据item中的属性设置相应的键显示标签和值 -->
<el-option
v-for="item in operates"
:key="item.value"
@ -94,6 +122,7 @@
:value="item.value">
</el-option>
</el-select>
<!-- el-button按钮组件距离左边距20px样式类名为"search-button"点击时调用handleBatchOperate方法按钮类型为"primary"主要按钮样式按钮尺寸为"small"用于确定批量操作 -->
<el-button
style="margin-left: 20px"
class="search-button"
@ -103,7 +132,9 @@
确定
</el-button>
</div>
<!-- 作为分页区域的容器 -->
<div class="pagination-container">
<!-- el-pagination分页组件设置背景色监听页面尺寸变化和当前页变化事件设置分页布局样式绑定每页显示数量可选的每页显示数量数组当前页码以及总数据量等相关属性 -->
<el-pagination
background
@size-change="handleSizeChange"
@ -115,27 +146,35 @@
:total="total">
</el-pagination>
</div>
<!-- el-dialog对话框组件标题为"选择专题"对话框显示状态双向绑定到selectDialogVisible变量宽度设置为50% -->
<el-dialog title="选择专题" :visible.sync="selectDialogVisible" width="50%">
<!-- el-input输入框组件双向绑定数据到dialogData.listQuery.keyword设置宽度底边距以及尺寸等样式属性有相应的占位提示文字内部包含一个用于搜索操作的el-button按钮 -->
<el-input v-model="dialogData.listQuery.keyword"
style="width: 250px;margin-bottom: 20px"
size="small"
placeholder="专题名称搜索">
<el-button slot="append" icon="el-icon-search" @click="handleSelectSearch()"></el-button>
</el-input>
<!-- el-table表格组件绑定的数据为dialogData.list监听行选择变化事件显示表格边框 -->
<el-table :data="dialogData.list"
@selection-change="handleDialogSelectionChange" border>
<!-- el-table-column表格列组件设置列类型为"selection"用于行选择的复选框列宽度为60px内容居中对齐 -->
<el-table-column type="selection" width="60" align="center"></el-table-column>
<!-- el-table-column表格列组件对应的标签为"专题名称"内容居中对齐通过插槽作用域展示对应行数据中的title属性 -->
<el-table-column label="专题名称" align="center">
<template slot-scope="scope">{{scope.row.title}}</template>
</el-table-column>
<!-- el-table-column表格列组件对应的标签为"所属分类"宽度为160px内容居中对齐通过插槽作用域展示对应行数据中的categoryName属性 -->
<el-table-column label="所属分类" width="160" align="center">
<template slot-scope="scope">{{scope.row.categoryName}}</template>
</el-table-column>
<!-- el-table-column表格列组件对应的标签为"添加时间"宽度为160px内容居中对齐通过过滤器formatTime对时间数据进行格式化展示 -->
<el-table-column label="添加时间" width="160" align="center">
<template slot-scope="scope">{{scope.row.createTime | formatTime}}</template>
</el-table-column>
</el-table>
<div class="pagination-container">
<!-- el-pagination分页组件设置背景色监听对话框内页面尺寸变化和当前页变化事件设置分页布局样式绑定对话框内每页显示数量当前页码以及总数据量等相关属性 -->
<el-pagination
background
@size-change="handleDialogSizeChange"
@ -149,291 +188,340 @@
</div>
<div style="clear: both;"></div>
<div slot="footer">
<!-- el-button按钮组件按钮尺寸为"small"点击时关闭对话框设置selectDialogVisible为false -->
<el-button size="small" @click="selectDialogVisible = false"> </el-button>
<!-- el-button按钮组件按钮尺寸为"small"按钮类型为"primary"主要按钮样式点击时调用handleSelectDialogConfirm方法用于确定操作 -->
<el-button size="small" type="primary" @click="handleSelectDialogConfirm()"> </el-button>
</div>
</el-dialog>
<!-- el-dialog对话框组件标题为"设置排序"对话框显示状态双向绑定到sortDialogVisible变量宽度设置为40% -->
<el-dialog title="设置排序"
:visible.sync="sortDialogVisible"
width="40%">
<!-- el-form表单组件绑定的数据模型是sortDialogData标签宽度为150px -->
<el-form :model="sortDialogData"
label-width="150px">
<!-- el-form-item表单项目组件对应的标签为"排序:"内部包含一个el-input输入框组件用于输入排序相关的值设置输入框宽度 -->
<el-form-item label="排序:">
<el-input v-model="sortDialogData.sort" style="width: 200px"></el-input>
</el-form-item>
</el-form>
<span slot="footer">
<!-- el-button按钮组件点击时关闭对话框设置sortDialogVisible为false按钮尺寸为"small" -->
<el-button @click="sortDialogVisible = false" size="small"> </el-button>
<!-- el-button按钮组件按钮类型为"primary"主要按钮样式点击时调用handleUpdateSort方法按钮尺寸为"small"用于确定排序设置操作 -->
<el-button type="primary" @click="handleUpdateSort" size="small"> </el-button>
</span>
</el-dialog>
</div>
</template>
<script>
import {fetchList,updateRecommendStatus,deleteHomeSubject,createHomeSubject,updateHomeSubjectSort} from '@/api/homeSubject';
import {fetchList as fetchSubjectList} from '@/api/subject';
import {formatDate} from '@/utils/date';
// '@/api/homeSubject'
import {fetchList,updateRecommendStatus,deleteHomeSubject,createHomeSubject,updateHomeSubjectSort} from '@/api/homeSubject';
// '@/api/subject'fetchListfetchSubjectList
import {fetchList as fetchSubjectList} from '@/api/subject';
// '@/utils/date'formatDate
import {formatDate} from '@/utils/date';
const defaultListQuery = {
pageNum: 1,
pageSize: 5,
subjectName: null,
recommendStatus: null
};
const defaultRecommendOptions = [
{
label: '未推荐',
value: 0
},
{
label: '推荐中',
value: 1
}
];
export default {
name: 'homeSubjectList',
data() {
return {
listQuery: Object.assign({}, defaultListQuery),
recommendOptions: Object.assign({}, defaultRecommendOptions),
//
const defaultListQuery = {
pageNum: 1,
pageSize: 5,
subjectName: null,
recommendStatus: null
};
//
const defaultRecommendOptions = [
{
label: '未推荐',
value: 0
},
{
label: '推荐中',
value: 1
}
];
export default {
name: 'homeSubjectList',
data() {
return {
// defaultListQuery便
listQuery: Object.assign({}, defaultListQuery),
// defaultRecommendOptions
recommendOptions: Object.assign({}, defaultRecommendOptions),
// null
list: null,
// null
total: null,
// truefalse
listLoading: false,
//
multipleSelection: [],
//
operates: [
{
label: "设为推荐",
value: 0
},
{
label: "取消推荐",
value: 1
},
{
label: "删除",
value: 2
}
],
// null
operateType: null,
// falsetrue
selectDialogVisible: false,
//
dialogData: {
list: null,
total: null,
listLoading: false,
multipleSelection: [],
operates: [
{
label: "设为推荐",
value: 0
},
{
label: "取消推荐",
value: 1
},
{
label: "删除",
value: 2
}
],
operateType: null,
selectDialogVisible:false,
dialogData:{
list: null,
total: null,
multipleSelection:[],
listQuery:{
keyword: null,
pageNum: 1,
pageSize: 5
}
},
sortDialogVisible:false,
sortDialogData:{sort:0,id:null}
listQuery: {
keyword: null,
pageNum: 1,
pageSize: 5
}
},
// falsetrue
sortDialogVisible: false,
// id
sortDialogData: { sort: 0, id: null }
}
},
created() {
// getList
this.getList();
},
filters: {
// 1""""
formatRecommendStatus(status) {
if (status === 1) {
return '推荐中';
} else {
return '未推荐';
}
},
created() {
// "N/A"
formatTime(time) {
if (time == null || time === '') {
return 'N/A';
}
let date = new Date(time);
return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
},
},
methods: {
// defaultListQuery
handleResetSearch() {
this.listQuery = Object.assign({}, defaultListQuery);
},
// 1getList
handleSearchList() {
this.listQuery.pageNum = 1;
this.getList();
},
filters:{
formatRecommendStatus(status){
if(status===1){
return '推荐中';
}else{
return '未推荐';
}
},
formatTime(time){
if(time==null||time===''){
return 'N/A';
}
let date = new Date(time);
return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
},
// multipleSelection使
handleSelectionChange(val) {
this.multipleSelection = val;
},
methods: {
handleResetSearch() {
this.listQuery = Object.assign({}, defaultListQuery);
},
handleSearchList() {
this.listQuery.pageNum = 1;
this.getList();
},
handleSelectionChange(val){
this.multipleSelection = val;
},
handleSizeChange(val) {
this.listQuery.pageNum = 1;
this.listQuery.pageSize = val;
this.getList();
},
handleCurrentChange(val) {
this.listQuery.pageNum = val;
this.getList();
},
handleRecommendStatusStatusChange(index,row){
this.updateRecommendStatusStatus(row.id,row.recommendStatus);
},
handleDelete(index,row){
this.deleteSubject(row.id);
},
handleBatchOperate(){
if (this.multipleSelection < 1) {
// 1getList
handleSizeChange(val) {
this.listQuery.pageNum = 1;
this.listQuery.pageSize = val;
this.getList();
},
// getList
handleCurrentChange(val) {
this.listQuery.pageNum = val;
this.getList();
},
// updateRecommendStatusStatusid
handleRecommendStatusStatusChange(index, row) {
this.updateRecommendStatusStatus(row.id, row.recommendStatus);
},
// deleteSubjectid
handleDelete(index, row) {
this.deleteSubject(row.id);
},
//
//
handleBatchOperate() {
if (this.multipleSelection < 1) { //
this.$message({
message: '请选择一条记录',
type: 'warning',
duration: 1000
});
return;
}
let ids = []; //
for (let i = 0; i < this.multipleSelection.length; i++) {
ids.push(this.multipleSelection[i].id);
}
if (this.operateType === 0) {
//
this.updateRecommendStatusStatus(ids, 1);
} else if (this.operateType === 1) {
//
this.updateRecommendStatusStatus(ids, 0);
} else if (this.operateType === 2) {
//
this.deleteSubject(ids);
} else {
this.$message({
message: '请选择批量操作类型',
type: 'warning',
duration: 1000
});
}
},
//
handleSelectSubject() {
this.selectDialogVisible = true;
this.dialogData.listQuery.keyword = null;
this.getDialogList();//getDialogList
},
//
handleSelectSearch() {
this.getDialogList(); //getDialogList
},
//
handleDialogSizeChange(val) {
this.dialogData.listQuery.pageNum = 1; //1
this.dialogData.listQuery.pageSize = val;
this.getDialogList(); //getDialogList
},
//
handleDialogCurrentChange(val) {
this.dialogData.listQuery.pageNum = val;
this.getDialogList(); //getDialogList
},
// 使
handleDialogSelectionChange(val) {
this.dialogData.multipleSelection = val;
},
//
handleSelectDialogConfirm() {
if (this.dialogData.multipleSelection < 1) {
this.$message({
message: '请选择一条记录',
type: 'warning',
duration: 1000
});
return;
}
let selectSubjects = [];
for (let i = 0; i < this.dialogData.multipleSelection.length; i++) {
selectSubjects.push({
subjectId: this.dialogData.multipleSelection[i].id,
subjectName: this.dialogData.multipleSelection[i].title
});
}
this.$confirm('使用要进行添加操作?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
createHomeSubject(selectSubjects).then(response => { //// createHomeSubject
this.selectDialogVisible = false;
this.dialogData.multipleSelection = [];
this.getList();
this.$message({
message: '请选择一条记录',
type: 'warning',
duration: 1000
type: 'success',
message: '添加成功!'
});
return;
}
let ids = [];
for (let i = 0; i < this.multipleSelection.length; i++) {
ids.push(this.multipleSelection[i].id);
}
if (this.operateType === 0) {
//
this.updateRecommendStatusStatus(ids,1);
} else if (this.operateType === 1) {
//
this.updateRecommendStatusStatus(ids,0);
} else if(this.operateType===2){
//
this.deleteSubject(ids);
}else {
});
});
},
//
handleEditSort(index, row) {
this.sortDialogVisible = true;
this.sortDialogData.sort = row.sort;
this.sortDialogData.id = row.id; //id
},
//
handleUpdateSort() {
this.$confirm('是否要修改排序?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
updateHomeSubjectSort(this.sortDialogData).then(response => { //updateHomeSubjectSort
this.sortDialogVisible = false;
this.getList();
this.$message({
message: '请选择批量操作类型',
type: 'warning',
duration: 1000
type: 'success',
message: '删除成功!' //updateHomeSubjectSort
});
}
},
handleSelectSubject(){
this.selectDialogVisible=true;
this.dialogData.listQuery.keyword=null;
this.getDialogList();
},
handleSelectSearch(){
this.getDialogList();
},
handleDialogSizeChange(val) {
this.dialogData.listQuery.pageNum = 1;
this.dialogData.listQuery.pageSize = val;
this.getDialogList();
},
handleDialogCurrentChange(val) {
this.dialogData.listQuery.pageNum = val;
this.getDialogList();
},
handleDialogSelectionChange(val){
this.dialogData.multipleSelection = val;
},
handleSelectDialogConfirm(){
if (this.dialogData.multipleSelection < 1) {
});
})
},
//
getList() {
this.listLoading = true; //true
fetchList(this.listQuery).then(response => { //fetchList
this.listLoading = false; //false
this.list = response.data.list; ////
this.total = response.data.total;
})
},
//
updateRecommendStatusStatus(ids, status) {
this.$confirm('是否要修改推荐状态?', '提示', { //
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
let params = new URLSearchParams(); //URLSearchParamsid
params.append("ids", ids);
params.append("finalRecommendStatus", status);
updateRecommendStatus(params).then(response => { //// updateRecommendStatus
this.getList();
this.$message({
message: '请选择一条记录',
type: 'warning',
duration: 1000
});
return;
}
let selectSubjects = [];
for (let i = 0; i < this.dialogData.multipleSelection.length; i++) {
selectSubjects.push({
subjectId:this.dialogData.multipleSelection[i].id,
subjectName:this.dialogData.multipleSelection[i].title
});
}
this.$confirm('使用要进行添加操作?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
createHomeSubject(selectSubjects).then(response=>{
this.selectDialogVisible=false;
this.dialogData.multipleSelection=[];
this.getList();
this.$message({
type: 'success',
message: '添加成功!'
});
type: 'success',
message: '修改成功!' //
});
});
},
handleEditSort(index,row){
this.sortDialogVisible=true;
this.sortDialogData.sort=row.sort;
this.sortDialogData.id=row.id;
},
handleUpdateSort(){
this.$confirm('是否要修改排序?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
updateHomeSubjectSort(this.sortDialogData).then(response=>{
this.sortDialogVisible=false;
this.getList();
this.$message({
type: 'success',
message: '删除成功!'
});
});
})
},
getList() {
this.listLoading = true;
fetchList(this.listQuery).then(response => {
this.listLoading = false;
this.list = response.data.list;
this.total = response.data.total;
})
},
updateRecommendStatusStatus(ids,status){
this.$confirm('是否要修改推荐状态?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
let params=new URLSearchParams();
params.append("ids",ids);
params.append("recommendStatus",status);
updateRecommendStatus(params).then(response=>{
this.getList();
this.$message({
type: 'success',
message: '修改成功!'
});
});
}).catch(() => {
}).catch(() => {
this.$message({
type: 'success',
message: '已取消操作!' //
});
this.getList();
});
},
//
deleteSubject(ids) {
this.$confirm('是否要删除该推荐?', '提示', { //
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
let params = new URLSearchParams(); //URLSearchParamsid
params.append("ids", ids);
deleteHomeSubject(params).then(response => { //// deleteHomeSubject
this.getList();
this.$message({
type: 'success',
message: '已取消操作!'
message: '删除成功!' //
});
this.getList();
});
},
deleteSubject(ids){
this.$confirm('是否要删除该推荐?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
let params=new URLSearchParams();
params.append("ids",ids);
deleteHomeSubject(params).then(response=>{
this.getList();
this.$message({
type: 'success',
message: '删除成功!'
});
});
})
},
getDialogList(){
fetchSubjectList(this.dialogData.listQuery).then(response=>{
this.dialogData.list=response.data.list;
this.dialogData.total=response.data.total;
})
}
})
},
//
getDialogList() {
fetchSubjectList(this.dialogData.listQuery).then(response => { //fetchSubjectList
this.dialogData.list = response.data.list; //
this.dialogData.total = response.data.total;
})
}
}
}
</script>
<style></style>

Loading…
Cancel
Save