@pisell/materials 6.11.5 → 6.11.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/lowcode/assets-daily.json +11 -11
- package/build/lowcode/assets-dev.json +2 -2
- package/build/lowcode/assets-prod.json +11 -11
- package/build/lowcode/index.js +1 -1
- package/build/lowcode/meta.js +7 -7
- package/build/lowcode/preview.js +9 -9
- package/build/lowcode/render/default/view.css +1 -1
- package/build/lowcode/render/default/view.js +23 -23
- package/build/lowcode/view.css +1 -1
- package/build/lowcode/view.js +19 -19
- package/es/components/PisellTabbar/PisellTabbar.js +47 -44
- package/es/components/PisellTabbar/locales.d.ts +8 -0
- package/es/components/PisellTabbar/locales.js +8 -0
- package/es/components/PisellTabbar/template/Template1/PisellTabbar.d.ts +3 -18
- package/es/components/PisellTabbar/template/Template1/PisellTabbar.js +124 -28
- package/es/components/PisellTabbar/template/Template1/constants.js +1 -1
- package/es/components/PisellTabbar2/locales.d.ts +8 -0
- package/es/components/PisellTabbar2/locales.js +8 -0
- package/es/components/PisellTabbar3/locales.d.ts +8 -0
- package/es/components/PisellTabbar3/locales.js +8 -0
- package/es/components/config-provider/index.d.ts +2 -0
- package/es/components/config-provider/index.js +6 -0
- package/es/components/dataSourceComponents/fields/Input.Mobile/serve.d.ts +2 -0
- package/es/components/dataSourceComponents/fields/Input.Phone/serve.d.ts +2 -0
- package/es/components/dataSourceComponents/fields/Translation/BaseTranslation.js +8 -0
- package/es/components/dataSourceComponents/fields/Translation/type.d.ts +2 -0
- package/es/components/dataSourceComponents/fields/Upload/constants.d.ts +1 -1
- package/es/components/dataSourceComponents/fields/Upload/constants.js +1 -1
- package/es/components/dataSourceComponents/fields/Upload/utils.js +1 -1
- package/es/components/page/index.js +11 -1
- package/es/components/pisellDateTimeDisplay/PisellDateTimeDisplay.js +47 -34
- package/es/components/pisellDateTimeDisplay/PisellDateTimeDisplay.stories.d.ts +19 -0
- package/es/components/pisellDateTimeDisplay/PisellDateTimeDisplay.stories.js +74 -0
- package/es/components/pisellDateTimeDisplay/components/DateDisplay.d.ts +6 -1
- package/es/components/pisellDateTimeDisplay/components/DateDisplay.js +10 -3
- package/es/components/pisellDateTimeDisplay/formats/dateTimeDisplayFormats.d.ts +7 -0
- package/es/components/pisellDateTimeDisplay/formats/dateTimeDisplayFormats.js +81 -0
- package/es/components/pisellDateTimeDisplay/formats/index.d.ts +1 -0
- package/es/components/pisellDateTimeDisplay/formats/index.js +1 -0
- package/es/components/pisellDateTimeDisplay/hooks/useCurrentTime.d.ts +2 -2
- package/es/components/pisellDateTimeDisplay/hooks/useCurrentTime.js +2 -2
- package/es/components/pisellDateTimeDisplay/types.d.ts +48 -2
- package/es/components/pisellDateTimeDisplay/utils/formatDate.js +25 -6
- package/es/components/pisellDateTimeDisplay/utils/formatDateOrRelative.d.ts +17 -0
- package/es/components/pisellDateTimeDisplay/utils/formatDateOrRelative.js +38 -0
- package/es/components/pisellDateTimeDisplay/utils/formatWeekday.js +11 -12
- package/es/components/pisellDateTimeDisplay/utils/index.d.ts +3 -1
- package/es/components/pisellDateTimeDisplay/utils/index.js +3 -1
- package/es/components/pisellDateTimeDisplay/utils/localeUtils.d.ts +2 -7
- package/es/components/pisellDateTimeDisplay/utils/localeUtils.js +4 -17
- package/es/components/pisellDateTimeDisplay/utils/relativeDay.d.ts +23 -0
- package/es/components/pisellDateTimeDisplay/utils/relativeDay.js +45 -0
- package/es/components/pisellLookup/components/LookupTrigger.js +66 -6
- package/es/components/pisellText/components/Editable/index.d.ts +3 -0
- package/es/components/pisellTimeRangeDisplay/PisellTimeRangeDisplay.d.ts +32 -0
- package/es/components/pisellTimeRangeDisplay/PisellTimeRangeDisplay.js +197 -0
- package/es/components/pisellTimeRangeDisplay/PisellTimeRangeDisplay.less +49 -0
- package/es/components/pisellTimeRangeDisplay/PisellTimeRangeDisplay.stories.d.ts +61 -0
- package/es/components/pisellTimeRangeDisplay/PisellTimeRangeDisplay.stories.js +209 -0
- package/es/components/pisellTimeRangeDisplay/components/DateBlock.d.ts +20 -0
- package/es/components/pisellTimeRangeDisplay/components/DateBlock.js +30 -0
- package/es/components/pisellTimeRangeDisplay/components/DurationBlock.d.ts +19 -0
- package/es/components/pisellTimeRangeDisplay/components/DurationBlock.js +25 -0
- package/es/components/pisellTimeRangeDisplay/components/TimeRangeBlock.d.ts +30 -0
- package/es/components/pisellTimeRangeDisplay/components/TimeRangeBlock.js +86 -0
- package/es/components/pisellTimeRangeDisplay/components/WeekdayBlock.d.ts +18 -0
- package/es/components/pisellTimeRangeDisplay/components/WeekdayBlock.js +23 -0
- package/es/components/pisellTimeRangeDisplay/components/index.d.ts +8 -0
- package/es/components/pisellTimeRangeDisplay/components/index.js +4 -0
- package/es/components/pisellTimeRangeDisplay/index.d.ts +3 -0
- package/es/components/pisellTimeRangeDisplay/index.js +1 -0
- package/es/components/pisellTimeRangeDisplay/types.d.ts +137 -0
- package/es/components/pisellTimeRangeDisplay/types.js +1 -0
- package/es/components/pisellTimeRangeDisplay/utils/formatDuration.d.ts +14 -0
- package/es/components/pisellTimeRangeDisplay/utils/formatDuration.js +53 -0
- package/es/components/pisellTimeRangeDisplay/utils/index.d.ts +4 -0
- package/es/components/pisellTimeRangeDisplay/utils/index.js +5 -0
- package/es/components/pisellTimeRangeDisplay/utils/parseTimeRange.d.ts +23 -0
- package/es/components/pisellTimeRangeDisplay/utils/parseTimeRange.js +27 -0
- package/es/components/productCard/cartSkuCard/components/timeRange/index.d.ts +2 -0
- package/es/components/productCard/cartSkuCard/components/timeRange/index.js +5 -1
- package/es/components/productCard/cartSkuCard/locales.d.ts +64 -0
- package/es/components/productCard/cartSkuCard/locales.js +16 -0
- package/es/components/productCard/locales.d.ts +54 -0
- package/es/components/productCard/locales.js +84 -0
- package/es/components/productCard/utils.d.ts +2 -0
- package/es/components/productCard/utils.js +8 -2
- package/es/components/translation/index.d.ts +2 -0
- package/es/components/translation/index.js +12 -0
- package/es/components/translation/utils.d.ts +2 -0
- package/es/components/translation/utils.js +3 -1
- package/es/components/walletCard/index.d.ts +2 -0
- package/es/components/walletCard/index.js +11 -3
- package/es/index.d.ts +2 -0
- package/es/index.js +7 -0
- package/es/locales/index.js +6 -2
- package/es/locales/ja.d.ts +337 -0
- package/es/locales/ja.js +416 -0
- package/es/locales/pt.d.ts +337 -0
- package/es/locales/pt.js +416 -0
- package/es/utils/platform.d.ts +1 -1
- package/lib/components/PisellTabbar/PisellTabbar.js +64 -57
- package/lib/components/PisellTabbar/locales.d.ts +8 -0
- package/lib/components/PisellTabbar/locales.js +8 -0
- package/lib/components/PisellTabbar/template/Template1/PisellTabbar.d.ts +3 -18
- package/lib/components/PisellTabbar/template/Template1/PisellTabbar.js +171 -55
- package/lib/components/PisellTabbar/template/Template1/constants.js +1 -1
- package/lib/components/PisellTabbar2/locales.d.ts +8 -0
- package/lib/components/PisellTabbar2/locales.js +8 -0
- package/lib/components/PisellTabbar3/locales.d.ts +8 -0
- package/lib/components/PisellTabbar3/locales.js +8 -0
- package/lib/components/config-provider/index.d.ts +2 -0
- package/lib/components/config-provider/index.js +6 -0
- package/lib/components/dataSourceComponents/fields/Input.Mobile/serve.d.ts +2 -0
- package/lib/components/dataSourceComponents/fields/Input.Phone/serve.d.ts +2 -0
- package/lib/components/dataSourceComponents/fields/Translation/BaseTranslation.js +5 -1
- package/lib/components/dataSourceComponents/fields/Translation/type.d.ts +2 -0
- package/lib/components/dataSourceComponents/fields/Upload/constants.d.ts +1 -1
- package/lib/components/dataSourceComponents/fields/Upload/constants.js +1 -1
- package/lib/components/dataSourceComponents/fields/Upload/utils.js +1 -1
- package/lib/components/page/index.js +11 -1
- package/lib/components/pisellDateTimeDisplay/PisellDateTimeDisplay.js +27 -17
- package/lib/components/pisellDateTimeDisplay/PisellDateTimeDisplay.stories.d.ts +19 -0
- package/lib/components/pisellDateTimeDisplay/PisellDateTimeDisplay.stories.js +63 -0
- package/lib/components/pisellDateTimeDisplay/components/DateDisplay.d.ts +6 -1
- package/lib/components/pisellDateTimeDisplay/components/DateDisplay.js +5 -1
- package/lib/components/pisellDateTimeDisplay/formats/dateTimeDisplayFormats.d.ts +7 -0
- package/lib/components/pisellDateTimeDisplay/formats/dateTimeDisplayFormats.js +98 -0
- package/lib/components/pisellDateTimeDisplay/formats/index.d.ts +1 -0
- package/lib/components/pisellDateTimeDisplay/formats/index.js +29 -0
- package/lib/components/pisellDateTimeDisplay/hooks/useCurrentTime.d.ts +2 -2
- package/lib/components/pisellDateTimeDisplay/types.d.ts +48 -2
- package/lib/components/pisellDateTimeDisplay/utils/formatDate.js +14 -1
- package/lib/components/pisellDateTimeDisplay/utils/formatDateOrRelative.d.ts +17 -0
- package/lib/components/pisellDateTimeDisplay/utils/formatDateOrRelative.js +54 -0
- package/lib/components/pisellDateTimeDisplay/utils/formatWeekday.js +6 -6
- package/lib/components/pisellDateTimeDisplay/utils/index.d.ts +3 -1
- package/lib/components/pisellDateTimeDisplay/utils/index.js +8 -2
- package/lib/components/pisellDateTimeDisplay/utils/localeUtils.d.ts +2 -7
- package/lib/components/pisellDateTimeDisplay/utils/localeUtils.js +2 -11
- package/lib/components/pisellDateTimeDisplay/utils/relativeDay.d.ts +23 -0
- package/lib/components/pisellDateTimeDisplay/utils/relativeDay.js +54 -0
- package/lib/components/pisellLookup/components/LookupTrigger.js +45 -7
- package/lib/components/pisellText/components/Editable/index.d.ts +3 -0
- package/lib/components/pisellTimeRangeDisplay/PisellTimeRangeDisplay.d.ts +32 -0
- package/lib/components/pisellTimeRangeDisplay/PisellTimeRangeDisplay.js +193 -0
- package/lib/components/pisellTimeRangeDisplay/PisellTimeRangeDisplay.less +49 -0
- package/lib/components/pisellTimeRangeDisplay/PisellTimeRangeDisplay.stories.d.ts +61 -0
- package/lib/components/pisellTimeRangeDisplay/PisellTimeRangeDisplay.stories.js +187 -0
- package/lib/components/pisellTimeRangeDisplay/components/DateBlock.d.ts +20 -0
- package/lib/components/pisellTimeRangeDisplay/components/DateBlock.js +69 -0
- package/lib/components/pisellTimeRangeDisplay/components/DurationBlock.d.ts +19 -0
- package/lib/components/pisellTimeRangeDisplay/components/DurationBlock.js +65 -0
- package/lib/components/pisellTimeRangeDisplay/components/TimeRangeBlock.d.ts +30 -0
- package/lib/components/pisellTimeRangeDisplay/components/TimeRangeBlock.js +120 -0
- package/lib/components/pisellTimeRangeDisplay/components/WeekdayBlock.d.ts +18 -0
- package/lib/components/pisellTimeRangeDisplay/components/WeekdayBlock.js +64 -0
- package/lib/components/pisellTimeRangeDisplay/components/index.d.ts +8 -0
- package/lib/components/pisellTimeRangeDisplay/components/index.js +38 -0
- package/lib/components/pisellTimeRangeDisplay/index.d.ts +3 -0
- package/lib/components/pisellTimeRangeDisplay/index.js +40 -0
- package/lib/components/pisellTimeRangeDisplay/types.d.ts +137 -0
- package/lib/components/pisellTimeRangeDisplay/types.js +17 -0
- package/lib/components/pisellTimeRangeDisplay/utils/formatDuration.d.ts +14 -0
- package/lib/components/pisellTimeRangeDisplay/utils/formatDuration.js +52 -0
- package/lib/components/pisellTimeRangeDisplay/utils/index.d.ts +4 -0
- package/lib/components/pisellTimeRangeDisplay/utils/index.js +47 -0
- package/lib/components/pisellTimeRangeDisplay/utils/parseTimeRange.d.ts +23 -0
- package/lib/components/pisellTimeRangeDisplay/utils/parseTimeRange.js +49 -0
- package/lib/components/productCard/cartSkuCard/components/timeRange/index.d.ts +2 -0
- package/lib/components/productCard/cartSkuCard/components/timeRange/index.js +5 -1
- package/lib/components/productCard/cartSkuCard/locales.d.ts +64 -0
- package/lib/components/productCard/cartSkuCard/locales.js +18 -0
- package/lib/components/productCard/locales.d.ts +54 -0
- package/lib/components/productCard/locales.js +60 -0
- package/lib/components/productCard/utils.d.ts +2 -0
- package/lib/components/productCard/utils.js +8 -2
- package/lib/components/translation/index.d.ts +2 -0
- package/lib/components/translation/index.js +14 -0
- package/lib/components/translation/utils.d.ts +2 -0
- package/lib/components/translation/utils.js +3 -1
- package/lib/components/walletCard/index.d.ts +2 -0
- package/lib/components/walletCard/index.js +11 -3
- package/lib/index.d.ts +2 -0
- package/lib/index.js +3 -0
- package/lib/locales/index.js +6 -2
- package/lib/locales/ja.d.ts +337 -0
- package/lib/locales/ja.js +396 -0
- package/lib/locales/pt.d.ts +337 -0
- package/lib/locales/pt.js +396 -0
- package/lib/utils/platform.d.ts +1 -1
- package/lowcode/pisell-time-range-display/index.ts +3 -0
- package/lowcode/pisell-time-range-display/meta.ts +375 -0
- package/lowcode/pisell-time-range-display/snippets.ts +1 -0
- package/package.json +3 -3
|
@@ -5,11 +5,13 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
5
5
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
6
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
7
|
import React from 'react';
|
|
8
|
+
import dayjs from 'dayjs';
|
|
8
9
|
import 'dayjs/locale/zh-cn';
|
|
9
10
|
import 'dayjs/locale/en';
|
|
10
11
|
import { useCurrentTime } from "./hooks";
|
|
11
|
-
import { getRefreshInterval, isChinese as checkIsChinese } from "./utils";
|
|
12
|
+
import { getRefreshInterval, isChinese as checkIsChinese, getRelativeDay, getRelativeDayLabel, getDayjsLocale } from "./utils";
|
|
12
13
|
import { TimeDisplay, DateDisplay, WeekdayDisplay } from "./components";
|
|
14
|
+
import { DATETIME_DISPLAY_FORMATS } from "./formats/dateTimeDisplayFormats";
|
|
13
15
|
import "./PisellDateTimeDisplay.less";
|
|
14
16
|
|
|
15
17
|
/**
|
|
@@ -40,11 +42,13 @@ import "./PisellDateTimeDisplay.less";
|
|
|
40
42
|
* />
|
|
41
43
|
*/
|
|
42
44
|
export var PisellDateTimeDisplay = function PisellDateTimeDisplay(props) {
|
|
45
|
+
var _ref, _presetSource$localeK;
|
|
43
46
|
var _props$layout = props.layout,
|
|
44
47
|
layout = _props$layout === void 0 ? 'horizontal' : _props$layout,
|
|
45
48
|
_props$textAlign = props.textAlign,
|
|
46
49
|
textAlign = _props$textAlign === void 0 ? 'center' : _props$textAlign,
|
|
47
50
|
fields = props.fields,
|
|
51
|
+
formatByLocale = props.formatByLocale,
|
|
48
52
|
timeFormat = props.timeFormat,
|
|
49
53
|
dateFormat = props.dateFormat,
|
|
50
54
|
weekdayFormat = props.weekdayFormat,
|
|
@@ -64,8 +68,18 @@ export var PisellDateTimeDisplay = function PisellDateTimeDisplay(props) {
|
|
|
64
68
|
className = props.className,
|
|
65
69
|
style = props.style;
|
|
66
70
|
|
|
71
|
+
// 多语言格式:formatByLocale 优先,否则用内置 DATETIME_DISPLAY_FORMATS;再与单项 props 合并(单项优先)
|
|
72
|
+
var localeKey = getDayjsLocale(locale);
|
|
73
|
+
var baseLocale = localeKey.split('-')[0];
|
|
74
|
+
var presetSource = formatByLocale !== null && formatByLocale !== void 0 ? formatByLocale : DATETIME_DISPLAY_FORMATS;
|
|
75
|
+
var preset = (_ref = (_presetSource$localeK = presetSource[localeKey]) !== null && _presetSource$localeK !== void 0 ? _presetSource$localeK : presetSource[baseLocale]) !== null && _ref !== void 0 ? _ref : {};
|
|
76
|
+
var effectiveFields = _objectSpread(_objectSpread({}, preset.fields), fields);
|
|
77
|
+
var effectiveDateFormat = _objectSpread(_objectSpread({}, preset.dateFormat), dateFormat);
|
|
78
|
+
var effectiveTimeFormat = _objectSpread(_objectSpread({}, preset.timeFormat), timeFormat);
|
|
79
|
+
var effectiveWeekdayFormat = _objectSpread(_objectSpread({}, preset.weekdayFormat), weekdayFormat);
|
|
80
|
+
|
|
67
81
|
// 计算刷新间隔
|
|
68
|
-
var computedRefreshInterval = refreshInterval !== null && refreshInterval !== void 0 ? refreshInterval : getRefreshInterval(
|
|
82
|
+
var computedRefreshInterval = refreshInterval !== null && refreshInterval !== void 0 ? refreshInterval : getRefreshInterval(effectiveTimeFormat);
|
|
69
83
|
|
|
70
84
|
// 使用自定义 hook 管理当前时间
|
|
71
85
|
var currentTime = useCurrentTime({
|
|
@@ -93,16 +107,21 @@ export var PisellDateTimeDisplay = function PisellDateTimeDisplay(props) {
|
|
|
93
107
|
}, /*#__PURE__*/React.createElement("span", null, formattedTime));
|
|
94
108
|
}
|
|
95
109
|
|
|
96
|
-
//
|
|
97
|
-
var
|
|
98
|
-
|
|
99
|
-
showTime =
|
|
100
|
-
|
|
101
|
-
showDate =
|
|
102
|
-
|
|
103
|
-
showWeekday =
|
|
104
|
-
|
|
105
|
-
fieldOrder =
|
|
110
|
+
// 获取字段配置(已含多语言预设合并)
|
|
111
|
+
var _ref2 = effectiveFields || {},
|
|
112
|
+
_ref2$showTime = _ref2.showTime,
|
|
113
|
+
showTime = _ref2$showTime === void 0 ? true : _ref2$showTime,
|
|
114
|
+
_ref2$showDate = _ref2.showDate,
|
|
115
|
+
showDate = _ref2$showDate === void 0 ? true : _ref2$showDate,
|
|
116
|
+
_ref2$showWeekday = _ref2.showWeekday,
|
|
117
|
+
showWeekday = _ref2$showWeekday === void 0 ? true : _ref2$showWeekday,
|
|
118
|
+
_ref2$fieldOrder = _ref2.fieldOrder,
|
|
119
|
+
fieldOrder = _ref2$fieldOrder === void 0 ? ['time', 'date', 'weekday'] : _ref2$fieldOrder;
|
|
120
|
+
|
|
121
|
+
// 日期与星期一体:若日期以相对日(今天/昨天/明天)展示,则不展示星期
|
|
122
|
+
var referenceDate = dayjs();
|
|
123
|
+
var relativeDay = effectiveDateFormat !== null && effectiveDateFormat !== void 0 && effectiveDateFormat.showRelativeDay ? getRelativeDay(currentTime, referenceDate) : null;
|
|
124
|
+
var hideWeekdayWhenDateRelative = showDate && relativeDay !== null;
|
|
106
125
|
|
|
107
126
|
// 构建容器样式
|
|
108
127
|
var containerInlineStyle = _objectSpread({
|
|
@@ -122,21 +141,22 @@ export var PisellDateTimeDisplay = function PisellDateTimeDisplay(props) {
|
|
|
122
141
|
return showTime ? /*#__PURE__*/React.createElement(TimeDisplay, {
|
|
123
142
|
key: "time",
|
|
124
143
|
time: currentTime,
|
|
125
|
-
format:
|
|
144
|
+
format: effectiveTimeFormat,
|
|
126
145
|
style: timeStyle
|
|
127
146
|
}) : null;
|
|
128
147
|
case 'date':
|
|
129
148
|
return showDate ? /*#__PURE__*/React.createElement(DateDisplay, {
|
|
130
149
|
key: "date",
|
|
131
150
|
date: currentTime,
|
|
132
|
-
format:
|
|
151
|
+
format: effectiveDateFormat,
|
|
152
|
+
referenceDate: dayjs(),
|
|
133
153
|
style: dateStyle
|
|
134
154
|
}) : null;
|
|
135
155
|
case 'weekday':
|
|
136
|
-
return showWeekday ? /*#__PURE__*/React.createElement(WeekdayDisplay, {
|
|
156
|
+
return showWeekday && !hideWeekdayWhenDateRelative ? /*#__PURE__*/React.createElement(WeekdayDisplay, {
|
|
137
157
|
key: "weekday",
|
|
138
158
|
weekday: currentTime,
|
|
139
|
-
format:
|
|
159
|
+
format: effectiveWeekdayFormat,
|
|
140
160
|
style: weekdayStyle
|
|
141
161
|
}) : null;
|
|
142
162
|
default:
|
|
@@ -144,14 +164,12 @@ export var PisellDateTimeDisplay = function PisellDateTimeDisplay(props) {
|
|
|
144
164
|
}
|
|
145
165
|
};
|
|
146
166
|
|
|
147
|
-
//
|
|
167
|
+
// 单行布局:使用分隔符连接,支持每段不同分隔符(如 2025-12-31 - 2:00 周四)
|
|
148
168
|
if (layout === 'inline') {
|
|
149
|
-
|
|
169
|
+
var inlineSeparators = effectiveFields === null || effectiveFields === void 0 ? void 0 : effectiveFields.inlineSeparators;
|
|
150
170
|
var _renderedFields = fieldOrder.map(renderField).filter(function (field) {
|
|
151
171
|
return field !== null;
|
|
152
172
|
});
|
|
153
|
-
|
|
154
|
-
// 如果没有要显示的字段,返回 null
|
|
155
173
|
if (_renderedFields.length === 0) {
|
|
156
174
|
return null;
|
|
157
175
|
}
|
|
@@ -160,11 +178,12 @@ export var PisellDateTimeDisplay = function PisellDateTimeDisplay(props) {
|
|
|
160
178
|
style: containerInlineStyle,
|
|
161
179
|
onClick: onClick
|
|
162
180
|
}, _renderedFields.map(function (field, index) {
|
|
181
|
+
var _inlineSeparators$ind;
|
|
163
182
|
return /*#__PURE__*/React.createElement(React.Fragment, {
|
|
164
183
|
key: index
|
|
165
184
|
}, field, index < _renderedFields.length - 1 && /*#__PURE__*/React.createElement("span", {
|
|
166
185
|
className: "pisell-datetime-display-separator"
|
|
167
|
-
}, inlineSeparator));
|
|
186
|
+
}, (_inlineSeparators$ind = inlineSeparators === null || inlineSeparators === void 0 ? void 0 : inlineSeparators[index]) !== null && _inlineSeparators$ind !== void 0 ? _inlineSeparators$ind : inlineSeparator));
|
|
168
187
|
}));
|
|
169
188
|
}
|
|
170
189
|
|
|
@@ -187,20 +206,14 @@ export var PisellDateTimeDisplay = function PisellDateTimeDisplay(props) {
|
|
|
187
206
|
var currentLocale = currentTime.locale();
|
|
188
207
|
var isChinese = checkIsChinese(currentLocale);
|
|
189
208
|
|
|
190
|
-
//
|
|
209
|
+
// 当同时显示日期和星期时,使用合并格式;有相对日时只展示相对日,不展示具体日期与星期
|
|
191
210
|
if (showDate && showWeekday) {
|
|
192
|
-
var
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
} else {
|
|
199
|
-
// 英文环境:使用格式 "Sat, 21 Mar"
|
|
200
|
-
var _weekdayStr = currentTime.format('ddd'); // Sat
|
|
201
|
-
var _dateStr = currentTime.format('D MMM'); // 21 Mar
|
|
202
|
-
combinedStr = "".concat(_weekdayStr, ", ").concat(_dateStr);
|
|
203
|
-
}
|
|
211
|
+
var _labels$relativeDay;
|
|
212
|
+
var labels = effectiveDateFormat === null || effectiveDateFormat === void 0 ? void 0 : effectiveDateFormat.relativeDayLabels;
|
|
213
|
+
var dateStr = relativeDay ? (_labels$relativeDay = labels === null || labels === void 0 ? void 0 : labels[relativeDay]) !== null && _labels$relativeDay !== void 0 ? _labels$relativeDay : getRelativeDayLabel(relativeDay, currentTime.locale()) : isChinese ? currentTime.format('M月D日') : currentTime.format('D MMM');
|
|
214
|
+
var weekdayStr = currentTime.format('ddd');
|
|
215
|
+
// 相对日替换掉原日期展示:有今天/昨天/明天时只显示相对日,不拼接具体日期或星期
|
|
216
|
+
var combinedStr = relativeDay ? dateStr : isChinese ? "".concat(weekdayStr, " ").concat(dateStr) : "".concat(weekdayStr, ", ").concat(dateStr);
|
|
204
217
|
|
|
205
218
|
// 构建日期样式
|
|
206
219
|
var dateInlineStyle = {
|
|
@@ -26,6 +26,11 @@ export declare const InlineLayout: Story;
|
|
|
26
26
|
* 单行布局 - 自定义分隔符
|
|
27
27
|
*/
|
|
28
28
|
export declare const InlineWithCustomSeparator: Story;
|
|
29
|
+
/**
|
|
30
|
+
* 中文完整日期格式:2025-12-31 - 2:00 周四
|
|
31
|
+
* 单行、日期在前、日期与时间之间 " - "、时间与星期之间空格
|
|
32
|
+
*/
|
|
33
|
+
export declare const InlineDateTimeWeekdayZh: Story;
|
|
29
34
|
/**
|
|
30
35
|
* 12小时制
|
|
31
36
|
*/
|
|
@@ -62,6 +67,20 @@ export declare const DateDMY: Story;
|
|
|
62
67
|
* 中文日期带单位
|
|
63
68
|
*/
|
|
64
69
|
export declare const DateChinese: Story;
|
|
70
|
+
/**
|
|
71
|
+
* 相对日:今天/昨天/明天
|
|
72
|
+
* 与「当前日期」同天显示「今天」,前一天「昨天」,后一天「明天」;其他日期仍按原格式。
|
|
73
|
+
* 参考日为 dayjs(),随时间变化:例如 2 月 4 日当天,2 月 4 日显示「今天」,2 月 3 日显示「昨天」。
|
|
74
|
+
*/
|
|
75
|
+
export declare const RelativeDay: Story;
|
|
76
|
+
/**
|
|
77
|
+
* 相对日 - 英文
|
|
78
|
+
*/
|
|
79
|
+
export declare const RelativeDayEn: Story;
|
|
80
|
+
/**
|
|
81
|
+
* 相对日 - 自定义文案
|
|
82
|
+
*/
|
|
83
|
+
export declare const RelativeDayCustomLabels: Story;
|
|
65
84
|
/**
|
|
66
85
|
* 英文完整月份
|
|
67
86
|
*/
|
|
@@ -70,6 +70,28 @@ export var InlineWithCustomSeparator = {
|
|
|
70
70
|
}
|
|
71
71
|
};
|
|
72
72
|
|
|
73
|
+
/**
|
|
74
|
+
* 中文完整日期格式:2025-12-31 - 2:00 周四
|
|
75
|
+
* 单行、日期在前、日期与时间之间 " - "、时间与星期之间空格
|
|
76
|
+
*/
|
|
77
|
+
export var InlineDateTimeWeekdayZh = {
|
|
78
|
+
args: {
|
|
79
|
+
layout: 'inline',
|
|
80
|
+
locale: 'zh-cn',
|
|
81
|
+
fields: {
|
|
82
|
+
fieldOrder: ['date', 'time', 'weekday'],
|
|
83
|
+
inlineSeparators: [' - ', ' ']
|
|
84
|
+
},
|
|
85
|
+
dateFormat: {
|
|
86
|
+
order: 'YMD',
|
|
87
|
+
showYear: true,
|
|
88
|
+
separator: '-',
|
|
89
|
+
showChineseUnit: false,
|
|
90
|
+
showRelativeDay: false
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
73
95
|
/**
|
|
74
96
|
* 12小时制
|
|
75
97
|
*/
|
|
@@ -180,6 +202,58 @@ export var DateChinese = {
|
|
|
180
202
|
}
|
|
181
203
|
};
|
|
182
204
|
|
|
205
|
+
/**
|
|
206
|
+
* 相对日:今天/昨天/明天
|
|
207
|
+
* 与「当前日期」同天显示「今天」,前一天「昨天」,后一天「明天」;其他日期仍按原格式。
|
|
208
|
+
* 参考日为 dayjs(),随时间变化:例如 2 月 4 日当天,2 月 4 日显示「今天」,2 月 3 日显示「昨天」。
|
|
209
|
+
*/
|
|
210
|
+
export var RelativeDay = {
|
|
211
|
+
args: {
|
|
212
|
+
layout: 'horizontal',
|
|
213
|
+
dateFormat: {
|
|
214
|
+
showRelativeDay: true,
|
|
215
|
+
showYear: true,
|
|
216
|
+
showChineseUnit: true
|
|
217
|
+
},
|
|
218
|
+
locale: 'zh-cn'
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* 相对日 - 英文
|
|
224
|
+
*/
|
|
225
|
+
export var RelativeDayEn = {
|
|
226
|
+
args: {
|
|
227
|
+
layout: 'horizontal',
|
|
228
|
+
dateFormat: {
|
|
229
|
+
showRelativeDay: true,
|
|
230
|
+
order: 'MDY',
|
|
231
|
+
showYear: true
|
|
232
|
+
},
|
|
233
|
+
locale: 'en'
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* 相对日 - 自定义文案
|
|
239
|
+
*/
|
|
240
|
+
export var RelativeDayCustomLabels = {
|
|
241
|
+
args: {
|
|
242
|
+
layout: 'horizontal',
|
|
243
|
+
dateFormat: {
|
|
244
|
+
showRelativeDay: true,
|
|
245
|
+
relativeDayLabels: {
|
|
246
|
+
today: '今日',
|
|
247
|
+
yesterday: '昨日',
|
|
248
|
+
tomorrow: '翌日'
|
|
249
|
+
},
|
|
250
|
+
showYear: true,
|
|
251
|
+
showChineseUnit: true
|
|
252
|
+
},
|
|
253
|
+
locale: 'zh-cn'
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
|
|
183
257
|
/**
|
|
184
258
|
* 英文完整月份
|
|
185
259
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type
|
|
2
|
+
import { type Dayjs } from 'dayjs';
|
|
3
3
|
import type { DateFormatConfig, TextStyleConfig } from '../types';
|
|
4
4
|
/**
|
|
5
5
|
* DateDisplay 组件 Props
|
|
@@ -13,6 +13,10 @@ export interface DateDisplayProps {
|
|
|
13
13
|
* 日期格式配置
|
|
14
14
|
*/
|
|
15
15
|
format?: DateFormatConfig;
|
|
16
|
+
/**
|
|
17
|
+
* 参考日期(用于「今天/昨天/明天」判定,默认当前时间 dayjs())
|
|
18
|
+
*/
|
|
19
|
+
referenceDate?: Dayjs;
|
|
16
20
|
/**
|
|
17
21
|
* 文本样式
|
|
18
22
|
*/
|
|
@@ -27,6 +31,7 @@ export interface DateDisplayProps {
|
|
|
27
31
|
*
|
|
28
32
|
* @description
|
|
29
33
|
* - 格式化并展示日期
|
|
34
|
+
* - 支持 showRelativeDay:今天/昨天/明天时用相对日替换原日期展示,不展示具体日期
|
|
30
35
|
* - 支持不同的日期顺序(YMD/MDY/DMY)
|
|
31
36
|
* - 支持年月日字段显隐
|
|
32
37
|
* - 支持中文单位(年、月、日)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import dayjs from 'dayjs';
|
|
3
|
+
import { formatDate, getRelativeDay, getRelativeDayLabel } from "../utils";
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* DateDisplay 组件 Props
|
|
@@ -10,6 +11,7 @@ import { formatDate } from "../utils";
|
|
|
10
11
|
*
|
|
11
12
|
* @description
|
|
12
13
|
* - 格式化并展示日期
|
|
14
|
+
* - 支持 showRelativeDay:今天/昨天/明天时用相对日替换原日期展示,不展示具体日期
|
|
13
15
|
* - 支持不同的日期顺序(YMD/MDY/DMY)
|
|
14
16
|
* - 支持年月日字段显隐
|
|
15
17
|
* - 支持中文单位(年、月、日)
|
|
@@ -23,12 +25,17 @@ import { formatDate } from "../utils";
|
|
|
23
25
|
* />
|
|
24
26
|
*/
|
|
25
27
|
export var DateDisplay = function DateDisplay(_ref) {
|
|
28
|
+
var _labels$relativeDay;
|
|
26
29
|
var date = _ref.date,
|
|
27
30
|
format = _ref.format,
|
|
31
|
+
_ref$referenceDate = _ref.referenceDate,
|
|
32
|
+
referenceDate = _ref$referenceDate === void 0 ? dayjs() : _ref$referenceDate,
|
|
28
33
|
style = _ref.style,
|
|
29
34
|
className = _ref.className;
|
|
30
|
-
|
|
31
|
-
var
|
|
35
|
+
var labels = format === null || format === void 0 ? void 0 : format.relativeDayLabels;
|
|
36
|
+
var relativeDay = format !== null && format !== void 0 && format.showRelativeDay ? getRelativeDay(date, referenceDate) : null;
|
|
37
|
+
// 相对日替换原日期展示:有今天/昨天/明天时只显示相对日,不展示具体日期
|
|
38
|
+
var formattedDate = relativeDay ? (_labels$relativeDay = labels === null || labels === void 0 ? void 0 : labels[relativeDay]) !== null && _labels$relativeDay !== void 0 ? _labels$relativeDay : getRelativeDayLabel(relativeDay, date.locale()) : formatDate(date, format);
|
|
32
39
|
|
|
33
40
|
// 如果没有要显示的内容,返回 null
|
|
34
41
|
if (!formattedDate) {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { DateTimeDisplayFormatPreset } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* PisellDateTimeDisplay 按语言预设的格式
|
|
4
|
+
* - zh-cn:完整日期 - 时间 星期(如 2025-12-31 - 2:00 周四)、相对日今天/昨天/明天
|
|
5
|
+
* - en:时间 星期, 日期(如 2:00 Sat, 21 Mar, 2026)、相对日 Today/Yesterday/Tomorrow
|
|
6
|
+
*/
|
|
7
|
+
export declare const DATETIME_DISPLAY_FORMATS: Record<string, Partial<DateTimeDisplayFormatPreset>>;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PisellDateTimeDisplay 按语言预设的格式
|
|
3
|
+
* - zh-cn:完整日期 - 时间 星期(如 2025-12-31 - 2:00 周四)、相对日今天/昨天/明天
|
|
4
|
+
* - en:时间 星期, 日期(如 2:00 Sat, 21 Mar, 2026)、相对日 Today/Yesterday/Tomorrow
|
|
5
|
+
*/
|
|
6
|
+
export var DATETIME_DISPLAY_FORMATS = {
|
|
7
|
+
'zh-cn': {
|
|
8
|
+
dateFormat: {
|
|
9
|
+
order: 'YMD',
|
|
10
|
+
showYear: true,
|
|
11
|
+
separator: '-',
|
|
12
|
+
showChineseUnit: false,
|
|
13
|
+
showRelativeDay: true
|
|
14
|
+
},
|
|
15
|
+
timeFormat: {
|
|
16
|
+
use12Hour: false,
|
|
17
|
+
showSeconds: false
|
|
18
|
+
},
|
|
19
|
+
weekdayFormat: {
|
|
20
|
+
full: false,
|
|
21
|
+
singleLetter: false
|
|
22
|
+
},
|
|
23
|
+
fields: {
|
|
24
|
+
showTime: true,
|
|
25
|
+
showDate: true,
|
|
26
|
+
showWeekday: true,
|
|
27
|
+
fieldOrder: ['date', 'time', 'weekday'],
|
|
28
|
+
inlineSeparators: [' - ', ' ']
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
zh: {
|
|
32
|
+
// 兜底 zh
|
|
33
|
+
dateFormat: {
|
|
34
|
+
order: 'YMD',
|
|
35
|
+
showYear: true,
|
|
36
|
+
separator: '-',
|
|
37
|
+
showChineseUnit: false,
|
|
38
|
+
showRelativeDay: true
|
|
39
|
+
},
|
|
40
|
+
timeFormat: {
|
|
41
|
+
use12Hour: false,
|
|
42
|
+
showSeconds: false
|
|
43
|
+
},
|
|
44
|
+
weekdayFormat: {
|
|
45
|
+
full: false,
|
|
46
|
+
singleLetter: false
|
|
47
|
+
},
|
|
48
|
+
fields: {
|
|
49
|
+
showTime: true,
|
|
50
|
+
showDate: true,
|
|
51
|
+
showWeekday: true,
|
|
52
|
+
fieldOrder: ['date', 'time', 'weekday'],
|
|
53
|
+
inlineSeparators: [' - ', ' ']
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
en: {
|
|
57
|
+
dateFormat: {
|
|
58
|
+
order: 'DMY',
|
|
59
|
+
shortMonth: true,
|
|
60
|
+
showYear: true,
|
|
61
|
+
showRelativeDay: true,
|
|
62
|
+
useCommaBeforeYear: true
|
|
63
|
+
},
|
|
64
|
+
timeFormat: {
|
|
65
|
+
use12Hour: false,
|
|
66
|
+
showSeconds: false
|
|
67
|
+
},
|
|
68
|
+
weekdayFormat: {
|
|
69
|
+
full: false,
|
|
70
|
+
singleLetter: false,
|
|
71
|
+
trailingComma: true
|
|
72
|
+
},
|
|
73
|
+
fields: {
|
|
74
|
+
showTime: true,
|
|
75
|
+
showDate: true,
|
|
76
|
+
showWeekday: true,
|
|
77
|
+
fieldOrder: ['time', 'weekday', 'date'],
|
|
78
|
+
inlineSeparators: [' ', ' ']
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DATETIME_DISPLAY_FORMATS } from './dateTimeDisplayFormats';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DATETIME_DISPLAY_FORMATS } from "./dateTimeDisplayFormats";
|
|
@@ -15,7 +15,7 @@ export interface UseCurrentTimeOptions {
|
|
|
15
15
|
disabled?: boolean;
|
|
16
16
|
/**
|
|
17
17
|
* dayjs locale
|
|
18
|
-
* @default
|
|
18
|
+
* @default 优先使用全局配置,其次使用 i18n 当前语言(getCurrentLocale)
|
|
19
19
|
* @example 'zh-CN' | 'zh-HK' | 'en' | 'en-US' | 'ja'
|
|
20
20
|
*/
|
|
21
21
|
locale?: string;
|
|
@@ -30,7 +30,7 @@ export interface UseCurrentTimeOptions {
|
|
|
30
30
|
* @description
|
|
31
31
|
* - 自动创建定时器刷新时间
|
|
32
32
|
* - 支持自定义刷新间隔
|
|
33
|
-
* - 支持国际化(locale):优先级为 用户指定 > 全局配置 >
|
|
33
|
+
* - 支持国际化(locale):优先级为 用户指定 > 全局配置 > i18n 当前语言
|
|
34
34
|
* - 组件卸载时自动清除定时器
|
|
35
35
|
*
|
|
36
36
|
* @example
|
|
@@ -19,7 +19,7 @@ import usePisellConfig from "../../pisell-config-provider/hooks/usePisellConfig"
|
|
|
19
19
|
* @description
|
|
20
20
|
* - 自动创建定时器刷新时间
|
|
21
21
|
* - 支持自定义刷新间隔
|
|
22
|
-
* - 支持国际化(locale):优先级为 用户指定 > 全局配置 >
|
|
22
|
+
* - 支持国际化(locale):优先级为 用户指定 > 全局配置 > i18n 当前语言
|
|
23
23
|
* - 组件卸载时自动清除定时器
|
|
24
24
|
*
|
|
25
25
|
* @example
|
|
@@ -45,7 +45,7 @@ export function useCurrentTime(options) {
|
|
|
45
45
|
var globalConfig = usePisellConfig();
|
|
46
46
|
var globalLocale = globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.locale;
|
|
47
47
|
|
|
48
|
-
// 获取实际使用的 locale(优先级:用户指定 > 全局配置 >
|
|
48
|
+
// 获取实际使用的 locale(优先级:用户指定 > 全局配置 > i18n 当前语言)
|
|
49
49
|
var dayjsLocale = getDayjsLocale(userLocale || globalLocale);
|
|
50
50
|
|
|
51
51
|
// 初始化时间
|
|
@@ -99,6 +99,26 @@ export interface DateFormatConfig {
|
|
|
99
99
|
* @default true
|
|
100
100
|
*/
|
|
101
101
|
showDay?: boolean;
|
|
102
|
+
/**
|
|
103
|
+
* 英文 DMY 时年月之间是否加逗号(如 21 Mar, 2026;false 时为 22 Jan 2025)
|
|
104
|
+
* @default true
|
|
105
|
+
*/
|
|
106
|
+
useCommaBeforeYear?: boolean;
|
|
107
|
+
/**
|
|
108
|
+
* 是否在「今天/昨天/明天」时用相对日替换具体日期
|
|
109
|
+
* 开启后:与参考日同天显示「今天」,前一天「昨天」,后一天「明天」;其他日期仍按原格式
|
|
110
|
+
* @default false
|
|
111
|
+
*/
|
|
112
|
+
showRelativeDay?: boolean;
|
|
113
|
+
/**
|
|
114
|
+
* 相对日文案覆盖(用于 i18n 或自定义)
|
|
115
|
+
* 不传时按 locale 使用默认:zh 今天/昨天/明天,en Today/Yesterday/Tomorrow
|
|
116
|
+
*/
|
|
117
|
+
relativeDayLabels?: {
|
|
118
|
+
today?: string;
|
|
119
|
+
yesterday?: string;
|
|
120
|
+
tomorrow?: string;
|
|
121
|
+
};
|
|
102
122
|
}
|
|
103
123
|
/**
|
|
104
124
|
* 星期格式配置
|
|
@@ -116,6 +136,11 @@ export interface WeekdayFormatConfig {
|
|
|
116
136
|
* @example true -> "S" / "六" | false -> "Sat" / "周六"
|
|
117
137
|
*/
|
|
118
138
|
singleLetter?: boolean;
|
|
139
|
+
/**
|
|
140
|
+
* 是否在星期后加逗号(用于与日期拼接如 "Sat, 21 Mar, 2026")
|
|
141
|
+
* @default false
|
|
142
|
+
*/
|
|
143
|
+
trailingComma?: boolean;
|
|
119
144
|
}
|
|
120
145
|
/**
|
|
121
146
|
* 字段配置
|
|
@@ -141,6 +166,12 @@ export interface FieldConfig {
|
|
|
141
166
|
* @default ['time', 'date', 'weekday']
|
|
142
167
|
*/
|
|
143
168
|
fieldOrder?: FieldType[];
|
|
169
|
+
/**
|
|
170
|
+
* 单行布局时每段之间的分隔符,按顺序对应字段之间
|
|
171
|
+
* 如 ['date','time','weekday'] 配 inlineSeparators: [' - ', ' '] => "2025-12-31 - 2:00 周四"
|
|
172
|
+
* 不足时用组件 inlineSeparator 补齐
|
|
173
|
+
*/
|
|
174
|
+
inlineSeparators?: string[];
|
|
144
175
|
}
|
|
145
176
|
/**
|
|
146
177
|
* 文本样式配置
|
|
@@ -202,6 +233,16 @@ export interface ContainerStyleConfig {
|
|
|
202
233
|
*/
|
|
203
234
|
gap?: number | string;
|
|
204
235
|
}
|
|
236
|
+
/**
|
|
237
|
+
* 多语言格式预设(日期/时间/星期 + 字段顺序与分隔符)
|
|
238
|
+
* 用于 formatByLocale[locale] 或默认多语言配置
|
|
239
|
+
*/
|
|
240
|
+
export interface DateTimeDisplayFormatPreset {
|
|
241
|
+
dateFormat?: DateFormatConfig;
|
|
242
|
+
timeFormat?: TimeFormatConfig;
|
|
243
|
+
weekdayFormat?: WeekdayFormatConfig;
|
|
244
|
+
fields?: FieldConfig;
|
|
245
|
+
}
|
|
205
246
|
/**
|
|
206
247
|
* PisellDateTimeDisplay 组件 Props
|
|
207
248
|
*/
|
|
@@ -220,6 +261,11 @@ export interface PisellDateTimeDisplayProps {
|
|
|
220
261
|
* 字段显示配置
|
|
221
262
|
*/
|
|
222
263
|
fields?: FieldConfig;
|
|
264
|
+
/**
|
|
265
|
+
* 多语言格式配置:按 locale 取对应格式预设,再与下方单项配置合并(单项优先)
|
|
266
|
+
* @example formatByLocale={{ 'zh-cn': { dateFormat: {...}, fields: { fieldOrder: ['date','time','weekday'], inlineSeparators: [' - ', ' '] } }, 'en': {...} }}
|
|
267
|
+
*/
|
|
268
|
+
formatByLocale?: Record<string, Partial<DateTimeDisplayFormatPreset>>;
|
|
223
269
|
/**
|
|
224
270
|
* 时间格式配置
|
|
225
271
|
*/
|
|
@@ -274,11 +320,11 @@ export interface PisellDateTimeDisplayProps {
|
|
|
274
320
|
disableAutoRefresh?: boolean;
|
|
275
321
|
/**
|
|
276
322
|
* dayjs locale(语言代码)
|
|
277
|
-
* @default 优先使用全局配置(usePisellConfig
|
|
323
|
+
* @default 优先使用全局配置(usePisellConfig),其次使用 i18n 当前语言(getCurrentLocale:全局配置 / umi_locale)
|
|
278
324
|
* @example 'zh-CN' | 'zh-HK' | 'en' | 'en-US' | 'ja'
|
|
279
325
|
* @description
|
|
280
326
|
* - 支持标准 BCP 47 语言代码,会自动标准化为 dayjs 兼容格式
|
|
281
|
-
* - 优先级:组件 locale 属性 > PisellConfigProvider 全局配置 >
|
|
327
|
+
* - 优先级:组件 locale 属性 > PisellConfigProvider 全局配置 > i18n 当前语言
|
|
282
328
|
*/
|
|
283
329
|
locale?: string;
|
|
284
330
|
/**
|
|
@@ -41,7 +41,9 @@ export function formatDate(date, config) {
|
|
|
41
41
|
_ref$showMonth = _ref.showMonth,
|
|
42
42
|
showMonth = _ref$showMonth === void 0 ? true : _ref$showMonth,
|
|
43
43
|
_ref$showDay = _ref.showDay,
|
|
44
|
-
showDay = _ref$showDay === void 0 ? true : _ref$showDay
|
|
44
|
+
showDay = _ref$showDay === void 0 ? true : _ref$showDay,
|
|
45
|
+
_ref$useCommaBeforeYe = _ref.useCommaBeforeYear,
|
|
46
|
+
useCommaBeforeYear = _ref$useCommaBeforeYe === void 0 ? true : _ref$useCommaBeforeYe;
|
|
45
47
|
|
|
46
48
|
// 判断是否为中文环境
|
|
47
49
|
var locale = date.locale();
|
|
@@ -99,13 +101,10 @@ export function formatDate(date, config) {
|
|
|
99
101
|
return date.format(parts.join(''));
|
|
100
102
|
}
|
|
101
103
|
|
|
102
|
-
// MDY 格式特殊处理(英文习惯)
|
|
104
|
+
// MDY 格式特殊处理(英文习惯)Mar 21, 2026
|
|
103
105
|
if (order === 'MDY' && !isChinese) {
|
|
104
|
-
// 月日之间用空格,日年之间用逗号+空格
|
|
105
106
|
var formatted = date.format(parts.join(' '));
|
|
106
|
-
// 如果有年份,在日和年之间加逗号
|
|
107
107
|
if (showYear && showMonth && showDay) {
|
|
108
|
-
// 例如: "Mar 21 2026" -> "Mar 21, 2026"
|
|
109
108
|
var _formatted$split = formatted.split(' '),
|
|
110
109
|
_formatted$split2 = _slicedToArray(_formatted$split, 3),
|
|
111
110
|
month = _formatted$split2[0],
|
|
@@ -114,7 +113,6 @@ export function formatDate(date, config) {
|
|
|
114
113
|
return "".concat(month, " ").concat(day, ", ").concat(year);
|
|
115
114
|
}
|
|
116
115
|
if (showYear && showDay && !showMonth) {
|
|
117
|
-
// 例如: "21 2026" -> "21, 2026"
|
|
118
116
|
var _formatted$split3 = formatted.split(' '),
|
|
119
117
|
_formatted$split4 = _slicedToArray(_formatted$split3, 2),
|
|
120
118
|
_day = _formatted$split4[0],
|
|
@@ -124,6 +122,27 @@ export function formatDate(date, config) {
|
|
|
124
122
|
return formatted;
|
|
125
123
|
}
|
|
126
124
|
|
|
125
|
+
// DMY 格式英文:21 Mar, 2026 或 22 Jan 2025(useCommaBeforeYear 控制)
|
|
126
|
+
if (order === 'DMY' && !isChinese) {
|
|
127
|
+
var _formatted = date.format(parts.join(' '));
|
|
128
|
+
if (showYear && showMonth && showDay && useCommaBeforeYear) {
|
|
129
|
+
var _formatted$split5 = _formatted.split(' '),
|
|
130
|
+
_formatted$split6 = _slicedToArray(_formatted$split5, 3),
|
|
131
|
+
_day2 = _formatted$split6[0],
|
|
132
|
+
_month = _formatted$split6[1],
|
|
133
|
+
_year2 = _formatted$split6[2];
|
|
134
|
+
return "".concat(_day2, " ").concat(_month, ", ").concat(_year2);
|
|
135
|
+
}
|
|
136
|
+
if (showYear && showDay && !showMonth && useCommaBeforeYear) {
|
|
137
|
+
var _formatted$split7 = _formatted.split(' '),
|
|
138
|
+
_formatted$split8 = _slicedToArray(_formatted$split7, 2),
|
|
139
|
+
_day3 = _formatted$split8[0],
|
|
140
|
+
_year3 = _formatted$split8[1];
|
|
141
|
+
return "".concat(_day3, ", ").concat(_year3);
|
|
142
|
+
}
|
|
143
|
+
return _formatted;
|
|
144
|
+
}
|
|
145
|
+
|
|
127
146
|
// 其他情况使用分隔符
|
|
128
147
|
return date.format(parts.join(separator));
|
|
129
148
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Dayjs } from 'dayjs';
|
|
2
|
+
import type { DateFormatConfig, WeekdayFormatConfig } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* 获取「日期部分」的展示文案(相对日内置在 datetime)
|
|
5
|
+
* - 若开启 showRelativeDay 且日期为今天/昨天/明天,返回相对日文案(如「今天」「Yesterday」)
|
|
6
|
+
* - 否则返回「星期, 日期」格式(用于时间区间跨天等场景)
|
|
7
|
+
*
|
|
8
|
+
* 供 PisellDateTimeDisplay、PisellTimeRangeDisplay 等统一使用,相对时间逻辑只在此处维护
|
|
9
|
+
*/
|
|
10
|
+
export declare function getDatePartDisplay(params: {
|
|
11
|
+
date: Dayjs;
|
|
12
|
+
dateFormat?: DateFormatConfig;
|
|
13
|
+
weekdayFormat?: WeekdayFormatConfig;
|
|
14
|
+
referenceDate: Dayjs;
|
|
15
|
+
/** 覆盖日期格式(如跨天时的 order: 'DMY', shortMonth: true) */
|
|
16
|
+
dateFormatOverride?: Partial<DateFormatConfig>;
|
|
17
|
+
}): string;
|