帖子管理模糊查询&前端优化

This commit is contained in:
linfeng 2022-05-11 17:17:12 +08:00
parent c6d4b384ac
commit c7e6667f8f
3 changed files with 73 additions and 39 deletions

View File

@ -73,4 +73,15 @@ public class WechatUtil {
}
return null;
}
/**
* @Title: isEmpty
* @Description: 判断对象是否为空
* @param obj
* @return
* @return Integer
*/
public static boolean isEmpty(Object obj) {
return null == obj || "".equals(obj);
}
}

View File

@ -1,5 +1,6 @@
package io.linfeng.modules.admin.service.impl;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@ -53,30 +54,43 @@ public class PostServiceImpl extends ServiceImpl<PostDao, PostEntity> implements
@Override
public PageUtils queryPage(Map<String, Object> params) {
QueryWrapper<PostEntity> queryWrapper=new QueryWrapper<>();
//条件查询
String key = (String)params.get("key");
String status = (String)params.get("status");
if(!WechatUtil.isEmpty(key)){
params.put("page","1");//如果是查询分页重置为第一页
queryWrapper.like("content", key).or().like("title",key);
}
if(!WechatUtil.isEmpty(status)){
params.put("page","1");//如果是查询分页重置为第一页
queryWrapper.eq("status", Integer.parseInt(status));
}
queryWrapper.lambda().orderByDesc(PostEntity::getId);
IPage<PostEntity> page = this.page(
new Query<PostEntity>().getPage(params),
new QueryWrapper<>()
queryWrapper
);
List<PostEntity> data = page.getRecords();
List<PostListResponse> responseList = new ArrayList<>();
data.forEach(l -> {
PostListResponse response = new PostListResponse();
BeanUtils.copyProperties(l, response);
if (response.getDiscussId() > 0) {
List<PostListResponse> responseList=new ArrayList<>();
data.forEach(l->{
PostListResponse response=new PostListResponse();
BeanUtils.copyProperties(l,response);
if(ObjectUtil.isNotNull(response.getDiscussId())&&response.getDiscussId()>0){
DiscussEntity discussEntity = discussService.getById(response.getDiscussId());
response.setDiscussTitle(discussEntity.getTitle());
if(ObjectUtil.isNotNull(discussEntity)){
response.setDiscussTitle(discussEntity.getTitle());
}
}
response.setTopicName(topicService.getById(response.getTopicId()).getTopicName());
response.setCollectionCount(postCollectionService.collectCount(response.getId()));
response.setCommentCount(commentService.getCountByTopicId(response.getId()));
response.setUserInfo(appUserService.getById(response.getUid()));
String jsonString = l.getMedia();
List<String> list = JsonUtils.JsonToList(jsonString);
response.setMedia(list);
response.setMedia(JsonUtils.JsonToList(l.getMedia()));
responseList.add(response);
});
PageUtils pageUtils = new PageUtils(page);
PageUtils pageUtils=new PageUtils(page);
pageUtils.setList(responseList);
return pageUtils;
}

View File

@ -5,21 +5,26 @@
:model="dataForm"
@keyup.enter.native="getDataList()"
>
<!-- <el-form-item>
<el-form-item>
<el-input
v-model="dataForm.key"
placeholder="请输入帖子内容搜索"
placeholder="帖子内容或标题搜索"
clearable
></el-input>
</el-form-item> -->
<el-form-item>
<!-- <el-button @click="getDataList()">查询</el-button> -->
<!-- <el-form-item>
<el-radio v-model="dataForm.status" label="0">正常</el-radio>
<el-radio v-model="dataForm.status" label="1">待审核</el-radio>
<el-radio v-model="dataForm.status" label="2">已下架</el-radio>
</el-form-item>
<el-button @click="getDataList()">查询</el-button> -->
<el-form-item>
<!-- 选择框 -->
<el-select v-model="dataForm.status" clearable placeholder="请选择状态">
<el-option
v-for="item in options"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
<el-button @click="getDataList()">查询</el-button>
<el-button @click="refresh()">重置</el-button>
<!-- <el-button
v-if="isAuth('admin:post:delete')"
@ -123,20 +128,6 @@
label="文件"
>
<template slot-scope="scope">
<!-- <img
v-if="scope.row.type == 1 && scope.row.media[0]"
style="width: 80px; height: 50px"
:src="scope.row.media[0]"
/> -->
<!-- <video
v-if="scope.row.type == 2"
class="myVideo"
id="myVideo"
:src="scope.row.media[0]"
enable-danmu
danmu-btn
controls
></video> -->
<el-button v-if="scope.row.type == 2" type="text" @click="openVideo(scope.row.media[0])">点击预览</el-button>
<el-button v-if="scope.row.type == 1 && scope.row.media[0]" type="text" @click="openPic(scope.row.media)">点击查看</el-button>
</template>
@ -162,13 +153,13 @@
label="点赞数"
>
</el-table-column>
<!-- <el-table-column
<el-table-column
prop="discussTitle"
header-align="center"
align="center"
label="话题"
>
</el-table-column> -->
</el-table-column>
<el-table-column
prop="postTop"
header-align="center"
@ -334,6 +325,17 @@ export default {
dialogVisible2: false,
videoUrl:"",
media: [],
options: [{
value: 0,
label: '正常'
}, {
value: 1,
label: '待审核'
}, {
value: 2,
label: '已下架'
}],
// value: ''
};
},
components: {
@ -343,6 +345,13 @@ export default {
this.getDataList();
},
methods: {
refresh(){
this.dataForm.key='';
this.dataForm.status='';
this.pageIndex=1;
this.pageSize=10;
this.getDataList();
},
//
getDataList() {
this.dataListLoading = true;
@ -352,8 +361,8 @@ export default {
params: this.$http.adornParams({
page: this.pageIndex,
limit: this.pageSize,
// key: this.dataForm.key,
// status:this.dataForm.status
key: this.dataForm.key,
status:this.dataForm.status
}),
}).then(({ data }) => {
if (data && data.code === 0) {