feat(公司tab): 日志管理列表按 uid 成员集筛,麦象行走 OR 不被筛掉

生产只读取证(2026-10-05 15:1x,主机 A 业务库只读):device_log_file COUNT(*)=1028,
GROUP BY source = client 831 / maixiang 197 ⇒ 客户端占多数 ⇒ 这页留在批次 1、照声明
companyScoped(若麦象占多数,公司 tab 只会筛掉小半边,就该把这页摘出清单)。

22 行 source='client' 且 uid IS NULL 的匿名客户端日志的处置:选了公司后接受它们从
每一个 tab 里消失(条件定成 (source='maixiang' OR uid IN (成员集)),不加 uid IS NULL
那条腿)。理由是那 197 行麦象能进每一个 tab,是因为它是平台自己的采集机(基础设施),
而这 22 行只是「没登录的桌面端」——一家没有归属的行在每一家各冒充一份,既错归属也让
「这家有多少日志」这个数失去意义;tab 只是超管的视图过滤器(这页 9 个端点全在
requireSuperAdmin 之后,无非超管调用方),全量仍可由不带 company_id 的请求拿到
(readScope(operator, null) ⇒ unfiltered ⇒ memberUids=null ⇒ 一条条件都不叠)。
代价与定案写进 DeviceLogServiceTest 的 @DisplayName
「定案:那 22 行 source=client 且 uid IS NULL 的匿名客户端日志——选了公司就接受它们消失」。

接线口径:controller 收 @RequestParam(name = "company_id", required = false) 并在 handler
体内算 dataReadScope.readScope(...).userIdsOr(null) 当实参交给 service(G2 断言 C 认的形状);
条件加在 wrapperBuilder 闭包内部,selectCount 与 selectList 共用同一把尺子;空成员集退化
成 eq(source,'maixiang') 而不是不叠条件;content/download/delete/devices 与三个写端点刻意
不收 company_id,由两支 SourceScan 用例钉住。
This commit is contained in:
2026-10-05 17:20:57 +08:00
parent 66f9178557
commit c772a07fbe
6 changed files with 233 additions and 15 deletions
@@ -64,6 +64,8 @@ export interface DeviceLogQuery {
endDate?: string
page: number
pageSize: number
/** 超管选中的公司 tab;null/undefined=不发这个参数,后端按「不筛」出全量(非超管恒不发)。 */
companyId?: number | null
}
/** 分页查询日志文件列表:GET /api/admin/device-logs/files */
@@ -73,6 +75,9 @@ export async function fetchDeviceLogFiles(params: DeviceLogQuery): Promise<Devic
if (params.uid) query.uid = params.uid
if (params.startDate) query.startDate = params.startDate
if (params.endDate) query.endDate = params.endDate
// 公司值由页面组件(companyTab.requestCompanyId)传进来,本模块不读 Pinia store。
// query 是这里逐字段点名的白名单构造 ⇒ 右半边只许取原始 params。
if (params.companyId != null) query.company_id = params.companyId
const { data } = await http.get('/api/admin/device-logs/files', { params: query })
return unwrap<DeviceLogPage>(data)
}
@@ -2,10 +2,11 @@
/** 日志管理页:桌面客户端 / 麦象采集机上报的日志浏览(仅超管)。
* 支持来源/用户/日期筛选,尾部内容查看(自动滚到底、可向前加载更早内容)、
* 完整下载、删除;「采集配置」可调全量/精选模式(全局默认 + 终端覆盖)。 */
import { computed, nextTick, onMounted, ref } from 'vue'
import { computed, nextTick, onMounted, ref, watch } from 'vue'
import OldPagination from '@/components/OldPagination.vue'
import { ElMessage } from 'element-plus'
import { formatDateTime, todayDateInput } from '@/utils/datetime'
import { useCompanyTabStore } from '@/stores/company-tab'
import { fetchHistoryUserOptions } from './history-api.ts'
import type { HistoryUserOption } from './history-user-option.ts'
import {
@@ -49,6 +50,8 @@ function formatBytes(bytes: number | null | undefined): string {
return `${value >= 100 ? value.toFixed(0) : value.toFixed(1)} ${units[unitIndex]}`
}
const companyTab = useCompanyTabStore()
const loading = ref(false)
const rows = ref<DeviceLogFileRow[]>([])
const total = ref(0)
@@ -74,6 +77,7 @@ async function load() {
endDate: endDate.value || undefined,
page: page.value,
pageSize: pageSize.value,
companyId: companyTab.requestCompanyId,
})
rows.value = result?.items || []
total.value = Number(result?.total || 0)
@@ -85,6 +89,10 @@ async function load() {
}
}
// 切公司 = 重新取数(形状同店铺管理页):只有列表这一个取数口按公司收窄,
// 内容/下载/删除/终端下拉都不带 company_id,所以这里只需重跑 load()。
watch(() => companyTab.activeId, () => void load())
async function loadUserOptions() {
usersLoading.value = true
try {