feat: 新增货主侧商品流水、视频监控模块,完善工作台与库存报表功能
- 新增货主侧商品流水页面 storage/productflow/store - 新增视频监控模块 video/camera 和 video/cameraServer - 完善工作台配置与视图功能 - 增强库存 API、报表 API 和工作台 API - 更新路由映射 componentMap
This commit is contained in:
parent
c7d832b0b0
commit
11fe10829e
@ -581,3 +581,61 @@ export function stockTransactionStoreList(
|
||||
isSystemApi: true
|
||||
} as any)
|
||||
}
|
||||
|
||||
// ─── 商品流水导出 ──────────────────────────────────────────────────────────
|
||||
|
||||
/** 仓库侧异步导出商品流水 */
|
||||
export function transactionExport(data?: {
|
||||
where?: Record<string, unknown>
|
||||
sort?: StockTransactionListSort
|
||||
all?: boolean
|
||||
mode?: string
|
||||
}) {
|
||||
return request({
|
||||
url: '/system',
|
||||
method: 'post',
|
||||
params: {
|
||||
method: 'stock.transaction.export',
|
||||
v,
|
||||
timestamp: new Date().getTime()
|
||||
},
|
||||
data: data ?? {},
|
||||
isSystemApi: true
|
||||
} as any)
|
||||
}
|
||||
|
||||
/** 货主侧异步导出商品流水 */
|
||||
export function transactionExportStore(data?: {
|
||||
store_id: number
|
||||
where?: Record<string, unknown>
|
||||
sort?: StockTransactionListSort
|
||||
all?: boolean
|
||||
mode?: string
|
||||
}) {
|
||||
return request({
|
||||
url: '/system',
|
||||
method: 'post',
|
||||
params: {
|
||||
method: 'stock.transaction.exportStore',
|
||||
v,
|
||||
timestamp: new Date().getTime()
|
||||
},
|
||||
data: data ?? {},
|
||||
isSystemApi: true
|
||||
} as any)
|
||||
}
|
||||
|
||||
/** 查询商品流水导出任务进度(仓库/货主共用) */
|
||||
export function transactionExportTaskProgress(data: { task_id: string }) {
|
||||
return request({
|
||||
url: '/system',
|
||||
method: 'post',
|
||||
params: {
|
||||
method: 'stock.transaction.exportTaskProgress',
|
||||
v,
|
||||
timestamp: new Date().getTime()
|
||||
},
|
||||
data,
|
||||
isSystemApi: true
|
||||
} as any)
|
||||
}
|
||||
|
||||
@ -90,7 +90,7 @@ export function searchInventoryReport(
|
||||
url: '/system',
|
||||
method: 'post',
|
||||
params: {
|
||||
method: 'storage.report.search',
|
||||
method: 'stock.report.search',
|
||||
v,
|
||||
timestamp: new Date().getTime()
|
||||
},
|
||||
@ -107,7 +107,7 @@ export function searchStoreReport(
|
||||
url: '/system',
|
||||
method: 'post',
|
||||
params: {
|
||||
method: 'storage.report.searchStore',
|
||||
method: 'stock.report.searchStore',
|
||||
v,
|
||||
timestamp: new Date().getTime()
|
||||
},
|
||||
@ -123,7 +123,7 @@ export function exportInventoryReport(
|
||||
url: '/system',
|
||||
method: 'post',
|
||||
params: {
|
||||
method: 'storage.report.export',
|
||||
method: 'stock.report.export',
|
||||
v,
|
||||
timestamp: new Date().getTime()
|
||||
},
|
||||
@ -140,7 +140,7 @@ export function exportStoreReport(
|
||||
url: '/system',
|
||||
method: 'post',
|
||||
params: {
|
||||
method: 'storage.report.exportStore',
|
||||
method: 'stock.report.exportStore',
|
||||
v,
|
||||
timestamp: new Date().getTime()
|
||||
},
|
||||
@ -156,7 +156,7 @@ export function getExportTaskProgress(
|
||||
url: '/system',
|
||||
method: 'post',
|
||||
params: {
|
||||
method: 'storage.report.exportTaskProgress',
|
||||
method: 'stock.report.exportTaskProgress',
|
||||
v,
|
||||
timestamp: new Date().getTime()
|
||||
},
|
||||
|
||||
@ -126,3 +126,21 @@ export function business(data: {
|
||||
isSystemApi: true
|
||||
} as any)
|
||||
}
|
||||
|
||||
/** 工作台绑定/解绑摄像头,校验工作台与摄像头归属后更新 device_ids */
|
||||
export function bindCamera(data: {
|
||||
id: number
|
||||
camera_ids?: number[]
|
||||
}) {
|
||||
return request({
|
||||
url: '/system',
|
||||
method: 'post',
|
||||
params: {
|
||||
method: 'workbench.bindCamera',
|
||||
v,
|
||||
timestamp: new Date().getTime()
|
||||
},
|
||||
data,
|
||||
isSystemApi: true
|
||||
} as any)
|
||||
}
|
||||
|
||||
@ -37,6 +37,8 @@ export const componentMap: Record<string, any> = {
|
||||
'storage/inventory': () => import('@/views/storage/inventory/index.vue'),
|
||||
'storage/stockout': () => import('@/views/storage/stockout/index.vue'),
|
||||
'store/productflow': () => import('@/views/storage/productflow/index.vue'),
|
||||
/** 货主侧商品流水 */
|
||||
'storage/productflow/store': () => import('@/views/storage/productflow/store/index.vue'),
|
||||
'store/index': () => import('@/views/store/stores/index.vue'),
|
||||
'Externalwarehouse/shipperSigning/index': () => import('@/views/Externalwarehouse/shipperSigning/index.vue'),
|
||||
'wave/index': () => import('@/views/order/waveOrder/index.vue'),
|
||||
@ -61,4 +63,6 @@ export const componentMap: Record<string, any> = {
|
||||
'material/packageMaterial/index':() => import('@/views/material/packageMaterial/index.vue'),
|
||||
'material/packageSupplier/index':() => import('@/views/material/packageSupplier/index.vue'),
|
||||
'system/setting/pickcart/index':() => import('@/views/system/setting/pickcart/index.vue'),
|
||||
'video/cameraServer/index': () => import('@/views/video/cameraServer/index.vue'),
|
||||
'video/camera/index': () => import('@/views/video/camera/index.vue'),
|
||||
};
|
||||
@ -40,9 +40,11 @@
|
||||
:table-size="tableSize"
|
||||
:pagination="pagination"
|
||||
:show-index="true"
|
||||
show-selection
|
||||
:loading="loading"
|
||||
:query-time="queryTime"
|
||||
@current-change="handleRowClick"
|
||||
@selection-change="handleSelectionChange"
|
||||
@page-change="handlePageChange"
|
||||
@page-size-change="handlePageSizeChange"
|
||||
@sort-change="handleSortChange"
|
||||
@ -56,8 +58,23 @@
|
||||
{{ getTransactionTypeLabel(row.transaction_type) }}
|
||||
</el-tag>
|
||||
</template>
|
||||
<template #column-quantity="{ row }">
|
||||
<span :class="getQuantityClass(row)">{{ formatQuantityDisplay(row) }}</span>
|
||||
<template #column-stock_quantity="{ row }">
|
||||
<span :class="getQuantityClass(row, 'stock')">{{ formatStockQuantity(row) }}</span>
|
||||
</template>
|
||||
<template #column-lock_quantity="{ row }">
|
||||
<span :class="getQuantityClass(row, 'lock')">{{ formatLockQuantity(row) }}</span>
|
||||
</template>
|
||||
<template #column-before_quantity="{ row }">
|
||||
<span :class="getStockClass(row.transaction_type)">{{ row.before_quantity ?? '—' }}</span>
|
||||
</template>
|
||||
<template #column-after_quantity="{ row }">
|
||||
<span :class="getStockClass(row.transaction_type)">{{ row.after_quantity ?? '—' }}</span>
|
||||
</template>
|
||||
<template #column-before_locked_quantity="{ row }">
|
||||
<span :class="getLockClass(row.transaction_type)">{{ row.before_locked_quantity ?? '—' }}</span>
|
||||
</template>
|
||||
<template #column-after_locked_quantity="{ row }">
|
||||
<span :class="getLockClass(row.transaction_type)">{{ row.after_locked_quantity ?? '—' }}</span>
|
||||
</template>
|
||||
<template #column-batch_no="{ row }">
|
||||
{{ row.batch_no || '—' }}
|
||||
@ -132,6 +149,19 @@
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<AsyncExportProgressDialog
|
||||
v-model:visible="exportDialogVisible"
|
||||
title="商品流水导出进度"
|
||||
:loading="exportLoading"
|
||||
:progress-percent="exportProgressPercent"
|
||||
:progress-status="exportProgressStatus"
|
||||
:status-label="exportStatusLabel"
|
||||
:task-id="exportTaskProgress.taskId"
|
||||
:message="exportTaskProgress.message"
|
||||
:error="exportTaskProgress.error"
|
||||
:update-time="exportTaskProgress.updateTime"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@ -142,11 +172,13 @@ import ScanBox from '@/components/ScanBox/index.vue'
|
||||
import UpperTable from '@/components/UpperTable/index.vue'
|
||||
import OrderToolbarButtonGroup from '@/views/order/orderManagement/component/OrderToolbarButtonGroup.vue'
|
||||
import type { ToolbarButtonConfig } from '@/views/order/orderManagement/config/order-common-config'
|
||||
import { stockTransactionList } from '@/api/stock/stock'
|
||||
import { stockTransactionList, transactionExport, transactionExportTaskProgress } from '@/api/stock/stock'
|
||||
import * as indexApi from '@/api/index/index'
|
||||
import { useSettingsStore } from '@/stores/modules/settings'
|
||||
import { useVerticalSplitPane } from '@/composables/useVerticalSplitPane'
|
||||
import { useAsyncExportTask } from '@/composables/useAsyncExportTask'
|
||||
import { safeInvoke } from '@/utils/safe-invoke'
|
||||
import AsyncExportProgressDialog from '@/components/AsyncExportProgressDialog.vue'
|
||||
import {
|
||||
columns as defaultColumns,
|
||||
availableFields,
|
||||
@ -185,11 +217,29 @@ const queryTime = ref(0)
|
||||
const list = ref<any[]>([])
|
||||
const selectedFlowId = ref<number | string | null>(null)
|
||||
const detailVisible = ref(true)
|
||||
|
||||
const {
|
||||
exportLoading,
|
||||
exportDialogVisible,
|
||||
exportTaskProgress,
|
||||
exportProgressPercent,
|
||||
exportProgressStatus,
|
||||
exportStatusLabel,
|
||||
submitExportTaskWithMode,
|
||||
resumeExportTaskFromStorage,
|
||||
hasPendingExportTask
|
||||
} = useAsyncExportTask({
|
||||
storageKey: 'stock.transaction.export.taskId',
|
||||
submitExport: (payload) => transactionExport(payload as any),
|
||||
queryProgress: (params) => transactionExportTaskProgress(params)
|
||||
})
|
||||
|
||||
const pagination = reactive({ currentPage: 1, pageSize: 20, total: 0 })
|
||||
const tableSize = ref('small')
|
||||
const columns = ref(defaultColumns)
|
||||
const currentCondition = ref<any>(null)
|
||||
const currentSort = reactive({ prop: 'created_at', order: 'DESC' })
|
||||
const selectedIds = ref<number[]>([])
|
||||
|
||||
const toolbarButtons = productflowToolbarButtons
|
||||
|
||||
@ -231,7 +281,13 @@ const toolbarActionMap: Record<string, () => void> = {
|
||||
void loadList()
|
||||
},
|
||||
openColumnConfigPanel: () => openColumnConfigPanel(),
|
||||
toggleDetailVisible: () => toggleDetailVisible()
|
||||
toggleDetailVisible: () => toggleDetailVisible(),
|
||||
handleExportAll: () => {
|
||||
void handleExportAction('all')
|
||||
},
|
||||
handleExportSelected: () => {
|
||||
void handleExportAction('selected')
|
||||
}
|
||||
}
|
||||
|
||||
function handleToolbarButtonClick(action: ToolbarButtonConfig['action']) {
|
||||
@ -291,12 +347,45 @@ function formatQuantityDisplay(row: any): string {
|
||||
return String(qty)
|
||||
}
|
||||
|
||||
function getQuantityClass(row: any): string {
|
||||
/** 库存变动列:仅 INBOUND/OUTBOUND 有值,其余为 0 */
|
||||
function formatStockQuantity(row: any): string {
|
||||
const t = (row.transaction_type || '').toUpperCase()
|
||||
if (t === 'INBOUND' || t === 'OUTBOUND') return formatQuantityDisplay(row)
|
||||
return '0'
|
||||
}
|
||||
|
||||
/** 锁定变动列:仅 LOCK/UNLOCK 有值,其余为 0 */
|
||||
function formatLockQuantity(row: any): string {
|
||||
const t = (row.transaction_type || '').toUpperCase()
|
||||
if (t === 'LOCK' || t === 'UNLOCK') return formatQuantityDisplay(row)
|
||||
return '0'
|
||||
}
|
||||
|
||||
function getQuantityClass(row: any, mode?: 'stock' | 'lock'): string {
|
||||
const t = (row.transaction_type || '').toUpperCase()
|
||||
// 非目标类型 → 灰色
|
||||
if (mode === 'stock' && t !== 'INBOUND' && t !== 'OUTBOUND') return 'qty-flat'
|
||||
if (mode === 'lock' && t !== 'LOCK' && t !== 'UNLOCK') return 'qty-flat'
|
||||
|
||||
const qty = formatQuantityDelta(row)
|
||||
if (qty === undefined || qty === null || qty === 0) return 'qty-flat'
|
||||
return qty > 0 ? 'qty-up' : 'qty-down'
|
||||
}
|
||||
|
||||
function getStockClass(type?: string): string {
|
||||
const t = (type || '').toUpperCase()
|
||||
if (t === 'INBOUND') return 'stock-in'
|
||||
if (t === 'OUTBOUND') return 'stock-out'
|
||||
return ''
|
||||
}
|
||||
|
||||
function getLockClass(type?: string): string {
|
||||
const t = (type || '').toUpperCase()
|
||||
if (t === 'LOCK') return 'lock-lock'
|
||||
if (t === 'UNLOCK') return 'lock-unlock'
|
||||
return ''
|
||||
}
|
||||
|
||||
async function loadFilterData() {
|
||||
try {
|
||||
const [storesRes, presetRes]: any = await Promise.all([
|
||||
@ -388,6 +477,10 @@ function handleRowClick(row: any) {
|
||||
selectedFlowId.value = row?.id ?? null
|
||||
}
|
||||
|
||||
function handleSelectionChange(rows: any[]) {
|
||||
selectedIds.value = rows.map((r: any) => r.id).filter((id: any) => id != null)
|
||||
}
|
||||
|
||||
function handlePageChange(page: number) {
|
||||
pagination.currentPage = page
|
||||
loadList()
|
||||
@ -407,6 +500,41 @@ function handleSortChange(payload: { prop?: string; order?: string }) {
|
||||
loadList()
|
||||
}
|
||||
|
||||
// ─── 导出 ────────────────────────────────────────────────────────────────────
|
||||
|
||||
function buildExportPayload(mode: 'all' | 'selected'): Record<string, unknown> {
|
||||
const where: Record<string, any> = {}
|
||||
// 导出选中:用 ids 作为条件
|
||||
if (mode === 'selected' && selectedIds.value.length > 0) {
|
||||
where.ids = selectedIds.value
|
||||
} else if (mode === 'all') {
|
||||
// 导出全部:使用当前筛选条件
|
||||
Object.assign(where, currentCondition.value || {})
|
||||
}
|
||||
|
||||
return {
|
||||
where: Object.keys(where).length > 0 ? where : undefined,
|
||||
sort: {
|
||||
sortField: currentSort.prop || 'created_at',
|
||||
sortOrder: currentSort.order || 'DESC'
|
||||
},
|
||||
mode
|
||||
}
|
||||
}
|
||||
|
||||
async function handleExportAction(mode: 'all' | 'selected') {
|
||||
if (mode === 'selected' && selectedIds.value.length === 0) {
|
||||
ElMessage.warning('请先勾选要导出的流水记录')
|
||||
return
|
||||
}
|
||||
if (hasPendingExportTask()) {
|
||||
ElMessage.warning('检测到未完成导出任务,请等待当前任务完成后再试')
|
||||
resumeExportTaskFromStorage()
|
||||
return
|
||||
}
|
||||
await submitExportTaskWithMode(buildExportPayload(mode), mode)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadFilterData()
|
||||
loadList()
|
||||
@ -463,6 +591,26 @@ onMounted(() => {
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
|
||||
.stock-in {
|
||||
font-weight: 700;
|
||||
color: var(--el-color-success);
|
||||
}
|
||||
|
||||
.stock-out {
|
||||
font-weight: 700;
|
||||
color: var(--el-color-danger);
|
||||
}
|
||||
|
||||
.lock-lock {
|
||||
font-weight: 700;
|
||||
color: var(--el-color-warning);
|
||||
}
|
||||
|
||||
.lock-unlock {
|
||||
font-weight: 700;
|
||||
color: var(--el-color-info);
|
||||
}
|
||||
|
||||
.empty-tip {
|
||||
text-align: center;
|
||||
font-size: 13px;
|
||||
|
||||
@ -8,10 +8,8 @@ export function formatDateTime(dateStr: string | null | undefined): string {
|
||||
export const transactionTypeConfig: Record<string, { text: string; tagType: string }> = {
|
||||
INBOUND: { text: '入库', tagType: 'success' },
|
||||
OUTBOUND: { text: '出库', tagType: 'danger' },
|
||||
LOCK: { text: '锁定', tagType: 'warning' },
|
||||
UNLOCK: { text: '解锁', tagType: 'info' },
|
||||
ADJUST: { text: '调整', tagType: 'primary' },
|
||||
TRANSFER: { text: '移库', tagType: 'primary' }
|
||||
LOCK: { text: '锁定库存', tagType: 'warning' },
|
||||
UNLOCK: { text: '取消锁定', tagType: 'info' }
|
||||
}
|
||||
|
||||
export const orderTypeConfig: Record<string, string> = {
|
||||
@ -29,7 +27,8 @@ export const columns = [
|
||||
{ prop: 'stock_id', label: '商品ID', width: 90 },
|
||||
{ prop: 'store_id', label: '货主ID', width: 90 },
|
||||
{ prop: 'warehouse_id', label: '仓库ID', width: 90 },
|
||||
{ prop: 'quantity', label: '变动数量', width: 90 },
|
||||
{ prop: 'stock_quantity', label: '库存变动', width: 90 },
|
||||
{ prop: 'lock_quantity', label: '锁定变动', width: 90 },
|
||||
{ prop: 'before_quantity', label: '变动前库存', width: 100 },
|
||||
{ prop: 'after_quantity', label: '变动后库存', width: 100 },
|
||||
{ prop: 'before_locked_quantity', label: '变动前锁定', width: 100 },
|
||||
@ -46,6 +45,16 @@ export const columns = [
|
||||
export const productflowToolbarButtons: ToolbarButtonConfig[] = [
|
||||
{ key: 'refresh', label: '刷新', type: 'primary', size: 'small', loadingKey: 'loading', action: 'loadList' },
|
||||
{ key: 'columnConfig', label: '字段设置', size: 'small', action: 'openColumnConfigPanel' },
|
||||
{
|
||||
key: 'export',
|
||||
label: '导出',
|
||||
buttonType: 'dropdown',
|
||||
size: 'small',
|
||||
dropdownOptions: [
|
||||
{ label: '导出全部', action: 'handleExportAll' },
|
||||
{ label: '导出选中', action: 'handleExportSelected', divided: true }
|
||||
]
|
||||
},
|
||||
{
|
||||
key: 'toggleDetail',
|
||||
label: '显示详情',
|
||||
@ -123,6 +132,75 @@ export const availableFields = [
|
||||
}
|
||||
]
|
||||
|
||||
/** 货主侧筛选字段:仓库筛选替代货主筛选 */
|
||||
export const storeAvailableFields = [
|
||||
{
|
||||
label: '商品ID',
|
||||
value: 'stock_id',
|
||||
type: 'number',
|
||||
placeholder: '请输入商品ID',
|
||||
operators: ['eq'],
|
||||
defaultOperator: 'eq'
|
||||
},
|
||||
{
|
||||
label: '订单号',
|
||||
value: 'order_no',
|
||||
type: 'text',
|
||||
placeholder: '请输入订单号',
|
||||
operators: ['contains', 'eq'],
|
||||
defaultOperator: 'eq'
|
||||
},
|
||||
{
|
||||
label: '批次号',
|
||||
value: 'batch_no',
|
||||
type: 'text',
|
||||
placeholder: '请输入批次号',
|
||||
operators: ['contains', 'eq'],
|
||||
defaultOperator: 'eq'
|
||||
},
|
||||
{
|
||||
label: '操作人',
|
||||
value: 'operator_name',
|
||||
type: 'text',
|
||||
placeholder: '请输入操作人',
|
||||
operators: ['eq', 'contains'],
|
||||
defaultOperator: 'eq'
|
||||
},
|
||||
{
|
||||
label: '仓库',
|
||||
value: 'warehouse_id',
|
||||
type: 'select',
|
||||
multiple: true,
|
||||
filterable: true,
|
||||
options: [] as Array<{ label: string; value: unknown }>
|
||||
},
|
||||
{
|
||||
label: '流水时间',
|
||||
value: 'created_at',
|
||||
type: 'date',
|
||||
operators: ['between', 'eq', 'gt', 'lt'],
|
||||
defaultOperator: 'between'
|
||||
},
|
||||
{
|
||||
label: '流水类型',
|
||||
value: 'transaction_type',
|
||||
type: 'select',
|
||||
options: Object.entries(transactionTypeConfig).map(([value, cfg]) => ({
|
||||
label: cfg.text,
|
||||
value
|
||||
}))
|
||||
},
|
||||
{
|
||||
label: '订单类型',
|
||||
value: 'order_type',
|
||||
type: 'select',
|
||||
options: Object.entries(orderTypeConfig).map(([value, label]) => ({
|
||||
label,
|
||||
value
|
||||
}))
|
||||
}
|
||||
]
|
||||
|
||||
export function getTransactionTypeLabel(type: string): string {
|
||||
return transactionTypeConfig[type]?.text || type || '—'
|
||||
}
|
||||
@ -141,9 +219,23 @@ export function formatQuantityDelta(row: {
|
||||
after_quantity?: number
|
||||
transaction_type?: string
|
||||
}): number | undefined {
|
||||
if (row.quantity !== undefined && row.quantity !== null) return row.quantity
|
||||
const before = row.before_quantity
|
||||
const after = row.after_quantity
|
||||
if (before === undefined || after === undefined) return undefined
|
||||
return after - before
|
||||
let value: number | undefined
|
||||
if (row.quantity !== undefined && row.quantity !== null) {
|
||||
value = row.quantity
|
||||
} else {
|
||||
const before = row.before_quantity
|
||||
const after = row.after_quantity
|
||||
if (before === undefined || after === undefined) return undefined
|
||||
value = after - before
|
||||
}
|
||||
|
||||
if (value === undefined) return undefined
|
||||
|
||||
// 根据流水类型决定正负号:出库/锁定为负,入库/解锁为正
|
||||
const type = row.transaction_type?.toUpperCase() || ''
|
||||
const abs = Math.abs(value)
|
||||
if (type === 'OUTBOUND' || type === 'LOCK') {
|
||||
return -abs
|
||||
}
|
||||
return abs
|
||||
}
|
||||
|
||||
643
src/views/storage/productflow/store/index.vue
Normal file
643
src/views/storage/productflow/store/index.vue
Normal file
@ -0,0 +1,643 @@
|
||||
<template>
|
||||
<div class="order-sub-container" :style="{ height: containerHeight }">
|
||||
<scan-box
|
||||
ref="scanBox"
|
||||
cache-key="store-productflow"
|
||||
width="250px"
|
||||
:tree-props="{ children: 'children', label: 'label' }"
|
||||
:auto-submit="false"
|
||||
:preset-tree="presetTree"
|
||||
:available-fields="availableFieldsRef"
|
||||
@condition-change="handleConditionChange"
|
||||
@reset="handleConditionReset"
|
||||
@condition-clear="handleConditionClear"
|
||||
/>
|
||||
|
||||
<div class="main-content">
|
||||
<div class="toolbar">
|
||||
<div class="toolbar-left">
|
||||
<order-toolbar-button-group
|
||||
:buttons="toolbarButtons"
|
||||
:resolve-disabled="resolveButtonDisabled"
|
||||
:resolve-loading="resolveButtonLoading"
|
||||
:resolve-label="resolveButtonLabel"
|
||||
:layout-key="toolbarLayoutKey"
|
||||
@action="handleToolbarButtonClick"
|
||||
/>
|
||||
</div>
|
||||
<div class="toolbar-right">
|
||||
<WarehouseSelect
|
||||
v-model="selectedWarehouseId"
|
||||
@change="handleWarehouseChange"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="split-stack" ref="splitStackRef">
|
||||
<div class="upper-wrapper" :style="detailVisible ? upperPaneStyle : upperPaneFullStyle">
|
||||
<upper-table
|
||||
ref="upperTable"
|
||||
title="货主商品流水列表"
|
||||
default-align="center"
|
||||
table-id="store-productflow-list"
|
||||
:enable-column-config="true"
|
||||
:data="list"
|
||||
:columns="columns"
|
||||
:table-size="tableSize"
|
||||
:pagination="pagination"
|
||||
:show-index="true"
|
||||
show-selection
|
||||
:loading="loading"
|
||||
:query-time="queryTime"
|
||||
@current-change="handleRowClick"
|
||||
@selection-change="handleSelectionChange"
|
||||
@page-change="handlePageChange"
|
||||
@page-size-change="handlePageSizeChange"
|
||||
@sort-change="handleSortChange"
|
||||
@refresh="loadList"
|
||||
>
|
||||
<template #column-created_at="{ row }">
|
||||
{{ formatDateTime(row.created_at) }}
|
||||
</template>
|
||||
<template #column-transaction_type="{ row }">
|
||||
<el-tag size="small" :type="getTransactionTypeTag(row.transaction_type)" effect="light">
|
||||
{{ getTransactionTypeLabel(row.transaction_type) }}
|
||||
</el-tag>
|
||||
</template>
|
||||
<template #column-stock_quantity="{ row }">
|
||||
<span :class="getQuantityClass(row, 'stock')">{{ formatStockQuantity(row) }}</span>
|
||||
</template>
|
||||
<template #column-lock_quantity="{ row }">
|
||||
<span :class="getQuantityClass(row, 'lock')">{{ formatLockQuantity(row) }}</span>
|
||||
</template>
|
||||
<template #column-before_quantity="{ row }">
|
||||
<span :class="getStockClass(row.transaction_type)">{{ row.before_quantity ?? '—' }}</span>
|
||||
</template>
|
||||
<template #column-after_quantity="{ row }">
|
||||
<span :class="getStockClass(row.transaction_type)">{{ row.after_quantity ?? '—' }}</span>
|
||||
</template>
|
||||
<template #column-before_locked_quantity="{ row }">
|
||||
<span :class="getLockClass(row.transaction_type)">{{ row.before_locked_quantity ?? '—' }}</span>
|
||||
</template>
|
||||
<template #column-after_locked_quantity="{ row }">
|
||||
<span :class="getLockClass(row.transaction_type)">{{ row.after_locked_quantity ?? '—' }}</span>
|
||||
</template>
|
||||
<template #column-batch_no="{ row }">
|
||||
{{ row.batch_no || '—' }}
|
||||
</template>
|
||||
<template #column-order_type="{ row }">
|
||||
{{ getOrderTypeLabel(row.order_type) }}
|
||||
</template>
|
||||
<template #column-order_no="{ row }">
|
||||
{{ row.order_no || '—' }}
|
||||
</template>
|
||||
<template #column-operator_name="{ row }">
|
||||
{{ row.operator_name || '—' }}
|
||||
</template>
|
||||
<template #column-remark="{ row }">
|
||||
<span class="remark-text">{{ row.remark || '—' }}</span>
|
||||
</template>
|
||||
<template #empty>
|
||||
<div class="empty-tip">暂无商品流水</div>
|
||||
</template>
|
||||
</upper-table>
|
||||
</div>
|
||||
|
||||
<template v-if="detailVisible">
|
||||
<div
|
||||
class="pane-resizer"
|
||||
title="拖动调整列表与详情区域高度"
|
||||
@mousedown="beginSplitDrag"
|
||||
/>
|
||||
<div v-if="selectedFlowId" class="lower-level" :class="tableSize" :style="lowerPaneStyle">
|
||||
<div class="detail-header">
|
||||
<div class="detail-info">
|
||||
<span class="detail-title">流水详情 #{{ selectedFlowId }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="detail-container">
|
||||
<el-descriptions :column="2" border size="small">
|
||||
<el-descriptions-item label="流水ID">{{ selectedRowData.id }}</el-descriptions-item>
|
||||
<el-descriptions-item label="流水时间">{{ formatDateTime(selectedRowData.created_at) }}</el-descriptions-item>
|
||||
<el-descriptions-item label="流水类型">
|
||||
<el-tag size="small" :type="getTransactionTypeTag(selectedRowData.transaction_type)" effect="light">
|
||||
{{ getTransactionTypeLabel(selectedRowData.transaction_type) }}
|
||||
</el-tag>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="操作人">{{ selectedRowData.operator_name || '—' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="商品ID">{{ selectedRowData.stock_id ?? '—' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="仓库ID">{{ selectedRowData.warehouse_id ?? '—' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="批次号">{{ selectedRowData.batch_no || '—' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="变动数量">
|
||||
<span :class="getQuantityClass(selectedRowData)">{{ formatQuantityDisplay(selectedRowData) }}</span>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="可用库存">
|
||||
{{ selectedRowData.before_quantity ?? '—' }} → {{ selectedRowData.after_quantity ?? '—' }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="锁定库存">
|
||||
{{ selectedRowData.before_locked_quantity ?? '—' }} → {{ selectedRowData.after_locked_quantity ?? '—' }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="订单类型">{{ getOrderTypeLabel(selectedRowData.order_type) }}</el-descriptions-item>
|
||||
<el-descriptions-item label="订单号">{{ selectedRowData.order_no || '—' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="订单ID">{{ selectedRowData.order_id || '—' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="收货单ID">{{ selectedRowData.receiving_id || '—' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="入库单ID">{{ selectedRowData.entry_order_id || '—' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="备注" :span="2">{{ selectedRowData.remark || '—' }}</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="no-selection" :style="lowerPaneStyle">
|
||||
<div class="empty-tip">
|
||||
<p>请从上方列表中选择一项查看详情</p>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<AsyncExportProgressDialog
|
||||
v-model:visible="exportDialogVisible"
|
||||
title="商品流水导出进度"
|
||||
:loading="exportLoading"
|
||||
:progress-percent="exportProgressPercent"
|
||||
:progress-status="exportProgressStatus"
|
||||
:status-label="exportStatusLabel"
|
||||
:task-id="exportTaskProgress.taskId"
|
||||
:message="exportTaskProgress.message"
|
||||
:error="exportTaskProgress.error"
|
||||
:update-time="exportTaskProgress.updateTime"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, computed, onMounted } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import ScanBox from '@/components/ScanBox/index.vue'
|
||||
import UpperTable from '@/components/UpperTable/index.vue'
|
||||
import WarehouseSelect from '@/components/WarehouseSelect.vue'
|
||||
import OrderToolbarButtonGroup from '@/views/order/orderManagement/component/OrderToolbarButtonGroup.vue'
|
||||
import type { ToolbarButtonConfig } from '@/views/order/orderManagement/config/order-common-config'
|
||||
import { stockTransactionStoreList, transactionExportStore, transactionExportTaskProgress } from '@/api/stock/stock'
|
||||
import * as indexApi from '@/api/index/index'
|
||||
import { useSettingsStore } from '@/stores/modules/settings'
|
||||
import { useUserStore } from '@/stores/modules/user'
|
||||
import { useVerticalSplitPane } from '@/composables/useVerticalSplitPane'
|
||||
import { useAsyncExportTask } from '@/composables/useAsyncExportTask'
|
||||
import { safeInvoke } from '@/utils/safe-invoke'
|
||||
import AsyncExportProgressDialog from '@/components/AsyncExportProgressDialog.vue'
|
||||
import {
|
||||
columns as defaultColumns,
|
||||
availableFields,
|
||||
productflowToolbarButtons,
|
||||
formatDateTime,
|
||||
getTransactionTypeLabel,
|
||||
getTransactionTypeTag,
|
||||
getOrderTypeLabel,
|
||||
formatQuantityDelta
|
||||
} from '../productflow-config'
|
||||
|
||||
const scanBox = ref<any>(null)
|
||||
const upperTable = ref<any>(null)
|
||||
const presetTree = ref<any[]>([])
|
||||
const availableFieldsRef = reactive(
|
||||
JSON.parse(JSON.stringify(availableFields)).filter((f: any) => f.value !== 'store_id')
|
||||
)
|
||||
|
||||
const settingsStore = useSettingsStore()
|
||||
const userStore = useUserStore()
|
||||
const shortcutExpanded = computed(() => settingsStore.shortcutExpanded)
|
||||
const containerHeight = computed(() => shortcutExpanded.value ? 'calc(100vh - 150px)' : 'calc(100vh - 100px)')
|
||||
|
||||
const {
|
||||
splitStackRef,
|
||||
beginSplitDrag,
|
||||
lowerPaneStyle,
|
||||
upperPaneStyle
|
||||
} = useVerticalSplitPane({ defaultLowerPercent: 40 })
|
||||
|
||||
const upperPaneFullStyle = computed(() => ({
|
||||
flex: '1 1 auto',
|
||||
minHeight: '0',
|
||||
overflow: 'hidden'
|
||||
}))
|
||||
|
||||
const loading = ref(false)
|
||||
const queryTime = ref(0)
|
||||
const list = ref<any[]>([])
|
||||
const selectedFlowId = ref<number | string | null>(null)
|
||||
const detailVisible = ref(true)
|
||||
|
||||
const {
|
||||
exportLoading,
|
||||
exportDialogVisible,
|
||||
exportTaskProgress,
|
||||
exportProgressPercent,
|
||||
exportProgressStatus,
|
||||
exportStatusLabel,
|
||||
submitExportTaskWithMode,
|
||||
resumeExportTaskFromStorage,
|
||||
hasPendingExportTask
|
||||
} = useAsyncExportTask({
|
||||
storageKey: 'stock.transaction.exportStore.taskId',
|
||||
submitExport: (payload) => transactionExportStore(payload as any),
|
||||
queryProgress: (params) => transactionExportTaskProgress(params)
|
||||
})
|
||||
|
||||
const pagination = reactive({ currentPage: 1, pageSize: 20, total: 0 })
|
||||
const tableSize = ref('small')
|
||||
const columns = ref(defaultColumns)
|
||||
const currentCondition = ref<any>(null)
|
||||
const currentSort = reactive({ prop: 'created_at', order: 'DESC' })
|
||||
const selectedWarehouseId = ref<string | number | null>(null)
|
||||
const selectedIds = ref<number[]>([])
|
||||
|
||||
const toolbarButtons = productflowToolbarButtons
|
||||
|
||||
const buttonLoadingMap = computed(() => ({
|
||||
loading: loading.value
|
||||
}))
|
||||
|
||||
const buttonLabelMap = computed(() => ({
|
||||
detailToggleLabel: detailVisible.value ? '隐藏详情' : '显示详情'
|
||||
}))
|
||||
|
||||
const toolbarLayoutKey = computed(() =>
|
||||
JSON.stringify({
|
||||
loading: buttonLoadingMap.value,
|
||||
labels: buttonLabelMap.value
|
||||
})
|
||||
)
|
||||
|
||||
const selectedRowData = computed(() => {
|
||||
return list.value.find(item => item.id === selectedFlowId.value) || {}
|
||||
})
|
||||
|
||||
function resolveButtonLoading(loadingKey?: string) {
|
||||
if (!loadingKey) return false
|
||||
return Boolean((buttonLoadingMap.value as Record<string, boolean>)[loadingKey])
|
||||
}
|
||||
|
||||
function resolveButtonDisabled(_disabledKey?: string) {
|
||||
return false
|
||||
}
|
||||
|
||||
function resolveButtonLabel(defaultLabel: string, dynamicLabelKey?: string) {
|
||||
if (!dynamicLabelKey) return defaultLabel
|
||||
return (buttonLabelMap.value as Record<string, string>)[dynamicLabelKey] || defaultLabel
|
||||
}
|
||||
|
||||
const toolbarActionMap: Record<string, () => void> = {
|
||||
loadList: () => {
|
||||
void loadList()
|
||||
},
|
||||
openColumnConfigPanel: () => openColumnConfigPanel(),
|
||||
toggleDetailVisible: () => toggleDetailVisible(),
|
||||
handleExportAll: () => {
|
||||
void handleExportAction('all')
|
||||
},
|
||||
handleExportSelected: () => {
|
||||
void handleExportAction('selected')
|
||||
}
|
||||
}
|
||||
|
||||
function handleToolbarButtonClick(action: ToolbarButtonConfig['action']) {
|
||||
const handler = toolbarActionMap[action]
|
||||
if (!handler) return
|
||||
safeInvoke(() => handler())
|
||||
}
|
||||
|
||||
function toggleDetailVisible() {
|
||||
detailVisible.value = !detailVisible.value
|
||||
}
|
||||
|
||||
function openColumnConfigPanel() {
|
||||
upperTable.value?.openColumnConfig?.()
|
||||
}
|
||||
|
||||
function normalizeToWhere(condition: any) {
|
||||
if (!condition) return {}
|
||||
|
||||
if (condition.conditions && typeof condition.conditions === 'object') {
|
||||
const where: Record<string, any> = {}
|
||||
Object.keys(condition.conditions).forEach(k => {
|
||||
const c = condition.conditions[k]
|
||||
if (c && typeof c === 'object' && c.value !== undefined) {
|
||||
where[k] = c.operator
|
||||
? { operator: c.operator, value: c.value, type: c.type }
|
||||
: c.value
|
||||
} else if (c !== undefined) {
|
||||
where[k] = c
|
||||
}
|
||||
})
|
||||
return where
|
||||
}
|
||||
|
||||
if (typeof condition === 'object') {
|
||||
const where: Record<string, any> = {}
|
||||
Object.keys(condition).forEach(k => {
|
||||
const c = condition[k]
|
||||
if (c && typeof c === 'object' && c.value !== undefined) {
|
||||
where[k] = c.operator
|
||||
? { operator: c.operator, value: c.value, type: c.type }
|
||||
: c.value
|
||||
} else if (c !== undefined) {
|
||||
where[k] = c
|
||||
}
|
||||
})
|
||||
return where
|
||||
}
|
||||
|
||||
return {}
|
||||
}
|
||||
|
||||
function formatQuantityDisplay(row: any): string {
|
||||
const qty = formatQuantityDelta(row)
|
||||
if (qty === undefined || qty === null) return '—'
|
||||
if (qty > 0) return `+${qty}`
|
||||
return String(qty)
|
||||
}
|
||||
|
||||
/** 库存变动列:仅 INBOUND/OUTBOUND 有值,其余为 0 */
|
||||
function formatStockQuantity(row: any): string {
|
||||
const t = (row.transaction_type || '').toUpperCase()
|
||||
if (t === 'INBOUND' || t === 'OUTBOUND') return formatQuantityDisplay(row)
|
||||
return '0'
|
||||
}
|
||||
|
||||
/** 锁定变动列:仅 LOCK/UNLOCK 有值,其余为 0 */
|
||||
function formatLockQuantity(row: any): string {
|
||||
const t = (row.transaction_type || '').toUpperCase()
|
||||
if (t === 'LOCK' || t === 'UNLOCK') return formatQuantityDisplay(row)
|
||||
return '0'
|
||||
}
|
||||
|
||||
function getQuantityClass(row: any, mode?: 'stock' | 'lock'): string {
|
||||
const t = (row.transaction_type || '').toUpperCase()
|
||||
// 非目标类型 → 灰色
|
||||
if (mode === 'stock' && t !== 'INBOUND' && t !== 'OUTBOUND') return 'qty-flat'
|
||||
if (mode === 'lock' && t !== 'LOCK' && t !== 'UNLOCK') return 'qty-flat'
|
||||
|
||||
const qty = formatQuantityDelta(row)
|
||||
if (qty === undefined || qty === null || qty === 0) return 'qty-flat'
|
||||
return qty > 0 ? 'qty-up' : 'qty-down'
|
||||
}
|
||||
|
||||
function getStockClass(type?: string): string {
|
||||
const t = (type || '').toUpperCase()
|
||||
if (t === 'INBOUND') return 'stock-in'
|
||||
if (t === 'OUTBOUND') return 'stock-out'
|
||||
return ''
|
||||
}
|
||||
|
||||
function getLockClass(type?: string): string {
|
||||
const t = (type || '').toUpperCase()
|
||||
if (t === 'LOCK') return 'lock-lock'
|
||||
if (t === 'UNLOCK') return 'lock-unlock'
|
||||
return ''
|
||||
}
|
||||
|
||||
async function loadFilterData() {
|
||||
try {
|
||||
const presetRes: any = await indexApi.fastWhereTree('stock')
|
||||
if (presetRes?.code === 200) {
|
||||
presetTree.value = presetRes.presetTree || []
|
||||
}
|
||||
} catch {
|
||||
// 筛选项加载失败不阻塞列表
|
||||
}
|
||||
}
|
||||
|
||||
async function loadList() {
|
||||
if (loading.value) return
|
||||
const storeId = userStore.user?.store_id
|
||||
if (!storeId) {
|
||||
ElMessage.warning('未获取到货主信息')
|
||||
return
|
||||
}
|
||||
|
||||
loading.value = true
|
||||
const start = Date.now()
|
||||
try {
|
||||
const where: Record<string, any> = { ...(currentCondition.value || {}) }
|
||||
// 顶部仓库选择器选中的仓库会覆盖/补充 where 条件
|
||||
if (selectedWarehouseId.value !== null && selectedWarehouseId.value !== '') {
|
||||
where.warehouse_id = Number(selectedWarehouseId.value)
|
||||
}
|
||||
|
||||
const res: any = await stockTransactionStoreList({
|
||||
store_id: Number(storeId),
|
||||
where: Object.keys(where).length > 0 ? where : undefined,
|
||||
pagination: {
|
||||
page: pagination.currentPage,
|
||||
pageSize: pagination.pageSize
|
||||
},
|
||||
sort: {
|
||||
sortField: currentSort.prop || 'created_at',
|
||||
sortOrder: currentSort.order || 'DESC'
|
||||
}
|
||||
})
|
||||
|
||||
const payload = res?.data ?? res
|
||||
if (payload?.flag === 'success' || payload?.code === 200 || payload?.code === 1 || Array.isArray(payload?.list)) {
|
||||
list.value = payload.list || []
|
||||
const pg = payload.pagination || {}
|
||||
pagination.currentPage = pg.page || pagination.currentPage
|
||||
pagination.pageSize = pg.pageSize || pagination.pageSize
|
||||
pagination.total = pg.total || 0
|
||||
queryTime.value = Date.now() - start
|
||||
|
||||
if (selectedFlowId.value && !list.value.some(item => item.id === selectedFlowId.value)) {
|
||||
selectedFlowId.value = null
|
||||
}
|
||||
} else {
|
||||
list.value = []
|
||||
pagination.total = 0
|
||||
selectedFlowId.value = null
|
||||
ElMessage.error(payload?.message || '获取商品流水失败')
|
||||
}
|
||||
} catch {
|
||||
list.value = []
|
||||
pagination.total = 0
|
||||
selectedFlowId.value = null
|
||||
ElMessage.error('获取商品流水失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function handleConditionChange(condition: any) {
|
||||
currentCondition.value = normalizeToWhere(condition)
|
||||
pagination.currentPage = 1
|
||||
loadList()
|
||||
}
|
||||
|
||||
function handleConditionClear() {
|
||||
currentCondition.value = null
|
||||
pagination.currentPage = 1
|
||||
loadList()
|
||||
}
|
||||
|
||||
function handleConditionReset() {
|
||||
currentCondition.value = null
|
||||
pagination.currentPage = 1
|
||||
if (scanBox.value?.reset) {
|
||||
scanBox.value.reset()
|
||||
} else if (scanBox.value?.clear) {
|
||||
scanBox.value.clear()
|
||||
}
|
||||
loadList()
|
||||
}
|
||||
|
||||
function handleRowClick(row: any) {
|
||||
selectedFlowId.value = row?.id ?? null
|
||||
}
|
||||
|
||||
function handleSelectionChange(rows: any[]) {
|
||||
selectedIds.value = rows.map((r: any) => r.id).filter((id: any) => id != null)
|
||||
}
|
||||
|
||||
function handlePageChange(page: number) {
|
||||
pagination.currentPage = page
|
||||
loadList()
|
||||
}
|
||||
|
||||
function handlePageSizeChange(size: number) {
|
||||
pagination.pageSize = size
|
||||
pagination.currentPage = 1
|
||||
loadList()
|
||||
}
|
||||
|
||||
function handleSortChange(payload: { prop?: string; order?: string }) {
|
||||
currentSort.prop = payload?.prop || 'created_at'
|
||||
const order = String(payload?.order || '').toLowerCase()
|
||||
currentSort.order = order === 'ascending' ? 'ASC' : order === 'descending' ? 'DESC' : 'DESC'
|
||||
pagination.currentPage = 1
|
||||
loadList()
|
||||
}
|
||||
|
||||
function handleWarehouseChange() {
|
||||
pagination.currentPage = 1
|
||||
loadList()
|
||||
}
|
||||
|
||||
// ─── 导出 ────────────────────────────────────────────────────────────────────
|
||||
|
||||
function buildExportPayload(mode: 'all' | 'selected'): Record<string, unknown> {
|
||||
const storeId = userStore.user?.store_id
|
||||
const where: Record<string, any> = {}
|
||||
if (mode === 'selected' && selectedIds.value.length > 0) {
|
||||
where.ids = selectedIds.value
|
||||
} else if (mode === 'all') {
|
||||
Object.assign(where, currentCondition.value || {})
|
||||
if (selectedWarehouseId.value !== null && selectedWarehouseId.value !== '') {
|
||||
where.warehouse_id = Number(selectedWarehouseId.value)
|
||||
}
|
||||
}
|
||||
return {
|
||||
store_id: storeId ? Number(storeId) : undefined,
|
||||
where: Object.keys(where).length > 0 ? where : undefined,
|
||||
sort: {
|
||||
sortField: currentSort.prop || 'created_at',
|
||||
sortOrder: currentSort.order || 'DESC'
|
||||
},
|
||||
mode
|
||||
}
|
||||
}
|
||||
|
||||
async function handleExportAction(mode: 'all' | 'selected') {
|
||||
if (mode === 'selected' && selectedIds.value.length === 0) {
|
||||
ElMessage.warning('请先勾选要导出的流水记录')
|
||||
return
|
||||
}
|
||||
if (hasPendingExportTask()) {
|
||||
ElMessage.warning('检测到未完成导出任务,请等待当前任务完成后再试')
|
||||
resumeExportTaskFromStorage()
|
||||
return
|
||||
}
|
||||
await submitExportTaskWithMode(buildExportPayload(mode), mode)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadFilterData()
|
||||
loadList()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
@use "../../../order/orderManagement/styles/order-sub.scss";
|
||||
|
||||
.order-sub-container .main-content .lower-level .detail-container {
|
||||
padding: 10px;
|
||||
overflow: auto;
|
||||
|
||||
:deep(.el-descriptions__label) {
|
||||
width: 100px;
|
||||
}
|
||||
}
|
||||
|
||||
.order-sub-container .main-content .lower-level .detail-header {
|
||||
padding: 10px;
|
||||
|
||||
.detail-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
|
||||
.detail-title {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: #303133;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.remark-text {
|
||||
display: inline-block;
|
||||
max-width: 100%;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.qty-up {
|
||||
color: var(--el-color-success);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.qty-down {
|
||||
color: var(--el-color-danger);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.qty-flat {
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
|
||||
.stock-in {
|
||||
font-weight: 700;
|
||||
color: var(--el-color-success);
|
||||
}
|
||||
|
||||
.stock-out {
|
||||
font-weight: 700;
|
||||
color: var(--el-color-danger);
|
||||
}
|
||||
|
||||
.lock-lock {
|
||||
font-weight: 700;
|
||||
color: var(--el-color-warning);
|
||||
}
|
||||
|
||||
.lock-unlock {
|
||||
font-weight: 700;
|
||||
color: var(--el-color-info);
|
||||
}
|
||||
|
||||
.empty-tip {
|
||||
text-align: center;
|
||||
font-size: 13px;
|
||||
line-height: 1.5;
|
||||
max-width: 360px;
|
||||
}
|
||||
</style>
|
||||
@ -46,6 +46,13 @@
|
||||
</el-tag>
|
||||
</template>
|
||||
|
||||
<template #column-device_ids="{ row }">
|
||||
<el-tag v-if="Array.isArray(row.device_ids) && row.device_ids.length > 0" type="success" size="small">
|
||||
已绑定 {{ row.device_ids.length }} 个
|
||||
</el-tag>
|
||||
<el-tag v-else type="info" size="small">未绑定</el-tag>
|
||||
</template>
|
||||
|
||||
<template #column-created_at="{ row }">
|
||||
<el-text size="small">{{ formatTime(row.created_at) }}</el-text>
|
||||
</template>
|
||||
@ -57,6 +64,7 @@
|
||||
<template #column-actions="{ row }">
|
||||
<el-button link type="primary" size="small" @click.stop="openDetail(row)">详情</el-button>
|
||||
<el-button link type="primary" size="small" @click.stop="openEdit(row)">编辑</el-button>
|
||||
<el-button link type="success" size="small" @click.stop="openBindCamera(row)">摄像头</el-button>
|
||||
<el-button link type="danger" size="small" @click.stop="handleDelete(row)">删除</el-button>
|
||||
</template>
|
||||
|
||||
@ -129,12 +137,60 @@
|
||||
<el-empty v-else-if="!detailLoading" description="暂无详情" />
|
||||
</div>
|
||||
</el-drawer>
|
||||
|
||||
<!-- 绑定摄像头 -->
|
||||
<el-dialog
|
||||
v-model="bindCameraVisible"
|
||||
:title="`绑定摄像头 — ${bindCameraWorkbenchName}`"
|
||||
width="640px"
|
||||
align-center
|
||||
@close="resetBindCamera"
|
||||
>
|
||||
<div v-loading="bindCameraLoading" class="bind-camera-body">
|
||||
<div class="bind-camera-toolbar">
|
||||
<el-input
|
||||
v-model="cameraSearchKeyword"
|
||||
placeholder="搜索摄像头名称"
|
||||
clearable
|
||||
size="small"
|
||||
style="width: 240px"
|
||||
@input="filterCameraList"
|
||||
>
|
||||
<template #prefix>
|
||||
<el-icon><Search /></el-icon>
|
||||
</template>
|
||||
</el-input>
|
||||
<div class="bind-camera-count">
|
||||
已选 <strong>{{ selectedCameraIds.length }}</strong> / {{ allCameras.length }} 个摄像头
|
||||
</div>
|
||||
</div>
|
||||
<el-checkbox-group v-model="selectedCameraIds" class="camera-checkbox-group">
|
||||
<el-checkbox
|
||||
v-for="cam in filteredCameras"
|
||||
:key="cam.id"
|
||||
:label="cam.id"
|
||||
class="camera-checkbox-item"
|
||||
>
|
||||
<div class="camera-item-info">
|
||||
<span class="camera-item-name">{{ cam.custom_name || cam.channel_name || `摄像头-${cam.id}` }}</span>
|
||||
<span class="camera-item-server">{{ cam.server?.name || '' }}</span>
|
||||
</div>
|
||||
</el-checkbox>
|
||||
</el-checkbox-group>
|
||||
<el-empty v-if="filteredCameras.length === 0 && !bindCameraLoading" description="暂无摄像头" :image-size="60" />
|
||||
</div>
|
||||
<template #footer>
|
||||
<el-button @click="bindCameraVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="bindCameraSaving" @click="submitBindCamera">保存</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 { Search } from '@element-plus/icons-vue'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
import ScanBox from '@/components/ScanBox/index.vue'
|
||||
import UpperTable from '@/components/UpperTable/index.vue'
|
||||
@ -144,8 +200,10 @@ import {
|
||||
create as workbenchCreate,
|
||||
update as workbenchUpdate,
|
||||
del as workbenchDelete,
|
||||
checkBarcode as workbenchCheckBarcode
|
||||
checkBarcode as workbenchCheckBarcode,
|
||||
bindCamera as workbenchBindCamera
|
||||
} from '@/api/workbench/workbench'
|
||||
import { list as cameraList } from '@/api/camera/camera'
|
||||
import { useSettingsStore } from '@/stores/modules/settings'
|
||||
import {
|
||||
buildWorkbenchListPayload,
|
||||
@ -382,6 +440,97 @@ async function openDetail(row: WorkbenchRecord) {
|
||||
}
|
||||
}
|
||||
|
||||
// ─── 绑定摄像头 ──────────────────────────────────────────────────────────────
|
||||
|
||||
type CameraOption = {
|
||||
id: number
|
||||
channel_name?: string
|
||||
custom_name?: string
|
||||
server?: { id?: number; name?: string }
|
||||
}
|
||||
|
||||
const bindCameraVisible = ref(false)
|
||||
const bindCameraLoading = ref(false)
|
||||
const bindCameraSaving = ref(false)
|
||||
const bindCameraWorkbenchId = ref<number | undefined>(undefined)
|
||||
const bindCameraWorkbenchName = ref('')
|
||||
const allCameras = ref<CameraOption[]>([])
|
||||
const filteredCameras = ref<CameraOption[]>([])
|
||||
const selectedCameraIds = ref<number[]>([])
|
||||
const cameraSearchKeyword = ref('')
|
||||
|
||||
function filterCameraList() {
|
||||
const keyword = cameraSearchKeyword.value.trim().toLowerCase()
|
||||
if (!keyword) {
|
||||
filteredCameras.value = allCameras.value
|
||||
return
|
||||
}
|
||||
filteredCameras.value = allCameras.value.filter((cam) => {
|
||||
const name = (cam.custom_name || cam.channel_name || '').toLowerCase()
|
||||
const server = (cam.server?.name || '').toLowerCase()
|
||||
return name.includes(keyword) || server.includes(keyword)
|
||||
})
|
||||
}
|
||||
|
||||
async function openBindCamera(row: WorkbenchRecord) {
|
||||
if (!row.id) return
|
||||
bindCameraWorkbenchId.value = row.id
|
||||
bindCameraWorkbenchName.value = row.name || `工作台-${row.id}`
|
||||
bindCameraVisible.value = true
|
||||
bindCameraLoading.value = true
|
||||
cameraSearchKeyword.value = ''
|
||||
|
||||
// 从列表行数据中直接读取已绑定的 device_ids
|
||||
selectedCameraIds.value = Array.isArray(row.device_ids) ? [...row.device_ids] : []
|
||||
|
||||
try {
|
||||
const camRes: any = await cameraList({ pagination: { page: 1, pageSize: 999 } })
|
||||
if (isSuccess(camRes)) {
|
||||
allCameras.value = camRes?.list || []
|
||||
} else {
|
||||
allCameras.value = []
|
||||
}
|
||||
filterCameraList()
|
||||
} catch {
|
||||
allCameras.value = []
|
||||
filteredCameras.value = []
|
||||
} finally {
|
||||
bindCameraLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function resetBindCamera() {
|
||||
bindCameraWorkbenchId.value = undefined
|
||||
bindCameraWorkbenchName.value = ''
|
||||
allCameras.value = []
|
||||
filteredCameras.value = []
|
||||
selectedCameraIds.value = []
|
||||
cameraSearchKeyword.value = ''
|
||||
}
|
||||
|
||||
async function submitBindCamera() {
|
||||
if (bindCameraWorkbenchId.value === undefined || bindCameraSaving.value) return
|
||||
|
||||
bindCameraSaving.value = true
|
||||
try {
|
||||
const res: any = await workbenchBindCamera({
|
||||
id: bindCameraWorkbenchId.value,
|
||||
camera_ids: selectedCameraIds.value.length > 0 ? selectedCameraIds.value : undefined
|
||||
})
|
||||
if (isSuccess(res)) {
|
||||
ElMessage.success('摄像头绑定更新成功')
|
||||
bindCameraVisible.value = false
|
||||
loadList()
|
||||
} else {
|
||||
ElMessage.error(res?.message || '绑定失败')
|
||||
}
|
||||
} catch {
|
||||
ElMessage.error('绑定失败')
|
||||
} finally {
|
||||
bindCameraSaving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// ─── 删除 ────────────────────────────────────────────────────────────────────
|
||||
|
||||
async function handleDelete(row: WorkbenchRecord) {
|
||||
@ -460,4 +609,60 @@ onMounted(() => {
|
||||
padding: 20px 0;
|
||||
}
|
||||
}
|
||||
|
||||
// ─── 绑定摄像头弹窗 ──────────────────────────────────────────────────────────
|
||||
.bind-camera-body {
|
||||
min-height: 280px;
|
||||
max-height: 400px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.bind-camera-toolbar {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.bind-camera-count {
|
||||
font-size: 13px;
|
||||
color: #606266;
|
||||
}
|
||||
|
||||
.camera-checkbox-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.camera-checkbox-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 8px 12px;
|
||||
border: 1px solid #ebeef5;
|
||||
border-radius: 6px;
|
||||
margin-right: 0;
|
||||
transition: background 0.2s;
|
||||
|
||||
&:hover {
|
||||
background: #f5f7fa;
|
||||
}
|
||||
}
|
||||
|
||||
.camera-item-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
margin-left: 4px;
|
||||
|
||||
.camera-item-name {
|
||||
font-size: 14px;
|
||||
color: #303133;
|
||||
}
|
||||
|
||||
.camera-item-server {
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@ -4,7 +4,9 @@ export type WorkbenchRecord = {
|
||||
name?: string
|
||||
barcode?: string
|
||||
status?: number
|
||||
type?: string
|
||||
remark?: string
|
||||
device_ids?: number[] | null
|
||||
created_at?: string
|
||||
updated_at?: string
|
||||
deleted_at?: string | null
|
||||
@ -19,9 +21,10 @@ export const workbenchColumns = [
|
||||
{ prop: 'warehouse_id', label: '仓库ID', width: '100' },
|
||||
{ prop: 'status', label: '状态', width: '80' },
|
||||
{ prop: 'remark', label: '备注', minWidth: '140', showOverflowTooltip: true },
|
||||
{ prop: 'device_ids', label: '绑定摄像头', width: '120' },
|
||||
{ prop: 'created_at', label: '创建时间', minWidth: '160' },
|
||||
{ prop: 'updated_at', label: '更新时间', minWidth: '160' },
|
||||
{ prop: 'actions', label: '操作', width: '200', fixed: 'right' }
|
||||
{ prop: 'actions', label: '操作', width: '260', fixed: 'right' }
|
||||
]
|
||||
|
||||
export const workbenchScanFields = [
|
||||
|
||||
506
src/views/video/camera/index.vue
Normal file
506
src/views/video/camera/index.vue
Normal file
@ -0,0 +1,506 @@
|
||||
<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>
|
||||
493
src/views/video/cameraServer/index.vue
Normal file
493
src/views/video/cameraServer/index.vue
Normal file
@ -0,0 +1,493 @@
|
||||
<template>
|
||||
<div class="video-container" :style="{ height: containerHeight }">
|
||||
<scan-box
|
||||
ref="scanBox"
|
||||
cache-key="video-camera-server"
|
||||
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-server"
|
||||
: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-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="100px">
|
||||
<el-form-item label="服务器名称" prop="name">
|
||||
<el-input v-model="formData.name" placeholder="请输入服务器名称" maxlength="100" show-word-limit />
|
||||
</el-form-item>
|
||||
<el-form-item label="品牌" prop="brand">
|
||||
<el-select v-model="formData.brand" placeholder="请选择品牌" clearable style="width: 100%">
|
||||
<el-option label="海康威视" value="hikvision" />
|
||||
<el-option label="大华" value="dahua" />
|
||||
<el-option label="宇视" value="uniview" />
|
||||
<el-option label="其他" value="other" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="公网IP" prop="public_ip">
|
||||
<el-input v-model="formData.public_ip" placeholder="请输入公网IP" maxlength="50" />
|
||||
</el-form-item>
|
||||
<el-form-item label="内网IP" prop="internal_ip">
|
||||
<el-input v-model="formData.internal_ip" placeholder="请输入内网IP" maxlength="50" />
|
||||
</el-form-item>
|
||||
<el-form-item label="端口" prop="port">
|
||||
<el-input-number v-model="formData.port" :min="1" :max="65535" placeholder="请输入端口" style="width: 100%" />
|
||||
</el-form-item>
|
||||
<el-form-item label="用户名" prop="username">
|
||||
<el-input v-model="formData.username" placeholder="请输入用户名" maxlength="50" />
|
||||
</el-form-item>
|
||||
<el-form-item label="密码" prop="password">
|
||||
<el-input v-model="formData.password" type="password" placeholder="请输入密码" maxlength="50" show-password />
|
||||
</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_server/camera_server'
|
||||
import { useSettingsStore } from '@/stores/modules/settings'
|
||||
|
||||
type CameraServerRecord = {
|
||||
id?: number
|
||||
name?: string
|
||||
brand?: string
|
||||
public_ip?: string
|
||||
internal_ip?: string
|
||||
port?: number
|
||||
username?: string
|
||||
status?: number
|
||||
remark?: string
|
||||
created_at?: string
|
||||
updated_at?: 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: 'name', label: '服务器名称', minWidth: '160', showOverflowTooltip: true },
|
||||
{ prop: 'brand', label: '品牌', width: '120' },
|
||||
{ prop: 'public_ip', label: '公网IP', width: '150' },
|
||||
{ prop: 'internal_ip', label: '内网IP', width: '150' },
|
||||
{ prop: 'port', label: '端口', width: '80' },
|
||||
{ prop: 'username', label: '用户名', width: '120' },
|
||||
{ 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: '服务器名称/IP',
|
||||
operators: ['contains'],
|
||||
defaultOperator: 'contains'
|
||||
},
|
||||
{
|
||||
value: 'name',
|
||||
label: '服务器名称',
|
||||
type: 'text',
|
||||
placeholder: '请输入名称',
|
||||
operators: ['contains'],
|
||||
defaultOperator: 'contains'
|
||||
},
|
||||
{
|
||||
value: 'status',
|
||||
label: '状态',
|
||||
type: 'select',
|
||||
clearable: true,
|
||||
options: [
|
||||
{ label: '启用', value: '1' },
|
||||
{ label: '禁用', value: '0' }
|
||||
]
|
||||
},
|
||||
{
|
||||
value: 'brand',
|
||||
label: '品牌',
|
||||
type: 'select',
|
||||
clearable: true,
|
||||
options: [
|
||||
{ label: '海康威视', value: 'hikvision' },
|
||||
{ label: '大华', value: 'dahua' },
|
||||
{ label: '宇视', value: 'uniview' },
|
||||
{ label: '其他', value: 'other' }
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
const presetTree = ref<any[]>([])
|
||||
const loading = ref(false)
|
||||
const saving = ref(false)
|
||||
const tableData = ref<CameraServerRecord[]>([])
|
||||
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,
|
||||
name: '',
|
||||
brand: '',
|
||||
public_ip: '',
|
||||
internal_ip: '',
|
||||
port: undefined as number | undefined,
|
||||
username: '',
|
||||
password: '',
|
||||
status: 1 as number,
|
||||
remark: ''
|
||||
})
|
||||
|
||||
const rules: FormRules = {
|
||||
name: [{ required: true, message: '请输入服务器名称', 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') {
|
||||
where.status = 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
|
||||
}
|
||||
}
|
||||
|
||||
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.name = ''
|
||||
formData.brand = ''
|
||||
formData.public_ip = ''
|
||||
formData.internal_ip = ''
|
||||
formData.port = undefined
|
||||
formData.username = ''
|
||||
formData.password = ''
|
||||
formData.status = 1
|
||||
formData.remark = ''
|
||||
formRef.value?.clearValidate()
|
||||
}
|
||||
|
||||
function openCreate() {
|
||||
dialogMode.value = 'create'
|
||||
dialogVisible.value = true
|
||||
resetForm()
|
||||
}
|
||||
|
||||
function openEdit(row: CameraServerRecord) {
|
||||
if (!row.id) return
|
||||
dialogMode.value = 'edit'
|
||||
dialogVisible.value = true
|
||||
formData.id = row.id
|
||||
formData.name = row.name || ''
|
||||
formData.brand = row.brand || ''
|
||||
formData.public_ip = row.public_ip || ''
|
||||
formData.internal_ip = row.internal_ip || ''
|
||||
formData.port = row.port
|
||||
formData.username = row.username || ''
|
||||
formData.password = ''
|
||||
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({
|
||||
name: formData.name.trim(),
|
||||
brand: formData.brand || undefined,
|
||||
public_ip: formData.public_ip.trim() || undefined,
|
||||
internal_ip: formData.internal_ip.trim() || undefined,
|
||||
port: formData.port,
|
||||
username: formData.username.trim() || undefined,
|
||||
password: formData.password || 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,
|
||||
name: formData.name.trim() || undefined,
|
||||
brand: formData.brand || undefined,
|
||||
public_ip: formData.public_ip.trim() || undefined,
|
||||
internal_ip: formData.internal_ip.trim() || undefined,
|
||||
port: formData.port,
|
||||
username: formData.username.trim() || undefined,
|
||||
password: formData.password || 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: CameraServerRecord) {
|
||||
if (!row.id) return
|
||||
const name = row.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()
|
||||
})
|
||||
</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>
|
||||
Loading…
x
Reference in New Issue
Block a user