renusify 1.1.0 → 1.1.2

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.
@@ -1,649 +1,658 @@
1
1
  <template>
2
- <div :class="`${$r.prefix}timepicker-clock`">
3
- <div ref="clock" class="clock ltr">
4
- <div ref="circle" class="circle" :class="{ 'is-small': isSmall }"></div>
5
- <div ref="center" class="center"></div>
6
- <div ref="hand" class="clock-item-hand hour"></div>
7
-
8
- <div
9
- v-for="(hour, i) in nums"
10
- :key="i"
11
- class="number"
12
- :class="['number' + i]"
13
- :ref="'number' + i"
14
- @click="set(i)"
15
- >
16
- {{ hour }}
17
- </div>
18
- </div>
19
- <div class="text-meridiem ltr" v-if="!is24Hour">
20
- <div
21
- class="time-meridiem"
22
- @click="(meridiem = 'AM'),emit()"
23
- :class="{ 'meridiem-active': meridiem === 'AM' }"
24
- >
25
- {{$t('timepicker_am','renusify')}}
26
- </div>
27
- <div
28
- class="time-meridiem"
29
- @click="(meridiem = 'PM'),emit()"
30
- :class="{ 'meridiem-active': meridiem === 'PM' }"
31
- >
32
- {{$t('timepicker_pm','renusify')}}
33
- </div>
34
- </div>
35
- <div class="text-time ltr">
36
- <input
37
- @input="emit"
38
- v-model="hour"
39
- placeholder="00"
40
- @update:model-value="handle_hour()"
41
- @click.prevent.stop="handle_hour(false)"
42
- class="time-show"
43
- :class="{
2
+ <div :class="`${$r.prefix}timepicker-clock`">
3
+ <div ref="clock" class="clock ltr">
4
+ <div ref="circle" class="circle" :class="{ 'is-small': isSmall }"></div>
5
+ <div ref="center" class="center"></div>
6
+ <div ref="hand" class="clock-item-hand hour"></div>
7
+
8
+ <div
9
+ v-for="(num, i) in nums"
10
+ :key="i"
11
+ class="number"
12
+ :class="['number' + i,{'number-disabled':disableTime(parseInt(i),show,hour,min,sec)}]"
13
+ :ref="'number' + i"
14
+ @click="set(i)"
15
+ >
16
+ {{ num }}
17
+ </div>
18
+ </div>
19
+ <div class="text-meridiem ltr" v-if="!is24Hour">
20
+ <div
21
+ class="time-meridiem"
22
+ @click="(meridiem = 'AM'),emit()"
23
+ :class="{ 'meridiem-active': meridiem === 'AM' }"
24
+ >
25
+ {{ $t('timepicker_am', 'renusify') }}
26
+ </div>
27
+ <div
28
+ class="time-meridiem"
29
+ @click="(meridiem = 'PM'),emit()"
30
+ :class="{ 'meridiem-active': meridiem === 'PM' }"
31
+ >
32
+ {{ $t('timepicker_pm', 'renusify') }}
33
+ </div>
34
+ </div>
35
+ <div class="text-time ltr">
36
+ <input
37
+ @input="emit"
38
+ v-model="hour"
39
+ placeholder="00"
40
+ @update:model-value="handle_hour()"
41
+ @click.prevent.stop="handle_hour(false)"
42
+ class="time-show"
43
+ :class="{
44
44
  'time-active': show === 'hours24'||show==='hours12',
45
45
  'time-selected': hour != null
46
46
  }"
47
- />
48
- <div class="t-text">:</div>
49
- <input
50
- @input="emit"
51
- v-model="min"
52
- placeholder="00"
53
- @update:model-value="handle_min()"
54
- @click.prevent.stop="handle_min(false)"
55
- class="time-show"
56
- :class="{
47
+ />
48
+ <div class="t-text">:</div>
49
+ <input
50
+ @input="emit"
51
+ v-model="min"
52
+ placeholder="00"
53
+ @update:model-value="handle_min()"
54
+ @click.prevent.stop="handle_min(false)"
55
+ class="time-show"
56
+ :class="{
57
57
  'time-active': show === 'mins',
58
58
  'time-selected': min != null
59
59
  }"
60
- />
61
- <div class="t-text" v-if="withSec">:</div>
62
- <input
63
- @input="emit"
64
- v-if="withSec"
65
- v-model="sec"
66
- placeholder="00"
67
- @update:model-value="handle_sec()"
68
- @click.prevent.stop="handle_sec(false)"
69
- class="time-show"
70
- :class="{
60
+ />
61
+ <div class="t-text" v-if="withSec">:</div>
62
+ <input
63
+ @input="emit"
64
+ v-if="withSec"
65
+ v-model="sec"
66
+ placeholder="00"
67
+ @update:model-value="handle_sec()"
68
+ @click.prevent.stop="handle_sec(false)"
69
+ class="time-show"
70
+ :class="{
71
71
  'time-active': show === 'seconds',
72
72
  'time-selected': sec != null
73
73
  }"
74
- />
75
- </div>
74
+ />
76
75
  </div>
76
+ </div>
77
77
  </template>
78
78
 
79
79
  <script>
80
- export default {
81
- name: "timepicker",
82
- props: {
83
- withSec: Boolean,
84
- is24Hour: Boolean,
85
- modelValue: String
86
- },
87
- data() {
88
- return {
89
- show: this.is24Hour ? "hours24" : "hours12",
90
- hour: 0,
91
- meridiem: "AM",
92
- min: 0,
93
- sec: 0,
94
- isSmall: false,
95
- isHand: false,
96
- hours12: {
97
- 1: "1",
98
- 2: "2",
99
- 3: "3",
100
- 4: "4",
101
- 5: "5",
102
- 6: "6",
103
- 7: "7",
104
- 8: "8",
105
- 9: "9",
106
- 10: "10",
107
- 11: "11",
108
- 12: "12"
109
- },
110
- hours24: {
111
- 1: "1",
112
- 2: "2",
113
- 3: "3",
114
- 4: "4",
115
- 5: "5",
116
- 6: "6",
117
- 7: "7",
118
- 8: "8",
119
- 9: "9",
120
- 10: "10",
121
- 11: "11",
122
- 12: "12",
123
- 0: "0",
124
- 13: "13",
125
- 14: "14",
126
- 15: "15",
127
- 16: "16",
128
- 17: "17",
129
- 18: "18",
130
- 19: "19",
131
- 20: "20",
132
- 21: "21",
133
- 22: "22",
134
- 23: "23"
135
- },
136
- mins: {
137
- 0: "0",
138
- 1: "",
139
- 2: "",
140
- 3: "",
141
- 4: "",
142
- 5: "5",
143
- 6: "",
144
- 7: "",
145
- 8: "",
146
- 9: "",
147
- 10: "10",
148
- 11: "",
149
- 12: "",
150
- 13: "",
151
- 14: "",
152
- 15: "15",
153
- 16: "",
154
- 17: "",
155
- 18: "",
156
- 19: "",
157
- 20: "20",
158
- 21: "",
159
- 22: "",
160
- 23: "",
161
- 24: "",
162
- 25: "25",
163
- 26: "",
164
- 27: "",
165
- 28: "",
166
- 29: "",
167
- 30: "30",
168
- 31: "",
169
- 32: "",
170
- 33: "",
171
- 34: "",
172
- 35: "35",
173
- 36: "",
174
- 37: "",
175
- 38: "",
176
- 39: "",
177
- 40: "40",
178
- 41: "",
179
- 42: "",
180
- 43: "",
181
- 44: "",
182
- 45: "45",
183
- 46: "",
184
- 47: "",
185
- 48: "",
186
- 49: "",
187
- 50: "50",
188
- 51: "",
189
- 52: "",
190
- 53: "",
191
- 54: "",
192
- 55: "55",
193
- 56: "",
194
- 57: "",
195
- 58: "",
196
- 59: ""
197
- },
198
- seconds: {
199
- 0: "0",
200
- 1: "",
201
- 2: "",
202
- 3: "",
203
- 4: "",
204
- 5: "5",
205
- 6: "",
206
- 7: "",
207
- 8: "",
208
- 9: "",
209
- 10: "10",
210
- 11: "",
211
- 12: "",
212
- 13: "",
213
- 14: "",
214
- 15: "15",
215
- 16: "",
216
- 17: "",
217
- 18: "",
218
- 19: "",
219
- 20: "20",
220
- 21: "",
221
- 22: "",
222
- 23: "",
223
- 24: "",
224
- 25: "25",
225
- 26: "",
226
- 27: "",
227
- 28: "",
228
- 29: "",
229
- 30: "30",
230
- 31: "",
231
- 32: "",
232
- 33: "",
233
- 34: "",
234
- 35: "35",
235
- 36: "",
236
- 37: "",
237
- 38: "",
238
- 39: "",
239
- 40: "40",
240
- 41: "",
241
- 42: "",
242
- 43: "",
243
- 44: "",
244
- 45: "45",
245
- 46: "",
246
- 47: "",
247
- 48: "",
248
- 49: "",
249
- 50: "50",
250
- 51: "",
251
- 52: "",
252
- 53: "",
253
- 54: "",
254
- 55: "55",
255
- 56: "",
256
- 57: "",
257
- 58: "",
258
- 59: ""
259
- }
260
- };
261
- },
262
- mounted() {
263
- this.setup_hour();
264
- this.parser(this.modelValue)
265
- },
266
- computed: {
267
- nums() {
268
- return this[this.show];
269
- }
270
- },
271
- methods: {
272
- parser(txt) {
273
- if (!txt) {
274
- return
275
- }
276
- txt = txt.split(' ')
277
- if (txt.length === 2) {
278
- this.meridiem = txt[1]
279
- }
280
- txt = txt[0].split(':')
281
- this.hour = parseInt(txt[0])
282
- this.min = parseInt(txt[1])
283
- this.handle_hour(false)
284
- },
285
- emit() {
286
- let hour = this.hour
287
- let min = this.min
288
- let sec = this.sec
289
- if (hour < 10) {
290
- hour = '0' + hour;
291
- }
292
- if (min < 10) {
293
- min = '0' + min;
294
- }
295
- if (sec < 10) {
296
- sec = '0' + sec;
297
- }
298
- let n = hour + ":" + min;
299
- if (this.withSec) {
300
- n += ":" + sec;
301
- }
302
- if (!this.is24Hour) {
303
- n += " " + this.meridiem;
304
- }
305
- this.$emit("update:model-value", n);
306
- if ((min !== null && !this.withSec) || sec !== null) {
307
- this.$emit("finish", true);
308
- }
309
- },
310
- handle_hour(next = true) {
311
- if (this.hour > (this.is24Hour ? 23 : 12)) {
312
- this.hour = this.is24Hour ? 23 : 12;
313
- }
314
-
315
- this.show = this.is24Hour ? "hours24" : "hours12";
316
- setTimeout(() => {
317
- this.setup_hour();
318
- this.hour && this.set(this.hour, next);
319
- }, 10);
320
- },
321
- handle_min(next = true) {
322
- if (this.min > 59) {
323
- this.min = 59;
324
- }
325
- this.show = "mins";
326
-
327
- setTimeout(() => {
328
- this.setup_min();
329
- this.min && this.set(this.min, next);
330
- }, 10);
331
- },
332
- handle_sec(next = true) {
333
- if (this.sec > 59) {
334
- this.sec = 59;
335
- }
336
- this.show = "seconds";
337
- setTimeout(() => {
338
- this.setup_min();
339
- this.sec && this.set(this.sec, next);
340
- }, 10);
341
- },
342
-
343
- set(h, next = true) {
344
- h = parseInt(h);
345
- const circle = this.$refs.circle;
346
- const cl = this.$refs["number" + h];
347
- const hand = this.$refs.hand;
348
- const clock = this.$refs.clock.getBoundingClientRect();
349
-
350
- const b = cl.getBoundingClientRect();
351
- circle.style.top = parseInt(cl.style.top) + 10 + "px";
352
- circle.style.left = parseInt(cl.style.left) + 10 + "px";
353
-
354
- let ang = this.angle(
355
- b.left + 10,
356
- b.top + 10,
357
- clock.width / 2 + clock.left,
358
- clock.top,
359
- clock.width / 2 + clock.left,
360
- clock.height / 2 + clock.top
361
- );
362
- if (
363
- (this.show === "hours24" || this.show === "hours12") &&
364
- ((h > 6 && h < 13) || (h > 18 && h <= 23))
365
- ) {
366
- ang = 180 + 180 - ang;
367
- } else if (h > 30) {
368
- ang = 180 + 180 - ang;
369
- }
370
- hand.style.transform = "rotate(" + ang + "deg)";
371
-
372
- if (this.show === "hours24" && (h === 0 || h >= 13)) {
373
- hand.style.height = "60px";
374
- } else {
375
- hand.style.height = "100px";
376
- }
377
-
378
- if (!next) {
379
- return
380
- }
381
- if (this.show === "hours24") {
382
- this.show = "mins";
383
- this.hour = h;
384
- setTimeout(() => {
385
- this.setup_min();
386
- }, 10);
387
- } else if (this.show === "hours12") {
388
- this.show = "mins";
389
- setTimeout(() => {
390
- this.setup_min();
391
- }, 10);
392
- this.hour = h;
393
- } else if (this.show === "mins") {
394
- this.min = h;
395
- if ([0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55].includes(h)) {
396
- this.isSmall = false;
397
- this.isHand = false;
398
- } else {
399
- this.isSmall = true;
400
- this.isHand = true;
401
- }
402
- if (this.withSec) {
403
- this.show = "seconds";
404
- setTimeout(() => {
405
- this.setup_min();
406
- }, 10);
407
- }
408
- } else {
409
- this.sec = h;
410
- }
411
- this.emit();
412
- },
413
- angle(p1x, p1y, p2x, p2y, p3x, p3y) {
414
- let p0c = Math.sqrt(Math.pow(p3x - p1x, 2) + Math.pow(p3y - p1y, 2));
415
- let p1c = Math.sqrt(Math.pow(p3x - p2x, 2) + Math.pow(p3y - p2y, 2));
416
- let p0p1 = Math.sqrt(Math.pow(p2x - p1x, 2) + Math.pow(p2y - p1y, 2));
417
- return (
418
- Math.acos((p1c * p1c + p0c * p0c - p0p1 * p0p1) / (2 * p1c * p0c)) *
419
- (180 / Math.PI)
420
- );
421
- },
422
-
423
- movePointAtAngle(point, angle, distance) {
424
- return [
425
- point[0] + Math.sin(angle) * distance,
426
- point[1] - Math.cos(angle) * distance
427
- ];
428
- },
429
-
430
- print_point(n, lng, nums = 12) {
431
- return this.movePointAtAngle([130, 130], ((Math.PI * 2) / nums) * n, lng);
432
- },
433
- setup_hour() {
434
- let cl = null;
435
- let po = null;
436
- for (let i = 1; i <= 12; i++) {
437
- cl = this.$refs["number" + i];
438
- po = this.print_point(i, 110);
439
- cl.style.left = po[0] - 10 + "px";
440
- cl.style.top = po[1] - 10 + "px";
441
- cl.classList.add('number-show')
442
- }
443
- if (this.is24Hour) {
444
- for (let i = 13; i <= 23; i++) {
445
- cl = this.$refs["number" + i];
446
- po = this.print_point(i, 70);
447
- cl.style.left = po[0] - 10 + "px";
448
- cl.style.top = po[1] - 10 + "px";
449
- cl.classList.add('number-show')
450
- }
451
- cl = this.$refs["number0"];
452
- po = this.print_point(0, 70);
453
- cl.style.left = po[0] - 10 + "px";
454
- cl.style.top = po[1] - 10 + "px";
455
- cl.classList.add('number-show')
456
- }
457
- },
458
- setup_min() {
459
- const circle = this.$refs.circle;
460
- circle.style.left = "130px";
461
- circle.style.top = "20px";
462
-
463
- const clock = this.$refs.hand;
464
- clock.style.transform = "rotate(0)";
465
- clock.style.height = "100px";
466
-
467
- let cl = null;
468
- let po = null;
469
- for (let i = 0; i <= 59; i++) {
470
- cl = this.$refs["number" + i];
471
- po = this.print_point(i, 110, 60);
472
- cl.style.left = po[0] - 10 + "px";
473
- cl.style.top = po[1] - 10 + "px";
474
- cl.classList.add('number-show')
475
- }
476
- }
477
- }
80
+ export default {
81
+ name: "timepicker",
82
+ props: {
83
+ disableTime: {
84
+ type: Function, default: () => {
85
+ return false
86
+ }
87
+ },
88
+ withSec: Boolean,
89
+ is24Hour: Boolean,
90
+ modelValue: String
91
+ },
92
+ data() {
93
+ return {
94
+ show: this.is24Hour ? "hours24" : "hours12",
95
+ hour: 0,
96
+ meridiem: "AM",
97
+ min: 0,
98
+ sec: 0,
99
+ isSmall: false,
100
+ isHand: false,
101
+ hours12: {
102
+ 1: "1",
103
+ 2: "2",
104
+ 3: "3",
105
+ 4: "4",
106
+ 5: "5",
107
+ 6: "6",
108
+ 7: "7",
109
+ 8: "8",
110
+ 9: "9",
111
+ 10: "10",
112
+ 11: "11",
113
+ 12: "12"
114
+ },
115
+ hours24: {
116
+ 1: "1",
117
+ 2: "2",
118
+ 3: "3",
119
+ 4: "4",
120
+ 5: "5",
121
+ 6: "6",
122
+ 7: "7",
123
+ 8: "8",
124
+ 9: "9",
125
+ 10: "10",
126
+ 11: "11",
127
+ 12: "12",
128
+ 0: "0",
129
+ 13: "13",
130
+ 14: "14",
131
+ 15: "15",
132
+ 16: "16",
133
+ 17: "17",
134
+ 18: "18",
135
+ 19: "19",
136
+ 20: "20",
137
+ 21: "21",
138
+ 22: "22",
139
+ 23: "23"
140
+ },
141
+ mins: {
142
+ 0: "0",
143
+ 1: "",
144
+ 2: "",
145
+ 3: "",
146
+ 4: "",
147
+ 5: "5",
148
+ 6: "",
149
+ 7: "",
150
+ 8: "",
151
+ 9: "",
152
+ 10: "10",
153
+ 11: "",
154
+ 12: "",
155
+ 13: "",
156
+ 14: "",
157
+ 15: "15",
158
+ 16: "",
159
+ 17: "",
160
+ 18: "",
161
+ 19: "",
162
+ 20: "20",
163
+ 21: "",
164
+ 22: "",
165
+ 23: "",
166
+ 24: "",
167
+ 25: "25",
168
+ 26: "",
169
+ 27: "",
170
+ 28: "",
171
+ 29: "",
172
+ 30: "30",
173
+ 31: "",
174
+ 32: "",
175
+ 33: "",
176
+ 34: "",
177
+ 35: "35",
178
+ 36: "",
179
+ 37: "",
180
+ 38: "",
181
+ 39: "",
182
+ 40: "40",
183
+ 41: "",
184
+ 42: "",
185
+ 43: "",
186
+ 44: "",
187
+ 45: "45",
188
+ 46: "",
189
+ 47: "",
190
+ 48: "",
191
+ 49: "",
192
+ 50: "50",
193
+ 51: "",
194
+ 52: "",
195
+ 53: "",
196
+ 54: "",
197
+ 55: "55",
198
+ 56: "",
199
+ 57: "",
200
+ 58: "",
201
+ 59: ""
202
+ },
203
+ seconds: {
204
+ 0: "0",
205
+ 1: "",
206
+ 2: "",
207
+ 3: "",
208
+ 4: "",
209
+ 5: "5",
210
+ 6: "",
211
+ 7: "",
212
+ 8: "",
213
+ 9: "",
214
+ 10: "10",
215
+ 11: "",
216
+ 12: "",
217
+ 13: "",
218
+ 14: "",
219
+ 15: "15",
220
+ 16: "",
221
+ 17: "",
222
+ 18: "",
223
+ 19: "",
224
+ 20: "20",
225
+ 21: "",
226
+ 22: "",
227
+ 23: "",
228
+ 24: "",
229
+ 25: "25",
230
+ 26: "",
231
+ 27: "",
232
+ 28: "",
233
+ 29: "",
234
+ 30: "30",
235
+ 31: "",
236
+ 32: "",
237
+ 33: "",
238
+ 34: "",
239
+ 35: "35",
240
+ 36: "",
241
+ 37: "",
242
+ 38: "",
243
+ 39: "",
244
+ 40: "40",
245
+ 41: "",
246
+ 42: "",
247
+ 43: "",
248
+ 44: "",
249
+ 45: "45",
250
+ 46: "",
251
+ 47: "",
252
+ 48: "",
253
+ 49: "",
254
+ 50: "50",
255
+ 51: "",
256
+ 52: "",
257
+ 53: "",
258
+ 54: "",
259
+ 55: "55",
260
+ 56: "",
261
+ 57: "",
262
+ 58: "",
263
+ 59: ""
264
+ }
478
265
  };
479
- </script>
480
-
481
- <style lang="scss">
482
- @import "../../../style/include";
483
-
484
- .#{$prefix}timepicker-clock {
485
-
486
- --color-timepicker: var(--color-one);
487
-
488
- .text-time {
489
- display: flex;
490
- justify-content: center;
491
- align-content: center;
492
- margin-top: 40px;
493
- width: 260px;
494
- height: 60px;
495
- color: #818181;
496
- font-size: 30px;
497
- }
498
-
499
- .text-time > .time-show {
500
- background-color: #e0e0e0;
501
- width: 60px;
502
- text-align: center;
503
- border-radius: 10px;
504
- padding-top: 10px;
505
- }
506
-
507
- .text-meridiem {
508
- display: flex;
509
- justify-content: space-between;
510
- width: 260px;
511
- height: 40px;
512
- color: #818181;
513
- font-size: 16px;
514
- margin-top: -20px;
515
- padding: 20px;
516
- }
517
-
518
- .meridiem-active {
519
- background-color: var(--color-timepicker);
520
- color: #fff;
521
- }
522
-
523
- .text-meridiem > .time-meridiem {
524
- width: 40px;
525
- height: 40px;
526
- text-align: center;
527
- border-radius: 10px;
528
- padding: 12px 5px 5px 5px;
529
- border: 1px solid #e0e0e0;
530
- }
531
-
532
- .text-time > .t-text {
533
- text-align: center;
534
- padding: 20px 5px 0 5px;
535
- }
536
-
537
- .time-selected {
538
- color: #141414;
539
- }
540
-
541
- .clock {
542
- width: 260px;
543
- height: 260px;
544
- background: #e0e0e0;
545
- border-radius: 50%;
546
- position: relative;
547
- }
548
-
549
- .clock > .number:hover {
550
- cursor: pointer;
551
- }
552
-
553
- .clock > .number {
554
- position: absolute;
555
- width: 20px;
556
- height: 20px;
557
- font-size: 15px;
558
- font-weight: 600;
559
- transform-origin: left top;
560
- text-align: center;
561
- z-index: 20;
562
- white-space: nowrap;
563
- opacity: 0;
266
+ },
267
+ mounted() {
268
+ this.setup_hour();
269
+ this.parser(this.modelValue)
270
+ },
271
+ computed: {
272
+ nums() {
273
+ return this[this.show];
274
+ }
275
+ },
276
+ methods: {
277
+ parser(txt) {
278
+ if (!txt) {
279
+ return
564
280
  }
565
-
566
- .number-show {
567
- opacity: 1 !important;
281
+ txt = txt.split(' ')
282
+ if (txt.length === 2) {
283
+ this.meridiem = txt[1]
284
+ }
285
+ txt = txt[0].split(':')
286
+ this.hour = parseInt(txt[0])
287
+ this.min = parseInt(txt[1])
288
+ this.handle_hour(false)
289
+ },
290
+ emit() {
291
+ let hour = this.hour
292
+ let min = this.min
293
+ let sec = this.sec
294
+ if (hour < 10) {
295
+ hour = '0' + hour;
296
+ }
297
+ if (min < 10) {
298
+ min = '0' + min;
299
+ }
300
+ if (sec < 10) {
301
+ sec = '0' + sec;
302
+ }
303
+ let n = hour + ":" + min;
304
+ if (this.withSec) {
305
+ n += ":" + sec;
306
+ }
307
+ if (!this.is24Hour) {
308
+ n += " " + this.meridiem;
309
+ }
310
+ this.$emit("update:model-value", n);
311
+ if ((min !== null && !this.withSec) || sec !== null) {
312
+ this.$emit("finish", true);
313
+ }
314
+ },
315
+ handle_hour(next = true) {
316
+ if (this.hour > (this.is24Hour ? 23 : 12)) {
317
+ this.hour = this.is24Hour ? 23 : 12;
568
318
  }
569
319
 
570
- .clock > .clock-item-hand {
571
- width: 2px;
572
- height: 110px;
573
- bottom: 130px;
574
- left: 129px;
575
- position: absolute;
576
- z-index: 10;
577
- background-color: var(--color-timepicker);
578
- border: 1px solid var(--color-timepicker);
579
- border-top-left-radius: 10px;
580
- border-top-right-radius: 10px;
581
- transform-origin: bottom;
582
- }
583
-
584
- .clock > .clock-item {
585
- position: absolute;
586
- bottom: 50%;
587
- left: 50%;
588
- background-color: black;
589
- border: 1px solid white;
590
- border-top-left-radius: 10px;
591
- border-top-right-radius: 10px;
592
- transform-origin: bottom;
593
- z-index: 10;
594
- }
595
-
596
- .clock .center {
597
- position: absolute;
598
- background-color: var(--color-timepicker);
599
- z-index: 11;
600
- width: 10px;
601
- height: 10px;
602
- top: 125px;
603
- left: 125px;
604
- border-radius: 50%;
605
- }
606
-
607
- .clock .circle {
608
- position: absolute;
609
- z-index: 11;
610
- width: 35px;
611
- height: 35px;
612
- top: 20px;
613
- left: 130px;
614
- border-radius: 50%;
615
- color: var(--color-timepicker);
616
- background-color: var(--color-timepicker);
617
- border: 2px solid;
618
- transform: translate(-50%, -50%);
619
- }
620
-
621
- .time-active {
622
- color: var(--color-timepicker);
623
- }
320
+ this.show = this.is24Hour ? "hours24" : "hours12";
321
+ setTimeout(() => {
322
+ this.setup_hour();
323
+ this.hour && this.set(this.hour, next);
324
+ }, 10);
325
+ },
326
+ handle_min(next = true) {
327
+ if (this.min > 59) {
328
+ this.min = 59;
329
+ }
330
+ this.show = "mins";
331
+
332
+ setTimeout(() => {
333
+ this.setup_min();
334
+ this.min && this.set(this.min, next);
335
+ }, 10);
336
+ },
337
+ handle_sec(next = true) {
338
+ if (this.sec > 59) {
339
+ this.sec = 59;
340
+ }
341
+ this.show = "seconds";
342
+ setTimeout(() => {
343
+ this.setup_min();
344
+ this.sec && this.set(this.sec, next);
345
+ }, 10);
346
+ },
347
+
348
+ set(h, next = true) {
349
+ h = parseInt(h);
350
+ const circle = this.$refs.circle;
351
+ const cl = this.$refs["number" + h];
352
+ const hand = this.$refs.hand;
353
+ const clock = this.$refs.clock.getBoundingClientRect();
354
+
355
+ const b = cl.getBoundingClientRect();
356
+ circle.style.top = parseInt(cl.style.top) + 10 + "px";
357
+ circle.style.left = parseInt(cl.style.left) + 10 + "px";
358
+
359
+ let ang = this.angle(
360
+ b.left + 10,
361
+ b.top + 10,
362
+ clock.width / 2 + clock.left,
363
+ clock.top,
364
+ clock.width / 2 + clock.left,
365
+ clock.height / 2 + clock.top
366
+ );
367
+ if (
368
+ (this.show === "hours24" || this.show === "hours12") &&
369
+ ((h > 6 && h < 13) || (h > 18 && h <= 23))
370
+ ) {
371
+ ang = 180 + 180 - ang;
372
+ } else if (h > 30) {
373
+ ang = 180 + 180 - ang;
374
+ }
375
+ hand.style.transform = "rotate(" + ang + "deg)";
624
376
 
625
- .clock > .number:hover {
626
- color: white;
627
- }
377
+ if (this.show === "hours24" && (h === 0 || h >= 13)) {
378
+ hand.style.height = "60px";
379
+ } else {
380
+ hand.style.height = "100px";
381
+ }
628
382
 
629
- .time-meridiem:hover {
630
- cursor: pointer;
383
+ if (!next) {
384
+ return
385
+ }
386
+ if (this.show === "hours24") {
387
+ this.show = "mins";
388
+ this.hour = h;
389
+ setTimeout(() => {
390
+ this.setup_min();
391
+ }, 10);
392
+ } else if (this.show === "hours12") {
393
+ this.show = "mins";
394
+ setTimeout(() => {
395
+ this.setup_min();
396
+ }, 10);
397
+ this.hour = h;
398
+ } else if (this.show === "mins") {
399
+ this.min = h;
400
+ if ([0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55].includes(h)) {
401
+ this.isSmall = false;
402
+ this.isHand = false;
403
+ } else {
404
+ this.isSmall = true;
405
+ this.isHand = true;
631
406
  }
632
-
633
- .clock > .clock-item.hour {
634
- width: 4px;
635
- height: 36%;
636
- background-color: var(--color-timepicker);
407
+ if (this.withSec) {
408
+ this.show = "seconds";
409
+ setTimeout(() => {
410
+ this.setup_min();
411
+ }, 10);
637
412
  }
638
-
639
- .is-small {
640
- width: 12px !important;
641
- height: 12px !important;
642
- border-radius: 50% !important;
643
- border: 2px solid;
644
- background-color: unset !important;
645
- transform: translate(-50%, -50%) !important;
413
+ } else {
414
+ this.sec = h;
415
+ }
416
+ this.emit();
417
+ },
418
+ angle(p1x, p1y, p2x, p2y, p3x, p3y) {
419
+ let p0c = Math.sqrt(Math.pow(p3x - p1x, 2) + Math.pow(p3y - p1y, 2));
420
+ let p1c = Math.sqrt(Math.pow(p3x - p2x, 2) + Math.pow(p3y - p2y, 2));
421
+ let p0p1 = Math.sqrt(Math.pow(p2x - p1x, 2) + Math.pow(p2y - p1y, 2));
422
+ return (
423
+ Math.acos((p1c * p1c + p0c * p0c - p0p1 * p0p1) / (2 * p1c * p0c)) *
424
+ (180 / Math.PI)
425
+ );
426
+ },
427
+
428
+ movePointAtAngle(point, angle, distance) {
429
+ return [
430
+ point[0] + Math.sin(angle) * distance,
431
+ point[1] - Math.cos(angle) * distance
432
+ ];
433
+ },
434
+
435
+ print_point(n, lng, nums = 12) {
436
+ return this.movePointAtAngle([130, 130], ((Math.PI * 2) / nums) * n, lng);
437
+ },
438
+ setup_hour() {
439
+ let cl = null;
440
+ let po = null;
441
+ for (let i = 1; i <= 12; i++) {
442
+ cl = this.$refs["number" + i];
443
+ po = this.print_point(i, 110);
444
+ cl.style.left = po[0] - 10 + "px";
445
+ cl.style.top = po[1] - 10 + "px";
446
+ cl.classList.add('number-show')
447
+ }
448
+ if (this.is24Hour) {
449
+ for (let i = 13; i <= 23; i++) {
450
+ cl = this.$refs["number" + i];
451
+ po = this.print_point(i, 70);
452
+ cl.style.left = po[0] - 10 + "px";
453
+ cl.style.top = po[1] - 10 + "px";
454
+ cl.classList.add('number-show')
646
455
  }
647
-
456
+ cl = this.$refs["number0"];
457
+ po = this.print_point(0, 70);
458
+ cl.style.left = po[0] - 10 + "px";
459
+ cl.style.top = po[1] - 10 + "px";
460
+ cl.classList.add('number-show')
461
+ }
462
+ },
463
+ setup_min() {
464
+ const circle = this.$refs.circle;
465
+ circle.style.left = "130px";
466
+ circle.style.top = "20px";
467
+
468
+ const clock = this.$refs.hand;
469
+ clock.style.transform = "rotate(0)";
470
+ clock.style.height = "100px";
471
+
472
+ let cl = null;
473
+ let po = null;
474
+ for (let i = 0; i <= 59; i++) {
475
+ cl = this.$refs["number" + i];
476
+ po = this.print_point(i, 110, 60);
477
+ cl.style.left = po[0] - 10 + "px";
478
+ cl.style.top = po[1] - 10 + "px";
479
+ cl.classList.add('number-show')
480
+ }
648
481
  }
482
+ }
483
+ };
484
+ </script>
485
+
486
+ <style lang="scss">
487
+ @import "../../../style/include";
488
+
489
+ .#{$prefix}timepicker-clock {
490
+
491
+ --color-timepicker: var(--color-one);
492
+
493
+ .text-time {
494
+ display: flex;
495
+ justify-content: center;
496
+ align-content: center;
497
+ margin-top: 40px;
498
+ width: 260px;
499
+ height: 60px;
500
+ color: #818181;
501
+ font-size: 30px;
502
+ }
503
+
504
+ .text-time > .time-show {
505
+ background-color: #e0e0e0;
506
+ width: 60px;
507
+ text-align: center;
508
+ border-radius: 10px;
509
+ padding-top: 10px;
510
+ }
511
+
512
+ .text-meridiem {
513
+ display: flex;
514
+ justify-content: space-between;
515
+ width: 260px;
516
+ height: 40px;
517
+ color: #818181;
518
+ font-size: 16px;
519
+ margin-top: -20px;
520
+ padding: 20px;
521
+ }
522
+
523
+ .meridiem-active {
524
+ background-color: var(--color-timepicker);
525
+ color: #fff;
526
+ }
527
+
528
+ .text-meridiem > .time-meridiem {
529
+ width: 40px;
530
+ height: 40px;
531
+ text-align: center;
532
+ border-radius: 10px;
533
+ padding: 12px 5px 5px 5px;
534
+ border: 1px solid #e0e0e0;
535
+ }
536
+
537
+ .text-time > .t-text {
538
+ text-align: center;
539
+ padding: 20px 5px 0 5px;
540
+ }
541
+
542
+ .time-selected {
543
+ color: #141414;
544
+ }
545
+
546
+ .clock {
547
+ width: 260px;
548
+ height: 260px;
549
+ background: #e0e0e0;
550
+ border-radius: 50%;
551
+ position: relative;
552
+ }
553
+
554
+ .clock > .number:hover {
555
+ cursor: pointer;
556
+ }
557
+
558
+ .clock > .number {
559
+ position: absolute;
560
+ width: 20px;
561
+ height: 20px;
562
+ font-size: 15px;
563
+ font-weight: 600;
564
+ transform-origin: left top;
565
+ text-align: center;
566
+ z-index: 20;
567
+ white-space: nowrap;
568
+ opacity: 0;
569
+ }
570
+
571
+ .number-show {
572
+ opacity: 1 !important;
573
+ }
574
+
575
+ .clock > .clock-item-hand {
576
+ width: 2px;
577
+ height: 110px;
578
+ bottom: 130px;
579
+ left: 129px;
580
+ position: absolute;
581
+ z-index: 10;
582
+ background-color: var(--color-timepicker);
583
+ border: 1px solid var(--color-timepicker);
584
+ border-top-left-radius: 10px;
585
+ border-top-right-radius: 10px;
586
+ transform-origin: bottom;
587
+ }
588
+
589
+ .clock > .clock-item {
590
+ position: absolute;
591
+ bottom: 50%;
592
+ left: 50%;
593
+ background-color: black;
594
+ border: 1px solid white;
595
+ border-top-left-radius: 10px;
596
+ border-top-right-radius: 10px;
597
+ transform-origin: bottom;
598
+ z-index: 10;
599
+ }
600
+
601
+ .clock .center {
602
+ position: absolute;
603
+ background-color: var(--color-timepicker);
604
+ z-index: 11;
605
+ width: 10px;
606
+ height: 10px;
607
+ top: 125px;
608
+ left: 125px;
609
+ border-radius: 50%;
610
+ }
611
+
612
+ .clock .circle {
613
+ position: absolute;
614
+ z-index: 11;
615
+ width: 35px;
616
+ height: 35px;
617
+ top: 20px;
618
+ left: 130px;
619
+ border-radius: 50%;
620
+ color: var(--color-timepicker);
621
+ background-color: var(--color-timepicker);
622
+ border: 2px solid;
623
+ transform: translate(-50%, -50%);
624
+ }
625
+
626
+ .time-active {
627
+ color: var(--color-timepicker);
628
+ }
629
+
630
+ .clock > .number:hover {
631
+ color: white;
632
+ }
633
+
634
+ .time-meridiem:hover {
635
+ cursor: pointer;
636
+ }
637
+
638
+ .clock > .clock-item.hour {
639
+ width: 4px;
640
+ height: 36%;
641
+ background-color: var(--color-timepicker);
642
+ }
643
+
644
+ .is-small {
645
+ width: 12px !important;
646
+ height: 12px !important;
647
+ border-radius: 50% !important;
648
+ border: 2px solid;
649
+ background-color: unset !important;
650
+ transform: translate(-50%, -50%) !important;
651
+ }
652
+
653
+ .number-disabled {
654
+ pointer-events: none;
655
+ color: var(--color-disabled)
656
+ }
657
+ }
649
658
  </style>