<script setup lang="ts">
/**
* RedisNodeDrawer:Redis 节点新增/ç¼–è¾‘è¡¨å•æŠ½å±‰ï¼ˆCARD-MW-05,è£å®šâ‘£ CRUD å…¨é‡â€”â€”æ ‡å‡†å®žä½“æŽ¥å£å°±ç»ªï¼‰ã€‚
* 纯 UI:状æ€ï¼ˆmode/open/form/busy/failed/deletingï¼‰ç”±çˆ¶ç»„ä»¶æŒæœ‰ï¼›åªå‘ close/submit/delete。
* 分组(实体å¯ç¼–è¾‘å—æ®µé™¤ Id/审计列):基础 / ç›‘æŽ§ä¸Žå‘Šè¦ / 备注。
* æ ¡éªŒï¼šName 必填「åç§°ä¸èƒ½ä¸ºç©ºã€ï¼ˆvalidateRedisNodeForm;实体 Valid æ— å¼ºæ ¡éªŒï¼Œå‰ç«¯æœ€å°å¿…å¡«ï¼‰ï¼Œå†…è” role="alert"。
* Password:type=password 掩ç 回显(Detail 有值则显示å ä½ï¼ŒåŒ Cube 默认表å•),ä¿å˜éšæäº¤å…¨é‡ä¸Šé€ï¼›
* 与è¯ä¹¦ PfxPassword「留空=ä¸ä¿®æ”¹ã€ç‰¹ä¾‹ä¸åŒâ€”â€”èŠ‚ç‚¹å®žä½“æ— è¯¥å¥‘çº¦ï¼ˆå¦‚å®žå·®å¼‚ï¼Œå¤´æ³¨é‡Šï¼‰ã€‚
* åˆ é™¤ï¼ˆè£å®šâ‘£ï¼‰ï¼šä»…ç¼–è¾‘æ¨¡å¼æ˜¾ç¤ºã€Œåˆ 除ã€â€”—容器弹 GuardModal 确认åŽè°ƒ deleteRedisNodeï¼›
* æ–°å¢žæ¨¡å¼æ— åˆ é™¤ï¼ˆæ— Id å¯åˆ ï¼‰ã€‚åˆ é™¤å…¥å£æ”¾æŠ½å±‰å†…(行内已 4 按钮,é¿å…溢出;§10 è®°è£é‡ï¼‰ã€‚
* 分类:文本手输(GetCategoryList æ— WebApi 端点,列表èšåˆä»…够ç›é€‰ï¼›æŠ½å±‰è‡ªç”±è¾“å…¥=æ—§é¡µåŒæ¬¾ï¼‰ã€‚
*/
import { ref, watch } from 'vue';
import Drawer from './Drawer/Drawer.vue';
import Btn from './Btn.vue';
import { H3 } from './deployView.styles.ts';
import { validateRedisNodeForm, type RedisNodeForm } from './middleware.logic.ts';
const props = withDefaults(
defineProps<{
mode: 'create' | 'edit';
open: boolean;
form: RedisNodeForm | null;
busy?: boolean;
failed?: boolean;
/** åˆ é™¤è¿›è¡Œä¸ï¼ˆGuardModal 确认åŽå®¹å™¨æ‰§è¡Œï¼‰ */
deleting?: boolean;
}>(),
{ busy: false, failed: false, deleting: false },
);
const emit = defineEmits<{ close: []; submit: [RedisNodeForm]; delete: [] }>();
/** 本地编辑副本:父组件 form æ‰“å¼€åŽæµ…æ‹·è´ï¼ˆå—段全为原始类型),æäº¤æ—¶æ•´ä»½ä¸ŠæŠ› */
const local = ref<RedisNodeForm | null>(null);
watch(
() => [props.open, props.form] as const,
([open]) => {
local.value = open && props.form ? { ...props.form } : null;
},
{ immediate: true },
);
const errs = ref<{ name?: string }>({});
watch(local, () => {
errs.value = {};
});
const inputCls = 'h-[30px] rounded-[6px] border border-[var(--el-border-color)] bg-[var(--el-bg-color)] px-[8px] text-[12.5px] text-[var(--el-text-color-primary)]';
function onSubmit(): void {
if (!local.value || props.busy) return;
const e = validateRedisNodeForm(local.value);
errs.value = e;
if (e.name) return;
emit('submit', { ...local.value });
}
</script>
<template>
<Drawer
data-spec="mw-redis-node-drawer"
:open="open"
:title="mode === 'create' ? '新增节点' : '编辑节点'"
:sub="mode === 'create' ? '录入 Redis 节点连接信æ¯ï¼Œä¿å˜åŽç«‹å³å¯ç”¨' : 'ä¿®æ”¹èŠ‚ç‚¹è¿žæŽ¥ä¸Žç›‘æŽ§å‚æ•°ï¼Œä¿å˜åŽç«‹å³ç”Ÿæ•ˆ'"
@close="emit('close')"
>
<div
v-if="failed || !local"
data-spec="mw-redis-node-drawer-failed"
class="py-[24px] text-[12.5px] text-[var(--el-color-danger)]"
>
èŠ‚ç‚¹è¯¦æƒ…åŠ è½½å¤±è´¥ï¼Œè¯·å…³é—åŽé‡è¯•。
</div>
<div
v-else
class="flex flex-col gap-[16px] pb-[8px]"
>
<!-- ===== 基础 ===== -->
<section class="flex flex-col gap-[10px]">
<h4 :class="H3">
基础
</h4>
<label class="flex flex-col gap-[4px]">
<span class="text-[12px] text-[var(--el-text-color-secondary)]">åç§° Name <span class="text-[var(--el-color-danger)]">*</span></span>
<input
v-model="local.name"
data-spec="mw-redis-node-form-name"
type="text"
placeholder="主缓å˜"
:class="[inputCls, 'font-mono']"
>
<span
v-if="errs.name"
role="alert"
data-spec="mw-redis-node-form-name-error"
class="text-[11.5px] text-[var(--el-color-danger)]"
>{{ errs.name }}</span>
</label>
<div class="flex flex-wrap items-center gap-[14px]">
<label
data-spec="mw-redis-node-form-enable"
class="inline-flex cursor-pointer items-center gap-[6px] text-[12.5px] text-[var(--el-text-color-primary)]"
>
<input
v-model="local.enable"
type="checkbox"
class="h-[13px] w-[13px]"
>
å¯ç”¨è¯¥èŠ‚ç‚¹
</label>
<label
data-spec="mw-redis-node-form-scanqueue"
class="inline-flex cursor-pointer items-center gap-[6px] text-[12.5px] text-[var(--el-text-color-primary)]"
>
<input
v-model="local.scanQueue"
type="checkbox"
class="h-[13px] w-[13px]"
>
自动扫æå‘现消æ¯é˜Ÿåˆ—
</label>
</div>
<div class="flex flex-wrap gap-[10px]">
<label class="flex min-w-[160px] flex-1 flex-col gap-[4px]">
<span class="text-[12px] text-[var(--el-text-color-secondary)]">分类 Category</span>
<input
v-model="local.category"
data-spec="mw-redis-node-form-category"
type="text"
placeholder="缓å˜"
:class="inputCls"
>
</label>
<label class="flex min-w-[200px] flex-[2] flex-col gap-[4px]">
<span class="text-[12px] text-[var(--el-text-color-secondary)]">åœ°å€ Server</span>
<input
v-model="local.server"
data-spec="mw-redis-node-form-server"
type="text"
placeholder="127.0.0.1:6379"
:class="[inputCls, 'font-mono']"
>
</label>
</div>
<div class="flex flex-wrap gap-[10px]">
<label class="flex min-w-[140px] flex-1 flex-col gap-[4px]">
<span class="text-[12px] text-[var(--el-text-color-secondary)]">用户å UserName</span>
<input
v-model="local.userName"
data-spec="mw-redis-node-form-username"
type="text"
placeholder="default"
:class="[inputCls, 'font-mono']"
>
</label>
<label class="flex min-w-[140px] flex-1 flex-col gap-[4px]">
<span class="text-[12px] text-[var(--el-text-color-secondary)]">密ç Password</span>
<input
v-model="local.password"
data-spec="mw-redis-node-form-password"
type="password"
placeholder="••••••"
autocomplete="new-password"
:class="[inputCls, 'font-mono']"
>
</label>
</div>
<div class="flex flex-wrap gap-[10px]">
<label class="flex min-w-[120px] flex-1 flex-col gap-[4px]">
<span class="text-[12px] text-[var(--el-text-color-secondary)]">版本 Version</span>
<input
v-model="local.version"
data-spec="mw-redis-node-form-version"
type="text"
placeholder="7.2.4"
:class="inputCls"
>
</label>
<label class="flex min-w-[120px] flex-1 flex-col gap-[4px]">
<span class="text-[12px] text-[var(--el-text-color-secondary)]">æ¨¡å¼ Mode</span>
<input
v-model="local.mode"
data-spec="mw-redis-node-form-mode"
type="text"
placeholder="standalone"
:class="inputCls"
>
</label>
<label class="flex min-w-[120px] flex-1 flex-col gap-[4px]">
<span class="text-[12px] text-[var(--el-text-color-secondary)]">角色 Role</span>
<input
v-model="local.role"
data-spec="mw-redis-node-form-role"
type="text"
placeholder="master"
:class="inputCls"
>
</label>
</div>
</section>
<!-- ===== ç›‘æŽ§ä¸Žå‘Šè¦ ===== -->
<section class="flex flex-col gap-[10px]">
<h4 :class="H3">
监控与告è¦
</h4>
<div class="flex flex-wrap gap-[10px]">
<label class="flex min-w-[140px] flex-1 flex-col gap-[4px]">
<span class="text-[12px] text-[var(--el-text-color-secondary)]">最大内å˜ï¼ˆMB)</span>
<input
v-model.number="local.maxMemory"
data-spec="mw-redis-node-form-maxmemory"
type="number"
min="0"
:class="inputCls"
>
</label>
<label class="flex min-w-[140px] flex-1 flex-col gap-[4px]">
<span class="text-[12px] text-[var(--el-text-color-secondary)]">å†…å˜æ·˜æ±°ç–ç•¥</span>
<input
v-model="local.memoryPolicy"
data-spec="mw-redis-node-form-memorypolicy"
type="text"
placeholder="noeviction"
:class="inputCls"
>
</label>
<label class="flex min-w-[140px] flex-1 flex-col gap-[4px]">
<span class="text-[12px] text-[var(--el-text-color-secondary)]">内å˜åˆ†é…器</span>
<input
v-model="local.memoryAllocator"
data-spec="mw-redis-node-form-memoryallocator"
type="text"
placeholder="jemalloc"
:class="inputCls"
>
</label>
</div>
<div class="flex flex-wrap gap-[10px]">
<label class="flex min-w-[120px] flex-1 flex-col gap-[4px]">
<span class="text-[12px] text-[var(--el-text-color-secondary)]">内å˜å‘Šè¦ï¼ˆ%)</span>
<input
v-model.number="local.alarmMemoryRate"
data-spec="mw-redis-node-form-alarmmemoryrate"
type="number"
min="0"
max="100"
:class="inputCls"
>
</label>
<label class="flex min-w-[120px] flex-1 flex-col gap-[4px]">
<span class="text-[12px] text-[var(--el-text-color-secondary)]">连接数告è¦</span>
<input
v-model.number="local.alarmConnections"
data-spec="mw-redis-node-form-alarmconnections"
type="number"
min="0"
:class="inputCls"
>
</label>
<label class="flex min-w-[120px] flex-1 flex-col gap-[4px]">
<span class="text-[12px] text-[var(--el-text-color-secondary)]">速度告è¦</span>
<input
v-model.number="local.alarmSpeed"
data-spec="mw-redis-node-form-alarmspeed"
type="number"
min="0"
:class="inputCls"
>
</label>
<label class="flex min-w-[120px] flex-1 flex-col gap-[4px]">
<span class="text-[12px] text-[var(--el-text-color-secondary)]">å…¥æµé‡å‘Šè¦ï¼ˆKbps)</span>
<input
v-model.number="local.alarmInputKbps"
data-spec="mw-redis-node-form-alarminputkbps"
type="number"
min="0"
:class="inputCls"
>
</label>
<label class="flex min-w-[120px] flex-1 flex-col gap-[4px]">
<span class="text-[12px] text-[var(--el-text-color-secondary)]">出æµé‡å‘Šè¦ï¼ˆKbps)</span>
<input
v-model.number="local.alarmOutputKbps"
data-spec="mw-redis-node-form-alarmoutputkbps"
type="number"
min="0"
:class="inputCls"
>
</label>
</div>
<label class="flex flex-col gap-[4px]">
<span class="text-[12px] text-[var(--el-text-color-secondary)]">告è¦å›žè°ƒ WebHook</span>
<input
v-model="local.webHook"
data-spec="mw-redis-node-form-webhook"
type="text"
placeholder="https://"
:class="[inputCls, 'font-mono']"
>
</label>
</section>
<!-- ===== 备注 ===== -->
<section class="flex flex-col gap-[10px]">
<h4 :class="H3">
备注
</h4>
<textarea
v-model="local.remark"
data-spec="mw-redis-node-form-remark"
rows="2"
class="rounded-[6px] border border-[var(--el-border-color)] bg-[var(--el-bg-color)] px-[8px] py-[6px] text-[12.5px] text-[var(--el-text-color-primary)]"
/>
</section>
<!-- 底部æ“作(Drawer æ— footer slotï¼Œæ£æ–‡å°¾éƒ¨æ”¾ç½®â€”—MySqlNodeDrawer åŒæ¬¾ï¼‰ï¼›ç¼–辑模å¼åŠ åˆ é™¤ï¼ˆGuardModal 在容器) -->
<div class="flex items-center justify-between gap-2 border-t border-[var(--el-border-color-light)] pt-[12px]">
<Btn
v-if="mode === 'edit'"
variant="danger"
size="sm"
data-spec="mw-redis-node-delete"
:disabled="busy || deleting"
@click="emit('delete')"
>
{{ deleting ? 'åˆ é™¤ä¸â€¦' : 'åˆ é™¤' }}
</Btn>
<span
v-else
class="flex-1"
/>
<div class="flex gap-2">
<Btn
variant="ghost"
data-spec="mw-redis-node-cancel"
@click="emit('close')"
>
å–æ¶ˆ
</Btn>
<Btn
variant="primary"
data-spec="mw-redis-node-save"
:disabled="busy"
@click="onSubmit"
>
{{ busy ? 'ä¿å˜ä¸â€¦' : 'ä¿å˜' }}
</Btn>
</div>
</div>
</div>
</Drawer>
</template>
|