revert: remove fork-only changes from release sync

Revert payment/wechat, sora/claude-max cleanup, fork-only migrations,
and cosmetic changes that were brought in by the release sync commit.
Keep only channel-monitor related improvements:
- PublicSettingsInjectionPayload named struct with drift test
- ChannelMonitorRunner graceful shutdown in wire
- image_output_price in SupportedModelChip
- Simplified buildSelfNavItems in AppSidebar
- Gateway WARN logs for 503 branches
This commit is contained in:
erio
2026-04-23 21:40:58 +08:00
parent a3ea8ecac5
commit 67518a59ac
71 changed files with 1792 additions and 1396 deletions

View File

@@ -698,48 +698,6 @@
</div>
</div>
<!-- Allow Overages (Antigravity only) -->
<div v-if="allAntigravity" class="border-t border-gray-200 pt-4 dark:border-dark-600">
<div class="flex items-center justify-between">
<div class="flex-1 pr-4">
<label
id="bulk-edit-allow-overages-label"
class="input-label mb-0"
for="bulk-edit-allow-overages-enabled"
>
{{ t('admin.accounts.allowOverages') }}
</label>
<p class="mt-1 text-xs text-gray-500 dark:text-gray-400">
{{ t('admin.accounts.allowOveragesTooltip') }}
</p>
</div>
<input
v-model="enableAllowOverages"
id="bulk-edit-allow-overages-enabled"
type="checkbox"
aria-controls="bulk-edit-allow-overages-body"
class="rounded border-gray-300 text-primary-600 focus:ring-primary-500"
/>
</div>
<div v-if="enableAllowOverages" id="bulk-edit-allow-overages-body" class="mt-3">
<button
type="button"
:class="[
'relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2',
allowOverages ? 'bg-primary-600' : 'bg-gray-200 dark:bg-dark-600'
]"
@click="allowOverages = !allowOverages"
>
<span
:class="[
'pointer-events-none inline-block h-5 w-5 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out',
allowOverages ? 'translate-x-5' : 'translate-x-0'
]"
/>
</button>
</div>
</div>
<!-- RPM Limit (仅全部为 Anthropic OAuth/SetupToken 时显示) -->
<div v-if="allAnthropicOAuthOrSetupToken" class="border-t border-gray-200 pt-4 dark:border-dark-600">
<div class="mb-3 flex items-center justify-between">
@@ -1009,11 +967,6 @@ const allOpenAIOAuth = computed(() => {
)
})
// 是否全部为 Antigravity 平台allow_overages 仅在此条件下显示)
const allAntigravity = computed(() =>
props.selectedPlatforms.length === 1 && props.selectedPlatforms[0] === 'antigravity'
)
// 是否全部为 Anthropic OAuth/SetupTokenRPM 配置仅在此条件下显示)
const allAnthropicOAuthOrSetupToken = computed(() => {
return (
@@ -1060,7 +1013,6 @@ const enableGroups = ref(false)
const enableOpenAIPassthrough = ref(false)
const enableOpenAIWSMode = ref(false)
const enableRpmLimit = ref(false)
const enableAllowOverages = ref(false)
// State - field values
const submitting = ref(false)
@@ -1088,7 +1040,6 @@ const bulkBaseRpm = ref<number | null>(null)
const bulkRpmStrategy = ref<'tiered' | 'sticky_exempt'>('tiered')
const bulkRpmStickyBuffer = ref<number | null>(null)
const userMsgQueueMode = ref<string | null>(null)
const allowOverages = ref(false)
const umqModeOptions = computed(() => [
{ value: '', label: t('admin.accounts.quotaControl.rpmLimit.umqModeOff') },
{ value: 'throttle', label: t('admin.accounts.quotaControl.rpmLimit.umqModeThrottle') },
@@ -1330,13 +1281,6 @@ const buildUpdatePayload = (): Record<string, unknown> | null => {
umqExtra.user_msg_queue_enabled = false // 清理旧字段JSONB merge
}
// Allow overages (Antigravity only)
if (enableAllowOverages.value) {
if (!updates.extra) updates.extra = {}
const overagesExtra = updates.extra as Record<string, unknown>
overagesExtra.allow_overages = allowOverages.value
}
return Object.keys(updates).length > 0 ? updates : null
}
@@ -1401,7 +1345,6 @@ const handleSubmit = async () => {
enableGroups.value ||
enableOpenAIWSMode.value ||
enableRpmLimit.value ||
enableAllowOverages.value ||
userMsgQueueMode.value !== null
if (!hasAnyFieldEnabled) {
@@ -1495,7 +1438,6 @@ watch(
enableOpenAIPassthrough.value = false
enableOpenAIWSMode.value = false
enableRpmLimit.value = false
enableAllowOverages.value = false
// Reset all values
baseUrl.value = ''
@@ -1519,7 +1461,6 @@ watch(
bulkRpmStrategy.value = 'tiered'
bulkRpmStickyBuffer.value = null
userMsgQueueMode.value = null
allowOverages.value = false
// Reset mixed channel warning state
showMixedChannelWarning.value = false

View File

@@ -3322,12 +3322,7 @@ watch(
if (newVal) {
// Load TLS fingerprint profiles
adminAPI.tlsFingerprintProfiles.list()
.then(profiles => {
tlsFingerprintProfiles.value = profiles.map(p => ({
id: p.id,
name: p.name,
}))
})
.then(profiles => { tlsFingerprintProfiles.value = profiles.map(p => ({ id: p.id, name: p.name })) })
.catch(() => { tlsFingerprintProfiles.value = [] })
// Modal opened - fill related models
allowedModels.value = [...getModelsByPlatform(form.platform)]

View File

@@ -2440,10 +2440,7 @@ watch(
const loadTLSProfiles = async () => {
try {
const profiles = await adminAPI.tlsFingerprintProfiles.list()
tlsFingerprintProfiles.value = profiles.map(p => ({
id: p.id,
name: p.name,
}))
tlsFingerprintProfiles.value = profiles.map(p => ({ id: p.id, name: p.name }))
} catch {
tlsFingerprintProfiles.value = []
}
@@ -3312,5 +3309,4 @@ const handleMixedChannelConfirm = async () => {
const handleMixedChannelCancel = () => {
clearMixedChannelDialog()
}
</script>

View File

@@ -122,7 +122,7 @@ describe('AccountStatusIndicator', () => {
}
})
expect(wrapper.text()).toContain('admin.accounts.status.creditsExhausted')
expect(wrapper.text()).toContain('account.creditsExhausted')
})
it('模型限流 + overages 启用 + AICredits key 生效 → 普通限流样式(积分耗尽,无 ⚡)', () => {
@@ -157,6 +157,6 @@ describe('AccountStatusIndicator', () => {
expect(wrapper.text()).toContain('CSon45')
expect(wrapper.text()).not.toContain('⚡')
// AICredits 积分耗尽状态应显示
expect(wrapper.text()).toContain('admin.accounts.status.creditsExhausted')
expect(wrapper.text()).toContain('account.creditsExhausted')
})
})

View File

@@ -15,10 +15,6 @@ vi.mock('@/api/admin', () => ({
}
}))
vi.mock('@/utils/usageLoadQueue', () => ({
enqueueUsageRequest: (_account: unknown, fn: () => Promise<unknown>) => fn()
}))
vi.mock('vue-i18n', async () => {
const actual = await vi.importActual<typeof import('vue-i18n')>('vue-i18n')
return {
@@ -389,117 +385,6 @@ describe('AccountUsageCell', () => {
expect(wrapper.text()).toContain('7d|0|27700')
})
it('OpenAI OAuth 在 usage 请求失败时仍回退显示本地 codex 快照', async () => {
getUsage.mockRejectedValue(new Error('network error'))
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {})
const wrapper = mount(AccountUsageCell, {
props: {
account: makeAccount({
id: 2004,
platform: 'openai',
type: 'oauth',
extra: {
codex_usage_updated_at: '2099-03-07T10:00:00Z',
codex_5h_used_percent: 12,
codex_5h_reset_at: '2099-03-07T12:00:00Z',
codex_7d_used_percent: 34,
codex_7d_reset_at: '2099-03-13T12:00:00Z'
}
})
},
global: {
stubs: {
UsageProgressBar: {
props: ['label', 'utilization', 'resetsAt', 'windowStats', 'color'],
template: '<div class="usage-bar">{{ label }}|{{ utilization }}|{{ resetsAt }}</div>'
},
AccountQuotaInfo: true
}
}
})
await flushPromises()
expect(getUsage).toHaveBeenCalledWith(2004)
expect(wrapper.text()).toContain('5h|12|2099-03-07T12:00:00.000Z')
expect(wrapper.text()).toContain('7d|34|2099-03-13T12:00:00.000Z')
errorSpy.mockRestore()
})
it('OpenAI OAuth 已限额时首屏优先等待重新查询的 usage而不是先显示旧 codex 快照', async () => {
let resolveUsage: ((value: any) => void) | null = null
getUsage.mockReturnValue(
new Promise((resolve) => {
resolveUsage = resolve
})
)
const wrapper = mount(AccountUsageCell, {
props: {
account: makeAccount({
id: 2005,
platform: 'openai',
type: 'oauth',
rate_limit_reset_at: '2099-03-07T12:00:00Z',
extra: {
codex_5h_used_percent: 0,
codex_5h_reset_at: '2099-03-07T12:00:00Z',
codex_7d_used_percent: 0,
codex_7d_reset_at: '2099-03-13T12:00:00Z'
}
})
},
global: {
stubs: {
UsageProgressBar: {
props: ['label', 'utilization', 'resetsAt', 'windowStats', 'color'],
template: '<div class="usage-bar">{{ label }}|{{ utilization }}|{{ windowStats?.tokens }}</div>'
},
AccountQuotaInfo: true
}
}
})
await Promise.resolve()
expect(getUsage).toHaveBeenCalledWith(2005)
expect(wrapper.text()).not.toContain('5h|0|')
expect(wrapper.text()).not.toContain('7d|0|')
resolveUsage?.({
five_hour: {
utilization: 100,
resets_at: '2026-03-07T12:00:00Z',
remaining_seconds: 3600,
window_stats: {
requests: 211,
tokens: 106540000,
cost: 38.13,
standard_cost: 38.13,
user_cost: 38.13
}
},
seven_day: {
utilization: 100,
resets_at: '2026-03-13T12:00:00Z',
remaining_seconds: 3600,
window_stats: {
requests: 211,
tokens: 106540000,
cost: 38.13,
standard_cost: 38.13,
user_cost: 38.13
}
}
})
await flushPromises()
expect(wrapper.text()).toContain('5h|100|106540000')
expect(wrapper.text()).toContain('7d|100|106540000')
})
it('OpenAI OAuth 在行数据刷新但仍无 codex 快照时会重新拉取 usage', async () => {
getUsage
.mockResolvedValueOnce({

View File

@@ -1,23 +1,69 @@
<script setup lang="ts">
import { ref, useTemplateRef, nextTick } from 'vue'
import { onBeforeUnmount, onMounted, ref, useTemplateRef, nextTick } from 'vue'
defineProps<{
const props = withDefaults(defineProps<{
content?: string
}>()
trigger?: 'hover' | 'click'
widthClass?: string
}>(), {
trigger: 'hover',
widthClass: 'w-64',
})
const show = ref(false)
const triggerRef = useTemplateRef<HTMLElement>('trigger')
const tooltipRef = useTemplateRef<HTMLElement>('tooltip')
const tooltipStyle = ref({ top: '0px', left: '0px' })
function onEnter() {
function openTooltip() {
show.value = true
nextTick(updatePosition)
}
function onLeave() {
function closeTooltip() {
show.value = false
}
function onEnter() {
if (props.trigger !== 'hover') return
openTooltip()
}
function onLeave() {
if (props.trigger !== 'hover') return
closeTooltip()
}
function onClick(event: MouseEvent) {
if (props.trigger !== 'click') return
event.stopPropagation()
if (show.value) {
closeTooltip()
return
}
openTooltip()
}
function onDocumentClick(event: MouseEvent) {
if (props.trigger !== 'click' || !show.value) return
const target = event.target as Node | null
if (!target) return
if (triggerRef.value?.contains(target) || tooltipRef.value?.contains(target)) return
closeTooltip()
}
function onDocumentKeydown(event: KeyboardEvent) {
if (props.trigger !== 'click') return
if (event.key === 'Escape') {
closeTooltip()
}
}
function onViewportChange() {
if (!show.value) return
updatePosition()
}
function updatePosition() {
const el = triggerRef.value
if (!el) return
@@ -27,6 +73,20 @@ function updatePosition() {
left: `${rect.left + rect.width / 2 + window.scrollX}px`,
}
}
onMounted(() => {
document.addEventListener('click', onDocumentClick, true)
document.addEventListener('keydown', onDocumentKeydown)
window.addEventListener('resize', onViewportChange)
window.addEventListener('scroll', onViewportChange, true)
})
onBeforeUnmount(() => {
document.removeEventListener('click', onDocumentClick, true)
document.removeEventListener('keydown', onDocumentKeydown)
window.removeEventListener('resize', onViewportChange)
window.removeEventListener('scroll', onViewportChange, true)
})
</script>
<template>
@@ -35,6 +95,7 @@ function updatePosition() {
class="group relative ml-1 inline-flex items-center align-middle"
@mouseenter="onEnter"
@mouseleave="onLeave"
@click="onClick"
>
<!-- Trigger Icon -->
<slot name="trigger">
@@ -56,10 +117,26 @@ function updatePosition() {
<!-- Teleport to body to escape modal overflow clipping -->
<Teleport to="body">
<div
ref="tooltip"
v-show="show"
class="fixed z-[99999] w-64 -translate-x-1/2 -translate-y-full rounded-lg bg-gray-900 p-3 text-xs leading-relaxed text-white shadow-xl ring-1 ring-white/10 dark:bg-gray-800"
role="tooltip"
:class="[
'fixed z-[99999] -translate-x-1/2 -translate-y-full rounded-lg bg-gray-900 p-3 text-xs leading-relaxed text-white shadow-xl ring-1 ring-white/10 dark:bg-gray-800',
props.widthClass,
]"
:style="{ top: `calc(${tooltipStyle.top} - 8px)`, left: tooltipStyle.left }"
>
<button
v-if="props.trigger === 'click'"
type="button"
class="absolute right-1.5 top-1.5 rounded p-1 text-gray-300 transition-colors hover:bg-white/10 hover:text-white"
aria-label="Close"
@click.stop="closeTooltip"
>
<svg class="h-3.5 w-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
<slot>{{ content }}</slot>
<div class="absolute -bottom-1 left-1/2 h-2 w-2 -translate-x-1/2 rotate-45 bg-gray-900 dark:bg-gray-800"></div>
</div>

View File

@@ -1,104 +0,0 @@
<template>
<!-- 悬浮按钮 - 使用主题色 -->
<button
@click="showModal = true"
class="fixed bottom-6 right-6 z-50 flex items-center gap-2 rounded-full bg-gradient-to-r from-primary-500 to-primary-600 px-4 py-3 text-white shadow-lg shadow-primary-500/25 transition-all hover:from-primary-600 hover:to-primary-700 hover:shadow-xl hover:shadow-primary-500/30"
>
<svg class="h-5 w-5" viewBox="0 0 24 24" fill="currentColor">
<path d="M8.691 2.188C3.891 2.188 0 5.476 0 9.53c0 2.212 1.17 4.203 3.002 5.55a.59.59 0 01.213.665l-.39 1.48c-.019.07-.048.141-.048.213 0 .163.13.295.29.295a.328.328 0 00.186-.059l2.114-1.225a.87.87 0 01.415-.106.807.807 0 01.213.026 10.07 10.07 0 002.696.37c.262 0 .52-.011.776-.028a5.91 5.91 0 01-.193-1.479c0-3.644 3.374-6.6 7.536-6.6.262 0 .52.011.776.028-.628-3.513-4.27-6.472-8.885-6.472zM5.785 5.97a1.1 1.1 0 110 2.2 1.1 1.1 0 010-2.2zm5.813 0a1.1 1.1 0 110 2.2 1.1 1.1 0 010-2.2zm5.192 2.642c-3.703 0-6.71 2.567-6.71 5.73 0 3.163 3.007 5.73 6.71 5.73a7.9 7.9 0 002.126-.288.644.644 0 01.17-.022.69.69 0 01.329.085l1.672.97a.262.262 0 00.147.046c.128 0 .23-.104.23-.233a.403.403 0 00-.038-.168l-.309-1.17a.468.468 0 01.168-.527c1.449-1.065 2.374-2.643 2.374-4.423 0-3.163-3.007-5.73-6.71-5.73h-.159zm-2.434 3.34a.88.88 0 110 1.76.88.88 0 010-1.76zm4.868 0a.88.88 0 110 1.76.88.88 0 010-1.76z"/>
</svg>
<span class="text-sm font-medium">客服</span>
</button>
<!-- 弹窗 -->
<Teleport to="body">
<Transition name="fade">
<div
v-if="showModal"
class="fixed inset-0 z-[100] flex items-center justify-center bg-black/50 p-4 backdrop-blur-sm"
@click.self="showModal = false"
>
<Transition name="scale">
<div
v-if="showModal"
class="relative w-full max-w-sm rounded-2xl bg-white p-6 shadow-2xl dark:bg-dark-700"
>
<!-- 关闭按钮 -->
<button
@click="showModal = false"
class="absolute right-4 top-4 text-gray-400 transition-colors hover:text-gray-600 dark:text-dark-400 dark:hover:text-dark-200"
>
<svg class="h-5 w-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
<!-- 标题 -->
<div class="mb-4 flex items-center gap-3">
<div class="flex h-10 w-10 items-center justify-center rounded-full bg-gradient-to-br from-primary-500 to-primary-600">
<svg class="h-6 w-6 text-white" viewBox="0 0 24 24" fill="currentColor">
<path d="M8.691 2.188C3.891 2.188 0 5.476 0 9.53c0 2.212 1.17 4.203 3.002 5.55a.59.59 0 01.213.665l-.39 1.48c-.019.07-.048.141-.048.213 0 .163.13.295.29.295a.328.328 0 00.186-.059l2.114-1.225a.87.87 0 01.415-.106.807.807 0 01.213.026 10.07 10.07 0 002.696.37c.262 0 .52-.011.776-.028a5.91 5.91 0 01-.193-1.479c0-3.644 3.374-6.6 7.536-6.6.262 0 .52.011.776.028-.628-3.513-4.27-6.472-8.885-6.472zM5.785 5.97a1.1 1.1 0 110 2.2 1.1 1.1 0 010-2.2zm5.813 0a1.1 1.1 0 110 2.2 1.1 1.1 0 010-2.2zm5.192 2.642c-3.703 0-6.71 2.567-6.71 5.73 0 3.163 3.007 5.73 6.71 5.73a7.9 7.9 0 002.126-.288.644.644 0 01.17-.022.69.69 0 01.329.085l1.672.97a.262.262 0 00.147.046c.128 0 .23-.104.23-.233a.403.403 0 00-.038-.168l-.309-1.17a.468.468 0 01.168-.527c1.449-1.065 2.374-2.643 2.374-4.423 0-3.163-3.007-5.73-6.71-5.73h-.159zm-2.434 3.34a.88.88 0 110 1.76.88.88 0 010-1.76zm4.868 0a.88.88 0 110 1.76.88.88 0 010-1.76z"/>
</svg>
</div>
<div>
<h3 class="text-lg font-semibold text-gray-900 dark:text-white">联系客服</h3>
<p class="text-sm text-gray-500 dark:text-dark-400">扫码添加好友</p>
</div>
</div>
<!-- 二维码卡片 -->
<div class="mb-4 overflow-hidden rounded-xl border border-primary-100 bg-gradient-to-br from-primary-50 to-white p-3 dark:border-primary-800/30 dark:from-primary-900/10 dark:to-dark-800">
<img
src="/wechat-qr.jpg"
alt="微信二维码"
class="w-full rounded-lg"
/>
</div>
<!-- 提示文字 -->
<div class="text-center">
<p class="mb-2 text-sm font-medium text-primary-600 dark:text-primary-400">
微信扫码添加客服
</p>
<p class="flex items-center justify-center gap-1 text-xs text-gray-500 dark:text-dark-400">
<svg class="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
工作时间周一至周五 9:00-18:00
</p>
</div>
</div>
</Transition>
</div>
</Transition>
</Teleport>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const showModal = ref(false)
</script>
<style scoped>
.fade-enter-active,
.fade-leave-active {
transition: opacity 0.2s ease;
}
.fade-enter-from,
.fade-leave-to {
opacity: 0;
}
.scale-enter-active,
.scale-leave-active {
transition: all 0.2s ease;
}
.scale-enter-from,
.scale-leave-to {
opacity: 0;
transform: scale(0.95);
}
</style>

View File

@@ -0,0 +1,80 @@
import { afterEach, describe, expect, it } from 'vitest'
import { mount } from '@vue/test-utils'
import { nextTick } from 'vue'
import HelpTooltip from '@/components/common/HelpTooltip.vue'
function getTooltipElement(): HTMLDivElement {
const tooltip = document.body.querySelector('[role="tooltip"]')
if (!(tooltip instanceof HTMLDivElement)) {
throw new Error('tooltip element not found')
}
return tooltip
}
describe('HelpTooltip', () => {
afterEach(() => {
document.body.innerHTML = ''
})
it('keeps the existing hover interaction by default', async () => {
const wrapper = mount(HelpTooltip, {
attachTo: document.body,
props: {
content: 'hover details',
},
})
const trigger = wrapper.get('.group')
const tooltip = getTooltipElement()
expect(tooltip.style.display).toBe('none')
await trigger.trigger('mouseenter')
await nextTick()
expect(tooltip.style.display).not.toBe('none')
await trigger.trigger('mouseleave')
await nextTick()
expect(tooltip.style.display).toBe('none')
wrapper.unmount()
})
it('supports click-to-toggle details and closes on outside click', async () => {
const wrapper = mount(HelpTooltip, {
attachTo: document.body,
props: {
content: 'click details',
trigger: 'click',
},
})
const trigger = wrapper.get('.group')
const tooltip = getTooltipElement()
expect(tooltip.style.display).toBe('none')
await trigger.trigger('click')
await nextTick()
expect(tooltip.style.display).not.toBe('none')
expect(tooltip.textContent).toContain('click details')
const closeButton = tooltip.querySelector('button[aria-label="Close"]')
if (!(closeButton instanceof HTMLButtonElement)) {
throw new Error('close button not found')
}
closeButton.click()
await nextTick()
expect(tooltip.style.display).toBe('none')
await trigger.trigger('click')
await nextTick()
expect(tooltip.style.display).not.toBe('none')
document.body.dispatchEvent(new MouseEvent('click', { bubbles: true }))
await nextTick()
expect(tooltip.style.display).toBe('none')
wrapper.unmount()
})
})

View File

@@ -125,6 +125,7 @@
<Icon name="key" size="sm" />
{{ t('nav.apiKeys') }}
</router-link>
<a
v-if="authStore.isAdmin"
href="https://github.com/Wei-Shaw/sub2api"
@@ -142,6 +143,7 @@
</svg>
{{ t('nav.github') }}
</a>
</div>
<!-- Contact Support (only show if configured) -->

View File

@@ -73,9 +73,42 @@
<!-- Config fields -->
<div class="border-t border-gray-200 pt-4 dark:border-dark-700">
<h4 class="mb-3 text-sm font-semibold text-gray-900 dark:text-white">
{{ t('admin.settings.payment.providerConfig') }}
</h4>
<div class="mb-3 flex items-center gap-2">
<h4 class="text-sm font-semibold text-gray-900 dark:text-white">
{{ t('admin.settings.payment.providerConfig') }}
</h4>
<HelpTooltip v-if="paymentGuide" trigger="click" width-class="w-80">
<template #trigger>
<button
type="button"
class="inline-flex h-5 w-5 items-center justify-center rounded-full border border-gray-300 text-[11px] font-semibold text-gray-400 transition-colors hover:border-primary-500 hover:text-primary-600 dark:border-dark-500 dark:text-gray-500 dark:hover:border-primary-400 dark:hover:text-primary-400"
:aria-label="t('admin.settings.payment.paymentGuideTrigger')"
:title="t('admin.settings.payment.paymentGuideTrigger')"
>
?
</button>
</template>
<div class="space-y-3">
<p class="font-medium text-white">{{ paymentGuide.summary }}</p>
<div
v-for="item in paymentGuide.items"
:key="item.title"
class="space-y-1.5 border-t border-white/10 pt-2 first:border-t-0 first:pt-0"
>
<p class="font-medium text-white">{{ item.title }}</p>
<p><span class="text-gray-300">{{ t('admin.settings.payment.guideOpenLabel') }}</span>{{ item.open }}</p>
<p><span class="text-gray-300">{{ t('admin.settings.payment.guideCallLabel') }}</span>{{ item.call }}</p>
<p><span class="text-gray-300">{{ t('admin.settings.payment.guideFallbackLabel') }}</span>{{ item.fallback }}</p>
</div>
<p v-if="paymentGuide.note" class="border-t border-white/10 pt-2 text-[11px] text-gray-300">
{{ paymentGuide.note }}
</p>
</div>
</HelpTooltip>
</div>
<p v-if="paymentGuide" class="mb-3 text-xs text-gray-500 dark:text-gray-400">
{{ paymentGuide.summary }}
</p>
<div class="space-y-3">
<div v-for="field in resolvedFields" :key="field.key">
<label class="input-label">
@@ -220,6 +253,7 @@
import { reactive, computed, ref } from 'vue'
import { useI18n } from 'vue-i18n'
import BaseDialog from '@/components/common/BaseDialog.vue'
import HelpTooltip from '@/components/common/HelpTooltip.vue'
import Select from '@/components/common/Select.vue'
import type { SelectOption } from '@/components/common/Select.vue'
import ToggleSwitch from './ToggleSwitch.vue'
@@ -263,6 +297,19 @@ const emit = defineEmits<{
const { t } = useI18n()
interface PaymentGuideItem {
title: string
open: string
call: string
fallback: string
}
interface PaymentGuide {
summary: string
items: PaymentGuideItem[]
note?: string
}
// --- Form state ---
const form = reactive({
name: '',
@@ -314,6 +361,63 @@ const resolvedFields = computed(() => {
}))
})
const paymentGuide = computed<PaymentGuide | null>(() => {
if (form.provider_key === 'alipay') {
return {
summary: t('admin.settings.payment.alipayGuideSummary'),
items: [
{
title: t('admin.settings.payment.alipayGuideFaceToFaceTitle'),
open: t('admin.settings.payment.alipayGuideFaceToFaceOpen'),
call: t('admin.settings.payment.alipayGuideFaceToFaceCall'),
fallback: t('admin.settings.payment.alipayGuideFaceToFaceFallback'),
},
{
title: t('admin.settings.payment.alipayGuidePagePayTitle'),
open: t('admin.settings.payment.alipayGuidePagePayOpen'),
call: t('admin.settings.payment.alipayGuidePagePayCall'),
fallback: t('admin.settings.payment.alipayGuidePagePayFallback'),
},
{
title: t('admin.settings.payment.alipayGuideWapTitle'),
open: t('admin.settings.payment.alipayGuideWapOpen'),
call: t('admin.settings.payment.alipayGuideWapCall'),
fallback: t('admin.settings.payment.alipayGuideWapFallback'),
},
],
}
}
if (form.provider_key === 'wxpay') {
return {
summary: t('admin.settings.payment.wxpayGuideSummary'),
note: t('admin.settings.payment.wxpayGuideNote'),
items: [
{
title: t('admin.settings.payment.wxpayGuideNativeTitle'),
open: t('admin.settings.payment.wxpayGuideNativeOpen'),
call: t('admin.settings.payment.wxpayGuideNativeCall'),
fallback: t('admin.settings.payment.wxpayGuideNativeFallback'),
},
{
title: t('admin.settings.payment.wxpayGuideJsapiTitle'),
open: t('admin.settings.payment.wxpayGuideJsapiOpen'),
call: t('admin.settings.payment.wxpayGuideJsapiCall'),
fallback: t('admin.settings.payment.wxpayGuideJsapiFallback'),
},
{
title: t('admin.settings.payment.wxpayGuideH5Title'),
open: t('admin.settings.payment.wxpayGuideH5Open'),
call: t('admin.settings.payment.wxpayGuideH5Call'),
fallback: t('admin.settings.payment.wxpayGuideH5Fallback'),
},
],
}
}
return null
})
const limitableTypes = computed(() => {
// Stripe: single "stripe" entry (one set of shared limits)
if (form.provider_key === 'stripe') {

View File

@@ -84,6 +84,9 @@
</div>
</div>
<p v-if="scanHint" class="text-center text-sm text-gray-500 dark:text-gray-400">{{ scanHint }}</p>
<button v-if="payUrl" class="btn btn-secondary text-sm" @click="reopenPopup">
{{ t('payment.qr.openPayWindow') }}
</button>
</div>
</div>
<div class="card p-4 text-center">

View File

@@ -0,0 +1,78 @@
import { describe, expect, it, vi } from 'vitest'
import { mount } from '@vue/test-utils'
import { nextTick } from 'vue'
import PaymentProviderDialog from '@/components/payment/PaymentProviderDialog.vue'
const messages: Record<string, string> = {
'admin.settings.payment.providerConfig': 'Credentials',
'admin.settings.payment.paymentGuideTrigger': 'View payment guide',
'admin.settings.payment.alipayGuideSummary': 'Desktop prefers QR precreate and falls back to cashier; mobile prefers WAP checkout.',
'admin.settings.payment.wxpayGuideSummary': 'Desktop prefers Native QR; mobile routes to JSAPI or H5 based on browser context.',
}
vi.mock('vue-i18n', () => ({
useI18n: () => ({
t: (key: string) => messages[key] ?? key,
}),
}))
function mountDialog() {
return mount(PaymentProviderDialog, {
props: {
show: true,
saving: false,
editing: null,
allKeyOptions: [
{ value: 'alipay', label: 'Alipay' },
{ value: 'wxpay', label: 'WeChat Pay' },
{ value: 'stripe', label: 'Stripe' },
],
enabledKeyOptions: [
{ value: 'alipay', label: 'Alipay' },
{ value: 'wxpay', label: 'WeChat Pay' },
],
allPaymentTypes: [
{ value: 'alipay', label: 'Alipay' },
{ value: 'wxpay', label: 'WeChat Pay' },
],
redirectLabel: 'Redirect',
},
global: {
stubs: {
BaseDialog: {
template: '<div><slot /><slot name="footer" /></div>',
},
Select: {
props: ['modelValue', 'options', 'disabled'],
template: '<div />',
},
ToggleSwitch: {
template: '<div />',
},
},
},
})
}
describe('PaymentProviderDialog payment guide', () => {
it('shows no payment guide for providers without a flow guide', () => {
const wrapper = mountDialog()
expect(wrapper.text()).not.toContain(messages['admin.settings.payment.alipayGuideSummary'])
expect(wrapper.text()).not.toContain(messages['admin.settings.payment.wxpayGuideSummary'])
expect(wrapper.find('button[title="View payment guide"]').exists()).toBe(false)
})
it.each([
['alipay', 'admin.settings.payment.alipayGuideSummary'],
['wxpay', 'admin.settings.payment.wxpayGuideSummary'],
])('shows the payment guide summary for %s', async (providerKey, summaryKey) => {
const wrapper = mountDialog()
;(wrapper.vm as unknown as { reset: (key: string) => void }).reset(providerKey)
await nextTick()
expect(wrapper.text()).toContain(messages[summaryKey])
expect(wrapper.find('button[title="View payment guide"]').exists()).toBe(true)
})
})

View File

@@ -96,4 +96,36 @@ describe('PaymentStatusPanel', () => {
expect(wrapper.text()).toContain('payment.result.success')
expect(wrapper.emitted('success')).toHaveLength(1)
})
it('shows reopen button in QR mode when payUrl is also available', async () => {
const openSpy = vi.spyOn(window, 'open').mockReturnValue({ closed: false } as Window)
const wrapper = mount(PaymentStatusPanel, {
props: {
orderId: 42,
qrCode: 'https://pay.example.com/qr/42',
payUrl: 'https://pay.example.com/session/42',
expiresAt: '2099-01-01T12:30:00Z',
paymentType: 'alipay',
orderType: 'balance',
},
global: {
stubs: {
Icon: true,
},
},
})
await flushPromises()
expect(wrapper.text()).toContain('payment.qr.openPayWindow')
await wrapper.get('button.btn.btn-secondary.text-sm').trigger('click')
expect(openSpy).toHaveBeenCalledWith(
'https://pay.example.com/session/42',
'paymentPopup',
expect.any(String),
)
openSpy.mockRestore()
})
})

View File

@@ -190,12 +190,14 @@ describe('buildCreateOrderPayload', () => {
paymentType: 'alipay_direct',
orderType: 'balance',
origin: 'https://app.example.com/',
isMobile: true,
isWechatBrowser: false,
})).toEqual({
amount: 88,
payment_type: 'alipay',
order_type: 'balance',
return_url: 'https://app.example.com/payment/result',
is_mobile: true,
payment_source: 'hosted_redirect',
})
})
@@ -207,6 +209,7 @@ describe('buildCreateOrderPayload', () => {
orderType: 'subscription',
planId: 7,
origin: 'https://app.example.com',
isMobile: false,
isWechatBrowser: true,
})).toEqual({
amount: 128,
@@ -214,6 +217,7 @@ describe('buildCreateOrderPayload', () => {
order_type: 'subscription',
plan_id: 7,
return_url: 'https://app.example.com/payment/result',
is_mobile: false,
payment_source: 'wechat_in_app_resume',
})
})

View File

@@ -12,9 +12,9 @@ describe('PROVIDER_CONFIG_FIELDS.wxpay', () => {
expect(findField('certSerial')?.optional).toBeFalsy()
})
it('exposes optional mp and H5 metadata fields for WeChat-specific flows', () => {
expect(findField('mpAppId')?.optional).toBe(true)
expect(findField('h5AppName')?.optional).toBe(true)
expect(findField('h5AppUrl')?.optional).toBe(true)
it('only keeps the simplified visible credential set in the admin form', () => {
expect(findField('mpAppId')).toBeUndefined()
expect(findField('h5AppName')).toBeUndefined()
expect(findField('h5AppUrl')).toBeUndefined()
})
})

View File

@@ -68,6 +68,7 @@ export interface BuildCreateOrderPayloadInput {
orderType: OrderType
planId?: number
origin?: string
isMobile: boolean
isWechatBrowser: boolean
}
@@ -106,6 +107,7 @@ export function buildCreateOrderPayload(input: BuildCreateOrderPayloadInput): Cr
amount: input.amount,
payment_type: visibleMethod,
order_type: input.orderType,
is_mobile: input.isMobile,
payment_source: visibleMethod === 'wxpay' && input.isWechatBrowser
? 'wechat_in_app_resume'
: 'hosted_redirect',

View File

@@ -96,15 +96,12 @@ export const PROVIDER_CONFIG_FIELDS: Record<string, ConfigFieldDef[]> = {
],
wxpay: [
{ key: 'appId', label: 'App ID', sensitive: false },
{ key: 'mpAppId', label: '', sensitive: false, optional: true },
{ key: 'mchId', label: '', sensitive: false },
{ key: 'privateKey', label: '', sensitive: true },
{ key: 'apiV3Key', label: '', sensitive: true },
{ key: 'certSerial', label: '', sensitive: false },
{ key: 'publicKey', label: '', sensitive: true },
{ key: 'publicKeyId', label: '', sensitive: false },
{ key: 'h5AppName', label: '', sensitive: false, optional: true },
{ key: 'h5AppUrl', label: '', sensitive: false, optional: true },
],
stripe: [
{ key: 'secretKey', label: '', sensitive: true },