feat(mq): improve Kafka peek and admin localization
This commit is contained in:
1 parent
a9e76dc130
commit
68b1777aa4
29 files changed
+4561
-636
No files matched your search
@@ -1,6 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { formatError } from "@/lib/backend/errorUtils";
|
||||
import { ref, watch } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import type { TopicRef, TopicInfo, SubscriptionInfo, ResetPosition, SkipCount, PeekedMessage } from "@/types/mq";
|
||||
import { mqListSubscriptions, mqCreateSubscription, mqDeleteSubscription, mqResetCursor, mqSkipMessages, mqClearBacklog, mqPeekMessages, mqExpireMessages } from "@/lib/backend/api";
|
||||
|
||||
@@ -23,6 +24,8 @@ const emit = defineEmits<{
|
||||
subscriptionSelected: [subscription: string];
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
const subscriptions = ref<SubscriptionInfo[]>([]);
|
||||
const loading = ref(false);
|
||||
const error = ref<string>();
|
||||
@@ -52,11 +55,10 @@ const skipFormData = ref({
|
||||
});
|
||||
|
||||
const expireSeconds = ref(3600);
|
||||
const readOnlyMessage = "当前连接为只读模式,不能执行写操作";
|
||||
|
||||
function guardWritable() {
|
||||
if (props.readOnly) {
|
||||
error.value = readOnlyMessage;
|
||||
error.value = t("mqSubscriptions.readOnly");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -143,7 +145,7 @@ async function handleCreate() {
|
||||
if (!guardWritable()) return;
|
||||
const topicRef = getTopicRef();
|
||||
if (!formData.value.subName.trim() || !topicRef) {
|
||||
error.value = "Subscription name is required";
|
||||
error.value = t("mqSubscriptions.subscriptionNameRequired");
|
||||
return;
|
||||
}
|
||||
loading.value = true;
|
||||
@@ -162,7 +164,7 @@ async function handleCreate() {
|
||||
|
||||
async function handleDelete(sub: SubscriptionInfo) {
|
||||
if (!guardWritable()) return;
|
||||
if (!confirm(`确定要删除订阅 "${sub.name}" 吗?此操作不可逆。`)) return;
|
||||
if (!confirm(t("mqSubscriptions.confirmDelete", { name: sub.name }))) return;
|
||||
const topicRef = getTopicRef();
|
||||
if (!topicRef) return;
|
||||
loading.value = true;
|
||||
@@ -220,7 +222,7 @@ async function handleSkipMessages() {
|
||||
|
||||
async function handleClearBacklog(sub: SubscriptionInfo) {
|
||||
if (!guardWritable()) return;
|
||||
if (!confirm(`确定要清空订阅 "${sub.name}" 的所有积压消息吗?`)) return;
|
||||
if (!confirm(t("mqSubscriptions.confirmClearBacklog", { name: sub.name }))) return;
|
||||
const topicRef = getTopicRef();
|
||||
if (!topicRef) return;
|
||||
loading.value = true;
|
||||
@@ -281,28 +283,28 @@ watch(
|
||||
<template>
|
||||
<div class="subscriptions-panel">
|
||||
<div class="panel-toolbar">
|
||||
<h3>订阅管理</h3>
|
||||
<button v-if="supportsCreateSubscription !== false" @click="openCreateDialog" :disabled="loading || readOnly || !topic" class="btn-primary">+ 创建订阅</button>
|
||||
<h3>{{ t("mqSubscriptions.title") }}</h3>
|
||||
<button v-if="supportsCreateSubscription !== false" @click="openCreateDialog" :disabled="loading || readOnly || !topic" class="btn-primary">+ {{ t("mqSubscriptions.createSubscription") }}</button>
|
||||
</div>
|
||||
|
||||
<div v-if="!topic" class="panel-placeholder">请先选择一个主题</div>
|
||||
<div v-if="!topic" class="panel-placeholder">{{ t("mqSubscriptions.selectTopicFirst") }}</div>
|
||||
|
||||
<div v-else-if="error" class="panel-error">{{ error }}</div>
|
||||
|
||||
<div v-else-if="loading && !subscriptions.length" class="panel-loading">加载中...</div>
|
||||
<div v-else-if="loading && !subscriptions.length" class="panel-loading">{{ t("mqSubscriptions.loading") }}</div>
|
||||
|
||||
<div v-else-if="!subscriptions.length" class="panel-placeholder">该主题暂无订阅</div>
|
||||
<div v-else-if="!subscriptions.length" class="panel-placeholder">{{ t("mqSubscriptions.noSubscriptions") }}</div>
|
||||
|
||||
<div v-else class="subscriptions-table">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>订阅名称</th>
|
||||
<th>类型</th>
|
||||
<th>积压消息</th>
|
||||
<th>消费速率</th>
|
||||
<th>消费者</th>
|
||||
<th>操作</th>
|
||||
<th>{{ t("mqSubscriptions.subscriptionName") }}</th>
|
||||
<th>{{ t("mqSubscriptions.type") }}</th>
|
||||
<th>{{ t("mqSubscriptions.backlog") }}</th>
|
||||
<th>{{ t("mqSubscriptions.consumeRate") }}</th>
|
||||
<th>{{ t("mqSubscriptions.consumers") }}</th>
|
||||
<th>{{ t("mqSubscriptions.actions") }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -316,15 +318,15 @@ watch(
|
||||
{{ sub.msgBacklog.toLocaleString() }}
|
||||
</span>
|
||||
</td>
|
||||
<td>{{ sub.msgRateOut.toFixed(2) }} msg/s</td>
|
||||
<td>{{ sub.consumers.length }} 个</td>
|
||||
<td>{{ t("mqSubscriptions.msgRate", { rate: sub.msgRateOut.toFixed(2) }) }}</td>
|
||||
<td>{{ t("mqSubscriptions.consumerCount", { count: sub.consumers.length }) }}</td>
|
||||
<td class="actions">
|
||||
<button v-if="supportsResetCursor !== false" @click.stop="openResetDialog(sub)" :disabled="readOnly" class="btn-sm">重置游标</button>
|
||||
<button v-if="supportsSkipMessages !== false" @click.stop="openSkipDialog(sub)" :disabled="readOnly" class="btn-sm">跳过消息</button>
|
||||
<button v-if="supportsClearBacklog !== false" @click.stop="handleClearBacklog(sub)" :disabled="readOnly" class="btn-sm">清空积压</button>
|
||||
<button v-if="supportsPeekMessages" @click.stop="openPeekDialog(sub)" class="btn-sm">Peek</button>
|
||||
<button v-if="supportsExpireMessages !== false" @click.stop="openExpireDialog(sub)" :disabled="readOnly" class="btn-sm">过期消息</button>
|
||||
<button @click.stop="handleDelete(sub)" :disabled="readOnly" class="btn-sm btn-danger">删除</button>
|
||||
<button v-if="supportsResetCursor !== false" @click.stop="openResetDialog(sub)" :disabled="readOnly" class="btn-sm">{{ t("mqSubscriptions.resetCursor") }}</button>
|
||||
<button v-if="supportsSkipMessages !== false" @click.stop="openSkipDialog(sub)" :disabled="readOnly" class="btn-sm">{{ t("mqSubscriptions.skipMessages") }}</button>
|
||||
<button v-if="supportsClearBacklog !== false" @click.stop="handleClearBacklog(sub)" :disabled="readOnly" class="btn-sm">{{ t("mqSubscriptions.clearBacklog") }}</button>
|
||||
<button v-if="supportsPeekMessages" @click.stop="openPeekDialog(sub)" class="btn-sm">{{ t("mqSubscriptions.peek") }}</button>
|
||||
<button v-if="supportsExpireMessages !== false" @click.stop="openExpireDialog(sub)" :disabled="readOnly" class="btn-sm">{{ t("mqSubscriptions.expireMessages") }}</button>
|
||||
<button @click.stop="handleDelete(sub)" :disabled="readOnly" class="btn-sm btn-danger">{{ t("mqSubscriptions.delete") }}</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
@@ -335,36 +337,36 @@ watch(
|
||||
<div v-if="showCreateDialog" class="dialog-overlay" @click="showCreateDialog = false">
|
||||
<div class="dialog" @click.stop>
|
||||
<div class="dialog-header">
|
||||
<h3>创建订阅</h3>
|
||||
<h3>{{ t("mqSubscriptions.createDialogTitle") }}</h3>
|
||||
<button @click="showCreateDialog = false" class="btn-close">×</button>
|
||||
</div>
|
||||
<div class="dialog-body">
|
||||
<div class="form-group">
|
||||
<label>主题</label>
|
||||
<label>{{ t("mqSubscriptions.topic") }}</label>
|
||||
<input type="text" :value="topic?.shortName" disabled />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>订阅名称*</label>
|
||||
<input v-model="formData.subName" type="text" placeholder="例如: my-subscription" :disabled="readOnly" />
|
||||
<label>{{ t("mqSubscriptions.subscriptionNameLabel") }}</label>
|
||||
<input v-model="formData.subName" type="text" :placeholder="t('mqSubscriptions.subscriptionNamePlaceholder')" :disabled="readOnly" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>起始位置</label>
|
||||
<label>{{ t("mqSubscriptions.startPosition") }}</label>
|
||||
<div class="radio-group">
|
||||
<label class="radio-label">
|
||||
<input type="radio" v-model="formData.startFrom" value="earliest" :disabled="readOnly" />
|
||||
从最早消息开始(Earliest)
|
||||
{{ t("mqSubscriptions.startFromEarliest") }}
|
||||
</label>
|
||||
<label class="radio-label">
|
||||
<input type="radio" v-model="formData.startFrom" value="latest" :disabled="readOnly" />
|
||||
从最新消息开始(Latest)
|
||||
{{ t("mqSubscriptions.startFromLatest") }}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="error" class="form-error">{{ error }}</div>
|
||||
</div>
|
||||
<div class="dialog-footer">
|
||||
<button @click="showCreateDialog = false" class="btn-secondary">取消</button>
|
||||
<button @click="handleCreate" :disabled="loading || readOnly" class="btn-primary">创建</button>
|
||||
<button @click="showCreateDialog = false" class="btn-secondary">{{ t("mqSubscriptions.cancel") }}</button>
|
||||
<button @click="handleCreate" :disabled="loading || readOnly" class="btn-primary">{{ t("mqSubscriptions.create") }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -373,37 +375,37 @@ watch(
|
||||
<div v-if="showResetDialog" class="dialog-overlay" @click="showResetDialog = false">
|
||||
<div class="dialog" @click.stop>
|
||||
<div class="dialog-header">
|
||||
<h3>重置游标: {{ selectedSub?.name }}</h3>
|
||||
<h3>{{ t("mqSubscriptions.resetDialogTitle", { name: selectedSub?.name }) }}</h3>
|
||||
<button @click="showResetDialog = false" class="btn-close">×</button>
|
||||
</div>
|
||||
<div class="dialog-body">
|
||||
<div class="form-group">
|
||||
<label>重置到</label>
|
||||
<label>{{ t("mqSubscriptions.resetTo") }}</label>
|
||||
<div class="radio-group">
|
||||
<label class="radio-label">
|
||||
<input type="radio" v-model="resetFormData.position" value="earliest" :disabled="readOnly" />
|
||||
最早消息(Earliest)
|
||||
{{ t("mqSubscriptions.earliest") }}
|
||||
</label>
|
||||
<label class="radio-label">
|
||||
<input type="radio" v-model="resetFormData.position" value="latest" :disabled="readOnly" />
|
||||
最新消息(Latest)
|
||||
{{ t("mqSubscriptions.latest") }}
|
||||
</label>
|
||||
<label class="radio-label">
|
||||
<input type="radio" v-model="resetFormData.position" value="timestamp" :disabled="readOnly" />
|
||||
指定时间戳
|
||||
{{ t("mqSubscriptions.timestamp") }}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="resetFormData.position === 'timestamp'" class="form-group">
|
||||
<label>时间戳(毫秒)</label>
|
||||
<label>{{ t("mqSubscriptions.timestampMs") }}</label>
|
||||
<input v-model.number="resetFormData.timestampMs" type="number" :disabled="readOnly" />
|
||||
<div class="form-hint">当前时间: {{ new Date(resetFormData.timestampMs).toLocaleString() }}</div>
|
||||
<div class="form-hint">{{ t("mqSubscriptions.currentTime", { time: new Date(resetFormData.timestampMs).toLocaleString() }) }}</div>
|
||||
</div>
|
||||
<div v-if="error" class="form-error">{{ error }}</div>
|
||||
</div>
|
||||
<div class="dialog-footer">
|
||||
<button @click="showResetDialog = false" class="btn-secondary">取消</button>
|
||||
<button @click="handleResetCursor" :disabled="loading || readOnly" class="btn-primary">重置</button>
|
||||
<button @click="showResetDialog = false" class="btn-secondary">{{ t("mqSubscriptions.cancel") }}</button>
|
||||
<button @click="handleResetCursor" :disabled="loading || readOnly" class="btn-primary">{{ t("mqSubscriptions.reset") }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -412,32 +414,32 @@ watch(
|
||||
<div v-if="showSkipDialog" class="dialog-overlay" @click="showSkipDialog = false">
|
||||
<div class="dialog" @click.stop>
|
||||
<div class="dialog-header">
|
||||
<h3>跳过消息: {{ selectedSub?.name }}</h3>
|
||||
<h3>{{ t("mqSubscriptions.skipDialogTitle", { name: selectedSub?.name }) }}</h3>
|
||||
<button @click="showSkipDialog = false" class="btn-close">×</button>
|
||||
</div>
|
||||
<div class="dialog-body">
|
||||
<div class="form-group">
|
||||
<label>跳过模式</label>
|
||||
<label>{{ t("mqSubscriptions.skipMode") }}</label>
|
||||
<div class="radio-group">
|
||||
<label class="radio-label">
|
||||
<input type="radio" v-model="skipFormData.mode" value="count" :disabled="readOnly" />
|
||||
跳过指定数量
|
||||
{{ t("mqSubscriptions.skipCount") }}
|
||||
</label>
|
||||
<label class="radio-label">
|
||||
<input type="radio" v-model="skipFormData.mode" value="all" :disabled="readOnly" />
|
||||
跳过全部积压
|
||||
{{ t("mqSubscriptions.skipAll") }}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="skipFormData.mode === 'count'" class="form-group">
|
||||
<label>跳过数量</label>
|
||||
<label>{{ t("mqSubscriptions.skipCountLabel") }}</label>
|
||||
<input v-model.number="skipFormData.count" type="number" min="1" :disabled="readOnly" />
|
||||
</div>
|
||||
<div v-if="error" class="form-error">{{ error }}</div>
|
||||
</div>
|
||||
<div class="dialog-footer">
|
||||
<button @click="showSkipDialog = false" class="btn-secondary">取消</button>
|
||||
<button @click="handleSkipMessages" :disabled="loading || readOnly" class="btn-primary">跳过</button>
|
||||
<button @click="showSkipDialog = false" class="btn-secondary">{{ t("mqSubscriptions.cancel") }}</button>
|
||||
<button @click="handleSkipMessages" :disabled="loading || readOnly" class="btn-primary">{{ t("mqSubscriptions.skip") }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -446,28 +448,28 @@ watch(
|
||||
<div v-if="showPeekDialog" class="dialog-overlay" @click="showPeekDialog = false">
|
||||
<div class="dialog dialog-wide" @click.stop>
|
||||
<div class="dialog-header">
|
||||
<h3>Peek 消息: {{ selectedSub?.name }}</h3>
|
||||
<h3>{{ t("mqSubscriptions.peekDialogTitle", { name: selectedSub?.name }) }}</h3>
|
||||
<button @click="showPeekDialog = false" class="btn-close">×</button>
|
||||
</div>
|
||||
<div class="dialog-body">
|
||||
<div class="peek-toolbar">
|
||||
<label>
|
||||
数量
|
||||
{{ t("mqSubscriptions.count") }}
|
||||
<input v-model.number="peekCount" type="number" min="1" max="100" />
|
||||
</label>
|
||||
<button @click="handlePeekMessages" :disabled="peekLoading" class="btn-sm">
|
||||
{{ peekLoading ? "加载中..." : "刷新" }}
|
||||
{{ peekLoading ? t("mqSubscriptions.loading") : t("mqSubscriptions.refresh") }}
|
||||
</button>
|
||||
</div>
|
||||
<div v-if="error" class="form-error">{{ error }}</div>
|
||||
<div v-else-if="peekLoading && !peekedMessages.length" class="panel-loading">加载中...</div>
|
||||
<div v-else-if="!peekedMessages.length" class="panel-placeholder">没有可查看的消息</div>
|
||||
<div v-else-if="peekLoading && !peekedMessages.length" class="panel-loading">{{ t("mqSubscriptions.loading") }}</div>
|
||||
<div v-else-if="!peekedMessages.length" class="panel-placeholder">{{ t("mqSubscriptions.noPeekMessages") }}</div>
|
||||
<div v-else class="peek-results">
|
||||
<div v-for="message in peekedMessages" :key="message.position" class="peek-message">
|
||||
<div class="peek-message-header">
|
||||
<span>#{{ message.position }}</span>
|
||||
<span v-if="message.messageId">{{ message.messageId }}</span>
|
||||
<span v-if="message.key">key={{ message.key }}</span>
|
||||
<span v-if="message.key">{{ t("mqSubscriptions.peekMessageKey", { key: message.key }) }}</span>
|
||||
</div>
|
||||
<div v-if="Object.keys(message.properties).length" class="peek-properties">
|
||||
<span v-for="(value, key) in message.properties" :key="key">{{ key }}={{ value }}</span>
|
||||
@@ -477,7 +479,7 @@ watch(
|
||||
</div>
|
||||
</div>
|
||||
<div class="dialog-footer">
|
||||
<button @click="showPeekDialog = false" class="btn-secondary">关闭</button>
|
||||
<button @click="showPeekDialog = false" class="btn-secondary">{{ t("mqSubscriptions.close") }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -486,20 +488,20 @@ watch(
|
||||
<div v-if="showExpireDialog" class="dialog-overlay" @click="showExpireDialog = false">
|
||||
<div class="dialog" @click.stop>
|
||||
<div class="dialog-header">
|
||||
<h3>过期消息: {{ selectedSub?.name }}</h3>
|
||||
<h3>{{ t("mqSubscriptions.expireDialogTitle", { name: selectedSub?.name }) }}</h3>
|
||||
<button @click="showExpireDialog = false" class="btn-close">×</button>
|
||||
</div>
|
||||
<div class="dialog-body">
|
||||
<div class="form-group">
|
||||
<label>过期时间(秒)</label>
|
||||
<label>{{ t("mqSubscriptions.expireSeconds") }}</label>
|
||||
<input v-model.number="expireSeconds" type="number" min="1" :disabled="readOnly" />
|
||||
<div class="form-hint">将删除所有早于 {{ expireSeconds }} 秒的消息</div>
|
||||
<div class="form-hint">{{ t("mqSubscriptions.expireHint", { seconds: expireSeconds }) }}</div>
|
||||
</div>
|
||||
<div v-if="error" class="form-error">{{ error }}</div>
|
||||
</div>
|
||||
<div class="dialog-footer">
|
||||
<button @click="showExpireDialog = false" class="btn-secondary">取消</button>
|
||||
<button @click="handleExpireMessages" :disabled="loading || readOnly" class="btn-primary">过期</button>
|
||||
<button @click="showExpireDialog = false" class="btn-secondary">{{ t("mqSubscriptions.cancel") }}</button>
|
||||
<button @click="handleExpireMessages" :disabled="loading || readOnly" class="btn-primary">{{ t("mqSubscriptions.expire") }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user