index.tsx 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import { observer } from '@formily/react';
  2. import { Space, Tabs, Tooltip } from 'antd';
  3. import BaseMetadata from './Base';
  4. import { useIntl } from '@@/plugin-locale/localeExports';
  5. import Import from './Import';
  6. import type { ReactNode } from 'react';
  7. import { useState } from 'react';
  8. import Cat from './Cat';
  9. import Service from '@/pages/device/components/Metadata/service';
  10. import { InfoCircleOutlined } from '@ant-design/icons';
  11. import styles from './index.less';
  12. import { InstanceModel, service as instanceService } from '@/pages/device/Instance';
  13. import { PermissionButton } from '@/components';
  14. import { Store } from 'jetlinks-store';
  15. import SystemConst from '@/utils/const';
  16. import { useParams } from 'umi';
  17. import { onlyMessage } from '@/utils/util';
  18. interface Props {
  19. tabAction?: ReactNode;
  20. type: 'product' | 'device';
  21. independentMetadata?: boolean;
  22. }
  23. export const service = new Service();
  24. const Metadata = observer((props: Props) => {
  25. const intl = useIntl();
  26. const [visible, setVisible] = useState<boolean>(false);
  27. const [cat, setCat] = useState<boolean>(false);
  28. const { permission } = PermissionButton.usePermission(
  29. props.type === 'device' ? 'device/Instance' : 'device/Product',
  30. );
  31. const params = useParams<{ id: string }>();
  32. const resetMetadata = async () => {
  33. const resp = await instanceService.deleteMetadata(params.id);
  34. if (resp.status === 200) {
  35. const res = await instanceService.detail(params.id);
  36. if (res.status === 200) {
  37. InstanceModel.detail = res?.result || [];
  38. }
  39. onlyMessage('操作成功');
  40. Store.set(SystemConst.REFRESH_DEVICE, true);
  41. setTimeout(() => {
  42. Store.set(SystemConst.REFRESH_METADATA_TABLE, true);
  43. }, 400);
  44. }
  45. };
  46. return (
  47. <div className={'device-detail-metadata'} style={{ position: 'relative' }}>
  48. <div className={styles.tips} style={{ width: 'calc(100% - 670px)' }}>
  49. <Tooltip
  50. title={
  51. InstanceModel.detail?.independentMetadata && props.type === 'device'
  52. ? '该设备已脱离产品物模型,修改产品物模型对该设备无影响'
  53. : '设备会默认继承产品的物模型,修改设备物模型后将脱离产品物模型'
  54. }
  55. >
  56. <div className={'ellipsis'}>
  57. <InfoCircleOutlined style={{ marginRight: '3px' }} />
  58. {InstanceModel.detail?.independentMetadata && props.type === 'device'
  59. ? '该设备已脱离产品物模型,修改产品物模型对该设备无影响'
  60. : '设备会默认继承产品的物模型,修改设备物模型后将脱离产品物模型'}
  61. </div>
  62. </Tooltip>
  63. </div>
  64. <Tabs
  65. className={styles.metadataNav}
  66. type="card"
  67. tabBarExtraContent={
  68. <Space>
  69. {InstanceModel.detail?.independentMetadata && props.type === 'device' && (
  70. <PermissionButton
  71. isPermission={permission.update}
  72. popConfirm={{
  73. title: '确认重置?',
  74. onConfirm: resetMetadata,
  75. }}
  76. tooltip={{
  77. title: '重置后将使用产品的物模型配置',
  78. }}
  79. key={'reload'}
  80. >
  81. 重置操作
  82. </PermissionButton>
  83. )}
  84. <PermissionButton isPermission={permission.update} onClick={() => setVisible(true)}>
  85. {intl.formatMessage({
  86. id: 'pages.device.productDetail.metadata.quickImport',
  87. defaultMessage: '快速导入',
  88. })}
  89. </PermissionButton>
  90. <PermissionButton isPermission={true} onClick={() => setCat(true)}>
  91. {intl.formatMessage({
  92. id: 'pages.device.productDetail.metadata',
  93. defaultMessage: '物模型TSL',
  94. })}
  95. TSL
  96. </PermissionButton>
  97. </Space>
  98. }
  99. destroyInactiveTabPane
  100. >
  101. <Tabs.TabPane
  102. tab={intl.formatMessage({
  103. id: 'pages.device.productDetail.metadata.propertyDefinition',
  104. defaultMessage: '属性定义',
  105. })}
  106. key="properties"
  107. >
  108. <BaseMetadata target={props.type} type={'properties'} permission={permission} />
  109. </Tabs.TabPane>
  110. <Tabs.TabPane
  111. tab={intl.formatMessage({
  112. id: 'pages.device.productDetail.metadata.functionDefinition',
  113. defaultMessage: '功能定义',
  114. })}
  115. key="functions"
  116. >
  117. <BaseMetadata target={props.type} type={'functions'} permission={permission} />
  118. </Tabs.TabPane>
  119. <Tabs.TabPane
  120. tab={intl.formatMessage({
  121. id: 'pages.device.productDetail.metadata.eventDefinition',
  122. defaultMessage: '事件定义',
  123. })}
  124. key="events"
  125. >
  126. <BaseMetadata target={props.type} type={'events'} permission={permission} />
  127. </Tabs.TabPane>
  128. <Tabs.TabPane
  129. tab={intl.formatMessage({
  130. id: 'pages.device.productDetail.metadata.tagDefinition',
  131. defaultMessage: '标签定义',
  132. })}
  133. key="tags"
  134. >
  135. <BaseMetadata target={props.type} type={'tags'} permission={permission} />
  136. </Tabs.TabPane>
  137. </Tabs>
  138. <Import visible={visible} type={props.type} close={() => setVisible(false)} />
  139. <Cat visible={cat} close={() => setCat(false)} type={props.type} />
  140. </div>
  141. );
  142. });
  143. export default Metadata;