@ledvance/base 1.1.13 → 1.1.15
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/.prettierrc.js +0 -0
- package/package.json +1 -1
- package/src/api/native.d.ts +5 -0
- package/src/api/native.ts +193 -160
- package/src/api/nativeEventEmitter.ts +54 -54
- package/src/components/Card.tsx +25 -25
- package/src/components/Cell.tsx +32 -32
- package/src/components/ColorAdjustView.tsx +44 -44
- package/src/components/ColorTempAdjustView.tsx +37 -37
- package/src/components/ColorsLine.d.ts +7 -0
- package/src/components/ColorsLine.tsx +48 -0
- package/src/components/DeleteButton.d.ts +1 -1
- package/src/components/DeleteButton.tsx +27 -27
- package/src/components/Dialog.tsx +28 -28
- package/src/components/FanAdjustView.tsx +115 -105
- package/src/components/InfoText.tsx +29 -29
- package/src/components/LampAdjustView.tsx +52 -52
- package/src/components/LinearGradientLine.tsx +53 -53
- package/src/components/MoodColorsLine.d.ts +9 -0
- package/src/components/MoodColorsLine.tsx +38 -0
- package/src/components/Page.tsx +34 -34
- package/src/components/Popup.tsx +17 -17
- package/src/components/Segmented.d.ts +2 -2
- package/src/components/Segmented.tsx +66 -65
- package/src/components/Spacer.tsx +5 -5
- package/src/components/Tag.tsx +42 -42
- package/src/components/TextButton.d.ts +1 -1
- package/src/components/TextButton.tsx +23 -23
- package/src/components/TextField.tsx +58 -58
- package/src/components/connect.tsx +10 -10
- package/src/components/ldvColorBrightness.tsx +12 -12
- package/src/components/ldvColorSlider.tsx +109 -109
- package/src/components/ldvPickerView.tsx +70 -70
- package/src/components/ldvPresetView.tsx +68 -68
- package/src/components/ldvSaturation.tsx +14 -14
- package/src/components/ldvSlider.d.ts +3 -3
- package/src/components/ldvSlider.tsx +93 -93
- package/src/components/ldvSwitch.tsx +35 -35
- package/src/components/ldvTemperatureSlider.tsx +120 -120
- package/src/components/ldvTopBar.tsx +50 -50
- package/src/components/ldvTopName.tsx +44 -44
- package/src/components/segmentControl.tsx +59 -59
- package/src/components/weekSelect.tsx +76 -76
- package/src/composeLayout.tsx +165 -165
- package/src/i18n/index.ts +12 -12
- package/src/i18n/strings.ts +11004 -11004
- package/src/main.tsx +4 -4
- package/src/models/GlobalParams.ts +7 -7
- package/src/models/TuyaApi.d.ts +3 -3
- package/src/models/TuyaApi.ts +61 -61
- package/src/models/combine.ts +7 -7
- package/src/models/configureStore.ts +14 -14
- package/src/models/index.ts +4 -4
- package/src/models/modules/NativePropsSlice.tsx +170 -169
- package/src/models/modules/Result.ts +8 -8
- package/src/models/modules/common.ts +90 -90
- package/src/res/index.ts +35 -35
- package/src/utils/ColorParser.ts +150 -150
- package/src/utils/ColorUtils.tsx +414 -414
- package/src/utils/Support.d.ts +9 -0
- package/src/utils/Support.ts +85 -0
- package/src/utils/cctUtils.d.ts +1 -0
- package/src/utils/cctUtils.ts +111 -0
- package/src/utils/common.ts +186 -174
- package/src/utils/index.ts +123 -123
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const isPlug: (dpCodes: Record<string, string>) => boolean;
|
|
2
|
+
export declare const isGlassRGBWLamp: (dpCodes: Record<string, string>) => boolean;
|
|
3
|
+
export declare const isMixRGBWLamp: (dpCodes: Record<string, string>) => boolean;
|
|
4
|
+
export declare const isRGBWLamp: (dpCodes: Record<string, string>) => boolean;
|
|
5
|
+
export declare const isRGBLamp: (dpCodes: Record<string, string>) => boolean;
|
|
6
|
+
export declare const isOnlyRGBLamp: (dpCodes: Record<string, string>) => boolean;
|
|
7
|
+
export declare const isTWLamp: (dpCodes: Record<string, string>) => boolean;
|
|
8
|
+
export declare const isDIMLamp: (dpCodes: Record<string, string>) => boolean;
|
|
9
|
+
export declare const isGARDOT: (dpCodes: Record<string, string>) => boolean;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// 判断是否是plug
|
|
2
|
+
export const isPlug = (dpCodes: Record<string, string>) => {
|
|
3
|
+
return !!dpCodes.switch_1
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
// 玻璃灯:支持颜色和色温灯同时调节
|
|
7
|
+
export const isGlassRGBWLamp = (dpCodes: Record<string, string>) => {
|
|
8
|
+
return !!(
|
|
9
|
+
!dpCodes.mix_rgbcw &&
|
|
10
|
+
!dpCodes.temp_value &&
|
|
11
|
+
dpCodes.colour_data &&
|
|
12
|
+
dpCodes.bright_value
|
|
13
|
+
)
|
|
14
|
+
}
|
|
15
|
+
// 双灯泡吸顶灯:支持颜色和色温灯同时调节
|
|
16
|
+
export const isMixRGBWLamp = (dpCodes: Record<string, string>) => {
|
|
17
|
+
return !!(
|
|
18
|
+
dpCodes.mix_rgbcw &&
|
|
19
|
+
dpCodes.colour_data &&
|
|
20
|
+
dpCodes.temp_value &&
|
|
21
|
+
dpCodes.bright_value
|
|
22
|
+
)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// 支持调节:颜色/色温+亮度
|
|
26
|
+
export const isRGBWLamp = (dpCodes: Record<string, string>) => {
|
|
27
|
+
return !!(
|
|
28
|
+
!dpCodes.mix_rgbcw &&
|
|
29
|
+
dpCodes.colour_data &&
|
|
30
|
+
dpCodes.temp_value &&
|
|
31
|
+
dpCodes.bright_value
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// 支持调节:颜色/单一色温亮度
|
|
36
|
+
export const isRGBLamp = (dpCodes: Record<string, string>) => {
|
|
37
|
+
return !!(
|
|
38
|
+
!dpCodes.mix_rgbcw &&
|
|
39
|
+
!dpCodes.temp_value &&
|
|
40
|
+
dpCodes.colour_data &&
|
|
41
|
+
dpCodes.bright_value
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// 支持调节:颜色
|
|
46
|
+
export const isOnlyRGBLamp = (dpCodes: Record<string, string>) => {
|
|
47
|
+
return !!(
|
|
48
|
+
!dpCodes.mix_rgbcw &&
|
|
49
|
+
!dpCodes.temp_value &&
|
|
50
|
+
!dpCodes.bright_value &&
|
|
51
|
+
dpCodes.colour_data
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// 支持调节:色温+亮度
|
|
56
|
+
export const isTWLamp = (dpCodes: Record<string, string>) => {
|
|
57
|
+
return !!(
|
|
58
|
+
!dpCodes.mix_rgbcw &&
|
|
59
|
+
!dpCodes.colour_data &&
|
|
60
|
+
dpCodes.temp_value &&
|
|
61
|
+
dpCodes.bright_value
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// 支持调节:单一色温亮度
|
|
66
|
+
export const isDIMLamp = (dpCodes: Record<string, string>) => {
|
|
67
|
+
return !!(
|
|
68
|
+
!dpCodes.mix_rgbcw &&
|
|
69
|
+
!dpCodes.colour_data &&
|
|
70
|
+
!dpCodes.temp_value &&
|
|
71
|
+
dpCodes.bright_value
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// GARDOT灯具
|
|
76
|
+
export const isGARDOT = (dpCodes: Record<string, string>) => {
|
|
77
|
+
return !!(
|
|
78
|
+
dpCodes.switch_led &&
|
|
79
|
+
dpCodes.work_mode &&
|
|
80
|
+
dpCodes.colour_data &&
|
|
81
|
+
dpCodes.scene_data &&
|
|
82
|
+
dpCodes.countdown &&
|
|
83
|
+
dpCodes.control_data
|
|
84
|
+
)
|
|
85
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const cctToColor: (key: string | number, brightness?: string | number | undefined) => any;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
const ccts = {
|
|
2
|
+
'0': 'rgb(254, 172, 91)',
|
|
3
|
+
'1': 'rgb(254, 174, 94)',
|
|
4
|
+
'2': 'rgb(253, 176, 97)',
|
|
5
|
+
'3': 'rgb(253, 178, 101)',
|
|
6
|
+
'4': 'rgb(253, 180, 105)',
|
|
7
|
+
'5': 'rgb(253, 181, 109)',
|
|
8
|
+
'6': 'rgb(252, 183, 112)',
|
|
9
|
+
'7': 'rgb(252, 185, 116)',
|
|
10
|
+
'8': 'rgb(252, 187, 120)',
|
|
11
|
+
'9': 'rgb(252, 189, 123)',
|
|
12
|
+
'10': 'rgb(251, 191, 127)',
|
|
13
|
+
'11': 'rgb(251, 193, 131)',
|
|
14
|
+
'12': 'rgb(251, 194, 134)',
|
|
15
|
+
'13': 'rgb(251, 196, 138)',
|
|
16
|
+
'14': 'rgb(250, 198, 142)',
|
|
17
|
+
'15': 'rgb(250, 200, 146)',
|
|
18
|
+
'16': 'rgb(250, 202, 149)',
|
|
19
|
+
'17': 'rgb(250, 204, 153)',
|
|
20
|
+
'18': 'rgb(249, 206, 157)',
|
|
21
|
+
'19': 'rgb(249, 207, 160)',
|
|
22
|
+
'20': 'rgb(249, 209, 164)',
|
|
23
|
+
'21': 'rgb(249, 211, 167)',
|
|
24
|
+
'22': 'rgb(250, 213, 170)',
|
|
25
|
+
'23': 'rgb(250, 214, 173)',
|
|
26
|
+
'24': 'rgb(250, 216, 176)',
|
|
27
|
+
'25': 'rgb(250, 218, 179)',
|
|
28
|
+
'26': 'rgb(251, 220, 182)',
|
|
29
|
+
'27': 'rgb(251, 221, 185)',
|
|
30
|
+
'28': 'rgb(251, 223, 188)',
|
|
31
|
+
'29': 'rgb(251, 225, 191)',
|
|
32
|
+
'30': 'rgb(252, 227, 194)',
|
|
33
|
+
'31': 'rgb(252, 228, 197)',
|
|
34
|
+
'32': 'rgb(252, 230, 199)',
|
|
35
|
+
'33': 'rgb(252, 232, 203)',
|
|
36
|
+
'34': 'rgb(253, 234, 206)',
|
|
37
|
+
'35': 'rgb(253, 235, 209)',
|
|
38
|
+
'36': 'rgb(253, 237, 211)',
|
|
39
|
+
'37': 'rgb(253, 239, 214)',
|
|
40
|
+
'38': 'rgb(254, 241, 217)',
|
|
41
|
+
'39': 'rgb(254, 242, 220)',
|
|
42
|
+
'40': 'rgb(254, 244, 223)',
|
|
43
|
+
'41': 'rgb(254, 244, 224)',
|
|
44
|
+
'42': 'rgb(254, 245, 225)',
|
|
45
|
+
'43': 'rgb(254, 245, 226)',
|
|
46
|
+
'44': 'rgb(254, 245, 227)',
|
|
47
|
+
'45': 'rgb(253, 246, 228)',
|
|
48
|
+
'46': 'rgb(253, 246, 229)',
|
|
49
|
+
'47': 'rgb(253, 246, 230)',
|
|
50
|
+
'48': 'rgb(253, 246, 231)',
|
|
51
|
+
'49': 'rgb(253, 247, 232)',
|
|
52
|
+
'50': 'rgb(253, 247, 233)',
|
|
53
|
+
'51': 'rgb(253, 247, 234)',
|
|
54
|
+
'52': 'rgb(253, 248, 234)',
|
|
55
|
+
'53': 'rgb(253, 248, 235)',
|
|
56
|
+
'54': 'rgb(253, 248, 236)',
|
|
57
|
+
'55': 'rgb(252, 249, 237)',
|
|
58
|
+
'56': 'rgb(252, 249, 238)',
|
|
59
|
+
'57': 'rgb(252, 249, 239)',
|
|
60
|
+
'58': 'rgb(252, 249, 240)',
|
|
61
|
+
'59': 'rgb(252, 250, 241)',
|
|
62
|
+
'60': 'rgb(252, 250, 242)',
|
|
63
|
+
'61': 'rgb(251, 249, 242)',
|
|
64
|
+
'62': 'rgb(249, 248, 243)',
|
|
65
|
+
'63': 'rgb(248, 248, 243)',
|
|
66
|
+
'64': 'rgb(247, 247, 243)',
|
|
67
|
+
'65': 'rgb(246, 246, 243)',
|
|
68
|
+
'66': 'rgb(244, 245, 244)',
|
|
69
|
+
'67': 'rgb(243, 245, 244)',
|
|
70
|
+
'68': 'rgb(241, 244, 244)',
|
|
71
|
+
'69': 'rgb(240, 243, 245)',
|
|
72
|
+
'70': 'rgb(239, 242, 245)',
|
|
73
|
+
'71': 'rgb(238, 242, 245)',
|
|
74
|
+
'72': 'rgb(236, 241, 246)',
|
|
75
|
+
'73': 'rgb(235, 240, 246)',
|
|
76
|
+
'74': 'rgb(234, 239, 246)',
|
|
77
|
+
'75': 'rgb(232, 239, 247)',
|
|
78
|
+
'76': 'rgb(231, 238, 247)',
|
|
79
|
+
'77': 'rgb(230, 237, 247)',
|
|
80
|
+
'78': 'rgb(228, 236, 247)',
|
|
81
|
+
'79': 'rgb(227, 236, 248)',
|
|
82
|
+
'80': 'rgb(226, 235, 248)',
|
|
83
|
+
'81': 'rgb(224, 234, 248)',
|
|
84
|
+
'82': 'rgb(223, 233, 249)',
|
|
85
|
+
'83': 'rgb(221, 232, 249)',
|
|
86
|
+
'84': 'rgb(219, 231, 249)',
|
|
87
|
+
'85': 'rgb(218, 230, 250)',
|
|
88
|
+
'86': 'rgb(216, 230, 250)',
|
|
89
|
+
'87': 'rgb(215, 229, 250)',
|
|
90
|
+
'88': 'rgb(213, 228, 250)',
|
|
91
|
+
'89': 'rgb(212, 227, 251)',
|
|
92
|
+
'90': 'rgb(210, 226, 251)',
|
|
93
|
+
'91': 'rgb(208, 225, 251)',
|
|
94
|
+
'92': 'rgb(207, 224, 252)',
|
|
95
|
+
'93': 'rgb(205, 223, 252)',
|
|
96
|
+
'94': 'rgb(203, 222, 252)',
|
|
97
|
+
'95': 'rgb(202, 221, 253)',
|
|
98
|
+
'96': 'rgb(200, 221, 253)',
|
|
99
|
+
'97': 'rgb(199, 220, 253)',
|
|
100
|
+
'98': 'rgb(197, 219, 253)',
|
|
101
|
+
'99': 'rgb(196, 218, 254)',
|
|
102
|
+
'100': 'rgb(194, 217, 254)',
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export const cctToColor = (key: string | number, brightness?: string | number) => {
|
|
106
|
+
let color = ccts[String(key)]
|
|
107
|
+
if (color && (brightness || brightness === 0)) {
|
|
108
|
+
color = Number(brightness) === 0 ? 'rgb(0,0,0)' : `rgba(${color.slice(4, -1)}, ${Number(brightness) / 100 < 0.1 ? 0.1 : Number(brightness) / 100})`
|
|
109
|
+
}
|
|
110
|
+
return color
|
|
111
|
+
}
|
package/src/utils/common.ts
CHANGED
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
import { Platform
|
|
1
|
+
import {NativeModules, Platform} from 'react-native'
|
|
2
2
|
import I18n from '../i18n/index'
|
|
3
|
-
import {
|
|
4
|
-
import dayjs from
|
|
5
|
-
import RNFetchBlob from 'rn-fetch-blob'
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
3
|
+
import {formatNumber, openDownloadFile} from 'api/native'
|
|
4
|
+
import dayjs from 'dayjs'
|
|
5
|
+
import RNFetchBlob from 'rn-fetch-blob'
|
|
6
|
+
import {isEqual} from 'lodash'
|
|
7
|
+
import {Dialog} from 'tuya-panel-kit'
|
|
8
8
|
|
|
9
9
|
const loopsText = [
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
I18n.getLang('timeschedule_add_schedule_weekday7_text'),
|
|
11
|
+
I18n.getLang('timeschedule_add_schedule_weekday1_text'),
|
|
12
|
+
I18n.getLang('timeschedule_add_schedule_weekday2_text'),
|
|
13
|
+
I18n.getLang('timeschedule_add_schedule_weekday3_text'),
|
|
14
|
+
I18n.getLang('timeschedule_add_schedule_weekday4_text'),
|
|
15
|
+
I18n.getLang('timeschedule_add_schedule_weekday5_text'),
|
|
16
|
+
I18n.getLang('timeschedule_add_schedule_weekday6_text'),
|
|
17
17
|
]
|
|
18
18
|
|
|
19
19
|
export const loopText = (loop) => {
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
const loopStrArray = loopsText.filter((_item, index) => Number(loop[index]) === 1)
|
|
21
|
+
return loopStrArray.length == 7 ? I18n.getLang('motion_detection_time_schedule_notifications_field_weekdays_text4') : (loopStrArray.join(' ') || I18n.getLang('motion_detection_time_schedule_notifications_field_weekdays_text2'))
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
const tommorrow = () => {
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
const text = I18n.getLang('feature_summary_frequency_txt_2').split(' ')
|
|
26
|
+
return text?.length > 0 && text[text.length - 1] || ''
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
export const loopTommorrowText = (loop, isTommorrow) => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
30
|
+
const loopStrArray = loopsText.filter((_item, index) => loop[index] === 1)
|
|
31
|
+
return loopStrArray.length == 7 ? (I18n.getLang('motion_detection_time_schedule_notifications_field_weekdays_text4') + (isTommorrow && ` ${tommorrow()}` || '')) :
|
|
32
|
+
(loopStrArray.join(' ') && `${I18n.formatValue('timeschedule_add_schedule_text', loopStrArray.join(' '))} ${isTommorrow && `${tommorrow()}` || ''}` ||
|
|
33
|
+
I18n.getLang(isTommorrow && 'feature_summary_frequency_txt_2' || 'motion_detection_time_schedule_notifications_field_weekdays_text2'))
|
|
34
|
+
}
|
|
35
35
|
|
|
36
36
|
export const toFixed = (str, count) => {
|
|
37
|
-
|
|
38
|
-
}
|
|
37
|
+
return `${'0'.repeat(count)}${str}`.slice(-1 * count)
|
|
38
|
+
}
|
|
39
39
|
|
|
40
40
|
export function getArray(arr, size) { // size=5,要分割的长度
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
41
|
+
const arrNum = Math.ceil(arr.length / size) // Math.ceil()向上取整的方法,用来计算拆分后数组的长度
|
|
42
|
+
let index = 0 // 定义初始索引
|
|
43
|
+
let resIndex = 0 // 用来保存每次拆分的长度
|
|
44
|
+
const result: string[] = []
|
|
45
|
+
while (index < arrNum) {
|
|
46
|
+
result[index] = arr.slice(resIndex, size + resIndex)
|
|
47
|
+
resIndex += size
|
|
48
|
+
index++
|
|
49
|
+
}
|
|
50
|
+
return result
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
export function getWeek(weekString) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
const s = parseInt(weekString, 16).toString(2).padStart(8, '0')
|
|
55
|
+
const array = s.split('').map(item => parseInt(item)).reverse()
|
|
56
|
+
array.pop()
|
|
57
|
+
return array
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
/**
|
|
@@ -64,178 +64,190 @@ export function getWeek(weekString) {
|
|
|
64
64
|
* @returns ['','',...]
|
|
65
65
|
*/
|
|
66
66
|
export function spliceByStep(str: string, step: number): string[] {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
67
|
+
let res: string[] = []
|
|
68
|
+
for (let i = 0; i < str.length; i += step) {
|
|
69
|
+
res.push(str.substr(i, step))
|
|
70
|
+
}
|
|
71
|
+
return res
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
export function hex2Int(hex: string): number {
|
|
75
|
-
|
|
75
|
+
return parseInt(hex, 16)
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
let defaultLocale = 'en'
|
|
78
|
+
let defaultLocale = 'en'
|
|
79
79
|
if (Platform.OS === 'ios') {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
80
|
+
defaultLocale =
|
|
81
|
+
Platform.OS === 'ios'
|
|
82
|
+
? NativeModules.SettingsManager.settings.AppleLocale
|
|
83
|
+
: NativeModules.SettingsManager.settings.AppleLanguages[0]
|
|
84
84
|
} else if (Platform.OS === 'android') {
|
|
85
|
-
|
|
85
|
+
defaultLocale = NativeModules.I18nManager.localeIdentifier
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
// 德国数字格式化
|
|
89
89
|
export const localeNumber = (v: number | string, fixed?: number) => {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
return new Intl.NumberFormat(local).format(num)
|
|
100
|
-
} catch (_) {
|
|
101
|
-
return num
|
|
90
|
+
const mFixed = fixed || 2
|
|
91
|
+
const n = isNaN(Number(v)) ? 0 : Number(v)
|
|
92
|
+
const num = Number(n.toFixed(mFixed))
|
|
93
|
+
try {
|
|
94
|
+
if (Platform.OS === 'android') return formatNumber(n, mFixed)
|
|
95
|
+
let local = defaultLocale
|
|
96
|
+
if (defaultLocale !== 'pt_BR' && defaultLocale !== 'pt-BR') {
|
|
97
|
+
local = defaultLocale.split('_')[0]
|
|
102
98
|
}
|
|
99
|
+
return new Intl.NumberFormat(local).format(num)
|
|
100
|
+
} catch (_) {
|
|
101
|
+
return num
|
|
102
|
+
}
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
|
|
106
106
|
// 导出文件
|
|
107
107
|
export const exportFile = (list) => {
|
|
108
|
-
|
|
109
|
-
|
|
108
|
+
const value = list?.map(item => {
|
|
109
|
+
return [item?.key.split(' ')[0], item?.value]
|
|
110
|
+
})
|
|
111
|
+
const data = [
|
|
112
|
+
['Date', `${I18n.getLang('consumption_data_annual_bar_chart_system_back_text')} (kWh)`],
|
|
113
|
+
...value,
|
|
114
|
+
]
|
|
115
|
+
const timestamp = dayjs().format('YYYYMMDDHHmmss')
|
|
116
|
+
|
|
117
|
+
// 将CSV数据转换为CSV格式的字符串
|
|
118
|
+
const csvData = data.map(row => row.join(','))
|
|
119
|
+
|
|
120
|
+
// 创建 CSV 文件内容
|
|
121
|
+
const csvContent = csvData.join('\n')
|
|
122
|
+
|
|
123
|
+
// 定义文件保存路径
|
|
124
|
+
const documentsPath = RNFetchBlob.fs.dirs.DocumentDir
|
|
125
|
+
const filePath = Platform.OS === 'android' ? RNFetchBlob.fs.dirs.DownloadDir + `/energyConsumption${timestamp}.csv` : `${documentsPath}/energyConsumption${timestamp}.csv`
|
|
126
|
+
RNFetchBlob.fs.writeFile(filePath, csvContent, 'utf8')
|
|
127
|
+
.then(() => {
|
|
128
|
+
openDownloadFile(filePath)
|
|
129
|
+
})
|
|
130
|
+
.catch(error => {
|
|
131
|
+
console.error('导出 CSV 文件时出现错误:', error)
|
|
110
132
|
})
|
|
111
|
-
const data = [
|
|
112
|
-
['Date', `${I18n.getLang('consumption_data_annual_bar_chart_system_back_text')} (kWh)`],
|
|
113
|
-
...value
|
|
114
|
-
];
|
|
115
|
-
const timestamp = dayjs().format('YYYYMMDDHHmmss')
|
|
116
|
-
|
|
117
|
-
// 将CSV数据转换为CSV格式的字符串
|
|
118
|
-
const csvData = data.map(row => row.join(','));
|
|
119
|
-
|
|
120
|
-
// 创建 CSV 文件内容
|
|
121
|
-
const csvContent = csvData.join('\n');
|
|
122
|
-
|
|
123
|
-
// 定义文件保存路径
|
|
124
|
-
const documentsPath = RNFetchBlob.fs.dirs.DocumentDir;
|
|
125
|
-
const filePath = Platform.OS === 'android' ? RNFetchBlob.fs.dirs.DownloadDir + `/energyConsumption${timestamp}.csv` : `${documentsPath}/energyConsumption${timestamp}.csv`
|
|
126
|
-
RNFetchBlob.fs.writeFile(filePath, csvContent, 'utf8')
|
|
127
|
-
.then(() => {
|
|
128
|
-
openDownloadFile(filePath)
|
|
129
|
-
})
|
|
130
|
-
.catch(error => {
|
|
131
|
-
console.error('导出 CSV 文件时出现错误:', error);
|
|
132
|
-
});
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
export const exportHistoryFile = (list) => {
|
|
136
|
-
|
|
137
|
-
|
|
136
|
+
const value = list?.map(item => {
|
|
137
|
+
return item?.actions?.map(val => {
|
|
138
|
+
return [val?.date, val?.time, val?.action, tagTitle[val?.dpId - 1]]
|
|
139
|
+
})
|
|
140
|
+
})
|
|
141
|
+
const data = [
|
|
142
|
+
['Date', 'Time', 'Status', 'Jack'],
|
|
143
|
+
...value?.flat(),
|
|
144
|
+
]
|
|
145
|
+
const timestamp = dayjs().format('YYYYMMDDHHmmss')
|
|
146
|
+
|
|
147
|
+
// 将CSV数据转换为CSV格式的字符串
|
|
148
|
+
const csvData = data.map(row => row.join(','))
|
|
149
|
+
|
|
150
|
+
// 创建 CSV 文件内容
|
|
151
|
+
const csvContent = csvData.join('\n')
|
|
152
|
+
|
|
153
|
+
// 定义文件保存路径
|
|
154
|
+
const documentsPath = RNFetchBlob.fs.dirs.DocumentDir
|
|
155
|
+
const filePath = Platform.OS === 'android' ? RNFetchBlob.fs.dirs.DownloadDir + `/history${timestamp}.csv` : `${documentsPath}/history${timestamp}.csv`
|
|
156
|
+
RNFetchBlob.fs.writeFile(filePath, csvContent, 'utf8')
|
|
157
|
+
.then(() => {
|
|
158
|
+
openDownloadFile(filePath)
|
|
159
|
+
})
|
|
160
|
+
.catch(error => {
|
|
161
|
+
console.error('导出 CSV 文件时出现错误:', error)
|
|
138
162
|
})
|
|
139
|
-
const data = [
|
|
140
|
-
['Date', 'Time', 'Status', 'Jack'],
|
|
141
|
-
...value?.flat()
|
|
142
|
-
];
|
|
143
|
-
const timestamp = dayjs().format('YYYYMMDDHHmmss')
|
|
144
|
-
|
|
145
|
-
// 将CSV数据转换为CSV格式的字符串
|
|
146
|
-
const csvData = data.map(row => row.join(','));
|
|
147
|
-
|
|
148
|
-
// 创建 CSV 文件内容
|
|
149
|
-
const csvContent = csvData.join('\n');
|
|
150
|
-
|
|
151
|
-
// 定义文件保存路径
|
|
152
|
-
const documentsPath = RNFetchBlob.fs.dirs.DocumentDir;
|
|
153
|
-
const filePath = Platform.OS === 'android' ? RNFetchBlob.fs.dirs.DownloadDir + `/history${timestamp}.csv` : `${documentsPath}/history${timestamp}.csv`
|
|
154
|
-
RNFetchBlob.fs.writeFile(filePath, csvContent, 'utf8')
|
|
155
|
-
.then(() => {
|
|
156
|
-
openDownloadFile(filePath)
|
|
157
|
-
})
|
|
158
|
-
.catch(error => {
|
|
159
|
-
console.error('导出 CSV 文件时出现错误:', error);
|
|
160
|
-
});
|
|
161
163
|
}
|
|
162
164
|
|
|
163
165
|
//月份格式化
|
|
164
166
|
export const monthFormat = (v: number | string) => {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
167
|
+
const monthText = [
|
|
168
|
+
I18n.getLang('consumption_data_field4_month1_value_text'),
|
|
169
|
+
I18n.getLang('consumption_data_field4_month2_value_text'),
|
|
170
|
+
I18n.getLang('consumption_data_field4_month3_value_text'),
|
|
171
|
+
I18n.getLang('consumption_data_field4_month4_value_text'),
|
|
172
|
+
I18n.getLang('consumption_data_field4_month5_value_text'),
|
|
173
|
+
I18n.getLang('consumption_data_field4_month6_value_text'),
|
|
174
|
+
I18n.getLang('consumption_data_field4_month7_value_text'),
|
|
175
|
+
I18n.getLang('consumption_data_field4_month8_value_text'),
|
|
176
|
+
I18n.getLang('consumption_data_field4_month9_value_text'),
|
|
177
|
+
I18n.getLang('consumption_data_field4_month10_value_text'),
|
|
178
|
+
I18n.getLang('consumption_data_field4_month11_value_text'),
|
|
179
|
+
I18n.getLang('consumption_data_field4_month12_value_text'),
|
|
180
|
+
]
|
|
181
|
+
return monthText[Number(v) - 1]
|
|
180
182
|
}
|
|
181
183
|
|
|
182
184
|
export const tagTitle = [
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
185
|
+
I18n.getLang('feature_summary_action_component_6'),
|
|
186
|
+
I18n.getLang('feature_summary_action_component_7'),
|
|
187
|
+
I18n.getLang('feature_summary_action_component_8'),
|
|
188
|
+
I18n.getLang('feature_summary_action_component_9'),
|
|
187
189
|
]
|
|
188
190
|
|
|
189
191
|
export function isTimeSpanValid(timeData) {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
192
|
+
const startTime = timeData.startTime
|
|
193
|
+
const endTime = timeData.endTime
|
|
194
|
+
// 将小时和分钟转换为分钟总数
|
|
195
|
+
const startMinutes = parseInt(startTime[0]) * 60 + parseInt(startTime[1])
|
|
196
|
+
const endMinutes = parseInt(endTime[0]) * 60 + parseInt(endTime[1])
|
|
197
|
+
// 判断是否跨天,如果开始时间大于结束时间,则跨天
|
|
198
|
+
if (startMinutes > endMinutes) {
|
|
199
|
+
// 计算跨天情况下的时间间隔
|
|
200
|
+
const overnightInterval = 1440 - startMinutes + endMinutes
|
|
201
|
+
return overnightInterval
|
|
202
|
+
} else {
|
|
203
|
+
// 计算非跨天情况下的时间间隔
|
|
204
|
+
const interval = endMinutes - startMinutes
|
|
205
|
+
return interval
|
|
206
|
+
}
|
|
204
207
|
}
|
|
205
208
|
|
|
206
|
-
export function modifyPopup(beforeValue:object, editValue:object){
|
|
207
|
-
|
|
209
|
+
export function modifyPopup(beforeValue: object, editValue: object) {
|
|
210
|
+
return !isEqual(beforeValue, editValue)
|
|
208
211
|
}
|
|
209
212
|
|
|
210
213
|
// dialog
|
|
211
214
|
interface DialogProps {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
export function showDialog(props: DialogProps){
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
215
|
+
method: 'alert' | 'confirm'
|
|
216
|
+
title: string
|
|
217
|
+
showCancelText?: boolean
|
|
218
|
+
showConfirmText?: boolean
|
|
219
|
+
cancelText?: string
|
|
220
|
+
confirmText?: string
|
|
221
|
+
subTitle?: string
|
|
222
|
+
onConfirm: (data: any, args: { close: () => void }) => void
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export function showDialog(props: DialogProps) {
|
|
226
|
+
const {
|
|
227
|
+
method,
|
|
228
|
+
showCancelText = true,
|
|
229
|
+
showConfirmText = true,
|
|
230
|
+
title,
|
|
231
|
+
cancelText,
|
|
232
|
+
confirmText,
|
|
233
|
+
subTitle,
|
|
234
|
+
onConfirm,
|
|
235
|
+
} = props
|
|
236
|
+
return (
|
|
237
|
+
method === 'confirm' ?
|
|
238
|
+
Dialog.confirm({
|
|
239
|
+
title: title,
|
|
240
|
+
cancelText: showCancelText && (cancelText || I18n.getLang('conflict_dialog_save_item_fixedtimecycle_answer_no_text')) || '',
|
|
241
|
+
confirmText: showConfirmText && (confirmText || I18n.getLang('conflict_dialog_save_item_fixedtimecycle_answer_yes_text')) || '',
|
|
242
|
+
subTitle,
|
|
243
|
+
onConfirm,
|
|
244
|
+
})
|
|
245
|
+
:
|
|
246
|
+
Dialog.alert({
|
|
247
|
+
title: title,
|
|
248
|
+
confirmText: showConfirmText && (confirmText || I18n.getLang('conflict_dialog_save_item_fixedtimecycle_answer_yes_text')) || '',
|
|
249
|
+
subTitle,
|
|
250
|
+
onConfirm,
|
|
251
|
+
})
|
|
252
|
+
)
|
|
241
253
|
}
|