<script setup lang="ts">
/**
* MySqlDataCard:治ç†é¡µã€Œä¸é—´ä»¶ã€é¡µç¾â€”—MySQL æ•°æ®åŒºå—(CARD-MW-01ï¼Œå½¢æ€ 1 区å—å¡ï¼‰ã€‚
* 纯 UI:状æ€ï¼ˆrows/loading/error/total/page/filter/nodesï¼‰ç”±å®¹å™¨æŒæœ‰ï¼›åªå‘ filterChange/pageChange/retry。
* 12 列:编å·ï¼ˆé›ªèб Id)/ MySQL èŠ‚ç‚¹ï¼ˆå€™é€‰æ˜ å°„ï¼Œç¼ºã€Œâ€”ã€ï¼‰/ åç§° / å¯åŠ¨æ—¶é•¿ / 连接数(x / y)/
* QPS / TPS / æµé‡ï¼ˆæ”¶ / å‘)/ InnoDB ç¼“å†²æ± / 命ä¸çއ / 慢查询 / 线程(总 / 活跃)。
* åªè¯»æµè§ˆï¼ˆC02ï¼‰ï¼šæ— æ–°å¢ž/编辑/åˆ é™¤æŒ‰é’®ï¼›å¯¼å‡ºä¸åœ¨æ¤å¡ï¼ˆå®šç¨¿è£å®šï¼‰ã€‚
* 三æ€ï¼šåŠ è½½ã€ŒMySQL æ•°æ®åŠ è½½ä¸â€¦ã€/ 失败「MySQL æ•°æ®åŠ è½½å¤±è´¥ï¼š{åŽŸå› }ã€+é‡è¯• /
* ç©ºã€Œæš‚æ— MySQL é‡‡æ ·æ•°æ®ã€â€”—本地库常æ€å³ç©ºï¼ˆB1 一ç‰å…¬æ°‘),引导è¯=ç‰èŠ‚ç‚¹ä¸ŠæŠ¥ã€‚
* ç›é€‰æ¡ï¼ˆC01-C04):节点下拉 / æ—¶é—´åŒºé—´ï¼ˆæ³¨è®°ã€ŒæŒ‰é‡‡æ ·æ—¶é—´è¿‡æ»¤ã€ï¼‰/ å称关键å—ï¼›@change 峿Ÿ¥ï¼Œæ— ã€ŒæŸ¥è¯¢ã€æŒ‰é’®ã€‚
* 分页:æœåŠ¡ç«¯åˆ†é¡µï¼ˆpageIndex 从 0),上一页/下一页 + 页ç ï¼›total<=pageSize 时整行éšè—。
*/
import { computed } from 'vue';
import Btn from './Btn.vue';
import Card from './Card.vue';
import { H3, SELECT, TD, TH } from './deployView.styles.ts';
import { mysqlDataTotalPages, type MySqlDataRow, type MySqlNodeOption } from './middleware.logic.ts';
const props = withDefaults(
defineProps<{
rows: MySqlDataRow[];
loading?: boolean;
error?: string;
total?: number;
/** 当å‰é¡µï¼Œä»Ž 0 èµ· */
page?: number;
pageSize?: number;
/** 节点候选(ç›é€‰æ¡æ•°æ®æºï¼‰ï¼Œæ¥è‡ª fetchMySqlNodes */
nodes?: MySqlNodeOption[];
}>(),
{ loading: false, error: '', total: 0, page: 0, pageSize: 20, nodes: () => [] },
);
const emit = defineEmits<{
/** ç›é€‰å˜åŒ–ï¼ˆéƒ¨åˆ†è¡¥ï¼Œå®¹å™¨æŒæœ‰ filter å¹¶é‡å–,pageIndex 归零) */
filterChange: [patch: { mysqlId?: number; dtStart?: string; dtEnd?: string; q?: string }];
/** 翻页(容器改 pageIndex åŽé‡å–) */
pageChange: [pageIndex: number];
/** 失败æ€é‡è¯•(容器é‡å–æ•°æ®æŽ¥å£ï¼‰ */
retry: [];
}>();
const totalPages = computed(() => mysqlDataTotalPages(props.total, props.pageSize));
const hasPager = computed(() => props.total > props.pageSize && !props.loading && !props.error);
function onNode(e: Event): void {
emit('filterChange', { mysqlId: Number((e.target as HTMLSelectElement).value) || 0 });
}
function onDtStart(e: Event): void {
emit('filterChange', { dtStart: (e.target as HTMLInputElement).value });
}
function onDtEnd(e: Event): void {
emit('filterChange', { dtEnd: (e.target as HTMLInputElement).value });
}
function onQ(e: Event): void {
emit('filterChange', { q: (e.target as HTMLInputElement).value.trim() });
}
</script>
<template>
<Card
padding="none"
data-spec="mw-mysql-data"
>
<div class="flex flex-wrap items-center gap-2 px-[14px] pt-[12px]">
<h3 :class="H3">
MySQL æ•°æ®
<span class="text-[11.5px] font-normal text-[var(--el-text-color-secondary)]">å…± {{ total }} æ¡</span>
</h3>
</div>
<!-- ç›é€‰æ¡ï¼šåŠ è½½/失败æ€ä¸æ˜¾ç¤º -->
<div
v-if="!loading && !error"
class="mb-[10px] mt-[8px] flex flex-wrap items-center gap-2 px-[14px]"
data-spec="mw-mysql-data-filter"
>
<span class="text-[11.5px] text-[var(--el-text-color-secondary)]">节点</span>
<select
:class="SELECT"
aria-label="按 MySQL 节点ç›é€‰"
data-spec="mw-mysql-data-filter-node"
@change="onNode"
>
<option value="">
全部节点
</option>
<option
v-for="n in nodes"
:key="n.id"
:value="n.id"
>
{{ n.name }}
</option>
</select>
<span class="text-[11.5px] text-[var(--el-text-color-secondary)]">æ—¶é—´</span>
<input
type="date"
:class="SELECT"
aria-label="开始日期"
data-spec="mw-mysql-data-filter-dtstart"
@change="onDtStart"
>
<span class="text-[11.5px] text-[var(--el-text-color-secondary)]">~</span>
<input
type="date"
:class="SELECT"
aria-label="ç»“æŸæ—¥æœŸ"
data-spec="mw-mysql-data-filter-dtend"
@change="onDtEnd"
>
<span
class="text-[11px] text-[var(--el-text-color-secondary)]"
data-spec="mw-mysql-data-filter-time-note"
>æŒ‰é‡‡æ ·æ—¶é—´è¿‡æ»¤</span>
<span class="text-[11.5px] text-[var(--el-text-color-secondary)]">关键å—</span>
<input
type="text"
placeholder="åç§°"
:class="SELECT"
aria-label="按å称关键å—ç›é€‰"
data-spec="mw-mysql-data-filter-q"
@change="onQ"
>
</div>
<div
v-if="loading"
data-spec="mw-mysql-data-loading"
class="flex items-center gap-[8px] px-[14px] py-[18px] text-[12.5px] text-[var(--el-text-color-secondary)]"
>
<span class="inline-block h-[14px] w-[14px] animate-spin rounded-full border-2 border-[var(--el-border-color)] border-t-[var(--el-color-primary)]" />
MySQL æ•°æ®åŠ è½½ä¸â€¦
</div>
<div
v-else-if="error"
data-spec="mw-mysql-data-failed"
class="px-[14px] py-[14px]"
>
<div class="text-[12.5px] text-[var(--el-color-danger)]">
MySQL æ•°æ®åŠ è½½å¤±è´¥ï¼š{{ error }}
</div>
<button
type="button"
data-spec="mw-mysql-data-retry"
class="mt-[8px] cursor-pointer rounded-[6px] border border-[var(--el-border-color-light)] px-[10px] py-[4px] text-[12px] text-[var(--el-text-color-regular)] hover:bg-[var(--el-bg-color-overlay)]"
@click="emit('retry')"
>
é‡è¯•
</button>
</div>
<table
v-else
class="w-full border-collapse"
>
<thead>
<tr>
<th :class="TH">
ç¼–å·
</th>
<th :class="TH">
MySQL 节点
</th>
<th :class="TH">
åç§°
</th>
<th :class="[TH, 'text-right']">
å¯åŠ¨æ—¶é•¿
</th>
<th :class="[TH, 'text-right']">
连接数
</th>
<th :class="[TH, 'text-right']">
QPS
</th>
<th :class="[TH, 'text-right']">
TPS
</th>
<th :class="[TH, 'text-right']">
æµé‡
</th>
<th :class="[TH, 'text-right']">
InnoDB 缓冲æ±
</th>
<th :class="[TH, 'text-right']">
命ä¸çއ
</th>
<th :class="[TH, 'text-right']">
慢查询
</th>
<th :class="[TH, 'text-right']">
线程
</th>
</tr>
</thead>
<tbody class="group">
<tr
v-for="r in rows"
:key="r.id"
data-spec="mw-mysql-data-row"
class="hover:bg-[var(--el-bg-color-overlay)]"
>
<td :class="TD">
<span
class="font-mono text-[12px] text-[var(--el-text-color-secondary)]"
:title="r.id"
>{{ r.id }}</span>
</td>
<td :class="TD">
<span
v-if="r.nodeName || r.mysqlId > 0"
class="text-[12.5px] text-[var(--el-text-color-primary)]"
>{{ r.nodeName || `#${r.mysqlId}` }}</span>
<span
v-else
class="text-[12.5px] text-[var(--el-text-color-secondary)]"
>—</span>
</td>
<td :class="TD">
<div class="text-[12.5px] font-medium text-[var(--el-text-color-primary)]">
{{ r.name || '—' }}
</div>
</td>
<td :class="[TD, 'text-right']">
<span class="text-[12.5px] text-[var(--el-text-color-primary)]">{{ r.uptime }}</span>
</td>
<td :class="[TD, 'text-right']">
<span class="text-[12.5px] text-[var(--el-text-color-primary)]">{{ r.connections }} / {{ r.maxConnections }}</span>
</td>
<td :class="[TD, 'text-right']">
<span class="text-[12.5px] text-[var(--el-text-color-primary)]">{{ r.qps }}</span>
</td>
<td :class="[TD, 'text-right']">
<span class="text-[12.5px] text-[var(--el-text-color-primary)]">{{ r.tps }}</span>
</td>
<td :class="[TD, 'text-right']">
<span class="text-[12px] text-[var(--el-text-color-primary)]">{{ r.bytesIn }} / {{ r.bytesOut }}</span>
</td>
<td :class="[TD, 'text-right']">
<span class="text-[12px] text-[var(--el-text-color-primary)]">{{ r.bufferPool }}</span>
</td>
<td :class="[TD, 'text-right']">
<span class="text-[12.5px] text-[var(--el-text-color-primary)]">{{ r.hitRate }}</span>
</td>
<td :class="[TD, 'text-right']">
<span class="text-[12.5px] text-[var(--el-text-color-primary)]">{{ r.slowQueries }}</span>
</td>
<td :class="[TD, 'text-right']">
<span class="text-[12.5px] text-[var(--el-text-color-primary)]">{{ r.threads }} / {{ r.threadsRunning }}</span>
</td>
</tr>
<tr v-if="!rows.length">
<td
colspan="12"
data-spec="mw-mysql-data-empty"
class="px-[14px] py-[18px] text-center text-[12.5px] text-[var(--el-text-color-secondary)]"
>
<div>æš‚æ— MySQL é‡‡æ ·æ•°æ®</div>
<div class="mt-[4px] text-[11.5px]">
MySQL 节点接入采集åŽï¼Œçжæ€é‡‡æ ·ä¼šåœ¨è¿™é‡Œå±•示
</div>
</td>
</tr>
</tbody>
</table>
<!-- 分页:仅æœåŠ¡ç«¯æœ‰æ›´å¤šæ•°æ®æ—¶æ˜¾ç¤º -->
<div
v-if="hasPager"
class="flex items-center justify-end gap-[10px] px-[14px] pb-[12px] pt-[6px]"
data-spec="mw-mysql-data-pager"
>
<span
class="text-[11.5px] text-[var(--el-text-color-secondary)]"
data-spec="mw-mysql-data-page"
>第 {{ page + 1 }} / {{ totalPages }} 页</span>
<Btn
size="sm"
variant="default"
:disabled="page <= 0"
data-spec="mw-mysql-data-prev"
@click="emit('pageChange', page - 1)"
>
上一页
</Btn>
<Btn
size="sm"
variant="default"
:disabled="page + 1 >= totalPages"
data-spec="mw-mysql-data-next"
@click="emit('pageChange', page + 1)"
>
下一页
</Btn>
</div>
</Card>
</template>
|