提交 4f8f9080 authored 作者: fit2cloud-chenyw's avatar fit2cloud-chenyw

feat: 绑定日期过滤组件

上级 20c0b4b6
<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
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论