AIOptimization.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. <script setup lang="ts">
  2. import { computed, onMounted, onUnmounted, ref, shallowRef, useTemplateRef } from 'vue';
  3. import { Modal } from 'ant-design-vue';
  4. import { DeviceType } from '@/views/device-work-status/device-card';
  5. import SvgIcon from '@/components/SvgIcon.vue';
  6. import { useRequest } from '@/hooks/request';
  7. import { useViewVisible } from '@/hooks/view-visible';
  8. import { t } from '@/i18n';
  9. import { getAIOptimizeDevData, updateAIStartStopOptimize } from '@/api';
  10. import { isNotEmptyVal } from '@/utils';
  11. import ChillerUnitOptimize from '../device-optimize/ChillerUnitOptimize.vue';
  12. import CoolingTowerOptimize from '../device-optimize/CoolingTowerOptimize.vue';
  13. import type { Component } from 'vue';
  14. import type { ColumnType } from 'ant-design-vue/es/table';
  15. import type { AIOptimizeDevData, AIOptimizeSetItemInstance, GroupModuleInfo } from '@/types';
  16. interface Props {
  17. info: GroupModuleInfo;
  18. }
  19. const props = defineProps<Props>();
  20. interface OptimizeAlgorithmItem {
  21. algorithm: string;
  22. setValue?: number;
  23. isEnabled?: boolean;
  24. valuePropName: string;
  25. enablePropName: string;
  26. unit?: string;
  27. deviceType: DeviceType;
  28. modalWidth?: number;
  29. modalComponent?: Component;
  30. }
  31. const { isLoading, handleRequest } = useRequest();
  32. const optimizeDevData = ref<AIOptimizeDevData>();
  33. let optimizeTimer: number | undefined;
  34. onMounted(() => {
  35. getOptimizeDevData();
  36. });
  37. onUnmounted(() => {
  38. optimizeDevData.value = undefined;
  39. clearTimeout(optimizeTimer);
  40. });
  41. const getOptimizeDevData = () => {
  42. clearTimeout(optimizeTimer);
  43. handleRequest(async () => {
  44. const groupId = props.info.groupId;
  45. const data = await getAIOptimizeDevData(groupId);
  46. optimizeDevData.value = data;
  47. enableChillerUnit.value = data.enableHostWaterSet;
  48. enableCoolingTower.value = data.enableTowerWaterSet;
  49. chillerUnitWaterTemp.value = data.moduleInfoAi.aiSeekHostWaterTempValue;
  50. coolingTowerWaterTemp.value = data.moduleInfoAi.aiSeekTowerWaterTempValue;
  51. });
  52. optimizeTimer = window.setTimeout(getOptimizeDevData, 3000);
  53. };
  54. const chillerUnitWaterTemp = ref<number>();
  55. const coolingTowerWaterTemp = ref<number>();
  56. const enableChillerUnit = ref(false);
  57. const enableCoolingTower = ref(false);
  58. const dataSource = computed<OptimizeAlgorithmItem[]>(() => {
  59. const list: OptimizeAlgorithmItem[] = [];
  60. const moduleInfoAi = optimizeDevData.value?.moduleInfoAi;
  61. if (enableChillerUnit.value) {
  62. list.push({
  63. algorithm: '冷机水温寻优',
  64. setValue: moduleInfoAi?.aiSeekHostWaterTempValue,
  65. isEnabled: moduleInfoAi?.aiSeekHostWaterTempButton,
  66. valuePropName: 'aiSeekHostWaterTempValue',
  67. enablePropName: 'aiSeekHostWaterTempButton',
  68. unit: '°C',
  69. deviceType: DeviceType.冷水主机,
  70. modalComponent: shallowRef(ChillerUnitOptimize),
  71. });
  72. }
  73. if (enableCoolingTower.value) {
  74. list.push({
  75. algorithm: '塔出水温度寻优',
  76. setValue: moduleInfoAi?.aiSeekTowerWaterTempValue,
  77. isEnabled: moduleInfoAi?.aiSeekTowerWaterTempButton,
  78. valuePropName: 'aiSeekTowerWaterTempValue',
  79. enablePropName: 'aiSeekTowerWaterTempButton',
  80. unit: '°C',
  81. deviceType: DeviceType.冷却塔,
  82. modalWidth: 460,
  83. modalComponent: shallowRef(CoolingTowerOptimize),
  84. });
  85. }
  86. // {
  87. // algorithm: '冷冻泵寻优',
  88. // setValue: 10,
  89. // isEnabled: true,
  90. // },
  91. // {
  92. // algorithm: '冷却泵寻优',
  93. // setValue: 10,
  94. // isEnabled: true,
  95. // },
  96. return list;
  97. });
  98. const columns = computed<ColumnType<OptimizeAlgorithmItem>[]>(() => [
  99. {
  100. title: t('realTimeMonitor.optimizationAlgorithm'),
  101. dataIndex: 'algorithm',
  102. key: 'algorithm',
  103. },
  104. {
  105. title: t('realTimeMonitor.setValue'),
  106. dataIndex: 'setValue',
  107. key: 'setValue',
  108. },
  109. {
  110. title: t('realTimeMonitor.isEnabled'),
  111. dataIndex: 'isEnabled',
  112. key: 'isEnabled',
  113. },
  114. {
  115. title: t('common.operation'),
  116. dataIndex: 'operation',
  117. key: 'operation',
  118. },
  119. ]);
  120. const handleTempChange = (record: OptimizeAlgorithmItem, value: string | number | null) => {
  121. handleRequest(async () => {
  122. const id = optimizeDevData.value?.moduleInfoAi.id;
  123. const groupId = props.info.groupId;
  124. if (id && isNotEmptyVal(value)) {
  125. await updateAIStartStopOptimize({
  126. id,
  127. groupId,
  128. [record.valuePropName]: value,
  129. });
  130. }
  131. });
  132. };
  133. const handleSwitchClick = (record: OptimizeAlgorithmItem) => {
  134. const titlePrefix = record.isEnabled ? t('common.confirmClose') : t('common.confirmOpen');
  135. Modal.confirm({
  136. title: titlePrefix + record.algorithm,
  137. closable: true,
  138. centered: true,
  139. onOk() {
  140. handleRequest(async () => {
  141. const id = optimizeDevData.value?.moduleInfoAi.id;
  142. const groupId = props.info.groupId;
  143. if (id) {
  144. await updateAIStartStopOptimize({
  145. id,
  146. groupId,
  147. [record.enablePropName]: !record.isEnabled,
  148. });
  149. }
  150. });
  151. },
  152. });
  153. };
  154. const selectedAlgorithm = ref<OptimizeAlgorithmItem>();
  155. const handleSettingClick = (record: OptimizeAlgorithmItem) => {
  156. selectedAlgorithm.value = record;
  157. showView();
  158. };
  159. const { visible, showView, hideView } = useViewVisible();
  160. const { isLoading: isOptimizeSetLoading, handleRequest: handleOptimizeSetRequest } = useRequest();
  161. const optimizeSetRef = useTemplateRef<AIOptimizeSetItemInstance>('optimizeSetItem');
  162. const modalTitle = computed(() => {
  163. return selectedAlgorithm.value?.algorithm + t('common.settings');
  164. });
  165. const handleOk = () => {
  166. handleOptimizeSetRequest(async () => {
  167. await optimizeSetRef.value?.submit?.();
  168. hideView();
  169. });
  170. };
  171. </script>
  172. <template>
  173. <div class="ai-optimize-container">
  174. <ATable class="ai-optimize-table" :columns="columns" :data-source="dataSource" :pagination="false">
  175. <template #bodyCell="{ column, record }">
  176. <template v-if="column.key === 'algorithm'">
  177. <span>{{ record.algorithm }}</span>
  178. <span v-if="record.unit">({{ record.unit }})</span>
  179. </template>
  180. <template v-if="column.key === 'setValue'">
  181. <AInputNumber
  182. v-if="record.algorithm === '冷机水温寻优'"
  183. class="ai-optimize-input"
  184. v-model:value="chillerUnitWaterTemp"
  185. :disabled="record.isEnabled"
  186. :controls="false"
  187. @change="handleTempChange(record as OptimizeAlgorithmItem, $event)"
  188. />
  189. <AInputNumber
  190. v-else-if="record.algorithm === '塔出水温度寻优'"
  191. class="ai-optimize-input"
  192. v-model:value="coolingTowerWaterTemp"
  193. :disabled="record.isEnabled"
  194. :controls="false"
  195. @change="handleTempChange(record as OptimizeAlgorithmItem, $event)"
  196. />
  197. </template>
  198. <template v-if="column.key === 'isEnabled'">
  199. <ASwitch
  200. :checked="record.isEnabled"
  201. :checked-children="$t('common.on')"
  202. :un-checked-children="$t('common.off')"
  203. @click="handleSwitchClick(record as OptimizeAlgorithmItem)"
  204. />
  205. </template>
  206. <template v-else-if="column.key === 'operation'">
  207. <div class="ai-optimize-setting">
  208. <SvgIcon name="setting" @click="handleSettingClick(record as OptimizeAlgorithmItem)" />
  209. </div>
  210. </template>
  211. </template>
  212. </ATable>
  213. <ASpin v-if="isLoading" class="center-loading" :spinning="true" />
  214. <AModal
  215. v-model:open="visible"
  216. wrap-class-name="hvac-modal ai-optimize-modal"
  217. :title="modalTitle"
  218. :width="selectedAlgorithm?.modalWidth || 920"
  219. centered
  220. destroy-on-close
  221. :confirm-loading="isOptimizeSetLoading"
  222. @ok="handleOk"
  223. >
  224. <component ref="optimizeSetItem" :is="selectedAlgorithm?.modalComponent" :group-id="info.groupId" />
  225. </AModal>
  226. </div>
  227. </template>
  228. <style lang="scss">
  229. .ai-optimize-modal {
  230. .ant-modal-body {
  231. max-height: 638px;
  232. overflow-y: auto;
  233. }
  234. }
  235. </style>
  236. <style lang="scss" scoped>
  237. .ai-optimize-container {
  238. padding-inline: 24px;
  239. }
  240. :deep(.ai-optimize-table).ant-table-wrapper .ant-table {
  241. color: rgba(255 255 255 / 85%);
  242. background: transparent;
  243. .ant-table-thead > tr > th {
  244. padding: 12px;
  245. font-size: 14px;
  246. font-weight: 500;
  247. color: rgba(255 255 255 / 85%);
  248. background: rgba(255 255 255 / 8%);
  249. border-bottom: none;
  250. }
  251. .ant-table-header {
  252. border-radius: 0;
  253. }
  254. table > thead > tr:first-child > {
  255. *:first-child {
  256. border-start-start-radius: 0;
  257. }
  258. *:last-child {
  259. border-start-end-radius: 0;
  260. }
  261. }
  262. .ant-table-thead
  263. > tr
  264. > th.ant-table-cell:not(:last-child, .ant-table-selection-column, .ant-table-row-expand-icon-cell, [colspan]) {
  265. &::before {
  266. background-color: transparent;
  267. }
  268. }
  269. .ant-table-tbody > tr {
  270. > td {
  271. padding-inline: 12px;
  272. border-top-color: rgba(255 255 255 / 8%);
  273. }
  274. &:last-child > td {
  275. border-bottom-color: rgba(255 255 255 / 8%);
  276. }
  277. &.ant-table-row:hover > td,
  278. > td.ant-table-cell-row-hover {
  279. background: rgba(255 255 255 / 8%);
  280. }
  281. }
  282. .ant-empty-normal {
  283. color: rgba(255 255 255 / 25%);
  284. }
  285. .ant-table-placeholder:hover > td {
  286. background: transparent;
  287. }
  288. }
  289. .ai-optimize-input {
  290. width: 96px;
  291. background: rgb(30 37 48 / 32%);
  292. border-color: rgb(255 255 255 / 24%);
  293. border-radius: 4px;
  294. :deep(.ant-input-number-input) {
  295. color: #fff;
  296. }
  297. &:hover,
  298. &:focus,
  299. &.ant-input-number-focused {
  300. border-color: var(--antd-color-primary-hover);
  301. }
  302. &.ant-input-number-disabled {
  303. border-color: rgb(255 255 255 / 24%);
  304. opacity: 0.4;
  305. }
  306. }
  307. .ai-optimize-setting {
  308. display: flex;
  309. align-items: center;
  310. justify-content: center;
  311. font-size: 24px;
  312. color: var(--antd-color-primary);
  313. cursor: pointer;
  314. }
  315. </style>