摄像头列表:双击名称就地改名
- 名称列双击变成 input(自动聚焦并全选旧名),回车或失焦提交,Esc 取消 - 提交走 PUT /api/web/cameras/:id(只带 name),成功后只更新当前行,不整表重载 (避免丢失分页/滚动位置),并提示「已改名:xxx」 - 名称去空格后不得为空,为空时提示「摄像头名称不能为空」并放弃本次编辑 - 工具栏提示补上「双击名称可直接改名」,名称列光标为 text、悬停提示可改名 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
46c7d4f359
commit
52907b66b7
@ -4,7 +4,8 @@
|
|||||||
*
|
*
|
||||||
* 摄像头只能在 NVR 页「拉取通道 → 勾选导入」产生;这里负责查看 / 改名 / 启停 / 删除。
|
* 摄像头只能在 NVR 页「拉取通道 → 勾选导入」产生;这里负责查看 / 改名 / 启停 / 删除。
|
||||||
*/
|
*/
|
||||||
import { computed, onBeforeUnmount, onMounted, reactive, ref } from 'vue';
|
import { computed, nextTick, onBeforeUnmount, onMounted, reactive, ref } from 'vue';
|
||||||
|
import type { ComponentPublicInstance } from 'vue';
|
||||||
import AppLayout from '@/components/AppLayout.vue';
|
import AppLayout from '@/components/AppLayout.vue';
|
||||||
import DataPager from '@/components/DataPager.vue';
|
import DataPager from '@/components/DataPager.vue';
|
||||||
import ModalBox from '@/components/ModalBox.vue';
|
import ModalBox from '@/components/ModalBox.vue';
|
||||||
@ -156,6 +157,68 @@ async function toggleStatus(camera: Camera) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------- 列表内双击改名 ----------------
|
||||||
|
/** 正在改名的摄像头 id(null = 没有在改名) */
|
||||||
|
const inlineId = ref<number | null>(null);
|
||||||
|
const inlineName = ref('');
|
||||||
|
const inlineSaving = ref(false);
|
||||||
|
const inlineInput = ref<HTMLInputElement | null>(null);
|
||||||
|
|
||||||
|
/** v-for 里的 ref 会变成数组,这里用函数 ref 只留当前那个 input */
|
||||||
|
function bindInlineInput(el: Element | ComponentPublicInstance | null) {
|
||||||
|
inlineInput.value = el instanceof HTMLInputElement ? el : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function startRename(camera: Camera) {
|
||||||
|
if (inlineSaving.value) return;
|
||||||
|
inlineId.value = camera.id;
|
||||||
|
inlineName.value = camera.name || '';
|
||||||
|
void nextTick(() => {
|
||||||
|
inlineInput.value?.focus();
|
||||||
|
inlineInput.value?.select();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function cancelRename() {
|
||||||
|
if (inlineSaving.value) return;
|
||||||
|
inlineId.value = null;
|
||||||
|
inlineName.value = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 提交改名:回车 / 失焦都走这里;名称没变或为空就只是取消 */
|
||||||
|
async function commitRename(camera: Camera) {
|
||||||
|
if (inlineId.value !== camera.id || inlineSaving.value) return;
|
||||||
|
|
||||||
|
const next = inlineName.value.trim();
|
||||||
|
const previous = (camera.name || '').trim();
|
||||||
|
|
||||||
|
if (!next) {
|
||||||
|
error.value = '摄像头名称不能为空';
|
||||||
|
cancelRename();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (next === previous) {
|
||||||
|
cancelRename();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
inlineSaving.value = true;
|
||||||
|
error.value = '';
|
||||||
|
okMsg.value = '';
|
||||||
|
try {
|
||||||
|
await updateCamera(camera.id, { name: next });
|
||||||
|
// 就地更新,避免为了一个名字整表重载(会丢滚动位置和当前页)
|
||||||
|
camera.name = next;
|
||||||
|
okMsg.value = `已改名:${next}`;
|
||||||
|
inlineId.value = null;
|
||||||
|
inlineName.value = '';
|
||||||
|
} catch (err) {
|
||||||
|
error.value = err instanceof ApiError ? err.message : '改名失败';
|
||||||
|
} finally {
|
||||||
|
inlineSaving.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 页面关闭/刷新/切走时释放预览
|
* 页面关闭/刷新/切走时释放预览
|
||||||
*
|
*
|
||||||
@ -561,7 +624,7 @@ async function doPreset(action: 'set' | 'goto' | 'clear') {
|
|||||||
<button class="btn btn-danger" :disabled="!selectedIds.size" @click="doBatchDelete">
|
<button class="btn btn-danger" :disabled="!selectedIds.size" @click="doBatchDelete">
|
||||||
批量删除{{ selectedIds.size ? `(${selectedIds.size})` : '' }}
|
批量删除{{ selectedIds.size ? `(${selectedIds.size})` : '' }}
|
||||||
</button>
|
</button>
|
||||||
<span class="hint">新增请到「NVR 录像机 → 拉取通道」</span>
|
<span class="hint">新增请到「NVR 录像机 → 拉取通道」;双击名称可直接改名</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="table-wrap">
|
<div class="table-wrap">
|
||||||
@ -586,8 +649,18 @@ async function doPreset(action: 'set' | 'goto' | 'clear') {
|
|||||||
<td>
|
<td>
|
||||||
<input type="checkbox" :checked="selectedIds.has(camera.id)" @change="toggleOne(camera.id)" />
|
<input type="checkbox" :checked="selectedIds.has(camera.id)" @change="toggleOne(camera.id)" />
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td class="name-cell" :title="inlineId === camera.id ? '' : '双击可改名'" @dblclick="startRename(camera)">
|
||||||
{{ camera.name || '—' }}
|
<input v-if="inlineId === camera.id"
|
||||||
|
:ref="bindInlineInput"
|
||||||
|
v-model="inlineName"
|
||||||
|
class="inline-name-input"
|
||||||
|
:disabled="inlineSaving"
|
||||||
|
maxlength="64"
|
||||||
|
placeholder="输入名称后回车"
|
||||||
|
@keyup.enter="commitRename(camera)"
|
||||||
|
@keyup.esc="cancelRename"
|
||||||
|
@blur="commitRename(camera)" />
|
||||||
|
<span v-else :class="{ muted: !camera.name }">{{ camera.name || '—' }}</span>
|
||||||
</td>
|
</td>
|
||||||
<td :class="{ muted: !camera.channelName }">{{ camera.channelName || '未命名' }}</td>
|
<td :class="{ muted: !camera.channelName }">{{ camera.channelName || '未命名' }}</td>
|
||||||
<td>{{ camera.nvr ? (camera.nvr.name || camera.nvr.host) : '—' }}</td>
|
<td>{{ camera.nvr ? (camera.nvr.name || camera.nvr.host) : '—' }}</td>
|
||||||
@ -781,6 +854,24 @@ async function doPreset(action: 'set' | 'goto' | 'clear') {
|
|||||||
color: #cbd5e1;
|
color: #cbd5e1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 列表内改名:名称列双击变成输入框(同一行的 td 高度稳定,不跳动) */
|
||||||
|
.name-cell {
|
||||||
|
cursor: text;
|
||||||
|
min-width: 140px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.inline-name-input {
|
||||||
|
width: 100%;
|
||||||
|
min-width: 120px;
|
||||||
|
padding: 3px 6px;
|
||||||
|
font-size: 13px;
|
||||||
|
line-height: 1.4;
|
||||||
|
border: 1px solid #2563eb;
|
||||||
|
border-radius: 4px;
|
||||||
|
outline: none;
|
||||||
|
box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
|
||||||
|
}
|
||||||
|
|
||||||
.preview-head {
|
.preview-head {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: baseline;
|
align-items: baseline;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user