Files
pj_admin_cloud/src/views/admin/seataProbe/index.vue
T
2026-09-19 23:57:33 +08:00

86 lines
2.9 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<div class="layout-padding">
<div class="layout-padding-auto layout-padding-view">
<el-alert
title="用于验证 Seata Server(如升级到 2.1)后全局事务是否正常。请先在业务库执行 db/seata_tx_probe.sql。"
type="info"
:closable="false"
show-icon
class="mb8"
/>
<div class="mb8">
<el-button type="primary" :loading="commitLoading" @click="runCommit" v-auth="'admin_seata_probe'">
测试提交(应落库)
</el-button>
<el-button type="warning" :loading="rollbackLoading" @click="runRollback" v-auth="'admin_seata_probe'">
测试回滚(应不落库)
</el-button>
</div>
<el-descriptions v-if="lastResult" title="最近一次结果" :column="1" border>
<el-descriptions-item label="是否通过">
<el-tag :type="lastResult.pass ? 'success' : 'danger'">{{ lastResult.pass ? '通过' : '未通过' }}</el-tag>
</el-descriptions-item>
<el-descriptions-item label="说明">{{ lastResult.message }}</el-descriptions-item>
<el-descriptions-item label="类型">{{ lastResult.caseType }}</el-descriptions-item>
<el-descriptions-item label="mark">{{ lastResult.mark }}</el-descriptions-item>
<el-descriptions-item label="xid">{{ lastResult.xid || '-' }}</el-descriptions-item>
<el-descriptions-item label="库中行数">{{ lastResult.rowCount }}</el-descriptions-item>
</el-descriptions>
<div v-else style="color: #909399">点击上方按钮开始测试</div>
</div>
</div>
</template>
<script setup lang="ts" name="adminSeataProbe">
import { ref } from 'vue'
import { useMessage } from '/@/hooks/message'
import { seataProbeCommit, seataProbeRollback } from '/@/api/admin/seataProbe'
const commitLoading = ref(false)
const rollbackLoading = ref(false)
const lastResult = ref<any>(null)
const pickBody = (res: any) => {
if (res?.data && typeof res.data === 'object' && ('pass' in res.data || 'mark' in res.data)) {
return res.data
}
return res?.data ?? res
}
const runCommit = async () => {
commitLoading.value = true
try {
const res: any = await seataProbeCommit()
const body = pickBody(res)
lastResult.value = body
if (res?.code === 0 && body?.pass) {
useMessage().success(body.message || '提交探测通过')
} else {
useMessage().error(res?.msg || body?.message || '提交探测失败')
}
} catch (e: any) {
useMessage().error(e?.msg || e?.message || '请求失败')
} finally {
commitLoading.value = false
}
}
const runRollback = async () => {
rollbackLoading.value = true
try {
const res: any = await seataProbeRollback()
const body = pickBody(res)
lastResult.value = body
if (res?.code === 0 && body?.pass) {
useMessage().success(body.message || '回滚探测通过')
} else {
useMessage().error(res?.msg || body?.message || '回滚探测失败')
}
} catch (e: any) {
useMessage().error(e?.msg || e?.message || '请求失败')
} finally {
rollbackLoading.value = false
}
}
</script>