@ray-js/t-agent-ui-ray 0.1.0-beta-3 → 0.1.0-beta-5
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.js +1 -2
- package/dist/MessageInput/index.js +2 -4
- package/dist/contexts.d.ts +1 -1
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.js +2 -1
- package/dist/hooks/useLongPress.js +40 -23
- package/dist/hooks/useTranslate.d.ts +2 -0
- package/dist/hooks/useTranslate.js +62 -0
- package/dist/i18n/strings.d.ts +499 -0
- package/dist/i18n/strings.js +498 -0
- package/dist/tiles/BubbleTile/index.js +2 -5
- package/dist/tiles/DividerTile/index.d.ts +8 -0
- package/dist/tiles/DividerTile/index.js +16 -0
- package/dist/tiles/DividerTile/index.less +26 -0
- package/dist/tiles/ExecuteCardTile/bookmark.png +0 -0
- package/dist/tiles/ExecuteCardTile/index.d.ts +10 -0
- package/dist/tiles/ExecuteCardTile/index.js +231 -0
- package/dist/tiles/ExecuteCardTile/index.less +154 -0
- package/dist/tiles/OperateCardTile/Expand.d.ts +17 -0
- package/dist/tiles/OperateCardTile/Expand.js +167 -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 +226 -0
- package/dist/tiles/OperateCardTile/index.less +18 -0
- package/dist/tiles/OperateCardTile/lock.png +0 -0
- package/dist/tiles/map.js +7 -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,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,226 @@
|
|
|
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 { useTranslate } 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 t = useTranslate();
|
|
85
|
+
const [show, setShow] = useState(false);
|
|
86
|
+
const [showDetail, setShowDetail] = useState(false);
|
|
87
|
+
const tapDevice = e => {
|
|
88
|
+
const deviceId = e.currentTarget.dataset.id;
|
|
89
|
+
ty.openPanel({
|
|
90
|
+
deviceId,
|
|
91
|
+
fail: () => {
|
|
92
|
+
ty.showToast({
|
|
93
|
+
title: t('t-agent.operate-card-tile.open.device.failed'),
|
|
94
|
+
icon: 'error'
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
const tapScene = e => {
|
|
100
|
+
const sceneId = e.currentTarget.dataset.id;
|
|
101
|
+
ty.router({
|
|
102
|
+
url: "tuyaSmart://editScene?sceneId=".concat(sceneId, "&biz_type=ai_smart&action=edit"),
|
|
103
|
+
fail: () => {
|
|
104
|
+
ty.showToast({
|
|
105
|
+
title: t('t-agent.operate-card-tile.open.scene.failed'),
|
|
106
|
+
icon: 'error'
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
const {
|
|
112
|
+
operations
|
|
113
|
+
} = useMemo(() => {
|
|
114
|
+
let isShow = show;
|
|
115
|
+
const operations = {
|
|
116
|
+
device: [],
|
|
117
|
+
scene: [],
|
|
118
|
+
moreDevice: [],
|
|
119
|
+
moreScene: [],
|
|
120
|
+
more: []
|
|
121
|
+
};
|
|
122
|
+
if (deviceInfo !== null && deviceInfo !== void 0 && deviceInfo.length) {
|
|
123
|
+
deviceInfo.forEach(i => {
|
|
124
|
+
const {
|
|
125
|
+
intent
|
|
126
|
+
} = i;
|
|
127
|
+
switch (intent) {
|
|
128
|
+
case 'controlDevice':
|
|
129
|
+
isShow = true;
|
|
130
|
+
operations.device.push(i);
|
|
131
|
+
break;
|
|
132
|
+
default:
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
if (sceneInfo !== null && sceneInfo !== void 0 && sceneInfo.length) {
|
|
138
|
+
sceneInfo.forEach(i => {
|
|
139
|
+
if (i.valid == null) {
|
|
140
|
+
i.valid = true;
|
|
141
|
+
}
|
|
142
|
+
const {
|
|
143
|
+
intent
|
|
144
|
+
} = i;
|
|
145
|
+
switch (intent) {
|
|
146
|
+
case 'queryScene':
|
|
147
|
+
case 'updateScene':
|
|
148
|
+
break;
|
|
149
|
+
case 'deleteScene':
|
|
150
|
+
if (i.success) {
|
|
151
|
+
isShow = true;
|
|
152
|
+
operations.scene.push(i);
|
|
153
|
+
}
|
|
154
|
+
break;
|
|
155
|
+
default:
|
|
156
|
+
isShow = true;
|
|
157
|
+
operations.scene.push(_objectSpread(_objectSpread({}, i), {}, {
|
|
158
|
+
displayType: 'execute'
|
|
159
|
+
}));
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
if (changeInfo !== null && changeInfo !== void 0 && changeInfo.length) {
|
|
165
|
+
isShow = true;
|
|
166
|
+
changeInfo.forEach(i => {
|
|
167
|
+
switch (i.type) {
|
|
168
|
+
case 'scene':
|
|
169
|
+
operations.moreScene.push(i);
|
|
170
|
+
break;
|
|
171
|
+
case 'device':
|
|
172
|
+
operations.moreDevice.push(i);
|
|
173
|
+
break;
|
|
174
|
+
default:
|
|
175
|
+
{
|
|
176
|
+
let desc = '';
|
|
177
|
+
if (i.type === 'deviceRoom') {
|
|
178
|
+
desc = formatMessage(t, 't-agent.operate-card-tile.device.move.desc', {
|
|
179
|
+
device: i.fromData,
|
|
180
|
+
room: i.toData
|
|
181
|
+
});
|
|
182
|
+
} else {
|
|
183
|
+
desc = formatMessage(t, 't-agent.operate-card-tile.device.rename.desc', {
|
|
184
|
+
oldName: i.fromData,
|
|
185
|
+
newName: i.toData
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
i.desc = desc;
|
|
189
|
+
operations.more.push(i);
|
|
190
|
+
}
|
|
191
|
+
break;
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
if (isShow && !show) {
|
|
196
|
+
setShow(true);
|
|
197
|
+
}
|
|
198
|
+
return {
|
|
199
|
+
operations
|
|
200
|
+
};
|
|
201
|
+
}, [deviceInfo, sceneInfo, changeInfo, show, t]);
|
|
202
|
+
const desc = useMemo(() => handleDesc(operations, t), [operations, t]);
|
|
203
|
+
const toggleDetail = () => {
|
|
204
|
+
setShowDetail(!showDetail);
|
|
205
|
+
};
|
|
206
|
+
if (show) {
|
|
207
|
+
return /*#__PURE__*/React.createElement(View, {
|
|
208
|
+
className: "t-agent-scene-control-tile"
|
|
209
|
+
}, /*#__PURE__*/React.createElement(View, {
|
|
210
|
+
className: "t-agent-scene-control-tile-summary"
|
|
211
|
+
}, t('t-agent.operate-card-tile.operation.impact'), desc, /*#__PURE__*/React.createElement(Text, {
|
|
212
|
+
className: "t-agent-scene-control-tile-summary-detail",
|
|
213
|
+
onClick: toggleDetail
|
|
214
|
+
}, showDetail ? t('t-agent.operate-card-tile.hide.details') : t('t-agent.operate-card-tile.view.details'))), renderDetail && renderDetail({
|
|
215
|
+
operations,
|
|
216
|
+
tapDevice,
|
|
217
|
+
tapScene,
|
|
218
|
+
show: showDetail
|
|
219
|
+
}), showDetail && !renderDetail && /*#__PURE__*/React.createElement(Expand, {
|
|
220
|
+
operations: operations,
|
|
221
|
+
tapDevice: tapDevice,
|
|
222
|
+
tapScene: tapScene
|
|
223
|
+
}));
|
|
224
|
+
}
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
@@ -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
|
package/dist/tiles/map.js
CHANGED
|
@@ -9,6 +9,9 @@ import RecommendationsTile from './RecommendationsTile';
|
|
|
9
9
|
import CardTile from './CardTile';
|
|
10
10
|
import WorkflowTile from './WorkflowTile';
|
|
11
11
|
import DocumentsTile from './DocumentsTile';
|
|
12
|
+
import OperateCardTile from './OperateCardTile';
|
|
13
|
+
import ExecuteCardTile from './ExecuteCardTile';
|
|
14
|
+
import DividerTile from './DividerTile';
|
|
12
15
|
export const tileMap = {
|
|
13
16
|
bubble: BubbleTile,
|
|
14
17
|
image: ImageTile,
|
|
@@ -20,5 +23,8 @@ export const tileMap = {
|
|
|
20
23
|
recommendations: RecommendationsTile,
|
|
21
24
|
card: CardTile,
|
|
22
25
|
workflow: WorkflowTile,
|
|
23
|
-
documents: DocumentsTile
|
|
26
|
+
documents: DocumentsTile,
|
|
27
|
+
operateCard: OperateCardTile,
|
|
28
|
+
executeCard: ExecuteCardTile,
|
|
29
|
+
divider: DividerTile
|
|
24
30
|
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 用于处理多语言文本中的变量替换
|
|
3
|
+
* @param t i18n翻译函数
|
|
4
|
+
* @param key 多语言键名
|
|
5
|
+
* @param params 需要替换的变量对象,如 {name: '小明', age: 18}
|
|
6
|
+
* @returns 替换变量后的文本
|
|
7
|
+
*
|
|
8
|
+
* 使用示例:
|
|
9
|
+
* formatMessage(t, 'greet', {name: '小明'}) // 假设 'greet' 对应的文本是 "你好,{name}",将返回 "你好,小明"
|
|
10
|
+
*/
|
|
11
|
+
export declare const formatMessage: (t: (key: string) => string, key: string, params?: Record<string, string | number>) => string;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import "core-js/modules/es.regexp.exec.js";
|
|
2
|
+
import "core-js/modules/es.string.replace.js";
|
|
3
|
+
import "core-js/modules/esnext.iterator.constructor.js";
|
|
4
|
+
import "core-js/modules/esnext.iterator.for-each.js";
|
|
5
|
+
import "core-js/modules/web.dom-collections.iterator.js";
|
|
6
|
+
/**
|
|
7
|
+
* 用于处理多语言文本中的变量替换
|
|
8
|
+
* @param t i18n翻译函数
|
|
9
|
+
* @param key 多语言键名
|
|
10
|
+
* @param params 需要替换的变量对象,如 {name: '小明', age: 18}
|
|
11
|
+
* @returns 替换变量后的文本
|
|
12
|
+
*
|
|
13
|
+
* 使用示例:
|
|
14
|
+
* formatMessage(t, 'greet', {name: '小明'}) // 假设 'greet' 对应的文本是 "你好,{name}",将返回 "你好,小明"
|
|
15
|
+
*/
|
|
16
|
+
export const formatMessage = (t, key, params) => {
|
|
17
|
+
if (!params) {
|
|
18
|
+
return t(key);
|
|
19
|
+
}
|
|
20
|
+
let message = t(key);
|
|
21
|
+
|
|
22
|
+
// 替换所有的变量
|
|
23
|
+
Object.entries(params).forEach(_ref => {
|
|
24
|
+
let [paramKey, paramValue] = _ref;
|
|
25
|
+
message = message.replace("{".concat(paramKey, "}"), String(paramValue));
|
|
26
|
+
});
|
|
27
|
+
return message;
|
|
28
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function routeScene(sceneId) {
|
|
2
|
+
ty.router({
|
|
3
|
+
url: "tuyaSmart://editScene?sceneId=".concat(sceneId, "&biz_type=ai_smart&action=edit"),
|
|
4
|
+
fail: err => {
|
|
5
|
+
console.error('router fail', sceneId, err);
|
|
6
|
+
ty.showToast({
|
|
7
|
+
title: err.errorMsg || I18n.t('execute_fail'),
|
|
8
|
+
icon: 'error'
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
export * from './formatMessage';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ray-js/t-agent-ui-ray",
|
|
3
|
-
"version": "0.1.0-beta-
|
|
3
|
+
"version": "0.1.0-beta-5",
|
|
4
4
|
"author": "Tuya.inc",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"private": false,
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"@types/echarts": "^4.9.22",
|
|
42
42
|
"@types/markdown-it": "^14.1.1"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "061c94dea1a6668848c37f8f75efa0fa26329636"
|
|
45
45
|
}
|