Commit a8a504f4 authored by Xuguangxing's avatar Xuguangxing

feat: 查询条件增加模糊搜索,列表排序按照id倒序

parent c7f26271
...@@ -54,22 +54,32 @@ export default class ArticeService extends Service { ...@@ -54,22 +54,32 @@ export default class ArticeService extends Service {
} }
// 获取导航列表 // 获取导航列表
async getList(pageNo, pageSize, name = '', author = '') { async getList(pageNo, pageSize, name = '', author = '') {
const offset = (+pageNo - 1) * pageSize;; const offset = (+pageNo - 1) * pageSize;
const condition = { const condition = {
author: null, author: null,
name: null name: null
}; };
// 模糊匹配作者 // 模糊匹配作者
if (author) condition.author = author; if (author) {
// 模糊匹配名称 condition.author = {
if (name) condition.name = name; $like: '%' + author + '%'
};
}
if (name) {
condition.name = {
$like: '%' + name + '%'
};
}
if (!condition.author) delete condition.author; if (!condition.author) delete condition.author;
if (!condition.name) delete condition.name; if (!condition.name) delete condition.name;
const res = await this.context.model.NavigatorConfig const res = await this.context.model.NavigatorConfig
.findAndCountAll({ .findAndCountAll({
where: condition, where: condition,
limit: +pageSize, limit: +pageSize,
offset offset,
order: [
['id', 'DESC']
],
}) })
const result = { const result = {
total: res.count || 0, total: res.count || 0,
...@@ -85,10 +95,16 @@ export default class ArticeService extends Service { ...@@ -85,10 +95,16 @@ export default class ArticeService extends Service {
name: null, name: null,
id: null id: null
}; };
// 模糊匹配作者 if (author) {
if (author) condition.author = author; condition.author = {
// 模糊匹配名称 $like: '%' + author + '%'
if (name) condition.name = name; };
}
if (name) {
condition.name = {
$like: '%' + name + '%'
};
}
if (id) { if (id) {
condition.id = { condition.id = {
$notIn: [id] $notIn: [id]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment