AddInterface.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <script setup lang="ts">
  2. import { onMounted, reactive, ref } from 'vue';
  3. import { message } from 'ant-design-vue';
  4. import { useRequest } from '@/hooks/request';
  5. import { t } from '@/i18n';
  6. import { gatewayLinkAdd, gatewayLinkDelete, gatewayLinkGetList, getGatewayModelInterfaces } from '@/api';
  7. import deviceInterface from '@/assets/img/device-interface.png';
  8. import type {
  9. GatewayInterface,
  10. InterfaceData,
  11. InterfaceList,
  12. RegisterGatewayForm,
  13. UseGuideStepItemProps,
  14. } from '@/types';
  15. const props = defineProps<UseGuideStepItemProps<RegisterGatewayForm>>();
  16. let gatewayInterface: GatewayInterface[];
  17. const interfaceList = reactive<InterfaceList[]>([]);
  18. const { handleRequest } = useRequest();
  19. interface InterfaceStyle {
  20. backgroundImage: string;
  21. }
  22. // 定义一个响应式变量来存储样式对象
  23. const interfaceStyle = ref<InterfaceStyle>({
  24. backgroundImage: `url(${deviceInterface})`,
  25. });
  26. const interfaceData = ref<InterfaceData[]>([]);
  27. const postGetList = () => {
  28. handleRequest(async () => {
  29. interfaceData.value = await gatewayLinkGetList(props.form.id);
  30. });
  31. };
  32. // 根据条件显示背景
  33. const interfaceShow = (value: string) => {
  34. return value === 'LAN' ? 'background-color: rgba(54, 207, 201, 1);' : 'background-color: rgba(89, 126, 247, 1);';
  35. };
  36. // 添加接口列表
  37. const addInterface = () => {
  38. if (props.form.linkType) {
  39. interfaceList.forEach((option) => {
  40. if (option.value === props.form.linkType) {
  41. handleRequest(async () => {
  42. await gatewayLinkAdd({
  43. linkTypeId: Number(option.value),
  44. linkName: option.label,
  45. gatewayId: props.form.id,
  46. });
  47. postGetList();
  48. });
  49. }
  50. });
  51. } else {
  52. message.warning(t('registerGateway.pleaseSelectInterface'));
  53. }
  54. };
  55. // 删除接口
  56. const addDelete = (value: number) => {
  57. handleRequest(async () => {
  58. await gatewayLinkDelete(value);
  59. postGetList();
  60. });
  61. };
  62. onMounted(() => {
  63. handleRequest(async () => {
  64. gatewayInterface = await getGatewayModelInterfaces(props.form.modelId);
  65. gatewayInterface.forEach((item) => {
  66. interfaceList.push({
  67. value: String(item.id),
  68. label: item.dictValue,
  69. });
  70. });
  71. });
  72. postGetList();
  73. });
  74. </script>
  75. <template>
  76. <div>
  77. <div class="use-guide-title">{{ $t('registerGateway.addInterface') }}</div>
  78. <div class="use-guide-description">文本描述!!!</div>
  79. <AFormItem :label="$t('registerGateway.selectInterface')" name="linkType">
  80. <ASelect
  81. size="large"
  82. ref="select"
  83. v-model:value="form.linkType"
  84. class="interface-select"
  85. :options="interfaceList"
  86. />
  87. <AButton class="dev-but" type="primary" @click="addInterface">{{ $t('common.add') }}</AButton>
  88. </AFormItem>
  89. <div :style="interfaceStyle" class="interface-img">
  90. <div class="interface-bgc"></div>
  91. </div>
  92. <div class="use-guide-title">{{ $t('registerGateway.interfaceList') }}</div>
  93. <div class="interface-container main-container">
  94. <AFlex v-for="item in interfaceData" :key="item.id" class="interface-div" justify="flex-start" align="center">
  95. <ARow style="width: 100%">
  96. <ACol :span="14">
  97. <AFlex justify="flex-start" align="center">
  98. <AFlex class="interface-div1" :style="interfaceShow(item.valueType)" justify="center" align="center">
  99. <span class="interface-div1-span">{{ item.valueType }}</span>
  100. </AFlex>
  101. <div class="interface-div2">{{ item.linkName }}</div>
  102. </AFlex>
  103. </ACol>
  104. <ACol :span="10">
  105. <AFlex justify="flex-end" align="center">
  106. <AButton class="interface-but" type="link" danger @click="addDelete(item.id)">{{
  107. $t('common.delete')
  108. }}</AButton>
  109. </AFlex>
  110. </ACol>
  111. </ARow>
  112. </AFlex>
  113. </div>
  114. </div>
  115. </template>
  116. <style lang="scss" scoped>
  117. .dev-but {
  118. width: 108px;
  119. height: 40px;
  120. margin-left: 30px;
  121. border-radius: 3px;
  122. }
  123. .interface-select {
  124. width: 240px;
  125. margin-left: 15px;
  126. }
  127. .interface-bgc {
  128. position: relative;
  129. top: 66px;
  130. left: 229px;
  131. width: 53px;
  132. height: 53px;
  133. background-color: rgb(82 196 26 / 35%);
  134. border-radius: 8px;
  135. }
  136. .interface-div {
  137. width: 457px;
  138. height: 67px;
  139. margin-top: 14px;
  140. background-color: rgb(240 240 240 / 100%);
  141. border-radius: 8px;
  142. }
  143. .interface-img {
  144. position: 'static';
  145. width: 608px;
  146. height: 178px;
  147. margin-top: 25px;
  148. margin-bottom: 20px;
  149. background-size: '100% 100%';
  150. }
  151. .interface-div1 {
  152. width: 48px;
  153. height: 48px;
  154. margin-left: 20px;
  155. border-radius: 4px;
  156. }
  157. .interface-div1-span {
  158. font-size: 16px;
  159. font-style: normal;
  160. font-weight: 400;
  161. line-height: 18px;
  162. color: rgb(255 255 255 / 97%);
  163. }
  164. .interface-div2 {
  165. margin-left: 20px;
  166. font-size: 16px;
  167. font-style: normal;
  168. font-weight: 500;
  169. line-height: 17px;
  170. color: var(--antd-color-text-secondary);
  171. text-align: left;
  172. }
  173. .interface-but {
  174. margin-top: 8px;
  175. margin-right: 10px;
  176. }
  177. .interface-container {
  178. width: 565px;
  179. height: 410px;
  180. }
  181. </style>