@ledvance/base 1.0.28 → 1.0.30
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/package.json +2 -1
- package/src/api/native.ts +21 -5
- package/src/components/DelteButton.tsx +36 -0
- package/src/i18n/strings.d.ts +420 -0
- package/src/i18n/strings.ts +10500 -10080
- package/src/models/TuyaApi.ts +56 -0
- package/src/models/modules/NativePropsSlice.tsx +11 -1
- package/src/models/modules/common.d.ts +13 -21
- package/src/utils/common.d.ts +22 -0
- package/src/utils/common.ts +185 -2
package/src/models/TuyaApi.ts
CHANGED
|
@@ -34,4 +34,60 @@ export async function getDpReportSataData(
|
|
|
34
34
|
sortType: sortType || 'DESC',
|
|
35
35
|
}
|
|
36
36
|
return commonApi.statApi.getDpReportLog(params)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface DpResultByMonthResData {
|
|
40
|
+
years: object;
|
|
41
|
+
thisDay: string;
|
|
42
|
+
sum: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export async function getDpResultByMonth(
|
|
46
|
+
devId: string,
|
|
47
|
+
dpId: string,
|
|
48
|
+
type: "sum" | "minux" | "mac"
|
|
49
|
+
): Promise<DpResultByMonthResData> {
|
|
50
|
+
const params = {
|
|
51
|
+
devId,
|
|
52
|
+
dpId,
|
|
53
|
+
type
|
|
54
|
+
}
|
|
55
|
+
return commonApi.statApi.getDpResultByMonth(params) as any
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface DpResultByDataWithSpecifiedResData {
|
|
59
|
+
result: object;
|
|
60
|
+
min: string;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export async function getDataWithSpecified(
|
|
64
|
+
devId: string,
|
|
65
|
+
dpId: string,
|
|
66
|
+
startDay: string,
|
|
67
|
+
endDay: string,
|
|
68
|
+
type: "sum" | "minux" | "avg"
|
|
69
|
+
): Promise<DpResultByDataWithSpecifiedResData> {
|
|
70
|
+
const params = {
|
|
71
|
+
devId,
|
|
72
|
+
dpId,
|
|
73
|
+
startDay,
|
|
74
|
+
endDay,
|
|
75
|
+
type,
|
|
76
|
+
}
|
|
77
|
+
return commonApi.statApi.getDataWithSpecified(params) as any
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export async function getDpResultByHour(
|
|
81
|
+
devId: string,
|
|
82
|
+
dpId: string,
|
|
83
|
+
date: string,
|
|
84
|
+
type: "sum" | "minux" | "avg"
|
|
85
|
+
): Promise<DpResultByDataWithSpecifiedResData> {
|
|
86
|
+
const params = {
|
|
87
|
+
devId,
|
|
88
|
+
dpId,
|
|
89
|
+
date,
|
|
90
|
+
type
|
|
91
|
+
}
|
|
92
|
+
return commonApi.statApi.getDpResultByHour(params) as any
|
|
37
93
|
}
|
|
@@ -12,6 +12,7 @@ export interface NativeProps {
|
|
|
12
12
|
dps: any,
|
|
13
13
|
familyName: string,
|
|
14
14
|
timeSchedule: symbol;
|
|
15
|
+
energieverbrauch?: object
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
const initialState: NativeProps = {
|
|
@@ -20,6 +21,7 @@ const initialState: NativeProps = {
|
|
|
20
21
|
dps: {},
|
|
21
22
|
familyName: '',
|
|
22
23
|
timeSchedule: Symbol(),
|
|
24
|
+
energieverbrauch: {}
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
const nativePropsSlice = createSlice({
|
|
@@ -45,6 +47,9 @@ const nativePropsSlice = createSlice({
|
|
|
45
47
|
setTimeSchedule(state, action: PayloadAction<any>) {
|
|
46
48
|
state.timeSchedule = action.payload
|
|
47
49
|
},
|
|
50
|
+
setEnergieverbrauch(state, action: PayloadAction<any>) {
|
|
51
|
+
state.energieverbrauch = action.payload
|
|
52
|
+
},
|
|
48
53
|
},
|
|
49
54
|
})
|
|
50
55
|
|
|
@@ -134,9 +139,13 @@ const useTimeSchedule = (): [v:Symbol, f:any] => {
|
|
|
134
139
|
return [dps, setTimeScheduleFn]
|
|
135
140
|
}
|
|
136
141
|
|
|
142
|
+
const useEnergieverbrauch = () => {
|
|
143
|
+
return useSelector(store => store.ldvModules.energieverbrauch)
|
|
144
|
+
}
|
|
145
|
+
|
|
137
146
|
export const ldvModules = nativePropsSlice.reducer
|
|
138
147
|
|
|
139
|
-
export const {setNativeProps, setDps, setTimeSchedule} = nativePropsSlice.actions
|
|
148
|
+
export const {setNativeProps, setDps, setTimeSchedule, setEnergieverbrauch} = nativePropsSlice.actions
|
|
140
149
|
|
|
141
150
|
export {
|
|
142
151
|
simpleSetDps,
|
|
@@ -147,4 +156,5 @@ export {
|
|
|
147
156
|
useDps,
|
|
148
157
|
useFamilyName,
|
|
149
158
|
useTimeSchedule,
|
|
159
|
+
useEnergieverbrauch
|
|
150
160
|
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Observable } from 'rxjs/Observable';
|
|
3
|
-
import { ActionsObservable } from 'redux-observable';
|
|
1
|
+
import { DpValue } from 'tuya-panel-kit';
|
|
4
2
|
import 'rxjs/add/observable/fromPromise';
|
|
5
3
|
import 'rxjs/add/observable/of';
|
|
6
4
|
import 'rxjs/add/observable/merge';
|
|
@@ -18,27 +16,21 @@ export interface Log {
|
|
|
18
16
|
time: string;
|
|
19
17
|
isSend: boolean;
|
|
20
18
|
}
|
|
21
|
-
declare type Logs = Array<Log>;
|
|
22
|
-
declare type UpdateDevInfoPayload = DevInfo;
|
|
23
|
-
declare type UpdateDpStatePayload = Partial<DpState> & {
|
|
24
|
-
[key: string]: DpValue;
|
|
25
|
-
};
|
|
26
19
|
export declare const actions: {
|
|
27
|
-
devInfoChange:
|
|
28
|
-
deviceChange:
|
|
29
|
-
responseUpdateDp:
|
|
30
|
-
updateDp:
|
|
31
|
-
consoleChange:
|
|
32
|
-
clearConsole:
|
|
20
|
+
devInfoChange: any;
|
|
21
|
+
deviceChange: any;
|
|
22
|
+
responseUpdateDp: any;
|
|
23
|
+
updateDp: any;
|
|
24
|
+
consoleChange: any;
|
|
25
|
+
clearConsole: any;
|
|
33
26
|
};
|
|
34
|
-
export
|
|
27
|
+
export type Actions = {
|
|
35
28
|
[K in keyof typeof actions]: ReturnType<typeof actions[K]>;
|
|
36
29
|
};
|
|
37
30
|
export declare const reducers: {
|
|
38
|
-
dpState:
|
|
39
|
-
devInfo:
|
|
40
|
-
logs:
|
|
41
|
-
ldvModules:
|
|
31
|
+
dpState: any;
|
|
32
|
+
devInfo: any;
|
|
33
|
+
logs: any;
|
|
34
|
+
ldvModules: any;
|
|
42
35
|
};
|
|
43
|
-
export declare const epics: ((action$: ActionsObservable<
|
|
44
|
-
export {};
|
|
36
|
+
export declare const epics: ((action$: ActionsObservable<any>) => any)[];
|
package/src/utils/common.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export declare const loopText: (loop: any) => string;
|
|
2
|
+
export declare const loopTommorrowText: (loop: any, isTommorrow: any) => string;
|
|
2
3
|
export declare const toFixed: (str: any, count: any) => string;
|
|
3
4
|
export declare function getArray(arr: any, size: any): string[];
|
|
4
5
|
export declare function getWeek(weekString: any): number[];
|
|
@@ -10,3 +11,24 @@ export declare function getWeek(weekString: any): number[];
|
|
|
10
11
|
*/
|
|
11
12
|
export declare function spliceByStep(str: string, step: number): string[];
|
|
12
13
|
export declare function hex2Int(hex: string): number;
|
|
14
|
+
export declare const localeNumber: (v: number | string, fixed?: number) => string | number;
|
|
15
|
+
export declare const exportFile: (list: any) => void;
|
|
16
|
+
export declare const exportHistoryFile: (list: any) => void;
|
|
17
|
+
export declare const monthFormat: (v: number | string) => string;
|
|
18
|
+
export declare const tagTitle: string[];
|
|
19
|
+
export declare function isTimeSpanValid(timeData: any): number;
|
|
20
|
+
export declare function modifyPopup(beforeValue: object, editValue: object): boolean;
|
|
21
|
+
interface DialogProps {
|
|
22
|
+
method: 'alert' | 'confirm';
|
|
23
|
+
title: string;
|
|
24
|
+
showCancelText?: boolean;
|
|
25
|
+
showConfirmText?: boolean;
|
|
26
|
+
cancelText?: string;
|
|
27
|
+
confirmText?: string;
|
|
28
|
+
subTitle?: string;
|
|
29
|
+
onConfirm: (data: any, args: {
|
|
30
|
+
close: () => void;
|
|
31
|
+
}) => void;
|
|
32
|
+
}
|
|
33
|
+
export declare function showDialog(props: DialogProps): any;
|
|
34
|
+
export {};
|
package/src/utils/common.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
+
import { Platform, NativeModules } from "react-native";
|
|
1
2
|
import I18n from '../i18n/index'
|
|
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";
|
|
2
8
|
|
|
3
9
|
const loopsText = [
|
|
4
10
|
I18n.getLang('timeschedule_add_schedule_weekday7_text'),
|
|
@@ -11,10 +17,22 @@ const loopsText = [
|
|
|
11
17
|
]
|
|
12
18
|
|
|
13
19
|
export const loopText = (loop) => {
|
|
14
|
-
const loopStrArray = loopsText.filter((_item, index) => loop[index] === 1)
|
|
20
|
+
const loopStrArray = loopsText.filter((_item, index) => Number(loop[index]) === 1)
|
|
15
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'))
|
|
16
22
|
}
|
|
17
23
|
|
|
24
|
+
const tommorrow = () => {
|
|
25
|
+
const text = I18n.getLang('feature_summary_frequency_txt_2').split(' ')
|
|
26
|
+
return text?.length > 0 && text[text.length - 1] || ''
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const loopTommorrowText = (loop, isTommorrow) => {
|
|
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
|
+
|
|
18
36
|
export const toFixed = (str, count) => {
|
|
19
37
|
return `${"0".repeat(count)}${str}`.slice(-1 * count);
|
|
20
38
|
};
|
|
@@ -55,4 +73,169 @@ export function spliceByStep(str: string, step: number): string[] {
|
|
|
55
73
|
|
|
56
74
|
export function hex2Int(hex: string): number {
|
|
57
75
|
return parseInt(hex, 16)
|
|
58
|
-
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
let defaultLocale = 'en';
|
|
79
|
+
if (Platform.OS === 'ios') {
|
|
80
|
+
defaultLocale =
|
|
81
|
+
Platform.OS === 'ios'
|
|
82
|
+
? NativeModules.SettingsManager.settings.AppleLocale
|
|
83
|
+
: NativeModules.SettingsManager.settings.AppleLanguages[0];
|
|
84
|
+
} else if (Platform.OS === 'android') {
|
|
85
|
+
defaultLocale = NativeModules.I18nManager.localeIdentifier;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// 德国数字格式化
|
|
89
|
+
export const localeNumber = (v: number | string, fixed?: number) => {
|
|
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]
|
|
98
|
+
}
|
|
99
|
+
return new Intl.NumberFormat(local).format(num)
|
|
100
|
+
} catch (_) {
|
|
101
|
+
return num
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
// 导出文件
|
|
107
|
+
export const exportFile = (list) => {
|
|
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);
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export const exportHistoryFile = (list) => {
|
|
136
|
+
const value = list?.map(item => {
|
|
137
|
+
return item?.actions?.map(val => { return [val?.date, val?.time, val?.action, tagTitle[val?.dpId - 1]] })
|
|
138
|
+
})
|
|
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
|
+
}
|
|
162
|
+
|
|
163
|
+
//月份格式化
|
|
164
|
+
export const monthFormat = (v: number | string) => {
|
|
165
|
+
const monthText = [
|
|
166
|
+
I18n.getLang('consumption_data_field4_month1_value_text'),
|
|
167
|
+
I18n.getLang('consumption_data_field4_month2_value_text'),
|
|
168
|
+
I18n.getLang('consumption_data_field4_month3_value_text'),
|
|
169
|
+
I18n.getLang('consumption_data_field4_month4_value_text'),
|
|
170
|
+
I18n.getLang('consumption_data_field4_month5_value_text'),
|
|
171
|
+
I18n.getLang('consumption_data_field4_month6_value_text'),
|
|
172
|
+
I18n.getLang('consumption_data_field4_month7_value_text'),
|
|
173
|
+
I18n.getLang('consumption_data_field4_month8_value_text'),
|
|
174
|
+
I18n.getLang('consumption_data_field4_month9_value_text'),
|
|
175
|
+
I18n.getLang('consumption_data_field4_month10_value_text'),
|
|
176
|
+
I18n.getLang('consumption_data_field4_month11_value_text'),
|
|
177
|
+
I18n.getLang('consumption_data_field4_month12_value_text'),
|
|
178
|
+
]
|
|
179
|
+
return monthText[Number(v) - 1]
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export const tagTitle = [
|
|
183
|
+
I18n.getLang('feature_summary_action_component_6'),
|
|
184
|
+
I18n.getLang('feature_summary_action_component_7'),
|
|
185
|
+
I18n.getLang('feature_summary_action_component_8'),
|
|
186
|
+
I18n.getLang('feature_summary_action_component_9'),
|
|
187
|
+
]
|
|
188
|
+
|
|
189
|
+
export function isTimeSpanValid(timeData) {
|
|
190
|
+
const startTime = timeData.startTime;
|
|
191
|
+
const endTime = timeData.endTime;
|
|
192
|
+
// 将小时和分钟转换为分钟总数
|
|
193
|
+
const startMinutes = parseInt(startTime[0]) * 60 + parseInt(startTime[1]); const endMinutes = parseInt(endTime[0]) * 60 + parseInt(endTime[1]);
|
|
194
|
+
// 判断是否跨天,如果开始时间大于结束时间,则跨天
|
|
195
|
+
if (startMinutes > endMinutes) {
|
|
196
|
+
// 计算跨天情况下的时间间隔
|
|
197
|
+
const overnightInterval = 1440 - startMinutes + endMinutes;
|
|
198
|
+
return overnightInterval;
|
|
199
|
+
} else {
|
|
200
|
+
// 计算非跨天情况下的时间间隔
|
|
201
|
+
const interval = endMinutes - startMinutes;
|
|
202
|
+
return interval;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export function modifyPopup(beforeValue:object, editValue:object){
|
|
207
|
+
return !isEqual(beforeValue, editValue)
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// dialog
|
|
211
|
+
interface DialogProps {
|
|
212
|
+
method: 'alert' | 'confirm'
|
|
213
|
+
title: string
|
|
214
|
+
showCancelText?: boolean
|
|
215
|
+
showConfirmText?: boolean
|
|
216
|
+
cancelText?: string
|
|
217
|
+
confirmText?: string
|
|
218
|
+
subTitle?: string
|
|
219
|
+
onConfirm: (data: any, args: { close: () => void }) => void
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export function showDialog(props: DialogProps){
|
|
223
|
+
const { method , showCancelText = true, showConfirmText = true, title, cancelText, confirmText, subTitle, onConfirm } = props
|
|
224
|
+
return (
|
|
225
|
+
method === 'confirm' ?
|
|
226
|
+
Dialog.confirm({
|
|
227
|
+
title: title,
|
|
228
|
+
cancelText: showCancelText && (cancelText || I18n.getLang('conflict_dialog_save_item_fixedtimecycle_answer_no_text')) || '',
|
|
229
|
+
confirmText: showConfirmText && (confirmText || I18n.getLang('conflict_dialog_save_item_fixedtimecycle_answer_yes_text')) || '',
|
|
230
|
+
subTitle,
|
|
231
|
+
onConfirm
|
|
232
|
+
})
|
|
233
|
+
:
|
|
234
|
+
Dialog.alert({
|
|
235
|
+
title: title,
|
|
236
|
+
confirmText: showConfirmText && (confirmText || I18n.getLang('conflict_dialog_save_item_fixedtimecycle_answer_yes_text')) || '',
|
|
237
|
+
subTitle,
|
|
238
|
+
onConfirm
|
|
239
|
+
})
|
|
240
|
+
)
|
|
241
|
+
}
|