- 新增货主侧商品流水页面 storage/productflow/store - 新增视频监控模块 video/camera 和 video/cameraServer - 完善工作台配置与视图功能 - 增强库存 API、报表 API 和工作台 API - 更新路由映射 componentMap
507 lines
15 KiB
Vue
507 lines
15 KiB
Vue
<template>
|
||
<div class="video-container" :style="{ height: containerHeight }">
|
||
<scan-box
|
||
ref="scanBox"
|
||
cache-key="video-camera"
|
||
width="250px"
|
||
title="摄像头筛选"
|
||
:preset-tree="presetTree"
|
||
:available-fields="availableFields"
|
||
@condition-change="handleConditionChange"
|
||
@reset="handleReset"
|
||
/>
|
||
|
||
<div class="main-content">
|
||
<div class="toolbar">
|
||
<div class="toolbar-left">
|
||
<el-button size="small" type="primary" :loading="loading" @click="loadList">刷新</el-button>
|
||
<el-tag size="small" type="info">共 {{ pagination.total }} 条</el-tag>
|
||
</div>
|
||
<el-button type="success" size="small" @click="openCreate">新增摄像头</el-button>
|
||
</div>
|
||
|
||
<div class="upper-wrapper">
|
||
<upper-table
|
||
ref="upperTable"
|
||
title="摄像头列表"
|
||
default-align="center"
|
||
table-id="video-camera"
|
||
:data="tableData"
|
||
:columns="columns"
|
||
:table-size="tableSize"
|
||
:pagination="pagination"
|
||
:show-index="true"
|
||
:show-actions="false"
|
||
:loading="loading"
|
||
:query-time="queryTime"
|
||
row-key="id"
|
||
@page-change="handlePageChange"
|
||
@page-size-change="handlePageSizeChange"
|
||
@refresh="loadList"
|
||
>
|
||
<template #column-server_name="{ row }">
|
||
<span>{{ row.server?.name || row.server_name || '--' }}</span>
|
||
</template>
|
||
|
||
<template #column-status="{ row }">
|
||
<el-tag :type="formatStatus(row.status).type" size="small">
|
||
{{ formatStatus(row.status).text }}
|
||
</el-tag>
|
||
</template>
|
||
|
||
<template #column-actions="{ row }">
|
||
<el-button link type="primary" size="small" @click.stop="openEdit(row)">编辑</el-button>
|
||
<el-button link type="danger" size="small" @click.stop="handleDelete(row)">删除</el-button>
|
||
</template>
|
||
|
||
<template #empty>
|
||
<div class="empty-tip">暂无摄像头数据,可调整左侧筛选条件</div>
|
||
</template>
|
||
</upper-table>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 新增/编辑弹窗 -->
|
||
<el-dialog
|
||
v-model="dialogVisible"
|
||
:title="dialogMode === 'create' ? '新增摄像头' : '编辑摄像头'"
|
||
width="560px"
|
||
align-center
|
||
@close="resetForm"
|
||
>
|
||
<el-form ref="formRef" :model="formData" :rules="rules" label-width="120px">
|
||
<el-form-item label="所属录像服务器" prop="server_id">
|
||
<el-select
|
||
v-model="formData.server_id"
|
||
placeholder="请选择录像服务器"
|
||
filterable
|
||
style="width: 100%"
|
||
@focus="loadServerOptions"
|
||
>
|
||
<el-option
|
||
v-for="item in serverOptions"
|
||
:key="item.id"
|
||
:label="item.name"
|
||
:value="item.id"
|
||
/>
|
||
</el-select>
|
||
</el-form-item>
|
||
<el-form-item label="通道ID" prop="channel_id">
|
||
<el-input-number v-model="formData.channel_id" :min="1" placeholder="请输入通道ID" style="width: 100%" />
|
||
</el-form-item>
|
||
<el-form-item label="通道名称" prop="channel_name">
|
||
<el-input v-model="formData.channel_name" placeholder="请输入通道名称" maxlength="100" show-word-limit />
|
||
</el-form-item>
|
||
<el-form-item label="自定义名称" prop="custom_name">
|
||
<el-input v-model="formData.custom_name" placeholder="请输入自定义名称" maxlength="100" show-word-limit />
|
||
</el-form-item>
|
||
<el-form-item label="状态" prop="status">
|
||
<el-switch
|
||
v-model="formData.status"
|
||
:active-value="1"
|
||
:inactive-value="0"
|
||
active-text="启用"
|
||
inactive-text="禁用"
|
||
/>
|
||
</el-form-item>
|
||
<el-form-item label="备注" prop="remark">
|
||
<el-input v-model="formData.remark" type="textarea" :rows="3" placeholder="请输入备注" maxlength="200" show-word-limit />
|
||
</el-form-item>
|
||
</el-form>
|
||
<template #footer>
|
||
<el-button @click="dialogVisible = false">取消</el-button>
|
||
<el-button type="primary" :loading="saving" @click="submitForm">保存</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { computed, onMounted, reactive, ref } from 'vue'
|
||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||
import type { FormInstance, FormRules } from 'element-plus'
|
||
import ScanBox from '@/components/ScanBox/index.vue'
|
||
import UpperTable from '@/components/UpperTable/index.vue'
|
||
import { list, create, update, del } from '@/api/camera/camera'
|
||
import { list as serverList } from '@/api/camera_server/camera_server'
|
||
import { useSettingsStore } from '@/stores/modules/settings'
|
||
|
||
type CameraRecord = {
|
||
id?: number
|
||
server_id?: number
|
||
server_name?: string
|
||
channel_id?: number
|
||
channel_name?: string
|
||
custom_name?: string
|
||
status?: number
|
||
remark?: string
|
||
created_at?: string
|
||
updated_at?: string
|
||
}
|
||
|
||
type ServerOption = {
|
||
id: number
|
||
name: string
|
||
}
|
||
|
||
const settingsStore = useSettingsStore()
|
||
const scanBox = ref<any>(null)
|
||
const upperTable = ref<any>(null)
|
||
|
||
const shortcutExpanded = computed(() => settingsStore.shortcutExpanded)
|
||
const containerHeight = computed(() =>
|
||
shortcutExpanded.value ? 'calc(100vh - 150px)' : 'calc(100vh - 100px)'
|
||
)
|
||
|
||
const columns = [
|
||
{ prop: 'id', label: 'ID', width: '80', sortable: true },
|
||
{ prop: 'server_name', label: '所属服务器', minWidth: '150', showOverflowTooltip: true },
|
||
{ prop: 'channel_id', label: '通道ID', width: '100' },
|
||
{ prop: 'channel_name', label: '通道名称', width: '140', showOverflowTooltip: true },
|
||
{ prop: 'custom_name', label: '自定义名称', minWidth: '160', showOverflowTooltip: true },
|
||
{ prop: 'status', label: '状态', width: '90' },
|
||
{ prop: 'remark', label: '备注', minWidth: '160', showOverflowTooltip: true },
|
||
{ prop: 'actions', label: '操作', width: '150', fixed: 'right' }
|
||
]
|
||
|
||
const availableFields = [
|
||
{
|
||
value: 'quickWhere',
|
||
label: '关键词',
|
||
type: 'text',
|
||
placeholder: '通道名称/自定义名称',
|
||
operators: ['contains'],
|
||
defaultOperator: 'contains'
|
||
},
|
||
{
|
||
value: 'server_id',
|
||
label: '所属服务器',
|
||
type: 'select',
|
||
filterable: true,
|
||
clearable: true,
|
||
options: [] as { label: string; value: string | number }[]
|
||
},
|
||
{
|
||
value: 'custom_name',
|
||
label: '自定义名称',
|
||
type: 'text',
|
||
placeholder: '请输入自定义名称',
|
||
operators: ['contains'],
|
||
defaultOperator: 'contains'
|
||
},
|
||
{
|
||
value: 'status',
|
||
label: '状态',
|
||
type: 'select',
|
||
clearable: true,
|
||
options: [
|
||
{ label: '启用', value: '1' },
|
||
{ label: '禁用', value: '0' }
|
||
]
|
||
}
|
||
]
|
||
|
||
const presetTree = ref<any[]>([])
|
||
const loading = ref(false)
|
||
const saving = ref(false)
|
||
const tableData = ref<CameraRecord[]>([])
|
||
const serverOptions = ref<ServerOption[]>([])
|
||
const queryTime = ref(0)
|
||
const tableSize = ref<'small' | 'default' | 'large'>('small')
|
||
const currentConditionRaw = ref<any>(null)
|
||
|
||
const pagination = reactive({ currentPage: 1, pageSize: 20, total: 0 })
|
||
|
||
const dialogVisible = ref(false)
|
||
const dialogMode = ref<'create' | 'edit'>('create')
|
||
const formRef = ref<FormInstance>()
|
||
const formData = reactive({
|
||
id: undefined as number | undefined,
|
||
server_id: undefined as number | undefined,
|
||
channel_id: undefined as number | undefined,
|
||
channel_name: '',
|
||
custom_name: '',
|
||
status: 1 as number,
|
||
remark: ''
|
||
})
|
||
|
||
const rules: FormRules = {
|
||
server_id: [{ required: true, message: '请选择录像服务器', trigger: 'change' }],
|
||
channel_id: [{ required: true, message: '请输入通道ID', trigger: 'blur' }]
|
||
}
|
||
|
||
const isSuccess = (res: any) => res && [0, 1, 200].includes(res.code)
|
||
|
||
function formatStatus(status: number | undefined) {
|
||
if (status === 1) return { text: '启用', type: 'success' as const }
|
||
if (status === 0) return { text: '禁用', type: 'info' as const }
|
||
return { text: '--', type: 'info' as const }
|
||
}
|
||
|
||
/** 解包 ScanBox 的条件对象值,转为 API where 可接受的格式 */
|
||
function unwrapConditionValue(raw: unknown): string | number | null | Record<string, unknown> {
|
||
if (raw === null || raw === undefined || raw === '') return null
|
||
if (Array.isArray(raw) && raw.length === 0) return null
|
||
|
||
// ScanBox 对象值格式:{ operator, value }
|
||
if (raw && typeof raw === 'object' && !Array.isArray(raw)) {
|
||
const obj = raw as Record<string, unknown>
|
||
if (['isnull', 'isnotnull'].includes(String(obj.operator ?? ''))) {
|
||
return { operator: obj.operator as string, value: null }
|
||
}
|
||
const val = obj.value !== undefined ? obj.value : raw
|
||
if (val === null || val === undefined || val === '' || (Array.isArray(val) && val.length === 0)) {
|
||
return null
|
||
}
|
||
return { operator: obj.operator || 'eq', value: val }
|
||
}
|
||
|
||
return raw as string | number
|
||
}
|
||
|
||
function buildWhere(raw: any): Record<string, unknown> {
|
||
if (!raw) return {}
|
||
|
||
// ScanBox 发出 { conditions: { ... } },先解包
|
||
const conds =
|
||
raw.conditions && typeof raw.conditions === 'object' && !Array.isArray(raw.conditions)
|
||
? raw.conditions
|
||
: raw
|
||
|
||
if (!conds || typeof conds !== 'object') return {}
|
||
|
||
const where: Record<string, unknown> = {}
|
||
|
||
for (const key of Object.keys(conds)) {
|
||
const result = unwrapConditionValue(conds[key])
|
||
if (result === null) continue
|
||
|
||
if (key === 'quickWhere') {
|
||
// quickWhere 直接传字符串
|
||
where.quickWhere = typeof result === 'string' ? result : String((result as Record<string, unknown>).value ?? result)
|
||
} else if (key === 'status' || key === 'server_id') {
|
||
where[key] = typeof result === 'object' ? Number((result as Record<string, unknown>).value) : Number(result)
|
||
} else {
|
||
where[key] = result
|
||
}
|
||
}
|
||
|
||
return where
|
||
}
|
||
|
||
async function loadList() {
|
||
if (loading.value) return
|
||
loading.value = true
|
||
const start = Date.now()
|
||
try {
|
||
const where = buildWhere(currentConditionRaw.value)
|
||
const res: any = await list({
|
||
pagination: { page: pagination.currentPage, pageSize: pagination.pageSize },
|
||
where
|
||
})
|
||
if (!isSuccess(res)) {
|
||
ElMessage.error(res?.message || '获取摄像头列表失败')
|
||
tableData.value = []
|
||
pagination.total = 0
|
||
return
|
||
}
|
||
tableData.value = res?.list || []
|
||
pagination.total = Number(res?.pagination?.total ?? res?.total ?? 0)
|
||
} catch {
|
||
tableData.value = []
|
||
pagination.total = 0
|
||
ElMessage.error('获取摄像头列表失败')
|
||
} finally {
|
||
queryTime.value = Date.now() - start
|
||
loading.value = false
|
||
}
|
||
}
|
||
|
||
async function loadServerOptions() {
|
||
if (serverOptions.value.length > 0) return
|
||
try {
|
||
const res: any = await serverList({ pagination: { page: 1, pageSize: 999 } })
|
||
if (!isSuccess(res)) return
|
||
const list = res?.list || []
|
||
serverOptions.value = list.map((item: any) => ({
|
||
id: item.id,
|
||
name: item.name || `服务器-${item.id}`
|
||
}))
|
||
// 同步到筛选下拉
|
||
const field = availableFields.find((f: any) => f.value === 'server_id')
|
||
if (field) {
|
||
field.options = serverOptions.value.map((item) => ({
|
||
label: item.name,
|
||
value: item.id
|
||
}))
|
||
}
|
||
} catch {
|
||
// ignore
|
||
}
|
||
}
|
||
|
||
function handleConditionChange(condition: any) {
|
||
currentConditionRaw.value = condition
|
||
pagination.currentPage = 1
|
||
loadList()
|
||
}
|
||
|
||
function handleReset() {
|
||
currentConditionRaw.value = null
|
||
pagination.currentPage = 1
|
||
if (scanBox.value?.reset) scanBox.value.reset()
|
||
loadList()
|
||
}
|
||
|
||
function handlePageChange(page: number) {
|
||
pagination.currentPage = page
|
||
loadList()
|
||
}
|
||
|
||
function handlePageSizeChange(size: number) {
|
||
pagination.pageSize = size
|
||
pagination.currentPage = 1
|
||
loadList()
|
||
}
|
||
|
||
function resetForm() {
|
||
formData.id = undefined
|
||
formData.server_id = undefined
|
||
formData.channel_id = undefined
|
||
formData.channel_name = ''
|
||
formData.custom_name = ''
|
||
formData.status = 1
|
||
formData.remark = ''
|
||
formRef.value?.clearValidate()
|
||
}
|
||
|
||
function openCreate() {
|
||
dialogMode.value = 'create'
|
||
dialogVisible.value = true
|
||
resetForm()
|
||
}
|
||
|
||
function openEdit(row: CameraRecord) {
|
||
if (!row.id) return
|
||
dialogMode.value = 'edit'
|
||
dialogVisible.value = true
|
||
formData.id = row.id
|
||
formData.server_id = row.server_id
|
||
formData.channel_id = row.channel_id
|
||
formData.channel_name = row.channel_name || ''
|
||
formData.custom_name = row.custom_name || ''
|
||
formData.status = row.status ?? 1
|
||
formData.remark = row.remark || ''
|
||
formRef.value?.clearValidate()
|
||
}
|
||
|
||
async function submitForm() {
|
||
if (!formRef.value || saving.value) return
|
||
const valid = await formRef.value.validate().catch(() => false)
|
||
if (!valid) return
|
||
|
||
saving.value = true
|
||
try {
|
||
if (dialogMode.value === 'create') {
|
||
const res: any = await create({
|
||
server_id: formData.server_id!,
|
||
channel_id: formData.channel_id!,
|
||
channel_name: formData.channel_name.trim() || undefined,
|
||
custom_name: formData.custom_name.trim() || undefined,
|
||
status: formData.status,
|
||
remark: formData.remark.trim() || undefined
|
||
})
|
||
if (!isSuccess(res)) {
|
||
ElMessage.error(res?.message || '新增失败')
|
||
return
|
||
}
|
||
ElMessage.success('新增成功')
|
||
} else {
|
||
if (!formData.id) return
|
||
const res: any = await update({
|
||
id: formData.id,
|
||
server_id: formData.server_id,
|
||
channel_id: formData.channel_id,
|
||
channel_name: formData.channel_name.trim() || undefined,
|
||
custom_name: formData.custom_name.trim() || undefined,
|
||
status: formData.status,
|
||
remark: formData.remark.trim() || undefined
|
||
})
|
||
if (!isSuccess(res)) {
|
||
ElMessage.error(res?.message || '更新失败')
|
||
return
|
||
}
|
||
ElMessage.success('更新成功')
|
||
}
|
||
dialogVisible.value = false
|
||
loadList()
|
||
} catch {
|
||
ElMessage.error('保存失败')
|
||
} finally {
|
||
saving.value = false
|
||
}
|
||
}
|
||
|
||
function handleDelete(row: CameraRecord) {
|
||
if (!row.id) return
|
||
const name = row.custom_name || row.channel_name || String(row.id)
|
||
ElMessageBox.confirm(`确认删除摄像头「${name}」吗?`, '提示', { type: 'warning' })
|
||
.then(async () => {
|
||
const res: any = await del({ id: row.id as number })
|
||
if (!isSuccess(res)) {
|
||
ElMessage.error(res?.message || '删除失败')
|
||
return
|
||
}
|
||
ElMessage.success('删除成功')
|
||
if (tableData.value.length === 1 && pagination.currentPage > 1) {
|
||
pagination.currentPage -= 1
|
||
}
|
||
loadList()
|
||
})
|
||
.catch(() => undefined)
|
||
}
|
||
|
||
onMounted(() => {
|
||
loadList()
|
||
loadServerOptions()
|
||
})
|
||
</script>
|
||
|
||
<style scoped>
|
||
.video-container {
|
||
display: flex;
|
||
gap: 12px;
|
||
padding: 12px;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
.main-content {
|
||
flex: 1;
|
||
display: flex;
|
||
flex-direction: column;
|
||
min-width: 0;
|
||
}
|
||
|
||
.toolbar {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
margin-bottom: 12px;
|
||
}
|
||
|
||
.toolbar-left {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 12px;
|
||
}
|
||
|
||
.upper-wrapper {
|
||
flex: 1;
|
||
}
|
||
|
||
.empty-tip {
|
||
color: #909399;
|
||
padding: 24px;
|
||
}
|
||
</style>
|