cuiqian2004
4 天以前 2af5f043b60c1f7ac38ecccc8f5bf44743134325
pages/task/list.vue
@@ -1,7 +1,7 @@
<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="list-item" v-for="(item,index) in fixedList" :key="index"
               :auto-close="true" :disabled="taskStatus.taskGroupID == item.taskGroupID">
@@ -11,11 +11,11 @@
                  @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="list-item" v-for="(item,index) in tempList" :key="index"
               :auto-close="true" :disabled="taskStatus.taskGroupID == item.taskGroupID">
@@ -24,16 +24,16 @@
                  @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>
@@ -60,17 +60,15 @@
   import {
      v4 as uuidv4
   } from 'uuid';
   import {
      filter
   } from "rxjs";
   export default {
      name: "PagesTasklist",
      name: "PagesTaskList",
      components: {
         TaskItemView
      },
      data() {
         return {
            loading:false,
            loading: false,
            ip: "",
            sceneId: "",
            list: [],
@@ -80,7 +78,7 @@
               []
            ], // 每个项目的偏移量
            options: [{
               text: '删除',
               text: this.translate('delete'),
               style: {
                  backgroundColor: '#F56C6C'
               }
@@ -107,10 +105,10 @@
         this.ip = option.ip || ""
         this.sceneId = option.sceneId || ""
         this.isPageVisible = true
         this.$nextTick(()=>{
         this.$nextTick(() => {
            this.loadData()
         })
      },
      onShow() {
         this.isPageVisible = true
@@ -164,34 +162,38 @@
            } catch (ex) {
               showError(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
               showToast(`装载了${list.length}任务`)
            } catch (ex) {
               showError(ex)
               showError(ex, this.translate('error'))
            } finally {
               uni.hideLoading()
            }
         },
         async timerCheckTaskGroupStatus() {
            try {
               if (this.isPageVisible)
                  await this.checkTaskGroupStatus()
                  // setTimeout(this.timerCheckTaskGroupStatus, 1000);
               // setTimeout(this.timerCheckTaskGroupStatus, 1000);
            } catch (ex) {
               showToast(ex)
               // showError(ex).then((res)=>{
               // showError(ex,this.translate('error')).then((res)=>{
               //    setTimeout(this.timerCheckTaskGroupStatus, 1000);
               // })
            } finally {
                  setTimeout(this.timerCheckTaskGroupStatus, 1000);
               setTimeout(this.timerCheckTaskGroupStatus, 1000);
            }
         },
         async checkTaskGroupStatus() {
@@ -231,9 +233,9 @@
         },
         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) {
@@ -291,7 +293,7 @@
               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) {
@@ -317,16 +319,16 @@
               this.setTaskGroupStatus(cmdID)
            } catch (ex) {
               showError(ex)
               showError(ex, this.translate('error'))
            }
         },
         async clickStopTask(item) {
            try {
               await addTaskGroupCmd(this.ip, item.taskGroupID, this.taskStatus.taskGroupCmdID, 2)
               showToast("终止任务成功")
               showToast(this.translate("task_terminated_success"))
            } catch (ex) {
               showError(ex)
               showError(ex, this.translate('error'))
            }
         },
@@ -350,14 +352,13 @@
                     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) {
               showError(ex)
               showError(ex, this.translate('error'))
            }
         },
@@ -368,12 +369,18 @@
         async clickPauseTask(item) {},
         clickDelSetTask(item) {
            showModal("确认删除任务设置", "警告", true, "确定", "取消").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 {
@@ -384,19 +391,22 @@
               const index = list.findIndex((a) =>
                  a.taskGroupID == item.taskGroupID
               )
               showToast("删除任务成功")
               showToast(this.translate("delete_success"))
               if (index < 0)
                  return
               list.splice(index, 1)
               this.list = [...list]
            } catch (ex) {
               showError(ex)
               showError(ex, this.translate('error'))
            }
         },
         translate(t) {
            if (typeof this.$t == "function") return this.$t(`page.${t}`)
            else return t;
         },
      }
   }
</script>