@operato/scene-timer 0.0.11
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/@types/global/index.d.ts +1 -0
- package/CHANGELOG.md +12 -0
- package/LICENSE +21 -0
- package/README.md +31 -0
- package/assets/duetimer.png +0 -0
- package/assets/timer.png +0 -0
- package/dist/duetimer.d.ts +35 -0
- package/dist/duetimer.js +113 -0
- package/dist/duetimer.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/libs/format.d.ts +7 -0
- package/dist/libs/format.js +42 -0
- package/dist/libs/format.js.map +1 -0
- package/dist/templates/duetimer.d.ts +22 -0
- package/dist/templates/duetimer.js +24 -0
- package/dist/templates/duetimer.js.map +1 -0
- package/dist/templates/index.d.ts +18 -0
- package/dist/templates/index.js +4 -0
- package/dist/templates/index.js.map +1 -0
- package/dist/templates/timer.d.ts +18 -0
- package/dist/templates/timer.js +20 -0
- package/dist/templates/timer.js.map +1 -0
- package/dist/timer.d.ts +34 -0
- package/dist/timer.js +129 -0
- package/dist/timer.js.map +1 -0
- package/helps/scene/component/duetimer.ko.md +41 -0
- package/helps/scene/component/duetimer.md +40 -0
- package/helps/scene/component/duetimer.zh.md +39 -0
- package/helps/scene/component/timer.ko.md +64 -0
- package/helps/scene/component/timer.md +62 -0
- package/helps/scene/component/timer.zh.md +63 -0
- package/helps/scene/images/rect-button.png +0 -0
- package/helps/scene/images/timer-data-bind.png +0 -0
- package/helps/scene/images/timer-fill-color.png +0 -0
- package/package.json +62 -0
- package/src/duetimer.ts +138 -0
- package/src/index.ts +4 -0
- package/src/libs/format.ts +47 -0
- package/src/templates/duetimer.ts +24 -0
- package/src/templates/index.ts +4 -0
- package/src/templates/timer.ts +20 -0
- package/src/timer.ts +156 -0
- package/things-scene.config.js +5 -0
- package/translations/en.json +11 -0
- package/translations/ko.json +11 -0
- package/translations/ms.json +11 -0
- package/translations/zh.json +11 -0
- package/tsconfig.json +23 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# duetimer
|
|
2
|
+
|
|
3
|
+
세팅된 타임아웃값을 매초 카운트다운하는 컴포넌트이다.
|
|
4
|
+
타임아웃값은 days, hours, minutes, seconds 로 모델링시에 정적으로 설정할 수 있으며,
|
|
5
|
+
동적으로 설정하기 위해서는 실행중에 value 속성에 timeout(seconds)값을 설정하면 된다.
|
|
6
|
+
|
|
7
|
+
카운트다운 과정의 format-run, format-stop 에 의한 결과값이 data 속성에 설정된다.
|
|
8
|
+
|
|
9
|
+
또한, 듀타이머 컴포넌트는 심플한 수평형 프로그레스바의 표현기능을 제공한다.
|
|
10
|
+
fill-color에 설정된 색상이 카운트다운에 따라 표현된다.
|
|
11
|
+
|
|
12
|
+
![fill-color]
|
|
13
|
+
|
|
14
|
+
[fill-color]: ../images/timer-fill-color.png
|
|
15
|
+
|
|
16
|
+
## properties
|
|
17
|
+
|
|
18
|
+
- due
|
|
19
|
+
- timestamp (UTC 기준으로 1970년 1월 1일 0시 0분 0초부터 현재까지 경과된 밀리 초) : 듀 타이머 컴포넌트의 종료시간 타임스탬프 값이다.
|
|
20
|
+
- 듀 타이머 컴포넌트의 value property 이므로, 듀 타이머의 value 속성(due)에 세팅값을 설정할 수 있다.
|
|
21
|
+
- getter: 타이머 종료시간을 가지고 있다.
|
|
22
|
+
- setter: 타이머 종료시간을 설정할 수 있다.
|
|
23
|
+
- format-run
|
|
24
|
+
- string
|
|
25
|
+
- format : hh:mm:ss
|
|
26
|
+
- 카운트다운 결과 표현형식
|
|
27
|
+
- format-stop
|
|
28
|
+
- string
|
|
29
|
+
- format : --:--:--
|
|
30
|
+
- 카운트다운이 종료되었을 때 표현형식
|
|
31
|
+
- background color
|
|
32
|
+
- string, rgb color
|
|
33
|
+
- 컴포넌트의 배경 색상
|
|
34
|
+
|
|
35
|
+
## hidden properties
|
|
36
|
+
|
|
37
|
+
- countdown
|
|
38
|
+
|
|
39
|
+
- readonly
|
|
40
|
+
- number (seconds)
|
|
41
|
+
- 타이머 설정값 세팅 시점부터 카운트다운된 현재 값을 가지고 있다.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# duetimer
|
|
2
|
+
|
|
3
|
+
this component that counts down the set timeout value every second.
|
|
4
|
+
|
|
5
|
+
- To set statically, you can set during modeling, options in days, hours, minutes, and seconds.
|
|
6
|
+
- To set it dynamically, set the timeout(seconds) value in the value property during execution.
|
|
7
|
+
- The result value by format-run and format-stop of the countdown process is set in the data property.
|
|
8
|
+
- In addition, the timer component provides a simple horizontal progress bar expression function, you can set fill style on color setting.
|
|
9
|
+
|
|
10
|
+
![fill-color]
|
|
11
|
+
|
|
12
|
+
[fill-color]: ../images/timer-fill-color.png
|
|
13
|
+
|
|
14
|
+
## properties
|
|
15
|
+
|
|
16
|
+
- due
|
|
17
|
+
|
|
18
|
+
- timestamp (the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC.) : due time
|
|
19
|
+
- this is value property for duetimer, you need to set value (timeout due) to this property
|
|
20
|
+
- getter: hold due time of the timer
|
|
21
|
+
- setter: settable due time of the timer
|
|
22
|
+
|
|
23
|
+
- format-run
|
|
24
|
+
- string
|
|
25
|
+
- format : hh:mm:ss
|
|
26
|
+
- count down running format
|
|
27
|
+
- format-stop
|
|
28
|
+
- string
|
|
29
|
+
- format : --:--:--
|
|
30
|
+
- count down format on stop
|
|
31
|
+
- background color
|
|
32
|
+
- string, rgb color
|
|
33
|
+
- component background color
|
|
34
|
+
|
|
35
|
+
## hidden properties
|
|
36
|
+
|
|
37
|
+
- countdown
|
|
38
|
+
- readonly
|
|
39
|
+
- number (seconds)
|
|
40
|
+
- when timer set, count down will start automatically
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# DUE 计时器
|
|
2
|
+
|
|
3
|
+
它是每秒对设置的时间值进行递减计数的组件。
|
|
4
|
+
|
|
5
|
+
- 静态 : 可以在建模时以天,小时,分钟和秒为单位静态设置时间值。
|
|
6
|
+
- 动态 : 在运行时在 value 属性中设置时间(seconds)值。
|
|
7
|
+
- 在数据属性中设置倒计时过程的,按格式运行和按格式停止的结果值。
|
|
8
|
+
- 时间格式, 停止格式在运行和结束时以对应的格式设置为data
|
|
9
|
+
- 另外,计时器组件提供了简单的水平进度条功能。填充《填充颜色》中设置的颜色将会表示对应时间的进度条。
|
|
10
|
+
|
|
11
|
+
![fill-color]
|
|
12
|
+
|
|
13
|
+
[fill-color]: ../images/timer-fill-color.png
|
|
14
|
+
|
|
15
|
+
## 属性
|
|
16
|
+
|
|
17
|
+
- due (截止时间)
|
|
18
|
+
- timestamp (以UTC时间为准从1970-01-01 0点0分0秒开始到现在为止的毫秒) : 是DUE计时器组件的结束时间的时间戳
|
|
19
|
+
- 因为是计时器的 value 属性, 可以把数据传递到 value 属性(due)中设置数据值
|
|
20
|
+
|
|
21
|
+
- 时间格式,
|
|
22
|
+
- string
|
|
23
|
+
- format : hh:mm:ss
|
|
24
|
+
- 计时结果表现格式
|
|
25
|
+
- 停止格式
|
|
26
|
+
- string
|
|
27
|
+
- format : --:--:--
|
|
28
|
+
- 计时结束后显示的时间格式
|
|
29
|
+
- 背景颜色
|
|
30
|
+
- string, rgb color
|
|
31
|
+
- 组件背景颜色
|
|
32
|
+
|
|
33
|
+
## 隐藏属性
|
|
34
|
+
|
|
35
|
+
- countdown
|
|
36
|
+
|
|
37
|
+
- readonly
|
|
38
|
+
- number (seconds)
|
|
39
|
+
- 从设置定时器设置值开始,它就将当前值递减计数。
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# timer
|
|
2
|
+
|
|
3
|
+
세팅된 타임아웃값을 매초 카운트다운하는 컴포넌트이다.
|
|
4
|
+
타임아웃값은 days, hours, minutes, seconds 로 모델링시에 정적으로 설정할 수 있으며,
|
|
5
|
+
동적으로 설정하기 위해서는 실행중에 value 속성에 timeout(seconds)값을 설정하면 된다.
|
|
6
|
+
|
|
7
|
+
카운트다운 과정의 format-run, format-stop 에 의한 결과값이 data 속성에 설정된다.
|
|
8
|
+
|
|
9
|
+
또한, 타이머 컴포넌트는 심플한 수평형 프로그레스바의 표현기능을 제공한다.
|
|
10
|
+
fill-color에 설정된 색상이 카운트다운에 따라 표현된다.
|
|
11
|
+
|
|
12
|
+
![fill-color]
|
|
13
|
+
|
|
14
|
+
[fill-color]: ../images/timer-fill-color.png
|
|
15
|
+
|
|
16
|
+
## properties
|
|
17
|
+
|
|
18
|
+
- days
|
|
19
|
+
- number
|
|
20
|
+
- 타임아웃 날자 설정값(0- )
|
|
21
|
+
- hours
|
|
22
|
+
- number
|
|
23
|
+
- 타임아웃 시간 설정값(0-23)
|
|
24
|
+
- minutes
|
|
25
|
+
- number
|
|
26
|
+
- 타임아웃 분 설정값(0-59)
|
|
27
|
+
- seconds
|
|
28
|
+
- number
|
|
29
|
+
- 타임아웃 초 설정값(0-59)
|
|
30
|
+
- format-run
|
|
31
|
+
- string
|
|
32
|
+
- format : hh:mm:ss
|
|
33
|
+
- 카운트다운 결과 표현형식
|
|
34
|
+
- format-stop
|
|
35
|
+
- string
|
|
36
|
+
- format : --:--:--
|
|
37
|
+
- 카운트다운이 종료되었을 때 표현형식
|
|
38
|
+
- background color
|
|
39
|
+
- string, rgb color
|
|
40
|
+
- 컴포넌트의 배경 색상
|
|
41
|
+
|
|
42
|
+
## hidden properties
|
|
43
|
+
|
|
44
|
+
- timeout
|
|
45
|
+
|
|
46
|
+
- number (seconds)
|
|
47
|
+
- 타이머의 (초단위) 세팅 값이다.
|
|
48
|
+
- 타이머 컴포넌트의 value property 이므로, 타이머의 value 속성에 세팅값을 설정할 수 있다.
|
|
49
|
+
|
|
50
|
+
> ex) tap event에서 "set value to target component"옵션 사용, 아래 셈플은 class를 통한 데이터 전달 사용
|
|
51
|
+
|
|
52
|
+
![button]
|
|
53
|
+
|
|
54
|
+
> ex) 데이터 공유 옵션에서 timer의 value로 데이터 전달, 아래 셈플에서는 key를 사용한 데이터 전달 사용
|
|
55
|
+
|
|
56
|
+
![databind]
|
|
57
|
+
|
|
58
|
+
[button]: ../images/rect-button.png
|
|
59
|
+
[databind]: ../images/timer-data-bind.png
|
|
60
|
+
|
|
61
|
+
- countdown
|
|
62
|
+
- readonly
|
|
63
|
+
- number (seconds)
|
|
64
|
+
- 타이머 설정값 세팅 시점부터 카운트다운된 현재 값을 가지고 있다.
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# timer
|
|
2
|
+
|
|
3
|
+
this component that counts down the set timeout value every second.
|
|
4
|
+
|
|
5
|
+
- To set statically, you can set during modeling, options in days, hours, minutes, and seconds.
|
|
6
|
+
- To set it dynamically, set the timeout(seconds) value in the value property during execution.
|
|
7
|
+
- The result value by format-run and format-stop of the countdown process is set in the data property.
|
|
8
|
+
- In addition, the timer component provides a simple horizontal progress bar expression function, you can set fill style on color setting.
|
|
9
|
+
|
|
10
|
+
![fill-color]
|
|
11
|
+
|
|
12
|
+
[fill-color]: ../images/timer-fill-color.png
|
|
13
|
+
|
|
14
|
+
## properties
|
|
15
|
+
|
|
16
|
+
- days
|
|
17
|
+
- number
|
|
18
|
+
- timeout days(0- )
|
|
19
|
+
- hours
|
|
20
|
+
- number
|
|
21
|
+
- timeout hours(0-23)
|
|
22
|
+
- minutes
|
|
23
|
+
- number
|
|
24
|
+
- timeout minutes(0-59)
|
|
25
|
+
- seconds
|
|
26
|
+
- number
|
|
27
|
+
- timeout seconds(0-59)
|
|
28
|
+
- format-run
|
|
29
|
+
- string
|
|
30
|
+
- format : hh:mm:ss
|
|
31
|
+
- count down running format
|
|
32
|
+
- format-stop
|
|
33
|
+
- string
|
|
34
|
+
- format : --:--:--
|
|
35
|
+
- count down format on stop
|
|
36
|
+
- background color
|
|
37
|
+
- string, rgb color
|
|
38
|
+
- component background color
|
|
39
|
+
|
|
40
|
+
## hidden properties
|
|
41
|
+
|
|
42
|
+
- timeout
|
|
43
|
+
|
|
44
|
+
- number (seconds)
|
|
45
|
+
- This is the value of the timer (in seconds).
|
|
46
|
+
- This is value property, you need to set timeout value to this property
|
|
47
|
+
|
|
48
|
+
> ex) on tap event use "set value to target component" option. blowing sample set target with class
|
|
49
|
+
|
|
50
|
+
![button]
|
|
51
|
+
|
|
52
|
+
> ex) on data spread share data to timer's value, blowing sample set target value with key
|
|
53
|
+
|
|
54
|
+
![databind]
|
|
55
|
+
|
|
56
|
+
[button]: ../images/rect-button.png
|
|
57
|
+
[databind]: ../images/timer-data-bind.png
|
|
58
|
+
|
|
59
|
+
- countdown
|
|
60
|
+
- readonly
|
|
61
|
+
- number (seconds)
|
|
62
|
+
- when timer set, count down will start automatically
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# 计时器
|
|
2
|
+
|
|
3
|
+
它是每秒对设置的时间值进行递减计数的组件。
|
|
4
|
+
|
|
5
|
+
- 静态 : 可以在建模时以天,小时,分钟和秒为单位静态设置时间值。
|
|
6
|
+
- 动态 : 在运行时在 value 属性中设置时间(seconds)值。
|
|
7
|
+
- 在数据属性中设置倒计时过程的按格式运行和按格式停止的结果值。
|
|
8
|
+
- 时间格式, 停止格式在运行和结束时以对应的格式设置为 data
|
|
9
|
+
- 另外,计时器组件提供了简单的水平进度条功能。填充填充颜色中设置的颜色将会表示对应时间的进度条。
|
|
10
|
+
|
|
11
|
+
![fill-color]
|
|
12
|
+
|
|
13
|
+
[fill-color]: ../images/timer-fill-color.png
|
|
14
|
+
|
|
15
|
+
## 属性
|
|
16
|
+
|
|
17
|
+
- 天
|
|
18
|
+
- number
|
|
19
|
+
- 计时日期配置(0- )
|
|
20
|
+
- 时间
|
|
21
|
+
- number
|
|
22
|
+
- 计时时间配置(0-23)
|
|
23
|
+
- 分
|
|
24
|
+
- number
|
|
25
|
+
- 计时分配置(0-59)
|
|
26
|
+
- 秒
|
|
27
|
+
- number
|
|
28
|
+
- 计时秒配置(0-59)
|
|
29
|
+
- 时间格式
|
|
30
|
+
- string
|
|
31
|
+
- format : hh:mm:ss
|
|
32
|
+
- 计时结果表现格式
|
|
33
|
+
- 停止格式
|
|
34
|
+
- string
|
|
35
|
+
- format : --:--:--
|
|
36
|
+
- 计时结束后显示的时间格式
|
|
37
|
+
- 背景颜色
|
|
38
|
+
- string, rgb color
|
|
39
|
+
- 组件背景颜色
|
|
40
|
+
|
|
41
|
+
## 隐藏属性
|
|
42
|
+
|
|
43
|
+
- timeout
|
|
44
|
+
|
|
45
|
+
- number (seconds)
|
|
46
|
+
- 计时器的 value 属性(秒).
|
|
47
|
+
- 因为是计时器的 value 属性, 可以把数据传递到 value 属性中
|
|
48
|
+
|
|
49
|
+
> ex) 在点击事件中选择"set value to target component", 使用 class 传递数据
|
|
50
|
+
|
|
51
|
+
![button]
|
|
52
|
+
|
|
53
|
+
> ex) 在数据源的数据共享属性中将数据传递到计时器的 value 中, 使用(key)传递数据
|
|
54
|
+
|
|
55
|
+
![databind]
|
|
56
|
+
|
|
57
|
+
[button]: ../images/rect-button.png
|
|
58
|
+
[databind]: ../images/timer-data-bind.png
|
|
59
|
+
|
|
60
|
+
- countdown
|
|
61
|
+
- readonly: 只读属性
|
|
62
|
+
- number (seconds)
|
|
63
|
+
- 从设置定时器设置值开始,它就将当前值递减计数。
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@operato/scene-timer",
|
|
3
|
+
"description": "Timer component for things-scene",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"author": "heartyoh",
|
|
6
|
+
"version": "0.0.11",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"module": "dist/index.js",
|
|
9
|
+
"things-scene": true,
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public",
|
|
12
|
+
"@oprato:registry": "https://registry.npmjs.org"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/things-scene/operato-scene.git",
|
|
17
|
+
"directory": "packages/timer"
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"serve": "tsc && things-factory-dev",
|
|
21
|
+
"start": "tsc && concurrently -k -r \"tsc --watch --preserveWatchOutput\" \"wds\"",
|
|
22
|
+
"build": "tsc",
|
|
23
|
+
"prepublish": "tsc",
|
|
24
|
+
"lint": "eslint --ext .ts,.html . --ignore-path .gitignore && prettier \"**/*.ts\" --check --ignore-path .gitignore",
|
|
25
|
+
"format": "eslint --ext .ts,.html . --fix --ignore-path .gitignore && prettier \"**/*.ts\" --write --ignore-path .gitignore",
|
|
26
|
+
"migration": "things-factory-migration"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@hatiolab/things-scene": "^2.7.23"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@hatiolab/prettier-config": "^1.0.0",
|
|
33
|
+
"@hatiolab/things-scene": "^2.7.23",
|
|
34
|
+
"@operato/board": "^0.2.35",
|
|
35
|
+
"@things-factory/builder": "^4.0.10",
|
|
36
|
+
"@things-factory/operato-board": "^4.0.10",
|
|
37
|
+
"@typescript-eslint/eslint-plugin": "^4.33.0",
|
|
38
|
+
"@typescript-eslint/parser": "^4.33.0",
|
|
39
|
+
"@web/dev-server": "^0.1.28",
|
|
40
|
+
"concurrently": "^5.3.0",
|
|
41
|
+
"eslint": "^7.32.0",
|
|
42
|
+
"eslint-config-prettier": "^8.3.0",
|
|
43
|
+
"husky": "^4.3.8",
|
|
44
|
+
"lint-staged": "^10.5.4",
|
|
45
|
+
"prettier": "^2.4.1",
|
|
46
|
+
"tslib": "^2.3.1",
|
|
47
|
+
"typescript": "^4.5.2"
|
|
48
|
+
},
|
|
49
|
+
"prettier": "@hatiolab/prettier-config",
|
|
50
|
+
"husky": {
|
|
51
|
+
"hooks": {
|
|
52
|
+
"pre-commit": "lint-staged"
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"lint-staged": {
|
|
56
|
+
"*.ts": [
|
|
57
|
+
"eslint --fix",
|
|
58
|
+
"prettier --write"
|
|
59
|
+
]
|
|
60
|
+
},
|
|
61
|
+
"gitHead": "1421380ee3530169c280b01a21c81af8d1b9f9c4"
|
|
62
|
+
}
|
package/src/duetimer.ts
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { Component, Properties, RectPath, Shape, error } from '@hatiolab/things-scene'
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright © HatioLab Inc. All rights reserved.
|
|
5
|
+
*/
|
|
6
|
+
import format from './libs/format'
|
|
7
|
+
|
|
8
|
+
const NATURE = {
|
|
9
|
+
mutable: false,
|
|
10
|
+
resizable: true,
|
|
11
|
+
rotatable: true,
|
|
12
|
+
properties: [
|
|
13
|
+
{
|
|
14
|
+
type: 'number',
|
|
15
|
+
label: 'due',
|
|
16
|
+
name: 'due',
|
|
17
|
+
placeholder: 'timestamp'
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
type: 'string',
|
|
21
|
+
label: 'format-run',
|
|
22
|
+
name: 'format-run',
|
|
23
|
+
placeholder: 'hh:mm:ss'
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
type: 'string',
|
|
27
|
+
label: 'format-stop',
|
|
28
|
+
name: 'format-stop',
|
|
29
|
+
placeholder: '--:--:--'
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
type: 'color',
|
|
33
|
+
label: 'background-color',
|
|
34
|
+
name: 'backgroundColor',
|
|
35
|
+
property: 'backgroundColor'
|
|
36
|
+
}
|
|
37
|
+
],
|
|
38
|
+
'value-property': 'due',
|
|
39
|
+
help: 'scene/component/duetimer'
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export default class DueTimer extends RectPath(Shape) {
|
|
43
|
+
static get nature() {
|
|
44
|
+
return NATURE
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
ready() {
|
|
48
|
+
if (!this.app.isViewMode) {
|
|
49
|
+
return
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
var { due = 0 } = this.state
|
|
53
|
+
|
|
54
|
+
this.timeout = Math.max(Math.round((due - Date.now()) / 1000), 0)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
onchange(after: Properties) {
|
|
58
|
+
if ('due' in after) {
|
|
59
|
+
this.timeout = Math.max(Math.round((this.due - Date.now()) / 1000), 0)
|
|
60
|
+
this.counting()
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
counting() {
|
|
65
|
+
requestAnimationFrame(() => {
|
|
66
|
+
const countdown = this.countdown
|
|
67
|
+
|
|
68
|
+
if (countdown > 0) {
|
|
69
|
+
this.set('data', format(countdown, this.getState('format-run')))
|
|
70
|
+
|
|
71
|
+
setTimeout(() => {
|
|
72
|
+
this.counting()
|
|
73
|
+
}, 1000)
|
|
74
|
+
} else {
|
|
75
|
+
this.set('data', this.getState('format-stop'))
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
render(context: CanvasRenderingContext2D) {
|
|
81
|
+
var { top, left, height, width, backgroundColor = 'transparent' } = this.model
|
|
82
|
+
|
|
83
|
+
// background의 색상
|
|
84
|
+
context.beginPath()
|
|
85
|
+
context.rect(left, top, width, height)
|
|
86
|
+
|
|
87
|
+
context.fillStyle = backgroundColor
|
|
88
|
+
context.fill()
|
|
89
|
+
|
|
90
|
+
// value의 색상
|
|
91
|
+
context.beginPath()
|
|
92
|
+
|
|
93
|
+
var progress = (this.countdown / this.timeout) * 100
|
|
94
|
+
|
|
95
|
+
if (!isNaN(progress)) {
|
|
96
|
+
progress = width - (width * progress) / 100
|
|
97
|
+
progress = Math.max(Math.min(progress, width), 0)
|
|
98
|
+
|
|
99
|
+
context.rect(left, top, progress, height)
|
|
100
|
+
this.drawFill(context)
|
|
101
|
+
|
|
102
|
+
context.beginPath()
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// stroke
|
|
106
|
+
context.rect(left, top, width, height)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
postrender(context: CanvasRenderingContext2D) {
|
|
110
|
+
this.drawStroke(context)
|
|
111
|
+
this.drawText(context)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
get timeout() {
|
|
115
|
+
return Number(this.getState('timeout') || 0)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
set timeout(timeout) {
|
|
119
|
+
this.setState('timeout', Number(timeout) || 0)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
get due() {
|
|
123
|
+
return Number(this.getState('due') || 0)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
set due(due) {
|
|
127
|
+
this.setState('due', due)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
get countdown() {
|
|
131
|
+
const due = this.due
|
|
132
|
+
const now = Date.now()
|
|
133
|
+
|
|
134
|
+
return Math.max(Math.round((due - now) / 1000), 0)
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
Component.register('duetimer', DueTimer)
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 문자열 길이를 늘려주는 함수
|
|
3
|
+
*
|
|
4
|
+
* @param {String} i
|
|
5
|
+
* @param {Number} len
|
|
6
|
+
*/
|
|
7
|
+
function ii(i: number, len?: number) {
|
|
8
|
+
var s = i + ''
|
|
9
|
+
len = len || 2
|
|
10
|
+
while (s.length < len) s = '0' + s
|
|
11
|
+
return s
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 시간 표시 포맷을 맞추는 함수
|
|
16
|
+
*
|
|
17
|
+
* @param {Number} seconds seconds
|
|
18
|
+
* @param {string} format hh:mm:ss
|
|
19
|
+
*/
|
|
20
|
+
export default function format(seconds = 0, format = '') {
|
|
21
|
+
var h = 0,
|
|
22
|
+
m = 0,
|
|
23
|
+
s = 0
|
|
24
|
+
var formated = ''
|
|
25
|
+
|
|
26
|
+
h = Math.floor(seconds / 3600)
|
|
27
|
+
formated = format.replace(/(^|[^\\])hh+/g, '$1' + ii(h))
|
|
28
|
+
formated = formated.replace(/(^|[^\\])h/g, '$1' + h)
|
|
29
|
+
if (format != formated) {
|
|
30
|
+
format = formated
|
|
31
|
+
seconds %= 1440
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
m = Math.floor(seconds / 60)
|
|
35
|
+
formated = format.replace(/(^|[^\\])mm+/g, '$1' + ii(m))
|
|
36
|
+
formated = formated.replace(/(^|[^\\])m/g, '$1' + m)
|
|
37
|
+
if (format != formated) {
|
|
38
|
+
format = formated
|
|
39
|
+
seconds %= 60
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
s = seconds
|
|
43
|
+
formated = format.replace(/(^|[^\\])ss+/g, '$1' + ii(s))
|
|
44
|
+
formated = formated.replace(/(^|[^\\])s/g, '$1' + s)
|
|
45
|
+
|
|
46
|
+
return formated
|
|
47
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import icon from '../../assets/timer.png'
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
type: 'timer',
|
|
5
|
+
description: 'timer',
|
|
6
|
+
group: 'etc',
|
|
7
|
+
/* line|shape|textAndMedia|chartAndGauge|table|container|dataSource|IoT|3D|warehouse|form|etc */
|
|
8
|
+
icon,
|
|
9
|
+
model: {
|
|
10
|
+
type: 'timer',
|
|
11
|
+
left: 10,
|
|
12
|
+
top: 10,
|
|
13
|
+
width: 100,
|
|
14
|
+
height: 100,
|
|
15
|
+
strokeStyle: 'darkgray',
|
|
16
|
+
text: '#{data}',
|
|
17
|
+
days: 0,
|
|
18
|
+
hours: 0,
|
|
19
|
+
minutes: 0,
|
|
20
|
+
seconds: 0,
|
|
21
|
+
'format-run': 'mm:ss',
|
|
22
|
+
'format-stop': '--:--'
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import icon from '../../assets/duetimer.png'
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
type: 'duetimer',
|
|
5
|
+
description: 'duetimer',
|
|
6
|
+
group: 'etc',
|
|
7
|
+
/* line|shape|textAndMedia|chartAndGauge|table|container|dataSource|IoT|3D|warehouse|form|etc */
|
|
8
|
+
icon,
|
|
9
|
+
model: {
|
|
10
|
+
type: 'duetimer',
|
|
11
|
+
left: 10,
|
|
12
|
+
top: 10,
|
|
13
|
+
width: 100,
|
|
14
|
+
height: 100,
|
|
15
|
+
strokeStyle: 'darkgray',
|
|
16
|
+
text: '#{data}',
|
|
17
|
+
'format-run': 'mm:ss',
|
|
18
|
+
'format-stop': '--:--'
|
|
19
|
+
}
|
|
20
|
+
}
|