143 lines
2.8 KiB
JavaScript
143 lines
2.8 KiB
JavaScript
|
|
// 任务卡片组件逻辑
|
|||
|
|
const { TASK_STATUS } = require('../../utils/constant.js')
|
|||
|
|
|
|||
|
|
Component({
|
|||
|
|
properties: {
|
|||
|
|
// 任务ID
|
|||
|
|
taskId: {
|
|||
|
|
type: String,
|
|||
|
|
value: ''
|
|||
|
|
},
|
|||
|
|
// 任务标题
|
|||
|
|
title: {
|
|||
|
|
type: String,
|
|||
|
|
value: ''
|
|||
|
|
},
|
|||
|
|
// 任务描述
|
|||
|
|
description: {
|
|||
|
|
type: String,
|
|||
|
|
value: ''
|
|||
|
|
},
|
|||
|
|
// 任务类型
|
|||
|
|
type: {
|
|||
|
|
type: String,
|
|||
|
|
value: ''
|
|||
|
|
},
|
|||
|
|
// 任务状态
|
|||
|
|
status: {
|
|||
|
|
type: String,
|
|||
|
|
value: TASK_STATUS.PENDING
|
|||
|
|
},
|
|||
|
|
// 优先级
|
|||
|
|
priority: {
|
|||
|
|
type: String,
|
|||
|
|
value: ''
|
|||
|
|
},
|
|||
|
|
// 创建时间
|
|||
|
|
createdAt: {
|
|||
|
|
type: String,
|
|||
|
|
value: ''
|
|||
|
|
},
|
|||
|
|
// 更新时间
|
|||
|
|
updatedAt: {
|
|||
|
|
type: String,
|
|||
|
|
value: ''
|
|||
|
|
},
|
|||
|
|
// 处理结果
|
|||
|
|
result: {
|
|||
|
|
type: String,
|
|||
|
|
value: ''
|
|||
|
|
},
|
|||
|
|
// 进度(0-100)
|
|||
|
|
progress: {
|
|||
|
|
type: Number,
|
|||
|
|
value: 0
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
data: {
|
|||
|
|
statusText: ''
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
lifetimes: {
|
|||
|
|
attached() {
|
|||
|
|
this.updateStatusText()
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
observers: {
|
|||
|
|
'status': function(status) {
|
|||
|
|
this.updateStatusText()
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
methods: {
|
|||
|
|
// 更新状态文本
|
|||
|
|
updateStatusText() {
|
|||
|
|
const statusMap = {
|
|||
|
|
[TASK_STATUS.PENDING]: '待处理',
|
|||
|
|
[TASK_STATUS.PROCESSING]: '处理中',
|
|||
|
|
[TASK_STATUS.COMPLETED]: '已完成',
|
|||
|
|
[TASK_STATUS.FAILED]: '处理失败',
|
|||
|
|
[TASK_STATUS.CANCELLED]: '已取消'
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
this.setData({
|
|||
|
|
statusText: statusMap[this.properties.status] || '未知状态'
|
|||
|
|
})
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
// 开始处理任务
|
|||
|
|
startTask() {
|
|||
|
|
this.triggerEvent('start', {
|
|||
|
|
taskId: this.properties.taskId,
|
|||
|
|
title: this.properties.title
|
|||
|
|
})
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
// 完成任务
|
|||
|
|
completeTask() {
|
|||
|
|
this.triggerEvent('complete', {
|
|||
|
|
taskId: this.properties.taskId,
|
|||
|
|
title: this.properties.title
|
|||
|
|
})
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
// 重试任务
|
|||
|
|
retryTask() {
|
|||
|
|
this.triggerEvent('retry', {
|
|||
|
|
taskId: this.properties.taskId,
|
|||
|
|
title: this.properties.title
|
|||
|
|
})
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
// 查看任务详情
|
|||
|
|
viewDetails() {
|
|||
|
|
this.triggerEvent('detail', {
|
|||
|
|
taskId: this.properties.taskId,
|
|||
|
|
title: this.properties.title,
|
|||
|
|
description: this.properties.description,
|
|||
|
|
status: this.properties.status,
|
|||
|
|
result: this.properties.result,
|
|||
|
|
createdAt: this.properties.createdAt,
|
|||
|
|
updatedAt: this.properties.updatedAt
|
|||
|
|
})
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
// 取消任务
|
|||
|
|
cancelTask() {
|
|||
|
|
wx.showModal({
|
|||
|
|
title: '确认取消',
|
|||
|
|
content: `确定要取消任务"${this.properties.title}"吗?`,
|
|||
|
|
success: (res) => {
|
|||
|
|
if (res.confirm) {
|
|||
|
|
this.triggerEvent('cancel', {
|
|||
|
|
taskId: this.properties.taskId,
|
|||
|
|
title: this.properties.title
|
|||
|
|
})
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
})
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
})
|