@ledvance/ui-biz-bundle 1.1.70 → 1.1.71
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 +1 -1
- package/src/newModules/mood/AddMoodPage.tsx +194 -194
- package/src/newModules/mood/DynamicMoodEditorPage.tsx +650 -650
- package/src/newModules/mood/Interface.ts +225 -220
- package/src/newModules/mood/MixDynamicMoodEditor.tsx +789 -786
- package/src/newModules/mood/MoodActions.ts +244 -232
- package/src/newModules/mood/MoodInfo.ts +2151 -2151
- package/src/newModules/mood/MoodItem.tsx +160 -160
- package/src/newModules/mood/MoodPage.tsx +402 -386
- package/src/newModules/mood/MoodParse.ts +442 -443
- package/src/newModules/mood/RecommendMoodItem.tsx +81 -81
- package/src/newModules/mood/Router.ts +52 -43
- package/src/newModules/mood/StaticMoodEditorPage.tsx +290 -290
|
@@ -1,232 +1,244 @@
|
|
|
1
|
-
import { NativeApi, getFeature, putFeature } from '@ledvance/base/src/api/native';
|
|
2
|
-
import {
|
|
3
|
-
DefMoodOption,
|
|
4
|
-
LightCategory,
|
|
5
|
-
MixRemoteMoodInfo,
|
|
6
|
-
MoodInfo,
|
|
7
|
-
MoodPageParams,
|
|
8
|
-
MoodUIInfo,
|
|
9
|
-
RemoteMoodInfo,
|
|
10
|
-
} from './Interface';
|
|
11
|
-
import { parseJSON } from '@tuya/tuya-panel-lamp-sdk/lib/utils';
|
|
12
|
-
import { getDefMoodList } from './MoodInfo';
|
|
13
|
-
import {
|
|
14
|
-
MixCeilingDpObj,
|
|
15
|
-
MixDp2Obj,
|
|
16
|
-
MixObj2Dp,
|
|
17
|
-
dp2Obj,
|
|
18
|
-
obj2Dp,
|
|
19
|
-
stripDp2Obj,
|
|
20
|
-
stripObj2Dp,
|
|
21
|
-
} from './MoodParse';
|
|
22
|
-
import { useDp, useDps } from '@ledvance/base/src/models/modules/NativePropsSlice';
|
|
23
|
-
import { useState } from 'react';
|
|
24
|
-
import { useUpdateEffect } from 'ahooks';
|
|
25
|
-
import { WorkMode } from '@ledvance/base/src/utils/interface';
|
|
26
|
-
import { Result } from '@ledvance/base/src/models/modules/Result';
|
|
27
|
-
|
|
28
|
-
const SceneFeatureId = 'SimplifyScene';
|
|
29
|
-
const MixLightSceneListFeatureId = 'MixLightSceneList';
|
|
30
|
-
|
|
31
|
-
export const useWorkMode = (dp: string): [WorkMode, (value: WorkMode) => Promise<Result<any>>] => {
|
|
32
|
-
return useDp(dp);
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if (!res.
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
success:
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}
|
|
173
|
-
if (
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
:
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
1
|
+
import { NativeApi, getFeature, putFeature } from '@ledvance/base/src/api/native';
|
|
2
|
+
import {
|
|
3
|
+
DefMoodOption,
|
|
4
|
+
LightCategory,
|
|
5
|
+
MixRemoteMoodInfo,
|
|
6
|
+
MoodInfo,
|
|
7
|
+
MoodPageParams,
|
|
8
|
+
MoodUIInfo,
|
|
9
|
+
RemoteMoodInfo,
|
|
10
|
+
} from './Interface';
|
|
11
|
+
import { parseJSON } from '@tuya/tuya-panel-lamp-sdk/lib/utils';
|
|
12
|
+
import { getDefMoodList } from './MoodInfo';
|
|
13
|
+
import {
|
|
14
|
+
MixCeilingDpObj,
|
|
15
|
+
MixDp2Obj,
|
|
16
|
+
MixObj2Dp,
|
|
17
|
+
dp2Obj,
|
|
18
|
+
obj2Dp,
|
|
19
|
+
stripDp2Obj,
|
|
20
|
+
stripObj2Dp,
|
|
21
|
+
} from './MoodParse';
|
|
22
|
+
import { useDp, useDps } from '@ledvance/base/src/models/modules/NativePropsSlice';
|
|
23
|
+
import { useState } from 'react';
|
|
24
|
+
import { useUpdateEffect } from 'ahooks';
|
|
25
|
+
import { WorkMode } from '@ledvance/base/src/utils/interface';
|
|
26
|
+
import { Result } from '@ledvance/base/src/models/modules/Result';
|
|
27
|
+
|
|
28
|
+
const SceneFeatureId = 'SimplifyScene';
|
|
29
|
+
const MixLightSceneListFeatureId = 'MixLightSceneList';
|
|
30
|
+
|
|
31
|
+
export const useWorkMode = (dp: string): [WorkMode, (value: WorkMode) => Promise<Result<any>>] => {
|
|
32
|
+
return useDp(dp);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const useSwitchLed = (dp: string): [boolean, (value: boolean) => Promise<Result<any>>] => {
|
|
36
|
+
return useDp(dp);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const setRemoteMoodList = async (
|
|
40
|
+
devId: string,
|
|
41
|
+
isFeature: boolean,
|
|
42
|
+
remoteSceneList: RemoteMoodInfo[] | MixRemoteMoodInfo[],
|
|
43
|
+
featureId: string
|
|
44
|
+
) => {
|
|
45
|
+
if (isFeature) {
|
|
46
|
+
const res = await putFeature(devId, featureId, remoteSceneList);
|
|
47
|
+
return {
|
|
48
|
+
success: res.result,
|
|
49
|
+
msg: res.msg,
|
|
50
|
+
data: res.data,
|
|
51
|
+
};
|
|
52
|
+
} else {
|
|
53
|
+
const res = await NativeApi.putJson(devId, featureId, JSON.stringify(remoteSceneList));
|
|
54
|
+
return res;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const getMoodInfo = (mainDp: string, option: LightCategory, secondaryDp: string) => {
|
|
59
|
+
const moodInfo = !!(option.isStringLight || option.isStripLight)
|
|
60
|
+
? stripDp2Obj(mainDp, option.isStringLight)
|
|
61
|
+
: option.isMixLight
|
|
62
|
+
? MixDp2Obj(mainDp)
|
|
63
|
+
: option.isCeilingLight
|
|
64
|
+
? MixCeilingDpObj(mainDp, secondaryDp)
|
|
65
|
+
: dp2Obj(mainDp, option.isFanLight, option.isUVCFan);
|
|
66
|
+
return moodInfo;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const getMoodDp = (moodInfo: MoodUIInfo, option: LightCategory) => {
|
|
70
|
+
const moodDp = !!(option.isStringLight || option.isStripLight)
|
|
71
|
+
? stripObj2Dp(moodInfo, option.isStringLight)
|
|
72
|
+
: option.isMixLight
|
|
73
|
+
? MixObj2Dp(moodInfo)
|
|
74
|
+
: obj2Dp(moodInfo, option.isFanLight, option.isUVCFan);
|
|
75
|
+
return moodDp;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const remoteMoodInfo2MoodUIState = (
|
|
79
|
+
remoteMoodInfo,
|
|
80
|
+
_: number,
|
|
81
|
+
option: DefMoodOption
|
|
82
|
+
): MoodUIInfo => {
|
|
83
|
+
const moodInfo = option.isMixLight
|
|
84
|
+
? MixDp2Obj(remoteMoodInfo.value)
|
|
85
|
+
: getMoodInfo(remoteMoodInfo.i, option, remoteMoodInfo.s);
|
|
86
|
+
return {
|
|
87
|
+
name: option.isMixLight ? remoteMoodInfo.name : remoteMoodInfo.n,
|
|
88
|
+
image: '',
|
|
89
|
+
...moodInfo,
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export const getRemoteMoodList = async (
|
|
94
|
+
devId: string,
|
|
95
|
+
option: DefMoodOption,
|
|
96
|
+
featureId = SceneFeatureId
|
|
97
|
+
) => {
|
|
98
|
+
const isFeature = !(option.isCeilingLight || option.isStringLight || option.isStripLight);
|
|
99
|
+
if (isFeature) {
|
|
100
|
+
const moodFeatureId = option.isMixLight ? MixLightSceneListFeatureId : SceneFeatureId;
|
|
101
|
+
// await setRemoteMoodList(devId, isFeature, getDefMoodList(option), moodFeatureId);
|
|
102
|
+
const res = await getFeature(devId, moodFeatureId);
|
|
103
|
+
if (!res.result) {
|
|
104
|
+
return { success: false };
|
|
105
|
+
}
|
|
106
|
+
if (!res.data) {
|
|
107
|
+
const result = await setRemoteMoodList(
|
|
108
|
+
devId,
|
|
109
|
+
isFeature,
|
|
110
|
+
getDefMoodList(option),
|
|
111
|
+
moodFeatureId
|
|
112
|
+
);
|
|
113
|
+
if (!result.success) {
|
|
114
|
+
return { success: false };
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
success: true,
|
|
118
|
+
data: result.data.map((item, index) => remoteMoodInfo2MoodUIState(item, index, option)),
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
success: true,
|
|
123
|
+
data: res.data.map((item, index) => remoteMoodInfo2MoodUIState(item, index, option)),
|
|
124
|
+
};
|
|
125
|
+
} else {
|
|
126
|
+
const moodFeatureId = option.isCeilingLight ? SceneFeatureId : featureId;
|
|
127
|
+
// const defaultScene = getDefMoodList(option);
|
|
128
|
+
// await setRemoteMoodList(devId, isFeature, defaultScene, moodFeatureId);
|
|
129
|
+
const res = await NativeApi.getJson(devId, moodFeatureId);
|
|
130
|
+
const isNormalData = Array.isArray(parseJSON(res?.data));
|
|
131
|
+
if (res.success && isNormalData) {
|
|
132
|
+
return {
|
|
133
|
+
success: true,
|
|
134
|
+
data:
|
|
135
|
+
res.data &&
|
|
136
|
+
parseJSON(res.data).map((item, index) => remoteMoodInfo2MoodUIState(item, index, option)),
|
|
137
|
+
};
|
|
138
|
+
} else {
|
|
139
|
+
if (res.msg?.includes('资源未找到') || !isNormalData) {
|
|
140
|
+
const defaultScene = getDefMoodList(option);
|
|
141
|
+
const res = await setRemoteMoodList(devId, isFeature, defaultScene, moodFeatureId);
|
|
142
|
+
if (res.success) {
|
|
143
|
+
return {
|
|
144
|
+
success: true,
|
|
145
|
+
data: defaultScene.map((item, index) =>
|
|
146
|
+
remoteMoodInfo2MoodUIState(item, index, option)
|
|
147
|
+
),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
return { success: false };
|
|
151
|
+
}
|
|
152
|
+
return { success: false };
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
export const useMoodScene = (params: MoodPageParams): [MoodInfo, (moodInfo: MoodUIInfo) => Promise<Result<any>>] => {
|
|
158
|
+
const [dps, setDps] = useDps();
|
|
159
|
+
const main = dps[params.mainDp];
|
|
160
|
+
const secondaryWorkMode = params.secondaryWorkMode ? dps[params.secondaryWorkMode] : ''
|
|
161
|
+
const secondary = params.secondaryDp && secondaryWorkMode === WorkMode.Scene ? dps[params.secondaryDp] : '';
|
|
162
|
+
const [moodState, setMoodState] = useState(getMoodInfo(main, params, secondary));
|
|
163
|
+
|
|
164
|
+
useUpdateEffect(() => {
|
|
165
|
+
setMoodState(getMoodInfo(main, params, secondary));
|
|
166
|
+
}, [main, secondary]);
|
|
167
|
+
|
|
168
|
+
const setMoodFn = (moodInfo: MoodUIInfo) => {
|
|
169
|
+
const mainDps = {}
|
|
170
|
+
const secondaryDps = {}
|
|
171
|
+
if (moodInfo) {
|
|
172
|
+
const { mainLamp, secondaryLamp } = moodInfo
|
|
173
|
+
if (mainLamp?.nodes?.length) {
|
|
174
|
+
const mainHex = getMoodDp(params.isCeilingLight ? {...moodInfo, id: mainLamp.id!} : moodInfo, params);
|
|
175
|
+
mainDps[params.mainDp] = mainHex
|
|
176
|
+
mainDps[params.mainWorkMode] = WorkMode.Scene;
|
|
177
|
+
mainDps[params.mainSwitch] = true;
|
|
178
|
+
}
|
|
179
|
+
if (params.isCeilingLight && params.secondaryDp) {
|
|
180
|
+
if (secondaryLamp.nodes?.length){
|
|
181
|
+
const secondaryHex = stripObj2Dp({
|
|
182
|
+
...moodInfo,
|
|
183
|
+
mainLamp: secondaryLamp,
|
|
184
|
+
id: secondaryLamp.id!,
|
|
185
|
+
version: 1
|
|
186
|
+
});
|
|
187
|
+
console.log(secondaryHex, secondaryLamp, 'hexxxxx')
|
|
188
|
+
secondaryDps[params.secondaryDp] = secondaryHex
|
|
189
|
+
secondaryDps[params.secondaryWorkMode!] = WorkMode.Scene
|
|
190
|
+
secondaryDps[params.secondarySwitch!] = true
|
|
191
|
+
}else{
|
|
192
|
+
secondaryDps[params.secondaryWorkMode!] = WorkMode.Colour
|
|
193
|
+
}
|
|
194
|
+
setDps(secondaryDps).then()
|
|
195
|
+
}
|
|
196
|
+
mainLamp[params.switchLedDp] = true
|
|
197
|
+
}
|
|
198
|
+
return setDps(mainDps)
|
|
199
|
+
};
|
|
200
|
+
return [moodState, setMoodFn];
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
export const saveMoodList = (
|
|
204
|
+
devId: string,
|
|
205
|
+
moodList: MoodUIInfo[],
|
|
206
|
+
option: LightCategory,
|
|
207
|
+
featureId = SceneFeatureId
|
|
208
|
+
) => {
|
|
209
|
+
const remoteMoods: any = moodList.map(s => {
|
|
210
|
+
if (option.isMixLight) {
|
|
211
|
+
return {
|
|
212
|
+
name: s.name,
|
|
213
|
+
image: '',
|
|
214
|
+
value: MixObj2Dp(s),
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
return {
|
|
218
|
+
n: s.name,
|
|
219
|
+
i: getMoodDp(option.isCeilingLight ? { ...s, id: s.mainLamp.id! } : s, option),
|
|
220
|
+
s: s.secondaryLamp?.nodes?.length && option.isCeilingLight
|
|
221
|
+
? stripObj2Dp({
|
|
222
|
+
...s,
|
|
223
|
+
mainLamp: s.secondaryLamp,
|
|
224
|
+
id: s.secondaryLamp.id!
|
|
225
|
+
})
|
|
226
|
+
: '',
|
|
227
|
+
t: 0,
|
|
228
|
+
e: false,
|
|
229
|
+
};
|
|
230
|
+
});
|
|
231
|
+
const isFeature = !(
|
|
232
|
+
option.isCeilingLight ||
|
|
233
|
+
option.isStringLight ||
|
|
234
|
+
option.isStripLight ||
|
|
235
|
+
option.isMatterLight ||
|
|
236
|
+
option.isUVCFan
|
|
237
|
+
);
|
|
238
|
+
const moodFeatureId = !!(option.isStringLight || option.isStripLight)
|
|
239
|
+
? featureId
|
|
240
|
+
: option.isMixLight
|
|
241
|
+
? MixLightSceneListFeatureId
|
|
242
|
+
: SceneFeatureId;
|
|
243
|
+
return setRemoteMoodList(devId, isFeature, remoteMoods, moodFeatureId);
|
|
244
|
+
};
|