<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>
|
<uni-swipe-action class="list">
|
<uni-swipe-action-item :class="index== 0 ?'':'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>
|
<template v-slot:right>
|
<view class="btn-del" @click="clickDelSetTask(item)">删除</view>
|
</template>
|
</uni-swipe-action-item>
|
</uni-swipe-action>
|
<view class="list-header" v-if="tempList.length > 0">临时任务</view>
|
<uni-swipe-action class="list">
|
<uni-swipe-action-item :class="index== 0 ?'':'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>
|
<template v-slot:right>
|
<view class="btn-del" @click="clickDelSetTask(item)">删除</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>
|
<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>
|
</view>
|
</template>
|
|
<script>
|
import {
|
showToast,
|
showModal,
|
session,
|
} from "@/comm/utils.js"
|
import TaskItemView from "./infos/task-item.vue"
|
import {
|
tasks,
|
taskGroupStatus,
|
addTaskGroupCmd,
|
cancelTask,
|
delTask
|
|
} from "@/api/vehicle.js"
|
import {
|
v4 as uuidv4
|
} from 'uuid';
|
export default {
|
name: "PagesTasklist",
|
components: {
|
TaskItemView
|
},
|
data() {
|
return {
|
ip: "",
|
sceneId: "",
|
list: [],
|
startX: 0, // 触摸起始点
|
deleteX: [
|
[],
|
[]
|
], // 每个项目的偏移量
|
options: [{
|
text: '删除',
|
style: {
|
backgroundColor: '#F56C6C'
|
}
|
}],
|
taskStatus: {},
|
btnAddInfo: {
|
lx: 0,
|
ly: 0,
|
x: 0,
|
y: 0
|
},
|
}
|
},
|
computed: {
|
fixedList() {
|
return this.list.filter((a) => a.tasktype == 1)
|
},
|
tempList() {
|
return this.list.filter((a) => a.tasktype != 1)
|
},
|
},
|
onLoad(option) {
|
this.ip = option.ip || ""
|
this.sceneId = option.sceneId || ""
|
this.loadData()
|
},
|
methods: {
|
setData(obj) {
|
let that = this;
|
let keys = [];
|
let val, data;
|
|
Object.keys(obj).forEach(function(key) {
|
keys = key.split(".");
|
val = obj[key];
|
data = that.$data;
|
keys.forEach(function(key2, index) {
|
if (index + 1 == keys.length) {
|
that.$set(data, key2, val);
|
} else {
|
if (!data[key2]) {
|
that.$set(data, key2, {});
|
}
|
}
|
data = data[key2];
|
});
|
});
|
},
|
async loadData() {
|
try {
|
let btninfo = session.getValue('task_btn_add')
|
if (btninfo) {
|
|
if (btninfo.x > 10) {
|
btninfo.x = 10
|
}
|
if (btninfo.x > 40) {
|
btninfo.x = 40
|
}
|
this.btnAddInfo = btninfo
|
}
|
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)
|
}
|
},
|
async timerCheckTaskGroupStatus() {
|
if (this.timerCheckStatusId) {
|
return
|
}
|
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 || []
|
for (let i in list) {
|
if (list[i].status != 1 && list[i].status != 0) {
|
this.taskStatus = {}
|
return
|
}
|
}
|
this.taskStatus = info
|
return
|
}
|
|
}
|
this.taskStatus = {}
|
|
} catch (ex) {
|
|
this.taskStatus = {}
|
this.showError(ex)
|
}
|
},
|
setTaskGroupStatus(cmdID) {
|
const key = `task_cmd_id_${this.ip.replace(".","_")}`
|
session.setValue(key, cmdID)
|
|
},
|
clickAddTask() {
|
const _this = this
|
uni.navigateTo({
|
url: `/pages/task/add?ip=${this.ip}&title=新增任务`,
|
events: {
|
// 为指定事件添加一个监听器,获取被打开页面传送到当前页面的数据
|
add_task: function(data) {
|
_this.loadData()
|
},
|
}
|
})
|
},
|
btnAddTouchStart(e) {
|
this.btnAddInfo.lx = e.touches[0].clientX;
|
this.btnAddInfo.ly = e.touches[0].clientY;
|
},
|
btnAddTouchMove(e) {
|
|
if (this.btnAddInfo.ly < 40) {
|
this.btnAddInfo.x += (e.touches[0].clientX - this.btnAddInfo.lx)
|
this.btnAddInfo.lx = e.touches[0].clientX;
|
this.btnAddInfo.ly = e.touches[0].clientY;
|
if (this.btnAddInfo.x < 50 - this.windowWidth) {
|
this.btnAddInfo.x = 50 - this.windowWidth
|
}
|
if (this.btnAddInfo.x > 40) {
|
this.btnAddInfo.x = 40
|
}
|
session.setValue('task_btn_add', this.btnAddInfo)
|
return
|
}
|
|
this.btnAddInfo.x += (e.touches[0].clientX - this.btnAddInfo.lx)
|
this.btnAddInfo.y += (e.touches[0].clientY - this.btnAddInfo.ly)
|
this.btnAddInfo.lx = e.touches[0].clientX;
|
this.btnAddInfo.ly = e.touches[0].clientY;
|
|
|
if (this.btnAddInfo.x < 50 - this.windowWidth) {
|
this.btnAddInfo.x = 50 - this.windowWidth
|
}
|
if (this.btnAddInfo.x > 40) {
|
this.btnAddInfo.x = 40
|
}
|
if (this.btnAddInfo.y > 80) {
|
this.btnAddInfo.y = 80
|
}
|
|
|
|
session.setValue('task_btn_add', this.btnAddInfo)
|
},
|
|
|
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)}`,
|
events: {
|
// 为指定事件添加一个监听器,获取被打开页面传送到当前页面的数据
|
update_task: function(data) {
|
const curIndex = _this.list.findIndex((a) => a.taskGroupID == data.taskGroupID)
|
if (curIndex > -1) {
|
_this.list[curIndex] = {
|
taskGroupID: data.taskGroupID,
|
taskGroupName: data.taskGroupName,
|
cycleTime: data.cycleTime,
|
taskButton: data.taskButton,
|
tasktype: data.tasktype,
|
taskList: data.taskList
|
}
|
}
|
},
|
}
|
})
|
},
|
async clickPlayTask(item) {
|
try {
|
const cmdID = uuidv4()
|
await addTaskGroupCmd(this.ip, item.taskGroupID, cmdID, 1)
|
this.setTaskGroupStatus(cmdID)
|
|
} catch (ex) {
|
this.showError(ex)
|
}
|
},
|
|
async clickStopTask(item) {
|
try {
|
await addTaskGroupCmd(this.ip, item.taskGroupID, this.taskStatus.taskGroupCmdID, 2)
|
} catch (ex) {
|
this.showError(ex)
|
}
|
},
|
|
async clickSkipTask(item) {
|
try {
|
|
|
const taskStatusList = this.taskStatus.taskStatusList || []
|
let curIdx = taskStatusList.findIndex((a) => a.status == 1)
|
if (curIdx < 0)
|
curIdx = taskStatusList.findIndex((a) => a.status == 0)
|
if (curIdx > -1) {
|
const taskList = []
|
taskList.push({
|
taskID: taskStatusList[curIdx].taskID,
|
is_cancel: 1
|
})
|
await cancelTask(this.ip,
|
item.taskGroupID,
|
this.taskStatus.taskGroupCmdID,
|
taskList
|
)
|
|
showToast("跳过子任务成功")
|
|
} else {
|
showToast("未找到未开始或正在执行的子任务")
|
}
|
} catch (ex) {
|
this.showError(ex)
|
}
|
},
|
|
async clickRepeatTask(item) {
|
|
|
},
|
|
async clickPauseTask(item) {},
|
clickDelSetTask(item) {
|
showModal("确认删除任务设置", "警告").then((res) => {
|
if (res) {
|
this.deleteTask(item)
|
|
}
|
})
|
},
|
async deleteTask(item) {
|
try {
|
await delTask(this.ip, [{
|
taskGroupID: item.taskGroupID,
|
}])
|
const list = this.list
|
const index = list.findIndex((a) =>
|
a.taskGroupID == item.taskGroupID
|
)
|
console.log(index, item, list)
|
if (index < 0)
|
return
|
list.splice(index, 1)
|
this.list = [...list]
|
|
} catch (ex) {
|
this.showError(ex)
|
}
|
|
},
|
|
|
showError(ex) {
|
let exStr = JSON.stringify(ex)
|
if (exStr == "{}")
|
exStr = ex
|
let tip = typeof ex.msg == "string" ? ex.msg : exStr
|
showModal(tip, "错误", false)
|
},
|
}
|
}
|
</script>
|
|
<style lang="scss">
|
.pages-task-list {
|
display: flex;
|
width: 750rpx;
|
height: 100vh;
|
flex-direction: column;
|
position: relative;
|
|
.list-content {
|
display: flex;
|
width: 100%;
|
padding: 0 10px;
|
flex: 1;
|
flex-direction: column;
|
overflow-y: auto;
|
overflow-x: hidden;
|
|
.list-header {
|
margin: 10px;
|
// border-bottom: 1px solid #ddd;
|
}
|
|
.list {
|
// border: 1px solid #ccc;
|
border-radius: 10px;
|
|
background-color: #fff;
|
|
.list-item {
|
|
border-top: 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-no-content {
|
margin-top: 50px;
|
padding: 20rpx 40rpx;
|
align-items: center;
|
text-align: center;
|
display: flex;
|
flex-direction: column;
|
font-size: 30rpx;
|
font-weight: 400;
|
|
.img {
|
width: 212rpx;
|
height: 212rpx;
|
color: #ddd;
|
}
|
|
.space {
|
margin-top: 20rpx;
|
}
|
|
}
|
|
.position-add {
|
position: fixed;
|
right: 10px;
|
bottom: 40px;
|
}
|
}
|
</style>
|