Commit a53adc74 by 岑成威

fix: 兜底用户信息覆盖手机号码

1 parent 6806f48a
<template>
<view class="date-list">
<view v-if="ready && days.length" class="date-list">
<picker-view class="picker picker_max" :value="dateValues" indicator-class="indicator" @change="changeDate">
<picker-view-column>
<template v-for="(item, index) in days">
......@@ -29,158 +29,155 @@ import dayjs from 'dayjs'
export default {
name: 'DateTime',
inject: ['userInfo'],
props: {
defaultTime: {
type: String,
default: ''
}
},
data () {
return {
hours: [],
days: [],
minutes: [],
dateValues: [],
hourValues: [],
minuteValues: [],
loading: true
dateValues: [0],
hourValues: [0],
minuteValues: [0],
ready: false,
currentDate: '',
currentHour: '',
currentMinute: ''
}
},
props: {
},
mounted () {
this.initDate()
},
methods: {
initDate () {
this.dateValues = []
this.hourValues = []
this.minuteValues = []
const today = new Date()
this.getDateList('2019/01/01', new Date(today.getFullYear(), today.getMonth(), today.getDate()))
getList () {
this.ready = false
this.initDate()
},
getDateList (starDay, endDay) {
const arr = [];
const dates = [];
// 设置两个日期UTC时间
const db = new Date(starDay);
const de = new Date(endDay);
// 获取两个日期GTM时间
const s = db.getTime() - 24 * 60 * 60 * 1000;
const d = de.getTime() - 24 * 60 * 60 * 1000;
// 获取到两个日期之间的每一天的毫秒数
for (let i = s; i <= d;) {
i = i + 24 * 60 * 60 * 1000;
arr.push(parseInt(String(i)));
}
// 获取每一天的时间 YY-MM-DD
for (const j in arr) {
const time = new Date(arr[j]);
const year = time.getFullYear();
const mouth = time.getMonth() + 1 >= 10 ? time.getMonth() + 1 : '0' + (time.getMonth() + 1);
const day = time.getDate() >= 10 ? time.getDate() : '0' + time.getDate();
const YYMMDD = year + '/' + mouth + '/' + day;
dates.push(YYMMDD);
buildDayList () {
const days = []
const start = dayjs('2019-01-01').startOf('day')
const end = dayjs().startOf('day')
let cur = start
while (cur.isBefore(end) || cur.isSame(end, 'day')) {
days.push(cur.format('YYYY/MM/DD'))
cur = cur.add(1, 'day')
}
this.getHourList(dates)
return days
},
buildHourList (isToday) {
const len = isToday ? dayjs().hour() + 1 : 24
return Array.from({ length: len }, (_, i) => String(i).padStart(2, '0'))
},
buildMinuteList (isToday, hour) {
const now = dayjs()
const isCurrentHour = isToday && hour === now.format('HH')
const len = isCurrentHour ? now.minute() + 1 : 60
return Array.from({ length: len }, (_, i) => String(i).padStart(2, '0'))
},
getHourList (days) {
const hours = [], today = new Date();
for (let hour = 0; hour < today.getHours() + 1; hour++) {
hours.push(hour.toString().padStart(2, '0'));
pickIndex (list, value, fallbackLast) {
const index = list.indexOf(value)
if (index >= 0) return index
return fallbackLast ? Math.max(list.length - 1, 0) : 0
},
applyPickerValues (dateValues, hourValues, minuteValues) {
this.$nextTick(() => {
this.dateValues = dateValues
this.hourValues = hourValues
this.minuteValues = minuteValues
this.ready = true
this.$emit('onComplete')
})
},
initDate () {
const days = this.buildDayList()
if (!days.length) {
this.days = []
this.hours = []
this.minutes = []
this.ready = false
this.$emit('onComplete')
return
}
this.getMinuteList(days, hours)
},
getMinuteList (days, hours) {
const minutes = [];
const today = new Date()
for (let minute = 0; minute < today.getMinutes() + 1; minute++) {
minutes.push(minute.toString().padStart(2, '0'));
const today = dayjs()
const todayStr = today.format('YYYY/MM/DD')
let currentDate = todayStr
let currentHour = today.format('HH')
let currentMinute = today.format('mm')
if (this.defaultTime) {
const parsed = dayjs(this.defaultTime.replace(/-/g, '/'))
if (parsed.isValid()) {
currentDate = parsed.format('YYYY/MM/DD')
currentHour = parsed.format('HH')
currentMinute = parsed.format('mm')
}
}
// 设置默认时间
let { dateValues, hourValues, minuteValues } = this
const HOUR_STR = today.getHours().toString().padStart(2, '0')
const MUNTUE_STR = today.getMinutes().toString().padStart(2, '0')
// const defalutHIndex = hours.indexOf(HOUR_STR)
// const defalutMIndex = minutes.indexOf(MUNTUE_STR)
dateValues.push(days.length + 1)
hourValues.push(hours.length + 1)
minuteValues.push(minutes.length + 1)
this.currentDate = dayjs().format('YYYY/MM/DD')
this.currentHour = HOUR_STR
this.currentMinute = MUNTUE_STR
this.hours = hours
const isToday = currentDate === todayStr
const hours = this.buildHourList(isToday)
const minutes = this.buildMinuteList(isToday, currentHour)
if (!hours.includes(currentHour)) currentHour = hours[hours.length - 1]
if (!minutes.includes(currentMinute)) currentMinute = minutes[minutes.length - 1]
this.currentDate = currentDate
this.currentHour = currentHour
this.currentMinute = currentMinute
this.days = days
this.hours = hours
this.minutes = minutes
this.dateValues = dateValues
this.hourValues = hourValues
this.minuteValues = minuteValues
this.loading = false
setTimeout(() => {
this.minuteValues = minuteValues
this.loading = false
}, 100)
this.$emit('onComplete')
},
changeDate (e) {
const { days } = this
const { value } = e.detail
const index = value[0]
console.log( days[index],days,index)
this.currentDate = days[index]
// 选择过去时间需要重新初始化时分
const today = dayjs().format('YYYY/MM/DD')
const timeType = this.currentDate != today ? 1 : 0
this.getAllTimeOrPartTime(timeType)
},
changeHour (e) {
const { hours, days, dateValues } = this
const { value } = e.detail
const index = value[0]
this.currentHour = hours[index]
// 处理当前天切换别的小时,别的分不能选后面分到60的问题
// const dayIndex = dateValues[0]
// this.currentDate = days[dayIndex]
const today = dayjs().format('YYYY/MM/DD')
const timeType = this.currentDate != today ? 1 : 0
this.getAllTimeOrPartTimeMinute(timeType)
this.applyPickerValues(
[this.pickIndex(days, currentDate, true)],
[this.pickIndex(hours, currentHour, true)],
[this.pickIndex(minutes, currentMinute, true)]
)
},
changeMinutes (e) {
const { minutes } = this
const { value } = e.detail
const index = value[0]
this.currentMinute = minutes[index]
},
getAllTimeOrPartTime (type) {
const today = new Date()
const hours = [], minutes = [], hour_len = type == 1 ? 24 : today.getHours() + 1, minute_len = type == 1 ? 60 : today.getMinutes() + 1;
for (let hour = 0; hour < hour_len; hour++) {
hours.push(hour.toString().padStart(2, '0'));
}
for (let minute = 0; minute < minute_len; minute++) {
minutes.push(minute.toString().padStart(2, '0'));
changeDate (e) {
const index = e.detail.value[0]
const date = this.days[index]
if (!date) return
this.currentDate = date
const isToday = this.currentDate === dayjs().format('YYYY/MM/DD')
this.hours = this.buildHourList(isToday)
if (!this.hours.includes(this.currentHour)) {
this.currentHour = this.hours[this.hours.length - 1]
}
this.hours = hours
const minutes = this.buildMinuteList(isToday, this.currentHour)
this.minutes = minutes
if (!this.minutes.includes(this.currentMinute)) {
this.currentMinute = this.minutes[this.minutes.length - 1]
}
this.$nextTick(() => {
this.hourValues = [this.pickIndex(this.hours, this.currentHour, true)]
this.minuteValues = [this.pickIndex(this.minutes, this.currentMinute, true)]
})
},
getAllTimeOrPartTimeMinute (type) {
const today = new Date()
const currentHour = today.getHours()
const timeType = this.currentHour != currentHour ? 1 : 0
const minutes = [], minute_len = type == 1 || timeType == 1 ? 60 : today.getMinutes() + 1;
for (let minute = 0; minute < minute_len; minute++) {
minutes.push(minute.toString().padStart(2, '0'));
changeHour (e) {
const index = e.detail.value[0]
const hour = this.hours[index]
if (hour == null) return
this.currentHour = hour
const isToday = this.currentDate === dayjs().format('YYYY/MM/DD')
this.minutes = this.buildMinuteList(isToday, this.currentHour)
if (!this.minutes.includes(this.currentMinute)) {
this.currentMinute = this.minutes[this.minutes.length - 1]
}
this.minutes = minutes
this.$nextTick(() => {
this.minuteValues = [this.pickIndex(this.minutes, this.currentMinute, true)]
})
},
changeMinutes (e) {
const index = e.detail.value[0]
const minute = this.minutes[index]
if (minute == null) return
this.currentMinute = minute
},
getResult () {
console.log(this.currentDate,this.currentHour,this.currentMinute)
let str = ''
str = this.currentDate + ' ' + this.currentHour + ':' + this.currentMinute + ":00"
const result = dayjs(str).format('YYYY/MM/DD HH:mm:ss')
return result
const str = `${this.currentDate} ${this.currentHour}:${this.currentMinute}:00`
return dayjs(str.replace(/-/g, '/')).format('YYYY/MM/DD HH:mm:ss')
}
}
}
......
......@@ -17,7 +17,7 @@
</template>
<view v-if="componentObject[popupType]" :class="['popup-body', { 'hide-footer': componentObject[popupType].hideFooter }, { 'hide-search': componentObject[popupType].hideSearch }, { 'hide-footer-search': componentObject[popupType].hideFooter && componentObject[popupType].hideSearch }]">
<scroll-view scroll-y :class="['popup-scroll-view', { show: componentObject[popupType].loadComplete }]">
<component :is="componentObject[popupType].name" :params.sync="componentObject[popupType]" :data="data" :dataKey="dataKey" :isDefeatOrder="isDefeatOrder" :defaultTime="defaultTime" :positionTypeList="positionTypeList" :show-marketing-icon="showMarketingIcon" :boutique-order-types-only="boutiqueOrderTypesOnly" ref="componentRef" @choose="chooseContent = $event" @openSkuPopup="openSkuPopup" @onComplete="componentObject[popupType].loadComplete = true" @confirm="confirm"></component>
<component :is="componentObject[popupType].name" :params.sync="componentObject[popupType]" :data="data" :dataKey="dataKey" :isDefeatOrder="isDefeatOrder" :defaultTime="datePickerDefaultTime" :positionTypeList="positionTypeList" :show-marketing-icon="showMarketingIcon" :boutique-order-types-only="boutiqueOrderTypesOnly" ref="componentRef" @choose="chooseContent = $event" @openSkuPopup="openSkuPopup" @onComplete="componentObject[popupType].loadComplete = true" @confirm="confirm"></component>
<template v-if="componentObject[popupType].noData">
<view class="nothing flex">暂无数据</view>
</template>
......@@ -171,6 +171,11 @@ export default {
const { sceneType } = uni.$storage.get('userInfo')
return sceneType
},
datePickerDefaultTime () {
if (this.defaultTime) return this.defaultTime
const data = this.data || {}
return data.pay2Time || data.successDate || ''
}
},
mounted () {
},
......@@ -187,6 +192,9 @@ export default {
})
},
open () {
if (this.componentObject[this.popupType]) {
this.componentObject[this.popupType].loadComplete = false
}
this.$refs.popup.open()
// 等待当前 tick 的响应式 watcher(如 externalData → cacheData)执行完再初始化
this.$nextTick(() => {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!