From 3a3cc473c33cb4a97399ace76a1b35e9ffd68525 Mon Sep 17 00:00:00 2001
From: songshankun <songshankun@foxmail.com>
Date: 星期一, 20 十一月 2023 16:45:17 +0800
Subject: [PATCH] feat: 无任务选中通道时从p[lc读取统计
---
src/stores/plc.ts | 5 ++---
src/views/dashboard/components/ChannelCollapse.vue | 30 ++++++++++++++++++++++--------
src/stores/tasks.ts | 15 +++++++++++++--
src/api/index.ts | 1 -
4 files changed, 37 insertions(+), 14 deletions(-)
diff --git a/src/api/index.ts b/src/api/index.ts
index 8c68113..818c651 100644
--- a/src/api/index.ts
+++ b/src/api/index.ts
@@ -43,7 +43,6 @@
export interface ProductProgressParams {
channel: number
- procedureId: number
}
/**
diff --git a/src/stores/plc.ts b/src/stores/plc.ts
index b42f370..88d0122 100644
--- a/src/stores/plc.ts
+++ b/src/stores/plc.ts
@@ -27,8 +27,7 @@
} = useRequest(
() =>
getProductProgress({
- channel: taskStore.activeTask?.Channel,
- procedureId: taskStore.activeTask?.Procedure.ID
+ channel: taskStore.activeChannel ?? 0
} as ProductProgressParams),
{
manual: true,
@@ -42,7 +41,7 @@
* 濡傛灉鍒囨崲鍒板叾浠栭�氶亾鐨勪换鍔�,鍒欓噸鏂拌疆璇lc
*/
unwatch.value = watch(
- () => taskStore.activeTask?.Channel,
+ () => taskStore.activeChannel,
() => {
cancelPLCPolling()
startPLCPolling()
diff --git a/src/stores/tasks.ts b/src/stores/tasks.ts
index 971a627..6ebd205 100644
--- a/src/stores/tasks.ts
+++ b/src/stores/tasks.ts
@@ -49,9 +49,13 @@
if (firstNotEmptyChannel) {
const channelNumber = +firstNotEmptyChannel[0]
activeTask.value = channels[channelNumber].Tasks[0]
+ setActiveChannel(channelNumber)
} else {
// 濡傛灉娌℃湁浠诲姟灏辨竻绌哄綋鍓嶉�変腑鐨勪换鍔�
activeTask.value = undefined
+ if (channels[0]) {
+ setActiveChannel(0)
+ }
}
}
@@ -125,8 +129,13 @@
/** 褰撳墠楂樹寒鐨勪换鍔� */
const activeTask = ref<Task>()
- function setActiveTask(task: Task) {
+ function setActiveTask(task: Task | undefined) {
activeTask.value = task
+ }
+
+ const activeChannel = ref<number>(0)
+ function setActiveChannel(channelNumber: number) {
+ activeChannel.value = channelNumber
}
return {
@@ -138,6 +147,8 @@
setActiveTask,
moreChannelTasksBtn,
foldChannelTasksBtn,
- reloadAllData
+ reloadAllData,
+ activeChannel,
+ setActiveChannel
}
})
diff --git a/src/views/dashboard/components/ChannelCollapse.vue b/src/views/dashboard/components/ChannelCollapse.vue
index 1f483b7..8dda63a 100644
--- a/src/views/dashboard/components/ChannelCollapse.vue
+++ b/src/views/dashboard/components/ChannelCollapse.vue
@@ -1,19 +1,19 @@
<template>
<div class="channel-collapse">
<el-collapse v-model="activeChannel">
- <el-collapse-item
- v-for="(channel, channelNumber) in channels"
- :key="channelNumber"
- :title="CHANNEL_NAME_MAP[channelNumber] + ' 閫氶亾' + ' (' + (channel?.TaskCount ?? 0) + ')'"
- :name="String(channelNumber)"
- >
+ <el-collapse-item v-for="(channel, channelNumber) in channels" :key="channelNumber" :name="String(channelNumber)">
+ <template #title>
+ <div style="width: 100%; text-align: left" @click="selectChannel(channelNumber)">
+ {{ CHANNEL_NAME_MAP[channelNumber] + ' 閫氶亾' + ' (' + (channel?.TaskCount ?? 0) + ')' }}
+ </div>
+ </template>
<TaskInfo
v-for="task in channel.Tasks"
:key="task.Procedure.ID"
:active="task.Procedure.ID === tasksStore.activeTask?.Procedure.ID"
:task="task"
style="margin-bottom: 16px"
- @click="tasksStore.setActiveTask(task)"
+ @click="selectTask(task)"
></TaskInfo>
<div
@@ -39,11 +39,12 @@
</template>
<script setup lang="ts">
import { ref, watchEffect } from 'vue'
-import type { TasksGroupByChannel } from '@/api/task'
+import type { Task, TasksGroupByChannel } from '@/api/task'
import TaskInfo from './TaskInfo.vue'
import { CHANNEL_NAME_MAP } from '@/common/constants'
import { useTasksStore } from '@/stores/tasks'
import { ArrowDownBold, ArrowUpBold } from '@element-plus/icons-vue'
+import { isNumber } from 'lodash-es'
export interface ChannelCollapseProps {
channels: TasksGroupByChannel
@@ -59,6 +60,19 @@
const channelNumbers = Object.keys(props?.channels ?? {}).sort((a, b) => +a - +b)
activeChannel.value = [...channelNumbers]
})
+
+function selectChannel(channelNumber: number) {
+ tasksStore.setActiveTask(undefined)
+ tasksStore.setActiveChannel(+channelNumber)
+}
+
+function selectTask(task: Task | undefined) {
+ tasksStore.setActiveTask(task)
+ let channel = tasksStore?.activeTask?.Channel
+ if (isNumber(channel)) {
+ tasksStore.setActiveChannel(channel)
+ }
+}
</script>
<style scoped lang="scss">
--
Gitblit v1.8.0