feat(admin): 批量删除并入筛选行省一整行+公司管理加删除/批量删除(2026-11-23 用户口径)

- BatchDeleteActions margin-left:auto 右对齐、不再独占一行,14 页迁入各自筛选/工具行(Users/Groups/Menus/UserSecrets/QueryAsin/AsinInvalid/SkipPrice/DedupeRegistry/ProductCategory/DeviceLogs/DigitalHuman/ShopManage/ShopKeys/BrandGating);主按钮沿用全局 34px 同高,align-batch-toolbar-inline.test.ts 钉形状防回归
- 公司删除:DELETE /api/admin/companies/{id}(仅超管,名下有账号拒并带数量),只收公司行+columns 菜单树(PermissionMenuService.deleteTreeByCompany 与 copyTreeFromTemplate 对称),业务数据不级联;列表 VO 带 user_count 供前端置灰勾选/删除按钮;批量删除按用户管理同形走前端逐条循环
- CompaniesPage 加勾选列+行删除按钮(ops-cell 补 flex-wrap 过 ops-cell-must-wrap),删除后 refreshCompanyDirectory 同步 tab 条
- 测试:CompanyServiceDeleteTest 6+PermissionMenuServiceDeleteTreeTest 2+CompanyVoTest user_count 契约+CompanyControllerEndpointTest 翻转 exposesNoDeleteEndpoint→点名 DELETE 端点+CompanyReadPathMenuGateTest ensureSuperAdmin 3→4(delete 入册)+company-directory/row-buttons 补例;source-pin 基线重生成(265 文件/1859 例)
- 验证:admin-vue vue-tsc rc=0、node --test 1976 全绿、vitest mount 247 全绿;backend test-compile rc=0、Company*/PermissionMenu*/跨切守卫点名全绿(CatchSilenceRatchet 红因=另一路在飞件 JdPublishFillAiService 3 个 catch,归属京东窗不代抬)
This commit is contained in:
2026-11-23 01:41:37 +08:00
parent 87fe7ed383
commit 898e8a5ea9
35 changed files with 597 additions and 46 deletions
@@ -17,6 +17,12 @@ export interface CompanyItem {
updatedAt: string | null
/** 所属平台(V206):'amazon'|'jd';后端恒带值(列 NOT NULL DEFAULT 'amazon'),旧负载缺省不渲染。 */
platform?: string
/**
* 在册账号数(2026-11-23):仅列表回包带(create/update 不带)。
* 非零 ⇒ 该公司不能删(用户拍板「有账号不能删」),勾选框与删除按钮据此置灰。
* 缺省(旧负载/测试桩)按 0 读——那是"看起来可删",后端删除时仍有权威校验兜底。
*/
userCount?: number
}
/** 新建/改名的表单草稿。 */
@@ -30,6 +30,9 @@ export function toCompanyItem(raw: unknown): CompanyItem | null {
// platform 后端恒带(列 NOT NULL);旧负载/测试桩缺省就不渲染该键,字段形状与 users-model 一致。
const platform = text(r.platform)
if (platform) item.platform = platform
// user_count 仅公司目录列表下发(create/update 不带);非负整数才认,缺省不渲染(按 0 读)。
const userCount = numberOrNull(r.user_count)
if (userCount !== null && userCount >= 0) item.userCount = userCount
return item
}
+6 -1
View File
@@ -16,8 +16,13 @@ export async function createCompany(draft: CompanyDraft): Promise<CompanyItem |
return parseCompany(data)
}
/** 改名 / 启停;后端不做删除,停用即 status=0。 */
/** 改名 / 启停(删除走独立出口 deleteCompany,与用户管理同形)。 */
export async function updateCompany(id: number, draft: CompanyDraft): Promise<CompanyItem | null> {
const { data } = await http.put(`/api/admin/companies/${id}`, toCompanyPayload(draft))
return parseCompany(data)
}
/** 删除公司:DELETE /api/admin/companies/{id},success=false 由 unwrap 抛后端 message。 */
export async function deleteCompany(id: number): Promise<void> {
await http.delete<unknown>(`/api/admin/companies/${id}`)
}
@@ -28,7 +28,9 @@ defineProps<{
</template>
<style scoped>
.batch-delete-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
/* 2026-11-23 用户口径「批量删除放上去,最大化利用空间」:不再独占一行,由各页放进筛选/工具行,
margin-left:auto 在 flex 行内右对齐(落点=查询按钮右侧留白)。 */
.batch-delete-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-left: auto; }
.batch-delete-actions button {
min-height: 34px;
padding: 5px 12px;
@@ -39,6 +41,7 @@ defineProps<{
font: inherit;
cursor: pointer;
}
/* 主按钮沿用 34px:全局 main.css 已把 panel 内 .btn(查询)压到 34px,同高才不会一高一矮。 */
.batch-delete-actions .batch-delete-button { color: #fff; background: #b35f6a; border-color: #b35f6a; }
.batch-delete-button:hover:not(:disabled) { background: #a34f5b; }
.batch-clear-button:hover:not(:disabled) { background: #edf5fb; }
@@ -1,15 +1,20 @@
<script setup lang="ts">
/** 公司管理(设计文档 §2.3):列表 + 新建 + 改名/启停。
/** 公司管理(设计文档 §2.3):列表 + 新建 + 改名/启停 + 删除/批量删除(2026-11-23,名下有账号不能删)。
* 可见范围由后端收窄(超管全部、公司内 admin 只自己公司);写操作仅超管,这里隐藏入口只是配合,
* 真正的把关在 CompanyController,页面不得当作权限边界。 */
import { computed, onMounted, ref, watch } from 'vue'
import { ElMessage } from 'element-plus'
import { formatDateTime } from '@/utils/datetime'
import { fetchCompanies } from '@/api/companies'
import { useRowSelection } from '@/utils/use-row-selection'
import { deleteCompany, fetchCompanies } from '@/api/companies'
import { COMPANY_STATUS_ACTIVE, type CompanyItem } from '@/api/companies-dto'
import { useAdminSessionStore } from '@/stores/admin-session'
import { refreshCompanyDirectory } from '@/stores/company-tab'
import { usePlatformTabStore } from '@/stores/platform-tab'
import BatchDeleteActions from '@/components/BatchDeleteActions.vue'
import BatchDeleteCheckbox from '@/components/BatchDeleteCheckbox.vue'
import { openAdminConfirm } from '@/components/admin-confirm'
import OldPagination from '@/components/OldPagination.vue'
import CompanyEditorDialog from './CompanyEditorDialog.vue'
import { showAdminFeedback } from '@/components/admin-feedback-ui'
@@ -61,16 +66,58 @@ function openEdit(company: CompanyItem) {
editorVisible.value = true
}
/** 删除前置闸(勾选框置灰与删除按钮共用同一份理由;后端删除时还有权威校验兜底)。 */
function deleteBlockReasonOf(company: CompanyItem): string | undefined {
if (!canManage.value) return '只有超级管理员可以删除公司'
const userCount = company.userCount ?? 0
if (userCount > 0) return `该公司名下还有 ${userCount} 个账号,请先删除或转移后再删除公司`
return undefined
}
async function reloadCompaniesAndDirectory() {
await loadCompanies()
refreshCompanyDirectory().catch((error: unknown) => {
console.warn('[company-tab] 公司变动后目录重拉失败', error)
})
}
const batch = useRowSelection({
pageRows: () => pagedRows.value,
rowId: (row) => row.id,
rowLabel: (row) => row.companyName || `公司 ${row.id}`,
deleteOne: (id) => deleteCompany(id),
refresh: reloadCompaniesAndDirectory,
blocked: () => loading.value || !!loadFailure.value,
scope: () => [platformTab.active],
precheck: (row) => deleteBlockReasonOf(row),
})
async function removeCompany(company: CompanyItem) {
if (batch.busy) return
const reason = deleteBlockReasonOf(company)
if (reason) {
showAdminFeedback(reason, 'error')
return
}
// 对齐分组管理:统一确认出口,删除不做级联(账号与业务数据留在各自页面处理)。
if (!(await openAdminConfirm({ message: `确定删除公司“${company.companyName || company.id}”吗?删除后不可恢复。`, danger: true }))) return
try {
await deleteCompany(company.id)
batch.removeFromSelection(company.id)
ElMessage.success('删除成功')
await reloadCompaniesAndDirectory()
} catch (error) {
showAdminFeedback(error instanceof Error ? error.message : '删除失败', 'error')
}
}
// 保存成功后:本页列表照常重拉,共享公司目录(tab 条)强制重拉一份。
// 本页不参与公司隔离(控制方 2026-10-06「公司管理不要有 tab」)⇒ 走 store 的具名出口
// refreshCompanyDirectory,而不是自己持一份 company-tab store(后者形状与「给这页上了 tab」
// 分不开,company-config-entry-super-only 的 pageFiles 分母会当场红)。
// 重拉失败不弹新提示(§12 第 5 条未批的界面暴露):tab 条保留旧名单,下一次切平台 tab / 重进页面会再试。
async function onCompaniesSaved() {
await loadCompanies()
refreshCompanyDirectory().catch((error: unknown) => {
console.warn('[company-tab] 公司保存后目录重拉失败', error)
})
await reloadCompaniesAndDirectory()
}
// 切平台 tab(V206)= 重新取数:公司归属按平台分列,两 tab 各看各的公司。
@@ -95,6 +142,7 @@ onMounted(loadCompanies)
<label>公司名称</label>
<input v-model="filterKeyword" type="text" placeholder="输入公司名称" />
</div>
<BatchDeleteActions :batch="batch" />
</div>
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="loadCompanies" />
@@ -102,18 +150,26 @@ onMounted(loadCompanies)
<table>
<thead>
<tr>
<th class="batch-delete-cell" scope="col">
<BatchDeleteCheckbox label="全选当前页可删除公司" :checked="batch.pageAll" :partial="batch.pageSome"
:disabled="batch.disabled || batch.pageEmpty" @change="batch.togglePage" />
</th>
<th style="width: 58px">序号</th>
<th>公司名称</th>
<th style="width: 90px">状态</th>
<th style="width: 24%">备注</th>
<th style="width: 160px">创建时间</th>
<th style="width: 160px">修改时间</th>
<th style="width: 90px">操作</th>
<th style="width: 140px">操作</th>
</tr>
</thead>
<tbody>
<template v-if="filteredRows.length">
<tr v-for="(company, index) in pagedRows" :key="company.id">
<tr v-for="(company, index) in pagedRows" :key="company.id" :class="{ 'batch-selected': batch.isSelected(company) }">
<td class="batch-delete-cell">
<BatchDeleteCheckbox :label="batch.reason(company) || `选择 ${batch.label(company)}`" :checked="batch.isSelected(company)"
:disabled="batch.disabled || !!batch.reason(company)" @change="batch.toggle(company)" />
</td>
<td>{{ index + 1 }}</td>
<td>{{ company.companyName || '-' }}</td>
<td>
@@ -125,16 +181,20 @@ onMounted(loadCompanies)
<td>{{ formatDateTime(company.createdAt) }}</td>
<td>{{ formatDateTime(company.updatedAt || company.createdAt) }}</td>
<td class="ops-cell">
<button v-if="canManage" class="btn btn-sm" type="button" @click="openEdit(company)">编辑</button>
<template v-if="canManage">
<button class="btn btn-sm" type="button" @click="openEdit(company)">编辑</button>
<button class="btn btn-sm btn-danger" type="button" :disabled="batch.busy || !!deleteBlockReasonOf(company)"
:title="deleteBlockReasonOf(company) || undefined" @click="removeCompany(company)">删除</button>
</template>
<span v-else class="cell-none">-</span>
</td>
</tr>
</template>
<tr v-else-if="loading">
<td colspan="7" class="empty-tip">加载中...</td>
<td colspan="8" class="empty-tip">加载中...</td>
</tr>
<tr v-else>
<td colspan="7" class="empty-tip">{{ filterKeyword.trim() ? '暂无匹配公司' : '暂无公司' }}</td>
<td colspan="8" class="empty-tip">{{ filterKeyword.trim() ? '暂无匹配公司' : '暂无公司' }}</td>
</tr>
</tbody>
</table>
@@ -283,6 +343,7 @@ h3 {
align-items: center;
gap: 8px;
white-space: nowrap;
flex-wrap: wrap;
}
.cell-none {
color: #8293a5;
@@ -139,10 +139,10 @@ onMounted(loadGroups)
<label>组长</label>
<input v-model="filterLeader" type="text" placeholder="输入组长用户名" />
</div>
<BatchDeleteActions :batch="batch" />
</div>
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="loadGroups" />
<BatchDeleteActions :batch="batch" />
<div class="table-scroll">
<table>
<thead>
@@ -283,10 +283,10 @@ onMounted(loadMenus)
<el-option label="软件" value="app" />
</el-select>
</div>
<BatchDeleteActions :batch="batch" />
</div>
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="loadMenus" />
<BatchDeleteActions :batch="batch" />
<div class="table-scroll columns-table-scroll">
<table>
<thead>
@@ -393,10 +393,10 @@ onMounted(load)
</button>
</div>
</div>
<BatchDeleteActions :batch="batch" />
</div>
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="load" />
<BatchDeleteActions :batch="batch" />
<div class="secrets-table-scroll">
<table>
<thead>
@@ -257,6 +257,8 @@ onMounted(() => {
</el-select>
</div>
<button class="btn" type="button" @click="search">查询</button>
<!-- 批量删除并入筛选行(2026-11-23 用户口径),margin-left:auto 右对齐,不再独占一行。 -->
<BatchDeleteActions :batch="batch" />
</div>
<div v-if="statePhase === 'error' && loadError" class="msg err">
@@ -264,7 +266,6 @@ onMounted(() => {
<button class="btn btn-sm btn-secondary" type="button" @click="retry">重试</button>
</div>
<BatchDeleteActions :batch="batch" />
<div class="table-scroll user-table-scroll">
<table>
<thead>
@@ -186,10 +186,10 @@ onMounted(() => {
</el-select>
</div>
<button class="btn" type="button" @click="apply">查询</button>
<BatchDeleteActions :batch="batch" />
</div>
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="load" />
<BatchDeleteActions :batch="batch" />
<div class="table-scroll invalid-asin-table-scroll">
<table>
<thead>
@@ -410,6 +410,7 @@ onUnmounted(() => {
<div class="dedupe-filter-actions">
<button class="btn" type="button" @click="apply">查询</button>
</div>
<BatchDeleteActions :batch="batch" />
</div>
<div class="dedupe-filter-date-row">
@@ -429,7 +430,6 @@ onUnmounted(() => {
</div>
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="load" />
<BatchDeleteActions :batch="batch" />
<div class="table-scroll dedupe-table-scroll">
<table>
<thead>
@@ -343,11 +343,11 @@ onMounted(loadTree)
<button class="btn btn-sm btn-secondary" type="button" @click="exportCategories">导出</button>
<button v-if="selected && !searching" class="btn btn-sm" type="button" @click="openCreate(selected)">新增子类目</button>
<button class="btn" type="button" @click="openCreate(null)">新增类目</button>
<BatchDeleteActions :batch="batch" />
</div>
</div>
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="loadTree" />
<BatchDeleteActions :batch="batch" />
<div class="table-scroll category-table-scroll">
<table>
<thead>
@@ -435,10 +435,10 @@ onMounted(() => {
</div>
<button class="btn" type="button" @click="apply">查询</button>
<button class="btn btn-secondary" type="button" @click="doExport">导出 XLSX</button>
<BatchDeleteActions :batch="batch" />
</div>
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="load" />
<BatchDeleteActions :batch="batch" />
<div class="table-scroll query-asin-table-scroll">
<table>
<thead>
@@ -477,10 +477,10 @@ onMounted(() => {
</div>
<button class="btn" type="button" @click="apply">查询</button>
<button class="btn btn-secondary" type="button" @click="doExport">导出 XLSX</button>
<BatchDeleteActions :batch="batch" />
</div>
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="load" />
<BatchDeleteActions :batch="batch" />
<div class="table-scroll skip-price-asin-table-scroll">
<table>
<thead>
@@ -352,10 +352,10 @@ onMounted(() => {
<button class="btn btn-ghost" type="button" @click="reset">重置</button>
</div>
</div>
<BatchDeleteActions :batch="batch" />
</div>
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="load" />
<BatchDeleteActions :batch="batch" />
<div class="logs-table-scroll">
<table>
<thead>
@@ -232,11 +232,11 @@ onMounted(load)
<div class="dh-head-tools admin-header-controls">
<input v-model="versionKeyword" type="text" placeholder="搜索版本号" class="dh-keyword" />
<button class="btn" type="button" @click="uploadVisible = true">上传新版本</button>
<BatchDeleteActions :batch="batch" />
</div>
</div>
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="load" />
<BatchDeleteActions :batch="batch" />
<div class="table-scroll digital-human-version-table-scroll">
<table>
<thead>
@@ -244,10 +244,10 @@ onMounted(load)
</el-select>
</div>
<button class="btn" type="button" @click="apply">查询</button>
<BatchDeleteActions :batch="batch" />
</div>
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="load" />
<BatchDeleteActions :batch="batch" />
<div class="shop-key-table-scroll">
<table>
<thead>
@@ -267,10 +267,10 @@ onMounted(() => {
<input v-model="filter.shopName" type="text" placeholder="请输入店铺名" @keyup.enter="apply" />
</div>
<button class="btn" type="button" @click="apply">查询</button>
<BatchDeleteActions :batch="batch" />
</div>
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="load" />
<BatchDeleteActions :batch="batch" />
<div class="table-scroll shop-manage-table-scroll">
<table>
<thead>
@@ -339,11 +339,11 @@ onMounted(() => {
</el-select>
<button class="g-btn g-btn-primary" type="button" @click="query">查询</button>
<button class="g-btn g-btn-ghost" type="button" @click="resetFilter">重置</button>
<BatchDeleteActions :batch="batch" />
</div>
<LoadFailureBar v-if="loadError" :message="loadError" @retry="loadPage()" />
<BatchDeleteActions :batch="batch" />
<div class="g-table-wrap" v-loading="pageLoading">
<table v-if="rows.length" class="g-table">
<thead>
@@ -32,3 +32,14 @@ test('align_menus_row_buttons_old_btn', () => {
assert.doesNotMatch(s, /el-button[^>]*@click="openEdit/, '行内不再用 EP 按钮')
assert.match(s, /openAdminConfirm\(\{ message: `确定删除菜单/, '删除确认走统一确认出口,文案对齐旧版')
})
test('align_companies_row_buttons_old_btn', () => {
const s = readSource('src/pages/account/CompaniesPage.vue')
assert.match(s, /class="btn btn-sm"[^>]*@click="openEdit\(company\)"/, '编辑用旧版 btn-sm 实心小按钮')
assert.match(s, /class="btn btn-sm btn-danger"[^>]*@click="removeCompany\(company\)"/, '删除用旧版 btn-sm btn-danger(2026-11-23 用户口径:公司管理加删除)')
assert.doesNotMatch(s, /el-button[^>]*@click="openEdit/, '行内不再用 EP 按钮')
assert.match(s, /openAdminConfirm\(\{ message: `确定删除公司/, '删除确认走统一确认出口')
// 名下有账号的公司删不得:勾选框与删除按钮共用同一份理由(deleteBlockReasonOf)
assert.match(s, /deleteBlockReasonOf\(company\)/, '删除按钮按理由置灰,悬停可见原因')
assert.match(s, /该公司名下还有 \$\{userCount\} 个账号/, '置灰文案带账号数')
})
@@ -0,0 +1,38 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import { readSource } from './helpers.ts'
/**
* 2026-11-23 用户口径「批量删除放上去,最大化利用空间」:BatchDeleteActions 不再独占一行,
* 由各页并入筛选/工具行(组件 margin-left:auto 右对齐)。本钉防回归——有人把它挪回
* 「LoadFailureBar 之后独占一行」的旧形状即红。
*
* 正向锚点 = 该页筛选行里紧挨着它的前一个控件;负向 = 旧形状「LoadFailureBar 后跟独立批量行」。
*/
const MOVED_PAGES: Array<{ file: string; rowMate: RegExp; note: string }> = [
{ file: 'src/pages/account/UsersPage.vue', rowMate: /@click="search">查询<\/button>[\s\S]{0,300}?<BatchDeleteActions/, note: '查询按钮右侧' },
{ file: 'src/pages/account/GroupsPage.vue', rowMate: /placeholder="输入组长用户名" \/>\s*<\/div>\s*<BatchDeleteActions/, note: '组长输入框右侧' },
{ file: 'src/pages/account/MenusPage.vue', rowMate: /value="app" \/>\s*<\/el-select>\s*<\/div>\s*<BatchDeleteActions/, note: '菜单类型下拉右侧' },
{ file: 'src/pages/account/UserSecretsPage.vue', rowMate: /<\/button>\s*<\/div>\s*<\/div>\s*<BatchDeleteActions/, note: '刷新余额那组按钮右侧' },
{ file: 'src/pages/asin/QueryAsinPage.vue', rowMate: /导出 XLSX<\/button>\s*<BatchDeleteActions/, note: '导出按钮右侧' },
{ file: 'src/pages/asin/AsinInvalidPage.vue', rowMate: /@click="apply">查询<\/button>\s*<BatchDeleteActions/, note: '查询按钮右侧' },
{ file: 'src/pages/asin/SkipPricePage.vue', rowMate: /导出 XLSX<\/button>\s*<BatchDeleteActions/, note: '导出按钮右侧' },
{ file: 'src/pages/asin/DedupeRegistryPage.vue', rowMate: /@click="apply">查询<\/button>\s*<\/div>\s*<BatchDeleteActions/, note: '查询按钮组右侧' },
{ file: 'src/pages/asin/ProductCategoryPage.vue', rowMate: /@click="openCreate\(null\)">新增类目<\/button>\s*<BatchDeleteActions/, note: '新增类目按钮右侧' },
{ file: 'src/pages/records/DeviceLogsPage.vue', rowMate: /<\/button>\s*<\/div>\s*<\/div>\s*<BatchDeleteActions/, note: '重置按钮组右侧' },
{ file: 'src/pages/records/RecordsDigitalHumanVersionPage.vue', rowMate: /@click="uploadVisible = true">上传新版本<\/button>\s*<BatchDeleteActions/, note: '上传按钮右侧' },
{ file: 'src/pages/shop/ShopManagePage.vue', rowMate: /@click="apply">查询<\/button>\s*<BatchDeleteActions/, note: '查询按钮右侧' },
{ file: 'src/pages/shop/ShopKeysPage.vue', rowMate: /@click="apply">查询<\/button>\s*<BatchDeleteActions/, note: '查询按钮右侧' },
{ file: 'src/pages/tasks/BrandGatingPanel.vue', rowMate: /@click="resetFilter">重置<\/button>\s*<BatchDeleteActions/, note: '重置按钮右侧' },
]
for (const { file, rowMate, note } of MOVED_PAGES) {
test(`align_batch_inline_${file.split('/').pop()}`, () => {
const s = readSource(file)
assert.doesNotMatch(s, /<LoadFailureBar[^>]*\/>\s*<BatchDeleteActions/, `旧形状(LoadFailureBar 后独占一行)不许回来`)
assert.match(s, rowMate, `批量删除应并入筛选/工具行(${note}),紧跟行内前一个控件`)
// 行内形状收口:组件是该行容器的最后一个孩子,紧跟该行的闭合 </div>
assert.match(s, /<BatchDeleteActions :batch="batch" \/>\s*\n\s*<\/div>/, '组件应紧跟行容器闭合,而不是自己占一行再接表格')
assert.equal((s.match(/<BatchDeleteActions/g) || []).length, 1, '每页只许一份批量删除入口')
})
}
@@ -1,10 +1,10 @@
{
"note": "readSource 钉子逐文件基线。两把尺子:pins=落在用例体内的读盘,reads=全文读点总数(含模块级夹具与 helper)。都只许减;pins 下降而 reads 没同步下降=把读盘挪出体内,不算改进。由 tests/source-pin-ratchet.test.ts 生成。",
"totals": {
"files": 264,
"cases": 1857,
"pins": 462,
"reads": 663
"files": 265,
"cases": 1859,
"pins": 463,
"reads": 664
},
"files": {
"admin-scaffold.test.ts": {
@@ -22,6 +22,11 @@
"pins": 7,
"reads": 7
},
"align-batch-toolbar-inline.test.ts": {
"cases": 1,
"pins": 1,
"reads": 1
},
"align-category-tree.test.ts": {
"cases": 6,
"pins": 5,
@@ -208,7 +213,7 @@
"reads": 3
},
"company-directory.test.ts": {
"cases": 8,
"cases": 9,
"pins": 0,
"reads": 0
},
@@ -55,6 +55,24 @@ test('parseCompany 解析单条(新建/改名回包)', () => {
assert.equal(parseCompany({ success: true, data: { company_name: '无 id' } }), null)
})
test('user_count 仅列表解析进 userCount:非零即「名下有账号、删不得」(2026-11-23)', () => {
const rows = parseCompanyList({ success: true, data: [
{ id: 1, company_name: '厦门米椿花', status: 1, user_count: 3 },
{ id: 2, company_name: '福州数富', status: 1, user_count: 0 },
{ id: 3, company_name: '旧负载', status: 1 },
{ id: 4, company_name: '脏值', status: 1, user_count: -1 },
{ id: 5, company_name: '脏值2', status: 1, user_count: 'x' },
] })
assert.equal(rows[0].userCount, 3)
assert.equal(rows[1].userCount, 0, '零账号=可删,字段照带')
assert.ok(!('userCount' in rows[2]), '旧负载不带该键(按 0 读是消费方的事)')
assert.ok(!('userCount' in rows[3]), '负数不是合法计数,丢弃')
assert.ok(!('userCount' in rows[4]), '非数字丢弃')
// 新建/改名回包不带 user_count:单条解析同样不凭空造键
const saved = parseCompany({ success: true, data: { id: 6, company_name: '厦门米椿花', status: 1 } })
assert.ok(saved && !('userCount' in saved))
})
test('公司名必填、去空格后不得为空,且不超过列宽', () => {
assert.equal(validateCompanyDraft({ companyName: ' ' }), '公司名称不能为空')
assert.equal(validateCompanyDraft({ companyName: ' 厦门米椿花 ' }), '')