日历精确度问题修改

This commit is contained in:
aihe 2024-05-29 14:33:02 +08:00
parent 4414d3f71f
commit 7faea925b4

View File

@ -10,7 +10,7 @@
</u-input> </u-input>
<view class="pos-abt-all"> <view class="pos-abt-all">
<view v-if="showTools" @click.stop=""> <view v-if="showTools" @click.stop="">
<tpx-select :list="toolsRangesList" :value="value[0]" mode="drop" @onChange="handleToolsRangChange"> <tpx-select :list="toolsRangesList" v-model:value="rangeVal" mode="drop" @onChange="handleToolsRangChange">
<view :style="`height: 64rpx;`" ></view> <view :style="`height: 64rpx;`" ></view>
</tpx-select> </tpx-select>
</view> </view>
@ -24,13 +24,23 @@
<script> <script>
import { } from "@/common/untool" import { } from "@/common/untool"
import dayjs from "dayjs" import dayjs from "dayjs"
const formatStr = 'YYYY-MM-DD'
export default { export default {
computed: { computed: {
inputValue() { inputValue() {
const val = this.value let val = this.value
if(Array.isArray(val)) {
val = [].concat(val)
if(val.length > 1) {
val[0] = dayjs(val[0]).format(formatStr)
}
if(val.length > 1) {
val[1] = dayjs(val[1]).format(formatStr)
}
}
return val && (val.length > 1 ? val.join("~") : val[0]) return val && (val.length > 1 ? val.join("~") : val[0])
} },
}, },
props: { props: {
value: { value: {
@ -60,11 +70,14 @@
}, },
toolsRangesList: { toolsRangesList: {
default () { default () {
let today = dayjs().format(`${formatStr}`),
yesterday = dayjs().subtract(1, 'days').format(`${formatStr}`),
lastWeek = dayjs().subtract(7, 'days').format(`${formatStr}`)
return [ return [
{ title: '今日', val: dayjs().format("YYYY-MM-DD") }, { title: '今日', val: '1', range: [ today, today ] },
{ title: '昨日', val: dayjs().subtract(1, 'days').format("YYYY-MM-DD") }, { title: '昨日', val: '2', range: [yesterday, yesterday] },
{ title: '最近一周', val: dayjs().subtract(7, 'days').format("YYYY-MM-DD") }, { title: '最近一周', val: '3', range: [lastWeek, today] },
{ title: '自定义', val: -1 }, { title: '自定义', val: '-1', range: [] },
] ]
} }
}, },
@ -76,7 +89,8 @@
}, },
data() { data() {
return { return {
showCladar: false showCladar: false,
rangeVal: ''
} }
}, },
created() { created() {
@ -92,6 +106,8 @@
this.handleSwitchCladar() this.handleSwitchCladar()
}, },
handleChange(val){ handleChange(val){
val[0] = dayjs(val[0]).format(`${formatStr} 00:00:00`)
val[1] = dayjs(val[1]).format(`${formatStr} 23:59:59`)
this.$emit('change', val) this.$emit('change', val)
this.$emit('update:value', val) this.$emit('update:value', val)
}, },
@ -108,7 +124,8 @@
if(val == -1) { if(val == -1) {
this.handleSwitchCladar() this.handleSwitchCladar()
} else { } else {
this.handleChange([val, dayjs().format("YYYY-MM-DD")]) let sltRang = this.toolsRangesList.filter(t=> t.val == val)[0].range
this.handleChange(sltRang)
} }
} }
} }