VerifyProtocol.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <script setup lang="ts">
  2. import { onMounted, ref } from 'vue';
  3. import { useRequest } from '@/hooks/request';
  4. import { t } from '@/i18n';
  5. import { gatewayLinkGetList, gatewayLinkList, gatewayLinkProtocolList } from '@/api';
  6. import type {
  7. InterfaceData,
  8. ProtocolListPageItem,
  9. ProtocolListPageItemData,
  10. RegisterGatewayForm,
  11. UseGuideStepItemProps,
  12. VerificationAgreement,
  13. } from '@/types';
  14. const activeKey = ref();
  15. const interfaceValue = ref<number>(0);
  16. const { handleRequest } = useRequest();
  17. let interfaceList: InterfaceData[];
  18. interface InterfaceItem {
  19. id: number;
  20. baudRate: number;
  21. dataBit: number;
  22. stopBit: string;
  23. parityBit: string;
  24. protocolType: string;
  25. }
  26. interface ItemList {
  27. value: number;
  28. payload: string;
  29. id: number;
  30. baudRate: number;
  31. dataBit: number;
  32. stopBit: string;
  33. parityBit: string;
  34. protocolType: string;
  35. }
  36. const interfaceData = ref<ItemList[]>([]);
  37. const interfaceItem = ref<InterfaceItem>();
  38. const verificationAgreement = ref<VerificationAgreement[]>([]);
  39. const protocolList = ref<ProtocolListPageItem[]>([]);
  40. const props = defineProps<UseGuideStepItemProps<RegisterGatewayForm>>();
  41. const protocolColumns = [
  42. {
  43. title: t('setupProtocol.protocolParamFields.paramName'),
  44. dataIndex: 'paramName',
  45. key: 'paramName',
  46. },
  47. {
  48. title: t('setupProtocol.protocolParamFields.paramCode'),
  49. dataIndex: 'paramCode',
  50. key: 'paramCode',
  51. },
  52. {
  53. title: t('registerGateway.monitoringResults'),
  54. dataIndex: 'deviceType',
  55. key: 'deviceType',
  56. },
  57. {
  58. title: t('registerGateway.resultData'),
  59. dataIndex: 'deviceType',
  60. key: 'deviceType',
  61. },
  62. ];
  63. const interfaceAdd = (value: number | string) => {
  64. interfaceList.forEach((item) => {
  65. if (item.id === value) {
  66. const { baudRate, dataBit, stopBit, parityBit, id, protocolType } = item;
  67. interfaceItem.value = {
  68. baudRate,
  69. dataBit,
  70. stopBit,
  71. parityBit,
  72. id,
  73. protocolType,
  74. };
  75. }
  76. });
  77. if (interfaceItem.value) {
  78. postVerificationAgreement(interfaceItem.value.id);
  79. }
  80. };
  81. const addList = () => {
  82. postGatewayLinkProtocolList(Number(activeKey.value));
  83. };
  84. const postGatewayLinkProtocolList = (value: number) => {
  85. handleRequest(async () => {
  86. const { records } = await gatewayLinkProtocolList<ProtocolListPageItemData>({
  87. pageIndex: 1,
  88. pageSize: 10,
  89. id: value,
  90. });
  91. protocolList.value = records;
  92. });
  93. };
  94. const postVerificationAgreement = (id: number) => {
  95. handleRequest(async () => {
  96. verificationAgreement.value = await gatewayLinkList(id);
  97. if (verificationAgreement.value.length) {
  98. activeKey.value = verificationAgreement.value[0].id;
  99. postGatewayLinkProtocolList(activeKey.value);
  100. }
  101. });
  102. };
  103. onMounted(() => {
  104. handleRequest(async () => {
  105. interfaceList = await gatewayLinkGetList(props.form.id);
  106. if (interfaceList.length) {
  107. const { baudRate, dataBit, stopBit, parityBit, id, protocolType } = interfaceList[0];
  108. interfaceItem.value = {
  109. baudRate,
  110. dataBit,
  111. stopBit,
  112. parityBit,
  113. id,
  114. protocolType,
  115. };
  116. interfaceValue.value = id;
  117. interfaceList.forEach((item) => {
  118. const { baudRate, dataBit, stopBit, parityBit, id, protocolType, linkName } = item;
  119. interfaceData.value.push({
  120. value: id,
  121. payload: linkName,
  122. baudRate,
  123. dataBit,
  124. stopBit,
  125. parityBit,
  126. id,
  127. protocolType,
  128. });
  129. });
  130. postVerificationAgreement(id);
  131. }
  132. });
  133. });
  134. </script>
  135. <template>
  136. <div style="width: 1092px; padding-right: 40px">
  137. <div>
  138. <div class="use-guide-title">{{ $t('registerGateway.verificationAgreement') }}</div>
  139. <div class="use-guide-description" style="margin-bottom: 40px">文字描述</div>
  140. <ADivider />
  141. </div>
  142. <ARow>
  143. <ACol :span="12">
  144. <ASegmented
  145. class="agreement-segmented"
  146. v-model:value="interfaceValue"
  147. :options="interfaceData"
  148. @change="interfaceAdd"
  149. >
  150. <template #label="{ payload }">
  151. <div style="padding: 4px">
  152. <div>{{ payload }}</div>
  153. </div>
  154. </template>
  155. </ASegmented>
  156. </ACol>
  157. <ACol :span="12">
  158. <AFlex justify="flex-end">
  159. <span class="but-text">{{ $t('registerGateway.gatewayLog') }}</span>
  160. <AButton class="remote-debugging" type="primary" ghost>{{ $t('registerGateway.remoteDebugging') }}</AButton>
  161. <AButton type="primary" ghost>{{ $t('registerGateway.gatewayConfiguration') }}</AButton>
  162. </AFlex>
  163. </ACol>
  164. </ARow>
  165. <div class="agreement-text">
  166. <span>{{ $t('setupProtocol.protocolType') }}:</span> <span>{{ interfaceItem?.protocolType }}</span>
  167. <span class="agreement-text1">{{ $t('setupProtocol.baudRate') }}:</span>
  168. <span>{{ interfaceItem?.baudRate }}</span>
  169. <span class="agreement-text1">{{ $t('setupProtocol.dataBit') }}:</span>
  170. <span>{{ interfaceItem?.dataBit }}</span>
  171. <span class="agreement-text1">{{ $t('setupProtocol.stopBit') }}:</span>
  172. <span>{{ interfaceItem?.stopBit }}</span>
  173. <span class="agreement-text1">{{ $t('setupProtocol.parityBit') }}:</span>
  174. <span>{{ interfaceItem?.parityBit }}</span>
  175. </div>
  176. <ACollapse v-model:active-key="activeKey" class="protocol-collapse" @change="addList" accordion>
  177. <ACollapsePanel v-for="item in verificationAgreement" :key="item.id">
  178. <template #header>
  179. <span class="header-text">{{ $t('registerGateway.station') }}{{ item.station }}</span>
  180. <span class="header-text1">{{ $t('registerGateway.communicationProtocol') }}:{{ item.protocolName }}</span>
  181. </template>
  182. <template #extra>
  183. <AFlex>
  184. <span class="header-text2">
  185. <span>{{ $t('registerGateway.regularReportingFrequency') }}: </span>
  186. <span>{{ item.dataSendInterval }}s</span>
  187. </span>
  188. <span class="header-text2">
  189. <span>{{ $t('registerGateway.highFrequencyReportingFrequency') }}: </span>
  190. <span>{{ item.highFreqSendInterval }}s</span>
  191. </span>
  192. <span class="but-text" style="width: 75px; height: 24px">{{
  193. $t('registerGateway.refreshData')
  194. }}</span></AFlex
  195. >
  196. </template>
  197. <AFlex>
  198. <ATable
  199. style="width: 100%"
  200. row-key="id"
  201. :columns="protocolColumns"
  202. :data-source="protocolList"
  203. :pagination="false"
  204. />
  205. </AFlex>
  206. </ACollapsePanel>
  207. </ACollapse>
  208. </div>
  209. </template>
  210. <style lang="scss" scoped>
  211. :deep(.agreement-segmented .ant-segmented-item-selected) {
  212. border-radius: 8px;
  213. }
  214. .agreement-content-left {
  215. width: 240px;
  216. border-right: 2px solid #e4e7ed; /* 只设置右边框 */
  217. }
  218. .gateway-log {
  219. color: #32bac0;
  220. }
  221. .remote-debugging {
  222. margin-right: 16px;
  223. }
  224. .agreement-text {
  225. margin-top: 20px;
  226. margin-bottom: 15px;
  227. font-size: 14px;
  228. font-style: normal;
  229. font-weight: 500;
  230. line-height: 24px;
  231. color: #333;
  232. text-align: left;
  233. }
  234. .agreement-text1 {
  235. margin-left: 40px;
  236. }
  237. .header-text {
  238. margin-right: 15px;
  239. font-size: 14px;
  240. font-style: normal;
  241. font-weight: 500;
  242. line-height: 24px;
  243. color: #333;
  244. text-align: left;
  245. }
  246. .header-text1 {
  247. font-size: 14px;
  248. font-style: normal;
  249. font-weight: 500;
  250. line-height: 24px;
  251. color: #666;
  252. text-align: left;
  253. }
  254. .header-text2 {
  255. margin-right: 32px;
  256. font-size: 14px;
  257. font-style: normal;
  258. font-weight: 400;
  259. line-height: 24px;
  260. color: #666;
  261. text-align: left;
  262. }
  263. .but-text {
  264. display: flex;
  265. align-items: center;
  266. justify-content: center;
  267. width: 108px;
  268. height: 32px;
  269. font-size: 14px;
  270. font-style: normal;
  271. font-weight: 400;
  272. line-height: 24px;
  273. color: #32bac0;
  274. text-align: left;
  275. cursor: pointer;
  276. }
  277. </style>