feat: 绑定日期过滤组件
This commit is contained in:
parent
20c0b4b68d
commit
4f8f9080cf
@ -1,6 +1,7 @@
|
||||
<template>
|
||||
<el-date-picker
|
||||
v-if="options!== null && options.attrs!==null"
|
||||
ref="dateRef"
|
||||
v-model="options.value"
|
||||
:type="options.attrs.type"
|
||||
:range-separator="options.attrs.rangeSeparator"
|
||||
@ -12,6 +13,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { dateFormat } from '@/utils'
|
||||
export default {
|
||||
|
||||
props: {
|
||||
@ -44,10 +46,41 @@ export default {
|
||||
value: Array.isArray(this.options.value) ? this.options.value : [this.options.value],
|
||||
operator: this.operator
|
||||
}
|
||||
param.value = this.formatValues(param.value)
|
||||
this.inDraw && this.$store.dispatch('conditions/add', param)
|
||||
},
|
||||
dateChange(value) {
|
||||
// const nvalue = dateFormat(value, this.getFormat())
|
||||
// console.log(nvalue)
|
||||
this.setCondition()
|
||||
},
|
||||
formatValues(values) {
|
||||
if (!values || values.length === 0) {
|
||||
return []
|
||||
}
|
||||
return values.map(value => dateFormat(value, this.getFormat()))
|
||||
},
|
||||
getFormat() {
|
||||
let format = 'yyyy'
|
||||
switch (this.options.attrs.type) {
|
||||
case 'year':
|
||||
format = 'yyyy'
|
||||
break
|
||||
case 'month':
|
||||
format = 'yyyy-MM'
|
||||
break
|
||||
case 'date':
|
||||
format = 'yyyy-MM-dd'
|
||||
break
|
||||
case 'daterange':
|
||||
format = 'yyyy-MM-dd'
|
||||
this.operator = 'in'
|
||||
break
|
||||
default:
|
||||
format = 'yyyy'
|
||||
break
|
||||
}
|
||||
return format
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,6 +2,26 @@
|
||||
* Created by PanJiaChen on 16/11/18.
|
||||
*/
|
||||
|
||||
export function dateFormat(date, fmt) {
|
||||
let ret
|
||||
const opt = {
|
||||
'y+': date.getFullYear().toString(), // 年
|
||||
'M+': (date.getMonth() + 1).toString(), // 月
|
||||
'd+': date.getDate().toString(), // 日
|
||||
'H+': date.getHours().toString(), // 时
|
||||
'm+': date.getMinutes().toString(), // 分
|
||||
's+': date.getSeconds().toString() // 秒
|
||||
// 有其他格式化字符需求可以继续添加,必须转化成字符串
|
||||
}
|
||||
for (const k in opt) {
|
||||
ret = new RegExp('(' + k + ')').exec(fmt)
|
||||
if (ret) {
|
||||
fmt = fmt.replace(ret[1], (ret[1].length === 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, '0')))
|
||||
}
|
||||
}
|
||||
return fmt
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the time to string
|
||||
* @param {(Object|string|number)} time
|
||||
|
||||
Loading…
Reference in New Issue
Block a user