From 985befd1aacce206d49925399aba85a51c50ea6e Mon Sep 17 00:00:00 2001
From: songshankun <songshankun@foxmail.com>
Date: 星期二, 28 十一月 2023 17:20:03 +0800
Subject: [PATCH] feat: 下发后重连plc
---
src/views/dashboard/components/TaskControl.vue | 93 +++++++++++++++++++++++++++++++++++++---------
1 files changed, 74 insertions(+), 19 deletions(-)
diff --git a/src/views/dashboard/components/TaskControl.vue b/src/views/dashboard/components/TaskControl.vue
index 47b9945..755a2d9 100644
--- a/src/views/dashboard/components/TaskControl.vue
+++ b/src/views/dashboard/components/TaskControl.vue
@@ -21,8 +21,10 @@
寮�濮嬬敓浜�
</BigButton>
<template v-if="task?.Procedure.Status === 2 || task?.Procedure.Status === 3">
- <BigButton class="btn" bg-color="#ff9933">鎵撳嵃</BigButton>
- <BigButton class="btn" bg-color="#00cc33">鎶ュ伐</BigButton>
+ <BigButton class="btn" bg-color="#ff9933" :disabled="task?.Procedure.Status === 3">鎵撳嵃</BigButton>
+ <BigButton class="btn" bg-color="#00cc33" :disabled="task?.Procedure.Status === 3" @click="openReportModal">
+ 鎶ュ伐
+ </BigButton>
<el-popconfirm
width="340"
confirm-button-text="纭畾"
@@ -36,32 +38,38 @@
@confirm="finishTaskProduce"
>
<template #reference>
- <BigButton class="btn" bg-color="#ff0000">瀹屾垚</BigButton>
+ <BigButton class="btn" bg-color="#ff0000" :disabled="task?.Procedure.Status === 3">瀹屾垚</BigButton>
</template>
</el-popconfirm>
</template>
</div>
</div>
- <TaskControlModal
- v-model="showTaskControlModal"
- :task="task"
- @produce-start="emit('shouldReload', task)"
- ></TaskControlModal>
+ <TaskControlModal v-model="showTaskControlModal" :task="task" @produce-start="onProduceStart"></TaskControlModal>
+ <ReportProductionModal
+ v-model="showReportModal"
+ :amount="plcInfo?.finishNumber ?? 0"
+ @close="showReportModal = false"
+ @submit="onReportProduction"
+ ></ReportProductionModal>
</template>
<script setup lang="ts">
-import type { Task } from '@/api/task'
+import type { Task, Worker } from '@/api/task'
import { ref, toRefs } from 'vue'
import BigButton from '@/views/dashboard/components/BigButton.vue'
import { useDateFormat } from '@vueuse/core'
import TaskControlModal from '@/views/dashboard/components/TaskControlModal.vue'
import { CircleCloseFilled } from '@element-plus/icons-vue'
-import { finishTask } from '@/api'
+import { apiReportWork, finishTask } from '@/api'
import { ElMessage } from 'element-plus'
+import ReportProductionModal from '@/views/dashboard/components/ReportProductionModal.vue'
+import { usePLCStore } from '@/stores/plc'
+import { storeToRefs } from 'pinia'
const props = defineProps<{
task?: Task
+ workers: Worker[]
}>()
-const { task } = toRefs(props)
+const { task, workers } = toRefs(props)
const emit = defineEmits<{
shouldReload: [task: Task]
@@ -80,14 +88,14 @@
* 瀹屾垚浠诲姟
*/
function finishTaskProduce() {
- if (task?.value?.Procedure?.ID) {
+ if (task?.value && task.value?.Procedure?.ID) {
finishTask({ id: task!.value.Procedure.ID }).then(
(res) => {
ElMessage({
message: '鎿嶄綔鎴愬姛锛�',
type: 'success'
})
- emit('shouldReload', task.value)
+ emit('shouldReload', task.value as Task)
},
(err) => {
console.error(err)
@@ -105,6 +113,10 @@
}
}
+function onProduceStart() {
+ emit('shouldReload', task!.value as Task)
+}
+
/**
* 鏍煎紡鍖栨椂闂存埑
* @param timestamp 鍚庣杩旂殑10浣嶆椂闂存埑
@@ -113,8 +125,50 @@
if (!timestamp) {
return '--'
}
- const time = useDateFormat(timestamp * 1000, 'YYYY-MM-DD', { locales: 'zh-cn' })
+ const time = useDateFormat(timestamp * 1000, 'YYYY-MM-DD HH:mm:ss', { locales: 'zh-cn' })
return time.value
+}
+
+const plcStore = usePLCStore()
+const { plcInfo } = storeToRefs(plcStore)
+// 鎶ュ伐
+const showReportModal = ref(false)
+function openReportModal() {
+ showReportModal.value = true
+}
+
+/**
+ * 涓婃姤鍔犲伐鏁�
+ * @param amount 鍔犲伐鏁�
+ */
+function onReportProduction(amount: number) {
+ if (!task?.value) {
+ return
+ }
+ apiReportWork({
+ procedureId: task.value?.Procedure.ID,
+ reportAmount: amount,
+ workerID: workers.value[0].workerId
+ })
+ .then((res) => {
+ if (res.code === 200) {
+ ElMessage({
+ message: '鎶ュ伐鎴愬姛',
+ type: 'success',
+ duration: 2000
+ })
+ showReportModal.value = false
+ } else {
+ ElMessage({
+ message: '鎶ュ伐澶辫触',
+ type: 'error',
+ duration: 3000
+ })
+ }
+ })
+ .catch((err) => {
+ console.error(err)
+ })
}
</script>
<style scoped lang="scss">
@@ -126,10 +180,12 @@
align-items: start;
width: 100%;
}
-.task-info,
-.produce-btn {
- width: 50%;
+.task-info {
flex: 1;
+ height: 100%;
+}
+.produce-btn {
+ flex-shrink: 0;
height: 100%;
}
.produce-btn {
@@ -144,7 +200,6 @@
.task-info-item {
padding: 10px 20px;
- margin-bottom: 6px;
}
.task-info-title {
font-size: 18px;
@@ -154,7 +209,7 @@
font-size: 19px;
color: $content-text-color;
font-weight: 600;
- margin-top: 12px;
+ margin-top: 4px;
}
.produce-btn {
display: flex;
--
Gitblit v1.8.0