From 7b64d5337254349b32ce91f30bb36eab6ba8231f Mon Sep 17 00:00:00 2001 From: Tomas <tomasysh@gmail.com> Date: 星期一, 31 七月 2023 19:30:44 +0800 Subject: [PATCH] Fixed: 調整錯誤的 insert API URL --- PAMapp/components/Ui/UiDateFormat.vue | 81 +++++++++++++++++++++++++--------------- 1 files changed, 50 insertions(+), 31 deletions(-) diff --git a/PAMapp/components/Ui/UiDateFormat.vue b/PAMapp/components/Ui/UiDateFormat.vue index bda6f99..32f9651 100644 --- a/PAMapp/components/Ui/UiDateFormat.vue +++ b/PAMapp/components/Ui/UiDateFormat.vue @@ -1,47 +1,66 @@ <template> <span> - {{ formattedDate }} + {{ displayValue }} </span> </template> <script lang="ts"> -import { Vue, Component, Prop } from 'vue-property-decorator'; +import { Vue, Component, Prop, Watch } from 'vue-property-decorator'; @Component export default class UiDateFormat extends Vue { - @Prop() date!: Date | string; - @Prop() onlyShowSection!: 'DAY' | 'TIME'; + @Prop() + date!: Date | string; + + @Prop() + onlyShowSection!: 'YEAR' | 'DATE' | 'DAY' | 'TIME'; + compareTarget!: Date; + displayValue = ''; - get formattedDate(): string { + @Watch('date', {immediate: true}) + formattedDate(): void { + if (!this.date) return; - if (typeof this.date === 'string') { - this.compareTarget = new Date(this.date); - } else { - this.compareTarget = this.date; - } - const isToday = (compareDate: Date): boolean => { - return compareDate.getFullYear() === _now.getFullYear() - && compareDate.getMonth() === _now.getMonth() - && compareDate.getDate() === _now.getDate() - }; + const toDatePromise = new Promise((resolve, reject) => { + const date: Date = typeof(this.date) === 'string' ? new Date(this.date) : this.date as Date; + resolve(date); + }); - const isThisYear = (compareDate: Date): boolean => { - return compareDate.getFullYear() === _now.getFullYear(); - }; - const _now = new Date(); - const minutes = _now.getMinutes() > 9 ? _now.getMinutes() : `0${_now.getMinutes()}`; - const thisYearDayLabel = isToday(this.compareTarget) ? `隞予` : `${this.compareTarget.getMonth() + 1}/${this.compareTarget.getDate()}`; + toDatePromise.then((compareTarget: any) => { + const _now = new Date(); + const isToday = (compareDate: Date): boolean => { + return compareDate.getFullYear() === _now.getFullYear() + && compareDate.getMonth() === _now.getMonth() + && compareDate.getDate() === _now.getDate() + }; - if (this.onlyShowSection === 'DAY') { - return isThisYear(this.compareTarget) ? thisYearDayLabel : `${this.compareTarget.getFullYear()}/${this.compareTarget.getMonth() + 1}/${this.compareTarget.getDate()}`; - } else if (this.onlyShowSection === 'TIME') { - return `${this.compareTarget.getHours()}:${minutes}`; - } + const isThisYear = (compareDate: Date): boolean => { + return compareDate.getFullYear() === _now.getFullYear(); + }; - return isThisYear(this.compareTarget) - ? `${thisYearDayLabel} ${this.compareTarget.getHours()}:${minutes}` - : `${this.compareTarget.getFullYear()}/${this.compareTarget.getMonth() + 1}/${this.compareTarget.getDate()} ${this.compareTarget.getHours()}:${minutes}`; - } + const minutes = compareTarget.getMinutes() > 9 ? compareTarget.getMinutes() : `0${compareTarget.getMinutes()}`; + const thisYearDayLabel = isToday(compareTarget) ? `隞予` : `${compareTarget.getMonth() + 1}/${compareTarget.getDate()}`; + + if (this.onlyShowSection === 'DAY') { + this.displayValue = isThisYear(compareTarget) ? thisYearDayLabel : `${compareTarget.getFullYear()}/${compareTarget.getMonth() + 1}/${compareTarget.getDate()}`; + } else if (this.onlyShowSection === 'TIME') { + this.displayValue = `${compareTarget.getHours()}:${minutes}`; + } else if (this.onlyShowSection === 'DATE') { + this.displayValue = isThisYear(compareTarget) + ? thisYearDayLabel + : `${compareTarget.getMonth() + 1}/${compareTarget.getDate()}`; + } else if (this.onlyShowSection === 'YEAR') { + this.displayValue = `${compareTarget.getFullYear()}`; + } + + if (this.onlyShowSection) return; + + this.displayValue = isThisYear(compareTarget) + ? `${thisYearDayLabel} ${compareTarget.getHours()}:${minutes}` + : `${compareTarget.getFullYear()}/${compareTarget.getMonth() + 1}/${compareTarget.getDate()} ${compareTarget.getHours()}:${minutes}`; + } + )} + } -</script> \ No newline at end of file +</script> -- Gitblit v1.8.0