diff --git a/admin-frontend-vue/src/pages/shop/ShopKeysPage.vue b/admin-frontend-vue/src/pages/shop/ShopKeysPage.vue index 9dd5be15..3e3d285c 100644 --- a/admin-frontend-vue/src/pages/shop/ShopKeysPage.vue +++ b/admin-frontend-vue/src/pages/shop/ShopKeysPage.vue @@ -4,9 +4,9 @@ import { formatDateTime } from '@/utils/datetime' import { onMounted, reactive, ref } from 'vue' import { ElMessage, ElMessageBox } from 'element-plus' import { fetchShopKeyList, submitCreateShopKey, updateShopKey, deleteShopKey } from './shop-key-api.ts' -import { emptyShopKeyForm } from './shop-key-form-model.ts' +import { emptyShopKeyForm, normalizeZiniaoToken } from './shop-key-form-model.ts' import type { ShopKeyItem } from './shop-dto.ts' -import { toSensitiveString, type IpWhitelistStatus } from './shop-dto.ts' +import { whitelistStatusMeta } from './shop-key-model.ts' const loading = ref(false) const rows = ref([]) @@ -25,8 +25,16 @@ function maskToken(token: string): string { return `${value.slice(0, 4)}••••••••${value.slice(-4)}` } -function statusText(status: IpWhitelistStatus): string { - return status === 'ALLOWED' ? '已白名单' : status === 'BLOCKED' ? '被拦截' : '未知' +/** 编辑时保留原令牌的内存引用:令牌不落页面明文展示,留空提交则沿用原令牌。 */ +const originalToken = ref('') + +/** 白名单状态药丸悬停详情:检测时间 + 检测消息(对齐 admin)。 */ +function whitelistTooltip(row: ShopKeyItem): string { + const parts: string[] = [] + if (row.ipWhitelistCheckedAt) parts.push(`检测时间:${formatDateTime(row.ipWhitelistCheckedAt)}`) + if (row.ipWhitelistMessage) parts.push(row.ipWhitelistMessage) + if (parts.length === 0) parts.push(`白名单状态:${whitelistStatusMeta(row.ipWhitelistStatus).label}`) + return parts.join('\n') } async function load() { @@ -51,6 +59,7 @@ function openCreate() { function openEdit(row: ShopKeyItem) { editingId.value = row.id + originalToken.value = row.ziniaoToken Object.assign(form, emptyShopKeyForm()) form.remarkName = row.remarkName form.ziniaoAccountName = row.ziniaoAccountName @@ -58,14 +67,26 @@ function openEdit(row: ShopKeyItem) { } async function submit() { + const token = normalizeZiniaoToken(form.ziniaoToken) + const creating = editingId.value == null + if (creating && !token) { + ElMessage.warning('请完整填写紫鸟账号名称、紫鸟令牌') + return + } + if (!(form.ziniaoAccountName || '').trim()) { + ElMessage.warning('请完整填写紫鸟账号名称、紫鸟令牌') + return + } + // 编辑留空令牌 = 沿用原令牌(令牌不明文展示)。 + form.ziniaoToken = creating ? token : token || originalToken.value saving.value = true try { - if (editingId.value == null) { + if (creating) { await submitCreateShopKey({ ...form }) } else { - await updateShopKey(editingId.value, { ...form }) + await updateShopKey(editingId.value as number, { ...form }) } - ElMessage.success(editingId.value == null ? '已新增' : '已保存') + ElMessage.success(creating ? '已新增' : '已保存') dialogVisible.value = false load() } catch (error) { @@ -77,7 +98,7 @@ async function submit() { async function remove(row: ShopKeyItem) { try { - await ElMessageBox.confirm(`确认删除密钥「${row.ziniaoAccountName}」?`, '删除密钥', { type: 'warning' }) + await ElMessageBox.confirm(`确定删除店铺密钥“${row.ziniaoAccountName}”吗?`, '删除确认', { type: 'warning' }) } catch { return } @@ -117,16 +138,21 @@ onMounted(load) - + + + +