@ledvance/base 1.0.28 → 1.0.29

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.
@@ -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,4 +1,9 @@
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"
2
7
 
3
8
  const loopsText = [
4
9
  I18n.getLang('timeschedule_add_schedule_weekday7_text'),
@@ -11,10 +16,22 @@ const loopsText = [
11
16
  ]
12
17
 
13
18
  export const loopText = (loop) => {
14
- const loopStrArray = loopsText.filter((_item, index) => loop[index] === 1)
19
+ const loopStrArray = loopsText.filter((_item, index) => Number(loop[index]) === 1)
15
20
  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
21
  }
17
22
 
23
+ const tommorrow = () => {
24
+ const text = I18n.getLang('feature_summary_frequency_txt_2').split(' ')
25
+ return text?.length > 0 && text[text.length - 1] || ''
26
+ }
27
+
28
+ export const loopTommorrowText = (loop, isTommorrow) => {
29
+ const loopStrArray = loopsText.filter((_item, index) => loop[index] === 1);
30
+ return loopStrArray.length == 7 ? (I18n.getLang('motion_detection_time_schedule_notifications_field_weekdays_text4') + (isTommorrow && ` ${tommorrow()}` || '')) :
31
+ (loopStrArray.join(" ") && `${I18n.formatValue('timeschedule_add_schedule_text', loopStrArray.join(" "))} ${isTommorrow && `${tommorrow()}` || ''}` ||
32
+ I18n.getLang(isTommorrow && 'feature_summary_frequency_txt_2' || 'motion_detection_time_schedule_notifications_field_weekdays_text2'));
33
+ };
34
+
18
35
  export const toFixed = (str, count) => {
19
36
  return `${"0".repeat(count)}${str}`.slice(-1 * count);
20
37
  };
@@ -55,4 +72,137 @@ export function spliceByStep(str: string, step: number): string[] {
55
72
 
56
73
  export function hex2Int(hex: string): number {
57
74
  return parseInt(hex, 16)
58
- }
75
+ }
76
+
77
+ let defaultLocale = 'en';
78
+ if (Platform.OS === 'ios') {
79
+ defaultLocale =
80
+ Platform.OS === 'ios'
81
+ ? NativeModules.SettingsManager.settings.AppleLocale
82
+ : NativeModules.SettingsManager.settings.AppleLanguages[0];
83
+ } else if (Platform.OS === 'android') {
84
+ defaultLocale = NativeModules.I18nManager.localeIdentifier;
85
+ }
86
+
87
+ // 德国数字格式化
88
+ export const localeNumber = (v: number | string, fixed?: number) => {
89
+ const mFixed = fixed || 2
90
+ const n = isNaN(Number(v)) ? 0 : Number(v)
91
+ const num = Number(n.toFixed(mFixed))
92
+ try {
93
+ if (Platform.OS === 'android') return formatNumber(n, mFixed)
94
+ let local = defaultLocale
95
+ if (defaultLocale !== 'pt_BR' && defaultLocale !== 'pt-BR') {
96
+ local = defaultLocale.split('_')[0]
97
+ }
98
+ return new Intl.NumberFormat(local).format(num)
99
+ } catch (_) {
100
+ return num
101
+ }
102
+ }
103
+
104
+
105
+ // 导出文件
106
+ export const exportFile = (list) => {
107
+ const value = list?.map(item => {
108
+ return [item?.key.split(' ')[0], item?.value]
109
+ })
110
+ const data = [
111
+ ['Date', `${I18n.getLang('consumption_data_annual_bar_chart_system_back_text')} (kWh)`],
112
+ ...value
113
+ ];
114
+ const timestamp = dayjs().format('YYYYMMDDHHmmss')
115
+
116
+ // 将CSV数据转换为CSV格式的字符串
117
+ const csvData = data.map(row => row.join(','));
118
+
119
+ // 创建 CSV 文件内容
120
+ const csvContent = csvData.join('\n');
121
+
122
+ // 定义文件保存路径
123
+ const documentsPath = RNFetchBlob.fs.dirs.DocumentDir;
124
+ const filePath = Platform.OS === 'android' ? RNFetchBlob.fs.dirs.DownloadDir + `/energyConsumption${timestamp}.csv` : `${documentsPath}/energyConsumption${timestamp}.csv`
125
+ RNFetchBlob.fs.writeFile(filePath, csvContent, 'utf8')
126
+ .then(() => {
127
+ openDownloadFile(filePath)
128
+ })
129
+ .catch(error => {
130
+ console.error('导出 CSV 文件时出现错误:', error);
131
+ });
132
+ }
133
+
134
+ export const exportHistoryFile = (list) => {
135
+ const value = list?.map(item => {
136
+ return item?.actions?.map(val => { return [val?.date, val?.time, val?.action, tagTitle[val?.dpId - 1]] })
137
+ })
138
+ const data = [
139
+ ['Date', 'Time', 'Status', 'Jack'],
140
+ ...value?.flat()
141
+ ];
142
+ const timestamp = dayjs().format('YYYYMMDDHHmmss')
143
+
144
+ // 将CSV数据转换为CSV格式的字符串
145
+ const csvData = data.map(row => row.join(','));
146
+
147
+ // 创建 CSV 文件内容
148
+ const csvContent = csvData.join('\n');
149
+
150
+ // 定义文件保存路径
151
+ const documentsPath = RNFetchBlob.fs.dirs.DocumentDir;
152
+ const filePath = Platform.OS === 'android' ? RNFetchBlob.fs.dirs.DownloadDir + `/history${timestamp}.csv` : `${documentsPath}/history${timestamp}.csv`
153
+ RNFetchBlob.fs.writeFile(filePath, csvContent, 'utf8')
154
+ .then(() => {
155
+ openDownloadFile(filePath)
156
+ })
157
+ .catch(error => {
158
+ console.error('导出 CSV 文件时出现错误:', error);
159
+ });
160
+ }
161
+
162
+ //月份格式化
163
+ export const monthFormat = (v: number | string) => {
164
+ const monthText = [
165
+ I18n.getLang('consumption_data_field4_month1_value_text'),
166
+ I18n.getLang('consumption_data_field4_month2_value_text'),
167
+ I18n.getLang('consumption_data_field4_month3_value_text'),
168
+ I18n.getLang('consumption_data_field4_month4_value_text'),
169
+ I18n.getLang('consumption_data_field4_month5_value_text'),
170
+ I18n.getLang('consumption_data_field4_month6_value_text'),
171
+ I18n.getLang('consumption_data_field4_month7_value_text'),
172
+ I18n.getLang('consumption_data_field4_month8_value_text'),
173
+ I18n.getLang('consumption_data_field4_month9_value_text'),
174
+ I18n.getLang('consumption_data_field4_month10_value_text'),
175
+ I18n.getLang('consumption_data_field4_month11_value_text'),
176
+ I18n.getLang('consumption_data_field4_month12_value_text'),
177
+ ]
178
+ return monthText[Number(v) - 1]
179
+ }
180
+
181
+ export const tagTitle = [
182
+ I18n.getLang('feature_summary_action_component_6'),
183
+ I18n.getLang('feature_summary_action_component_7'),
184
+ I18n.getLang('feature_summary_action_component_8'),
185
+ I18n.getLang('feature_summary_action_component_9'),
186
+ ]
187
+
188
+ export function isTimeSpanValid(timeData) {
189
+ const startTime = timeData.startTime;
190
+ const endTime = timeData.endTime;
191
+ // 将小时和分钟转换为分钟总数
192
+ const startMinutes = parseInt(startTime[0]) * 60 + parseInt(startTime[1]); const endMinutes = parseInt(endTime[0]) * 60 + parseInt(endTime[1]);
193
+ // 判断是否跨天,如果开始时间大于结束时间,则跨天
194
+ if (startMinutes > endMinutes) {
195
+ // 计算跨天情况下的时间间隔
196
+ const overnightInterval = 1440 - startMinutes + endMinutes;
197
+ return overnightInterval;
198
+ } else {
199
+ // 计算非跨天情况下的时间间隔
200
+ const interval = endMinutes - startMinutes;
201
+ return interval;
202
+ }
203
+ }
204
+
205
+ export function modifyPopup(beforeValue:object, editValue:object){
206
+ return !isEqual(beforeValue, editValue)
207
+ }
208
+