From 2cffc40a0d6e5a8a9560b2f6e24590d742227833 Mon Sep 17 00:00:00 2001 From: zq <136432190602163.com> Date: Thu, 18 Dec 2025 16:17:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E5=85=AC=E5=85=B1=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E8=8E=B7=E5=8F=96=E6=97=A5=E6=9C=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/common.js | 33 +++++++++++++++++++++++++++++++++ src/views/agent/addCustomCoupon.vue | 26 ++------------------------ 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/src/utils/common.js b/src/utils/common.js index a3a9bf8..6fa0f6b 100644 --- a/src/utils/common.js +++ b/src/utils/common.js @@ -30,3 +30,36 @@ export function getServicePriceDesc(price, price_unit, unit_num, unit_name) { return price + price_unit + "/" +unit_str + unit_name; } +/** + * 获取格式化的日期字符串 + * @param {string} format - 日期格式,可选值:'YYYY-MM-DD', 'YYYY-MM', 'YYYY', 'HH:mm:ss' 等 + * @returns {string} 格式化后的日期字符串 + * + // 使用示例 + // console.log(getFormattedDate('YYYY')); // 2024 + // console.log(getFormattedDate('YYYY-MM')); // 2024-01 + // console.log(getFormattedDate('YYYY-MM-DD')); // 2024-01-15 + */ +export const getFormattedDate = (format = 'YYYY-MM-DD') => { + const now = new Date(); + const year = now.getFullYear(); + const month = String(now.getMonth() + 1).padStart(2, '0'); + const day = String(now.getDate()).padStart(2, '0'); + const hour = String(now.getHours()).padStart(2, '0'); + const minute = String(now.getMinutes()).padStart(2, '0'); + const second = String(now.getSeconds()).padStart(2, '0'); + + const formats = { + 'YYYY': year, + 'YYYY-MM': `${year}-${month}`, + 'YYYY-MM-DD': `${year}-${month}-${day}`, + 'HH:mm:ss': `${hour}:${minute}:${second}`, + 'YYYY-MM-DD HH:mm:ss': `${year}-${month}-${day} ${hour}:${minute}:${second}`, + 'YYYY/MM/DD': `${year}/${month}/${day}`, + 'YYYY年MM月DD日': `${year}年${month}月${day}日`, + }; + + return formats[format] || formats['YYYY-MM-DD']; + }; + + diff --git a/src/views/agent/addCustomCoupon.vue b/src/views/agent/addCustomCoupon.vue index d0afb54..9ee71db 100644 --- a/src/views/agent/addCustomCoupon.vue +++ b/src/views/agent/addCustomCoupon.vue @@ -138,6 +138,7 @@ import GuipRadio from '@/components/GuipRadio'; import GuipInput from '@/components/GuipInput.vue'; import GuipSelect from '@/components/GuipSelect.vue'; import GuipTextarea from '@/components/GuipTextarea.vue'; +import {getFormattedDate} from "@/utils/common"; export default { props: { @@ -150,13 +151,7 @@ export default { GuipRadio, }, data() { - const today = new Date(); - const fixedStartDate = this.formatDate(today); - - // 计算默认结束日期(例如:一周后) - const defaultEndDate = new Date(today); - defaultEndDate.setDate(today.getDate() + 7); - + const fixedStartDate = getFormattedDate('YYYY-MM-DD'); return { // 日期范围值 - 固定起始日期为今天 dateRange: [fixedStartDate, ''], @@ -170,8 +165,6 @@ export default { }, }, - // 固定起始日期(不可修改) - fixedStartDate: fixedStartDate, // 是否显示日期信息 fastWords: [ @@ -378,21 +371,6 @@ export default { const day = String(date.getDate()).padStart(2, '0'); return `${year}-${month}-${day}`; }, - // 处理日期变化 - handleDateChange(value) { - console.log('日期范围变化:', value); - - // 确保起始日期始终为固定值 - if (value && value[0] !== this.fixedStartDate) { - // 如果用户尝试修改起始日期,强制改回固定值 - setTimeout(() => { - this.dateRange = [this.fixedStartDate, value[1] || '']; - }, 0); - } - - // 更新显示信息 - this.showDateInfo = true; - }, checkFastWord(item) { this.searchWord = item.name; this.searchWordId = item.id;