From 2af5f043b60c1f7ac38ecccc8f5bf44743134325 Mon Sep 17 00:00:00 2001
From: cuiqian2004 <cuiqian2004@163.com>
Date: 星期五, 12 十二月 2025 18:08:00 +0800
Subject: [PATCH] test
---
pages/task/list.vue | 226 +++++++++++++++++++++++++++++++++++---------------------
1 files changed, 142 insertions(+), 84 deletions(-)
diff --git a/pages/task/list.vue b/pages/task/list.vue
index 0f2d992..561dba3 100644
--- a/pages/task/list.vue
+++ b/pages/task/list.vue
@@ -1,38 +1,39 @@
<template>
<view class="pages-task-list">
<view class="list-content" v-if="list.length > 0">
- <view class="list-header" v-if="fixedList.length > 0">鍥哄畾浠诲姟</view>
+ <view class="list-header" v-if="fixedList.length > 0">{{translate("fixed_task")}}</view>
<uni-swipe-action class="list">
- <uni-swipe-action-item :class="index== 0 ?'':'list-item'" v-for="(item,index) in fixedList" :key="index"
+ <uni-swipe-action-item class="list-item" v-for="(item,index) in fixedList" :key="index"
:auto-close="true" :disabled="taskStatus.taskGroupID == item.taskGroupID">
- <TaskItemView :taskData="item" :taskStatus="taskStatus" @click-item="clickEditTask"
- @click-play="clickPlayTask" @click-pause="clickPauseTask" @click-stop="clickStopTask"
- @click-skip="clickSkipTask" @click-repeat="clickRepeatTask">
+ <TaskItemView :taskData="item" :taskStatus="taskStatus" :showTaskRunning="showTaskRunning"
+ @click-btn="clickTaskBtn" @click-item="clickEditTask" @click-play="clickPlayTask"
+ @click-pause="clickPauseTask" @click-stop="clickStopTask" @click-skip="clickSkipTask"
+ @click-repeat="clickRepeatTask">
</TaskItemView>
<template v-slot:right>
- <view class="btn-del" @click="clickDelSetTask(item)">鍒犻櫎</view>
+ <view class="btn-del" @click="clickDelSetTask(item)">{{translate("delete")}}</view>
</template>
</uni-swipe-action-item>
</uni-swipe-action>
- <view class="list-header" v-if="tempList.length > 0">涓存椂浠诲姟</view>
+ <view class="list-header" v-if="tempList.length > 0">{{translate("temporary_task")}}</view>
<uni-swipe-action class="list">
- <uni-swipe-action-item :class="index== 0 ?'':'list-item'" v-for="(item,index) in tempList" :key="index"
+ <uni-swipe-action-item class="list-item" v-for="(item,index) in tempList" :key="index"
:auto-close="true" :disabled="taskStatus.taskGroupID == item.taskGroupID">
- <TaskItemView :taskData="item" :taskStatus="taskStatus" @click-item="clickEditTask"
- @click-play="clickPlayTask" @click-pause="clickPauseTask" @click-stop="clickStopTask"
- @click-skip="clickSkipTask" @click-repeat="clickRepeatTask">
- </TaskItemView>
+ <TaskItemView :taskData="item" :taskStatus="taskStatus" :showTaskRunning="showTaskRunning"
+ @click-btn="clickTaskBtn" @click-item="clickEditTask" @click-play="clickPlayTask"
+ @click-pause="clickPauseTask" @click-stop="clickStopTask" @click-skip="clickSkipTask"
+ @click-repeat="clickRepeatTask"></TaskItemView>
<template v-slot:right>
- <view class="btn-del" @click="clickDelSetTask(item)">鍒犻櫎</view>
+ <view class="btn-del" @click="clickDelSetTask(item)">{{translate("delete")}}</view>
</template>
</uni-swipe-action-item>
</uni-swipe-action>
</view>
<view class="list-no-content" v-else>
<uni-icons color="#ccc" type="info" size="128"></uni-icons>
- <view class="space">娌℃湁鎵惧埌绗﹀悎鏉′欢鐨勪换鍔�/view>
+ <view class="space">{{translate("not_task_found")}}</view>
</view>
- <view class="position-add" @click="clickAddTask()" @touchstart='btnAddTouchStart' @touchmove='btnAddTouchMove'
+ <view class="position-add" @click="clickAddTask" @touchstart='btnAddTouchStart' @touchmove='btnAddTouchMove'
:style="{transform:`translate(${btnAddInfo.x}px,${btnAddInfo.y}px) scale(1)`}">
<uni-icons class="img" type="plus-filled" size="80" color="#1890FF"></uni-icons>
</view>
@@ -44,6 +45,8 @@
showToast,
showModal,
session,
+ showError,
+ showInfo
} from "@/comm/utils.js"
import TaskItemView from "./infos/task-item.vue"
import {
@@ -57,13 +60,15 @@
import {
v4 as uuidv4
} from 'uuid';
+
export default {
- name: "PagesTasklist",
+ name: "PagesTaskList",
components: {
TaskItemView
},
data() {
return {
+ loading: false,
ip: "",
sceneId: "",
list: [],
@@ -73,7 +78,7 @@
[]
], // 姣忎釜椤圭洰鐨勫亸绉婚噺
options: [{
- text: '鍒犻櫎',
+ text: this.translate('delete'),
style: {
backgroundColor: '#F56C6C'
}
@@ -85,6 +90,7 @@
x: 0,
y: 0
},
+ showTaskRunning: false,
}
},
computed: {
@@ -98,7 +104,23 @@
onLoad(option) {
this.ip = option.ip || ""
this.sceneId = option.sceneId || ""
- this.loadData()
+ this.isPageVisible = true
+ this.$nextTick(() => {
+ this.loadData()
+ })
+
+ },
+ onShow() {
+ this.isPageVisible = true
+
+
+ },
+ onHide() {
+ this.isPageVisible = false
+
+ },
+ onUnload() {
+ this.isPageVisible = false
},
methods: {
setData(obj) {
@@ -135,56 +157,73 @@
}
this.btnAddInfo = btninfo
}
+ this.loadTaskList()
+ this.timerCheckTaskGroupStatus()
+
+ } catch (ex) {
+
+ showError(ex, this.translate('error'))
+ }
+ },
+ async loadTaskList() {
+ try {
+ uni.showLoading({
+ title: this.translate("loading")
+ })
const res = await tasks(this.ip)
const list = res?.data || []
this.list = list
- if (this.list.length > 0) {
- this.timerCheckTaskGroupStatus()
- }
} catch (ex) {
- this.showError(ex)
+ showError(ex, this.translate('error'))
+ } finally {
+ uni.hideLoading()
}
+
},
+
async timerCheckTaskGroupStatus() {
- if (this.timerCheckStatusId) {
- return
+ try {
+ if (this.isPageVisible)
+ await this.checkTaskGroupStatus()
+ // setTimeout(this.timerCheckTaskGroupStatus, 1000);
+ } catch (ex) {
+ showToast(ex)
+ // showError(ex,this.translate('error')).then((res)=>{
+ // setTimeout(this.timerCheckTaskGroupStatus, 1000);
+ // })
+ } finally {
+ setTimeout(this.timerCheckTaskGroupStatus, 1000);
}
- if (this.list.length == 0) {
- return
- }
- await this.checkTaskGroupStatus()
- this.timerCheckStatusId = setTimeout(() => {
- this.timerCheckStatusId = 0
- this.timerCheckTaskGroupStatus()
- }, 1000)
},
async checkTaskGroupStatus() {
try {
- const key = `task_cmd_id_${this.ip.replace(".","_")}`
- const cmdID = session.getValue(key)
- if (cmdID) {
- const info = await taskGroupStatus(this.ip) || {}
- if (info.taskGroupCmdID == cmdID) {
-
- const list = info.taskStatusList || []
+ const info = await taskGroupStatus(this.ip) || {}
+ if (info.taskGroupID) {
+ if (this.list.length == 0) {
+ await this.loadTaskList()
+ }
+ const curIndex = this.list.findIndex((a) => a.taskGroupID == info.taskGroupID)
+ if (curIndex > -1) {
+ let list = info.taskStatusList || []
+ list = list.filter((a) => a.cycleNumber == info.curCycleNumber)
for (let i in list) {
- if (list[i].status != 1 && list[i].status != 0) {
- this.taskStatus = {}
+ if (list[i].status == 1 || list[i].status == 0) {
+ this.taskStatus = info
return
}
}
- this.taskStatus = info
+ this.taskStatus = {}
return
}
-
}
+
this.taskStatus = {}
} catch (ex) {
this.taskStatus = {}
- this.showError(ex)
+ showToast(ex)
}
},
setTaskGroupStatus(cmdID) {
@@ -194,12 +233,13 @@
},
clickAddTask() {
const _this = this
+
uni.navigateTo({
- url: `/pages/task/add?ip=${this.ip}&title=鏂板浠诲姟`,
+ url: `/pages/task/add?ip=${this.ip}&title=${this.translate("new_task")}`,
events: {
// 涓烘寚瀹氫簨浠舵坊鍔犱竴涓洃鍚櫒锛岃幏鍙栬鎵撳紑椤甸潰浼犻�鍒板綋鍓嶉〉闈㈢殑鏁版嵁
add_task: function(data) {
- _this.loadData()
+ _this.loadTaskList()
},
}
})
@@ -244,15 +284,16 @@
session.setValue('task_btn_add', this.btnAddInfo)
},
-
-
+ clickTaskBtn(item) {
+ this.showTaskRunning = !this.showTaskRunning
+ },
clickEditTask(item) {
const _this = this
if (this.taskStatus.taskGroupID == item.taskGroupID) {
return
}
uni.navigateTo({
- url: `/pages/task/update?ip=${this.ip}&title=鏇存柊浠诲姟&task=${JSON.stringify(item)}`,
+ url: `/pages/task/update?ip=${this.ip}&title=${this.translate("update_task")}&task=${JSON.stringify(item)}`,
events: {
// 涓烘寚瀹氫簨浠舵坊鍔犱竴涓洃鍚櫒锛岃幏鍙栬鎵撳紑椤甸潰浼犻�鍒板綋鍓嶉〉闈㈢殑鏁版嵁
update_task: function(data) {
@@ -278,15 +319,16 @@
this.setTaskGroupStatus(cmdID)
} catch (ex) {
- this.showError(ex)
+ showError(ex, this.translate('error'))
}
},
async clickStopTask(item) {
try {
await addTaskGroupCmd(this.ip, item.taskGroupID, this.taskStatus.taskGroupCmdID, 2)
+ showToast(this.translate("task_terminated_success"))
} catch (ex) {
- this.showError(ex)
+ showError(ex, this.translate('error'))
}
},
@@ -294,7 +336,8 @@
try {
- const taskStatusList = this.taskStatus.taskStatusList || []
+ let taskStatusList = this.taskStatus.taskStatusList || []
+ taskStatusList = taskStatusList.filter((a) => a.cycleNumber == this.taskStatus.curCycleNumber)
let curIdx = taskStatusList.findIndex((a) => a.status == 1)
if (curIdx < 0)
curIdx = taskStatusList.findIndex((a) => a.status == 0)
@@ -306,17 +349,16 @@
})
await cancelTask(this.ip,
item.taskGroupID,
- this.taskStatus.taskGroupCmdID,
+ this.taskStatus.taskGroupCmdID,
taskList
)
-
- showToast("璺宠繃瀛愪换鍔℃垚鍔�)
+ showToast(this.translate("skip_sub_task_success"))
} else {
- showToast("鏈壘鍒版湭寮�鎴栨鍦ㄦ墽琛岀殑瀛愪换鍔�)
+ showToast(this.translate("no_sub_task_found_not_started_or_executing"))
}
} catch (ex) {
- this.showError(ex)
+ showError(ex, this.translate('error'))
}
},
@@ -327,12 +369,18 @@
async clickPauseTask(item) {},
clickDelSetTask(item) {
- showModal("纭鍒犻櫎浠诲姟璁剧疆", "璀﹀憡").then((res) => {
- if (res) {
- this.deleteTask(item)
+ showModal({
+ title: this.translate('ask_confirm_delete'),
+ content: this.translate('history_task_will_be_retained'),
+ confirmText: this.translate('delete'),
+ cancelText: this.translate('cancel'),
+ })
+ .then((res) => {
+ if (res) {
+ this.deleteTask(item)
- }
- })
+ }
+ })
},
async deleteTask(item) {
try {
@@ -343,25 +391,21 @@
const index = list.findIndex((a) =>
a.taskGroupID == item.taskGroupID
)
- console.log(index, item, list)
+ showToast(this.translate("delete_success"))
if (index < 0)
return
list.splice(index, 1)
this.list = [...list]
} catch (ex) {
- this.showError(ex)
+ showError(ex, this.translate('error'))
}
},
-
- showError(ex) {
- let exStr = JSON.stringify(ex)
- if (exStr == "{}")
- exStr = ex
- let tip = typeof ex.msg == "string" ? ex.msg : exStr
- showModal(tip, "閿欒", false)
+ translate(t) {
+ if (typeof this.$t == "function") return this.$t(`page.${t}`)
+ else return t;
},
}
}
@@ -378,15 +422,26 @@
.list-content {
display: flex;
width: 100%;
- padding: 0 10px;
+ padding: 10rpx 10px;
flex: 1;
flex-direction: column;
overflow-y: auto;
overflow-x: hidden;
.list-header {
- margin: 10px;
+ margin: 10rpx 10px;
// border-bottom: 1px solid #ddd;
+ }
+
+ .btn-del {
+ // margin: 10rpx;
+ display: flex;
+ padding: 0 10rpx;
+ background-color: #FF4D4F;
+ font-weight: 700;
+ color: #fff;
+ justify-content: center;
+ align-items: center;
}
.list {
@@ -397,20 +452,23 @@
.list-item {
- border-top: 1px solid #ddd;
+ border-bottom: 1px solid #ddd;
}
+
+ .list-item:first-child {
+ border-top-right-radius: 10px;
+ /* 鍙充笅瑙�*/
+ }
+
+ .list-item:last-child {
+ border-bottom: 0;
+ border-bottom-right-radius: 10px;
+ /* 鍙充笅瑙�*/
+ }
+
}
- .btn-del {
- margin: 10rpx;
- display: flex;
- padding: 0 10rpx;
- background-color: #FF4D4F;
- font-weight: 700;
- color: #fff;
- justify-content: center;
- align-items: center;
- }
+
}
--
Gitblit v1.9.1