提交 955a0ec6 authored 作者: fit2cloud-chenyw's avatar fit2cloud-chenyw

feat: 时间组件参数改为时间戳

上级 c38bc7f3
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
</template> </template>
<script> <script>
import { dateFormat } from '@/utils' import { timeSection } from '@/utils'
export default { export default {
props: { props: {
...@@ -29,7 +29,7 @@ export default { ...@@ -29,7 +29,7 @@ export default {
data() { data() {
return { return {
options: null, options: null,
operator: 'eq', operator: 'in',
values: null values: null
} }
}, },
...@@ -50,37 +50,26 @@ export default { ...@@ -50,37 +50,26 @@ export default {
this.inDraw && this.$store.dispatch('conditions/add', param) this.inDraw && this.$store.dispatch('conditions/add', param)
}, },
dateChange(value) { dateChange(value) {
// const nvalue = dateFormat(value, this.getFormat())
// console.log(nvalue)
this.setCondition() this.setCondition()
}, },
formatValues(values) { formatValues(values) {
if (!values || values.length === 0) { if (!values || values.length === 0) {
return [] return []
} }
return values.map(value => dateFormat(value, this.getFormat())) if (this.options.attrs.type === 'daterange') {
}, if (values.length !== 2) {
getFormat() { return null
let format = 'yyyy' }
switch (this.options.attrs.type) { let start = values[0]
case 'year': let end = values[1]
format = 'yyyy' start = timeSection(start, 'date')[0]
break end = timeSection(end, 'date')[1]
case 'month': const results = [start, end]
format = 'yyyy-MM' return results
break } else {
case 'date': const value = values[0]
format = 'yyyy-MM-dd' return timeSection(value, this.options.attrs.type)
break
case 'daterange':
format = 'yyyy-MM-dd'
this.operator = 'in'
break
default:
format = 'yyyy'
break
} }
return format
} }
} }
} }
......
/** /**
* Created by PanJiaChen on 16/11/18. * Created by PanJiaChen on 16/11/18.
*/ */
export function timeSection(date, type) {
if (!date) {
return null
}
const timeRanger = new Array(2)
date.setHours(0)
date.setMinutes(0)
date.setSeconds(0)
date.setMilliseconds(0)
const end = new Date(date)
if (type === 'year') {
date.setDate(1)
date.setMonth(0)
end.setFullYear(date.getFullYear() + 1)
timeRanger[1] = end.getTime() - 1
}
if (type === 'month') {
date.setDate(1)
const currentMonth = date.getMonth()
if (currentMonth === 11) {
end.setFullYear(date.getFullYear() + 1)
end.setMonth(0)
} else {
end.setMonth(date.getMonth() + 1)
}
timeRanger[1] = end.getTime() - 1
}
if (type === 'date') {
end.setHours(23)
end.setMinutes(59)
end.setSeconds(59)
end.setMilliseconds(999)
timeRanger[1] = end.getTime()
}
timeRanger[0] = date.getTime()
return timeRanger
}
export function dateFormat(date, fmt) { export function dateFormat(date, fmt) {
let ret let ret
const opt = { const opt = {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论