update 更多查询条件
This commit is contained in:
@@ -38,4 +38,7 @@ export const RSA_PUBLIC_KEY = '-----BEGIN PUBLIC KEY-----MIGfMA0GCSqGSIb3DQEBAQU
|
||||
*/
|
||||
export const CITY = '黄石市'
|
||||
|
||||
/**
|
||||
* 响应式响应宽度
|
||||
*/
|
||||
export const SIDER_BREAK_POINT = 1366
|
||||
@@ -1,3 +1,41 @@
|
||||
import moment from 'moment'
|
||||
|
||||
/**
|
||||
* 从键值对的query类型转换成数组类型
|
||||
* 键:自动作为field值
|
||||
* 值:得到一个数组作为value的值
|
||||
* queryType:一个json类型,已query的键为键,QueryType为值. 如果是一个QueryType的数组,则自动对应到value中的各个值
|
||||
* 示例:
|
||||
*
|
||||
getSearchInfo({
|
||||
query: {
|
||||
value: '123',
|
||||
text: '123',
|
||||
code: 'abc',
|
||||
check: ['1', '2', '3'],
|
||||
range: [1, 10]
|
||||
},
|
||||
queryType: {
|
||||
text: QueryType.Equal,
|
||||
code: QueryType.Like,
|
||||
check: QueryType.Equal,
|
||||
range: [QueryType.GreaterThanOrEqual, QueryType.LessThan]
|
||||
}
|
||||
})
|
||||
|
||||
=>
|
||||
|
||||
[
|
||||
{ field: 'value', value: ['123'] },
|
||||
{ field: 'text', value: ['123'], type: '=' },
|
||||
{ field: 'code', value: ['abc'], type: 'like' },
|
||||
{ field: 'check', value: ['1', '2', '3'], type: '=' },
|
||||
{ field: 'range', value: [1], type: '>=' },
|
||||
{ field: 'range', value: [10], type: '<' }
|
||||
]
|
||||
* @param {*} param0
|
||||
* @returns [{ field: '', value: [], type: '' } ...]
|
||||
*/
|
||||
export const getSearchInfo = ({ query, queryType }) => {
|
||||
const searchInfo = []
|
||||
Object.keys(query).forEach((p) => {
|
||||
@@ -38,4 +76,32 @@ export const getSearchInfo = ({ query, queryType }) => {
|
||||
})
|
||||
|
||||
return searchInfo
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取查询用时间范围数组
|
||||
* 在这里会自动将第二个时间增加1天
|
||||
* 如果选择的日期范围为2021-01-01~2021-01-10,最终需要取得 >=2021-01-01 and <2021-01-11 的结果
|
||||
* @param {*} range 时间范围数组
|
||||
* @param {*} format 格式化
|
||||
* @returns
|
||||
*/
|
||||
export const getSearchDateRange = (range, format = 'YYYY-MM-DD', unit = 'days') => {
|
||||
if (Array.isArray(range) && range.length === 2) {
|
||||
range[1] = moment(range[1]).add(1, unit)
|
||||
range = range.map(p => moment(p).format(format))
|
||||
}
|
||||
return range
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询条件类型
|
||||
*/
|
||||
export const QueryType = {
|
||||
GreaterThan: '>',
|
||||
GreaterThanOrEqual: '>=',
|
||||
LessThan: '<',
|
||||
LessThanOrEqual: '<=',
|
||||
Like: 'LIKE',
|
||||
Equal: '='
|
||||
}
|
||||
Reference in New Issue
Block a user