@ledvance/ui-biz-bundle 1.1.152 → 1.1.153

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 CHANGED
@@ -4,7 +4,7 @@
4
4
  "name": "@ledvance/ui-biz-bundle",
5
5
  "pid": [],
6
6
  "uiid": "",
7
- "version": "1.1.152",
7
+ "version": "1.1.153",
8
8
  "scripts": {},
9
9
  "dependencies": {
10
10
  "@ledvance/base": "^1.x",
@@ -1,13 +1,15 @@
1
1
  import { useNavigation, useRoute } from '@react-navigation/native'
2
- import React, { useEffect, useState } from 'react'
3
- import { Image, ScrollView, Text, TouchableOpacity, View } from 'react-native'
2
+ import React, { useCallback, useEffect, useMemo, useState } from 'react'
3
+ // 导入 Dimensions API 来获取屏幕宽度
4
+ import { Dimensions, Image, ScrollView, StyleSheet, Text, TouchableOpacity, View } from 'react-native'
4
5
  import { Utils } from 'tuya-panel-kit'
5
6
  import iconList from '../biorhythm/iconListData'
6
7
  import LDVTopBar from '@ledvance/base/src/components/ldvTopBar'
7
8
  import I18n from '@ledvance/base/src/i18n'
8
9
  import ThemeType from '@ledvance/base/src/config/themeType'
10
+ import { xLog } from '@ledvance/base/src/utils'
9
11
 
10
- const cx = Utils.RatioUtils.convertX
12
+ const { convertX: cx } = Utils.RatioUtils
11
13
  const { withTheme } = Utils.ThemeUtils
12
14
 
13
15
  interface SceneDetailPageParams {
@@ -17,6 +19,13 @@ interface SceneDetailPageParams {
17
19
  iconIdList: any
18
20
  }
19
21
 
22
+ // --- 新增:定义常量,方便维护 ---
23
+ const ICON_WIDTH = cx(32)
24
+ const ICON_MARGIN = cx(10)
25
+ const CONTAINER_HORIZONTAL_PADDING = cx(24)
26
+ // 每个图标占据的总宽度(图片宽度 + 左右margin)
27
+ const ITEM_TOTAL_WIDTH = ICON_WIDTH + ICON_MARGIN * 2
28
+
20
29
  function IconSelect(props: { theme?: ThemeType }) {
21
30
  const [list, setList] = useState(iconList)
22
31
  const navigation = useNavigation()
@@ -27,7 +36,7 @@ function IconSelect(props: { theme?: ThemeType }) {
27
36
  ...item,
28
37
  selectStatus: item?.id === id,
29
38
  }
30
- })
39
+ }) as typeof list
31
40
  setList(newList)
32
41
  }
33
42
  useEffect(() => {
@@ -39,26 +48,74 @@ function IconSelect(props: { theme?: ThemeType }) {
39
48
  selectStatus: item?.id === iconId,
40
49
  disabled: iconIdList?.some(val => val === item?.id && val !== iconId),
41
50
  }
42
- })
51
+ }) as typeof list
43
52
  setList(newList)
44
53
  }, [])
45
- useEffect(() =>{
46
- console.log(list, '< --- listttt')
47
- }, [list])
54
+
55
+ const getStyles = useCallback((theme?: ThemeType) => StyleSheet.create({
56
+ container: { flex: 1, flexDirection: 'column' },
57
+ scrollView: { marginHorizontal: CONTAINER_HORIZONTAL_PADDING },
58
+ titleView: { marginTop: cx(40), marginBottom: cx(20) },
59
+ title: { fontSize: cx(24), color: theme?.global.brand },
60
+ iconContainer: {
61
+ flexDirection: 'row',
62
+ flex: 1,
63
+ flexWrap: 'wrap',
64
+ justifyContent: 'space-between',
65
+ alignItems: 'center'
66
+ },
67
+ ghostItem: {
68
+ width: ICON_WIDTH,
69
+ height: 0,
70
+ margin: ICON_MARGIN,
71
+ }
72
+ }), [CONTAINER_HORIZONTAL_PADDING, ICON_WIDTH, ICON_MARGIN])
73
+
74
+ const styles = useMemo(() => getStyles(props.theme), [props.theme])
75
+
76
+ // --- 新增:动态计算需要渲染的幽灵元素数量 ---
77
+ const ghostElements = useMemo(() => {
78
+
79
+ // 1. 获取容器的可用宽度
80
+ const containerWidth = cx(Dimensions.get('window').width) - CONTAINER_HORIZONTAL_PADDING * 2
81
+
82
+ // 2. 计算每行可以容纳多少个元素
83
+ const itemsPerRow = Math.ceil(containerWidth / ITEM_TOTAL_WIDTH)
84
+ // 如果无法容纳任何元素,则不渲染幽灵元素
85
+ if (itemsPerRow <= 0) {
86
+ xLog('No ghost elements needed.')
87
+ return null
88
+ }
89
+
90
+ // 3. 计算需要补充的幽灵元素数量
91
+ const numberOfItems = list.length
92
+ const itemsInLastRow = numberOfItems % itemsPerRow
93
+
94
+ // 如果最后一行为空或已满,则不需要幽灵元素
95
+ if (itemsInLastRow === 0) {
96
+ return null
97
+ }
98
+
99
+ const numberOfGhosts = itemsPerRow - itemsInLastRow
100
+
101
+ // 4. 返回一个包含正确数量幽灵元素的数组
102
+ return Array.from({ length: numberOfGhosts }).map((_, index) => (
103
+ <View key={`ghost-${index}`} style={styles.ghostItem}/>
104
+ ))
105
+ }, [list.length]) // 依赖项:当图标总数变化时重新计算
106
+
48
107
  return (
49
- <View style={{ flex: 1, flexDirection: 'column' }}>
108
+ <View style={styles.container}>
50
109
  <LDVTopBar
51
110
  title={params.backText ?? I18n.getLang('add_new_trigger_time_system_back_text')}
52
- onBackPress={() => {
53
- navigation.goBack()
54
- }}
111
+ onBackPress={() => navigation.goBack()}
55
112
  />
56
- <ScrollView nestedScrollEnabled={true} style={{ marginHorizontal: cx(24) }}>
57
- <View style={{ marginTop: cx(40), marginBottom: cx(20) }}>
58
- <Text style={{ fontSize: cx(24), color: props.theme?.global.brand }}>{I18n.getLang('add_new_trigger_time_icon_selection_headline_text')}</Text>
113
+ <ScrollView nestedScrollEnabled={true} style={styles.scrollView}>
114
+ <View style={styles.titleView}>
115
+ <Text style={styles.title}>{I18n.getLang('add_new_trigger_time_icon_selection_headline_text')}</Text>
59
116
  </View>
60
- <View
61
- style={{ flexDirection: 'row', flex: 1, flexWrap: 'wrap', justifyContent: 'space-between', alignItems: 'flex-start' }}>
117
+ <View style={styles.iconContainer}>
118
+ {/* 渲染真实的图标 */}
62
119
  {list?.map(item => {
63
120
  return <TouchableOpacity
64
121
  onPress={() => {
@@ -71,14 +128,17 @@ function IconSelect(props: { theme?: ThemeType }) {
71
128
  <Image
72
129
  source={{ uri: item?.icon }}
73
130
  style={{
74
- width: cx(32),
75
- height: cx(32),
76
- margin: cx(10),
131
+ width: ICON_WIDTH,
132
+ height: cx(32), // 高度保持不变
133
+ margin: ICON_MARGIN,
77
134
  tintColor: item?.selectStatus ? props.theme?.icon.primary : item?.disabled && props.theme?.icon.disable || props.theme?.icon.normal,
78
135
  }}
79
136
  />
80
137
  </TouchableOpacity>
81
138
  })}
139
+
140
+ {/* 渲染精确计算出的幽灵元素 */}
141
+ {ghostElements}
82
142
  </View>
83
143
  </ScrollView>
84
144
  </View>
@@ -61,13 +61,8 @@ export async function getElectricity(devId: string, addEleDpCode: string, date:
61
61
  return res
62
62
  }
63
63
 
64
- let dpResultByMonthCache: DpResultByMonthResData | undefined = undefined
65
64
  const getDpResultByYear = async (devId: string, addEleDpCode: string, dateStr: string): Promise<OverviewItem[]> => {
66
- let res: DpResultByMonthResData | undefined
67
- if (!dpResultByMonthCache) {
68
- dpResultByMonthCache = await getDpResultByMonth(devId, addEleDpCode, 'sum')
69
- }
70
- res = dpResultByMonthCache
65
+ const res = await getDpResultByMonth(devId, addEleDpCode, 'sum')
71
66
  if (!isEmpty(res)) {
72
67
  if (!isEmpty(res.years)) {
73
68
  const year = dateStr
@@ -75,7 +70,7 @@ const getDpResultByYear = async (devId: string, addEleDpCode: string, dateStr: s
75
70
  if (!curMonth) {
76
71
  return []
77
72
  }
78
- const curMonthList = Object.keys(curMonth).sort((a, b) => parseInt(b) - parseInt(a))
73
+ const curMonthList = Object.keys(curMonth).sort((a, b) => parseInt(a) - parseInt(b))
79
74
  return curMonthList.map(month => {
80
75
  return {
81
76
  key: `${monthFormat(month)} ${year}`,
@@ -3,7 +3,6 @@ import res from '@ledvance/base/src/res'
3
3
  import React, { useCallback } from 'react'
4
4
  import { Image, TouchableOpacity, View } from 'react-native'
5
5
  import { Utils } from 'tuya-panel-kit'
6
- import DateSelectedItem from '../component/DateSelectedItem'
7
6
  import DateSwitch from '../component/DateSwitch'
8
7
  import { DateType } from '../co2Data'
9
8
  import DateTypeItem from '../component/DateTypeItem'
@@ -33,30 +32,13 @@ export const EnergyChartSection = ({ isLandscape, state, actions, params, styles
33
32
 
34
33
  return (
35
34
  <>
36
- {!isLandscape && (
37
- <View style={styles.dateSwitchContainer}>
38
- <DateSwitch
39
- style={{ flex: 1 }}
40
- date={state.date}
41
- dateType={state.dateType}
42
- headlineText={state.headlineText}
43
- onDateChange={actions.setDate}
44
- />
45
- <TouchableOpacity style={{ width: cx(30) }} onPress={handleExportCsv}>
46
- <Image
47
- style={styles.downloadIcon}
48
- source={{ uri: !isDataEmpty ? res.download_icon : undefined }}
49
- />
50
- </TouchableOpacity>
51
- </View>
52
- )}
53
35
  <View style={styles.dateTypeContainer}>
54
36
  <DateTypeItem
55
- style={{ flex: 1, marginHorizontal: cx(5) }}
37
+ style={{ flex: 0.5 }}
56
38
  dateType={state.dateType}
57
39
  onDateTypeChange={actions.setDateType}
58
40
  />
59
- <DateSelectedItem
41
+ <DateSwitch
60
42
  style={{ flex: 1 }}
61
43
  dateType={state.dateType}
62
44
  date={state.date}
@@ -67,8 +49,18 @@ export const EnergyChartSection = ({ isLandscape, state, actions, params, styles
67
49
  {(state.loading || isDataEmpty) ? (
68
50
  <EmptyDataView text={getEmptyDataTip()} theme={theme} styles={styles}/>
69
51
  ) : (
70
- !state.loading &&
71
- <NewBarChart height={chartHeight} data={state.chartData} price={state.price} unit={params.unit}/>
52
+ !state.loading && <>
53
+ {!isLandscape && <View style={styles.downloadContainer}>
54
+ <TouchableOpacity
55
+ style={{ width: cx(30) }}
56
+ onPress={handleExportCsv}>
57
+ <Image
58
+ style={styles.downloadIcon}
59
+ source={{ uri: res.download_icon }}/>
60
+ </TouchableOpacity>
61
+ </View>}
62
+ <NewBarChart height={chartHeight} data={state.chartData} price={state.price} unit={params.unit}/>
63
+ </>
72
64
  )}
73
65
  </>
74
66
  )
@@ -16,13 +16,17 @@ export const getStyles = (theme: ThemeType | undefined) => StyleSheet.create({
16
16
  listEmptyText: {
17
17
  flex: 0,
18
18
  },
19
+ downloadContainer: {
20
+ flexDirection: 'row',
21
+ justifyContent: 'flex-end',
22
+ // marginHorizontal: cx(24),
23
+ marginTop: cx(15),
24
+ marginBottom: cx(-15)
25
+ },
19
26
  downloadIcon: {
20
27
  width: cx(24),
21
28
  height: cx(24),
22
29
  tintColor: theme?.global.brand,
23
- position: 'absolute',
24
- right: 0,
25
- top: cx(10),
26
30
  },
27
31
  intervalContainer: {
28
32
  flexDirection: 'row',
@@ -79,7 +83,8 @@ export const getStyles = (theme: ThemeType | undefined) => StyleSheet.create({
79
83
  },
80
84
  dateTypeContainer: {
81
85
  flexDirection: 'row',
82
- marginBottom: cx(15),
86
+ marginTop: cx(15),
87
+ // marginBottom: cx(15),
83
88
  },
84
89
  scrollViewContent: {
85
90
  marginHorizontal: cx(24),
@@ -9,9 +9,11 @@ import { useCallback, useEffect } from 'react'
9
9
  import { ChartType, DateType } from '../co2Data'
10
10
  import { getElectricity, getPowerData, PowerDataItem } from '../EnergyConsumptionActions'
11
11
  import { EnergyConsumptionChartProps } from '../EnergyConsumptionChart'
12
+ import {useIsPad} from "@ledvance/base/src/models/modules/NativePropsSlice"
12
13
 
13
14
  export const useEnergyData = (params: EnergyConsumptionChartProps, devId: string) => {
14
15
  const isFocused = useIsFocused()
16
+ const isPad = useIsPad()
15
17
  const { addEleDpCode, powerDpCode, price, unit, date, over365Days, over7Days, chartData } = params
16
18
 
17
19
  const getDateType = useCallback((d: string) => {
@@ -26,7 +28,7 @@ export const useEnergyData = (params: EnergyConsumptionChartProps, devId: string
26
28
 
27
29
  const state = useReactive({
28
30
  loading: false,
29
- isSupportLandscape: OrientationService.isSupported(),
31
+ isSupportLandscape: OrientationService.isSupported() && !isPad,
30
32
  isLandscape: false,
31
33
  chartType: ChartType.kWh as ChartType,
32
34
  dateType: getDateType(date),
@@ -1,6 +1,7 @@
1
1
  import ThemeType from "@ledvance/base/src/config/themeType";
2
+ import DateSelectedItem from './DateSelectedItem'
2
3
  import React, {PropsWithChildren, useCallback, useEffect} from "react";
3
- import {Image, Text, TouchableOpacity, View, ViewProps} from "react-native";
4
+ import {Image, TouchableOpacity, View, ViewProps} from "react-native";
4
5
  import {Utils} from "tuya-panel-kit";
5
6
  import {useReactive} from "ahooks";
6
7
  import {DateType} from "../co2Data";
@@ -79,33 +80,34 @@ export default withTheme(function DateSwitch(props: DateSwitchProps) {
79
80
 
80
81
  return (<View style={[props.style, {flexDirection: 'row', alignItems: 'center', justifyContent: 'center'}]}>
81
82
  <TouchableOpacity
82
- disabled={state.disableArrowLeft}
83
- onPress={() => {
84
- changeDate(false);
85
- }}>
83
+ disabled={state.disableArrowLeft}
84
+ onPress={() => {
85
+ changeDate(false);
86
+ }}>
86
87
  <Image
87
- source={{ uri: res.arrow_left}}
88
- style={{tintColor: state.disableArrowLeft ? theme?.global.disabledFontColor : theme?.global.brand}}
89
- height={cx(36)}
90
- width={cx(36)}/>
88
+ source={{ uri: res.arrow_left}}
89
+ style={{tintColor: state.disableArrowLeft ? theme?.global.disabledFontColor : theme?.global.brand}}
90
+ height={cx(36)}
91
+ width={cx(36)}/>
91
92
  </TouchableOpacity>
92
- <Text style={{
93
- fontSize: cx(24),
94
- minWidth: cx(200),
95
- textAlign: 'center',
96
- color: theme?.global.brand,
97
- // fontFamily: 'helvetica_neue_lt_std_roman',
98
- }}>{state.headlineText}</Text>
93
+ <DateSelectedItem
94
+ style={{flex: 1}}
95
+ dateType={state.dateType}
96
+ date={state.date}
97
+ onDateChange={date => {
98
+ props.onDateChange(date)
99
+ }}
100
+ />
99
101
  <TouchableOpacity
100
- disabled={state.disableArrowRight}
101
- onPress={() => {
102
- changeDate(true);
103
- }}>
102
+ disabled={state.disableArrowRight}
103
+ onPress={() => {
104
+ changeDate(true);
105
+ }}>
104
106
  <Image
105
- source={{ uri: res.arrow_right}}
106
- style={{tintColor: state.disableArrowRight ? theme?.global.disabledFontColor : theme?.global.brand}}
107
- height={cx(36)}
108
- width={cx(36)}/>
107
+ source={{ uri: res.arrow_right}}
108
+ style={{tintColor: state.disableArrowRight ? theme?.global.disabledFontColor : theme?.global.brand}}
109
+ height={cx(36)}
110
+ width={cx(36)}/>
109
111
  </TouchableOpacity>
110
112
  </View>)
111
113
  })
@@ -62,6 +62,7 @@ const BarChartWithTouch = (props: BarChartProps) => {
62
62
  legend: {
63
63
  show: true,
64
64
  data: ['kWh', unit],
65
+ top: '5%',
65
66
  textStyle: {
66
67
  color: theme?.global?.fontColor,
67
68
  }