DeviceWorkParams.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <script setup lang="ts">
  2. import { computed, ref, watch } from 'vue';
  3. import SvgIcon from '@/components/SvgIcon.vue';
  4. import { useRequest } from '@/hooks/request';
  5. import { useViewVisible } from '@/hooks/view-visible';
  6. import { getDeviceParams } from '@/api';
  7. import type { DeviceParamGroup, DeviceParamItem, OptionItem } from '@/types';
  8. interface Props {
  9. devId: number;
  10. }
  11. const props = defineProps<Props>();
  12. const { visible, showView, hideView } = useViewVisible();
  13. const { isLoading, handleRequest } = useRequest();
  14. const allParamGroups = ref<DeviceParamGroup[]>([]);
  15. const activeGroup = ref(-1);
  16. const groupList = computed<OptionItem<number>[]>(() => {
  17. return allParamGroups.value.map((item) => ({
  18. value: item.id,
  19. label: item.deviceParamGroupName,
  20. }));
  21. });
  22. const paramList = computed<DeviceParamItem[]>(() => {
  23. const params = allParamGroups.value.find((item) => item.id === activeGroup.value);
  24. if (params) {
  25. return params.valueVos;
  26. }
  27. return [];
  28. });
  29. watch(visible, () => {
  30. if (visible.value) {
  31. getAllParamGroups();
  32. }
  33. });
  34. const getAllParamGroups = () => {
  35. handleRequest(async () => {
  36. const data = await getDeviceParams(props.devId, false);
  37. allParamGroups.value = data;
  38. if (data.length) {
  39. activeGroup.value = data[0].id;
  40. }
  41. });
  42. };
  43. const viewData = () => {
  44. return;
  45. };
  46. const handleClose = () => {
  47. allParamGroups.value = [];
  48. activeGroup.value = -1;
  49. };
  50. defineExpose({
  51. showView,
  52. hideView,
  53. });
  54. </script>
  55. <template>
  56. <AModal
  57. v-model:open="visible"
  58. wrap-class-name="dev-work-params-modal"
  59. :title="$t('createDevice.parameters')"
  60. :width="920"
  61. centered
  62. :footer="null"
  63. :after-close="handleClose"
  64. >
  65. <AEmpty v-show="!groupList.length" />
  66. <ASpin class="center-loading" :spinning="isLoading" />
  67. <ATabs class="hide-tabs-border" v-model:active-key="activeGroup">
  68. <ATabPane v-for="item in groupList" :key="item.value" :tab="item.label" />
  69. </ATabs>
  70. <div class="param-list">
  71. <ARow :gutter="[16, 16]">
  72. <ACol v-for="item in paramList" :key="item.deviceParamCode" :span="8">
  73. <div class="param-container">
  74. <div class="param-header">
  75. <div class="ellipsis-text param-name">{{ item.paramName }}</div>
  76. <div class="param-view" @click="viewData">{{ $t('deviceWorkStatus.viewData') }}</div>
  77. <SvgIcon name="right" :size="12" color="rgba(0, 0, 0, 0.25)" />
  78. </div>
  79. <div class="param-body">
  80. <div class="param-value">{{ item.value }}{{ item.unit }}</div>
  81. <div class="param-time">{{ item.time }}</div>
  82. </div>
  83. </div>
  84. </ACol>
  85. </ARow>
  86. </div>
  87. </AModal>
  88. </template>
  89. <style lang="scss">
  90. .dev-work-params-modal {
  91. .ant-modal,
  92. .ant-modal > div,
  93. .ant-modal-content {
  94. height: 640px;
  95. }
  96. .ant-modal-content {
  97. display: flex;
  98. flex-direction: column;
  99. overflow: hidden;
  100. }
  101. .ant-modal-body {
  102. display: flex;
  103. flex-direction: column;
  104. height: calc(100% - 32px);
  105. }
  106. .ant-empty {
  107. margin-top: 150px;
  108. }
  109. }
  110. </style>
  111. <style lang="scss" scoped>
  112. .param-list {
  113. height: 100%;
  114. overflow: hidden auto;
  115. }
  116. .param-container {
  117. width: 280px;
  118. height: 156px;
  119. background: #fff;
  120. border: 1px solid #e4e7ed;
  121. border-radius: 8px;
  122. }
  123. .param-header {
  124. display: flex;
  125. align-items: center;
  126. height: 50px;
  127. padding-right: 12px;
  128. padding-left: 16px;
  129. border-bottom: 1px solid #e4e7ed;
  130. }
  131. .param-name {
  132. flex: 1;
  133. margin-right: 16px;
  134. font-size: 14px;
  135. line-height: 22px;
  136. color: var(--antd-color-text);
  137. }
  138. .param-view {
  139. margin-right: 4px;
  140. font-size: 14px;
  141. font-weight: 500;
  142. line-height: 24px;
  143. color: var(--antd-color-primary);
  144. cursor: pointer;
  145. }
  146. .param-body {
  147. padding: 24px 16px;
  148. }
  149. .param-value {
  150. margin-bottom: 8px;
  151. font-size: 18px;
  152. font-weight: 600;
  153. line-height: 26px;
  154. color: var(--antd-color-text);
  155. }
  156. .param-time {
  157. font-size: 14px;
  158. line-height: 24px;
  159. color: var(--antd-color-text-tertiary);
  160. }
  161. </style>