feat(看板): 客户端任务管理从设备维度改为店铺维度全局在跑看板

原「在线设备」卡按日志上报窗口统计,把 89 台算成在线,与实际在跑的客户端数差一个
量级,且设备维度并不能回答"哪台机器上有任务卡住"。改为:

- 汇总卡:总店铺 / 在跑店铺 / 进行中任务 / 今日完成 / 疑似卡住
- 新增「在跑店铺看板」:当前所有进行中任务按店铺归组(在跑数、卡住数、业务分布、
  最近上报),点店铺行下筛该店铺任务;不落店铺的任务归「不挂店铺」桶
- 卡片与面板同源(同一个 aggregateShops),杜绝口径分裂
- 店铺只认两个真来源:上架结果文件 + 逐店落行的结果文件名;
  biz_task_progress_snapshot.current_scope_key 是实例锁不是店铺,已从口径中剔除
- 设备号退为详情附注,花名册 /devices 与在线判定整条链删除
- 上报口径只留一个 10 分钟窗口(进行中且超 10 分钟无上报 = 疑似卡住)

后端 3487 例全绿;新增反射护栏断言设备维度查询与快照当店铺的来源已彻底移除。
This commit is contained in:
2026-10-03 22:41:29 +08:00
parent e4083732a9
commit 06396d537e
18 changed files with 1222 additions and 1037 deletions
+21 -14
View File
@@ -1,27 +1,27 @@
import { http } from './http'
import { unwrap } from './envelope'
/** 客户端任务管理(后台看板):按账号 × 设备 × 业务统一查看客户端任务,全部只读。 */
/** 客户端任务管理(后台看板):按店铺 × 账号 × 业务统一查看客户端在跑任务,全部只读。 */
/** 查询参数(由页面侧 buildTaskQuery / buildVariantQuery 产出,空白项不下传)。 */
type QueryParams = Record<string, string | number>
export interface TaskCenterOverview {
deviceTotal: number
deviceOnline: number
shopTotal: number
shopRunning: number
runningTasks: number
todayFinishedTasks: number
stuckTasks: number
}
export interface TaskCenterDevice {
deviceId: string
deviceName: string | null
lastActiveAt: string | null
online: boolean
/** 店铺面板行:一个店铺在当前所有进行中任务里的汇总;「不挂店铺」是兜住无店铺模块的合成桶。 */
export interface TaskCenterShop {
shop: string
noShop: boolean
runningTasks: number
recentTaskAt: string | null
webDevice: boolean
stuckTasks: number
moduleSummary: string
lastReportAt: string | null
}
export interface TaskCenterTaskRow {
@@ -39,6 +39,7 @@ export interface TaskCenterTaskRow {
shopCount: number
createdAt: string | null
finishedAt: string | null
lastReportAt: string | null
progressTotal: number
progressSuccess: number
progressFailed: number
@@ -91,10 +92,16 @@ export async function fetchTaskCenterOverview(): Promise<TaskCenterOverview> {
return unwrap<TaskCenterOverview>(data)
}
/** 设备花名册(任务设备近 30 天 ∪ 日志设备近 7 天):GET /api/admin/task-center/devices */
export async function fetchTaskCenterDevices(): Promise<TaskCenterDevice[]> {
const { data } = await http.get('/api/admin/task-center/devices')
return unwrap<TaskCenterDevice[]>(data)
/** 店铺面板:当前全部进行中任务按店铺归组(与汇总卡的「在跑店铺」同源):GET /api/admin/task-center/shops */
export async function fetchTaskCenterShops(): Promise<TaskCenterShop[]> {
const { data } = await http.get('/api/admin/task-center/shops')
return unwrap<TaskCenterShop[]>(data)
}
/** 店铺筛选候选(店铺库内的店铺名,精确匹配):GET /api/admin/task-center/shop-options */
export async function fetchTaskCenterShopOptions(): Promise<string[]> {
const { data } = await http.get('/api/admin/task-center/shop-options')
return unwrap<string[]>(data)
}
/** 任务分页列表:GET /api/admin/task-center/tasks */
@@ -91,8 +91,8 @@ export const OPERATION_GUIDES: Record<string, OperationGuideData> = {
steps: ['选择日期范围', '筛选用户或分组', '核对各模块次数'],
},
admin_task_center: {
text: '按账号和设备查看客户端任务执行情况;点击设备可筛选该设备任务,点任务查看明细。',
steps: ['选择筛选条件', '查看设备与任务', '打开任务详情'],
text: '在跑店铺看板按店铺汇总当前进行中的客户端任务;点店铺行筛出该店铺任务,点任务查看明细。',
steps: ['看在跑店铺看板', '点店铺行筛任务', '打开任务详情'],
},
}
@@ -1,6 +1,6 @@
<script setup lang="ts">
/** 客户端任务管理看板:按账号 × 设备 × 业务统一查看客户端任务执行情况(只读,仅超管或被授权管理员)。
* 页签一「客户端任务」= biz_file_task(12 个客户端模块)∪ brand_crawl_tasks;
/** 客户端任务管理看板:全局看板看「哪些店铺有任务在跑」,再下钻到任务明细(只读,仅超管或被授权管理员)。
* 页签一「客户端任务」= biz_file_task(12 个客户端模块)∪ brand_crawl_tasks,顶部是按店铺归组的在跑面板;
* 页签二「变体采集」= 麦象批量任务(variant-collection),数据口径与列不同故独立页签。
* 30s 轮询:页面隐藏暂停、回前台立即刷新、卸载清理;另有手动刷新。 */
import { computed, onMounted, onUnmounted, reactive, ref } from 'vue'
@@ -8,13 +8,14 @@ import { ElMessage } from 'element-plus'
import OldPagination from '@/components/OldPagination.vue'
import { formatDateTime } from '@/utils/datetime'
import {
fetchTaskCenterDevices,
fetchTaskCenterOverview,
fetchTaskCenterShopOptions,
fetchTaskCenterShops,
fetchTaskCenterTaskDetail,
fetchTaskCenterTasks,
fetchTaskCenterVariantTasks,
type TaskCenterDevice,
type TaskCenterOverview,
type TaskCenterShop,
type TaskCenterTaskDetail,
type TaskCenterTaskRow,
type TaskCenterVariantTaskRow,
@@ -48,7 +49,8 @@ const activeTab = ref<BoardTab>('tasks')
// ---------------------------------------------------------------- 客户端任务
const overview = ref<TaskCenterOverview | null>(null)
const devices = ref<TaskCenterDevice[]>([])
const shops = ref<TaskCenterShop[]>([])
const shopOptions = ref<string[]>([])
const filter = reactive<TaskCenterTaskFilter>(createTaskFilter())
const tasks = ref<TaskCenterTaskRow[]>([])
const taskTotal = ref(0)
@@ -76,6 +78,15 @@ const updatedAt = ref('')
const taskTotalPages = computed(() => Math.max(1, Math.ceil(taskTotal.value / taskPageSize.value)))
const variantTotalPages = computed(() => Math.max(1, Math.ceil(variantTotal.value / variantPageSize.value)))
/** 下拉候选 = 店铺库 + 面板上出现的店铺名(后者可能已从店铺库删掉,下钻要筛得动)。 */
const shopFilterOptions = computed(() => {
const names = new Set(shopOptions.value)
for (const row of shops.value) {
if (!row.noShop) names.add(row.shop)
}
return [...names]
})
function errorText(error: unknown, fallback: string): string {
return error instanceof Error && error.message ? error.message : fallback
}
@@ -88,11 +99,20 @@ async function loadOverview() {
}
}
async function loadDevices() {
async function loadShops() {
try {
devices.value = (await fetchTaskCenterDevices()) || []
shops.value = (await fetchTaskCenterShops()) || []
} catch (error) {
ElMessage.error(errorText(error, '设备列表加载失败'))
ElMessage.error(errorText(error, '在跑店铺加载失败'))
}
}
/** 店铺库下拉候选。 */
async function loadShopOptions() {
try {
shopOptions.value = (await fetchTaskCenterShopOptions()) || []
} catch (error) {
ElMessage.error(errorText(error, '店铺候选加载失败'))
}
}
@@ -124,11 +144,12 @@ async function loadVariants(silent = false) {
}
}
/** 汇总卡与设备条只描述客户端任务,两个页签都刷新它们(切页签时看到的就是最新)。 */
/** 汇总卡与在跑店铺面板只描述客户端任务,两个页签都刷新它们(切页签时看到的就是最新)。 */
async function refreshAll(silent = false) {
await Promise.all([
loadOverview(),
loadDevices(),
loadShops(),
loadShopOptions(),
activeTab.value === 'tasks' ? loadTasks(silent) : loadVariants(silent),
])
updatedAt.value = formatDateTime(Date.now())
@@ -155,9 +176,9 @@ function resetFilter() {
void loadTasks()
}
/** 点设备卡:按该设备筛选任务(再点一次取消)。 */
function selectDevice(deviceId: string) {
filter.deviceId = filter.deviceId === deviceId ? '' : deviceId
/** 点店铺面板行:按该店铺精确筛选任务(再点一次取消);「不挂店铺」合成桶没有可下钻的店铺名。 */
function selectShop(shop: string) {
filter.shop = filter.shop === shop ? '' : shop
taskPage.value = 1
void loadTasks()
}
@@ -274,14 +295,14 @@ onUnmounted(() => {
<div v-if="activeTab === 'tasks'" class="tc-cards">
<div class="tc-card">
<span class="tc-card-label">设备总数</span>
<span class="tc-card-value">{{ overview?.deviceTotal ?? '—' }}</span>
<span class="tc-card-note">近 30 天任务 ∪ 近 7 天日志</span>
<span class="tc-card-label">总店铺</span>
<span class="tc-card-value">{{ overview?.shopTotal ?? '—' }}</span>
<span class="tc-card-note">店铺库内可见店铺</span>
</div>
<div class="tc-card">
<span class="tc-card-label">在线设备</span>
<span class="tc-card-value is-ok">{{ overview?.deviceOnline ?? '—' }}</span>
<span class="tc-card-note">5 分钟内有上报</span>
<span class="tc-card-label">在跑店铺</span>
<span class="tc-card-value is-ok">{{ overview?.shopRunning ?? '—' }}</span>
<span class="tc-card-note">有进行中任务的店铺</span>
</div>
<div class="tc-card">
<span class="tc-card-label">进行中任务</span>
@@ -298,7 +319,7 @@ onUnmounted(() => {
<span class="tc-card-value" :class="{ 'is-warn': (overview?.stuckTasks || 0) > 0 }">
{{ overview?.stuckTasks ?? '—' }}
</span>
<span class="tc-card-note">超过 10 分钟无更新</span>
<span class="tc-card-note">超过 10 分钟无上报</span>
</div>
</div>
</section>
@@ -307,31 +328,45 @@ onUnmounted(() => {
<template v-if="activeTab === 'tasks'">
<section class="panel-box">
<div class="box-head">
<h3>设备</h3>
<span class="box-note">点击设备卡按该设备筛选任务,再点一次取消</span>
<h3>在跑店铺看板</h3>
<span class="box-note">全局看每家店当前有哪些任务在跑,点店铺行筛出它的任务,不必逐台客户端检查</span>
</div>
<div v-if="devices.length" class="device-strip">
<button
v-for="device in devices"
:key="device.deviceId"
class="device-card"
:class="{ active: filter.deviceId === device.deviceId, online: device.online }"
type="button"
:title="device.deviceId"
@click="selectDevice(device.deviceId)"
>
<span class="device-line">
<span class="dot" :class="device.online ? 'is-online' : 'is-offline'"></span>
<span class="device-name">{{ deviceDisplayName(device.deviceName, device.deviceId) }}</span>
<span v-if="device.webDevice" class="badge web">网页</span>
</span>
<span class="device-meta">
{{ device.runningTasks > 0 ? `跑任务 ${device.runningTasks}` : '空闲' }} ·
{{ device.lastActiveAt ? formatDateTime(device.lastActiveAt) : '窗口内无活动' }}
</span>
</button>
<div v-if="shops.length" class="table-scroll">
<table>
<thead>
<tr>
<th style="width: 210px">店铺</th>
<th style="width: 90px">在跑任务</th>
<th style="width: 90px">疑似卡住</th>
<th style="width: 230px">业务分布</th>
<th style="width: 165px">最近上报</th>
</tr>
</thead>
<tbody>
<tr
v-for="row in shops"
:key="row.shop"
class="shop-row"
:class="{ 'is-bucket': row.noShop, active: !row.noShop && filter.shop === row.shop }"
@click="row.noShop ? null : selectShop(row.shop)"
>
<td>
<span class="strong">{{ row.shop }}</span>
<span v-if="row.noShop" class="sub">采集/货源/品牌这类任务不落店铺,按业务筛选查看</span>
</td>
<td>{{ row.runningTasks }}</td>
<td>
<span :class="{ 'is-warn-text': row.stuckTasks > 0 }">{{ row.stuckTasks }}</span>
</td>
<td>
<span class="scope" :title="row.moduleSummary">{{ row.moduleSummary || '—' }}</span>
</td>
<td>{{ row.lastReportAt ? formatDateTime(row.lastReportAt) : '—' }}</td>
</tr>
</tbody>
</table>
</div>
<div v-else class="empty-tip">暂无设备记录</div>
<div v-else class="empty-tip">暂无在跑店铺</div>
</section>
<section class="panel-box">
@@ -355,18 +390,19 @@ onUnmounted(() => {
<option v-for="option in TASK_STATUS_OPTIONS" :key="option.value" :value="option.value">{{ option.label }}</option>
</select>
</div>
<div class="form-group" style="min-width: 190px">
<label>设备</label>
<select v-model="filter.deviceId">
<option value="">全部设备</option>
<option v-for="device in devices" :key="device.deviceId" :value="device.deviceId">
{{ deviceDisplayName(device.deviceName, device.deviceId) }}
</option>
</select>
</div>
<div class="form-group" style="min-width: 160px">
<div class="form-group shop-filter">
<label>店铺</label>
<input v-model="filter.shop" type="text" placeholder="模糊搜索店铺名" @keyup.enter="search" />
<el-select
v-model="filter.shop"
filterable
clearable
placeholder="全部店铺"
style="width: 220px"
@change="search"
>
<el-option v-for="shop in shopFilterOptions" :key="shop" :label="shop" :value="shop" />
</el-select>
<span class="filter-tip">精确匹配店铺名</span>
</div>
<div class="form-group" style="min-width: 190px">
<label>创建时间(起)</label>
@@ -395,6 +431,7 @@ onUnmounted(() => {
<th style="width: 120px">状态</th>
<th style="width: 170px">当前处理</th>
<th style="width: 165px">开始时间</th>
<th style="width: 165px">最近上报</th>
<th style="width: 165px">结束时间</th>
<th style="width: 190px">进度</th>
<th style="width: 90px">操作</th>
@@ -417,6 +454,11 @@ onUnmounted(() => {
<span class="scope" :title="currentScopeOf(row)">{{ currentScopeOf(row) }}</span>
</td>
<td>{{ formatDateTime(row.createdAt) }}</td>
<td>
<span :class="{ 'is-warn-text': row.stuck }">
{{ row.lastReportAt ? formatDateTime(row.lastReportAt) : '—' }}
</span>
</td>
<td>{{ row.finishedAt ? formatDateTime(row.finishedAt) : '—' }}</td>
<td>
<div class="progress-line">
@@ -431,10 +473,10 @@ onUnmounted(() => {
</tr>
</template>
<tr v-else-if="tasksLoading">
<td colspan="9" class="empty-tip">加载中...</td>
<td colspan="10" class="empty-tip">加载中...</td>
</tr>
<tr v-else>
<td colspan="9" class="empty-tip">暂无符合条件的任务</td>
<td colspan="10" class="empty-tip">暂无符合条件的任务</td>
</tr>
</tbody>
</table>
@@ -542,6 +584,7 @@ onUnmounted(() => {
<span v-if="detail.stuck" class="badge warn">疑似卡住</span>
</el-descriptions-item>
<el-descriptions-item label="开始时间">{{ formatDateTime(detail.createdAt) }}</el-descriptions-item>
<el-descriptions-item label="最近上报">{{ detail.lastReportAt ? formatDateTime(detail.lastReportAt) : '—' }}</el-descriptions-item>
<el-descriptions-item label="结束时间">{{ detail.finishedAt ? formatDateTime(detail.finishedAt) : '—' }}</el-descriptions-item>
<el-descriptions-item label="进度">
{{ progressText(detail) }}
@@ -707,63 +750,31 @@ h3 {
color: #8598ab;
font-size: 12.5px;
}
.device-strip {
display: flex;
flex-wrap: wrap;
gap: 10px;
}
.device-card {
display: flex;
flex-direction: column;
gap: 6px;
min-width: 190px;
max-width: 260px;
padding: 10px 14px;
border: 1px solid #dbe6f0;
border-radius: 11px;
background: #ffffff;
color: #24384d;
font-family: inherit;
font-size: 13px;
text-align: left;
.shop-row {
cursor: pointer;
}
.device-card:hover {
border-color: #95b1cb;
.shop-row:hover td {
background: #f2f8fd;
}
.device-card.active {
border-color: #4f78a5;
box-shadow: 0 0 0 2px rgba(79, 120, 165, 0.18);
.shop-row.active td {
background: #eaf2fb;
}
.device-line {
display: flex;
align-items: center;
gap: 7px;
min-width: 0;
.shop-row.is-bucket,
.shop-row.is-bucket:hover td {
cursor: default;
background: #fafcfe;
}
.device-name {
font-weight: 600;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
.is-warn-text {
color: #b3803a;
font-weight: 650;
}
.device-meta {
color: #8598ab;
.shop-filter {
position: relative;
}
.filter-tip {
color: #93a4b5;
font-size: 11.5px;
}
.dot {
flex: none;
width: 8px;
height: 8px;
border-radius: 50%;
}
.dot.is-online {
background: #4f9a58;
}
.dot.is-offline {
background: #c2cdd8;
}
.form-row {
display: flex;
flex-wrap: wrap;
@@ -5,7 +5,7 @@ export interface TaskCenterTaskFilter {
username: string
moduleType: string
status: string
deviceId: string
/** 店铺名精确匹配(后端按 LOWER(TRIM(...)) 比较),候选来自 /shop-options 与面板下钻。 */
shop: string
startTime: string
endTime: string
@@ -19,7 +19,7 @@ export interface TaskCenterVariantFilter {
export type TaskCenterQueryParams = Record<string, string | number>
export function createTaskFilter(): TaskCenterTaskFilter {
return { username: '', moduleType: '', status: '', deviceId: '', shop: '', startTime: '', endTime: '' }
return { username: '', moduleType: '', status: '', shop: '', startTime: '', endTime: '' }
}
export function createVariantFilter(): TaskCenterVariantFilter {
@@ -173,7 +173,6 @@ export function buildTaskQuery(
put('username', text(filter.username))
put('moduleType', text(filter.moduleType))
put('status', text(filter.status))
put('deviceId', text(filter.deviceId))
put('shop', text(filter.shop))
put('startTime', toApiTime(filter.startTime))
put('endTime', toApiTime(filter.endTime))