@ledvance/base 1.2.81 → 1.2.83
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/.babelrc +31 -31
- package/.eslintignore +5 -5
- package/.eslintrc.js +27 -27
- package/.prettierrc.js +1 -1
- package/.versionrc +5 -5
- package/localazy.json +848 -848
- package/localazy.keys.json +4 -4
- package/package.json +74 -74
- package/rn-cli.config.js +8 -8
- package/src/api/native.d.ts +71 -71
- package/src/api/native.ts +423 -423
- package/src/api/nativeEventEmitter.d.ts +3 -3
- package/src/api/nativeEventEmitter.ts +125 -125
- package/src/components/AdvanceCard.d.ts +25 -25
- package/src/components/AdvanceCard.tsx +117 -117
- package/src/components/AdvanceList.d.ts +9 -9
- package/src/components/AdvanceList.tsx +69 -69
- package/src/components/ApplyForDeviceItem.d.ts +6 -6
- package/src/components/ApplyForDeviceItem.tsx +83 -83
- package/src/components/ApplyForDeviceList.d.ts +7 -7
- package/src/components/ApplyForDeviceList.tsx +61 -61
- package/src/components/ApplyForText.d.ts +6 -6
- package/src/components/ApplyForText.tsx +52 -52
- package/src/components/Card.d.ts +10 -10
- package/src/components/Card.tsx +40 -40
- package/src/components/Cell.d.ts +21 -21
- package/src/components/Cell.tsx +69 -69
- package/src/components/CircularProgress.d.ts +8 -8
- package/src/components/CircularProgress.tsx +42 -42
- package/src/components/ColorAdjustView.d.ts +12 -12
- package/src/components/ColorAdjustView.tsx +64 -64
- package/src/components/ColorExtractor.d.ts +73 -73
- package/src/components/ColorExtractor.tsx +374 -374
- package/src/components/ColorTempAdjustView.d.ts +13 -13
- package/src/components/ColorTempAdjustView.tsx +57 -57
- package/src/components/ColorsLine.d.ts +7 -7
- package/src/components/ColorsLine.tsx +47 -47
- package/src/components/CustomListDialog.d.ts +15 -15
- package/src/components/CustomListDialog.tsx +66 -65
- package/src/components/DeleteButton.d.ts +10 -10
- package/src/components/DeleteButton.tsx +40 -40
- package/src/components/Dialog.d.ts +10 -10
- package/src/components/Dialog.tsx +38 -38
- package/src/components/DrawToolView.d.ts +46 -46
- package/src/components/DrawToolView.tsx +262 -262
- package/src/components/FanAdjustView.d.ts +23 -23
- package/src/components/FanAdjustView.tsx +141 -141
- package/src/components/InfoText.d.ts +11 -11
- package/src/components/InfoText.tsx +45 -45
- package/src/components/LampAdjustView.d.ts +10 -10
- package/src/components/LampAdjustView.tsx +75 -75
- package/src/components/LampAdjustView2.d.ts +24 -24
- package/src/components/LampAdjustView2.tsx +104 -104
- package/src/components/LinearGradientLine.d.ts +9 -9
- package/src/components/LinearGradientLine.tsx +63 -63
- package/src/components/LoadingView.tsx +39 -39
- package/src/components/MoodColorsLine.d.ts +9 -9
- package/src/components/MoodColorsLine.tsx +38 -38
- package/src/components/Page.d.ts +21 -21
- package/src/components/Page.tsx +104 -104
- package/src/components/Popup.d.ts +7 -7
- package/src/components/Popup.tsx +71 -71
- package/src/components/Segmented.d.ts +14 -14
- package/src/components/Segmented.tsx +76 -76
- package/src/components/ShowSelect.d.ts +1 -1
- package/src/components/ShowSelect.tsx +158 -158
- package/src/components/SocketItem.d.ts +13 -13
- package/src/components/SocketItem.tsx +87 -87
- package/src/components/Spacer.d.ts +7 -7
- package/src/components/Spacer.tsx +13 -13
- package/src/components/Stepper.d.ts +19 -19
- package/src/components/Stepper.tsx +130 -130
- package/src/components/StripAdjustView.d.ts +16 -16
- package/src/components/StripAdjustView.tsx +129 -129
- package/src/components/StripLightView.d.ts +14 -14
- package/src/components/StripLightView.tsx +24 -24
- package/src/components/Summary.tsx +116 -124
- package/src/components/Tag.d.ts +8 -8
- package/src/components/Tag.tsx +56 -56
- package/src/components/TextButton.d.ts +9 -9
- package/src/components/TextButton.tsx +31 -31
- package/src/components/TextField.d.ts +9 -9
- package/src/components/TextField.tsx +92 -92
- package/src/components/TextFieldStyleButton.d.ts +8 -8
- package/src/components/TextFieldStyleButton.tsx +85 -85
- package/src/components/UATabTitle.d.ts +6 -6
- package/src/components/UATabTitle.tsx +31 -31
- package/src/components/UATabs.d.ts +12 -12
- package/src/components/UATabs.tsx +77 -77
- package/src/components/connect.d.ts +10 -10
- package/src/components/connect.tsx +20 -20
- package/src/components/ldvColorBrightness.d.ts +1 -1
- package/src/components/ldvColorBrightness.tsx +18 -18
- package/src/components/ldvColorSlider.d.ts +14 -14
- package/src/components/ldvColorSlider.tsx +131 -131
- package/src/components/ldvItemView.d.ts +12 -12
- package/src/components/ldvItemView.tsx +43 -43
- package/src/components/ldvPickerView.d.ts +13 -13
- package/src/components/ldvPickerView.tsx +97 -97
- package/src/components/ldvPresetView.d.ts +2 -2
- package/src/components/ldvPresetView.tsx +86 -86
- package/src/components/ldvSaturation.d.ts +2 -2
- package/src/components/ldvSaturation.tsx +22 -22
- package/src/components/ldvSlider.d.ts +15 -15
- package/src/components/ldvSlider.tsx +103 -103
- package/src/components/ldvSwitch.d.ts +10 -10
- package/src/components/ldvSwitch.tsx +52 -52
- package/src/components/ldvTemperatureSlider.d.ts +13 -13
- package/src/components/ldvTemperatureSlider.tsx +139 -139
- package/src/components/ldvTopBar.d.ts +10 -10
- package/src/components/ldvTopBar.tsx +76 -76
- package/src/components/ldvTopName.d.ts +9 -9
- package/src/components/ldvTopName.tsx +63 -63
- package/src/components/segmentControl.d.ts +1 -1
- package/src/components/segmentControl.tsx +65 -65
- package/src/components/weekSelect.d.ts +7 -7
- package/src/components/weekSelect.tsx +98 -98
- package/src/composeLayout.d.ts +30 -30
- package/src/composeLayout.tsx +261 -261
- package/src/config/dark-theme.ts +61 -61
- package/src/config/light-theme.ts +61 -61
- package/src/hooks/Hooks.d.ts +2 -2
- package/src/hooks/Hooks.ts +8 -8
- package/src/i18n/index.d.ts +16 -16
- package/src/i18n/index.ts +37 -37
- package/src/i18n/strings.d.ts +15953 -15953
- package/src/i18n/strings.ts +23723 -23723
- package/src/main.tsx +9 -9
- package/src/models/GlobalParams.d.ts +14 -14
- package/src/models/GlobalParams.ts +14 -14
- package/src/models/TuyaApi.d.ts +29 -29
- package/src/models/TuyaApi.ts +92 -92
- package/src/models/combine.d.ts +26 -26
- package/src/models/combine.ts +17 -17
- package/src/models/configureStore.d.ts +9 -9
- package/src/models/configureStore.ts +33 -33
- package/src/models/index.d.ts +31 -31
- package/src/models/index.ts +22 -22
- package/src/models/modules/NativePropsSlice.d.ts +61 -61
- package/src/models/modules/NativePropsSlice.tsx +467 -467
- package/src/models/modules/Result.d.ts +14 -14
- package/src/models/modules/Result.ts +15 -15
- package/src/models/modules/common.d.ts +44 -44
- package/src/models/modules/common.ts +161 -161
- package/src/res/index.d.ts +70 -70
- package/src/res/index.ts +73 -73
- package/src/utils/ColorParser.d.ts +66 -66
- package/src/utils/ColorParser.ts +189 -189
- package/src/utils/ColorUtils.d.ts +71 -71
- package/src/utils/ColorUtils.tsx +448 -448
- package/src/utils/Support.d.ts +13 -13
- package/src/utils/Support.ts +108 -108
- package/src/utils/TypeUtils.d.ts +3 -3
- package/src/utils/cctUtils.d.ts +1 -1
- package/src/utils/cctUtils.ts +110 -110
- package/src/utils/common.d.ts +35 -35
- package/src/utils/common.ts +379 -379
- package/src/utils/index.d.ts +26 -26
- package/src/utils/index.ts +191 -191
- package/src/utils/interface.d.ts +6 -6
- package/src/utils/interface.ts +50 -11
- package/src/utils/loopsCompare.d.ts +1 -1
- package/src/utils/loopsCompare.ts +62 -62
- package/tsconfig.json +50 -50
- package/update-localazy.py +52 -52
package/src/utils/common.ts
CHANGED
|
@@ -1,379 +1,379 @@
|
|
|
1
|
-
import { NativeModules, Platform } from 'react-native'
|
|
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, Utils } from 'tuya-panel-kit'
|
|
8
|
-
import {GlobalParams} from "../models/GlobalParams";
|
|
9
|
-
|
|
10
|
-
const { toFixedString } = Utils.NumberUtils
|
|
11
|
-
|
|
12
|
-
export const loopsText = [
|
|
13
|
-
I18n.getLang('timeschedule_add_schedule_weekday7_text'),
|
|
14
|
-
I18n.getLang('timeschedule_add_schedule_weekday1_text'),
|
|
15
|
-
I18n.getLang('timeschedule_add_schedule_weekday2_text'),
|
|
16
|
-
I18n.getLang('timeschedule_add_schedule_weekday3_text'),
|
|
17
|
-
I18n.getLang('timeschedule_add_schedule_weekday4_text'),
|
|
18
|
-
I18n.getLang('timeschedule_add_schedule_weekday5_text'),
|
|
19
|
-
I18n.getLang('timeschedule_add_schedule_weekday6_text'),
|
|
20
|
-
]
|
|
21
|
-
|
|
22
|
-
export const loopText = (loop, time = '') => {
|
|
23
|
-
let isToday = true
|
|
24
|
-
if (time) {
|
|
25
|
-
const currentTime = dayjs()
|
|
26
|
-
const targetTime = dayjs().set('hour', parseInt(time.split(':')[0])).set('minute', parseInt(time.split(':')[1]));
|
|
27
|
-
const isBeforeCurrentTime = targetTime.isBefore(currentTime)
|
|
28
|
-
isToday = !isBeforeCurrentTime
|
|
29
|
-
}
|
|
30
|
-
const loopStrArray = loopsText.filter((_item, index) => Number(loop[index]) === 1)
|
|
31
|
-
return loopStrArray.length === 0 ? (I18n.getLang(isToday ? 'motion_detection_time_schedule_notifications_field_weekdays_text2' : 'motion_detection_time_schedule_notifications_field_weekdays_text3')) : loopStrArray.length === 7 ? I18n.getLang('motion_detection_time_schedule_notifications_field_weekdays_text4') : loopStrArray.join(' ')
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const tommorrow = () => {
|
|
35
|
-
const text = I18n.getLang('feature_summary_frequency_txt_2').split(' ')
|
|
36
|
-
return text?.length > 0 && text[text.length - 1] || ''
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export const loopTommorrowText = (loop, isTommorrow) => {
|
|
40
|
-
const loopStrArray = loopsText.filter((_item, index) => loop[index] === 1)
|
|
41
|
-
return loopStrArray.length == 7 ? (I18n.getLang('motion_detection_time_schedule_notifications_field_weekdays_text4') + (isTommorrow && ` ${tommorrow()}` || '')) :
|
|
42
|
-
(loopStrArray.join(' ') && `${I18n.formatValue('timeschedule_add_schedule_text', loopStrArray.join(' '))} ${isTommorrow && `${tommorrow()}` || ''}` ||
|
|
43
|
-
I18n.getLang(isTommorrow && 'feature_summary_frequency_txt_2' || 'motion_detection_time_schedule_notifications_field_weekdays_text2'))
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export const toFixed = (str, count) => {
|
|
47
|
-
return `${'0'.repeat(count)}${str}`.slice(-1 * count)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function getArray(arr, size) { // size=5,要分割的长度
|
|
51
|
-
const arrNum = Math.ceil(arr.length / size) // Math.ceil()向上取整的方法,用来计算拆分后数组的长度
|
|
52
|
-
let index = 0 // 定义初始索引
|
|
53
|
-
let resIndex = 0 // 用来保存每次拆分的长度
|
|
54
|
-
const result: string[] = []
|
|
55
|
-
while (index < arrNum) {
|
|
56
|
-
result[index] = arr.slice(resIndex, size + resIndex)
|
|
57
|
-
resIndex += size
|
|
58
|
-
index++
|
|
59
|
-
}
|
|
60
|
-
return result
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export function getWeek(weekString) {
|
|
64
|
-
const s = parseInt(weekString, 16).toString(2).padStart(8, '0')
|
|
65
|
-
const array = s.split('').map(item => parseInt(item)).reverse()
|
|
66
|
-
array.pop()
|
|
67
|
-
return array
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* 按位分割字符串
|
|
72
|
-
* @param {*} str 要分割的字符串
|
|
73
|
-
* @param {*} step 按多少位分割
|
|
74
|
-
* @returns ['','',...]
|
|
75
|
-
*/
|
|
76
|
-
export function spliceByStep(str: string, step: number): string[] {
|
|
77
|
-
let res: string[] = []
|
|
78
|
-
for (let i = 0; i < str.length; i += step) {
|
|
79
|
-
res.push(str.substr(i, step))
|
|
80
|
-
}
|
|
81
|
-
return res
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export function hex2Int(hex: string): number {
|
|
85
|
-
return parseInt(hex, 16)
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
let defaultLocale = 'en'
|
|
89
|
-
if (Platform.OS === 'ios') {
|
|
90
|
-
defaultLocale =
|
|
91
|
-
Platform.OS === 'ios'
|
|
92
|
-
? NativeModules.SettingsManager.settings.AppleLocale
|
|
93
|
-
: NativeModules.SettingsManager.settings.AppleLanguages[0]
|
|
94
|
-
} else if (Platform.OS === 'android') {
|
|
95
|
-
defaultLocale = NativeModules.I18nManager.localeIdentifier
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// 德国数字格式化
|
|
99
|
-
export const localeNumber = (v: number | string, fixed?: number, showGroup?: boolean) => {
|
|
100
|
-
const mFixed = fixed || 2
|
|
101
|
-
const n = isNaN(Number(v)) ? 0 : Number(v)
|
|
102
|
-
try {
|
|
103
|
-
if (Platform.OS === 'android') return formatNumber(n, mFixed, showGroup)
|
|
104
|
-
let local = defaultLocale
|
|
105
|
-
if (defaultLocale !== 'pt_BR' && defaultLocale !== 'pt-BR') {
|
|
106
|
-
local = defaultLocale.split('_')[0]
|
|
107
|
-
}
|
|
108
|
-
return new Intl.NumberFormat(local, {
|
|
109
|
-
useGrouping: showGroup !== undefined ? showGroup : true,
|
|
110
|
-
maximumFractionDigits: mFixed
|
|
111
|
-
}).format(n)
|
|
112
|
-
} catch (_) {
|
|
113
|
-
return n === 0 ? n : n.toFixed(mFixed)
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// 转换成国际数字
|
|
118
|
-
export const exchangeNumber = (v: number | string) => {
|
|
119
|
-
return v.toString().replace(/[\,]/g, '.')
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
// 导出文件
|
|
124
|
-
export const exportFile = (list) => {
|
|
125
|
-
const value = list?.map(item => {
|
|
126
|
-
return [item?.key, item?.value]
|
|
127
|
-
})
|
|
128
|
-
const data = [
|
|
129
|
-
['Date', `${I18n.getLang('consumption_data_annual_bar_chart_system_back_text')} (kWh)`],
|
|
130
|
-
...value,
|
|
131
|
-
]
|
|
132
|
-
const timestamp = dayjs().format('YYYYMMDDHHmmss')
|
|
133
|
-
|
|
134
|
-
// 将CSV数据转换为CSV格式的字符串
|
|
135
|
-
const csvData = data.map(row => row.join(','))
|
|
136
|
-
|
|
137
|
-
// 创建 CSV 文件内容
|
|
138
|
-
const csvContent = csvData.join('\n')
|
|
139
|
-
|
|
140
|
-
// 定义文件保存路径
|
|
141
|
-
const documentsPath = RNFetchBlob.fs.dirs.DocumentDir
|
|
142
|
-
const filePath = Platform.OS === 'android' ? RNFetchBlob.fs.dirs.DownloadDir + `/energyConsumption${timestamp}.csv` : `${documentsPath}/energyConsumption${timestamp}.csv`
|
|
143
|
-
RNFetchBlob.fs.writeFile(filePath, csvContent, 'utf8')
|
|
144
|
-
.then(() => {
|
|
145
|
-
openDownloadFile(filePath)
|
|
146
|
-
})
|
|
147
|
-
.catch(error => {
|
|
148
|
-
console.error('导出 CSV 文件时出现错误:', error)
|
|
149
|
-
})
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export const exportHistoryFile = (list) => {
|
|
153
|
-
const value = list?.map(item => {
|
|
154
|
-
return item?.actions?.map(val => {
|
|
155
|
-
return [val?.date, val?.time, val?.action, tagTitle[val?.dpId - 1]]
|
|
156
|
-
})
|
|
157
|
-
})
|
|
158
|
-
const data = [
|
|
159
|
-
['Date', 'Time', 'Status', 'Jack'],
|
|
160
|
-
...value?.flat(),
|
|
161
|
-
]
|
|
162
|
-
const timestamp = dayjs().format('YYYYMMDDHHmmss')
|
|
163
|
-
|
|
164
|
-
// 将CSV数据转换为CSV格式的字符串
|
|
165
|
-
const csvData = data.map(row => row.join(','))
|
|
166
|
-
|
|
167
|
-
// 创建 CSV 文件内容
|
|
168
|
-
const csvContent = csvData.join('\n')
|
|
169
|
-
|
|
170
|
-
// 定义文件保存路径
|
|
171
|
-
const documentsPath = RNFetchBlob.fs.dirs.DocumentDir
|
|
172
|
-
const filePath = Platform.OS === 'android' ? RNFetchBlob.fs.dirs.DownloadDir + `/history${timestamp}.csv` : `${documentsPath}/history${timestamp}.csv`
|
|
173
|
-
RNFetchBlob.fs.writeFile(filePath, csvContent, 'utf8')
|
|
174
|
-
.then(() => {
|
|
175
|
-
openDownloadFile(filePath)
|
|
176
|
-
})
|
|
177
|
-
.catch(error => {
|
|
178
|
-
console.error('导出 CSV 文件时出现错误:', error)
|
|
179
|
-
})
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
//月份格式化
|
|
183
|
-
export const monthFormat = (v: number | string) => {
|
|
184
|
-
const monthText = [
|
|
185
|
-
I18n.getLang('consumption_data_field4_month1_value_text'),
|
|
186
|
-
I18n.getLang('consumption_data_field4_month2_value_text'),
|
|
187
|
-
I18n.getLang('consumption_data_field4_month3_value_text'),
|
|
188
|
-
I18n.getLang('consumption_data_field4_month4_value_text'),
|
|
189
|
-
I18n.getLang('consumption_data_field4_month5_value_text'),
|
|
190
|
-
I18n.getLang('consumption_data_field4_month6_value_text'),
|
|
191
|
-
I18n.getLang('consumption_data_field4_month7_value_text'),
|
|
192
|
-
I18n.getLang('consumption_data_field4_month8_value_text'),
|
|
193
|
-
I18n.getLang('consumption_data_field4_month9_value_text'),
|
|
194
|
-
I18n.getLang('consumption_data_field4_month10_value_text'),
|
|
195
|
-
I18n.getLang('consumption_data_field4_month11_value_text'),
|
|
196
|
-
I18n.getLang('consumption_data_field4_month12_value_text'),
|
|
197
|
-
]
|
|
198
|
-
return monthText[Number(v) - 1]
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
//月份格式化
|
|
202
|
-
export const monthFormatShort = (v: number | string) => {
|
|
203
|
-
const monthText = [
|
|
204
|
-
I18n.getLang('month_short_january'),
|
|
205
|
-
I18n.getLang('month_short_february'),
|
|
206
|
-
I18n.getLang('month_short_march'),
|
|
207
|
-
I18n.getLang('month_short_april'),
|
|
208
|
-
I18n.getLang('month_short_may'),
|
|
209
|
-
I18n.getLang('month_short_june'),
|
|
210
|
-
I18n.getLang('month_short_july'),
|
|
211
|
-
I18n.getLang('month_short_august'),
|
|
212
|
-
I18n.getLang('month_short_september'),
|
|
213
|
-
I18n.getLang('month_short_october'),
|
|
214
|
-
I18n.getLang('month_short_november'),
|
|
215
|
-
I18n.getLang('month_short_december'),
|
|
216
|
-
]
|
|
217
|
-
return monthText[Number(v) - 1]
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
export const tagTitle = [
|
|
221
|
-
I18n.getLang('feature_summary_action_component_6'),
|
|
222
|
-
I18n.getLang('feature_summary_action_component_7'),
|
|
223
|
-
I18n.getLang('feature_summary_action_component_8'),
|
|
224
|
-
I18n.getLang('feature_summary_action_component_9'),
|
|
225
|
-
]
|
|
226
|
-
|
|
227
|
-
export function isTimeSpanValid(timeData) {
|
|
228
|
-
const startTime = timeData.startTime
|
|
229
|
-
const endTime = timeData.endTime
|
|
230
|
-
// 将小时和分钟转换为分钟总数
|
|
231
|
-
const startMinutes = parseInt(startTime[0]) * 60 + parseInt(startTime[1])
|
|
232
|
-
const endMinutes = parseInt(endTime[0]) * 60 + parseInt(endTime[1])
|
|
233
|
-
// 判断是否跨天,如果开始时间大于结束时间,则跨天
|
|
234
|
-
if (startMinutes > endMinutes) {
|
|
235
|
-
// 计算跨天情况下的时间间隔
|
|
236
|
-
const overnightInterval = 1440 - startMinutes + endMinutes
|
|
237
|
-
return overnightInterval
|
|
238
|
-
} else {
|
|
239
|
-
// 计算非跨天情况下的时间间隔
|
|
240
|
-
const interval = endMinutes - startMinutes
|
|
241
|
-
return interval
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
export function modifyPopup(beforeValue: object, editValue: object) {
|
|
246
|
-
return !isEqual(beforeValue, editValue)
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
// dialog
|
|
250
|
-
interface DialogProps {
|
|
251
|
-
method: 'alert' | 'confirm'
|
|
252
|
-
title: string
|
|
253
|
-
showCancelText?: boolean
|
|
254
|
-
showConfirmText?: boolean
|
|
255
|
-
cancelText?: string
|
|
256
|
-
confirmText?: string
|
|
257
|
-
subTitle?: string
|
|
258
|
-
onConfirm: (data: any, args: { close: () => void }) => void
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
export function showDialog(props: DialogProps) {
|
|
262
|
-
const {
|
|
263
|
-
method,
|
|
264
|
-
showCancelText = true,
|
|
265
|
-
showConfirmText = true,
|
|
266
|
-
title,
|
|
267
|
-
cancelText,
|
|
268
|
-
confirmText,
|
|
269
|
-
subTitle,
|
|
270
|
-
onConfirm,
|
|
271
|
-
} = props
|
|
272
|
-
return (
|
|
273
|
-
method === 'confirm' ?
|
|
274
|
-
Dialog.confirm({
|
|
275
|
-
title: title,
|
|
276
|
-
cancelText: showCancelText && (cancelText || I18n.getLang('conflict_dialog_save_item_fixedtimecycle_answer_no_text')) || '',
|
|
277
|
-
confirmText: showConfirmText && (confirmText || I18n.getLang('conflict_dialog_save_item_fixedtimecycle_answer_yes_text')) || '',
|
|
278
|
-
subTitle,
|
|
279
|
-
onConfirm,
|
|
280
|
-
motionConfig: {
|
|
281
|
-
hideDuration: 0,
|
|
282
|
-
showDuration: 100
|
|
283
|
-
}
|
|
284
|
-
})
|
|
285
|
-
:
|
|
286
|
-
Dialog.alert({
|
|
287
|
-
title: title,
|
|
288
|
-
confirmText: showConfirmText && (confirmText || I18n.getLang('conflict_dialog_save_item_fixedtimecycle_answer_yes_text')) || '',
|
|
289
|
-
subTitle,
|
|
290
|
-
onConfirm,
|
|
291
|
-
motionConfig: {
|
|
292
|
-
hideDuration: 0,
|
|
293
|
-
showDuration: 100
|
|
294
|
-
}
|
|
295
|
-
})
|
|
296
|
-
)
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
export function convertTo12HourFormat(time24: string) {
|
|
300
|
-
// 将字符串按照':'分割成小时和分钟
|
|
301
|
-
var timeParts = time24.split(':');
|
|
302
|
-
var hours = parseInt(timeParts[0]);
|
|
303
|
-
var minutes = parseInt(timeParts[1]);
|
|
304
|
-
|
|
305
|
-
// 检查小时是否大于等于12
|
|
306
|
-
var suffix = (hours >= 12) ? I18n.getLang('manage_user_calendar_label_pm') : I18n.getLang('manage_user_calendar_label_am');
|
|
307
|
-
|
|
308
|
-
// 如果小时大于12,将小时减去12
|
|
309
|
-
hours = (hours > 12) ? hours - 12 : hours;
|
|
310
|
-
|
|
311
|
-
// 如果小时为0,则表示为12小时制中的12点
|
|
312
|
-
hours = (hours == 0) ? 12 : hours;
|
|
313
|
-
|
|
314
|
-
// 返回转换后的时间字符串
|
|
315
|
-
return suffix + ' ' + hours + ':' + (minutes < 10 ? '0' : '') + minutes;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
// 将分钟数转换为12小时制时间
|
|
319
|
-
export function convertMinutesTo12HourFormat(minutes: number, is24: boolean) {
|
|
320
|
-
let hours = Math.floor(minutes / 60); // 获取小时数
|
|
321
|
-
const mins = minutes % 60; // 获取剩余分钟数
|
|
322
|
-
if(is24){
|
|
323
|
-
return `${toFixedString(hours, 2)}:${toFixedString(mins, 2)}`
|
|
324
|
-
}
|
|
325
|
-
// 构造12小时制时间字符串
|
|
326
|
-
const suffix = (hours >= 12) ? I18n.getLang('manage_user_calendar_label_pm') : I18n.getLang('manage_user_calendar_label_am');
|
|
327
|
-
// 检查小时数是否大于12,并调整
|
|
328
|
-
if (hours > 12) {
|
|
329
|
-
hours -= 12;
|
|
330
|
-
}
|
|
331
|
-
hours = (hours == 0) ? 12 : hours; // 处理午夜0点为12小时制的12点
|
|
332
|
-
const time12Hour = suffix + ' ' + hours + ':' + (mins < 10 ? '0' : '') + mins;
|
|
333
|
-
|
|
334
|
-
return time12Hour;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
export function getGlobalParamsDp(key: string) {
|
|
338
|
-
return GlobalParams.dpSchemaMap[key] && GlobalParams.dpSchemaMap[key].dp.toString()
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
export function isSupportFunctions(...keys: string[]) {
|
|
342
|
-
return keys.every(key => key in GlobalParams.dpSchemaMap)
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
// 判断时间毫秒数在这一天中多少分钟
|
|
346
|
-
export function getMinutesOfTheDay(milliseconds: number) {
|
|
347
|
-
// 将给定的毫秒数转换为 Date 对象
|
|
348
|
-
const date = new Date(milliseconds);
|
|
349
|
-
|
|
350
|
-
// 获取该日期的起始时间(午夜 00:00:00)的时间戳(毫秒)
|
|
351
|
-
const startOfDay = new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime();
|
|
352
|
-
|
|
353
|
-
// 计算给定毫秒数与当天起始时间的差值(毫秒)
|
|
354
|
-
const differenceMillis = milliseconds - startOfDay;
|
|
355
|
-
|
|
356
|
-
// 将差值转换为分钟数
|
|
357
|
-
const minutes = Math.floor(differenceMillis / 60000);
|
|
358
|
-
|
|
359
|
-
return minutes;
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
export function getIsClosed(item: {weeks: number[], settingTime: number, endTime: number}){
|
|
363
|
-
const isOnce = item?.weeks?.every(w => w === 0)
|
|
364
|
-
let undone = true
|
|
365
|
-
if(isOnce && item.settingTime){
|
|
366
|
-
const setting = new Date(item.settingTime).toDateString()
|
|
367
|
-
const settingMin = getMinutesOfTheDay(item.settingTime)
|
|
368
|
-
const current = new Date().toDateString()
|
|
369
|
-
const currentMin = getMinutesOfTheDay(new Date().getTime())
|
|
370
|
-
if(setting !== current){
|
|
371
|
-
undone = false
|
|
372
|
-
}else{
|
|
373
|
-
if(settingMin < item.endTime && currentMin > item.endTime){
|
|
374
|
-
undone = false
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
return undone
|
|
379
|
-
}
|
|
1
|
+
import { NativeModules, Platform } from 'react-native'
|
|
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, Utils } from 'tuya-panel-kit'
|
|
8
|
+
import {GlobalParams} from "../models/GlobalParams";
|
|
9
|
+
|
|
10
|
+
const { toFixedString } = Utils.NumberUtils
|
|
11
|
+
|
|
12
|
+
export const loopsText = [
|
|
13
|
+
I18n.getLang('timeschedule_add_schedule_weekday7_text'),
|
|
14
|
+
I18n.getLang('timeschedule_add_schedule_weekday1_text'),
|
|
15
|
+
I18n.getLang('timeschedule_add_schedule_weekday2_text'),
|
|
16
|
+
I18n.getLang('timeschedule_add_schedule_weekday3_text'),
|
|
17
|
+
I18n.getLang('timeschedule_add_schedule_weekday4_text'),
|
|
18
|
+
I18n.getLang('timeschedule_add_schedule_weekday5_text'),
|
|
19
|
+
I18n.getLang('timeschedule_add_schedule_weekday6_text'),
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
export const loopText = (loop, time = '') => {
|
|
23
|
+
let isToday = true
|
|
24
|
+
if (time) {
|
|
25
|
+
const currentTime = dayjs()
|
|
26
|
+
const targetTime = dayjs().set('hour', parseInt(time.split(':')[0])).set('minute', parseInt(time.split(':')[1]));
|
|
27
|
+
const isBeforeCurrentTime = targetTime.isBefore(currentTime)
|
|
28
|
+
isToday = !isBeforeCurrentTime
|
|
29
|
+
}
|
|
30
|
+
const loopStrArray = loopsText.filter((_item, index) => Number(loop[index]) === 1)
|
|
31
|
+
return loopStrArray.length === 0 ? (I18n.getLang(isToday ? 'motion_detection_time_schedule_notifications_field_weekdays_text2' : 'motion_detection_time_schedule_notifications_field_weekdays_text3')) : loopStrArray.length === 7 ? I18n.getLang('motion_detection_time_schedule_notifications_field_weekdays_text4') : loopStrArray.join(' ')
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const tommorrow = () => {
|
|
35
|
+
const text = I18n.getLang('feature_summary_frequency_txt_2').split(' ')
|
|
36
|
+
return text?.length > 0 && text[text.length - 1] || ''
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const loopTommorrowText = (loop, isTommorrow) => {
|
|
40
|
+
const loopStrArray = loopsText.filter((_item, index) => loop[index] === 1)
|
|
41
|
+
return loopStrArray.length == 7 ? (I18n.getLang('motion_detection_time_schedule_notifications_field_weekdays_text4') + (isTommorrow && ` ${tommorrow()}` || '')) :
|
|
42
|
+
(loopStrArray.join(' ') && `${I18n.formatValue('timeschedule_add_schedule_text', loopStrArray.join(' '))} ${isTommorrow && `${tommorrow()}` || ''}` ||
|
|
43
|
+
I18n.getLang(isTommorrow && 'feature_summary_frequency_txt_2' || 'motion_detection_time_schedule_notifications_field_weekdays_text2'))
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const toFixed = (str, count) => {
|
|
47
|
+
return `${'0'.repeat(count)}${str}`.slice(-1 * count)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function getArray(arr, size) { // size=5,要分割的长度
|
|
51
|
+
const arrNum = Math.ceil(arr.length / size) // Math.ceil()向上取整的方法,用来计算拆分后数组的长度
|
|
52
|
+
let index = 0 // 定义初始索引
|
|
53
|
+
let resIndex = 0 // 用来保存每次拆分的长度
|
|
54
|
+
const result: string[] = []
|
|
55
|
+
while (index < arrNum) {
|
|
56
|
+
result[index] = arr.slice(resIndex, size + resIndex)
|
|
57
|
+
resIndex += size
|
|
58
|
+
index++
|
|
59
|
+
}
|
|
60
|
+
return result
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function getWeek(weekString) {
|
|
64
|
+
const s = parseInt(weekString, 16).toString(2).padStart(8, '0')
|
|
65
|
+
const array = s.split('').map(item => parseInt(item)).reverse()
|
|
66
|
+
array.pop()
|
|
67
|
+
return array
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* 按位分割字符串
|
|
72
|
+
* @param {*} str 要分割的字符串
|
|
73
|
+
* @param {*} step 按多少位分割
|
|
74
|
+
* @returns ['','',...]
|
|
75
|
+
*/
|
|
76
|
+
export function spliceByStep(str: string, step: number): string[] {
|
|
77
|
+
let res: string[] = []
|
|
78
|
+
for (let i = 0; i < str.length; i += step) {
|
|
79
|
+
res.push(str.substr(i, step))
|
|
80
|
+
}
|
|
81
|
+
return res
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function hex2Int(hex: string): number {
|
|
85
|
+
return parseInt(hex, 16)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
let defaultLocale = 'en'
|
|
89
|
+
if (Platform.OS === 'ios') {
|
|
90
|
+
defaultLocale =
|
|
91
|
+
Platform.OS === 'ios'
|
|
92
|
+
? NativeModules.SettingsManager.settings.AppleLocale
|
|
93
|
+
: NativeModules.SettingsManager.settings.AppleLanguages[0]
|
|
94
|
+
} else if (Platform.OS === 'android') {
|
|
95
|
+
defaultLocale = NativeModules.I18nManager.localeIdentifier
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// 德国数字格式化
|
|
99
|
+
export const localeNumber = (v: number | string, fixed?: number, showGroup?: boolean) => {
|
|
100
|
+
const mFixed = fixed || 2
|
|
101
|
+
const n = isNaN(Number(v)) ? 0 : Number(v)
|
|
102
|
+
try {
|
|
103
|
+
if (Platform.OS === 'android') return formatNumber(n, mFixed, showGroup)
|
|
104
|
+
let local = defaultLocale
|
|
105
|
+
if (defaultLocale !== 'pt_BR' && defaultLocale !== 'pt-BR') {
|
|
106
|
+
local = defaultLocale.split('_')[0]
|
|
107
|
+
}
|
|
108
|
+
return new Intl.NumberFormat(local, {
|
|
109
|
+
useGrouping: showGroup !== undefined ? showGroup : true,
|
|
110
|
+
maximumFractionDigits: mFixed
|
|
111
|
+
}).format(n)
|
|
112
|
+
} catch (_) {
|
|
113
|
+
return n === 0 ? n : n.toFixed(mFixed)
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// 转换成国际数字
|
|
118
|
+
export const exchangeNumber = (v: number | string) => {
|
|
119
|
+
return v.toString().replace(/[\,]/g, '.')
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
// 导出文件
|
|
124
|
+
export const exportFile = (list) => {
|
|
125
|
+
const value = list?.map(item => {
|
|
126
|
+
return [item?.key, item?.value]
|
|
127
|
+
})
|
|
128
|
+
const data = [
|
|
129
|
+
['Date', `${I18n.getLang('consumption_data_annual_bar_chart_system_back_text')} (kWh)`],
|
|
130
|
+
...value,
|
|
131
|
+
]
|
|
132
|
+
const timestamp = dayjs().format('YYYYMMDDHHmmss')
|
|
133
|
+
|
|
134
|
+
// 将CSV数据转换为CSV格式的字符串
|
|
135
|
+
const csvData = data.map(row => row.join(','))
|
|
136
|
+
|
|
137
|
+
// 创建 CSV 文件内容
|
|
138
|
+
const csvContent = csvData.join('\n')
|
|
139
|
+
|
|
140
|
+
// 定义文件保存路径
|
|
141
|
+
const documentsPath = RNFetchBlob.fs.dirs.DocumentDir
|
|
142
|
+
const filePath = Platform.OS === 'android' ? RNFetchBlob.fs.dirs.DownloadDir + `/energyConsumption${timestamp}.csv` : `${documentsPath}/energyConsumption${timestamp}.csv`
|
|
143
|
+
RNFetchBlob.fs.writeFile(filePath, csvContent, 'utf8')
|
|
144
|
+
.then(() => {
|
|
145
|
+
openDownloadFile(filePath)
|
|
146
|
+
})
|
|
147
|
+
.catch(error => {
|
|
148
|
+
console.error('导出 CSV 文件时出现错误:', error)
|
|
149
|
+
})
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export const exportHistoryFile = (list) => {
|
|
153
|
+
const value = list?.map(item => {
|
|
154
|
+
return item?.actions?.map(val => {
|
|
155
|
+
return [val?.date, val?.time, val?.action, tagTitle[val?.dpId - 1]]
|
|
156
|
+
})
|
|
157
|
+
})
|
|
158
|
+
const data = [
|
|
159
|
+
['Date', 'Time', 'Status', 'Jack'],
|
|
160
|
+
...value?.flat(),
|
|
161
|
+
]
|
|
162
|
+
const timestamp = dayjs().format('YYYYMMDDHHmmss')
|
|
163
|
+
|
|
164
|
+
// 将CSV数据转换为CSV格式的字符串
|
|
165
|
+
const csvData = data.map(row => row.join(','))
|
|
166
|
+
|
|
167
|
+
// 创建 CSV 文件内容
|
|
168
|
+
const csvContent = csvData.join('\n')
|
|
169
|
+
|
|
170
|
+
// 定义文件保存路径
|
|
171
|
+
const documentsPath = RNFetchBlob.fs.dirs.DocumentDir
|
|
172
|
+
const filePath = Platform.OS === 'android' ? RNFetchBlob.fs.dirs.DownloadDir + `/history${timestamp}.csv` : `${documentsPath}/history${timestamp}.csv`
|
|
173
|
+
RNFetchBlob.fs.writeFile(filePath, csvContent, 'utf8')
|
|
174
|
+
.then(() => {
|
|
175
|
+
openDownloadFile(filePath)
|
|
176
|
+
})
|
|
177
|
+
.catch(error => {
|
|
178
|
+
console.error('导出 CSV 文件时出现错误:', error)
|
|
179
|
+
})
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
//月份格式化
|
|
183
|
+
export const monthFormat = (v: number | string) => {
|
|
184
|
+
const monthText = [
|
|
185
|
+
I18n.getLang('consumption_data_field4_month1_value_text'),
|
|
186
|
+
I18n.getLang('consumption_data_field4_month2_value_text'),
|
|
187
|
+
I18n.getLang('consumption_data_field4_month3_value_text'),
|
|
188
|
+
I18n.getLang('consumption_data_field4_month4_value_text'),
|
|
189
|
+
I18n.getLang('consumption_data_field4_month5_value_text'),
|
|
190
|
+
I18n.getLang('consumption_data_field4_month6_value_text'),
|
|
191
|
+
I18n.getLang('consumption_data_field4_month7_value_text'),
|
|
192
|
+
I18n.getLang('consumption_data_field4_month8_value_text'),
|
|
193
|
+
I18n.getLang('consumption_data_field4_month9_value_text'),
|
|
194
|
+
I18n.getLang('consumption_data_field4_month10_value_text'),
|
|
195
|
+
I18n.getLang('consumption_data_field4_month11_value_text'),
|
|
196
|
+
I18n.getLang('consumption_data_field4_month12_value_text'),
|
|
197
|
+
]
|
|
198
|
+
return monthText[Number(v) - 1]
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
//月份格式化
|
|
202
|
+
export const monthFormatShort = (v: number | string) => {
|
|
203
|
+
const monthText = [
|
|
204
|
+
I18n.getLang('month_short_january'),
|
|
205
|
+
I18n.getLang('month_short_february'),
|
|
206
|
+
I18n.getLang('month_short_march'),
|
|
207
|
+
I18n.getLang('month_short_april'),
|
|
208
|
+
I18n.getLang('month_short_may'),
|
|
209
|
+
I18n.getLang('month_short_june'),
|
|
210
|
+
I18n.getLang('month_short_july'),
|
|
211
|
+
I18n.getLang('month_short_august'),
|
|
212
|
+
I18n.getLang('month_short_september'),
|
|
213
|
+
I18n.getLang('month_short_october'),
|
|
214
|
+
I18n.getLang('month_short_november'),
|
|
215
|
+
I18n.getLang('month_short_december'),
|
|
216
|
+
]
|
|
217
|
+
return monthText[Number(v) - 1]
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export const tagTitle = [
|
|
221
|
+
I18n.getLang('feature_summary_action_component_6'),
|
|
222
|
+
I18n.getLang('feature_summary_action_component_7'),
|
|
223
|
+
I18n.getLang('feature_summary_action_component_8'),
|
|
224
|
+
I18n.getLang('feature_summary_action_component_9'),
|
|
225
|
+
]
|
|
226
|
+
|
|
227
|
+
export function isTimeSpanValid(timeData) {
|
|
228
|
+
const startTime = timeData.startTime
|
|
229
|
+
const endTime = timeData.endTime
|
|
230
|
+
// 将小时和分钟转换为分钟总数
|
|
231
|
+
const startMinutes = parseInt(startTime[0]) * 60 + parseInt(startTime[1])
|
|
232
|
+
const endMinutes = parseInt(endTime[0]) * 60 + parseInt(endTime[1])
|
|
233
|
+
// 判断是否跨天,如果开始时间大于结束时间,则跨天
|
|
234
|
+
if (startMinutes > endMinutes) {
|
|
235
|
+
// 计算跨天情况下的时间间隔
|
|
236
|
+
const overnightInterval = 1440 - startMinutes + endMinutes
|
|
237
|
+
return overnightInterval
|
|
238
|
+
} else {
|
|
239
|
+
// 计算非跨天情况下的时间间隔
|
|
240
|
+
const interval = endMinutes - startMinutes
|
|
241
|
+
return interval
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export function modifyPopup(beforeValue: object, editValue: object) {
|
|
246
|
+
return !isEqual(beforeValue, editValue)
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// dialog
|
|
250
|
+
interface DialogProps {
|
|
251
|
+
method: 'alert' | 'confirm'
|
|
252
|
+
title: string
|
|
253
|
+
showCancelText?: boolean
|
|
254
|
+
showConfirmText?: boolean
|
|
255
|
+
cancelText?: string
|
|
256
|
+
confirmText?: string
|
|
257
|
+
subTitle?: string
|
|
258
|
+
onConfirm: (data: any, args: { close: () => void }) => void
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export function showDialog(props: DialogProps) {
|
|
262
|
+
const {
|
|
263
|
+
method,
|
|
264
|
+
showCancelText = true,
|
|
265
|
+
showConfirmText = true,
|
|
266
|
+
title,
|
|
267
|
+
cancelText,
|
|
268
|
+
confirmText,
|
|
269
|
+
subTitle,
|
|
270
|
+
onConfirm,
|
|
271
|
+
} = props
|
|
272
|
+
return (
|
|
273
|
+
method === 'confirm' ?
|
|
274
|
+
Dialog.confirm({
|
|
275
|
+
title: title,
|
|
276
|
+
cancelText: showCancelText && (cancelText || I18n.getLang('conflict_dialog_save_item_fixedtimecycle_answer_no_text')) || '',
|
|
277
|
+
confirmText: showConfirmText && (confirmText || I18n.getLang('conflict_dialog_save_item_fixedtimecycle_answer_yes_text')) || '',
|
|
278
|
+
subTitle,
|
|
279
|
+
onConfirm,
|
|
280
|
+
motionConfig: {
|
|
281
|
+
hideDuration: 0,
|
|
282
|
+
showDuration: 100
|
|
283
|
+
}
|
|
284
|
+
})
|
|
285
|
+
:
|
|
286
|
+
Dialog.alert({
|
|
287
|
+
title: title,
|
|
288
|
+
confirmText: showConfirmText && (confirmText || I18n.getLang('conflict_dialog_save_item_fixedtimecycle_answer_yes_text')) || '',
|
|
289
|
+
subTitle,
|
|
290
|
+
onConfirm,
|
|
291
|
+
motionConfig: {
|
|
292
|
+
hideDuration: 0,
|
|
293
|
+
showDuration: 100
|
|
294
|
+
}
|
|
295
|
+
})
|
|
296
|
+
)
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
export function convertTo12HourFormat(time24: string) {
|
|
300
|
+
// 将字符串按照':'分割成小时和分钟
|
|
301
|
+
var timeParts = time24.split(':');
|
|
302
|
+
var hours = parseInt(timeParts[0]);
|
|
303
|
+
var minutes = parseInt(timeParts[1]);
|
|
304
|
+
|
|
305
|
+
// 检查小时是否大于等于12
|
|
306
|
+
var suffix = (hours >= 12) ? I18n.getLang('manage_user_calendar_label_pm') : I18n.getLang('manage_user_calendar_label_am');
|
|
307
|
+
|
|
308
|
+
// 如果小时大于12,将小时减去12
|
|
309
|
+
hours = (hours > 12) ? hours - 12 : hours;
|
|
310
|
+
|
|
311
|
+
// 如果小时为0,则表示为12小时制中的12点
|
|
312
|
+
hours = (hours == 0) ? 12 : hours;
|
|
313
|
+
|
|
314
|
+
// 返回转换后的时间字符串
|
|
315
|
+
return suffix + ' ' + hours + ':' + (minutes < 10 ? '0' : '') + minutes;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// 将分钟数转换为12小时制时间
|
|
319
|
+
export function convertMinutesTo12HourFormat(minutes: number, is24: boolean) {
|
|
320
|
+
let hours = Math.floor(minutes / 60); // 获取小时数
|
|
321
|
+
const mins = minutes % 60; // 获取剩余分钟数
|
|
322
|
+
if(is24){
|
|
323
|
+
return `${toFixedString(hours, 2)}:${toFixedString(mins, 2)}`
|
|
324
|
+
}
|
|
325
|
+
// 构造12小时制时间字符串
|
|
326
|
+
const suffix = (hours >= 12) ? I18n.getLang('manage_user_calendar_label_pm') : I18n.getLang('manage_user_calendar_label_am');
|
|
327
|
+
// 检查小时数是否大于12,并调整
|
|
328
|
+
if (hours > 12) {
|
|
329
|
+
hours -= 12;
|
|
330
|
+
}
|
|
331
|
+
hours = (hours == 0) ? 12 : hours; // 处理午夜0点为12小时制的12点
|
|
332
|
+
const time12Hour = suffix + ' ' + hours + ':' + (mins < 10 ? '0' : '') + mins;
|
|
333
|
+
|
|
334
|
+
return time12Hour;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
export function getGlobalParamsDp(key: string) {
|
|
338
|
+
return GlobalParams.dpSchemaMap[key] && GlobalParams.dpSchemaMap[key].dp.toString()
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
export function isSupportFunctions(...keys: string[]) {
|
|
342
|
+
return keys.every(key => key in GlobalParams.dpSchemaMap)
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// 判断时间毫秒数在这一天中多少分钟
|
|
346
|
+
export function getMinutesOfTheDay(milliseconds: number) {
|
|
347
|
+
// 将给定的毫秒数转换为 Date 对象
|
|
348
|
+
const date = new Date(milliseconds);
|
|
349
|
+
|
|
350
|
+
// 获取该日期的起始时间(午夜 00:00:00)的时间戳(毫秒)
|
|
351
|
+
const startOfDay = new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime();
|
|
352
|
+
|
|
353
|
+
// 计算给定毫秒数与当天起始时间的差值(毫秒)
|
|
354
|
+
const differenceMillis = milliseconds - startOfDay;
|
|
355
|
+
|
|
356
|
+
// 将差值转换为分钟数
|
|
357
|
+
const minutes = Math.floor(differenceMillis / 60000);
|
|
358
|
+
|
|
359
|
+
return minutes;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
export function getIsClosed(item: {weeks: number[], settingTime: number, endTime: number}){
|
|
363
|
+
const isOnce = item?.weeks?.every(w => w === 0)
|
|
364
|
+
let undone = true
|
|
365
|
+
if(isOnce && item.settingTime){
|
|
366
|
+
const setting = new Date(item.settingTime).toDateString()
|
|
367
|
+
const settingMin = getMinutesOfTheDay(item.settingTime)
|
|
368
|
+
const current = new Date().toDateString()
|
|
369
|
+
const currentMin = getMinutesOfTheDay(new Date().getTime())
|
|
370
|
+
if(setting !== current){
|
|
371
|
+
undone = false
|
|
372
|
+
}else{
|
|
373
|
+
if(settingMin < item.endTime && currentMin > item.endTime){
|
|
374
|
+
undone = false
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
return undone
|
|
379
|
+
}
|