0
点赞
收藏
分享

微信扫一扫

作品管理-作品列表

楚木巽 2022-06-01 阅读 44

前端页面

作品管理-作品列表_ico

后端

定义列表分页查询的方法

作品管理-作品列表_ide_02

/**
 * <b>
 * 分页查询作品列表方法
 * </b>
 */
@ApiOperation(value&nbsp;=&nbsp;&quot;分页查询作品列表方法&quot;)
@GetMapping(&quot;/getContentPageQuery/{page}/{limit}&quot;)
public&nbsp;ResponseResult&nbsp;contentPageQuery(@PathVariable&nbsp;Long&nbsp;page,&nbsp;@PathVariable&nbsp;Long&nbsp;limit,&nbsp;ContentVO&nbsp;contentVO)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;Page&lt;Content&gt;&nbsp;pageParam&nbsp;=&nbsp;new&nbsp;Page&lt;&gt;(page,&nbsp;limit);
&nbsp;&nbsp;&nbsp;&nbsp;contentService.contentPageQuery(pageParam,&nbsp;contentVO);
&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;ResponseResult.ok().data(&quot;total&quot;,&nbsp;pageParam.getTotal()).data(&quot;rows&quot;,&nbsp;pageParam.getRecords());
}

修改 ​​ContentService​

/**
 * <b>
 * 分页查询作品列表方法
 * </b>
 *
 * @param pageParam 分页信息
 * @param contentVO 过滤条件信息实体
 */
void&nbsp;contentPageQuery(Page&lt;Content&gt;&nbsp;pageParam,&nbsp;ContentVO&nbsp;contentVO);

修改 ContentServiceImpl 实现对应的业务

@Override
public&nbsp;void&nbsp;contentPageQuery(Page&lt;Content&gt;&nbsp;pageParam,&nbsp;ContentVO&nbsp;contentVO)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;QueryWrapper&lt;Content&gt;&nbsp;queryWrapper&nbsp;=&nbsp;new&nbsp;QueryWrapper&lt;&gt;();
&nbsp;&nbsp;&nbsp;&nbsp;queryWrapper.orderByDesc(&quot;gmt_create&quot;);

&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(contentVO&nbsp;==&nbsp;null)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;baseMapper.selectPage(pageParam,&nbsp;queryWrapper);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return;
&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(!StringUtils.isEmpty(contentVO.getTitle()))&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;queryWrapper.like(&quot;title&quot;,&nbsp;contentVO.getTitle());
&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(!StringUtils.isEmpty(contentVO.getAuthorId()))&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;queryWrapper.eq(&quot;author_id&quot;,&nbsp;contentVO.getAuthorId());
&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(!StringUtils.isEmpty(contentVO.getCategoryParentId()))&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;queryWrapper.eq(&quot;category_parent_id&quot;,&nbsp;contentVO.getCategoryParentId());
&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(!StringUtils.isEmpty(contentVO.getCategoryId()))&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;queryWrapper.eq(&quot;category_id&quot;,&nbsp;contentVO.getCategoryId());
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;baseMapper.selectPage(pageParam,&nbsp;queryWrapper);
}

前端

在 content.js 当中定义请求接口

作品管理-作品列表_分页_03

// 作品列表
getContentPageList(page,&nbsp;limit,&nbsp;searchObj)&nbsp;{
&nbsp;&nbsp;return&nbsp;request({
&nbsp;&nbsp;&nbsp;&nbsp;url:&nbsp;`/service_video/content/getContentPageQuery/${page}/${limit}`,
    method: 'get',
    params: searchObj
  });
}

在 list.vue 当中引入相关组件与定义数据模型导入对应的 api 方法如下

作品管理-作品列表_ide_04

import&nbsp;content&nbsp;from&nbsp;&quot;@/api/video/content/content&quot;;
import&nbsp;category&nbsp;from&nbsp;&quot;@/api/video/category/category&quot;;

作品管理-作品列表_ico_05

data()&nbsp;{
&nbsp;&nbsp;return&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;// 是否显示loading信息
&nbsp;&nbsp;&nbsp;&nbsp;listLoading:&nbsp;true,
&nbsp;&nbsp;&nbsp;&nbsp;// 数据列表
&nbsp;&nbsp;&nbsp;&nbsp;list:&nbsp;null,
&nbsp;&nbsp;&nbsp;&nbsp;// 总记录数
&nbsp;&nbsp;&nbsp;&nbsp;total:&nbsp;0,
&nbsp;&nbsp;&nbsp;&nbsp;// 页码
&nbsp;&nbsp;&nbsp;&nbsp;page:&nbsp;1,
&nbsp;&nbsp;&nbsp;&nbsp;// 每页记录数
&nbsp;&nbsp;&nbsp;&nbsp;limit:&nbsp;10,
&nbsp;&nbsp;&nbsp;&nbsp;// 查询条件
&nbsp;&nbsp;&nbsp;&nbsp;searchObj:&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;categoryParentId:&nbsp;&#39;&#39;,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;categoryId:&nbsp;&#39;&#39;,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;title:&nbsp;&#39;&#39;,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;authorId:&nbsp;&#39;&#39;
&nbsp;&nbsp;&nbsp;&nbsp;},
&nbsp;&nbsp;&nbsp;&nbsp;// 作者列表
&nbsp;&nbsp;&nbsp;&nbsp;authorList:&nbsp;[],
&nbsp;&nbsp;&nbsp;&nbsp;// 一级分类列表
&nbsp;&nbsp;&nbsp;&nbsp;oneCategoryList:&nbsp;[],
&nbsp;&nbsp;&nbsp;&nbsp;// 二级分类列表
&nbsp;&nbsp;&nbsp;&nbsp;twoCategoryList:&nbsp;[]
&nbsp;&nbsp;}
},

初始化查询下拉列表数据

作品管理-作品列表_ide_06

created()&nbsp;{
&nbsp;&nbsp;// 当页面加载时获取数据
&nbsp;&nbsp;this.getData();
&nbsp;&nbsp;// 初始化分类列表
&nbsp;&nbsp;this.getCategoryList();
&nbsp;&nbsp;// 获取讲师列表
&nbsp;&nbsp;this.initAuthorList();
}

initAuthorList()&nbsp;{
&nbsp;&nbsp;content.getAuthorList().then(res&nbsp;=&gt;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;this.authorList&nbsp;=&nbsp;res.data.list;
&nbsp;&nbsp;}).catch(error&nbsp;=&gt;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;this.$message.error(error.message);
&nbsp;&nbsp;});
},

// 加载所有的分类
getCategoryList()&nbsp;{
&nbsp;&nbsp;// 1.获取一级分类
&nbsp;&nbsp;category.getCategoryData().then(res&nbsp;=&gt;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;this.oneCategoryList&nbsp;=&nbsp;res.data.list;
&nbsp;&nbsp;}).catch(error&nbsp;=&gt;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;this.$message.error(error.message);
&nbsp;&nbsp;});
},
// 当一级分类改变时调用的 方法  参数:当前一级分类选择的id
oneCategoryChanged(value)&nbsp;{
&nbsp;&nbsp;for&nbsp;(let&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;this.oneCategoryList.length;&nbsp;i++)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;let&nbsp;category&nbsp;=&nbsp;this.oneCategoryList[i];

&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(value&nbsp;===&nbsp;category.id)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.twoCategoryList&nbsp;=&nbsp;category.children;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// 清空已经选择的二级分类
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.searchObj.categoryId&nbsp;=&nbsp;&#39;&#39;;
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;}
},

// 调用api层获取数据库中的数据
getData(page&nbsp;=&nbsp;1)&nbsp;{
&nbsp;&nbsp;// 当点击分页组件的切换按钮的时候,会传输一个当前页码的参数page
&nbsp;&nbsp;// 解决分页无效问题
&nbsp;&nbsp;this.page&nbsp;=&nbsp;page;
&nbsp;&nbsp;this.listLoading&nbsp;=&nbsp;true;
&nbsp;&nbsp;content.getContentPageList(this.page,&nbsp;this.limit,&nbsp;this.searchObj).then(response&nbsp;=&gt;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;// debugger 设置断点调试
&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(response.success&nbsp;===&nbsp;true)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.list&nbsp;=&nbsp;response.data.rows;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.total&nbsp;=&nbsp;response.data.total;
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;this.listLoading&nbsp;=&nbsp;false;
&nbsp;&nbsp;}).catch(error&nbsp;=&gt;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;this.$message.error(error.message);
&nbsp;&nbsp;&nbsp;&nbsp;this.listLoading&nbsp;=&nbsp;false;
&nbsp;&nbsp;});
},

搜索查询页面添加

作品管理-作品列表_分页_07

<!--
查询表单
-->
<el-form :inline="true" class="demo-form-inline">
  <!--
  所属分类:级联下拉列表
  -->

  <!--
  一级分类
  -->
  <el-form-item label="分类">
    <el-select
      v-model="searchObj.categoryParentId"
      placeholder="请选择"
      @change="oneCategoryChanged">
      <el-option
        v-for="category in oneCategoryList"
        :key="category.id"
        :label="category.title"
        :value="category.id"/>
    </el-select>
    &nbsp;
    <!--
    二级分类
    -->
    <el-select placeholder="请选择" v-model="searchObj.categoryId">
      <el-option v-for="twoCategory in twoCategoryList"
                 :key="twoCategory.id"
                 :label="twoCategory.title"
                 :value="twoCategory.id"/>
    </el-select>
  </el-form-item>

  <!-- 标题 -->
  <el-form-item>
    <el-input v-model="searchObj.title" placeholder="作品标题"/>
  </el-form-item>

  <!-- 作者 -->
  <el-form-item>
    <el-select
      v-model="searchObj.authorId"
      placeholder="请选择作者">
      <el-option
        v-for="author in authorList"
        :key="author.id"
        :label="author.name"
        :value="author.id"/>
    </el-select>
  </el-form-item>
  <el-button type="primary" icon="el-icon-search" @click="getData()">查询</el-button>
  <el-button type="default" @click="resetData()">清空</el-button>
</el-form>

清空方法实现

resetData()&nbsp;{
&nbsp;&nbsp;this.searchObj&nbsp;=&nbsp;{};
&nbsp;&nbsp;// 二级分类列表
&nbsp;&nbsp;this.twoCategoryList&nbsp;=&nbsp;[];
&nbsp;&nbsp;this.getData();
},

列表页面添加

<el-row :gutter="15">
  <el-col :span="5" v-for="item in list">
    <div class="grid-content bg-purple">
      <img :src="item.cover" alt="scope.row.title" width="100%" height="150px">
      <a href="#" style="font-size: 14px; color: #333">{{ item.title }}</a>
      <p style="margin-top: 0">
        <router-link :to="'/content/info/'+item.id">
          <el-button type="text" size="mini" icon="el-icon-edit">编辑作品信息</el-button>
        </router-link>
        <el-button style="margin-left: 100px" type="text" size="mini"
                   @click="deleteContentById(item.id)" icon="el-icon-delete">删除
        </el-button>
      </p>
      <p style="font-size: 14px; color: red; margin-top: -15px;">
        价格: {{ Number(item.price) === 0 ? '免费' : '¥' + item.price.toFixed(2) }}
      </p>
    </div>
  </el-col>
</el-row>

<!-- 分页 -->
<el-pagination
  :current-page="page"
  :page-size="limit"
  :total="total"
  style="padding: 30px 0; text-align: center;"
  layout="total, prev, pager, next, jumper"
  @current-change="getData"
/>

注意点:需要在最外层套一个 ​​div​​ 如下图,不然使用不了 element-ui

作品管理-作品列表_分页_08

页面样式

&lt;style&nbsp;scoped&gt;
.app-container&nbsp;{
&nbsp;&nbsp;width:&nbsp;1260px;
}

.el-col&nbsp;{
&nbsp;&nbsp;margin-top:&nbsp;10px;
&nbsp;&nbsp;border-radius:&nbsp;4px;
}

.grid-content&nbsp;{
&nbsp;&nbsp;border-radius:&nbsp;4px;
&nbsp;&nbsp;min-height:&nbsp;36px;
&nbsp;&nbsp;height:&nbsp;250px;

}

.row-bg&nbsp;{
&nbsp;&nbsp;padding:&nbsp;10px&nbsp;0;
&nbsp;&nbsp;background-color:&nbsp;#f9fafc;
}
&lt;/style&gt;


举报

相关推荐

0 条评论