feat(店铺密钥): 筛选改走服务端、新增认当前 tab,操作列不再裁掉删除

三家公司的密钥挤在一页上,而"筛选"是拿当前页那 10 行在前端筛的:total 不动,
第 2 家的令牌要翻到它所在页才筛得出来。操作列给 160px 装不下三颗按钮,
最后一颗(删除)被 td 的 overflow:hidden + table-layout:fixed 整颗裁掉——
DOM 里在、事件也在,就是看不见点不到,这就是"没有删除功能"的真相。

- GET /api/admin/shop-keys 新增 keyword / token / whitelist_status,在公司读范围之内
  由服务端筛。keyword 那组 OR 必须括起来:不括就被后续 AND 短路成
  「备注名命中 OR (账号命中 AND 本公司)」,第 2 家的 tab 能读到第 1 家的令牌。
- create 的归属改为过读门(认当前 tab),不再只认操作者会话那一家。
  读认 tab、写认会话=两把尺子:admin 是 super_admin 且 company_id=1,
  他在别家 tab 点新增会"提示已新增、行却落进米椿花名下",再点一次就撞令牌唯一键。
  这一条推翻 10-06 定案,controller 的反向钉子(create 不许碰读门)同步换成
  「tab 必须过门 + 不许把请求原值直传下去」。
- 操作列 160→270px,.ops-cell 补 flex-wrap: wrap,把"超宽=静默消失"退化成"多占一行";
  同族结构隐患一次扫过 8 个页面(宽度够不够是像素账,会不会消失是结构账)。
- 护栏:ops-cell-must-wrap 钉跨页结构,shop-key-filter-params 钉参数下发与列宽;
  source-pin 棘轮补第二把尺子 reads=全文读点(体内+体外),
  pins 降而 reads 不同步降=把 readSource 挪出用例体冒充改进,当场红。

验证:将要提交的树(HEAD + 本批白名单)在独立 worktree 实跑——前端 1762 例 0 红、
vue-tsc rc=0、Java 41 例 0 红且 959 主源 + 498 测试源全量编译过(证明不依赖并行会话
未提交的符号);主树全量 1766 例 0 红。变异自证三支全杀:摘掉一页的 flex-wrap ⇒ 恰好
1 红点名该页;把体内读盘挪进 helper ⇒ 棘轮 1 红且文案点名"不算改进";
归属退回按会话、controller 绕门直传原值 ⇒ 各自红。
This commit is contained in:
2026-10-08 18:39:19 +08:00
parent f142744ed4
commit 6d835e947e
22 changed files with 1139 additions and 324 deletions
@@ -355,6 +355,7 @@ h3 {
align-items: center;
gap: 8px;
white-space: nowrap;
flex-wrap: wrap;
}
.empty-tip {
@@ -538,6 +538,7 @@ tr.is-column-dragging td {
align-items: center;
gap: 8px;
white-space: nowrap;
flex-wrap: wrap;
}
.empty-tip {
@@ -449,6 +449,7 @@ h3 {
align-items: center;
gap: 8px;
white-space: nowrap;
flex-wrap: wrap;
}
.expiry-cell-expired {
color: #c0392b;
@@ -408,6 +408,7 @@ h3 {
align-items: center;
gap: 8px;
white-space: nowrap;
flex-wrap: wrap;
}
.empty-tip {
@@ -700,6 +700,7 @@ h3 {
gap: 8px;
white-space: nowrap;
text-align: right;
flex-wrap: wrap;
}
.empty-tip {
@@ -710,6 +710,7 @@ h3 {
align-items: center;
gap: 8px;
white-space: nowrap;
flex-wrap: wrap;
}
.load-more-row td {
@@ -488,6 +488,7 @@ h3 {
align-items: center;
gap: 8px;
white-space: nowrap;
flex-wrap: wrap;
}
.empty-tip {
@@ -7,8 +7,8 @@ import { ElMessage } from 'element-plus'
import { useCompanyTabStore } from '@/stores/company-tab'
import { fetchShopKeyList, submitCreateShopKey, updateShopKey, deleteShopKey, checkShopKeyWhitelist } from './shop-key-api.ts'
import { emptyShopKeyForm, normalizeZiniaoToken, validateProxyUrl } from './shop-key-form-model.ts'
import type { ShopKeyItem } from './shop-dto.ts'
import { whitelistStatusMeta } from './shop-key-model.ts'
import type { IpWhitelistStatus, ShopKeyItem } from './shop-dto.ts'
import { whitelistStatusMeta, whitelistStatusOptions } from './shop-key-model.ts'
import OldPagination from '@/components/OldPagination.vue'
const companyTab = useCompanyTabStore()
@@ -19,15 +19,13 @@ const page = ref(1)
const pageSize = ref(10)
const jumpPage = ref('')
const totalPages = computed(() => Math.max(1, Math.ceil(total.value / pageSize.value)))
/** 筛选:备注名/紫鸟账号(用户要求店铺密钥列表补筛选)。 */
const filterKeyword = ref('')
const filteredRows = computed(() => {
const kw = (filterKeyword.value || '').trim().toLowerCase()
if (!kw) return rows.value
return rows.value.filter((r) =>
`${r.remarkName || ''} ${r.ziniaoAccountName || ''}`.toLowerCase().includes(kw),
)
})
/** 筛选:三个条件全部交后端做。曾经的"备注名/紫鸟账号"是前端 computed,只在**当前这一页的
* 10 行**里过滤且 total 纹丝不动 —— 第 11 行起就筛不掉,翻页后结果还会自己变回去。 */
const filter = reactive({ keyword: '', token: '', whitelistStatus: null as IpWhitelistStatus | null })
const statusOptions = whitelistStatusOptions()
const anyFilterActive = computed(
() => Boolean(filter.keyword.trim() || filter.token.trim() || filter.whitelistStatus),
)
const dialogVisible = ref(false)
const editingId = ref<number | null>(null)
@@ -61,6 +59,9 @@ async function load() {
const result = await fetchShopKeyList({
page: page.value,
pageSize: pageSize.value,
keyword: filter.keyword.trim() || undefined,
token: filter.token.trim() || undefined,
whitelistStatus: filter.whitelistStatus || undefined,
companyId: companyTab.requestCompanyId,
})
rows.value = result.items
@@ -130,7 +131,7 @@ async function submit() {
saving.value = true
try {
if (creating) {
await submitCreateShopKey({ ...form })
await submitCreateShopKey({ ...form }, companyTab.requestCompanyId)
} else {
await updateShopKey(editingId.value as number, { ...form })
}
@@ -178,7 +179,16 @@ function goJump() {
changePage(Math.min(Math.max(n, 1), totalPages.value))
}
watch(() => companyTab.activeId, () => { filterKeyword.value = ''; page.value = 1; void load() })
function apply() {
page.value = 1
void load()
}
// 切公司 = 清掉全部筛选 + 回第 1 页 + 重取数,与其余 9 页同一条约定
// (护栏 company-tab-wiring 的 WATCH_BODY_PINS 逐字钉着这一行)。
// 筛选改到服务端做之后这条更要守:留着上一家填的词去筛新一家,首屏就是一张
// 「暂无匹配密钥」而框里还显示着那个词——tab 看着像坏了,请求/后端/权限三处都没错。
watch(() => companyTab.activeId, () => { filter.keyword = ''; filter.token = ''; filter.whitelistStatus = null; page.value = 1; void load() })
onMounted(load)
</script>
@@ -194,8 +204,19 @@ onMounted(load)
<div class="form-row keys-filter-row">
<div class="form-group" style="min-width: 220px">
<label>备注名 / 紫鸟账号</label>
<input v-model="filterKeyword" type="text" placeholder="模糊搜索备注名或紫鸟账号" />
<input v-model="filter.keyword" type="text" placeholder="模糊搜索备注名或紫鸟账号" @keyup.enter="apply" />
</div>
<div class="form-group" style="min-width: 220px">
<label>紫鸟令牌</label>
<input v-model="filter.token" type="text" placeholder="粘贴令牌或其片段定位这一把" @keyup.enter="apply" />
</div>
<div class="form-group" style="min-width: 160px">
<label>白名单状态</label>
<el-select v-model="filter.whitelistStatus" class="admin-filter" clearable placeholder="全部状态">
<el-option v-for="option in statusOptions" :key="option.value" :label="option.label" :value="option.value" />
</el-select>
</div>
<button class="btn" type="button" @click="apply">查询</button>
</div>
<div class="shop-key-table-scroll">
@@ -210,12 +231,12 @@ onMounted(load)
<th style="width: 150px">白名单状态 <span class="table-help" aria-hidden="true">?</span></th>
<th style="width: 170px">创建时间</th>
<th style="width: 170px">修改时间</th>
<th style="width: 160px">操作</th>
<th style="width: 270px">操作</th>
</tr>
</thead>
<tbody>
<template v-if="filteredRows.length">
<tr v-for="(row, index) in filteredRows" :key="row.id">
<template v-if="rows.length">
<tr v-for="(row, index) in rows" :key="row.id">
<td>{{ (page - 1) * pageSize + index + 1 }}</td>
<td>{{ row.remarkName || '—' }}</td>
<td>{{ row.ziniaoAccountName }}</td>
@@ -258,7 +279,7 @@ onMounted(load)
<td colspan="9" class="empty-tip">加载中...</td>
</tr>
<tr v-else>
<td colspan="9" class="empty-tip">{{ filterKeyword ? '暂无匹配密钥' : '暂无店铺密钥' }}</td>
<td colspan="9" class="empty-tip">{{ anyFilterActive ? '暂无匹配密钥' : '暂无店铺密钥' }}</td>
</tr>
</tbody>
</table>
@@ -516,6 +537,10 @@ h3 {
align-items: center;
gap: 8px;
white-space: nowrap;
/* 兜底:单元格是 overflow:hidden + table-layout:fixed,按钮总宽一旦超过列宽,
最后一颗会整颗被裁掉(看不见也点不到,2026-10-08 的"删除按钮没了"就是这么来的)。
允许换行等于把"静默消失"换成"多占一行"。 */
flex-wrap: wrap;
}
.empty-tip {
@@ -520,6 +520,7 @@ h3 {
align-items: center;
gap: 8px;
white-space: nowrap;
flex-wrap: wrap;
}
.empty-tip {
+34 -5
View File
@@ -12,8 +12,10 @@ export function toSensitiveString(value: string): SensitiveString {
return value as SensitiveString
}
/** 紫鸟 IP 白名单状态。 */
/** 紫鸟 IP 白名单状态。取值清单住在这里(DTO 层),model 的归一与筛选下拉共用同一份,
* 否则"下拉里有的、后端说非法"和"药丸渲染出的态、筛不出来"会各错一次。 */
export type IpWhitelistStatus = 'UNKNOWN' | 'ALLOWED' | 'BLOCKED'
export const IP_WHITELIST_VALUES: readonly IpWhitelistStatus[] = ['UNKNOWN', 'ALLOWED', 'BLOCKED']
/** 店铺密钥行(GET /api/admin/shop-keys data.items;Java ShopKeyItemVo)。 */
export interface ShopKeyItem {
@@ -81,10 +83,16 @@ export interface ShopGroupOption {
leaderUsername?: string
}
/** 店铺密钥列表分页参数(分页 + 公司 tab;归一是白名单构造,不点名 companyId)。 */
/** 店铺密钥列表分页参数(分页 + 三个筛选 + 公司 tab;归一是白名单构造,不点名 companyId)。 */
export interface ShopKeyListParams {
page: number
pageSize: number
/** 备注名 / 紫鸟账号 模糊词。 */
keyword?: string
/** 紫鸟令牌 模糊词。 */
token?: string
/** 白名单状态等值筛;空 = 不筛。 */
whitelistStatus?: IpWhitelistStatus | null
/** 公司 tab 的值;normalizeKeyListParams 不点名它,只有 api 层能从原始 params 读到。 */
companyId?: number | null
}
@@ -102,6 +110,10 @@ export interface ShopManageListParams {
export interface ShopKeyPageQuery {
page: number
pageSize: number
/** 下划线形:与后端 @RequestParam(name = "keyword"/"token"/"whitelist_status") 逐字对齐。 */
keyword?: string
token?: string
whitelist_status?: string
/** 下划线形:与后端 @RequestParam(name = "company_id") 逐字对齐。 */
company_id?: number
}
@@ -128,6 +140,14 @@ function trimOrUndefined(value: unknown): string | undefined {
return typeof value === 'string' && value.trim() ? value.trim() : undefined
}
/** 白名单状态归一:大小写/空白容忍,不在清单里的一律当"不筛"(下拉只可能给清单内的值)。 */
function statusOrUndefined(value: unknown): IpWhitelistStatus | undefined {
const textValue = typeof value === 'string' ? value.trim().toUpperCase() : ''
return IP_WHITELIST_VALUES.includes(textValue as IpWhitelistStatus)
? (textValue as IpWhitelistStatus)
: undefined
}
/** 归一化分页:页码下限 1、页大小钳制在 1..100(与 Java 服务端一致)。 */
function normalizePageCore(raw: { page?: unknown; pageSize?: unknown }): { page: number; pageSize: number } {
const page = Math.max(finiteInt(raw.page) ?? SHOP_PAGE_MIN_PAGE, SHOP_PAGE_MIN_PAGE)
@@ -139,9 +159,14 @@ function normalizePageCore(raw: { page?: unknown; pageSize?: unknown }): { page:
return { page, pageSize }
}
/** 店铺密钥列表分页归一。 */
/** 店铺密钥列表分页/筛选归一:空白筛选词与非法状态都归成"不筛",与 toKeyPageQuery 只下发非空一致。 */
export function normalizeKeyListParams(raw: Partial<ShopKeyListParams>): ShopKeyListParams {
return normalizePageCore(raw)
return {
...normalizePageCore(raw),
keyword: trimOrUndefined(raw.keyword),
token: trimOrUndefined(raw.token),
whitelistStatus: statusOrUndefined(raw.whitelistStatus),
}
}
/** 店铺列表分页/筛选归一:负/缺分组 id 视为无筛选,空白店铺名视为无过滤。 */
@@ -154,7 +179,11 @@ export function normalizeShopListParams(raw: Partial<ShopManageListParams>): Sho
}
export function toKeyPageQuery(params: ShopKeyListParams): ShopKeyPageQuery {
return { page: params.page, pageSize: params.pageSize }
const query: ShopKeyPageQuery = { page: params.page, pageSize: params.pageSize }
if (params.keyword) query.keyword = params.keyword
if (params.token) query.token = params.token
if (params.whitelistStatus) query.whitelist_status = params.whitelistStatus
return query
}
/** 前端状态 → Java 查询参数(camelCase);仅下发非空可选字段。 */
@@ -27,13 +27,23 @@ export async function fetchShopKeyList(params: Partial<ShopKeyListParams> = {}):
return parseShopKeyPage(data)
}
/** 提交新增店铺密钥:先校验(失败抛首条错误不发请求),再 POST,解析返回的新记录。 */
export async function submitCreateShopKey(form: ShopKeyFormValues): Promise<ShopKeyItem> {
/**
* 提交新增店铺密钥:先校验(失败抛首条错误不发请求),再 POST,解析返回的新记录。
*
* 归属走**查询参数** `company_id`(不进请求体——Java 侧 requestDtoCarriesNoCompanyField 钉着 body
* 不许有 companyId 字段),取值是公司 tab;非超管时 `requestCompanyId` 恒为 null,
* 后端那道门会按会话落本公司,所以这里不为 null 编一个默认公司。
*/
export async function submitCreateShopKey(form: ShopKeyFormValues, companyId?: number | null): Promise<ShopKeyItem> {
const { valid, errors } = validateShopKeyForm(form)
if (!valid) {
throw new Error(Object.values(errors)[0] || '店铺密钥表单校验未通过')
}
const { data } = await http.post<unknown>(SHOP_KEYS_ENDPOINT, toShopKeyCreateRequest(form))
const { data } = await http.post<unknown>(
SHOP_KEYS_ENDPOINT,
toShopKeyCreateRequest(form),
companyId != null ? { params: { company_id: companyId } } : undefined,
)
const item = toShopKeyItem(unwrap<unknown>(data))
if (!item) {
throw new Error('新增店铺密钥响应异常:未返回有效记录')
@@ -3,13 +3,12 @@ import { unwrap } from '../../api/envelope.ts'
import {
emptyShopKeyPageResult,
toSensitiveString,
IP_WHITELIST_VALUES,
type IpWhitelistStatus,
type ShopKeyItem,
type ShopKeyPageResult,
} from './shop-dto.ts'
const IP_WHITELIST_VALUES: readonly string[] = ['UNKNOWN', 'ALLOWED', 'BLOCKED']
function text(value: unknown): string {
return typeof value === 'string' ? value.trim() : ''
}
@@ -21,7 +20,7 @@ function numberOrNull(value: unknown): number | null {
/** 归一白名单状态;未知/缺省一律回 UNKNOWN。 */
export function normalizeIpWhitelistStatus(value: unknown): IpWhitelistStatus {
const textValue = typeof value === 'string' ? value.trim().toUpperCase() : ''
return (IP_WHITELIST_VALUES.includes(textValue) ? textValue : 'UNKNOWN') as IpWhitelistStatus
return (IP_WHITELIST_VALUES.includes(textValue as IpWhitelistStatus) ? textValue : 'UNKNOWN') as IpWhitelistStatus
}
export interface WhitelistStatusMeta {
@@ -44,6 +43,18 @@ export function whitelistStatusMeta(status: IpWhitelistStatus | null | undefined
return SHOP_KEY_STATUS_META[key] || SHOP_KEY_STATUS_META.UNKNOWN
}
/**
* 筛选下拉的选项表:从上面那张文案表推导,不另立第二份「正常/未加白名单/未检测」。
* 顺序照 IP_WHITELIST_VALUES,下拉与列表药丸同名同序才不会让"筛出来的是未检测、
* 行上写着未加白名单"这种对不上的读法出现。
*/
export function whitelistStatusOptions(): Array<{ value: IpWhitelistStatus; label: string }> {
return IP_WHITELIST_VALUES.map((value) => ({
value: value as IpWhitelistStatus,
label: SHOP_KEY_STATUS_META[value as IpWhitelistStatus].label,
}))
}
/** 解析单条店铺密钥行;缺 id 视为无效。 */
export function toShopKeyItem(raw: unknown): ShopKeyItem | null {
if (!raw || typeof raw !== 'object') return null