- Adjusted button sizes in CameraPreviewDialog and OperationCellRenderer for uniformity. - Enhanced the layout and structure of ServerFormDialog and sign dialog to improve user experience. - Implemented a new task panel design for better alignment and readability in various dialogs. - Added computed properties for dynamic subtitles and footers in the sign dialog. - Replaced ElMessageBox.prompt with a custom rename remark dialog for better styling consistency.
512 lines
20 KiB
Vue
512 lines
20 KiB
Vue
<!--
|
||
╔══════════════════════════════════════════════════════════════╗
|
||
║ 录像服务器管理 — 基于 newcamara 页面模板 v2 架构 ║
|
||
╚══════════════════════════════════════════════════════════════╝
|
||
-->
|
||
<template>
|
||
<div class="page-wrapper" :style="{ height: containerHeight }">
|
||
<!-- ===== 多标签模式:显示顶部标签栏 ===== -->
|
||
<template v-if="PAGE_CONFIG.showTabArea && !PAGE_CONFIG.singlePage">
|
||
<div class="tab-section">
|
||
<TabArea
|
||
:tabs="tabList"
|
||
:default-active="activeTabName"
|
||
@tab-change="handleTabChange"
|
||
/>
|
||
</div>
|
||
</template>
|
||
|
||
<!-- ===== 主内容区 ===== -->
|
||
<div class="order-sub-container">
|
||
<!-- 左侧:ScanBox 筛选面板 -->
|
||
<ScanBox
|
||
ref="scanBoxRef"
|
||
:cache-key="currentScanBoxCacheKey"
|
||
width="220px"
|
||
:tree-props="{ children: 'children', label: 'label' }"
|
||
:auto-submit="false"
|
||
:preset-tree="presetTree"
|
||
:available-fields="currentScanBoxFields"
|
||
@condition-change="handleConditionChange"
|
||
@reset="handleConditionReset"
|
||
@condition-clear="handleConditionClear"
|
||
/>
|
||
|
||
<!-- 右侧:内容区 -->
|
||
<div class="main-content">
|
||
<transition name="tab-fade" mode="out-in">
|
||
<div :key="activeTabName" class="tab-content-inner">
|
||
<!-- 工具栏按钮组 -->
|
||
<div class="toolbar">
|
||
<div class="toolbar-left">
|
||
<OrderToolbarButtonGroup
|
||
:buttons="currentToolbarButtons"
|
||
:resolve-disabled="resolveButtonDisabled"
|
||
:resolve-loading="resolveButtonLoading"
|
||
:resolve-label="resolveButtonLabel"
|
||
:layout-key="toolbarLayoutKey"
|
||
@action="handleToolbarButtonClick"
|
||
/>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 表格占满全高 -->
|
||
<div class="upper-wrapper upper-wrapper--full">
|
||
<UpperTable
|
||
ref="upperTableRef"
|
||
:title="currentTabConfig?.upperTable.title ?? '列表'"
|
||
default-align="center"
|
||
:enable-column-config="currentTabConfig?.upperTable.enableColumnConfig ?? true"
|
||
:column-config-schema-version="1"
|
||
:table-id="`server-table-${activeTabName}`"
|
||
:data="listData"
|
||
:row-key="'id'"
|
||
:columns="currentColumns"
|
||
table-size="small"
|
||
:pagination="pagination"
|
||
:show-index="currentTabConfig?.upperTable.showIndex ?? true"
|
||
:show-selection="currentTabConfig?.upperTable.showSelection ?? false"
|
||
:loading="loading"
|
||
:query-time="queryTime"
|
||
@current-change="handleRowClick"
|
||
@row-click="handleRowClick"
|
||
@page-change="handlePageChange"
|
||
@page-size-change="handlePageSizeChange"
|
||
@refresh="loadData"
|
||
@sort-change="handleSortChange"
|
||
@selection-change="handleSelectionChange"
|
||
>
|
||
<template
|
||
v-for="(slotConfig, colProp) in currentColumnSlots"
|
||
:key="`columnSlots-${colProp}`"
|
||
#[`column-${colProp}`]="{ row }"
|
||
>
|
||
<!-- 操作列 -->
|
||
<template v-if="colProp === 'operation'">
|
||
<div class="operation-cell">
|
||
<el-button link type="primary" size="small" @click.stop="openServerForm('edit', getRowById(row['id']))">编辑</el-button>
|
||
<el-button link type="danger" size="small" @click.stop="handleDeleteServer(getRowById(row['id'])!)">删除</el-button>
|
||
</div>
|
||
</template>
|
||
<!-- 连通列 -->
|
||
<template v-else-if="colProp === 'connectivity'">
|
||
<el-button
|
||
size="small"
|
||
type="warning"
|
||
plain
|
||
:loading="testLoadingMap[row['id']]"
|
||
@click.stop="handleTestConnection(row)"
|
||
>
|
||
连通测试
|
||
</el-button>
|
||
</template>
|
||
<!-- 其他列 -->
|
||
<ColumnCellRenderer
|
||
v-else
|
||
:config="slotConfig"
|
||
:value="row[colProp]"
|
||
/>
|
||
</template>
|
||
|
||
<template #empty>
|
||
<div class="empty-tip">{{ currentTabConfig?.upperTable.emptyText ?? '暂无数据' }}</div>
|
||
</template>
|
||
</UpperTable>
|
||
</div>
|
||
</div>
|
||
</transition>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- ===== 新增/编辑弹窗 ===== -->
|
||
<ServerFormDialog
|
||
v-model:visible="serverFormVisible"
|
||
:row="serverFormRow"
|
||
:mode="serverFormMode"
|
||
@success="handleFormSuccess"
|
||
/>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
// ============================================================
|
||
// ★ 录像服务器管理页面
|
||
// ============================================================
|
||
defineOptions({ name: 'NewCameraServer' })
|
||
|
||
import { ref, computed, onMounted, reactive } from 'vue'
|
||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||
import { useSettingsStore } from '@/stores/modules/settings'
|
||
import ScanBox from '@/components/ScanBox/index.vue'
|
||
import UpperTable from '@/components/UpperTable/index.vue'
|
||
import TabArea from './components/TabArea.vue'
|
||
import ColumnCellRenderer from './components/ColumnCellRenderer.vue'
|
||
import ServerFormDialog from './pages/ServerFormDialog.vue'
|
||
import OrderToolbarButtonGroup from '@/views/order/orderManagement/component/OrderToolbarButtonGroup.vue'
|
||
import type { ToolbarButtonConfig as OrderToolbarButtonConfig } from '@/views/order/orderManagement/config/order-common-config'
|
||
import { del } from '@/api/camera_server/camera_server'
|
||
import { testConnection } from '@/api/camera_server/localServerApi'
|
||
import {
|
||
PAGE_CONFIG,
|
||
tabPages,
|
||
resolveTabConfig,
|
||
getTabToolbarButtons,
|
||
type TabPageConfig,
|
||
type DetailTabConfig,
|
||
type ToolbarButtonConfig,
|
||
} from './config/camaraserver-config'
|
||
|
||
// ============================================================
|
||
// 容器高度
|
||
// ============================================================
|
||
const settingsStore = useSettingsStore()
|
||
const shortcutExpanded = computed(() => settingsStore.shortcutExpanded)
|
||
const containerHeight = computed(() =>
|
||
shortcutExpanded.value ? 'calc(100vh - 150px)' : 'calc(100vh - 100px)'
|
||
)
|
||
|
||
// ============================================================
|
||
// 标签页
|
||
// ============================================================
|
||
const tabList = computed(() =>
|
||
tabPages.map((t) => ({ name: t.name, label: t.label }))
|
||
)
|
||
const activeTabName = ref(tabPages[0]?.name ?? 'server')
|
||
|
||
const currentTabConfig = computed<TabPageConfig | undefined>(() => {
|
||
const raw = tabPages.find((t) => t.name === activeTabName.value)
|
||
if (!raw) return undefined
|
||
return resolveTabConfig(raw)
|
||
})
|
||
|
||
const currentScanBoxCacheKey = computed(
|
||
() => currentTabConfig.value?.scanBoxCacheKey ?? 'server-default'
|
||
)
|
||
const currentScanBoxFields = computed(
|
||
() => currentTabConfig.value?.scanBoxFields ?? []
|
||
)
|
||
const currentColumns = computed(
|
||
() => currentTabConfig.value?.upperTable.columns ?? []
|
||
)
|
||
const currentColumnSlots = computed(
|
||
() => currentTabConfig.value?.columnSlots ?? {}
|
||
)
|
||
const currentDetailConfig = computed(
|
||
() => currentTabConfig.value?.detailConfig ?? []
|
||
)
|
||
const currentDetailTabs = computed<DetailTabConfig[]>(
|
||
() => currentTabConfig.value?.detailTabs ?? []
|
||
)
|
||
const activeDetailTabComponent = computed(() => {
|
||
const tab = currentDetailTabs.value.find(
|
||
(t) => t.name === activeDetailTab.value
|
||
)
|
||
return tab?.component ?? null
|
||
})
|
||
const currentDetailTabApiMethod = computed(() => {
|
||
const cfg = currentTabConfig.value
|
||
if (!cfg?.api) return undefined
|
||
const tab = currentDetailTabs.value.find((t) => t.name === activeDetailTab.value)
|
||
if (!tab) return undefined
|
||
let componentCfg: unknown
|
||
switch (tab.componentKey) {
|
||
case 'DetailPanel': componentCfg = cfg.api.detail; break
|
||
case 'LogPanel': componentCfg = cfg.api.log; break
|
||
default: return undefined
|
||
}
|
||
if (typeof componentCfg === 'function') return componentCfg
|
||
return undefined
|
||
})
|
||
|
||
// ============================================================
|
||
// 工具栏
|
||
// ============================================================
|
||
const currentToolbarButtons = computed<OrderToolbarButtonConfig[]>(() => {
|
||
const btns = getTabToolbarButtons(activeTabName.value)
|
||
return btns.map((btn: any) => ({
|
||
key: btn.key, label: btn.label, size: btn.size, type: btn.type,
|
||
plain: btn.plain, loadingKey: btn.loadingKey, disabledKey: btn.disabledKey,
|
||
action: btn.action, dynamicLabelKey: btn.dynamicLabelKey,
|
||
buttonType: btn.buttonType, dropdownOptions: btn.dropdownOptions,
|
||
category: btn.category
|
||
}))
|
||
})
|
||
|
||
const buttonDisabledMap = computed<Record<string, boolean>>(() => ({
|
||
noSelection: selectedRows.value.length === 0
|
||
}))
|
||
const buttonLoadingMap = computed<Record<string, boolean>>(() => ({
|
||
loading: loading.value
|
||
}))
|
||
const buttonLabelMap = computed<Record<string, string>>(() => ({}))
|
||
const toolbarLayoutKey = computed(() =>
|
||
JSON.stringify({ loading: buttonLoadingMap.value, disabled: buttonDisabledMap.value, labels: buttonLabelMap.value })
|
||
)
|
||
|
||
function resolveButtonLoading(loadingKey?: string) { return loadingKey ? Boolean(buttonLoadingMap.value[loadingKey]) : false }
|
||
function resolveButtonDisabled(disabledKey?: string) { return disabledKey ? Boolean(buttonDisabledMap.value[disabledKey]) : false }
|
||
function resolveButtonLabel(defaultLabel: string, dynamicLabelKey?: string) {
|
||
return dynamicLabelKey ? (buttonLabelMap.value[dynamicLabelKey] || defaultLabel) : defaultLabel
|
||
}
|
||
|
||
const toolbarActionMap: Record<string, () => void> = {
|
||
loadData: () => { void loadData() },
|
||
openColumnConfigPanel: () => { upperTableRef.value?.openColumnConfig?.() },
|
||
openAddServerDialog: () => { openServerForm('create') }
|
||
}
|
||
|
||
function handleToolbarButtonClick(action: string) {
|
||
const handler = toolbarActionMap[action]
|
||
if (handler) { handler(); return }
|
||
console.warn('[NewCameraServer] 未处理的工具栏动作:', action)
|
||
}
|
||
|
||
// ============================================================
|
||
// ServerFormDialog
|
||
// ============================================================
|
||
const serverFormVisible = ref(false)
|
||
const serverFormMode = ref<'create' | 'edit'>('create')
|
||
const serverFormRow = ref<Record<string, any> | null>(null)
|
||
|
||
function openServerForm(mode: 'create' | 'edit', row?: Record<string, any>) {
|
||
serverFormMode.value = mode
|
||
serverFormRow.value = row ?? null
|
||
serverFormVisible.value = true
|
||
}
|
||
|
||
function getRowById(id: any): Record<string, any> | undefined {
|
||
if (id === undefined || id === null) return undefined
|
||
return (listData.value as any[]).find((item: any) => item.id === id)
|
||
}
|
||
|
||
function handleFormSuccess() { loadData() }
|
||
|
||
// ============================================================
|
||
// 操作列
|
||
// ============================================================
|
||
async function handleDeleteServer(row: Record<string, any>) {
|
||
if (!row.id) return
|
||
const name = row.name || String(row.id)
|
||
try {
|
||
await ElMessageBox.confirm(`确认删除录像服务器「${name}」吗?删除后关联的摄像头将不可用`, '提示', {
|
||
type: 'warning',
|
||
// 按钮尺寸对齐面板表单底部按钮(Element Plus small)
|
||
buttonSize: 'small'
|
||
})
|
||
} catch { return }
|
||
try {
|
||
const res: any = await del({ id: row.id })
|
||
if (res && [0, 1, 200].includes(res.code)) {
|
||
ElMessage.success('删除成功')
|
||
if (listData.value.length === 1 && pagination.currentPage > 1) pagination.currentPage -= 1
|
||
loadData()
|
||
} else {
|
||
ElMessage.error(res?.message || '删除失败')
|
||
}
|
||
} catch { ElMessage.error('删除失败') }
|
||
}
|
||
|
||
// ============================================================
|
||
// 连通测试
|
||
// ============================================================
|
||
const testLoadingMap = ref<Record<number, boolean>>({})
|
||
|
||
async function handleTestConnection(row: Record<string, any>) {
|
||
const id = row.id
|
||
if (testLoadingMap.value[id]) return
|
||
|
||
const internalIp = (row.internal_ip || '').trim()
|
||
const publicIp = (row.public_ip || '').trim()
|
||
const username = (row.username || '').trim()
|
||
let password = (row.password || '').trim()
|
||
|
||
if (!internalIp && !publicIp) { ElMessage.warning('该服务器未配置内网IP与公网IP,无法测试连通'); return }
|
||
if (!username) { ElMessage.warning('缺少用户名,无法测试连通'); return }
|
||
|
||
if (!password) {
|
||
try {
|
||
const { value } = await ElMessageBox.prompt('请输入录像服务器密码', '连通测试', {
|
||
inputType: 'password',
|
||
confirmButtonText: '开始测试',
|
||
cancelButtonText: '取消',
|
||
inputPlaceholder: '请输入密码',
|
||
// 按钮尺寸对齐面板表单底部按钮(Element Plus small)
|
||
buttonSize: 'small'
|
||
})
|
||
if (!value?.trim()) { ElMessage.warning('密码不能为空'); return }
|
||
password = value.trim()
|
||
} catch { return }
|
||
}
|
||
|
||
testLoadingMap.value = { ...testLoadingMap.value, [id]: true }
|
||
const localBaseUrl = 'http://localhost:17311'
|
||
|
||
const tryIp = async (label: string, ip: string, port?: number): Promise<boolean> => {
|
||
try {
|
||
await testConnection(localBaseUrl, { ip, port: port || row.port, user: username, pass: password })
|
||
ElMessage.success(`「${row.name || row.id}」连通成功(${label}:${ip})`)
|
||
return true
|
||
} catch (e: any) { console.warn(`[连通测试] ${label} ${ip} 失败:`, e?.message || e); return false }
|
||
}
|
||
|
||
if (internalIp) {
|
||
const ok = await tryIp('内网IP', internalIp, row.internal_port)
|
||
if (ok) { testLoadingMap.value = { ...testLoadingMap.value, [id]: false }; return }
|
||
}
|
||
|
||
if (publicIp && publicIp !== internalIp) {
|
||
const ok = await tryIp('公网IP', publicIp, row.public_port)
|
||
if (ok) { testLoadingMap.value = { ...testLoadingMap.value, [id]: false }; return }
|
||
}
|
||
|
||
testLoadingMap.value = { ...testLoadingMap.value, [id]: false }
|
||
const triedIps = [internalIp, publicIp].filter(Boolean).join('、')
|
||
ElMessage.error(`「${row.name || row.id}」连通失败(已尝试:${triedIps})`)
|
||
}
|
||
|
||
// ============================================================
|
||
// 数据加载
|
||
// ============================================================
|
||
const listData = ref<Record<string, any>[]>([])
|
||
const loading = ref(false)
|
||
const queryTime = ref(0)
|
||
const pagination = reactive({ currentPage: 1, pageSize: 20, total: 0 })
|
||
const currentSort = reactive({ prop: '', order: '' })
|
||
|
||
const loadData = async () => {
|
||
const cfg = currentTabConfig.value
|
||
if (!cfg) return
|
||
loading.value = true
|
||
const startTime = performance.now()
|
||
try {
|
||
if (cfg.api) {
|
||
const conditions = scanBoxRef.value?.getConditions?.() || {}
|
||
const params = cfg.api.buildListParams
|
||
? cfg.api.buildListParams({
|
||
pagination: { page: pagination.currentPage, pageSize: pagination.pageSize },
|
||
conditions,
|
||
sort: currentSort.prop ? { prop: currentSort.prop, order: currentSort.order } : undefined
|
||
})
|
||
: { pagination: { page: pagination.currentPage, pageSize: pagination.pageSize }, where: conditions }
|
||
const res = await cfg.api.list(params)
|
||
if (res && [0, 1, 200].includes(res.code)) {
|
||
const parsed = cfg.api.parseListResponse
|
||
? cfg.api.parseListResponse(res)
|
||
: { list: res.data?.list ?? res.list ?? [], total: res.data?.pagination?.total ?? res.total ?? 0 }
|
||
listData.value = parsed.list
|
||
pagination.total = parsed.total
|
||
} else { throw new Error(res?.message || '接口返回异常') }
|
||
} else { listData.value = []; pagination.total = 0 }
|
||
} catch (e: any) {
|
||
console.error('[NewCameraServer] 加载列表失败:', e)
|
||
ElMessage.error(e?.message || '获取列表数据失败')
|
||
listData.value = []; pagination.total = 0
|
||
} finally {
|
||
loading.value = false
|
||
queryTime.value = Math.round(performance.now() - startTime)
|
||
}
|
||
}
|
||
|
||
// ============================================================
|
||
// ScanBox / UpperTable 事件
|
||
// ============================================================
|
||
const scanBoxRef = ref<any>(null)
|
||
const presetTree = ref<any[]>([])
|
||
const upperTableRef = ref<any>(null)
|
||
const selectedRows = ref<Record<string, any>[]>([])
|
||
|
||
const handleConditionChange = () => { pagination.currentPage = 1; loadData() }
|
||
const handleConditionReset = () => { pagination.currentPage = 1; loadData() }
|
||
const handleConditionClear = () => { pagination.currentPage = 1; loadData() }
|
||
const handleSortChange = ({ prop, order }: any) => { currentSort.prop = prop; currentSort.order = order; pagination.currentPage = 1; loadData() }
|
||
const handlePageChange = (page: number) => { pagination.currentPage = page; loadData() }
|
||
const handlePageSizeChange = (size: number) => { pagination.pageSize = size; pagination.currentPage = 1; loadData() }
|
||
const handleSelectionChange = (rows: Record<string, any>[]) => { selectedRows.value = rows }
|
||
|
||
// ============================================================
|
||
// 明细面板(未启用)
|
||
// ============================================================
|
||
const selectedRow = ref<Record<string, any> | null>(null)
|
||
const selectedDetail = ref<Record<string, any> | null>(null)
|
||
const activeDetailTab = ref('detail')
|
||
|
||
const handleRowClick = async (row: Record<string, any>) => {
|
||
if (!PAGE_CONFIG.enableDetailPanel) return
|
||
const cfg = currentTabConfig.value
|
||
if (!cfg) return
|
||
selectedRow.value = row
|
||
const detailCfg = cfg.api?.detail
|
||
if (typeof detailCfg === 'function') {
|
||
try {
|
||
const detailRes = await detailCfg({ id: row.id, code: row.code })
|
||
if (detailRes && [0, 1, 200].includes(detailRes.code)) { selectedDetail.value = detailRes.data ?? detailRes }
|
||
else { selectedDetail.value = { ...row } }
|
||
} catch { selectedDetail.value = { ...row } }
|
||
} else { selectedDetail.value = { ...row } }
|
||
}
|
||
|
||
const handleTabChange = (tabName: string) => {
|
||
if (activeTabName.value === tabName) return
|
||
activeTabName.value = tabName
|
||
pagination.currentPage = 1; currentSort.prop = ''; currentSort.order = ''
|
||
selectedRow.value = null; selectedDetail.value = null; selectedRows.value = []
|
||
activeDetailTab.value = 'detail'
|
||
loadData()
|
||
}
|
||
|
||
onMounted(() => { loadData() })
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
@use "../../order/orderManagement/styles/order-sub.scss";
|
||
|
||
.page-wrapper {
|
||
position: relative;
|
||
width: 100%;
|
||
display: flex;
|
||
flex-direction: column;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.tab-section {
|
||
flex-shrink: 0;
|
||
background: #fff;
|
||
border: 1px solid #e8eef7;
|
||
border-bottom: none;
|
||
border-radius: 6px 6px 0 0;
|
||
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
|
||
overflow: hidden;
|
||
}
|
||
|
||
.tab-content-inner {
|
||
flex: 1;
|
||
display: flex;
|
||
flex-direction: column;
|
||
min-height: 0;
|
||
}
|
||
|
||
.tab-fade-enter-active,
|
||
.tab-fade-leave-active {
|
||
transition: opacity 0.2s ease;
|
||
opacity: 1;
|
||
}
|
||
|
||
.tab-fade-enter-from,
|
||
.tab-fade-leave-to {
|
||
opacity: 0;
|
||
}
|
||
|
||
.empty-tip {
|
||
font-size: 13px;
|
||
color: #909399;
|
||
}
|
||
|
||
.wave-operation-actions {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
gap: 4px;
|
||
flex-wrap: wrap;
|
||
}
|
||
</style>
|