@luoxiao123/angular-material-date-time-range-picker 21.0.0
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/LICENSE +21 -0
- package/README.md +324 -0
- package/fesm2022/luoxiao123-angular-material-date-time-range-picker.mjs +1219 -0
- package/fesm2022/luoxiao123-angular-material-date-time-range-picker.mjs.map +1 -0
- package/package.json +49 -0
- package/types/luoxiao123-angular-material-date-time-range-picker.d.ts +155 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 xylplm
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
# 📅 Angular Material Date Time Range Picker
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@luoxiao123/angular-material-date-time-range-picker)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+
[]()
|
|
6
|
+
[](https://github.com/xylplm/angular-material-date-time-range-picker)
|
|
7
|
+
|
|
8
|
+
一个强大而灵活的**日期时间范围选择器**组件库。
|
|
9
|
+
|
|
10
|
+
[English](README.en.md) | [中文](README.md)
|
|
11
|
+
|
|
12
|
+
## 📚 目录
|
|
13
|
+
|
|
14
|
+
- [描述](#描述)
|
|
15
|
+
- [安装](#安装)
|
|
16
|
+
- [快速开始](#快速开始)
|
|
17
|
+
- [使用指南](#使用指南)
|
|
18
|
+
- [API 文档](#api-文档)
|
|
19
|
+
- [配置](#配置)
|
|
20
|
+
- [Angular 版本兼容性](#angular-版本兼容性)
|
|
21
|
+
- [贡献](#贡献)
|
|
22
|
+
- [许可证](#许可证)
|
|
23
|
+
|
|
24
|
+
## 描述
|
|
25
|
+
|
|
26
|
+
基于 **Angular 21** 和 **Angular Material** 构建,提供以下功能:
|
|
27
|
+
|
|
28
|
+
- 🎯 **直观的日期范围选择界面** - 支持快速预设和精确选择
|
|
29
|
+
- 📱 **响应式设计** - 移动设备自动切换为全屏,桌面使用 Dialog
|
|
30
|
+
- 🧭 **完整的时间选择** - 支持日期、小时、分钟的精确选择(24小时制)
|
|
31
|
+
- 📅 **智能预设** - 相对时间、固定日期、当前周期快捷选择
|
|
32
|
+
- 💾 **双向数据绑定** - 支持 ControlValueAccessor 和 ngModel
|
|
33
|
+
- 🏗️ **mat-form-field 集成** - 完美适配 Angular Material 表单
|
|
34
|
+
- 🎨 **可定制化格式** - 自定义日期和值格式
|
|
35
|
+
- ✨ **完全可定制** - 所有选项都可配置
|
|
36
|
+
- 📖 **完整的类型定义** - 100% TypeScript 支持
|
|
37
|
+
- 🎨 **深色/浅色主题** - 完整支持
|
|
38
|
+
|
|
39
|
+
**快速链接:**
|
|
40
|
+
- 📦 [NPM 包](https://www.npmjs.com/package/@luoxiao123/angular-material-date-time-range-picker)
|
|
41
|
+
- 🎨 [在线演示](https://xylplm.github.io/angular-material-date-time-range-picker/)
|
|
42
|
+
- 📖 [GitHub 仓库](https://github.com/xylplm/angular-material-date-time-range-picker)
|
|
43
|
+
|
|
44
|
+
## 安装
|
|
45
|
+
|
|
46
|
+
通过 npm 安装:
|
|
47
|
+
|
|
48
|
+
```sh
|
|
49
|
+
npm install @luoxiao123/angular-material-date-time-range-picker --save
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
或使用 yarn:
|
|
53
|
+
|
|
54
|
+
```sh
|
|
55
|
+
yarn add @luoxiao123/angular-material-date-time-range-picker
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## 快速开始
|
|
59
|
+
|
|
60
|
+
### 使用 Standalone Components(推荐)
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
import { Component } from '@angular/core';
|
|
64
|
+
import { DatePickerComponent, DateTimePickerValue } from '@luoxiao123/angular-material-date-time-range-picker';
|
|
65
|
+
|
|
66
|
+
@Component({
|
|
67
|
+
selector: 'app-root',
|
|
68
|
+
standalone: true,
|
|
69
|
+
imports: [DatePickerComponent],
|
|
70
|
+
template: `
|
|
71
|
+
<date-time-picker
|
|
72
|
+
[(ngModel)]="selectedRange"
|
|
73
|
+
[required]="true"
|
|
74
|
+
[dateFormat]="'yyyy年M月d日 HH:mm'"
|
|
75
|
+
[optionalFeatures]="true"
|
|
76
|
+
(selectionChange)="onRangeSelected($event)"
|
|
77
|
+
/>
|
|
78
|
+
`,
|
|
79
|
+
})
|
|
80
|
+
export class AppComponent {
|
|
81
|
+
selectedRange: DateTimePickerValue | undefined;
|
|
82
|
+
|
|
83
|
+
onRangeSelected(range: DateTimePickerValue | undefined) {
|
|
84
|
+
if (range) {
|
|
85
|
+
console.log('Start:', range.start); // ISO 8601 format
|
|
86
|
+
console.log('End:', range.end); // ISO 8601 format
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### 在 mat-form-field 中使用
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
<mat-form-field>
|
|
96
|
+
<mat-label>选择日期时间范围</mat-label>
|
|
97
|
+
<date-time-picker
|
|
98
|
+
matInput
|
|
99
|
+
[(ngModel)]="selectedRange"
|
|
100
|
+
[required]="true"
|
|
101
|
+
[dateFormat]="'yyyy-MM-dd HH:mm'"
|
|
102
|
+
/>
|
|
103
|
+
@if (formControl.hasError('required')) {
|
|
104
|
+
<mat-error>此字段为必填</mat-error>
|
|
105
|
+
}
|
|
106
|
+
</mat-form-field>
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### 使用响应式表单
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
import { FormControl } from '@angular/forms';
|
|
113
|
+
|
|
114
|
+
export class AppComponent {
|
|
115
|
+
rangeControl = new FormControl<DateTimePickerValue | null>(null, Validators.required);
|
|
116
|
+
|
|
117
|
+
onSubmit() {
|
|
118
|
+
if (this.rangeControl.valid) {
|
|
119
|
+
const range = this.rangeControl.value;
|
|
120
|
+
console.log('Selected range:', range);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// 模板
|
|
126
|
+
<date-time-picker
|
|
127
|
+
[formControl]="rangeControl"
|
|
128
|
+
[dateFormat]="'yyyy-MM-dd HH:mm'"
|
|
129
|
+
/>
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### 使用 NgModule(传统方式)
|
|
133
|
+
|
|
134
|
+
如果您使用基于 NgModule 的项目:
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
import { NgModule } from '@angular/core';
|
|
138
|
+
import { DatePickerComponent } from '@luoxiao123/angular-material-date-time-range-picker';
|
|
139
|
+
|
|
140
|
+
@NgModule({
|
|
141
|
+
imports: [DatePickerComponent],
|
|
142
|
+
exports: [DatePickerComponent],
|
|
143
|
+
})
|
|
144
|
+
export class DateRangeModule {}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## 使用指南
|
|
148
|
+
|
|
149
|
+
### Standalone Components
|
|
150
|
+
|
|
151
|
+
推荐用于现代 Angular 应用的方式。直接在组件 imports 中使用。
|
|
152
|
+
|
|
153
|
+
### mat-form-field 集成
|
|
154
|
+
|
|
155
|
+
组件完美适配 Angular Material 的 `mat-form-field`,可自动应用表单样式和错误提示。
|
|
156
|
+
|
|
157
|
+
### 双向数据绑定
|
|
158
|
+
|
|
159
|
+
支持 `[(ngModel)]` 和响应式表单 `[formControl]`。
|
|
160
|
+
|
|
161
|
+
## API 文档
|
|
162
|
+
|
|
163
|
+
### 输入属性
|
|
164
|
+
|
|
165
|
+
| 属性 | 类型 | 默认值 | 说明 |
|
|
166
|
+
|------|------|--------|------|
|
|
167
|
+
| `ngModel` / `formControl` | `DateTimePickerValue \| null` | - | 选中的日期时间范围(支持双向绑定) |
|
|
168
|
+
| `required` | `boolean` | `false` | 是否为必填项 |
|
|
169
|
+
| `disabled` | `boolean` | `false` | 是否禁用组件 |
|
|
170
|
+
| `dateFormat` | `string` | `'yyyy年M月d日 HH:mm'` | 日期显示格式(DatePipe 格式) |
|
|
171
|
+
| `valueFormat` | `string` | `'yyyy-MM-dd HH:mm:ss'` | 值的输出格式(DatePipe 格式) |
|
|
172
|
+
| `optionalFeatures` | `boolean` | `true` | 是否启用星期选择和小时范围选择 |
|
|
173
|
+
| `future` | `boolean` | `false` | 是否允许选择未来日期 |
|
|
174
|
+
|
|
175
|
+
### 输出事件
|
|
176
|
+
|
|
177
|
+
| 属性 | 类型 | 说明 |
|
|
178
|
+
|------|------|------|
|
|
179
|
+
| `selectionChange` | `EventEmitter<DateTimePickerValue \| undefined>` | 日期范围选择完成时触发 |
|
|
180
|
+
|
|
181
|
+
### 数据结构
|
|
182
|
+
|
|
183
|
+
#### DateTimePickerValue
|
|
184
|
+
|
|
185
|
+
| 属性 | 类型 | 说明 |
|
|
186
|
+
|------|------|------|
|
|
187
|
+
| `start` | `string` | 开始日期时间 (ISO 8601) |
|
|
188
|
+
| `end` | `string` | 结束日期时间 (ISO 8601) |
|
|
189
|
+
|
|
190
|
+
#### TimeRange
|
|
191
|
+
|
|
192
|
+
| 属性 | 类型 | 说明 |
|
|
193
|
+
|------|------|------|
|
|
194
|
+
| `label` | `string` | 显示标签 |
|
|
195
|
+
| `start` | `string` | 开始时间表达式 |
|
|
196
|
+
| `end` | `string` | 结束时间表达式 |
|
|
197
|
+
|
|
198
|
+
## 配置
|
|
199
|
+
|
|
200
|
+
### 基础示例
|
|
201
|
+
|
|
202
|
+
```typescript
|
|
203
|
+
<date-time-picker
|
|
204
|
+
[(ngModel)]="selectedRange"
|
|
205
|
+
[required]="true"
|
|
206
|
+
[disabled]="isLoading"
|
|
207
|
+
[optionalFeatures]="true"
|
|
208
|
+
[future]="false"
|
|
209
|
+
[dateFormat]="'yyyy-MM-dd HH:mm'"
|
|
210
|
+
(selectionChange)="onRangeSelected($event)"
|
|
211
|
+
/>
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### 自定义日期格式
|
|
215
|
+
|
|
216
|
+
```typescript
|
|
217
|
+
// 中文格式
|
|
218
|
+
[dateFormat]="'yyyy年M月d日 HH:mm'"
|
|
219
|
+
|
|
220
|
+
// 英文格式
|
|
221
|
+
[dateFormat]="'MMM d, yyyy HH:mm'"
|
|
222
|
+
|
|
223
|
+
// 标准格式
|
|
224
|
+
[dateFormat]="'yyyy-MM-dd HH:mm:ss'"
|
|
225
|
+
|
|
226
|
+
// 仅显示日期
|
|
227
|
+
[dateFormat]="'yyyy-MM-dd'"
|
|
228
|
+
|
|
229
|
+
// 仅显示时间
|
|
230
|
+
[dateFormat]="'HH:mm'"
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### 设置初始值
|
|
234
|
+
|
|
235
|
+
```typescript
|
|
236
|
+
ngOnInit() {
|
|
237
|
+
const now = new Date();
|
|
238
|
+
const startDate = new Date(now.getFullYear(), now.getMonth(), 1);
|
|
239
|
+
const endDate = new Date(now.getFullYear(), now.getMonth() + 1, 0);
|
|
240
|
+
|
|
241
|
+
this.selectedRange = {
|
|
242
|
+
start: startDate.toISOString(),
|
|
243
|
+
end: endDate.toISOString()
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
### 禁用组件
|
|
249
|
+
|
|
250
|
+
```typescript
|
|
251
|
+
<date-time-picker
|
|
252
|
+
[(ngModel)]="selectedRange"
|
|
253
|
+
[disabled]="isLoading"
|
|
254
|
+
/>
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
### 启用未来日期选择
|
|
258
|
+
|
|
259
|
+
```typescript
|
|
260
|
+
<date-time-picker
|
|
261
|
+
[(ngModel)]="selectedRange"
|
|
262
|
+
[future]="true"
|
|
263
|
+
/>
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
### 禁用可选功能(星期和小时选择)
|
|
267
|
+
|
|
268
|
+
```typescript
|
|
269
|
+
<date-time-picker
|
|
270
|
+
[(ngModel)]="selectedRange"
|
|
271
|
+
[optionalFeatures]="false"
|
|
272
|
+
/>
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
## Angular 版本兼容性
|
|
276
|
+
|
|
277
|
+
| Angular 版本 | 支持情况 |
|
|
278
|
+
|------------|--------|
|
|
279
|
+
| 21.x | ✅ 完全支持 |
|
|
280
|
+
| 20.x | ⚠️ 可能需要调整 |
|
|
281
|
+
| < 20 | ❌ 不支持 |
|
|
282
|
+
|
|
283
|
+
## 浏览器兼容性
|
|
284
|
+
|
|
285
|
+
- Chrome (latest)
|
|
286
|
+
- Firefox (latest)
|
|
287
|
+
- Safari (latest)
|
|
288
|
+
- Edge (latest)
|
|
289
|
+
|
|
290
|
+
## 常见问题
|
|
291
|
+
|
|
292
|
+
### Q: 可以在 Angular 20 中使用吗?
|
|
293
|
+
A: 本库针对 Angular 21+ 优化。使用 Angular 20 可能存在兼容性问题。
|
|
294
|
+
|
|
295
|
+
### Q: 支持国际化吗?
|
|
296
|
+
A: 当前版本使用中文界面。欢迎提交 PR 添加多语言支持。
|
|
297
|
+
|
|
298
|
+
### Q: 可以自定义样式吗?
|
|
299
|
+
A: 支持。组件使用标准的 Material Design 样式,可通过 CSS 变量和自定义 CSS 进行定制。
|
|
300
|
+
|
|
301
|
+
### Q: 如何处理时区问题?
|
|
302
|
+
A: 组件使用 ISO 8601 格式,完整支持时区信息。
|
|
303
|
+
|
|
304
|
+
## 贡献
|
|
305
|
+
|
|
306
|
+
欢迎提交 Issues 和 Pull Requests!
|
|
307
|
+
|
|
308
|
+
### 报告 Bug
|
|
309
|
+
请提交详细的 bug 报告,包括:
|
|
310
|
+
- 重现步骤
|
|
311
|
+
- 预期行为
|
|
312
|
+
- 实际行为
|
|
313
|
+
- 环境信息(Angular 版本、浏览器等)
|
|
314
|
+
|
|
315
|
+
### 提交功能请求
|
|
316
|
+
在提交功能请求前,请先检查是否已存在相关议题。
|
|
317
|
+
|
|
318
|
+
## 致谢
|
|
319
|
+
|
|
320
|
+
本项目基于 [material-tailwind-range-date-picker](https://github.com/omidkh68/material-tailwind-range-date-picker) 二次开发重构,感谢原作者的杰出工作!
|
|
321
|
+
|
|
322
|
+
## 许可证
|
|
323
|
+
|
|
324
|
+
MIT License © 2026 [xylplm](https://github.com/xylplm)
|