|
|
@ -34,7 +34,7 @@ export function getServicePriceDesc(price, price_unit, unit_num, unit_name) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 获取格式化的日期字符串 |
|
|
* 获取格式化的日期字符串--是当下日期 |
|
|
* @param {string} format - 日期格式,可选值:'YYYY-MM-DD', 'YYYY-MM', 'YYYY', 'HH:mm:ss' 等 |
|
|
* @param {string} format - 日期格式,可选值:'YYYY-MM-DD', 'YYYY-MM', 'YYYY', 'HH:mm:ss' 等 |
|
|
* @returns {string} 格式化后的日期字符串 |
|
|
* @returns {string} 格式化后的日期字符串 |
|
|
* |
|
|
* |
|
|
@ -65,6 +65,54 @@ export const getFormattedDate = (format = 'YYYY-MM-DD') => { |
|
|
return formats[format] || formats['YYYY-MM-DD']; |
|
|
return formats[format] || formats['YYYY-MM-DD']; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// 根据指定日期获取年月格式字符串
|
|
|
|
|
|
/** |
|
|
|
|
|
* 日期格式化函数 |
|
|
|
|
|
* |
|
|
|
|
|
* @param {string} dateStr - 日期字符串,可被Date构造函数解析 |
|
|
|
|
|
* @param {string} [format='yyyy-mm'] - 输出格式,可选值:'year'、'month'、'year-month'、'yyyy'、'mm'、'm'、'yyyy-mm'、'yyyy-m' |
|
|
|
|
|
* @returns {string} 格式化后的日期字符串,如果日期无效则返回'Invalid date' |
|
|
|
|
|
* 使用示例 |
|
|
|
|
|
* 1. console.log(getDate('2023-12-31')); // 输出: "2023-12"
|
|
|
|
|
|
* 2. console.log(getDate('2023-12-31', 'yyyy' || 'year')); // 输出: "2023"
|
|
|
|
|
|
* 3. console.log(getDate('2023-12-31', 'yyyy-m')); // 输出: "2023-12"
|
|
|
|
|
|
* 4. console.log(getDate('2023-12-31', 'm' || 'month')); // 输出: "12"
|
|
|
|
|
|
* 7. console.log(getDate('2023-12-31', 'year-month')); // 输出: "2023-12"
|
|
|
|
|
|
* 8. console.log(getDate('2023-12-31', 'yyyy/mm')); // 输出: "Invalid date"(因为格式'yyyy/mm'不在可选值中)
|
|
|
|
|
|
* 9.console.log(getDate('2025-03-15T10:30:00', 'yyyy-mm')); // ISO格式
|
|
|
|
|
|
* 10.console.log(getDate('March 15, 2025', 'yyyy'));//2023 // 英文日期
|
|
|
|
|
|
* 11.console.log(getDate('2025/03/15', 'year-month')); // 输出: "2025-03"
|
|
|
|
|
|
*/ |
|
|
|
|
|
export function getDate(dateStr, format = 'yyyy-mm') { |
|
|
|
|
|
try { |
|
|
|
|
|
const date = new Date(dateStr); |
|
|
|
|
|
|
|
|
|
|
|
// 检查日期是否有效
|
|
|
|
|
|
if (isNaN(date.getTime())) { |
|
|
|
|
|
throw new Error('日期无效'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const year = date.getFullYear(); |
|
|
|
|
|
const month = date.getMonth() + 1; |
|
|
|
|
|
|
|
|
|
|
|
const formats = { |
|
|
|
|
|
'year': `${year}`, |
|
|
|
|
|
'month': `${month.toString().padStart(2, '0')}`, |
|
|
|
|
|
'year-month': `${year}-${month.toString().padStart(2, '0')}`, |
|
|
|
|
|
'yyyy': `${year}`, |
|
|
|
|
|
'mm': `${month.toString().padStart(2, '0')}`, |
|
|
|
|
|
'm': `${month}`, |
|
|
|
|
|
'yyyy-mm': `${year}-${month.toString().padStart(2, '0')}`, //补0
|
|
|
|
|
|
'yyyy-m': `${year}-${month}`//不补0
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
return formats[format] || formats['yyyy-mm']; |
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
console.error('Error parsing date:', error); |
|
|
|
|
|
return 'Invalid date'; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
//金额千分符 会在整数后添加两个0 --适用于直接显示的
|
|
|
//金额千分符 会在整数后添加两个0 --适用于直接显示的
|
|
|
export function stateFormat(row, column, cellValue) { |
|
|
export function stateFormat(row, column, cellValue) { |
|
|
if (cellValue) { |
|
|
if (cellValue) { |
|
|
|