1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = void 0;
|
7 |
|
8 | var _vue = require("vue");
|
9 |
|
10 | var _vueTypes = _interopRequireDefault(require("../_util/vue-types"));
|
11 |
|
12 | var _BaseMixin = _interopRequireDefault(require("../_util/BaseMixin"));
|
13 |
|
14 | var _moment = _interopRequireDefault(require("moment"));
|
15 |
|
16 | var _antInputDirective = _interopRequireDefault(require("../_util/antInputDirective"));
|
17 |
|
18 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
19 |
|
20 | var Header = {
|
21 | inheritAttrs: false,
|
22 | name: 'Header',
|
23 | mixins: [_BaseMixin.default],
|
24 | props: {
|
25 | format: _vueTypes.default.string,
|
26 | prefixCls: _vueTypes.default.string,
|
27 | disabledDate: _vueTypes.default.func,
|
28 | placeholder: _vueTypes.default.string,
|
29 | clearText: _vueTypes.default.string,
|
30 | value: _vueTypes.default.object,
|
31 | inputReadOnly: _vueTypes.default.looseBool.def(false),
|
32 | hourOptions: _vueTypes.default.array,
|
33 | minuteOptions: _vueTypes.default.array,
|
34 | secondOptions: _vueTypes.default.array,
|
35 | disabledHours: _vueTypes.default.func,
|
36 | disabledMinutes: _vueTypes.default.func,
|
37 | disabledSeconds: _vueTypes.default.func,
|
38 |
|
39 |
|
40 |
|
41 | allowEmpty: _vueTypes.default.looseBool,
|
42 | defaultOpenValue: _vueTypes.default.object,
|
43 | currentSelectPanel: _vueTypes.default.string,
|
44 | focusOnOpen: _vueTypes.default.looseBool,
|
45 |
|
46 | clearIcon: _vueTypes.default.any
|
47 | },
|
48 | data: function data() {
|
49 | var value = this.value,
|
50 | format = this.format;
|
51 | return {
|
52 | str: value && value.format(format) || '',
|
53 | invalid: false
|
54 | };
|
55 | },
|
56 | mounted: function mounted() {
|
57 | var _this = this;
|
58 |
|
59 | if (this.focusOnOpen) {
|
60 |
|
61 | var requestAnimationFrame = window.requestAnimationFrame || window.setTimeout;
|
62 | requestAnimationFrame(function () {
|
63 | _this.refInput.focus();
|
64 |
|
65 | _this.refInput.select();
|
66 | });
|
67 | }
|
68 | },
|
69 | watch: {
|
70 | value: function value(val) {
|
71 | var _this2 = this;
|
72 |
|
73 | this.$nextTick(function () {
|
74 | _this2.setState({
|
75 | str: val && val.format(_this2.format) || '',
|
76 | invalid: false
|
77 | });
|
78 | });
|
79 | }
|
80 | },
|
81 | methods: {
|
82 | onInputChange: function onInputChange(e) {
|
83 | var _e$target = e.target,
|
84 | str = _e$target.value,
|
85 | composing = _e$target.composing;
|
86 | var _this$str = this.str,
|
87 | oldStr = _this$str === void 0 ? '' : _this$str;
|
88 | if (e.isComposing || composing || oldStr === str) return;
|
89 | this.setState({
|
90 | str: str
|
91 | });
|
92 | var format = this.format,
|
93 | hourOptions = this.hourOptions,
|
94 | minuteOptions = this.minuteOptions,
|
95 | secondOptions = this.secondOptions,
|
96 | disabledHours = this.disabledHours,
|
97 | disabledMinutes = this.disabledMinutes,
|
98 | disabledSeconds = this.disabledSeconds,
|
99 | originalValue = this.value;
|
100 |
|
101 | if (str) {
|
102 | var value = this.getProtoValue().clone();
|
103 | var parsed = (0, _moment.default)(str, format, true);
|
104 |
|
105 | if (!parsed.isValid()) {
|
106 | this.setState({
|
107 | invalid: true
|
108 | });
|
109 | return;
|
110 | }
|
111 |
|
112 | value.hour(parsed.hour()).minute(parsed.minute()).second(parsed.second());
|
113 |
|
114 | if (hourOptions.indexOf(value.hour()) < 0 || minuteOptions.indexOf(value.minute()) < 0 || secondOptions.indexOf(value.second()) < 0) {
|
115 | this.setState({
|
116 | invalid: true
|
117 | });
|
118 | return;
|
119 | }
|
120 |
|
121 |
|
122 | var disabledHourOptions = disabledHours();
|
123 | var disabledMinuteOptions = disabledMinutes(value.hour());
|
124 | var disabledSecondOptions = disabledSeconds(value.hour(), value.minute());
|
125 |
|
126 | if (disabledHourOptions && disabledHourOptions.indexOf(value.hour()) >= 0 || disabledMinuteOptions && disabledMinuteOptions.indexOf(value.minute()) >= 0 || disabledSecondOptions && disabledSecondOptions.indexOf(value.second()) >= 0) {
|
127 | this.setState({
|
128 | invalid: true
|
129 | });
|
130 | return;
|
131 | }
|
132 |
|
133 | if (originalValue) {
|
134 | if (originalValue.hour() !== value.hour() || originalValue.minute() !== value.minute() || originalValue.second() !== value.second()) {
|
135 |
|
136 | var changedValue = originalValue.clone();
|
137 | changedValue.hour(value.hour());
|
138 | changedValue.minute(value.minute());
|
139 | changedValue.second(value.second());
|
140 |
|
141 | this.__emit('change', changedValue);
|
142 | }
|
143 | } else if (originalValue !== value) {
|
144 | this.__emit('change', value);
|
145 | }
|
146 | } else {
|
147 | this.__emit('change', null);
|
148 | }
|
149 |
|
150 | this.setState({
|
151 | invalid: false
|
152 | });
|
153 | },
|
154 | onKeyDown: function onKeyDown(e) {
|
155 | if (e.keyCode === 27) {
|
156 | this.__emit('esc');
|
157 | }
|
158 |
|
159 | this.__emit('keydown', e);
|
160 | },
|
161 | getProtoValue: function getProtoValue() {
|
162 | return this.value || this.defaultOpenValue;
|
163 | },
|
164 | getInput: function getInput() {
|
165 | var _this3 = this;
|
166 |
|
167 | var prefixCls = this.prefixCls,
|
168 | placeholder = this.placeholder,
|
169 | inputReadOnly = this.inputReadOnly,
|
170 | invalid = this.invalid,
|
171 | str = this.str;
|
172 | var invalidClass = invalid ? "".concat(prefixCls, "-input-invalid") : '';
|
173 | return (0, _vue.withDirectives)((0, _vue.createVNode)("input", {
|
174 | "class": "".concat(prefixCls, "-input ").concat(invalidClass),
|
175 | "ref": function ref(_ref) {
|
176 | _this3.refInput = _ref;
|
177 | },
|
178 | "onKeydown": this.onKeyDown,
|
179 | "value": str,
|
180 | "placeholder": placeholder,
|
181 | "onInput": this.onInputChange,
|
182 | "onChange": this.onInputChange,
|
183 | "readonly": !!inputReadOnly
|
184 | }, null), [[_antInputDirective.default]]);
|
185 | }
|
186 | },
|
187 | render: function render() {
|
188 | var prefixCls = this.prefixCls;
|
189 | return (0, _vue.createVNode)("div", {
|
190 | "class": "".concat(prefixCls, "-input-wrap")
|
191 | }, [this.getInput()]);
|
192 | }
|
193 | };
|
194 | var _default = Header;
|
195 | exports.default = _default; |
\ | No newline at end of file |