调整列表工具类
This commit is contained in:
@@ -26,19 +26,21 @@ module.exports = {
|
||||
console.log(`${chalk.bgBlue.black(" DATABASE ")} 数据库已连接`)
|
||||
},
|
||||
query,
|
||||
list: ({table, search, con = '', sort}) => {
|
||||
list: ({table, search, con = 'name', sort}) => {
|
||||
//列表查询
|
||||
let total = 0, records = []
|
||||
if (table) {
|
||||
const {current, size = 10} = search, params = JSON.parse(JSON.stringify(search))
|
||||
const conValue = params[con]
|
||||
delete params.current
|
||||
delete params.size
|
||||
delete params[con]
|
||||
const sqlCon = Object.keys(params).map(e => `and ${e}='${params[e]}'`).join(" ")
|
||||
return Promise.all([
|
||||
query(`select 1 from ${table} where name like '%${con}%' ${sqlCon}`).then(res => {
|
||||
query(`select 1 from ${table} where ${con} like '%${conValue}%' ${sqlCon}`).then(res => {
|
||||
return total = res.length
|
||||
}),
|
||||
query(`select * from ${table} where name like '%${con}%' ${sqlCon} order by ${sort||'createTime'} desc limit ${((current-1)||0)*size},${size}`).then(res => {
|
||||
query(`select * from ${table} where ${con} like '%${conValue}%' ${sqlCon} order by ${sort||'createTime'} desc limit ${((current-1)||0)*size},${size}`).then(res => {
|
||||
return records = res
|
||||
})
|
||||
]).then(() => {
|
||||
|
||||
Reference in New Issue
Block a user