优化结构

This commit is contained in:
Yvan
2026-08-21 11:16:12 +08:00
parent 055f6811ca
commit e81a641953
13 changed files with 432 additions and 7 deletions
+5
View File
@@ -23,3 +23,8 @@ export const refundPaymentOrder = (data) => service({
method: 'post',
data
})
export const testPaymentProvider = (provider) => service({
url: `/payment/providers/${encodeURIComponent(provider)}/test`,
method: 'post'
})
+22 -2
View File
@@ -34,6 +34,7 @@
</el-form>
<div class="editor-actions">
<el-button type="primary" :loading="saving" :icon="Check" @click="save">保存配置</el-button>
<el-button :loading="testing" :icon="Connection" @click="testProvider">测试渠道</el-button>
<el-button v-if="selected.configured" type="danger" plain :icon="Delete" @click="remove">删除配置</el-button>
<el-button text :icon="DocumentCopy" @click="copyConfig">复制 JSON</el-button>
</div>
@@ -46,14 +47,33 @@
<script setup>
import { computed, ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { Check, Delete, DocumentCopy, Refresh } from '@element-plus/icons-vue'
import { Check, Connection, Delete, DocumentCopy, Refresh } from '@element-plus/icons-vue'
import { deleteIntegrationConfig, getIntegrationConfigs, saveIntegrationConfig } from '@/api/integration'
import { testPaymentProvider } from '@/api/payment'
const configs = ref([]); const selectedProvider = ref(''); const loading = ref(false); const saving = ref(false)
const configs = ref([]); const selectedProvider = ref(''); const loading = ref(false); const saving = ref(false); const testing = ref(false)
const selected = computed(() => configs.value.find((item) => item.provider === selectedProvider.value) || configs.value[0])
const select = (item) => { selectedProvider.value = item.provider }
const load = async () => { loading.value = true; try { const res = await getIntegrationConfigs('payment'); if (res.code === 0) { configs.value = (res.data || []).map((item) => ({ ...item, config: { ...(item.config || {}) } })); if (!configs.value.some((item) => item.provider === selectedProvider.value)) selectedProvider.value = configs.value[0]?.provider || '' } } finally { loading.value = false } }
const save = async () => { if (!selected.value) return; saving.value = true; try { const res = await saveIntegrationConfig('payment', selected.value.provider, { enabled: selected.value.enabled, config: selected.value.config }); if (res.code === 0) { ElMessage.success('支付渠道配置已保存'); await load() } } finally { saving.value = false } }
const testProvider = async () => {
if (!selected.value) return
const environment = String(selected.value.config?.environment || '').toLowerCase()
if (environment === 'production' || environment === 'prod') {
try { await ElMessageBox.confirm('当前渠道使用生产环境,测试会真实创建最小金额订单。确认使用专用测试商户执行吗?', '生产环境测试确认', { type: 'warning', confirmButtonText: '确认测试' }) } catch { return }
}
testing.value = true
try {
const res = await testPaymentProvider(selected.value.provider)
const result = res.data || {}
const stages = (result.stages || []).map((stage) => `${stage.status === 'passed' ? '通过' : stage.status === 'skipped' ? '跳过' : '失败'}:${stage.name}${stage.message ? ` - ${stage.message}` : ''}${stage.durationMs != null ? ` (${stage.durationMs}ms)` : ''}`).join('\n')
if (res.code === 0 && result.passed) {
const title = result.fullFlow ? '渠道完整链路测试通过' : '渠道连通性测试通过(完整支付链路未完成)'
ElMessage.success({ message: `${title}\n${stages}`, duration: 9000, showClose: true })
}
else ElMessage.error({ message: `渠道测试未通过\n${stages || res.msg || '未知错误'}`, duration: 9000, showClose: true })
} finally { testing.value = false }
}
const remove = async () => { if (!selected.value) return; await ElMessageBox.confirm(`确认删除 ${selected.value.name || selected.value.provider} 配置吗?`, '删除配置', { type: 'warning' }); const res = await deleteIntegrationConfig('payment', selected.value.provider); if (res.code === 0) { ElMessage.success('配置已删除'); await load() } }
const copyConfig = async () => { if (!selected.value) return; await navigator.clipboard.writeText(JSON.stringify(selected.value.config || {}, null, 2)); ElMessage.success('JSON 已复制') }
load()