zartui 2.0.90 → 2.0.91-beta.1

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.
@@ -3,7 +3,7 @@
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
4
 
5
5
  exports.__esModule = true;
6
- exports.default = void 0;
6
+ exports.default = exports.RANGE_END_PICKER = exports.RANGE_START_PICKER = void 0;
7
7
 
8
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
9
 
@@ -13,21 +13,325 @@ var _TimePicker = _interopRequireDefault(require("./TimePicker"));
13
13
 
14
14
  var _DatePicker = _interopRequireDefault(require("./DatePicker"));
15
15
 
16
+ var _date = require("../utils/validate/date");
17
+
18
+ var _popup = _interopRequireDefault(require("../popup"));
19
+
20
+ var _button = _interopRequireDefault(require("../button"));
21
+
22
+ var _toast = _interopRequireDefault(require("../toast"));
23
+
24
+ var _dayjs = _interopRequireDefault(require("dayjs"));
25
+
16
26
  var _createNamespace = (0, _utils.createNamespace)('datetime-picker'),
17
27
  createComponent = _createNamespace[0],
18
28
  bem = _createNamespace[1];
19
29
 
20
- var _default = createComponent({
21
- props: (0, _extends2.default)({}, _TimePicker.default.props, _DatePicker.default.props),
30
+ var RANGE_START_PICKER = 0;
31
+ exports.RANGE_START_PICKER = RANGE_START_PICKER;
32
+ var RANGE_END_PICKER = 1;
33
+ exports.RANGE_END_PICKER = RANGE_END_PICKER;
34
+
35
+ var _default2 = createComponent({
36
+ props: (0, _extends2.default)({}, _TimePicker.default.props, _DatePicker.default.props, {
37
+ // 是否开启时间范围选择
38
+ range: {
39
+ type: Boolean,
40
+ default: false
41
+ },
42
+ startValue: {
43
+ type: Date,
44
+ default: function _default() {
45
+ return new Date();
46
+ },
47
+ validator: _date.isDate
48
+ },
49
+ endValue: {
50
+ type: Date,
51
+ default: function _default() {
52
+ return new Date();
53
+ },
54
+ validator: _date.isDate
55
+ },
56
+ rangeHeaderStartText: {
57
+ type: String,
58
+ default: '开始时间'
59
+ },
60
+ rangeHeaderEndText: {
61
+ type: String,
62
+ default: '结束时间'
63
+ }
64
+ }),
65
+ data: function data() {
66
+ return {
67
+ rangeSelectedIndex: RANGE_START_PICKER,
68
+ refreshComputedKey: new Date().getTime(),
69
+ innerStartValue: this.startValue,
70
+ innerEndValue: this.endValue,
71
+ confirmedPopupPickerIndex: false
72
+ };
73
+ },
74
+ computed: {
75
+ currentStartText: function currentStartText() {
76
+ return this.genOriginValueText(this.innerStartValue);
77
+ },
78
+ currentEndText: function currentEndText() {
79
+ return this.genOriginValueText(this.innerEndValue);
80
+ }
81
+ },
82
+ watch: {
83
+ showPicker: function showPicker(val) {
84
+ var _this = this;
85
+
86
+ // 在第一次打开popup时,需要初始化内部picker存储的时间列index,避免初次打开直接关闭,导致picker内部index丢失
87
+ if (val && !this.confirmedPopupPickerIndex) {
88
+ // 注意这里实际上是双层nextTick,为了解决picker组件setConfirmIndex也在nextTick中执行,导致无法正确设置index的问题
89
+ this.$nextTick(function () {
90
+ _this.updatePickerConfirm();
91
+
92
+ _this.confirmedPopupPickerIndex = true;
93
+ });
94
+ }
95
+ }
96
+ },
22
97
  methods: {
23
98
  // @exposed-api
24
99
  getPicker: function getPicker() {
100
+ if (this.range) {
101
+ return [this.$refs.rangeStart.getProxiedPicker(), this.$refs.rangeEnd.getProxiedPicker()];
102
+ }
103
+
25
104
  return this.$refs.root.getProxiedPicker();
105
+ },
106
+ genValueText: function genValueText(dateValue, timeValue) {
107
+ var text = '';
108
+
109
+ if (dateValue.length > 0) {
110
+ text += dateValue.join('/');
111
+ }
112
+
113
+ if (timeValue.length > 0) {
114
+ text = text + ' ' + timeValue.join(':');
115
+ }
116
+
117
+ return text;
118
+ },
119
+ genOriginValueText: function genOriginValueText(values) {
120
+ if (!values) return '-';
121
+ var dateTime = (0, _dayjs.default)(values).format('YYYY-MM-DDTHH:mm:ss');
122
+ var dateTimeArr = dateTime.split(/[-T:]/);
123
+ var dateValues = [];
124
+ var timeValues = [];
125
+
126
+ if (this.$refs.rangeStart && this.$refs.rangeStart.originColumns) {
127
+ this.$refs.rangeStart.originColumns.forEach(function (_ref, index) {
128
+ var type = _ref.type;
129
+
130
+ if (index < dateTimeArr.length) {
131
+ if (['year', 'month', 'day'].includes(type)) {
132
+ dateValues.push(dateTimeArr[index]);
133
+ } else if (['hour', 'minute', 'second'].includes(type)) {
134
+ timeValues.push(dateTimeArr[index]);
135
+ }
136
+ }
137
+ });
138
+ return this.genValueText(dateValues, timeValues);
139
+ }
140
+ },
141
+ genRangeHeader: function genRangeHeader() {
142
+ var _this2 = this;
143
+
144
+ var h = this.$createElement;
145
+ return h("div", {
146
+ "class": bem('title-tab-bar')
147
+ }, [h("div", {
148
+ "class": [bem('title-bar', {
149
+ selected: this.rangeSelectedIndex === RANGE_START_PICKER,
150
+ unselected: this.rangeSelectedIndex === RANGE_END_PICKER
151
+ })],
152
+ "on": {
153
+ "click": function click() {
154
+ _this2.rangeSelectedIndex = RANGE_START_PICKER;
155
+ }
156
+ }
157
+ }, [h("div", {
158
+ "class": ['zt2-ellipsis', bem('title', {
159
+ selected: this.rangeSelectedIndex === RANGE_START_PICKER,
160
+ unselected: this.rangeSelectedIndex === RANGE_END_PICKER
161
+ })]
162
+ }, [this.rangeHeaderStartText]), h("div", {
163
+ "class": ['zt2-ellipsis', bem('value')]
164
+ }, [this.currentStartText])]), h("span", {
165
+ "class": bem('title-separator')
166
+ }), h("div", {
167
+ "class": [bem('title-bar', {
168
+ selected: this.rangeSelectedIndex === RANGE_END_PICKER,
169
+ unselected: this.rangeSelectedIndex === RANGE_START_PICKER
170
+ })],
171
+ "on": {
172
+ "click": function click() {
173
+ _this2.rangeSelectedIndex = RANGE_END_PICKER;
174
+ }
175
+ }
176
+ }, [h("div", {
177
+ "class": ['zt2-ellipsis', bem('title', {
178
+ selected: this.rangeSelectedIndex === RANGE_END_PICKER,
179
+ unselected: this.rangeSelectedIndex === RANGE_START_PICKER
180
+ })]
181
+ }, [this.rangeHeaderEndText]), h("div", {
182
+ "class": ['zt2-ellipsis', bem('value')]
183
+ }, [this.currentEndText])])]);
184
+ },
185
+ genCancel: function genCancel() {
186
+ var h = this.$createElement;
187
+ return h(_button.default, {
188
+ "attrs": {
189
+ "size": "normal",
190
+ "block": true
191
+ },
192
+ "style": {
193
+ marginRigth: '4px',
194
+ backgroundColor: 'white'
195
+ },
196
+ "on": {
197
+ "click": this.onCancel
198
+ }
199
+ }, [this.cancelButtonText || '取消']);
200
+ },
201
+ genConfirm: function genConfirm() {
202
+ var h = this.$createElement;
203
+ return h(_button.default, {
204
+ "attrs": {
205
+ "type": "primary",
206
+ "size": "normal",
207
+ "block": true
208
+ },
209
+ "style": {
210
+ marginLeft: '8px'
211
+ },
212
+ "on": {
213
+ "click": this.onConfirm
214
+ }
215
+ }, [this.confirmButtonText || '确认']);
216
+ },
217
+ genToolbar: function genToolbar() {
218
+ var h = this.$createElement;
219
+
220
+ if (this.showToolbar) {
221
+ return h("div", {
222
+ "class": bem('toolbar')
223
+ }, [[this.genCancel(), this.genConfirm()]]);
224
+ }
225
+ },
226
+
227
+ /**
228
+ * 这里必须手动调用一次picker组件内部pureRecordConfirmIndex,保证picker组件内部confirmIndex是当前选中的时间项index
229
+ */
230
+ updatePickerConfirm: function updatePickerConfirm() {
231
+ var _this3 = this;
232
+
233
+ this.$nextTick(function () {
234
+ var pickers = _this3.getPicker();
235
+
236
+ if (Array.isArray(pickers)) {
237
+ pickers.forEach(function (p) {
238
+ return p.pureRecordConfirmIndex();
239
+ });
240
+ }
241
+ });
242
+ },
243
+ checkRangeValid: function checkRangeValid() {
244
+ return (0, _dayjs.default)(this.innerEndValue).isAfter(this.innerStartValue);
245
+ },
246
+ onConfirm: function onConfirm() {
247
+ if (!this.checkRangeValid()) {
248
+ (0, _toast.default)('结束日期不能早于开始日期');
249
+ return;
250
+ }
251
+
252
+ this.updatePickerConfirm();
253
+ this.$emit('update:startValue', this.innerStartValue);
254
+ this.$emit('update:endValue', this.innerEndValue);
255
+ this.$emit('confirm', [this.innerStartValue, this.innerEndValue]);
256
+ },
257
+ onCancel: function onCancel() {
258
+ this.$emit('update:showPicker', false);
259
+ this.$emit('cancel');
26
260
  }
27
261
  },
28
262
  render: function render() {
263
+ var _this4 = this;
264
+
29
265
  var h = arguments[0];
30
266
  var Component = this.type === 'time' ? _TimePicker.default : _DatePicker.default;
267
+
268
+ if (this.range) {
269
+ var props = (0, _extends2.default)({}, this.$props, {
270
+ bem: bem,
271
+ showRange: true
272
+ });
273
+ var startRangeProps = (0, _extends2.default)({}, props, {
274
+ value: this.startValue
275
+ });
276
+ var startListener = (0, _extends2.default)({}, this.$listeners, {
277
+ input: function input(val) {
278
+ _this4.innerStartValue = val;
279
+ },
280
+ change: function change(pickerRef) {
281
+ _this4.$emit('startChange', pickerRef);
282
+ }
283
+ });
284
+ var endRangeProps = (0, _extends2.default)({}, props, {
285
+ value: this.endValue
286
+ });
287
+ var endListener = (0, _extends2.default)({}, this.$listeners, {
288
+ input: function input(val) {
289
+ _this4.innerEndValue = val;
290
+ },
291
+ change: function change(pickerRef) {
292
+ _this4.$emit('endChange', pickerRef);
293
+ }
294
+ });
295
+ return h(_popup.default, {
296
+ "attrs": {
297
+ "value": this.showPicker,
298
+ "round": true,
299
+ "position": "bottom"
300
+ },
301
+ "on": {
302
+ "input": function input(val) {
303
+ if (val) {
304
+ _this4.$emit('update:showPicker', true);
305
+ } else {
306
+ _this4.$emit('update:showPicker', false);
307
+ }
308
+ }
309
+ }
310
+ }, [this.genRangeHeader(), h("div", {
311
+ "class": bem('range')
312
+ }, [h(Component, {
313
+ "ref": "rangeStart",
314
+ "directives": [{
315
+ name: "show",
316
+ value: this.rangeSelectedIndex === RANGE_START_PICKER
317
+ }],
318
+ "class": bem(),
319
+ "scopedSlots": this.$scopedSlots,
320
+ "props": (0, _extends2.default)({}, startRangeProps),
321
+ "on": (0, _extends2.default)({}, startListener)
322
+ }), h(Component, {
323
+ "ref": "rangeEnd",
324
+ "directives": [{
325
+ name: "show",
326
+ value: this.rangeSelectedIndex === RANGE_END_PICKER
327
+ }],
328
+ "class": bem(),
329
+ "scopedSlots": this.$scopedSlots,
330
+ "props": (0, _extends2.default)({}, endRangeProps),
331
+ "on": (0, _extends2.default)({}, endListener)
332
+ })]), this.genToolbar()]);
333
+ }
334
+
31
335
  return h(Component, {
32
336
  "ref": "root",
33
337
  "class": bem(),
@@ -38,4 +342,4 @@ var _default = createComponent({
38
342
  }
39
343
  });
40
344
 
41
- exports.default = _default;
345
+ exports.default = _default2;
@@ -0,0 +1,81 @@
1
+ @import '../style/var';
2
+ @import '../style/hairline';
3
+
4
+ .@{base-prefix}-datetime-picker {
5
+ @date-time-picker-title-bar-selected-color: @blue;
6
+
7
+ &__title-tab-bar {
8
+ display: flex;
9
+ align-items: center;
10
+ }
11
+
12
+ &__title-bar {
13
+ display: flex;
14
+ flex-direction: column;
15
+ align-items: center;
16
+ padding: 12px;
17
+ flex: 1;
18
+ color: @text-color-default;
19
+
20
+ &--unselected {
21
+ color: @text-color-4;
22
+ }
23
+ }
24
+
25
+ &__title {
26
+ font-weight: bold;
27
+ font-size: @font-size-md;
28
+ line-height: @line-height-md;
29
+ height: @line-height-md;
30
+
31
+ &--selected {
32
+ color: @date-time-picker-title-bar-selected-color;
33
+ }
34
+
35
+ &--unselected {
36
+ font-weight: normal;
37
+ }
38
+ }
39
+
40
+ &__value {
41
+ font-size: @font-size-md;
42
+ line-height: @line-height-md;
43
+ height: @line-height-md;
44
+ margin-top: 4px;
45
+ }
46
+
47
+ &__toolbar {
48
+ box-sizing: content-box;
49
+ display: flex;
50
+ align-items: center;
51
+ justify-content: space-between;
52
+ height: @picker-toolbar-height;
53
+ padding: 8px 16px 8px 16px;
54
+ border-top: 1px solid rgba(45, 75, 115, 0.1);
55
+ position: relative;
56
+ }
57
+
58
+ &__cancel,
59
+ &__confirm {
60
+ height: 100%;
61
+ padding: @picker-action-padding;
62
+ font-size: @picker-action-font-size;
63
+ background-color: transparent;
64
+ border: none;
65
+ cursor: pointer;
66
+
67
+ &:active {
68
+ opacity: @active-opacity;
69
+ }
70
+ }
71
+
72
+ &__confirm {
73
+ color: @picker-confirm-action-color;
74
+ font-weight: @picker-confirm-action-font-weight;
75
+ }
76
+
77
+ &__cancel {
78
+ color: @picker-cancel-action-color;
79
+ font-weight: @picker-cancel-action-font-weight;
80
+ }
81
+ }
@@ -32,6 +32,10 @@ var sharedProps = (0, _extends2.default)({}, _shared.pickerProps, {
32
32
  default: function _default(type, value) {
33
33
  return value;
34
34
  }
35
+ },
36
+ showRange: {
37
+ type: Boolean,
38
+ default: false
35
39
  }
36
40
  });
37
41
  exports.sharedProps = sharedProps;
@@ -87,12 +91,12 @@ var TimePickerMixin = {
87
91
  var hour = t('hour');
88
92
  var minute = t('minute');
89
93
  var presetHeaders = {
90
- 'date': [year, month, day],
94
+ date: [year, month, day],
91
95
  'year-month': [year, month],
92
96
  'month-day': [month, day],
93
- 'time': [hour, minute],
94
- 'datetime': [year, month, day, hour, minute],
95
- 'datehour': [year, month, day, hour]
97
+ time: [hour, minute],
98
+ datetime: [year, month, day, hour, minute],
99
+ datehour: [year, month, day, hour]
96
100
  }; // console.log('type ' + this.type + ' ' + JSON.stringify(presetHeaders[this.type]))
97
101
 
98
102
  return presetHeaders[this.type] || [];
@@ -180,6 +184,15 @@ var TimePickerMixin = {
180
184
  Object.keys(_shared.pickerProps).forEach(function (key) {
181
185
  props[key] = _this6[key];
182
186
  });
187
+
188
+ if (this.showRange) {
189
+ (0, _extends2.default)(props, {
190
+ popup: false,
191
+ showToolbar: false,
192
+ title: ''
193
+ });
194
+ }
195
+
183
196
  return h(_picker.default, {
184
197
  "attrs": {
185
198
  "show-picker": this.showPicker,
@@ -4,5 +4,7 @@ require('../../info/index.css');
4
4
  require('../../icon/index.css');
5
5
  require('../../popup/index.css');
6
6
  require('../../loading/index.css');
7
+ require('../../toast/index.css');
7
8
  require('../../button/index.css');
8
- require('../../picker/index.css');
9
+ require('../../picker/index.css');
10
+ require('../index.css');
@@ -4,5 +4,7 @@ require('../../info/index.less');
4
4
  require('../../icon/index.less');
5
5
  require('../../popup/index.less');
6
6
  require('../../loading/index.less');
7
+ require('../../toast/index.less');
7
8
  require('../../button/index.less');
8
- require('../../picker/index.less');
9
+ require('../../picker/index.less');
10
+ require('../index.less');