|
@@ -1,4 +1,4 @@
|
|
|
-import store from '../store';
|
|
|
|
|
|
|
+const store = require('../store');
|
|
|
|
|
|
|
|
// 日期格式化
|
|
// 日期格式化
|
|
|
export function parseTime(time, pattern) {
|
|
export function parseTime(time, pattern) {
|
|
@@ -50,6 +50,41 @@ export function parseTime(time, pattern) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
// 千分号
|
|
// 千分号
|
|
|
|
|
+// 中文日期格式(年-月-日)
|
|
|
|
|
+export function formatChineseDate(time) {
|
|
|
|
|
+ // 统一处理日期格式
|
|
|
|
|
+ const formatDate = (dateObj) => {
|
|
|
|
|
+ const year = dateObj.getFullYear();
|
|
|
|
|
+ const month = (dateObj.getMonth() + 1).toString().padStart(2, '0');
|
|
|
|
|
+ const day = dateObj.getDate().toString().padStart(2, '0');
|
|
|
|
|
+ return `${year}年${month}月${day}日`;
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ // 处理字符串格式(支持多种分隔符)
|
|
|
|
|
+ if (typeof time === 'string') {
|
|
|
|
|
+ // 清理日期字符串中的时间部分(如果有)
|
|
|
|
|
+ const dateString = time.split(' ')[0];
|
|
|
|
|
+ // 匹配 yyyy-mm-dd 或 yyyy/m/d 等格式
|
|
|
|
|
+ if (/^\d{4}[-\/]\d{1,2}[-\/]\d{1,2}$/.test(dateString)) {
|
|
|
|
|
+ const separator = dateString.includes('-') ? '-' : '/';
|
|
|
|
|
+ const [year, month, day] = dateString.split(separator);
|
|
|
|
|
+ return formatDate(new Date(year, month - 1, day));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 处理时间戳和Date对象
|
|
|
|
|
+ try {
|
|
|
|
|
+ const date = new Date(time);
|
|
|
|
|
+ if (!isNaN(date)) {
|
|
|
|
|
+ return formatDate(date);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ console.error('Invalid date format:', time);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return '无效日期格式';
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
export function Micrometer(num) {
|
|
export function Micrometer(num) {
|
|
|
if (num != null) {
|
|
if (num != null) {
|
|
|
let numt = (num || 0).toString().split('.');
|
|
let numt = (num || 0).toString().split('.');
|