Compare commits
3 Commits
anhlt
...
ea07d0c99e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ea07d0c99e | ||
|
|
ed5751002b | ||
|
|
6d1c085ff7 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -14,3 +14,4 @@
|
|||||||
.turbopack
|
.turbopack
|
||||||
/dist
|
/dist
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
/wdoc
|
||||||
@@ -22,7 +22,7 @@ export default defineConfig({
|
|||||||
name: 'gms.monitor',
|
name: 'gms.monitor',
|
||||||
icon: 'icon-monitor',
|
icon: 'icon-monitor',
|
||||||
path: '/monitor',
|
path: '/monitor',
|
||||||
component: './Slave/GMS/Monitor',
|
component: './Slave/Spole/Monitor',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
...managerRouteBase,
|
...managerRouteBase,
|
||||||
|
|||||||
@@ -24,6 +24,11 @@ const proxyDev: Record<string, any> = {
|
|||||||
target: target,
|
target: target,
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
},
|
},
|
||||||
|
'/mqtt': {
|
||||||
|
target: target,
|
||||||
|
changeOrigin: true,
|
||||||
|
ws: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
test: {
|
test: {
|
||||||
'/test': {
|
'/test': {
|
||||||
|
|||||||
@@ -102,7 +102,9 @@ export const handleRequestConfig: RequestConfig = {
|
|||||||
...options,
|
...options,
|
||||||
headers: {
|
headers: {
|
||||||
...options.headers,
|
...options.headers,
|
||||||
...(token ? { Authorization: `${token}` } : {}),
|
...(token && !options.headers.Authorization
|
||||||
|
? { Authorization: `${token}` }
|
||||||
|
: {}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -86,7 +86,9 @@ export const handleRequestConfig: RequestConfig = {
|
|||||||
...options,
|
...options,
|
||||||
headers: {
|
headers: {
|
||||||
...options.headers,
|
...options.headers,
|
||||||
...(token ? { Authorization: `${token}` } : {}),
|
...(token && !options.headers.Authorization
|
||||||
|
? { Authorization: `${token}` }
|
||||||
|
: {}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -39,6 +39,10 @@ export const commonManagerRoutes = [
|
|||||||
path: '/manager/devices',
|
path: '/manager/devices',
|
||||||
component: './Manager/Device',
|
component: './Manager/Device',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: '/manager/devices/:thingId',
|
||||||
|
component: './Manager/Device/Detail',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ export const layout: RunTimeLayoutConfig = ({ initialState }) => {
|
|||||||
contentWidth: 'Fluid',
|
contentWidth: 'Fluid',
|
||||||
navTheme: isDark ? 'realDark' : 'light',
|
navTheme: isDark ? 'realDark' : 'light',
|
||||||
splitMenus: true,
|
splitMenus: true,
|
||||||
iconfontUrl: '//at.alicdn.com/t/c/font_5096559_pwy498d2aw.js',
|
iconfontUrl: '//at.alicdn.com/t/c/font_5096559_qeg2471go4g.js',
|
||||||
contentStyle: {
|
contentStyle: {
|
||||||
padding: 0,
|
padding: 0,
|
||||||
margin: 0,
|
margin: 0,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { createFromIconfontCN } from '@ant-design/icons';
|
import { createFromIconfontCN } from '@ant-design/icons';
|
||||||
|
|
||||||
const IconFont = createFromIconfontCN({
|
const IconFont = createFromIconfontCN({
|
||||||
scriptUrl: '//at.alicdn.com/t/c/font_5096559_pwy498d2aw.js',
|
scriptUrl: '//at.alicdn.com/t/c/font_5096559_qeg2471go4g.js',
|
||||||
});
|
});
|
||||||
|
|
||||||
export default IconFont;
|
export default IconFont;
|
||||||
|
|||||||
82
src/components/shared/Alarm/AlarmUnConfirmButton.tsx
Normal file
82
src/components/shared/Alarm/AlarmUnConfirmButton.tsx
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
import { HTTPSTATUS } from '@/constants';
|
||||||
|
import { apiUnconfirmAlarm } from '@/services/master/AlarmController';
|
||||||
|
import { CloseOutlined } from '@ant-design/icons';
|
||||||
|
import { useIntl } from '@umijs/max';
|
||||||
|
import { Button, Popconfirm } from 'antd';
|
||||||
|
import { MessageInstance } from 'antd/es/message/interface';
|
||||||
|
|
||||||
|
type AlarmUnConfirmButtonProps = {
|
||||||
|
alarm: MasterModel.Alarm;
|
||||||
|
onFinish?: (isReload: boolean) => void;
|
||||||
|
message: MessageInstance;
|
||||||
|
button?: React.ReactNode;
|
||||||
|
};
|
||||||
|
const AlarmUnConfirmButton = ({
|
||||||
|
alarm,
|
||||||
|
message,
|
||||||
|
button,
|
||||||
|
onFinish,
|
||||||
|
}: AlarmUnConfirmButtonProps) => {
|
||||||
|
const intl = useIntl();
|
||||||
|
return (
|
||||||
|
<Popconfirm
|
||||||
|
title={intl.formatMessage({
|
||||||
|
id: 'master.alarms.unconfirm.body',
|
||||||
|
defaultMessage: 'Are you sure you want to unconfirm this alarm?',
|
||||||
|
})}
|
||||||
|
okText={intl.formatMessage({
|
||||||
|
id: 'common.yes',
|
||||||
|
defaultMessage: 'Yes',
|
||||||
|
})}
|
||||||
|
cancelText={intl.formatMessage({
|
||||||
|
id: 'common.no',
|
||||||
|
defaultMessage: 'No',
|
||||||
|
})}
|
||||||
|
onConfirm={async () => {
|
||||||
|
const body: MasterModel.ConfirmAlarmRequest = {
|
||||||
|
id: alarm.id,
|
||||||
|
thing_id: alarm.thing_id,
|
||||||
|
time: alarm.time,
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
const resp = await apiUnconfirmAlarm(body);
|
||||||
|
if (resp.status === HTTPSTATUS.HTTP_SUCCESS) {
|
||||||
|
message.success({
|
||||||
|
content: intl.formatMessage({
|
||||||
|
id: 'master.alarms.unconfirm.success',
|
||||||
|
defaultMessage: 'Confirm alarm successfully',
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
onFinish?.(true);
|
||||||
|
} else if (resp.status === HTTPSTATUS.HTTP_NOTFOUND) {
|
||||||
|
message.warning({
|
||||||
|
content: intl.formatMessage({
|
||||||
|
id: 'master.alarms.not_found',
|
||||||
|
defaultMessage: 'Alarm has expired or does not exist',
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
onFinish?.(true);
|
||||||
|
} else {
|
||||||
|
throw new Error('Failed to confirm alarm');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error when unconfirm alarm: ', error);
|
||||||
|
message.error({
|
||||||
|
content: intl.formatMessage({
|
||||||
|
id: 'master.alarms.unconfirm.fail',
|
||||||
|
defaultMessage: 'Unconfirm alarm failed',
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{button ? (
|
||||||
|
button
|
||||||
|
) : (
|
||||||
|
<Button danger icon={<CloseOutlined />} size="small" />
|
||||||
|
)}
|
||||||
|
</Popconfirm>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default AlarmUnConfirmButton;
|
||||||
158
src/components/shared/DeviceAlarmList.tsx
Normal file
158
src/components/shared/DeviceAlarmList.tsx
Normal file
@@ -0,0 +1,158 @@
|
|||||||
|
import { DATE_TIME_FORMAT, DEFAULT_PAGE_SIZE, DURATION_POLLING } from '@/const';
|
||||||
|
import AlarmDescription from '@/pages/Alarm/components/AlarmDescription';
|
||||||
|
import AlarmFormConfirm from '@/pages/Alarm/components/AlarmFormConfirm';
|
||||||
|
import { apiGetAlarms } from '@/services/master/AlarmController';
|
||||||
|
import { CheckOutlined } from '@ant-design/icons';
|
||||||
|
import { ActionType, ProList, ProListMetas } from '@ant-design/pro-components';
|
||||||
|
import { useIntl } from '@umijs/max';
|
||||||
|
import { Button, message, theme, Typography } from 'antd';
|
||||||
|
import moment from 'moment';
|
||||||
|
import { useRef, useState } from 'react';
|
||||||
|
import AlarmUnConfirmButton from './Alarm/AlarmUnConfirmButton';
|
||||||
|
import { getBadgeStatus, getTitleColorByDeviceStateLevel } from './ThingShared';
|
||||||
|
|
||||||
|
type DeviceAlarmListProps = {
|
||||||
|
thingId: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const DeviceAlarmList = ({ thingId }: DeviceAlarmListProps) => {
|
||||||
|
const { token } = theme.useToken();
|
||||||
|
const [messageApi, contextHolder] = message.useMessage();
|
||||||
|
const intl = useIntl();
|
||||||
|
const actionRef = useRef<ActionType>();
|
||||||
|
const [loading, setIsLoading] = useState<boolean>(false);
|
||||||
|
const [alarmConfirmed, setAlarmConfirmed] = useState<
|
||||||
|
MasterModel.Alarm | undefined
|
||||||
|
>(undefined);
|
||||||
|
const columns: ProListMetas<MasterModel.Alarm> = {
|
||||||
|
title: {
|
||||||
|
dataIndex: 'name',
|
||||||
|
render(_, item) {
|
||||||
|
return (
|
||||||
|
<Typography.Text
|
||||||
|
style={{
|
||||||
|
color: getTitleColorByDeviceStateLevel(item.level || 0, token),
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{item.name}
|
||||||
|
</Typography.Text>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
avatar: {
|
||||||
|
render: (_, item) => getBadgeStatus(item.level || 0),
|
||||||
|
},
|
||||||
|
description: {
|
||||||
|
dataIndex: 'time',
|
||||||
|
render: (_, item) => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{item.confirmed ? (
|
||||||
|
<AlarmDescription alarm={item} size="small" />
|
||||||
|
) : (
|
||||||
|
<div>{moment.unix(item?.time || 0).format(DATE_TIME_FORMAT)}</div>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
actions: {
|
||||||
|
render: (_, entity) => [
|
||||||
|
entity.confirmed ? (
|
||||||
|
<AlarmUnConfirmButton
|
||||||
|
key="unconfirm"
|
||||||
|
alarm={entity}
|
||||||
|
message={messageApi}
|
||||||
|
onFinish={(isReload) => {
|
||||||
|
if (isReload) actionRef.current?.reload();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<Button
|
||||||
|
key="confirm"
|
||||||
|
icon={<CheckOutlined />}
|
||||||
|
type="dashed"
|
||||||
|
className="green-btn"
|
||||||
|
style={{ color: 'green', borderColor: 'green' }}
|
||||||
|
size="small"
|
||||||
|
onClick={() => setAlarmConfirmed(entity)}
|
||||||
|
></Button>
|
||||||
|
),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{contextHolder}
|
||||||
|
<AlarmFormConfirm
|
||||||
|
isOpen={!!alarmConfirmed}
|
||||||
|
setIsOpen={(v) => {
|
||||||
|
if (!v) setAlarmConfirmed(undefined);
|
||||||
|
}}
|
||||||
|
alarm={alarmConfirmed || ({} as MasterModel.Alarm)}
|
||||||
|
trigger={<></>}
|
||||||
|
message={messageApi}
|
||||||
|
onFinish={(isReload) => {
|
||||||
|
if (isReload) actionRef.current?.reload();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<ProList<MasterModel.Alarm>
|
||||||
|
rowKey={(record) => `${record.thing_id}_${record.id}`}
|
||||||
|
bordered
|
||||||
|
actionRef={actionRef}
|
||||||
|
metas={columns}
|
||||||
|
polling={DURATION_POLLING}
|
||||||
|
loading={loading}
|
||||||
|
search={false}
|
||||||
|
dateFormatter="string"
|
||||||
|
cardProps={{
|
||||||
|
bodyStyle: { paddingInline: 16, paddingBlock: 8 },
|
||||||
|
}}
|
||||||
|
pagination={{
|
||||||
|
defaultPageSize: DEFAULT_PAGE_SIZE * 2,
|
||||||
|
showSizeChanger: false,
|
||||||
|
pageSizeOptions: ['5', '10', '15', '20'],
|
||||||
|
showTotal: (total, range) =>
|
||||||
|
`${range[0]}-${range[1]}
|
||||||
|
${intl.formatMessage({
|
||||||
|
id: 'common.paginations.of',
|
||||||
|
defaultMessage: 'of',
|
||||||
|
})}
|
||||||
|
${total} ${intl.formatMessage({
|
||||||
|
id: 'master.alarms.table.pagination',
|
||||||
|
defaultMessage: 'alarms',
|
||||||
|
})}`,
|
||||||
|
}}
|
||||||
|
request={async (params) => {
|
||||||
|
setIsLoading(true);
|
||||||
|
try {
|
||||||
|
const { current, pageSize } = params;
|
||||||
|
const offset = current === 1 ? 0 : (current! - 1) * pageSize!;
|
||||||
|
const body: MasterModel.SearchAlarmPaginationBody = {
|
||||||
|
limit: pageSize,
|
||||||
|
offset: offset,
|
||||||
|
thing_id: thingId,
|
||||||
|
dir: 'desc',
|
||||||
|
};
|
||||||
|
const res = await apiGetAlarms(body);
|
||||||
|
return {
|
||||||
|
data: res.alarms,
|
||||||
|
total: res.total,
|
||||||
|
success: true,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
data: [],
|
||||||
|
total: 0,
|
||||||
|
success: false,
|
||||||
|
};
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default DeviceAlarmList;
|
||||||
@@ -4,7 +4,7 @@ import {
|
|||||||
STATUS_SOS,
|
STATUS_SOS,
|
||||||
STATUS_WARNING,
|
STATUS_WARNING,
|
||||||
} from '@/constants';
|
} from '@/constants';
|
||||||
import { Badge } from 'antd';
|
import { Badge, GlobalToken } from 'antd';
|
||||||
import IconFont from '../IconFont';
|
import IconFont from '../IconFont';
|
||||||
|
|
||||||
export const getBadgeStatus = (status: number) => {
|
export const getBadgeStatus = (status: number) => {
|
||||||
@@ -30,3 +30,21 @@ export const getBadgeConnection = (online: boolean) => {
|
|||||||
return <IconFont type="icon-cloud-disconnect" />;
|
return <IconFont type="icon-cloud-disconnect" />;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getTitleColorByDeviceStateLevel = (
|
||||||
|
level: number,
|
||||||
|
token: GlobalToken,
|
||||||
|
) => {
|
||||||
|
switch (level) {
|
||||||
|
case STATUS_NORMAL:
|
||||||
|
return token.colorSuccess;
|
||||||
|
case STATUS_WARNING:
|
||||||
|
return token.colorWarning;
|
||||||
|
case STATUS_DANGEROUS:
|
||||||
|
return token.colorError;
|
||||||
|
case STATUS_SOS:
|
||||||
|
return token.colorError;
|
||||||
|
default:
|
||||||
|
return token.colorText;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
69
src/components/shared/TooltipIconFontButton.tsx
Normal file
69
src/components/shared/TooltipIconFontButton.tsx
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
import type { ButtonProps } from 'antd';
|
||||||
|
import { Button, Tooltip } from 'antd';
|
||||||
|
import React from 'react';
|
||||||
|
import IconFont from '../IconFont';
|
||||||
|
|
||||||
|
type TooltipIconFontButtonProps = {
|
||||||
|
tooltip?: string;
|
||||||
|
iconFontName: string;
|
||||||
|
color?: string;
|
||||||
|
onClick?: () => void;
|
||||||
|
} & Omit<ButtonProps, 'icon' | 'color'>;
|
||||||
|
|
||||||
|
const TooltipIconFontButton: React.FC<TooltipIconFontButtonProps> = ({
|
||||||
|
tooltip,
|
||||||
|
iconFontName,
|
||||||
|
color,
|
||||||
|
onClick,
|
||||||
|
...buttonProps
|
||||||
|
}) => {
|
||||||
|
const wrapperClassName = `tooltip-iconfont-wrapper-${color?.replace(
|
||||||
|
/[^a-zA-Z0-9]/g,
|
||||||
|
'-',
|
||||||
|
)}`;
|
||||||
|
const icon = (
|
||||||
|
<IconFont
|
||||||
|
type={iconFontName}
|
||||||
|
style={{ color: color || 'black' }}
|
||||||
|
className={wrapperClassName}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
||||||
|
if (tooltip) {
|
||||||
|
return (
|
||||||
|
<Tooltip title={tooltip}>
|
||||||
|
<Button
|
||||||
|
onClick={onClick}
|
||||||
|
icon={icon}
|
||||||
|
{...buttonProps}
|
||||||
|
style={
|
||||||
|
color
|
||||||
|
? {
|
||||||
|
...buttonProps.style,
|
||||||
|
['--icon-button-color' as string]: color,
|
||||||
|
}
|
||||||
|
: buttonProps.style
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</Tooltip>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
onClick={onClick}
|
||||||
|
icon={icon}
|
||||||
|
{...buttonProps}
|
||||||
|
style={
|
||||||
|
color
|
||||||
|
? {
|
||||||
|
...buttonProps.style,
|
||||||
|
['--icon-button-color' as string]: color,
|
||||||
|
}
|
||||||
|
: buttonProps.style
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default TooltipIconFontButton;
|
||||||
@@ -76,3 +76,29 @@
|
|||||||
.table-row-select tbody tr:hover {
|
.table-row-select tbody tr:hover {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Target icon inside the color wrapper - higher specificity
|
||||||
|
:local(.tooltip-iconfont-wrapper) .iconfont,
|
||||||
|
.tooltip-iconfont-wrapper .iconfont,
|
||||||
|
.tooltip-iconfont-wrapper svg {
|
||||||
|
color: currentcolor !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Even more specific - target within Button
|
||||||
|
.ant-btn .tooltip-iconfont-wrapper .iconfont {
|
||||||
|
color: currentcolor !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Most aggressive - global selector
|
||||||
|
:global {
|
||||||
|
.ant-btn .tooltip-iconfont-wrapper .iconfont,
|
||||||
|
.ant-btn .tooltip-iconfont-wrapper svg {
|
||||||
|
color: currentcolor !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use CSS variable approach
|
||||||
|
.ant-btn[style*='--icon-button-color'] .iconfont,
|
||||||
|
.ant-btn[style*='--icon-button-color'] svg {
|
||||||
|
color: var(--icon-button-color) !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ export const API_ALARMS_CONFIRM = '/api/alarms/confirm';
|
|||||||
// Thing API Constants
|
// Thing API Constants
|
||||||
export const API_THINGS_SEARCH = '/api/things/search';
|
export const API_THINGS_SEARCH = '/api/things/search';
|
||||||
export const API_THING_POLICY = '/api/things/policy2';
|
export const API_THING_POLICY = '/api/things/policy2';
|
||||||
export const API_SHARE_THING = '/api/things';
|
export const API_THING = '/api/things';
|
||||||
|
|
||||||
// Group API Constants
|
// Group API Constants
|
||||||
export const API_GROUPS = '/api/groups';
|
export const API_GROUPS = '/api/groups';
|
||||||
@@ -17,7 +17,7 @@ export const API_GROUP_MEMBERS = '/api/members';
|
|||||||
export const API_GROUP_CHILDREN = '/api/groups';
|
export const API_GROUP_CHILDREN = '/api/groups';
|
||||||
|
|
||||||
// Log API Constants
|
// Log API Constants
|
||||||
export const API_LOGS = '/api/reader/channels';
|
export const API_READER = '/api/reader/channels';
|
||||||
|
|
||||||
// User API Constants
|
// User API Constants
|
||||||
export const API_USERS = '/api/users';
|
export const API_USERS = '/api/users';
|
||||||
|
|||||||
@@ -2,4 +2,5 @@ export const ROUTE_LOGIN = '/login';
|
|||||||
export const ROUTER_HOME = '/';
|
export const ROUTER_HOME = '/';
|
||||||
export const ROUTE_PROFILE = '/profile';
|
export const ROUTE_PROFILE = '/profile';
|
||||||
export const ROUTE_MANAGER_USERS = '/manager/users';
|
export const ROUTE_MANAGER_USERS = '/manager/users';
|
||||||
|
export const ROUTE_MANAGER_DEVICES = '/manager/devices';
|
||||||
export const ROUTE_MANAGER_USERS_PERMISSIONS = 'permissions';
|
export const ROUTE_MANAGER_USERS_PERMISSIONS = 'permissions';
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import masterGroupEn from './master-group-en';
|
|||||||
import masterSysLogEn from './master-log-en';
|
import masterSysLogEn from './master-log-en';
|
||||||
import masterMenuEn from './master-menu-en';
|
import masterMenuEn from './master-menu-en';
|
||||||
import masterMenuProfileEn from './master-profile-en';
|
import masterMenuProfileEn from './master-profile-en';
|
||||||
|
import masterThingDetailEn from './master-thing-detail-en';
|
||||||
import masterThingEn from './master-thing-en';
|
import masterThingEn from './master-thing-en';
|
||||||
import masterUserEn from './master-user-en';
|
import masterUserEn from './master-user-en';
|
||||||
export default {
|
export default {
|
||||||
@@ -16,4 +17,5 @@ export default {
|
|||||||
...masterSysLogEn,
|
...masterSysLogEn,
|
||||||
...masterUserEn,
|
...masterUserEn,
|
||||||
...masterGroupEn,
|
...masterGroupEn,
|
||||||
|
...masterThingDetailEn,
|
||||||
};
|
};
|
||||||
|
|||||||
1
src/locales/en-US/master/master-thing-detail-en.ts
Normal file
1
src/locales/en-US/master/master-thing-detail-en.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export default { 'master.thing.detail.alarmList.title': 'Alarm List' };
|
||||||
3
src/locales/vi-VN/master/master-thing-detail-vi.ts
Normal file
3
src/locales/vi-VN/master/master-thing-detail-vi.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export default {
|
||||||
|
'master.thing.detail.alarmList.title': 'Danh sách cảnh báo',
|
||||||
|
};
|
||||||
@@ -4,6 +4,7 @@ import masterGroupVi from './master-group-vi';
|
|||||||
import masterSysLogVi from './master-log-vi';
|
import masterSysLogVi from './master-log-vi';
|
||||||
import masterMenuVi from './master-menu-vi';
|
import masterMenuVi from './master-menu-vi';
|
||||||
import masterProfileVi from './master-profile-vi';
|
import masterProfileVi from './master-profile-vi';
|
||||||
|
import masterThingDetailVi from './master-thing-detail-vi';
|
||||||
import masterThingVi from './master-thing-vi';
|
import masterThingVi from './master-thing-vi';
|
||||||
import masterUserVi from './master-user-vi';
|
import masterUserVi from './master-user-vi';
|
||||||
export default {
|
export default {
|
||||||
@@ -16,4 +17,5 @@ export default {
|
|||||||
...masterSysLogVi,
|
...masterSysLogVi,
|
||||||
...masterUserVi,
|
...masterUserVi,
|
||||||
...masterGroupVi,
|
...masterGroupVi,
|
||||||
|
...masterThingDetailVi,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,21 +4,23 @@ import {
|
|||||||
UserOutlined,
|
UserOutlined,
|
||||||
} from '@ant-design/icons';
|
} from '@ant-design/icons';
|
||||||
import { Space, Typography } from 'antd';
|
import { Space, Typography } from 'antd';
|
||||||
|
import { SpaceSize } from 'antd/es/space';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
|
||||||
const { Text } = Typography;
|
const { Text } = Typography;
|
||||||
|
|
||||||
interface AlarmDescriptionProps {
|
interface AlarmDescriptionProps {
|
||||||
alarm: MasterModel.Alarm;
|
alarm: MasterModel.Alarm;
|
||||||
|
size?: SpaceSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
const AlarmDescription = ({ alarm }: AlarmDescriptionProps) => {
|
const AlarmDescription = ({ alarm, size = 'large' }: AlarmDescriptionProps) => {
|
||||||
if (!alarm?.confirmed) {
|
if (!alarm?.confirmed) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Space size="large" wrap>
|
<Space size={size} wrap>
|
||||||
<Space align="baseline" size={10}>
|
<Space align="baseline" size={10}>
|
||||||
<CheckCircleOutlined style={{ color: '#52c41a' }} />
|
<CheckCircleOutlined style={{ color: '#52c41a' }} />
|
||||||
<Text type="secondary" style={{ fontSize: 15 }}>
|
<Text type="secondary" style={{ fontSize: 15 }}>
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import { FormattedMessage, useIntl } from '@umijs/max';
|
|||||||
import { Button, Flex } from 'antd';
|
import { Button, Flex } from 'antd';
|
||||||
import { MessageInstance } from 'antd/es/message/interface';
|
import { MessageInstance } from 'antd/es/message/interface';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import { useRef, useState } from 'react';
|
import React, { useRef } from 'react';
|
||||||
|
|
||||||
type AlarmForm = {
|
type AlarmForm = {
|
||||||
name: string;
|
name: string;
|
||||||
@@ -19,22 +19,26 @@ type AlarmForm = {
|
|||||||
description: string;
|
description: string;
|
||||||
};
|
};
|
||||||
type AlarmFormConfirmProps = {
|
type AlarmFormConfirmProps = {
|
||||||
|
isOpen: boolean;
|
||||||
|
setIsOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
||||||
|
trigger?: React.ReactNode;
|
||||||
alarm: MasterModel.Alarm;
|
alarm: MasterModel.Alarm;
|
||||||
message: MessageInstance;
|
message: MessageInstance;
|
||||||
onFinish?: (reload: boolean) => void;
|
onFinish?: (reload: boolean) => void;
|
||||||
};
|
};
|
||||||
const AlarmFormConfirm = ({
|
const AlarmFormConfirm = ({
|
||||||
|
isOpen,
|
||||||
|
setIsOpen,
|
||||||
|
trigger,
|
||||||
alarm,
|
alarm,
|
||||||
message,
|
message,
|
||||||
onFinish,
|
onFinish,
|
||||||
}: AlarmFormConfirmProps) => {
|
}: AlarmFormConfirmProps) => {
|
||||||
const [modalVisit, setModalVisit] = useState(false);
|
|
||||||
const formRef = useRef<ProFormInstance<AlarmForm>>();
|
const formRef = useRef<ProFormInstance<AlarmForm>>();
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ModalForm<AlarmForm>
|
<ModalForm<AlarmForm>
|
||||||
open={modalVisit}
|
open={isOpen}
|
||||||
formRef={formRef}
|
formRef={formRef}
|
||||||
title={
|
title={
|
||||||
<Flex align="center" justify="center">
|
<Flex align="center" justify="center">
|
||||||
@@ -45,8 +49,9 @@ const AlarmFormConfirm = ({
|
|||||||
layout="horizontal"
|
layout="horizontal"
|
||||||
modalProps={{
|
modalProps={{
|
||||||
destroyOnHidden: true,
|
destroyOnHidden: true,
|
||||||
|
// maskStyle: { backgroundColor: 'rgba(0,0,0,0.1)' },
|
||||||
}}
|
}}
|
||||||
onOpenChange={setModalVisit}
|
onOpenChange={setIsOpen}
|
||||||
request={async () => {
|
request={async () => {
|
||||||
return {
|
return {
|
||||||
name: alarm.name ?? '',
|
name: alarm.name ?? '',
|
||||||
@@ -95,17 +100,20 @@ const AlarmFormConfirm = ({
|
|||||||
return true;
|
return true;
|
||||||
}}
|
}}
|
||||||
trigger={
|
trigger={
|
||||||
|
React.isValidElement(trigger) ? (
|
||||||
|
trigger
|
||||||
|
) : (
|
||||||
<Button
|
<Button
|
||||||
size="small"
|
size="small"
|
||||||
variant="solid"
|
type="primary"
|
||||||
color="green"
|
|
||||||
icon={<CheckOutlined />}
|
icon={<CheckOutlined />}
|
||||||
onClick={() => setModalVisit(true)}
|
onClick={() => setIsOpen(true)}
|
||||||
>
|
>
|
||||||
{intl.formatMessage({
|
{intl.formatMessage({
|
||||||
id: 'common.confirm',
|
id: 'common.confirm',
|
||||||
})}
|
})}
|
||||||
</Button>
|
</Button>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<ProForm.Group>
|
<ProForm.Group>
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
|
import AlarmUnConfirmButton from '@/components/shared/Alarm/AlarmUnConfirmButton';
|
||||||
import ThingsFilter from '@/components/shared/ThingFilterModal';
|
import ThingsFilter from '@/components/shared/ThingFilterModal';
|
||||||
import { DATE_TIME_FORMAT, DEFAULT_PAGE_SIZE, HTTPSTATUS } from '@/constants';
|
import { DATE_TIME_FORMAT, DEFAULT_PAGE_SIZE } from '@/constants';
|
||||||
import {
|
import { apiGetAlarms } from '@/services/master/AlarmController';
|
||||||
apiGetAlarms,
|
|
||||||
apiUnconfirmAlarm,
|
|
||||||
} from '@/services/master/AlarmController';
|
|
||||||
import {
|
import {
|
||||||
CloseOutlined,
|
CloseOutlined,
|
||||||
DeleteOutlined,
|
DeleteOutlined,
|
||||||
@@ -11,7 +9,7 @@ import {
|
|||||||
} from '@ant-design/icons';
|
} from '@ant-design/icons';
|
||||||
import { ActionType, ProColumns, ProTable } from '@ant-design/pro-components';
|
import { ActionType, ProColumns, ProTable } from '@ant-design/pro-components';
|
||||||
import { FormattedMessage, useIntl, useModel } from '@umijs/max';
|
import { FormattedMessage, useIntl, useModel } from '@umijs/max';
|
||||||
import { Button, Flex, message, Popconfirm, Progress, Tooltip } from 'antd';
|
import { Button, Flex, message, Progress, Tooltip } from 'antd';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import { useRef, useState } from 'react';
|
import { useRef, useState } from 'react';
|
||||||
import AlarmDescription from './components/AlarmDescription';
|
import AlarmDescription from './components/AlarmDescription';
|
||||||
@@ -26,7 +24,7 @@ const AlarmPage = () => {
|
|||||||
const [messageApi, contextHolder] = message.useMessage();
|
const [messageApi, contextHolder] = message.useMessage();
|
||||||
const { initialState } = useModel('@@initialState');
|
const { initialState } = useModel('@@initialState');
|
||||||
const { currentUserProfile } = initialState || {};
|
const { currentUserProfile } = initialState || {};
|
||||||
|
const [isConfirmModalOpen, setIsConfirmModalOpen] = useState<boolean>(false);
|
||||||
const columns: ProColumns<MasterModel.Alarm>[] = [
|
const columns: ProColumns<MasterModel.Alarm>[] = [
|
||||||
{
|
{
|
||||||
title: intl.formatMessage({
|
title: intl.formatMessage({
|
||||||
@@ -202,65 +200,22 @@ const AlarmPage = () => {
|
|||||||
return (
|
return (
|
||||||
<Flex gap={10}>
|
<Flex gap={10}>
|
||||||
{alarm?.confirmed || false ? (
|
{alarm?.confirmed || false ? (
|
||||||
<Popconfirm
|
<AlarmUnConfirmButton
|
||||||
title={intl.formatMessage({
|
alarm={alarm}
|
||||||
id: 'master.alarms.unconfirm.body',
|
message={messageApi}
|
||||||
defaultMessage:
|
button={
|
||||||
'Are you sure you want to unconfirm this alarm?',
|
|
||||||
})}
|
|
||||||
okText={intl.formatMessage({
|
|
||||||
id: 'common.yes',
|
|
||||||
defaultMessage: 'Yes',
|
|
||||||
})}
|
|
||||||
cancelText={intl.formatMessage({
|
|
||||||
id: 'common.no',
|
|
||||||
defaultMessage: 'No',
|
|
||||||
})}
|
|
||||||
onConfirm={async () => {
|
|
||||||
const body: MasterModel.ConfirmAlarmRequest = {
|
|
||||||
id: alarm.id,
|
|
||||||
thing_id: alarm.thing_id,
|
|
||||||
time: alarm.time,
|
|
||||||
};
|
|
||||||
try {
|
|
||||||
const resp = await apiUnconfirmAlarm(body);
|
|
||||||
if (resp.status === HTTPSTATUS.HTTP_SUCCESS) {
|
|
||||||
message.success({
|
|
||||||
content: intl.formatMessage({
|
|
||||||
id: 'master.alarms.unconfirm.success',
|
|
||||||
defaultMessage: 'Confirm alarm successfully',
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
tableRef.current?.reload();
|
|
||||||
} else if (resp.status === HTTPSTATUS.HTTP_NOTFOUND) {
|
|
||||||
message.warning({
|
|
||||||
content: intl.formatMessage({
|
|
||||||
id: 'master.alarms.not_found',
|
|
||||||
defaultMessage:
|
|
||||||
'Alarm has expired or does not exist',
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
tableRef.current?.reload();
|
|
||||||
} else {
|
|
||||||
throw new Error('Failed to confirm alarm');
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error when unconfirm alarm: ', error);
|
|
||||||
message.error({
|
|
||||||
content: intl.formatMessage({
|
|
||||||
id: 'master.alarms.unconfirm.fail',
|
|
||||||
defaultMessage: 'Unconfirm alarm failed',
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Button danger icon={<DeleteOutlined />} size="small">
|
<Button danger icon={<DeleteOutlined />} size="small">
|
||||||
<FormattedMessage id="master.alarms.unconfirm.title" />
|
<FormattedMessage id="master.alarms.unconfirm.title" />
|
||||||
</Button>
|
</Button>
|
||||||
</Popconfirm>
|
}
|
||||||
|
onFinish={(isReload) => {
|
||||||
|
if (isReload) tableRef.current?.reload();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
) : (
|
) : (
|
||||||
<AlarmFormConfirm
|
<AlarmFormConfirm
|
||||||
|
isOpen={isConfirmModalOpen}
|
||||||
|
setIsOpen={setIsConfirmModalOpen}
|
||||||
alarm={alarm}
|
alarm={alarm}
|
||||||
message={messageApi}
|
message={messageApi}
|
||||||
onFinish={(isReload) => {
|
onFinish={(isReload) => {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { apiSearchThings } from '@/services/master/ThingController';
|
import { apiGetThingDetail } from '@/services/master/ThingController';
|
||||||
import { wsClient } from '@/utils/wsClient';
|
import { wsClient } from '@/utils/wsClient';
|
||||||
import {
|
import {
|
||||||
ArrowLeftOutlined,
|
ArrowLeftOutlined,
|
||||||
@@ -111,7 +111,7 @@ const CameraConfigPage = () => {
|
|||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
wsClient.connect('wss://gms.smatec.com.vn/mqtt', false);
|
wsClient.connect('/mqtt', false);
|
||||||
const unsubscribe = wsClient.subscribe((data: any) => {
|
const unsubscribe = wsClient.subscribe((data: any) => {
|
||||||
console.log('Received WS data:', data);
|
console.log('Received WS data:', data);
|
||||||
});
|
});
|
||||||
@@ -126,16 +126,8 @@ const CameraConfigPage = () => {
|
|||||||
if (!thingId) return;
|
if (!thingId) return;
|
||||||
try {
|
try {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const response = await apiSearchThings({
|
const thing = await apiGetThingDetail(thingId);
|
||||||
offset: 0,
|
setThingName(thing.name || thingId);
|
||||||
limit: 1,
|
|
||||||
id: thingId,
|
|
||||||
});
|
|
||||||
if (response?.things && response.things.length > 0) {
|
|
||||||
setThingName(response.things[0].name || thingId);
|
|
||||||
} else {
|
|
||||||
setThingName(thingId);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to fetch thing info:', error);
|
console.error('Failed to fetch thing info:', error);
|
||||||
setThingName(thingId);
|
setThingName(thingId);
|
||||||
|
|||||||
105
src/pages/Manager/Device/Detail/components/BinarySensors.tsx
Normal file
105
src/pages/Manager/Device/Detail/components/BinarySensors.tsx
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
import IconFont from '@/components/IconFont';
|
||||||
|
import { StatisticCard } from '@ant-design/pro-components';
|
||||||
|
import { Flex, GlobalToken, Grid, theme } from 'antd';
|
||||||
|
|
||||||
|
type BinarySensorsProps = {
|
||||||
|
nodeConfigs: MasterModel.NodeConfig[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getBinaryEntities = (
|
||||||
|
nodeConfigs: MasterModel.NodeConfig[] = [],
|
||||||
|
): MasterModel.Entity[] =>
|
||||||
|
nodeConfigs.flatMap((nodeConfig) =>
|
||||||
|
nodeConfig.type === 'din'
|
||||||
|
? nodeConfig.entities.filter(
|
||||||
|
(entity) => entity.type === 'bin' && entity.active === 1,
|
||||||
|
)
|
||||||
|
: [],
|
||||||
|
);
|
||||||
|
interface IconTypeResult {
|
||||||
|
iconType: string;
|
||||||
|
color: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const getIconTypeByEntity = (
|
||||||
|
entity: MasterModel.Entity,
|
||||||
|
token: GlobalToken,
|
||||||
|
): IconTypeResult => {
|
||||||
|
if (!entity.config || entity.config.length === 0) {
|
||||||
|
return {
|
||||||
|
iconType: 'icon-device-setting',
|
||||||
|
color: token.colorPrimary,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
switch (entity.config[0].subType) {
|
||||||
|
case 'smoke':
|
||||||
|
return {
|
||||||
|
iconType: 'icon-fire',
|
||||||
|
color: entity.value === 0 ? token.colorSuccess : token.colorWarning,
|
||||||
|
};
|
||||||
|
case 'heat':
|
||||||
|
return {
|
||||||
|
iconType: 'icon-fire',
|
||||||
|
color: entity.value === 0 ? token.colorSuccess : token.colorWarning,
|
||||||
|
};
|
||||||
|
case 'motion':
|
||||||
|
return {
|
||||||
|
iconType: 'icon-motion',
|
||||||
|
color: entity.value === 0 ? token.colorTextBase : token.colorInfoActive,
|
||||||
|
};
|
||||||
|
case 'flood':
|
||||||
|
return {
|
||||||
|
iconType: 'icon-water-ingress',
|
||||||
|
color: entity.value === 0 ? token.colorSuccess : token.colorWarning,
|
||||||
|
};
|
||||||
|
case 'door':
|
||||||
|
return {
|
||||||
|
iconType: entity.value === 0 ? 'icon-door' : 'icon-door-open',
|
||||||
|
color: entity.value === 0 ? token.colorText : token.colorWarning,
|
||||||
|
};
|
||||||
|
case 'button':
|
||||||
|
return {
|
||||||
|
iconType: 'icon-alarm-button',
|
||||||
|
color: entity.value === 0 ? token.colorText : token.colorSuccess,
|
||||||
|
};
|
||||||
|
default:
|
||||||
|
return {
|
||||||
|
iconType: 'icon-door',
|
||||||
|
color: token.colorPrimary,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const StatisticCardItem = (entity: MasterModel.Entity, token: GlobalToken) => {
|
||||||
|
const { iconType, color } = getIconTypeByEntity(entity, token);
|
||||||
|
return (
|
||||||
|
<StatisticCard
|
||||||
|
key={entity.entityId}
|
||||||
|
statistic={{
|
||||||
|
title: entity.name,
|
||||||
|
icon: (
|
||||||
|
<IconFont type={iconType} style={{ color: color, fontSize: 24 }} />
|
||||||
|
),
|
||||||
|
value: entity.active === 1 ? 'Active' : 'Inactive',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const BinarySensors = ({ nodeConfigs }: BinarySensorsProps) => {
|
||||||
|
const binarySensors = getBinaryEntities(nodeConfigs);
|
||||||
|
console.log('BinarySensor: ', binarySensors);
|
||||||
|
|
||||||
|
const { token } = theme.useToken();
|
||||||
|
const { useBreakpoint } = Grid;
|
||||||
|
const screens = useBreakpoint();
|
||||||
|
return (
|
||||||
|
<Flex wrap="wrap">
|
||||||
|
<StatisticCard.Group direction={screens.sm ? 'row' : 'column'}>
|
||||||
|
{binarySensors.map((entity) => StatisticCardItem(entity, token))}
|
||||||
|
</StatisticCard.Group>
|
||||||
|
</Flex>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default BinarySensors;
|
||||||
34
src/pages/Manager/Device/Detail/components/ThingTitle.tsx
Normal file
34
src/pages/Manager/Device/Detail/components/ThingTitle.tsx
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import { getBadgeConnection } from '@/components/shared/ThingShared';
|
||||||
|
import { useIntl } from '@umijs/max';
|
||||||
|
import { Flex, Typography } from 'antd';
|
||||||
|
import moment from 'moment';
|
||||||
|
const { Text, Title } = Typography;
|
||||||
|
const ThingTitle = ({ thing }: { thing: MasterModel.Thing | null }) => {
|
||||||
|
const intl = useIntl();
|
||||||
|
if (thing === null) {
|
||||||
|
return <Text>{intl.formatMessage({ id: 'common.undefined' })}</Text>;
|
||||||
|
}
|
||||||
|
|
||||||
|
const connectionDuration = thing.metadata!.connected
|
||||||
|
? thing.metadata!.uptime! * 1000
|
||||||
|
: (Math.round(new Date().getTime() / 1000) -
|
||||||
|
thing.metadata!.updated_time!) *
|
||||||
|
1000;
|
||||||
|
return (
|
||||||
|
<Flex gap={10}>
|
||||||
|
<Title level={4} style={{ margin: 0 }}>
|
||||||
|
{thing.name || intl.formatMessage({ id: 'common.undefined' })}
|
||||||
|
</Title>
|
||||||
|
<Flex gap={5} align="center" justify="center">
|
||||||
|
{getBadgeConnection(thing.metadata!.connected || false)}
|
||||||
|
<Text type={thing.metadata?.connected ? undefined : 'secondary'}>
|
||||||
|
{connectionDuration > 0
|
||||||
|
? moment.duration(connectionDuration).humanize()
|
||||||
|
: ''}
|
||||||
|
</Text>
|
||||||
|
</Flex>
|
||||||
|
</Flex>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ThingTitle;
|
||||||
115
src/pages/Manager/Device/Detail/index.tsx
Normal file
115
src/pages/Manager/Device/Detail/index.tsx
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
import DeviceAlarmList from '@/components/shared/DeviceAlarmList';
|
||||||
|
import TooltipIconFontButton from '@/components/shared/TooltipIconFontButton';
|
||||||
|
import { ROUTER_HOME } from '@/constants/routes';
|
||||||
|
import { apiQueryNodeConfigMessage } from '@/services/master/MessageController';
|
||||||
|
import { apiGetThingDetail } from '@/services/master/ThingController';
|
||||||
|
import { PageContainer, ProCard } from '@ant-design/pro-components';
|
||||||
|
import { history, useIntl, useModel, useParams } from '@umijs/max';
|
||||||
|
import { Grid } from 'antd';
|
||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import BinarySensors from './components/BinarySensors';
|
||||||
|
import ThingTitle from './components/ThingTitle';
|
||||||
|
|
||||||
|
const DetailDevicePage = () => {
|
||||||
|
const { thingId } = useParams();
|
||||||
|
const [thing, setThing] = useState<MasterModel.Thing | null>(null);
|
||||||
|
const [isLoading, setIsLoading] = useState<boolean>(false);
|
||||||
|
const { initialState } = useModel('@@initialState');
|
||||||
|
const { useBreakpoint } = Grid;
|
||||||
|
const screens = useBreakpoint();
|
||||||
|
const intl = useIntl();
|
||||||
|
const [nodeConfigs, setNodeConfigs] = useState<MasterModel.NodeConfig[]>([]);
|
||||||
|
const getThingDetail = async () => {
|
||||||
|
setIsLoading(true);
|
||||||
|
try {
|
||||||
|
const thing = await apiGetThingDetail(thingId || '');
|
||||||
|
setThing(thing);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error when get Thing: ', error);
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const getDeviceConfig = async () => {
|
||||||
|
try {
|
||||||
|
const resp = await apiQueryNodeConfigMessage(
|
||||||
|
thing?.metadata?.data_channel_id || '',
|
||||||
|
initialState?.currentUserProfile?.metadata?.frontend_thing_key || '',
|
||||||
|
{
|
||||||
|
offset: 0,
|
||||||
|
limit: 1,
|
||||||
|
subtopic: `config.${thing?.metadata?.type}.node`,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
if (resp.messages && resp.messages.length > 0) {
|
||||||
|
console.log('Node Configs: ', resp.messages[0].string_value_parsed);
|
||||||
|
|
||||||
|
setNodeConfigs(resp.messages[0].string_value_parsed ?? []);
|
||||||
|
}
|
||||||
|
} catch (error) {}
|
||||||
|
};
|
||||||
|
useEffect(() => {
|
||||||
|
if (thingId) {
|
||||||
|
getThingDetail();
|
||||||
|
}
|
||||||
|
}, [thingId]);
|
||||||
|
useEffect(() => {
|
||||||
|
if (thing) {
|
||||||
|
getDeviceConfig();
|
||||||
|
}
|
||||||
|
}, [thing]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<PageContainer
|
||||||
|
title={isLoading ? 'Loading...' : <ThingTitle thing={thing} />}
|
||||||
|
header={{
|
||||||
|
onBack: () => history.push(ROUTER_HOME),
|
||||||
|
breadcrumb: undefined,
|
||||||
|
}}
|
||||||
|
extra={[
|
||||||
|
<TooltipIconFontButton
|
||||||
|
key="logs"
|
||||||
|
tooltip="Nhật ký"
|
||||||
|
iconFontName="icon-system-diary"
|
||||||
|
shape="circle"
|
||||||
|
size="middle"
|
||||||
|
onClick={() => {}}
|
||||||
|
/>,
|
||||||
|
<TooltipIconFontButton
|
||||||
|
key="notifications"
|
||||||
|
tooltip="Thông báo"
|
||||||
|
iconFontName="icon-bell"
|
||||||
|
shape="circle"
|
||||||
|
size="middle"
|
||||||
|
onClick={() => {}}
|
||||||
|
/>,
|
||||||
|
<TooltipIconFontButton
|
||||||
|
key="settings"
|
||||||
|
tooltip="Cài đặt"
|
||||||
|
iconFontName="icon-setting-device"
|
||||||
|
shape="circle"
|
||||||
|
size="middle"
|
||||||
|
onClick={() => {}}
|
||||||
|
/>,
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<ProCard split={screens.md ? 'vertical' : 'horizontal'}>
|
||||||
|
<ProCard
|
||||||
|
title={intl.formatMessage({
|
||||||
|
id: 'master.thing.detail.alarmList.title',
|
||||||
|
})}
|
||||||
|
colSpan={{ xs: 24, sm: 24, md: 24, lg: 6, xl: 6 }}
|
||||||
|
bodyStyle={{ paddingInline: 0, paddingBlock: 0 }}
|
||||||
|
bordered
|
||||||
|
>
|
||||||
|
<DeviceAlarmList key="thing-alarms-key" thingId={thingId || ''} />
|
||||||
|
</ProCard>
|
||||||
|
<ProCard>
|
||||||
|
<BinarySensors nodeConfigs={nodeConfigs} />
|
||||||
|
</ProCard>
|
||||||
|
</ProCard>
|
||||||
|
</PageContainer>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default DetailDevicePage;
|
||||||
@@ -5,6 +5,7 @@ import {
|
|||||||
} from '@/components/shared/ThingShared';
|
} from '@/components/shared/ThingShared';
|
||||||
import TreeGroup from '@/components/shared/TreeGroup';
|
import TreeGroup from '@/components/shared/TreeGroup';
|
||||||
import { DEFAULT_PAGE_SIZE } from '@/constants';
|
import { DEFAULT_PAGE_SIZE } from '@/constants';
|
||||||
|
import { ROUTE_MANAGER_DEVICES } from '@/constants/routes';
|
||||||
import { apiSearchThings } from '@/services/master/ThingController';
|
import { apiSearchThings } from '@/services/master/ThingController';
|
||||||
import {
|
import {
|
||||||
ActionType,
|
ActionType,
|
||||||
@@ -12,12 +13,12 @@ import {
|
|||||||
ProColumns,
|
ProColumns,
|
||||||
ProTable,
|
ProTable,
|
||||||
} from '@ant-design/pro-components';
|
} from '@ant-design/pro-components';
|
||||||
import { FormattedMessage, useIntl } from '@umijs/max';
|
import { FormattedMessage, history, useIntl } from '@umijs/max';
|
||||||
import { Flex, Grid, theme, Typography } from 'antd';
|
import { Flex, Grid, theme, Typography } from 'antd';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import React, { useRef, useState } from 'react';
|
import React, { useRef, useState } from 'react';
|
||||||
import { TagStateCallbackPayload } from '../../SGW/Map/type';
|
import { TagStateCallbackPayload } from '../../SGW/Map/type';
|
||||||
const { Text } = Typography;
|
const { Text, Link } = Typography;
|
||||||
const SpoleHome: React.FC = () => {
|
const SpoleHome: React.FC = () => {
|
||||||
const { useBreakpoint } = Grid;
|
const { useBreakpoint } = Grid;
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
@@ -39,9 +40,6 @@ const SpoleHome: React.FC = () => {
|
|||||||
{
|
{
|
||||||
key: 'name',
|
key: 'name',
|
||||||
ellipsis: true,
|
ellipsis: true,
|
||||||
title: (
|
|
||||||
<FormattedMessage id="master.devices.name" defaultMessage="Name" />
|
|
||||||
),
|
|
||||||
tip: intl.formatMessage({
|
tip: intl.formatMessage({
|
||||||
id: 'master.devices.name.tip',
|
id: 'master.devices.name.tip',
|
||||||
defaultMessage: 'The device name',
|
defaultMessage: 'The device name',
|
||||||
@@ -49,6 +47,20 @@ const SpoleHome: React.FC = () => {
|
|||||||
dataIndex: 'name',
|
dataIndex: 'name',
|
||||||
hideInSearch: true,
|
hideInSearch: true,
|
||||||
copyable: true,
|
copyable: true,
|
||||||
|
render: (_, row) => {
|
||||||
|
return (
|
||||||
|
<Link
|
||||||
|
copyable
|
||||||
|
onClick={() => history.push(`${ROUTE_MANAGER_DEVICES}/${row.id}`)}
|
||||||
|
>
|
||||||
|
{row.name ||
|
||||||
|
intl.formatMessage({
|
||||||
|
id: 'common.undefined',
|
||||||
|
defaultMessage: 'Undefined',
|
||||||
|
})}
|
||||||
|
</Link>
|
||||||
|
);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'connected',
|
key: 'connected',
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import { API_LOGS } from '@/constants/api';
|
import { API_READER } from '@/constants/api';
|
||||||
import { request } from '@umijs/max';
|
import { request } from '@umijs/max';
|
||||||
|
|
||||||
export async function apiQueryLogs(
|
export async function apiQueryLogs(
|
||||||
params: MasterModel.SearchLogPaginationBody,
|
params: MasterModel.SearchLogPaginationBody,
|
||||||
type: MasterModel.LogTypeRequest,
|
type: MasterModel.LogTypeRequest,
|
||||||
) {
|
) {
|
||||||
return request<MasterModel.LogResponse>(`${API_LOGS}/${type}/messages`, {
|
return request<MasterModel.LogResponse>(`${API_READER}/${type}/messages`, {
|
||||||
params: params,
|
params: params,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
147
src/services/master/MessageController.ts
Normal file
147
src/services/master/MessageController.ts
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
import { API_READER } from '@/constants/api';
|
||||||
|
import { request } from '@umijs/max';
|
||||||
|
|
||||||
|
// Transform functions
|
||||||
|
function transformEntityConfigChildDetail(
|
||||||
|
raw: MasterModel.PurpleC,
|
||||||
|
): MasterModel.EntityConfigChildDetail {
|
||||||
|
return {
|
||||||
|
entityId: raw.eid || '',
|
||||||
|
value: raw.v,
|
||||||
|
operation: raw.op,
|
||||||
|
duration: raw.for,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function transformEntityConfigChild(
|
||||||
|
raw: MasterModel.CElement,
|
||||||
|
): MasterModel.EntityConfigChild {
|
||||||
|
return {
|
||||||
|
type: raw.t || '',
|
||||||
|
children: raw.c ? [transformEntityConfigChildDetail(raw.c)] : undefined,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function transformEntityConfig(raw: MasterModel.EC): MasterModel.EntityConfig {
|
||||||
|
return {
|
||||||
|
level: raw.l as 0 | 1 | 2 | undefined,
|
||||||
|
normalCondition: raw.nc,
|
||||||
|
subType: raw.st,
|
||||||
|
children: raw.c?.map(transformEntityConfigChild),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function transformEntity(raw: MasterModel.E): MasterModel.Entity {
|
||||||
|
return {
|
||||||
|
entityId: raw.eid || '',
|
||||||
|
type: raw.t || '',
|
||||||
|
name: raw.n || '',
|
||||||
|
active: raw.a,
|
||||||
|
value: raw.v,
|
||||||
|
config: raw.c ? [transformEntityConfig(raw.c)] : undefined,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function transformNodeConfig(
|
||||||
|
raw: MasterModel.RawNodeConfig,
|
||||||
|
): MasterModel.NodeConfig {
|
||||||
|
return {
|
||||||
|
nodeId: raw.nid || '',
|
||||||
|
type: raw.t || '',
|
||||||
|
name: raw.n || '',
|
||||||
|
entities: raw.e?.map(transformEntity) || [],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reverse transform functions
|
||||||
|
function reverseTransformEntityConfigChildDetail(
|
||||||
|
detail: MasterModel.EntityConfigChildDetail,
|
||||||
|
): MasterModel.PurpleC {
|
||||||
|
return {
|
||||||
|
eid: detail.entityId,
|
||||||
|
v: detail.value,
|
||||||
|
op: detail.operation,
|
||||||
|
for: detail.duration,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function reverseTransformEntityConfigChild(
|
||||||
|
child: MasterModel.EntityConfigChild,
|
||||||
|
): MasterModel.CElement {
|
||||||
|
return {
|
||||||
|
t: child.type,
|
||||||
|
c: child.children?.[0]
|
||||||
|
? reverseTransformEntityConfigChildDetail(child.children[0])
|
||||||
|
: undefined,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function reverseTransformEntityConfig(
|
||||||
|
raw: MasterModel.EntityConfig,
|
||||||
|
): MasterModel.EC {
|
||||||
|
return {
|
||||||
|
l: raw.level,
|
||||||
|
nc: raw.normalCondition,
|
||||||
|
st: raw.subType,
|
||||||
|
c: raw.children?.map(reverseTransformEntityConfigChild),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function reverseTransformEntity(entity: MasterModel.Entity): MasterModel.E {
|
||||||
|
return {
|
||||||
|
eid: entity.entityId,
|
||||||
|
t: entity.type,
|
||||||
|
n: entity.name,
|
||||||
|
a: entity.active,
|
||||||
|
v: entity.value,
|
||||||
|
c: entity.config?.[0]
|
||||||
|
? reverseTransformEntityConfig(entity.config[0])
|
||||||
|
: undefined,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function transformRawNodeConfig(
|
||||||
|
node: MasterModel.NodeConfig,
|
||||||
|
): MasterModel.RawNodeConfig {
|
||||||
|
return {
|
||||||
|
nid: node.nodeId,
|
||||||
|
t: node.type,
|
||||||
|
n: node.name,
|
||||||
|
e: node.entities.map(reverseTransformEntity),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function apiQueryNodeConfigMessage(
|
||||||
|
dataChanelId: string,
|
||||||
|
authorization: string,
|
||||||
|
params: MasterModel.SearchMessagePaginationBody,
|
||||||
|
) {
|
||||||
|
const resp = await request<
|
||||||
|
MasterModel.MesageReaderResponse<MasterModel.NodeConfig[]>
|
||||||
|
>(`${API_READER}/${dataChanelId}/messages`, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
Authorization: authorization,
|
||||||
|
},
|
||||||
|
params: params,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Process messages to add string_value_parsed
|
||||||
|
if (resp.messages) {
|
||||||
|
resp.messages = resp.messages.map((message) => {
|
||||||
|
if (message.string_value) {
|
||||||
|
try {
|
||||||
|
const rawNodeConfigs: MasterModel.RawNodeConfig[] = JSON.parse(
|
||||||
|
message.string_value,
|
||||||
|
);
|
||||||
|
message.string_value_parsed = rawNodeConfigs.map(transformNodeConfig);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to parse string_value:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return message;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp;
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
API_SHARE_THING,
|
API_THING,
|
||||||
API_THING_POLICY,
|
API_THING_POLICY,
|
||||||
API_THINGS_SEARCH,
|
API_THINGS_SEARCH,
|
||||||
} from '@/constants/api';
|
} from '@/constants/api';
|
||||||
@@ -55,7 +55,7 @@ export async function apiSearchThings(
|
|||||||
|
|
||||||
export async function apiUpdateThing(value: MasterModel.Thing) {
|
export async function apiUpdateThing(value: MasterModel.Thing) {
|
||||||
if (!value.id) throw new Error('Thing id is required');
|
if (!value.id) throw new Error('Thing id is required');
|
||||||
return request<MasterModel.Thing>(`${API_SHARE_THING}/${value.id}`, {
|
return request<MasterModel.Thing>(`${API_THING}/${value.id}`, {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
data: value,
|
data: value,
|
||||||
});
|
});
|
||||||
@@ -77,7 +77,7 @@ export async function apiDeleteUserThingPolicy(
|
|||||||
thing_id: string,
|
thing_id: string,
|
||||||
user_id: string,
|
user_id: string,
|
||||||
) {
|
) {
|
||||||
return request(`${API_SHARE_THING}/${thing_id}/share`, {
|
return request(`${API_THING}/${thing_id}/share`, {
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
data: {
|
data: {
|
||||||
policies: ['read', 'write', 'delete'],
|
policies: ['read', 'write', 'delete'],
|
||||||
@@ -91,7 +91,7 @@ export async function apiShareThingToUser(
|
|||||||
user_id: string,
|
user_id: string,
|
||||||
policies: string[],
|
policies: string[],
|
||||||
) {
|
) {
|
||||||
return request(`${API_SHARE_THING}/${thing_id}/share`, {
|
return request(`${API_THING}/${thing_id}/share`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: {
|
data: {
|
||||||
policies: policies,
|
policies: policies,
|
||||||
@@ -100,3 +100,7 @@ export async function apiShareThingToUser(
|
|||||||
getResponse: true,
|
getResponse: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function apiGetThingDetail(thing_id: string) {
|
||||||
|
return request<MasterModel.Thing>(`${API_THING}/${thing_id}`);
|
||||||
|
}
|
||||||
|
|||||||
40
src/services/master/typings/log.d.ts
vendored
40
src/services/master/typings/log.d.ts
vendored
@@ -8,7 +8,7 @@ declare namespace MasterModel {
|
|||||||
|
|
||||||
type LogTypeRequest = 'user_logs' | undefined;
|
type LogTypeRequest = 'user_logs' | undefined;
|
||||||
|
|
||||||
interface LogResponse {
|
interface MesageReaderResponse<T = MessageDataType> {
|
||||||
offset?: number;
|
offset?: number;
|
||||||
limit?: number;
|
limit?: number;
|
||||||
publisher?: string;
|
publisher?: string;
|
||||||
@@ -16,10 +16,17 @@ declare namespace MasterModel {
|
|||||||
to?: number;
|
to?: number;
|
||||||
format?: string;
|
format?: string;
|
||||||
total?: number;
|
total?: number;
|
||||||
messages?: Message[];
|
messages?: Message<T>[];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Message {
|
// Response types cho từng domain
|
||||||
|
type CameraMessageResponse = MesageReaderResponse<CameraV5>;
|
||||||
|
type CameraV6MessageResponse = MesageReaderResponse<CameraV6>;
|
||||||
|
type NodeConfigMessageResponse = MesageReaderResponse<NodeConfig[]>;
|
||||||
|
|
||||||
|
type MessageDataType = NodeConfig[] | CameraV5 | CameraV6;
|
||||||
|
|
||||||
|
interface Message<T = MessageDataType> {
|
||||||
channel?: string;
|
channel?: string;
|
||||||
subtopic?: string;
|
subtopic?: string;
|
||||||
publisher?: string;
|
publisher?: string;
|
||||||
@@ -27,5 +34,32 @@ declare namespace MasterModel {
|
|||||||
name?: string;
|
name?: string;
|
||||||
time?: number;
|
time?: number;
|
||||||
string_value?: string;
|
string_value?: string;
|
||||||
|
string_value_parsed?: T;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Message types cho từng domain
|
||||||
|
type CameraMessage = Message<CameraV5>;
|
||||||
|
type CameraV6Message = Message<CameraV6>;
|
||||||
|
type NodeConfigMessage = Message<NodeConfig[]>;
|
||||||
|
|
||||||
|
interface CameraV5 {
|
||||||
|
cams?: Camera[];
|
||||||
|
}
|
||||||
|
interface CameraV6 extends CameraV5 {
|
||||||
|
record_type?: string;
|
||||||
|
record_alarm_list?: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Camera {
|
||||||
|
id?: string;
|
||||||
|
name?: string;
|
||||||
|
cate_id?: string;
|
||||||
|
username?: string;
|
||||||
|
password?: string;
|
||||||
|
rtsp_port?: number;
|
||||||
|
http_port?: number;
|
||||||
|
channel?: number;
|
||||||
|
ip?: string;
|
||||||
|
stream?: number;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
101
src/services/master/typings/message.d.ts
vendored
Normal file
101
src/services/master/typings/message.d.ts
vendored
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
declare namespace MasterModel {
|
||||||
|
interface SearchMessagePaginationBody extends SearchPaginationBody {
|
||||||
|
subtopic?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface RawNodeConfig {
|
||||||
|
nid?: string;
|
||||||
|
t?: string;
|
||||||
|
n?: string;
|
||||||
|
e?: E[];
|
||||||
|
}
|
||||||
|
interface E {
|
||||||
|
eid?: string;
|
||||||
|
t?: string;
|
||||||
|
n?: string;
|
||||||
|
a?: number;
|
||||||
|
v?: number;
|
||||||
|
c?: EC;
|
||||||
|
vs?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface EC {
|
||||||
|
l?: number;
|
||||||
|
nc?: number;
|
||||||
|
st?: string;
|
||||||
|
c?: CElement[];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface CElement {
|
||||||
|
t?: string;
|
||||||
|
c?: PurpleC;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface PurpleC {
|
||||||
|
eid?: string;
|
||||||
|
v?: number;
|
||||||
|
op?: number;
|
||||||
|
for?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Interface Tranformed RawNodeConfig
|
||||||
|
|
||||||
|
interface NodeConfig {
|
||||||
|
/** Node ID - Định danh duy nhất */
|
||||||
|
nodeId: string;
|
||||||
|
/** Type - Loại thiết bị */
|
||||||
|
type: string;
|
||||||
|
/** Name - Tên hiển thị */
|
||||||
|
name: string;
|
||||||
|
/** Entities - Danh sách cảm biến */
|
||||||
|
entities: Entity[];
|
||||||
|
}
|
||||||
|
interface Entity {
|
||||||
|
/** Entity ID - Định danh duy nhất của cảm biến */
|
||||||
|
entityId: string;
|
||||||
|
/** Type - Loại cảm biến (vd: 'bin' - nhị phân 0/1, 'bin_t' - nhị phân có trigger) */
|
||||||
|
type: string;
|
||||||
|
/** Name - Tên hiển thị */
|
||||||
|
name: string;
|
||||||
|
/** Active - Đã kích hoạt cảm biến này hay chưa (1=đã kích hoạt, 0=chưa kích hoạt) */
|
||||||
|
active?: number;
|
||||||
|
/** Value - Giá trị hiện tại (1=có, 0=không) */
|
||||||
|
value?: number;
|
||||||
|
/** EntityConfig - Cấu hình bổ sung */
|
||||||
|
config?: EntityConfig[];
|
||||||
|
}
|
||||||
|
interface EntityConfig {
|
||||||
|
/** Level - Mức độ cảnh báo
|
||||||
|
0 = info,
|
||||||
|
1 = warning,
|
||||||
|
2 = critical */
|
||||||
|
level?: 0 | 1 | 2;
|
||||||
|
/** Normal Condition - Điều kiện bình thường */
|
||||||
|
normalCondition?: number;
|
||||||
|
/** SubType - Phân loại chi tiết */
|
||||||
|
subType?: string;
|
||||||
|
/** Children - Các cấu hình con */
|
||||||
|
children?: EntityConfigChild[];
|
||||||
|
}
|
||||||
|
interface EntityConfigChild {
|
||||||
|
/** Type - Loại điều kiện */
|
||||||
|
type: string;
|
||||||
|
children?: EntityConfigChildDetail[];
|
||||||
|
}
|
||||||
|
interface EntityConfigChildDetail {
|
||||||
|
/** entity ID - Cảm biến được theo dõi */
|
||||||
|
entityId: string;
|
||||||
|
/** Value - Ngưỡng giá trị */
|
||||||
|
value?: number;
|
||||||
|
/** Operation - Toán tử so sánh:
|
||||||
|
* 0 = == (bằng)
|
||||||
|
* 1 = != (khác)
|
||||||
|
* 2 = > (lớn hơn)
|
||||||
|
* 3 = >= (lớn hơn hoặc bằng)
|
||||||
|
* 4 = < (nhỏ hơn)
|
||||||
|
* 5 = <= (nhỏ hơn hoặc bằng) */
|
||||||
|
operation?: number;
|
||||||
|
/** Duration - Thời gian duy trì (giây) */
|
||||||
|
duration?: number;
|
||||||
|
}
|
||||||
|
}
|
||||||
1
src/services/master/typings/thing.d.ts
vendored
1
src/services/master/typings/thing.d.ts
vendored
@@ -30,6 +30,7 @@ declare namespace MasterModel {
|
|||||||
state_updated_time?: number;
|
state_updated_time?: number;
|
||||||
type?: string;
|
type?: string;
|
||||||
updated_time?: number;
|
updated_time?: number;
|
||||||
|
uptime?: number;
|
||||||
lat?: string;
|
lat?: string;
|
||||||
lng?: string;
|
lng?: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class WSClient {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Kết nối tới WebSocket server.
|
* Kết nối tới WebSocket server.
|
||||||
* @param url Địa chỉ WebSocket server
|
* @param url Địa chỉ WebSocket server (có thể là relative path như /mqtt)
|
||||||
* @param isAuthenticated Có sử dụng token xác thực hay không
|
* @param isAuthenticated Có sử dụng token xác thực hay không
|
||||||
*/
|
*/
|
||||||
connect(url: string, isAuthenticated: boolean) {
|
connect(url: string, isAuthenticated: boolean) {
|
||||||
@@ -18,7 +18,13 @@ class WSClient {
|
|||||||
if (isAuthenticated) {
|
if (isAuthenticated) {
|
||||||
token = getToken();
|
token = getToken();
|
||||||
}
|
}
|
||||||
const wsUrl = isAuthenticated ? `${url}?token=${token}` : url;
|
let wsUrl = url;
|
||||||
|
if (url.startsWith('/')) {
|
||||||
|
// Relative path, prepend base WebSocket URL
|
||||||
|
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||||
|
wsUrl = `${protocol}//${window.location.host}${url}`;
|
||||||
|
}
|
||||||
|
wsUrl = isAuthenticated ? `${wsUrl}?token=${token}` : wsUrl;
|
||||||
this.ws = new ReconnectingWebSocket(wsUrl, [], {
|
this.ws = new ReconnectingWebSocket(wsUrl, [], {
|
||||||
maxRetries: 10,
|
maxRetries: 10,
|
||||||
maxReconnectionDelay: 10000,
|
maxReconnectionDelay: 10000,
|
||||||
|
|||||||
Reference in New Issue
Block a user