@ray-js/t-agent-ui-ray 0.1.0-beta-2 → 0.1.0-beta-4
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/dist/ChatContainer/index.d.ts +1 -0
- package/dist/ChatContainer/index.js +4 -2
- package/dist/contexts.d.ts +1 -1
- package/dist/hooks/context.d.ts +1 -1
- package/dist/hooks/context.js +6 -1
- package/dist/hooks/useLongPress.js +13 -11
- package/dist/tiles/BubbleTile/index.js +2 -3
- package/dist/tiles/ExecuteCardTile/bookmark.png +0 -0
- package/dist/tiles/ExecuteCardTile/index.d.ts +10 -0
- package/dist/tiles/ExecuteCardTile/index.js +233 -0
- package/dist/tiles/ExecuteCardTile/index.less +154 -0
- package/dist/tiles/OperateCardTile/Expand.d.ts +17 -0
- package/dist/tiles/OperateCardTile/Expand.js +169 -0
- package/dist/tiles/OperateCardTile/Expand.less +135 -0
- package/dist/tiles/OperateCardTile/Tabs.d.ts +16 -0
- package/dist/tiles/OperateCardTile/Tabs.js +39 -0
- package/dist/tiles/OperateCardTile/Tabs.less +72 -0
- package/dist/tiles/OperateCardTile/index.d.ts +21 -0
- package/dist/tiles/OperateCardTile/index.js +228 -0
- package/dist/tiles/OperateCardTile/index.less +18 -0
- package/dist/tiles/OperateCardTile/lock.png +0 -0
- package/dist/tiles/map.js +5 -1
- package/dist/utils/formatMessage.d.ts +11 -0
- package/dist/utils/formatMessage.js +28 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +13 -0
- package/package.json +2 -2
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import "core-js/modules/esnext.iterator.constructor.js";
|
|
2
|
+
import "core-js/modules/esnext.iterator.map.js";
|
|
3
|
+
import { View, Text, Image } from '@ray-js/components';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { SceneType } from '@ray-js/t-agent-plugin-assistant';
|
|
6
|
+
import Tabs from './Tabs';
|
|
7
|
+
import './Expand.less';
|
|
8
|
+
import bookmark from '../ExecuteCardTile/bookmark.png';
|
|
9
|
+
import lockPng from './lock.png';
|
|
10
|
+
import { useRenderOptions } from '../../hooks';
|
|
11
|
+
import { formatMessage } from '../../utils';
|
|
12
|
+
export default function Expand(_ref) {
|
|
13
|
+
var _operations$device, _operations$moreDevic, _operations$scene, _operations$moreScene, _operations$more;
|
|
14
|
+
let {
|
|
15
|
+
operations = {
|
|
16
|
+
device: [],
|
|
17
|
+
scene: [],
|
|
18
|
+
moreDevice: [],
|
|
19
|
+
moreScene: [],
|
|
20
|
+
more: []
|
|
21
|
+
},
|
|
22
|
+
tapDevice,
|
|
23
|
+
tapScene
|
|
24
|
+
} = _ref;
|
|
25
|
+
const {
|
|
26
|
+
i18nTranslate: t
|
|
27
|
+
} = useRenderOptions();
|
|
28
|
+
const deviceCount = (((_operations$device = operations.device) === null || _operations$device === void 0 ? void 0 : _operations$device.length) || 0) + (((_operations$moreDevic = operations.moreDevice) === null || _operations$moreDevic === void 0 ? void 0 : _operations$moreDevic.length) || 0);
|
|
29
|
+
const sceneCount = (((_operations$scene = operations.scene) === null || _operations$scene === void 0 ? void 0 : _operations$scene.length) || 0) + (((_operations$moreScene = operations.moreScene) === null || _operations$moreScene === void 0 ? void 0 : _operations$moreScene.length) || 0);
|
|
30
|
+
const moreCount = ((_operations$more = operations.more) === null || _operations$more === void 0 ? void 0 : _operations$more.length) || 0;
|
|
31
|
+
const tabs = [];
|
|
32
|
+
if (deviceCount > 0) {
|
|
33
|
+
var _operations$device2, _operations$moreDevic2;
|
|
34
|
+
tabs.push({
|
|
35
|
+
key: 'device',
|
|
36
|
+
title: t('t-agent.expand.tab.device'),
|
|
37
|
+
badge: deviceCount,
|
|
38
|
+
content: /*#__PURE__*/React.createElement(View, {
|
|
39
|
+
className: "t-agent-expand-device-list"
|
|
40
|
+
}, (_operations$device2 = operations.device) === null || _operations$device2 === void 0 ? void 0 : _operations$device2.map(device => {
|
|
41
|
+
return /*#__PURE__*/React.createElement(View, {
|
|
42
|
+
key: device.deviceId,
|
|
43
|
+
className: "t-agent-expand-device-item",
|
|
44
|
+
onClick: () => tapDevice === null || tapDevice === void 0 ? void 0 : tapDevice({
|
|
45
|
+
currentTarget: {
|
|
46
|
+
dataset: {
|
|
47
|
+
id: device.deviceId
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
}, /*#__PURE__*/React.createElement(Image, {
|
|
52
|
+
src: device.icon,
|
|
53
|
+
className: "t-agent-expand-device-icon"
|
|
54
|
+
}), /*#__PURE__*/React.createElement(View, null, /*#__PURE__*/React.createElement(View, {
|
|
55
|
+
className: "t-agent-expand-device-info"
|
|
56
|
+
}, /*#__PURE__*/React.createElement(View, {
|
|
57
|
+
className: "t-agent-expand-device-name"
|
|
58
|
+
}, device.name), device.room && /*#__PURE__*/React.createElement(Text, {
|
|
59
|
+
className: "t-agent-expand-device-room"
|
|
60
|
+
}, "-", device.room)), /*#__PURE__*/React.createElement(Text, {
|
|
61
|
+
className: "t-agent-expand-device-status"
|
|
62
|
+
}, device.success ? t('t-agent.expand.execution.success') : t('t-agent.expand.execution.failed'))));
|
|
63
|
+
}), (_operations$moreDevic2 = operations.moreDevice) === null || _operations$moreDevic2 === void 0 ? void 0 : _operations$moreDevic2.map(device => /*#__PURE__*/React.createElement(View, {
|
|
64
|
+
key: device.id,
|
|
65
|
+
className: "t-agent-expand-device-item",
|
|
66
|
+
onClick: () => tapDevice === null || tapDevice === void 0 ? void 0 : tapDevice({
|
|
67
|
+
currentTarget: {
|
|
68
|
+
dataset: {
|
|
69
|
+
id: device.id
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
}, /*#__PURE__*/React.createElement(Image, {
|
|
74
|
+
src: bookmark,
|
|
75
|
+
className: "t-agent-expand-device-icon"
|
|
76
|
+
}), /*#__PURE__*/React.createElement(View, null, /*#__PURE__*/React.createElement(View, {
|
|
77
|
+
className: "t-agent-expand-device-info"
|
|
78
|
+
}, /*#__PURE__*/React.createElement(View, {
|
|
79
|
+
className: "t-agent-expand-device-name"
|
|
80
|
+
}, formatMessage(t, 't-agent.expand.device.rename', {
|
|
81
|
+
oldName: device.fromData,
|
|
82
|
+
newName: device.toData
|
|
83
|
+
}))), /*#__PURE__*/React.createElement(Text, {
|
|
84
|
+
className: "t-agent-expand-device-status"
|
|
85
|
+
}, device.success ? t('t-agent.expand.execution.success') : t('t-agent.expand.execution.failed'))))))
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
if (sceneCount > 0) {
|
|
89
|
+
var _operations$scene2, _operations$moreScene2;
|
|
90
|
+
tabs.push({
|
|
91
|
+
key: 'scene',
|
|
92
|
+
title: t('t-agent.expand.tab.scene'),
|
|
93
|
+
badge: sceneCount,
|
|
94
|
+
content: /*#__PURE__*/React.createElement(View, {
|
|
95
|
+
className: "t-agent-expand-scene-list"
|
|
96
|
+
}, (_operations$scene2 = operations.scene) === null || _operations$scene2 === void 0 ? void 0 : _operations$scene2.map(scene => {
|
|
97
|
+
const isExecuteScene = scene.type === SceneType.EXECUTE;
|
|
98
|
+
const icon = isExecuteScene ? lockPng : bookmark;
|
|
99
|
+
return /*#__PURE__*/React.createElement(View, {
|
|
100
|
+
key: scene.sceneId,
|
|
101
|
+
className: "t-agent-expand-scene-item",
|
|
102
|
+
onClick: () => tapScene === null || tapScene === void 0 ? void 0 : tapScene({
|
|
103
|
+
currentTarget: {
|
|
104
|
+
dataset: {
|
|
105
|
+
id: scene.sceneId
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
})
|
|
109
|
+
}, /*#__PURE__*/React.createElement(Image, {
|
|
110
|
+
src: scene.icon || icon,
|
|
111
|
+
className: "t-agent-expand-scene-icon"
|
|
112
|
+
}), /*#__PURE__*/React.createElement(View, null, /*#__PURE__*/React.createElement(View, {
|
|
113
|
+
className: "t-agent-expand-scene-name"
|
|
114
|
+
}, isExecuteScene ? t('t-agent.expand.scene.one-click') : t('t-agent.expand.scene.auto'), ' ', scene.name), /*#__PURE__*/React.createElement(Text, {
|
|
115
|
+
className: "t-agent-expand-scene-status"
|
|
116
|
+
}, scene.success ? t('t-agent.expand.execution.success') : t('t-agent.expand.execution.failed'))));
|
|
117
|
+
}), (_operations$moreScene2 = operations.moreScene) === null || _operations$moreScene2 === void 0 ? void 0 : _operations$moreScene2.map(scene => /*#__PURE__*/React.createElement(View, {
|
|
118
|
+
key: scene.id,
|
|
119
|
+
className: "t-agent-expand-scene-item",
|
|
120
|
+
onClick: () => tapScene === null || tapScene === void 0 ? void 0 : tapScene({
|
|
121
|
+
currentTarget: {
|
|
122
|
+
dataset: {
|
|
123
|
+
id: scene.id
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
})
|
|
127
|
+
}, /*#__PURE__*/React.createElement(Image, {
|
|
128
|
+
src: bookmark,
|
|
129
|
+
className: "t-agent-expand-scene-icon"
|
|
130
|
+
}), /*#__PURE__*/React.createElement(View, null, /*#__PURE__*/React.createElement(View, {
|
|
131
|
+
className: "t-agent-expand-scene-name"
|
|
132
|
+
}, formatMessage(t, 't-agent.expand.scene.rename', {
|
|
133
|
+
oldName: scene.fromData,
|
|
134
|
+
newName: scene.toData
|
|
135
|
+
})), /*#__PURE__*/React.createElement(Text, {
|
|
136
|
+
className: "t-agent-expand-scene-status"
|
|
137
|
+
}, scene.success ? t('t-agent.expand.execution.success') : t('t-agent.expand.execution.failed'))))))
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
if (moreCount > 0) {
|
|
141
|
+
var _operations$more2;
|
|
142
|
+
tabs.push({
|
|
143
|
+
key: 'more',
|
|
144
|
+
title: t('t-agent.expand.tab.more'),
|
|
145
|
+
badge: moreCount,
|
|
146
|
+
content: /*#__PURE__*/React.createElement(View, {
|
|
147
|
+
className: "t-agent-expand-more-list"
|
|
148
|
+
}, (_operations$more2 = operations.more) === null || _operations$more2 === void 0 ? void 0 : _operations$more2.map(item => /*#__PURE__*/React.createElement(View, {
|
|
149
|
+
key: item.id,
|
|
150
|
+
className: "t-agent-expand-more-item"
|
|
151
|
+
}, /*#__PURE__*/React.createElement(Image, {
|
|
152
|
+
src: bookmark,
|
|
153
|
+
className: "t-agent-expand-more-icon"
|
|
154
|
+
}), /*#__PURE__*/React.createElement(View, null, /*#__PURE__*/React.createElement(View, {
|
|
155
|
+
className: "t-agent-expand-more-name"
|
|
156
|
+
}, item.desc), /*#__PURE__*/React.createElement(Text, {
|
|
157
|
+
className: "t-agent-expand-more-status"
|
|
158
|
+
}, item.success ? t('t-agent.expand.execution.success') : t('t-agent.expand.execution.failed'))))))
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
return /*#__PURE__*/React.createElement(View, {
|
|
162
|
+
className: "t-agent-expand-container"
|
|
163
|
+
}, tabs.length > 0 ? /*#__PURE__*/React.createElement(Tabs, {
|
|
164
|
+
tabs: tabs,
|
|
165
|
+
defaultActiveKey: tabs[0].key
|
|
166
|
+
}) : /*#__PURE__*/React.createElement(View, {
|
|
167
|
+
className: "t-agent-expand-empty"
|
|
168
|
+
}, /*#__PURE__*/React.createElement(Text, null, t('t-agent.expand.no.details'))));
|
|
169
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
.t-agent-expand {
|
|
2
|
+
&-container {
|
|
3
|
+
padding: 16px;
|
|
4
|
+
background-color: #fff;
|
|
5
|
+
border-radius: 8px;
|
|
6
|
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
|
7
|
+
margin-top: 12px;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
&-empty {
|
|
11
|
+
display: flex;
|
|
12
|
+
justify-content: center;
|
|
13
|
+
align-items: center;
|
|
14
|
+
min-height: 100px;
|
|
15
|
+
color: #999;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
&-device {
|
|
19
|
+
&-list {
|
|
20
|
+
display: flex;
|
|
21
|
+
flex-direction: column;
|
|
22
|
+
gap: 12px;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
&-item {
|
|
26
|
+
display: flex;
|
|
27
|
+
align-items: center;
|
|
28
|
+
padding: 12px;
|
|
29
|
+
background-color: #f5f5f5;
|
|
30
|
+
border-radius: 6px;
|
|
31
|
+
|
|
32
|
+
&:active {
|
|
33
|
+
opacity: 0.8;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
&-icon {
|
|
38
|
+
width: 40px;
|
|
39
|
+
height: 40px;
|
|
40
|
+
border-radius: 12px;
|
|
41
|
+
margin-right: 5px;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
&-info {
|
|
45
|
+
display: flex;
|
|
46
|
+
align-items: center;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
&-name {
|
|
50
|
+
font-size: 14px;
|
|
51
|
+
font-weight: 500;
|
|
52
|
+
color: #333;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
&-room {
|
|
56
|
+
font-size: 12px;
|
|
57
|
+
color: #666;
|
|
58
|
+
margin-left: 4px;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
&-status {
|
|
62
|
+
font-size: 12px;
|
|
63
|
+
color: #0089ff;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
&-scene {
|
|
68
|
+
&-list {
|
|
69
|
+
display: flex;
|
|
70
|
+
flex-direction: column;
|
|
71
|
+
gap: 12px;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
&-item {
|
|
75
|
+
display: flex;
|
|
76
|
+
align-items: center;
|
|
77
|
+
padding: 12px;
|
|
78
|
+
background-color: #f5f5f5;
|
|
79
|
+
border-radius: 6px;
|
|
80
|
+
|
|
81
|
+
&:active {
|
|
82
|
+
opacity: 0.8;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
&-icon {
|
|
87
|
+
width: 40px;
|
|
88
|
+
height: 40px;
|
|
89
|
+
border-radius: 12px;
|
|
90
|
+
margin-right: 5px;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
&-name {
|
|
94
|
+
font-size: 14px;
|
|
95
|
+
font-weight: 500;
|
|
96
|
+
color: #333;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
&-status {
|
|
100
|
+
font-size: 12px;
|
|
101
|
+
color: #0089ff;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
&-more {
|
|
106
|
+
&-list {
|
|
107
|
+
display: flex;
|
|
108
|
+
flex-direction: column;
|
|
109
|
+
gap: 12px;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
&-item {
|
|
113
|
+
display: flex;
|
|
114
|
+
align-items: center;
|
|
115
|
+
padding: 12px;
|
|
116
|
+
background-color: #f5f5f5;
|
|
117
|
+
border-radius: 6px;
|
|
118
|
+
|
|
119
|
+
&:active {
|
|
120
|
+
opacity: 0.8;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
&-name {
|
|
125
|
+
font-size: 14px;
|
|
126
|
+
font-weight: 500;
|
|
127
|
+
color: #333;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
&-status {
|
|
131
|
+
font-size: 12px;
|
|
132
|
+
color: #0089ff;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import './Tabs.less';
|
|
3
|
+
export interface TabItem {
|
|
4
|
+
key: string;
|
|
5
|
+
title: string;
|
|
6
|
+
content: ReactNode;
|
|
7
|
+
badge?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface TabsProps {
|
|
10
|
+
tabs: TabItem[];
|
|
11
|
+
defaultActiveKey?: string;
|
|
12
|
+
onChange?: (key: string) => void;
|
|
13
|
+
className?: string;
|
|
14
|
+
}
|
|
15
|
+
declare const Tabs: React.FC<TabsProps>;
|
|
16
|
+
export default Tabs;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import "core-js/modules/esnext.iterator.constructor.js";
|
|
2
|
+
import "core-js/modules/esnext.iterator.map.js";
|
|
3
|
+
import "core-js/modules/web.dom-collections.iterator.js";
|
|
4
|
+
import { View, Text } from '@ray-js/components';
|
|
5
|
+
import React, { useState, useCallback } from 'react';
|
|
6
|
+
import './Tabs.less';
|
|
7
|
+
const Tabs = _ref => {
|
|
8
|
+
var _tabs$;
|
|
9
|
+
let {
|
|
10
|
+
tabs,
|
|
11
|
+
defaultActiveKey,
|
|
12
|
+
onChange,
|
|
13
|
+
className = ''
|
|
14
|
+
} = _ref;
|
|
15
|
+
const [activeKey, setActiveKey] = useState(defaultActiveKey || ((_tabs$ = tabs[0]) === null || _tabs$ === void 0 ? void 0 : _tabs$.key) || '');
|
|
16
|
+
const handleTabClick = useCallback(key => {
|
|
17
|
+
setActiveKey(key);
|
|
18
|
+
onChange === null || onChange === void 0 || onChange(key);
|
|
19
|
+
}, [onChange]);
|
|
20
|
+
return /*#__PURE__*/React.createElement(View, {
|
|
21
|
+
className: "t-agent-tabs ".concat(className)
|
|
22
|
+
}, /*#__PURE__*/React.createElement(View, {
|
|
23
|
+
className: "t-agent-tabs-header"
|
|
24
|
+
}, tabs.map(tab => /*#__PURE__*/React.createElement(View, {
|
|
25
|
+
key: tab.key,
|
|
26
|
+
className: "t-agent-tabs-tab ".concat(activeKey === tab.key ? 't-agent-tabs-tab--active' : ''),
|
|
27
|
+
onClick: () => handleTabClick(tab.key)
|
|
28
|
+
}, /*#__PURE__*/React.createElement(Text, {
|
|
29
|
+
className: "t-agent-tabs-tab-title"
|
|
30
|
+
}, tab.title), tab.badge !== undefined && tab.badge > 0 && /*#__PURE__*/React.createElement(View, {
|
|
31
|
+
className: "t-agent-tabs-tab-badge"
|
|
32
|
+
}, tab.badge)))), /*#__PURE__*/React.createElement(View, {
|
|
33
|
+
className: "t-agent-tabs-content"
|
|
34
|
+
}, tabs.map(tab => /*#__PURE__*/React.createElement(View, {
|
|
35
|
+
key: tab.key,
|
|
36
|
+
className: "t-agent-tabs-pane ".concat(activeKey === tab.key ? 't-agent-tabs-pane--active' : 't-agent-tabs-pane--inactive')
|
|
37
|
+
}, tab.content))));
|
|
38
|
+
};
|
|
39
|
+
export default Tabs;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
.t-agent-tabs {
|
|
2
|
+
width: 100%;
|
|
3
|
+
|
|
4
|
+
&-header {
|
|
5
|
+
display: flex;
|
|
6
|
+
border-bottom: 1px solid #e6e6e6;
|
|
7
|
+
margin-bottom: 16px;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
&-tab {
|
|
11
|
+
position: relative;
|
|
12
|
+
padding: 12px 16px;
|
|
13
|
+
margin-right: 8px;
|
|
14
|
+
cursor: pointer;
|
|
15
|
+
transition: all 0.3s;
|
|
16
|
+
|
|
17
|
+
&:last-child {
|
|
18
|
+
margin-right: 0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
&--active {
|
|
22
|
+
color: #0089ff;
|
|
23
|
+
font-weight: 500;
|
|
24
|
+
|
|
25
|
+
&::after {
|
|
26
|
+
content: '';
|
|
27
|
+
position: absolute;
|
|
28
|
+
bottom: 0;
|
|
29
|
+
left: 0;
|
|
30
|
+
width: 100%;
|
|
31
|
+
height: 2px;
|
|
32
|
+
background-color: #0089ff;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
&-title {
|
|
37
|
+
font-size: 14px;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
&-badge {
|
|
41
|
+
position: absolute;
|
|
42
|
+
top: 4px;
|
|
43
|
+
right: 4px;
|
|
44
|
+
min-width: 16px;
|
|
45
|
+
height: 16px;
|
|
46
|
+
padding: 0 4px;
|
|
47
|
+
background-color: #ff4d4f;
|
|
48
|
+
border-radius: 8px;
|
|
49
|
+
color: #fff;
|
|
50
|
+
font-size: 12px;
|
|
51
|
+
line-height: 16px;
|
|
52
|
+
text-align: center;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
&-content {
|
|
57
|
+
position: relative;
|
|
58
|
+
width: 100%;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
&-pane {
|
|
62
|
+
width: 100%;
|
|
63
|
+
|
|
64
|
+
&--active {
|
|
65
|
+
display: block;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
&--inactive {
|
|
69
|
+
display: none;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import './index.less';
|
|
3
|
+
import { ChangeInfoItem, DeviceInfoItem, SceneInfoItem } from '@ray-js/t-agent-plugin-assistant';
|
|
4
|
+
import { TileProps } from '../../types';
|
|
5
|
+
import { IOperations } from './Expand';
|
|
6
|
+
export interface OperateCardTileData {
|
|
7
|
+
deviceInfo: DeviceInfoItem[];
|
|
8
|
+
sceneInfo: SceneInfoItem[];
|
|
9
|
+
changeInfo: ChangeInfoItem[];
|
|
10
|
+
}
|
|
11
|
+
export interface OperateCardTileProps extends TileProps {
|
|
12
|
+
data: OperateCardTileData;
|
|
13
|
+
/** 自定义详情内容渲染函数 */
|
|
14
|
+
renderDetail?: (props: {
|
|
15
|
+
operations: IOperations;
|
|
16
|
+
tapDevice: (e: any) => void;
|
|
17
|
+
tapScene: (e: any) => void;
|
|
18
|
+
show: boolean;
|
|
19
|
+
}) => React.ReactNode;
|
|
20
|
+
}
|
|
21
|
+
export default function OperateCardTile({ data, renderDetail }: OperateCardTileProps): React.JSX.Element | null;
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import "core-js/modules/esnext.iterator.constructor.js";
|
|
3
|
+
import "core-js/modules/esnext.iterator.for-each.js";
|
|
4
|
+
import "core-js/modules/web.dom-collections.iterator.js";
|
|
5
|
+
import { Text, View } from '@ray-js/components';
|
|
6
|
+
import React, { useMemo, useState } from 'react';
|
|
7
|
+
import './index.less';
|
|
8
|
+
import { useRenderOptions } from '../../hooks';
|
|
9
|
+
import Expand from './Expand';
|
|
10
|
+
import { formatMessage } from '../../utils';
|
|
11
|
+
const handleDesc = (detail, t) => {
|
|
12
|
+
const {
|
|
13
|
+
device,
|
|
14
|
+
moreDevice,
|
|
15
|
+
scene,
|
|
16
|
+
moreScene,
|
|
17
|
+
more
|
|
18
|
+
} = detail;
|
|
19
|
+
const desc = [];
|
|
20
|
+
let deviceNum = device.length + moreDevice.length;
|
|
21
|
+
const sceneNum = scene.length + moreScene.length;
|
|
22
|
+
let homeNum = 0;
|
|
23
|
+
let roomNum = 0;
|
|
24
|
+
let groupNum = 0;
|
|
25
|
+
if (more.length) {
|
|
26
|
+
more.forEach(i => {
|
|
27
|
+
switch (i.type) {
|
|
28
|
+
case 'home':
|
|
29
|
+
homeNum += 1;
|
|
30
|
+
break;
|
|
31
|
+
case 'room':
|
|
32
|
+
roomNum += 1;
|
|
33
|
+
break;
|
|
34
|
+
case 'group':
|
|
35
|
+
groupNum += 1;
|
|
36
|
+
break;
|
|
37
|
+
case 'deviceRoom':
|
|
38
|
+
deviceNum += 1;
|
|
39
|
+
break;
|
|
40
|
+
default:
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
if (deviceNum) {
|
|
46
|
+
desc.push(formatMessage(t, 't-agent.operate-card-tile.device.count', {
|
|
47
|
+
count: deviceNum
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
if (sceneNum) {
|
|
51
|
+
desc.push(formatMessage(t, 't-agent.operate-card-tile.scene.count', {
|
|
52
|
+
count: sceneNum
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
55
|
+
if (homeNum) {
|
|
56
|
+
desc.push(formatMessage(t, 't-agent.operate-card-tile.home.count', {
|
|
57
|
+
count: homeNum
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
if (roomNum) {
|
|
61
|
+
desc.push(formatMessage(t, 't-agent.operate-card-tile.room.count', {
|
|
62
|
+
count: roomNum
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
if (groupNum) {
|
|
66
|
+
desc.push(formatMessage(t, 't-agent.operate-card-tile.group.count', {
|
|
67
|
+
count: groupNum
|
|
68
|
+
}));
|
|
69
|
+
}
|
|
70
|
+
return formatMessage(t, 't-agent.operate-card-tile.description.format', {
|
|
71
|
+
items: desc.join(t('t-agent.operate-card-tile.description.separator'))
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
export default function OperateCardTile(_ref) {
|
|
75
|
+
let {
|
|
76
|
+
data,
|
|
77
|
+
renderDetail
|
|
78
|
+
} = _ref;
|
|
79
|
+
const {
|
|
80
|
+
deviceInfo = [],
|
|
81
|
+
sceneInfo = [],
|
|
82
|
+
changeInfo = []
|
|
83
|
+
} = data || {};
|
|
84
|
+
const {
|
|
85
|
+
i18nTranslate: t
|
|
86
|
+
} = useRenderOptions();
|
|
87
|
+
const [show, setShow] = useState(false);
|
|
88
|
+
const [showDetail, setShowDetail] = useState(false);
|
|
89
|
+
const tapDevice = e => {
|
|
90
|
+
const deviceId = e.currentTarget.dataset.id;
|
|
91
|
+
ty.openPanel({
|
|
92
|
+
deviceId,
|
|
93
|
+
fail: () => {
|
|
94
|
+
ty.showToast({
|
|
95
|
+
title: t('t-agent.operate-card-tile.open.device.failed'),
|
|
96
|
+
icon: 'error'
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
const tapScene = e => {
|
|
102
|
+
const sceneId = e.currentTarget.dataset.id;
|
|
103
|
+
ty.router({
|
|
104
|
+
url: "tuyaSmart://editScene?sceneId=".concat(sceneId, "&biz_type=ai_smart&action=edit"),
|
|
105
|
+
fail: () => {
|
|
106
|
+
ty.showToast({
|
|
107
|
+
title: t('t-agent.operate-card-tile.open.scene.failed'),
|
|
108
|
+
icon: 'error'
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
const {
|
|
114
|
+
operations
|
|
115
|
+
} = useMemo(() => {
|
|
116
|
+
let isShow = show;
|
|
117
|
+
const operations = {
|
|
118
|
+
device: [],
|
|
119
|
+
scene: [],
|
|
120
|
+
moreDevice: [],
|
|
121
|
+
moreScene: [],
|
|
122
|
+
more: []
|
|
123
|
+
};
|
|
124
|
+
if (deviceInfo !== null && deviceInfo !== void 0 && deviceInfo.length) {
|
|
125
|
+
deviceInfo.forEach(i => {
|
|
126
|
+
const {
|
|
127
|
+
intent
|
|
128
|
+
} = i;
|
|
129
|
+
switch (intent) {
|
|
130
|
+
case 'controlDevice':
|
|
131
|
+
isShow = true;
|
|
132
|
+
operations.device.push(i);
|
|
133
|
+
break;
|
|
134
|
+
default:
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
if (sceneInfo !== null && sceneInfo !== void 0 && sceneInfo.length) {
|
|
140
|
+
sceneInfo.forEach(i => {
|
|
141
|
+
if (i.valid == null) {
|
|
142
|
+
i.valid = true;
|
|
143
|
+
}
|
|
144
|
+
const {
|
|
145
|
+
intent
|
|
146
|
+
} = i;
|
|
147
|
+
switch (intent) {
|
|
148
|
+
case 'queryScene':
|
|
149
|
+
case 'updateScene':
|
|
150
|
+
break;
|
|
151
|
+
case 'deleteScene':
|
|
152
|
+
if (i.success) {
|
|
153
|
+
isShow = true;
|
|
154
|
+
operations.scene.push(i);
|
|
155
|
+
}
|
|
156
|
+
break;
|
|
157
|
+
default:
|
|
158
|
+
isShow = true;
|
|
159
|
+
operations.scene.push(_objectSpread(_objectSpread({}, i), {}, {
|
|
160
|
+
displayType: 'execute'
|
|
161
|
+
}));
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
if (changeInfo !== null && changeInfo !== void 0 && changeInfo.length) {
|
|
167
|
+
isShow = true;
|
|
168
|
+
changeInfo.forEach(i => {
|
|
169
|
+
switch (i.type) {
|
|
170
|
+
case 'scene':
|
|
171
|
+
operations.moreScene.push(i);
|
|
172
|
+
break;
|
|
173
|
+
case 'device':
|
|
174
|
+
operations.moreDevice.push(i);
|
|
175
|
+
break;
|
|
176
|
+
default:
|
|
177
|
+
{
|
|
178
|
+
let desc = '';
|
|
179
|
+
if (i.type === 'deviceRoom') {
|
|
180
|
+
desc = formatMessage(t, 't-agent.operate-card-tile.device.move.desc', {
|
|
181
|
+
device: i.fromData,
|
|
182
|
+
room: i.toData
|
|
183
|
+
});
|
|
184
|
+
} else {
|
|
185
|
+
desc = formatMessage(t, 't-agent.operate-card-tile.device.rename.desc', {
|
|
186
|
+
oldName: i.fromData,
|
|
187
|
+
newName: i.toData
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
i.desc = desc;
|
|
191
|
+
operations.more.push(i);
|
|
192
|
+
}
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
if (isShow && !show) {
|
|
198
|
+
setShow(true);
|
|
199
|
+
}
|
|
200
|
+
return {
|
|
201
|
+
operations
|
|
202
|
+
};
|
|
203
|
+
}, [deviceInfo, sceneInfo, changeInfo, show, t]);
|
|
204
|
+
const desc = useMemo(() => handleDesc(operations, t), [operations, t]);
|
|
205
|
+
const toggleDetail = () => {
|
|
206
|
+
setShowDetail(!showDetail);
|
|
207
|
+
};
|
|
208
|
+
if (show) {
|
|
209
|
+
return /*#__PURE__*/React.createElement(View, {
|
|
210
|
+
className: "t-agent-scene-control-tile"
|
|
211
|
+
}, /*#__PURE__*/React.createElement(View, {
|
|
212
|
+
className: "t-agent-scene-control-tile-summary"
|
|
213
|
+
}, t('t-agent.operate-card-tile.operation.impact'), desc, /*#__PURE__*/React.createElement(Text, {
|
|
214
|
+
className: "t-agent-scene-control-tile-summary-detail",
|
|
215
|
+
onClick: toggleDetail
|
|
216
|
+
}, showDetail ? t('t-agent.operate-card-tile.hide.details') : t('t-agent.operate-card-tile.view.details'))), renderDetail && renderDetail({
|
|
217
|
+
operations,
|
|
218
|
+
tapDevice,
|
|
219
|
+
tapScene,
|
|
220
|
+
show: showDetail
|
|
221
|
+
}), showDetail && !renderDetail && /*#__PURE__*/React.createElement(Expand, {
|
|
222
|
+
operations: operations,
|
|
223
|
+
tapDevice: tapDevice,
|
|
224
|
+
tapScene: tapScene
|
|
225
|
+
}));
|
|
226
|
+
}
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
.t-agent-scene-control-tile {
|
|
2
|
+
transition: all 0.3s ease;
|
|
3
|
+
&-summary {
|
|
4
|
+
width: 100%;
|
|
5
|
+
display: flex;
|
|
6
|
+
align-items: center;
|
|
7
|
+
padding-top: 8px;
|
|
8
|
+
margin-top: 8px;
|
|
9
|
+
border-top: 1px solid var(--app-B3-N7);
|
|
10
|
+
font-size: 12px;
|
|
11
|
+
color: var(--app-B3-N3);
|
|
12
|
+
line-height: 18px;
|
|
13
|
+
|
|
14
|
+
&-detail {
|
|
15
|
+
color: var(--app-M4);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
Binary file
|