feat(web): 京东工具台三页头部加密钥设置入口(2026-11-22 用户口径「这边也要加密钥设置」,京东上架 AI 补值要读登录用户 LLM 密钥)
- BrandApiSecretSettingsButton 加可选 showProxy(默认 true,亚马逊侧现有调用零变化);透传面板既有 showProxy(708/771 行已按它条件保存/余额);副标题按 showProxy 派生(隐藏代理时不再提「代理设置保存在当前客户端」) - JdConsolePage/JdCollectTab/JdPublishTab 头部 .top-right(铃铛与用户名之间)各插 <BrandApiSecretSettingsButton variant="topbar" :show-proxy="false"/>——京东特性无代理消费方,隐藏代理区防「没配代理影响京东采集吗」误判(铁律 27 同款) - 弹窗/保存/检测/余额走既有 /newApi/api/user-secrets 链,零新端点零新权限 key - 判据:jd-secret-entry.test.ts(三页头部精确匹配+按钮四钉)+jd-secret-entry.mount.test.ts(top-right 触发钮/showProxy 透传/副标题三用例);四支既有 JD mount 补 ApiSecretSettingsPanel stub 防真发 fetch(31 绿+mount 59 绿零噪声+vue-tsc rc=0) 随下一 app-web 窗上线
This commit is contained in:
@@ -17,11 +17,11 @@
|
|||||||
<template #header>
|
<template #header>
|
||||||
<div class="dialog-header">
|
<div class="dialog-header">
|
||||||
<div class="dialog-title">密钥设置</div>
|
<div class="dialog-title">密钥设置</div>
|
||||||
<div class="dialog-subtitle">密钥保存在服务端并绑定当前账号,换设备登录后自动同步;代理设置保存在当前客户端。</div>
|
<div class="dialog-subtitle">{{ dialogSubtitle }}</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<ApiSecretSettingsPanel ref="panelRef" />
|
<ApiSecretSettingsPanel ref="panelRef" :show-proxy="showProxy" />
|
||||||
|
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<div class="dialog-footer">
|
<div class="dialog-footer">
|
||||||
@@ -48,19 +48,33 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, watch } from 'vue'
|
import { computed, ref, watch } from 'vue'
|
||||||
import ApiSecretSettingsPanel from '@/shared/components/ApiSecretSettingsPanel.vue'
|
import ApiSecretSettingsPanel from '@/shared/components/ApiSecretSettingsPanel.vue'
|
||||||
|
|
||||||
withDefaults(
|
const props = withDefaults(
|
||||||
defineProps<{
|
defineProps<{
|
||||||
/** topbar=顶栏纯文字样式(对齐主程序);默认=现有胶囊按钮 */
|
/** topbar=顶栏纯文字样式(对齐主程序);默认=现有胶囊按钮 */
|
||||||
variant?: 'topbar'
|
variant?: 'topbar'
|
||||||
|
/**
|
||||||
|
* 是否展示代理设置区(透传给面板,默认展示)。京东工具台入口传 false——
|
||||||
|
* 京东特性(采集=本机浏览器、上架补值=LLM 密钥)没有任何代理消费方,
|
||||||
|
* 展示青果/jikip 配置只会引来「没配代理影响京东采集吗」的误判。
|
||||||
|
*/
|
||||||
|
showProxy?: boolean
|
||||||
}>(),
|
}>(),
|
||||||
{
|
{
|
||||||
variant: undefined,
|
variant: undefined,
|
||||||
|
showProxy: true,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/** 副标题跟着代理区走:隐藏代理时不再提「代理设置保存在当前客户端」。 */
|
||||||
|
const dialogSubtitle = computed(() =>
|
||||||
|
props.showProxy
|
||||||
|
? '密钥保存在服务端并绑定当前账号,换设备登录后自动同步;代理设置保存在当前客户端。'
|
||||||
|
: '密钥保存在服务端并绑定当前账号,换设备登录后自动同步。',
|
||||||
|
)
|
||||||
|
|
||||||
const dialogVisible = ref(false)
|
const dialogVisible = ref(false)
|
||||||
const saving = ref(false)
|
const saving = ref(false)
|
||||||
const panelRef = ref<InstanceType<typeof ApiSecretSettingsPanel> | null>(null)
|
const panelRef = ref<InstanceType<typeof ApiSecretSettingsPanel> | null>(null)
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import { userNotice } from '@/shared/utils/user-notice'
|
|||||||
import { formatDateTime } from '@/shared/utils/datetime'
|
import { formatDateTime } from '@/shared/utils/datetime'
|
||||||
import { useLiveTaskBoard } from '@/shared/composables/useLiveTaskBoard'
|
import { useLiveTaskBoard } from '@/shared/composables/useLiveTaskBoard'
|
||||||
import NotificationBell from '@/shared/components/NotificationBell.vue'
|
import NotificationBell from '@/shared/components/NotificationBell.vue'
|
||||||
|
import BrandApiSecretSettingsButton from '@/pages/brand/components/BrandApiSecretSettingsButton.vue'
|
||||||
|
|
||||||
/** 京东「获取店铺数据」(v1.5):一键建单 → 推送本机客户端 → 右侧任务面板实时进度。
|
/** 京东「获取店铺数据」(v1.5):一键建单 → 推送本机客户端 → 右侧任务面板实时进度。
|
||||||
*
|
*
|
||||||
@@ -664,6 +665,7 @@ onUnmounted(() => {
|
|||||||
|
|
||||||
<div class="top-right">
|
<div class="top-right">
|
||||||
<NotificationBell />
|
<NotificationBell />
|
||||||
|
<BrandApiSecretSettingsButton variant="topbar" :show-proxy="false" />
|
||||||
<span class="admin-name">{{ username }}</span>
|
<span class="admin-name">{{ username }}</span>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
<div class="top-right">
|
<div class="top-right">
|
||||||
<NotificationBell />
|
<NotificationBell />
|
||||||
|
<BrandApiSecretSettingsButton variant="topbar" :show-proxy="false" />
|
||||||
<span class="admin-name">{{ username }}</span>
|
<span class="admin-name">{{ username }}</span>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
@@ -88,6 +89,7 @@
|
|||||||
import { onBeforeUnmount, onMounted, ref } from 'vue'
|
import { onBeforeUnmount, onMounted, ref } from 'vue'
|
||||||
|
|
||||||
import NotificationBell from '@/shared/components/NotificationBell.vue'
|
import NotificationBell from '@/shared/components/NotificationBell.vue'
|
||||||
|
import BrandApiSecretSettingsButton from '@/pages/brand/components/BrandApiSecretSettingsButton.vue'
|
||||||
import { resolvePageHref } from '@/shared/page-prefix'
|
import { resolvePageHref } from '@/shared/page-prefix'
|
||||||
import { getCurrentUserAppColumnKeys } from '@/shared/api/permission'
|
import { getCurrentUserAppColumnKeys } from '@/shared/api/permission'
|
||||||
import { filterJdToolsByPermission, JD_TOOLS, type JdToolInfo } from '@/pages/jd/tool-catalog'
|
import { filterJdToolsByPermission, JD_TOOLS, type JdToolInfo } from '@/pages/jd/tool-catalog'
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import { userNotice } from '@/shared/utils/user-notice'
|
|||||||
import { formatDateTime } from '@/shared/utils/datetime'
|
import { formatDateTime } from '@/shared/utils/datetime'
|
||||||
import { useLiveTaskBoard } from '@/shared/composables/useLiveTaskBoard'
|
import { useLiveTaskBoard } from '@/shared/composables/useLiveTaskBoard'
|
||||||
import NotificationBell from '@/shared/components/NotificationBell.vue'
|
import NotificationBell from '@/shared/components/NotificationBell.vue'
|
||||||
|
import BrandApiSecretSettingsButton from '@/pages/brand/components/BrandApiSecretSettingsButton.vue'
|
||||||
|
|
||||||
/** 京东「商品上架」(v1.5 蓝图 §4 Phase 4):选分类 → 勾商品 → 改价规则 → 建单 → 右侧任务面板实时行级进度。
|
/** 京东「商品上架」(v1.5 蓝图 §4 Phase 4):选分类 → 勾商品 → 改价规则 → 建单 → 右侧任务面板实时行级进度。
|
||||||
*
|
*
|
||||||
@@ -613,6 +614,7 @@ onUnmounted(() => {
|
|||||||
</div>
|
</div>
|
||||||
<div class="top-right">
|
<div class="top-right">
|
||||||
<NotificationBell />
|
<NotificationBell />
|
||||||
|
<BrandApiSecretSettingsButton variant="topbar" :show-proxy="false" />
|
||||||
<span class="admin-name">{{ username }}</span>
|
<span class="admin-name">{{ username }}</span>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
import assert from 'node:assert/strict'
|
||||||
|
import test from 'node:test'
|
||||||
|
import { existsSync, readFileSync } from 'node:fs'
|
||||||
|
import { join } from 'node:path'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 2026-11-22 京东工具台密钥设置入口(用户拍板「这边也要加密钥设置」)的源码绊线。
|
||||||
|
*
|
||||||
|
* 三件钉:
|
||||||
|
* 1. 三个京东页(工具台/采集/上架)头部 .top-right 都挂 BrandApiSecretSettingsButton
|
||||||
|
* (variant=topbar、show-proxy=false——京东特性没有代理消费方,面板代理区不许出现);
|
||||||
|
* 2. 按钮组件把 showProxy 透传给面板、副标题随代理区开关派生、默认仍 true(亚马逊侧零变化);
|
||||||
|
* 3. 面板本体与 setup 强制门不在本文件射程(不动)。
|
||||||
|
*/
|
||||||
|
|
||||||
|
const ROOT = process.cwd()
|
||||||
|
|
||||||
|
function read(relativePath: string, what: string): string {
|
||||||
|
const path = join(ROOT, relativePath)
|
||||||
|
assert.ok(existsSync(path), `${what} 尚未落地:${path}`)
|
||||||
|
return readFileSync(path, 'utf8')
|
||||||
|
}
|
||||||
|
|
||||||
|
const JD_PAGES = [
|
||||||
|
['src/pages/jd/JdConsolePage.vue', '京东工具台首页'],
|
||||||
|
['src/pages/jd/JdCollectTab.vue', '京东采集页'],
|
||||||
|
['src/pages/jd/JdPublishTab.vue', '京东上架页'],
|
||||||
|
] as const
|
||||||
|
|
||||||
|
const ENTRY_LINE = '<BrandApiSecretSettingsButton variant="topbar" :show-proxy="false" />'
|
||||||
|
|
||||||
|
test('三个京东页头部都挂密钥设置入口(variant=topbar、show-proxy=false)', () => {
|
||||||
|
for (const [file, what] of JD_PAGES) {
|
||||||
|
const src = read(file, what)
|
||||||
|
assert.ok(src.includes(ENTRY_LINE), `${what}(${file})头部没有密钥设置入口:${ENTRY_LINE}`)
|
||||||
|
assert.ok(
|
||||||
|
/import BrandApiSecretSettingsButton from '@\/pages\/brand\/components\/BrandApiSecretSettingsButton\.vue'/.test(src),
|
||||||
|
`${what}(${file})没有 import BrandApiSecretSettingsButton`,
|
||||||
|
)
|
||||||
|
// 入口必须画在 .top-right(铃铛与用户名之间),不得挪去别处
|
||||||
|
assert.ok(
|
||||||
|
/<div class="top-right">\s*<NotificationBell \/>\s*<BrandApiSecretSettingsButton[^>]*\/>\s*<span class="admin-name">/.test(src),
|
||||||
|
`${what}(${file})的密钥设置入口不在 top-right(NotificationBell 与用户名之间)`,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
test('按钮组件把 showProxy 透传给面板,副标题随代理区开关派生,默认 true(亚马逊侧零变化)', () => {
|
||||||
|
const src = read('src/pages/brand/components/BrandApiSecretSettingsButton.vue', '密钥设置按钮')
|
||||||
|
assert.ok(
|
||||||
|
/<ApiSecretSettingsPanel ref="panelRef" :show-proxy="showProxy" \/>/.test(src),
|
||||||
|
'按钮组件没有把 showProxy 透传给面板:京东入口传 false 也只会照常显示代理区',
|
||||||
|
)
|
||||||
|
assert.ok(/showProxy\?: boolean/.test(src), '按钮组件没有 showProxy prop')
|
||||||
|
assert.ok(
|
||||||
|
/props\.showProxy\s*\?/.test(src),
|
||||||
|
'副标题没有按 showProxy 派生:隐藏代理时不得再提「代理设置保存在当前客户端」',
|
||||||
|
)
|
||||||
|
assert.ok(/showProxy: true,/.test(src), 'showProxy 默认值必须是 true(亚马逊侧现有调用零变化)')
|
||||||
|
})
|
||||||
@@ -128,6 +128,8 @@ async function mountPage(realSelect = false) {
|
|||||||
...(realSelect ? { plugins: [ElementPlus] } : {}),
|
...(realSelect ? { plugins: [ElementPlus] } : {}),
|
||||||
stubs: {
|
stubs: {
|
||||||
NotificationBell: true,
|
NotificationBell: true,
|
||||||
|
// 2026-11-22 JD 页头部挂了密钥设置按钮:面板替身化,别在挂载用例里真发 /user-secrets fetch
|
||||||
|
ApiSecretSettingsPanel: true,
|
||||||
RouterLink: { template: '<a class="router-link-stub"><slot /></a>' },
|
RouterLink: { template: '<a class="router-link-stub"><slot /></a>' },
|
||||||
'router-link': { template: '<a class="router-link-stub"><slot /></a>' },
|
'router-link': { template: '<a class="router-link-stub"><slot /></a>' },
|
||||||
...(realSelect ? {} : { 'el-select': ElSelectStub, 'el-option': ElOptionStub }),
|
...(realSelect ? {} : { 'el-select': ElSelectStub, 'el-option': ElOptionStub }),
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ function mountConsole() {
|
|||||||
global: {
|
global: {
|
||||||
stubs: {
|
stubs: {
|
||||||
NotificationBell: true,
|
NotificationBell: true,
|
||||||
|
// 2026-11-22 JD 页头部挂了密钥设置按钮:面板替身化,别在挂载用例里真发 /user-secrets fetch
|
||||||
|
ApiSecretSettingsPanel: true,
|
||||||
RouterLink: { props: ['to'], template: '<a class="router-link-stub" :data-to="to"><slot /></a>' },
|
RouterLink: { props: ['to'], template: '<a class="router-link-stub" :data-to="to"><slot /></a>' },
|
||||||
'router-link': { props: ['to'], template: '<a class="router-link-stub" :data-to="to"><slot /></a>' },
|
'router-link': { props: ['to'], template: '<a class="router-link-stub" :data-to="to"><slot /></a>' },
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ async function mountConsole() {
|
|||||||
global: {
|
global: {
|
||||||
stubs: {
|
stubs: {
|
||||||
NotificationBell: true,
|
NotificationBell: true,
|
||||||
|
// 2026-11-22 JD 页头部挂了密钥设置按钮:面板替身化,别在挂载用例里真发 /user-secrets fetch
|
||||||
|
ApiSecretSettingsPanel: true,
|
||||||
RouterLink: { template: '<a class="router-link-stub"><slot /></a>' },
|
RouterLink: { template: '<a class="router-link-stub"><slot /></a>' },
|
||||||
'router-link': { template: '<a class="router-link-stub"><slot /></a>' },
|
'router-link': { template: '<a class="router-link-stub"><slot /></a>' },
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -61,6 +61,8 @@ async function mountPage() {
|
|||||||
global: {
|
global: {
|
||||||
stubs: {
|
stubs: {
|
||||||
NotificationBell: true, RouterLink: true, ElOption: true,
|
NotificationBell: true, RouterLink: true, ElOption: true,
|
||||||
|
// 2026-11-22 JD 页头部挂了密钥设置按钮:面板替身化,别在挂载用例里真发 /user-secrets fetch
|
||||||
|
ApiSecretSettingsPanel: true,
|
||||||
ElSelect: { props: ['modelValue'], emits: ['update:modelValue', 'change'], template: '<div><slot /></div>' },
|
ElSelect: { props: ['modelValue'], emits: ['update:modelValue', 'change'], template: '<div><slot /></div>' },
|
||||||
ElPagination: { emits: ['current-change'], template: '<div />' }, ElInputNumber: true,
|
ElPagination: { emits: ['current-change'], template: '<div />' }, ElInputNumber: true,
|
||||||
ElDrawer: { props: ['modelValue'], template: '<div v-if="modelValue"><slot /></div>' },
|
ElDrawer: { props: ['modelValue'], template: '<div v-if="modelValue"><slot /></div>' },
|
||||||
|
|||||||
@@ -0,0 +1,97 @@
|
|||||||
|
/**
|
||||||
|
* 2026-11-22 京东工具台密钥设置入口的挂载契约:
|
||||||
|
* - JdConsolePage 头部 .top-right 真挂出「密钥设置」触发钮(头部不受权限过滤影响,恒在);
|
||||||
|
* - BrandApiSecretSettingsButton 把 showProxy=false 透传给面板(京东入口隐藏代理区)、
|
||||||
|
* 默认 true(亚马逊侧现有调用零变化)、隐藏代理时副标题不再提「代理设置」。
|
||||||
|
* 跑法:cd frontend-vue && npx vitest run tests/mount/jd-secret-entry.mount.test.ts
|
||||||
|
*/
|
||||||
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||||
|
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||||
|
|
||||||
|
vi.mock('@/shared/api/permission', () => ({
|
||||||
|
getCurrentUserAppColumnKeys: vi.fn().mockResolvedValue(['jd_tools']),
|
||||||
|
}))
|
||||||
|
|
||||||
|
import JdConsolePage from '@/pages/jd/JdConsolePage.vue'
|
||||||
|
import BrandApiSecretSettingsButton from '@/pages/brand/components/BrandApiSecretSettingsButton.vue'
|
||||||
|
|
||||||
|
/** 面板替身:把收到的 showProxy 反到 DOM 上;expose 出按钮会调的 reload/saveAll。 */
|
||||||
|
const panelStub = {
|
||||||
|
props: ['showProxy'],
|
||||||
|
template: '<div class="panel-stub" :data-show-proxy="String(showProxy)" />',
|
||||||
|
setup(_: unknown, { expose }: { expose: (api: Record<string, unknown>) => void }) {
|
||||||
|
expose({ reload: vi.fn(), saveAll: vi.fn().mockResolvedValue(true) })
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const BUTTON_STUBS = { ApiSecretSettingsPanel: panelStub }
|
||||||
|
|
||||||
|
/** vitest 配置不挂 ElementPlusResolver ⇒ `<el-dialog>` 是未知元素、命名插槽不渲染;弹窗用例本地挂替身。 */
|
||||||
|
const dialogStub = {
|
||||||
|
props: ['modelValue', 'appendToBody'],
|
||||||
|
template: '<div class="dialog-stub"><slot name="header" /><slot /><slot name="footer" /></div>',
|
||||||
|
}
|
||||||
|
|
||||||
|
let wrapper: VueWrapper | null = null
|
||||||
|
|
||||||
|
describe('京东工具台密钥设置入口(2026-11-22)', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
window.localStorage.setItem('username', 'admin')
|
||||||
|
})
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
wrapper?.unmount()
|
||||||
|
wrapper = null
|
||||||
|
window.localStorage.clear()
|
||||||
|
document.body.innerHTML = ''
|
||||||
|
})
|
||||||
|
|
||||||
|
it('JdConsolePage 头部 top-right 挂出触发钮(NotificationBell 与用户名之间)', async () => {
|
||||||
|
wrapper = mount(JdConsolePage, {
|
||||||
|
global: {
|
||||||
|
stubs: {
|
||||||
|
NotificationBell: true,
|
||||||
|
RouterLink: { template: '<a class="router-link-stub"><slot /></a>' },
|
||||||
|
'router-link': { template: '<a class="router-link-stub"><slot /></a>' },
|
||||||
|
...BUTTON_STUBS,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
await flushPromises()
|
||||||
|
const topRight = wrapper.find('.top-right')
|
||||||
|
expect(topRight.exists()).toBe(true)
|
||||||
|
expect(topRight.find('.secret-settings-trigger').exists()).toBe(true)
|
||||||
|
expect(topRight.text()).toContain('密钥设置')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('按钮把 showProxy 透传给面板:京东入口 false、默认 true', () => {
|
||||||
|
const wFalse = mount(BrandApiSecretSettingsButton, {
|
||||||
|
props: { showProxy: false, variant: 'topbar' as const },
|
||||||
|
global: { stubs: { ...BUTTON_STUBS } },
|
||||||
|
})
|
||||||
|
expect(wFalse.find('.panel-stub').attributes('data-show-proxy')).toBe('false')
|
||||||
|
wFalse.unmount()
|
||||||
|
|
||||||
|
const wDefault = mount(BrandApiSecretSettingsButton, {
|
||||||
|
global: { stubs: { ...BUTTON_STUBS } },
|
||||||
|
})
|
||||||
|
expect(wDefault.find('.panel-stub').attributes('data-show-proxy')).toBe('true')
|
||||||
|
wDefault.unmount()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('隐藏代理时副标题不再提「代理设置」', async () => {
|
||||||
|
wrapper = mount(BrandApiSecretSettingsButton, {
|
||||||
|
props: { showProxy: false },
|
||||||
|
global: {
|
||||||
|
components: { ElDialog: dialogStub },
|
||||||
|
stubs: { ...BUTTON_STUBS },
|
||||||
|
},
|
||||||
|
})
|
||||||
|
await wrapper.find('.secret-settings-trigger').trigger('click')
|
||||||
|
await flushPromises()
|
||||||
|
const subtitle = wrapper.find('.dialog-subtitle')
|
||||||
|
expect(subtitle.exists()).toBe(true)
|
||||||
|
expect(subtitle.text()).toContain('密钥保存在服务端并绑定当前账号')
|
||||||
|
expect(subtitle.text()).not.toContain('代理设置')
|
||||||
|
})
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user