This commit is contained in:
张成
2025-12-19 13:24:12 +08:00
parent 34ebad316a
commit eca314e686
3 changed files with 106 additions and 61 deletions

File diff suppressed because one or more lines are too long

View File

@@ -177,7 +177,7 @@
</div>
<div class="priority-total-display">
<span>总权重<strong :class="{ 'weight-warning': totalWeight !== 100 }">{{ totalWeight
}}%</strong></span>
}}%</strong></span>
</div>
</div>
<div v-else class="empty-config">暂无配置</div>
@@ -357,20 +357,40 @@
</div>
<TabPane name="tasks" label="任务列表">
<div class="tab-content">
<div class="tab-body" v-if="tasksLoading">
<tables :columns="taskColumns" :value="tasksData"
:pageOption="tasksPageOption" @changePage="queryTasks">
</tables>
<div class="tab-body">
<Table :columns="taskColumns" :data="tasksData" :loading="tasksLoading" border>
</Table>
<Page
:current="tasksPageOption.page"
:total="tasksPageOption.total"
:page-size="tasksPageOption.pageSize"
show-total
show-elevator
show-sizer
@on-change="queryTasks"
@on-page-size-change="handleTasksPageSizeChange"
style="margin-top: 16px; text-align: right;">
</Page>
</div>
</div>
</TabPane>
<TabPane name="commands" label="指令列表">
<div class="tab-content">
<div class="tab-body" v-if="commandsLoading">
<tables :columns="commandColumns" :value="commandsData"
:pageOption="commandsPageOption" @changePage="queryCommands">
</tables>
<div class="tab-body">
<Table :columns="commandColumns" :data="commandsData" :loading="commandsLoading" border>
</Table>
<Page
:current="commandsPageOption.page"
:total="commandsPageOption.total"
:page-size="commandsPageOption.pageSize"
show-total
show-elevator
show-sizer
@on-change="queryCommands"
@on-page-size-change="handleCommandsPageSizeChange"
style="margin-top: 16px; text-align: right;">
</Page>
</div>
</div>
</TabPane>
@@ -996,15 +1016,11 @@ export default {
}
const res = await plaAccountServer.getTasks(this.accountId, param)
console.log('res', res);
this.tasksData = res.data.rows || []
this.tasksPageOption.total = res.data.count || 0
setTimeout(() => {
this.$forceUpdate()
}, 0)
} catch (error) {
this.$Message.error('加载任务列表失败')
this.tasksData = []
@@ -1030,9 +1046,6 @@ export default {
this.commandsData = res.data.rows || []
this.commandsPageOption.total = res.data.count || 0
setTimeout(() => {
this.$forceUpdate()
}, 0)
} catch (error) {
this.$Message.error('加载指令列表失败')
this.commandsData = []
@@ -1064,9 +1077,7 @@ export default {
await plaAccountServer.retryCommand(command.id)
this.$Message.success('重试指令成功')
// 刷新指令列表
setTimeout(() => {
this.queryCommands(this.commandsPageOption.page)
}, 1000)
} catch (error) {
console.error('重试指令失败:', error)
this.$Message.error(error.message || '重试指令失败')
@@ -1113,6 +1124,20 @@ export default {
}
},
// 任务列表分页大小改变
handleTasksPageSizeChange(pageSize) {
this.tasksPageOption.pageSize = pageSize
this.tasksPageOption.page = 1
this.queryTasks(1)
},
// 指令列表分页大小改变
handleCommandsPageSizeChange(pageSize) {
this.commandsPageOption.pageSize = pageSize
this.commandsPageOption.page = 1
this.queryCommands(1)
},
// 处理刷新
handleRefresh() {
if (this.activeTab === 'tasks') {
@@ -1673,13 +1698,23 @@ export default {
.tab-content {
display: flex;
flex-direction: column;
min-height: 400px;
min-height: 500px;
}
.tab-body {
flex: 1;
padding: 20px;
overflow: visible;
min-height: 500px;
}
/* TabPane 最小高度 */
.tabs-card>>>.ivu-tabs-content {
min-height: 500px;
}
.tabs-card>>>.ivu-tabs-tabpane {
min-height: 500px;
}
/* Tab右侧按钮 */

View File

@@ -243,13 +243,18 @@ class PlaAccountService {
}
// 通过 sn_code 查询任务列表
// 使用 attributes 只查询需要的字段,提升性能
const result = await task_status.findAndCountAll({
where: {
sn_code: account.sn_code
},
limit,
offset,
order: [['id', 'DESC']]
order: [['id', 'DESC']],
// 不查询大字段以提升性能
attributes: {
exclude: ['taskParams', 'result', 'errorMessage', 'errorStack']
}
});
// 将 Sequelize 模型实例转换为普通对象
@@ -271,7 +276,6 @@ class PlaAccountService {
const task_commands = db.getModel('task_commands');
const task_status = db.getModel('task_status');
const Sequelize = require('sequelize');
const Op = Sequelize.Op;
const { id, limit, offset } = params;
@@ -285,44 +289,50 @@ class PlaAccountService {
throw new Error('账号不存在');
}
// 先查询所有匹配 sn_code 的任务 ID
const tasks = await task_status.findAll({
where: {
sn_code: account.sn_code
},
attributes: ['id']
});
// 使用子查询优化性能,避免先查询所有任务ID
const sequelize = task_commands.sequelize;
const taskIds = tasks.map(task => task.id);
// 使用子查询一次性完成查询和计数
const countSql = `
SELECT COUNT(*) as count
FROM task_commands tc
WHERE tc.task_id IN (
SELECT id FROM task_status WHERE sn_code = :sn_code
)
`;
// 如果没有任务,直接返回空结果
if (taskIds.length === 0) {
return {
count: 0,
rows: []
};
}
const dataSql = `
SELECT tc.*,
tc.create_time
FROM task_commands tc
WHERE tc.task_id IN (
SELECT id FROM task_status WHERE sn_code = :sn_code
)
ORDER BY tc.id DESC
LIMIT :limit OFFSET :offset
`;
// 使用 Sequelize 模型查询指令列表
const result = await task_commands.findAndCountAll({
where: {
task_id: {
[Op.in]: taskIds
}
},
limit,
offset,
order: [['id', 'DESC']]
});
// 并行执行查询和计数
const [countResult, dataResult] = await Promise.all([
sequelize.query(countSql, {
replacements: { sn_code: account.sn_code },
type: Sequelize.QueryTypes.SELECT
}),
sequelize.query(dataSql, {
replacements: {
sn_code: account.sn_code,
limit: limit,
offset: offset
},
type: Sequelize.QueryTypes.SELECT
})
]);
// 将 Sequelize 模型实例转换为普通对象
const rows = result.rows.map(row => {
const plainRow = row.get({ plain: true });
const count = countResult[0]?.count || 0;
// 添加 create_time 字段(使用 start_time 或 createdAt
if (!plainRow.create_time) {
plainRow.create_time = plainRow.start_time || plainRow.createdAt || null;
}
// 将原始数据转换为普通对象
const rows = dataResult.map(row => {
const plainRow = { ...row };
// 解析 JSON 字段
if (plainRow.command_params && typeof plainRow.command_params === 'string') {
@@ -344,7 +354,7 @@ class PlaAccountService {
});
return {
count: result.count,
count: parseInt(count),
rows: rows
};
}