|
@@ -1,16 +1,24 @@
|
|
|
<script setup lang="ts">
|
|
|
-import { computed, ref } from 'vue';
|
|
|
-import { message, Modal } from 'ant-design-vue';
|
|
|
+import { computed, onMounted, onUnmounted, ref, watch } from 'vue';
|
|
|
+import { Modal } from 'ant-design-vue';
|
|
|
|
|
|
import SvgIcon from '@/components/SvgIcon.vue';
|
|
|
+import { useRequest } from '@/hooks/request';
|
|
|
import { t } from '@/i18n';
|
|
|
+import { getAIStartStopData, updateAIStartStopData, updateAIStartStopOptimize } from '@/api';
|
|
|
+import { CtrlCabinetStartType } from '@/constants';
|
|
|
|
|
|
import type { SegmentedBaseOption } from 'ant-design-vue/es/segmented/src/segmented';
|
|
|
+import type { AIStartStopDeviceItem, GroupModuleInfo } from '@/types';
|
|
|
|
|
|
-type ModeValue = 'fullAuto' | 'halfAuto' | 'jog';
|
|
|
+interface Props {
|
|
|
+ info: GroupModuleInfo;
|
|
|
+}
|
|
|
+
|
|
|
+const props = defineProps<Props>();
|
|
|
|
|
|
interface ModeTypeItem extends SegmentedBaseOption {
|
|
|
- value: ModeValue;
|
|
|
+ value: CtrlCabinetStartType;
|
|
|
payload: {
|
|
|
title: string;
|
|
|
confirmTip: string;
|
|
@@ -20,21 +28,21 @@ interface ModeTypeItem extends SegmentedBaseOption {
|
|
|
const modeTypes = computed<ModeTypeItem[]>(() => {
|
|
|
return [
|
|
|
{
|
|
|
- value: 'fullAuto',
|
|
|
+ value: CtrlCabinetStartType.FullAuto,
|
|
|
payload: {
|
|
|
title: t('realTimeMonitor.fullAutoMode'),
|
|
|
confirmTip: t('realTimeMonitor.fullAutoConfirmTip'),
|
|
|
},
|
|
|
},
|
|
|
{
|
|
|
- value: 'halfAuto',
|
|
|
+ value: CtrlCabinetStartType.HalfAuto,
|
|
|
payload: {
|
|
|
title: t('realTimeMonitor.halfAutoMode'),
|
|
|
confirmTip: t('realTimeMonitor.halfAutoConfirmTip'),
|
|
|
},
|
|
|
},
|
|
|
{
|
|
|
- value: 'jog',
|
|
|
+ value: CtrlCabinetStartType.Jog,
|
|
|
disabled: true,
|
|
|
payload: {
|
|
|
title: t('realTimeMonitor.jogMode'),
|
|
@@ -44,7 +52,14 @@ const modeTypes = computed<ModeTypeItem[]>(() => {
|
|
|
];
|
|
|
});
|
|
|
|
|
|
-const currentModeType = ref<ModeValue>('fullAuto');
|
|
|
+const currentModeType = computed<CtrlCabinetStartType>(() => {
|
|
|
+ return props.info.moduleInfoAi?.aiStartType ?? CtrlCabinetStartType.FullAuto;
|
|
|
+});
|
|
|
+
|
|
|
+watch(currentModeType, () => {
|
|
|
+ deviceList.value = [];
|
|
|
+ getDeviceList();
|
|
|
+});
|
|
|
|
|
|
const handleModeClick = (option: ModeTypeItem) => {
|
|
|
if (option.disabled || option.value === currentModeType.value) {
|
|
@@ -55,40 +70,89 @@ const handleModeClick = (option: ModeTypeItem) => {
|
|
|
title: t('realTimeMonitor.confirmSwitchToMode', { mode: option.payload.title }),
|
|
|
content: option.payload.confirmTip,
|
|
|
closable: true,
|
|
|
- async onOk() {
|
|
|
- try {
|
|
|
- currentModeType.value = option.value;
|
|
|
- } catch (err) {
|
|
|
- message.error((err as Error).message);
|
|
|
- console.error(err);
|
|
|
- }
|
|
|
+ centered: true,
|
|
|
+ onOk() {
|
|
|
+ handleRequest(async () => {
|
|
|
+ const id = props.info.moduleInfoAi.id;
|
|
|
+ const groupId = props.info.groupId;
|
|
|
+
|
|
|
+ await updateAIStartStopOptimize({
|
|
|
+ id,
|
|
|
+ groupId,
|
|
|
+ aiStartType: option.value,
|
|
|
+ });
|
|
|
+ });
|
|
|
},
|
|
|
});
|
|
|
};
|
|
|
|
|
|
-type DeviceStatus = 'on' | 'off';
|
|
|
+const { handleRequest } = useRequest();
|
|
|
+const deviceList = ref<AIStartStopDeviceItem[]>([]);
|
|
|
+let deviceTimer: number | undefined;
|
|
|
|
|
|
-interface DeviceItem {
|
|
|
- name: string;
|
|
|
- status: DeviceStatus;
|
|
|
-}
|
|
|
+onMounted(() => {
|
|
|
+ getDeviceList();
|
|
|
+});
|
|
|
+
|
|
|
+onUnmounted(() => {
|
|
|
+ deviceList.value = [];
|
|
|
+ clearTimeout(deviceTimer);
|
|
|
+});
|
|
|
+
|
|
|
+const getDeviceList = () => {
|
|
|
+ clearTimeout(deviceTimer);
|
|
|
+
|
|
|
+ handleRequest(async () => {
|
|
|
+ const groupId = props.info.groupId;
|
|
|
+ const startType = props.info.moduleInfoAi.aiStartType;
|
|
|
+ deviceList.value = await getAIStartStopData(groupId, startType);
|
|
|
+ });
|
|
|
+
|
|
|
+ deviceTimer = window.setTimeout(getDeviceList, 3000);
|
|
|
+};
|
|
|
+
|
|
|
+const handleFullStartStatusSwitch = () => {
|
|
|
+ const device = deviceList.value[0];
|
|
|
+ const title = device.startStatus ? t('realTimeMonitor.confirmFullPowerOff') : t('realTimeMonitor.confirmFullPowerOn');
|
|
|
+ const content = device.startStatus
|
|
|
+ ? t('realTimeMonitor.confirmFullPowerOffTip')
|
|
|
+ : t('realTimeMonitor.confirmFullPowerOnTip');
|
|
|
+
|
|
|
+ Modal.confirm({
|
|
|
+ title,
|
|
|
+ content,
|
|
|
+ closable: true,
|
|
|
+ centered: true,
|
|
|
+ onOk() {
|
|
|
+ handleRequest(async () => {
|
|
|
+ await updateAIStartStopData({
|
|
|
+ deviceId: device.deviceId,
|
|
|
+ status: !device.startStatus,
|
|
|
+ startType: currentModeType.value,
|
|
|
+ });
|
|
|
+ });
|
|
|
+ },
|
|
|
+ });
|
|
|
+};
|
|
|
+
|
|
|
+const handleStartStatusSwitch = (device: AIStartStopDeviceItem) => {
|
|
|
+ const title = device.startStatus ? t('common.confirmClose') : t('common.confirmOpen');
|
|
|
|
|
|
-const deviceList = ref<DeviceItem[]>([
|
|
|
- { name: '五期-1#冷水主机', status: 'off' },
|
|
|
- { name: '五期-2#冷水主机', status: 'on' },
|
|
|
- { name: '五期-3#冷水主机', status: 'off' },
|
|
|
- { name: '五期-3#冷水主机', status: 'off' },
|
|
|
- { name: '五期-3#冷水主机', status: 'off' },
|
|
|
- { name: '五期-3#冷水主机', status: 'off' },
|
|
|
- { name: '五期-3#冷水主机', status: 'off' },
|
|
|
- { name: '五期-3#冷水主机', status: 'off' },
|
|
|
- { name: '五期-3#冷水主机', status: 'off' },
|
|
|
- { name: '五期-3#冷水主机', status: 'off' },
|
|
|
- { name: '五期-3#冷水主机', status: 'off' },
|
|
|
- { name: '五期-3#冷水主机', status: 'off' },
|
|
|
- { name: '五期-3#冷水主机', status: 'off' },
|
|
|
- { name: '五期-3#冷水主机', status: 'off' },
|
|
|
-]);
|
|
|
+ Modal.confirm({
|
|
|
+ title: title + device.deviceName,
|
|
|
+ closable: true,
|
|
|
+ centered: true,
|
|
|
+ onOk() {
|
|
|
+ handleRequest(async () => {
|
|
|
+ await updateAIStartStopData({
|
|
|
+ deviceId: device.deviceId,
|
|
|
+ status: !device.startStatus,
|
|
|
+ startType: currentModeType.value,
|
|
|
+ });
|
|
|
+ });
|
|
|
+ },
|
|
|
+ });
|
|
|
+};
|
|
|
</script>
|
|
|
|
|
|
<template>
|
|
@@ -98,29 +162,32 @@ const deviceList = ref<DeviceItem[]>([
|
|
|
<span @click="handleModeClick(option as ModeTypeItem)">{{ option.payload.title }}</span>
|
|
|
</template>
|
|
|
</ASegmented>
|
|
|
- <template v-if="currentModeType === 'fullAuto'">
|
|
|
- <div class="power-button">
|
|
|
+ <template v-if="currentModeType === CtrlCabinetStartType.FullAuto">
|
|
|
+ <div class="power-button" @click="handleFullStartStatusSwitch">
|
|
|
<div class="power-button-content">
|
|
|
<SvgIcon name="power-off" />
|
|
|
- <div>{{ $t('realTimeMonitor.fullPowerOff') }}</div>
|
|
|
+ <div>
|
|
|
+ {{ deviceList[0]?.startStatus ? $t('realTimeMonitor.fullPowerOff') : $t('realTimeMonitor.fullPowerOn') }}
|
|
|
+ </div>
|
|
|
</div>
|
|
|
<div class="power-button-segmented-border"></div>
|
|
|
</div>
|
|
|
</template>
|
|
|
- <div v-else-if="currentModeType === 'halfAuto'" class="ctrl-panel-scroll-content">
|
|
|
+ <div v-else-if="currentModeType === CtrlCabinetStartType.HalfAuto" class="ctrl-panel-scroll-content">
|
|
|
<div v-for="(item, index) in deviceList" :key="index" class="device-item">
|
|
|
<div>
|
|
|
- <span :class="['device-item-tag', { 'device-tag-run': item.status === 'on' }]">
|
|
|
- {{ item.status === 'on' ? $t('common.run') : $t('common.shutDown') }}
|
|
|
+ <span :class="['device-item-tag', { 'device-tag-run': item.runningStatus === 1 }]">
|
|
|
+ {{ item.runningStatus === 1 ? $t('common.run') : $t('common.shutDown') }}
|
|
|
</span>
|
|
|
- <span class="device-item-title">{{ item.name }}</span>
|
|
|
+ <span class="device-item-title">{{ item.deviceName }}</span>
|
|
|
</div>
|
|
|
<ASwitch
|
|
|
- v-model:checked="item.status"
|
|
|
- checked-value="on"
|
|
|
- un-checked-value="off"
|
|
|
+ :checked="item.startStatus"
|
|
|
+ :checked-value="1"
|
|
|
+ :un-checked-value="0"
|
|
|
:checked-children="$t('common.on')"
|
|
|
:un-checked-children="$t('common.off')"
|
|
|
+ @click="handleStartStatusSwitch(item)"
|
|
|
/>
|
|
|
</div>
|
|
|
</div>
|