1
This commit is contained in:
parent
cd205c4853
commit
5ccc42fdbc
BIN
dist.tar.gz
BIN
dist.tar.gz
Binary file not shown.
90
src/api/print_computer/print_computer.ts
Normal file
90
src/api/print_computer/print_computer.ts
Normal file
@ -0,0 +1,90 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
const v = '1.0'
|
||||
|
||||
/** 打印电脑列表(仓库隔离,分页+筛选) */
|
||||
export function list(data?: {
|
||||
pagination?: { page?: number; pageSize?: number }
|
||||
where?: { name?: string; status?: number; is_recording?: number }
|
||||
}) {
|
||||
return request({
|
||||
url: '/system',
|
||||
method: 'post',
|
||||
params: {
|
||||
method: 'print_computer.list',
|
||||
v,
|
||||
timestamp: new Date().getTime()
|
||||
},
|
||||
data: data || {},
|
||||
isSystemApi: true
|
||||
} as any)
|
||||
}
|
||||
|
||||
/** 更新打印电脑 */
|
||||
export function update(data: {
|
||||
id: number
|
||||
name?: string
|
||||
}) {
|
||||
return request({
|
||||
url: '/system',
|
||||
method: 'post',
|
||||
params: {
|
||||
method: 'print_computer.update',
|
||||
v,
|
||||
timestamp: new Date().getTime()
|
||||
},
|
||||
data,
|
||||
isSystemApi: true
|
||||
} as any)
|
||||
}
|
||||
|
||||
/** 设置录制电脑(会先取消同仓库下其他录制电脑,再设置当前电脑) */
|
||||
export function setRecording(data: {
|
||||
id: number
|
||||
recording_size_value: number
|
||||
recording_size_unit: string
|
||||
remote_play_url: string
|
||||
recording_directory: string
|
||||
}) {
|
||||
return request({
|
||||
url: '/system',
|
||||
method: 'post',
|
||||
params: {
|
||||
method: 'print_computer.setRecording',
|
||||
v,
|
||||
timestamp: new Date().getTime()
|
||||
},
|
||||
data,
|
||||
isSystemApi: true
|
||||
} as any)
|
||||
}
|
||||
|
||||
/** 取消录制电脑(清除录制标记及相关参数) */
|
||||
export function cancelRecording(data: { id: number }) {
|
||||
return request({
|
||||
url: '/system',
|
||||
method: 'post',
|
||||
params: {
|
||||
method: 'print_computer.cancelRecording',
|
||||
v,
|
||||
timestamp: new Date().getTime()
|
||||
},
|
||||
data,
|
||||
isSystemApi: true
|
||||
} as any)
|
||||
}
|
||||
|
||||
/** 软删除打印电脑(若存在关联的未删除打印台则拒绝删除;成功后通知打印服务注销电脑连接) */
|
||||
export function del(data: { id: number }) {
|
||||
return request({
|
||||
url: '/system',
|
||||
method: 'post',
|
||||
params: {
|
||||
method: 'print_computer.delete',
|
||||
v,
|
||||
timestamp: new Date().getTime()
|
||||
},
|
||||
data,
|
||||
isSystemApi: true
|
||||
} as any)
|
||||
}
|
||||
@ -72,6 +72,7 @@ export default {
|
||||
'workbench':'Workbench',
|
||||
// 'OwnerReceiving':'Owner Receiving',
|
||||
'PackingFlow':'Packing Flow',
|
||||
'printcomputer':'Print Computer',
|
||||
},
|
||||
"login": {
|
||||
"title": "Login",
|
||||
|
||||
@ -75,6 +75,7 @@ export default {
|
||||
// 'OwnerReceiving':'仓库收货单',
|
||||
'WmsCameraServer':'录像服务器',
|
||||
'PackingFlow':'打包流水',
|
||||
'printcomputer':'打印电脑',
|
||||
},
|
||||
"login": {
|
||||
"title": "登录",
|
||||
|
||||
@ -38,7 +38,7 @@ export const componentMap: Record<string, any> = {
|
||||
'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'),
|
||||
'storage/productflow/store': (): Promise<any> => 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'),
|
||||
@ -66,4 +66,5 @@ export const componentMap: Record<string, any> = {
|
||||
'video/cameraServer/index': () => import('@/views/video/newcamaraserver/index.vue'),
|
||||
'video/camera/index': () => import('@/views/video/newcamara/index.vue'),
|
||||
'data/packingflow': () => import('@/views/data/packingflow/index.vue'),
|
||||
'system/setting/printcomputer/index':() => import('@/views/system/setting/printcomputer/index.vue'),
|
||||
};
|
||||
@ -728,7 +728,7 @@ export const orderDetailFullSections: OrderDetailSectionConfig[] = [
|
||||
column: 4,
|
||||
fields: [
|
||||
{ prop: 'id', label: '订单ID' },
|
||||
{ prop: 'delivery_order_code', label: '发货单号' },
|
||||
{ prop: 'delivery_order_code', label: '外部订单号' },
|
||||
{ prop: 'pre_delivery_order_code', label: '前置单号' },
|
||||
{ prop: 'pre_delivery_order_id', label: '前置单ID' },
|
||||
{ prop: 'order_type', label: '订单类型' },
|
||||
@ -853,7 +853,7 @@ export const orderDetailCompactSections: OrderDetailSectionConfig[] = [
|
||||
title: '基础信息',
|
||||
column: 3,
|
||||
fields: [
|
||||
{ prop: 'delivery_order_code', label: '发货单号' },
|
||||
{ prop: 'delivery_order_code', label: '外部订单号' },
|
||||
{ prop: 'order_type', label: '订单类型' },
|
||||
{ prop: 'sys_platform_name', label: '平台' },
|
||||
{ prop: 'create_channel', label: '来源' },
|
||||
@ -1155,6 +1155,8 @@ export const orderIdScanField = scanBasicField({ label: '订单ID', value: 'id',
|
||||
export const orderFlagScanField = scanBasicField({ label: '订单标记', value: 'order_flag', type: 'text', operators: ['like', 'notlike'], defaultOperator: 'like' })
|
||||
export const waveNoScanField = scanBasicField({ label: '波次号', value: 'wave_no', type: 'text', operators: ORDER_BULK_SEARCH_OPERATORS, defaultOperator: 'eq' })
|
||||
export const deliveryOrderCodeScanField = scanBasicField({ label: '发货单号', value: 'delivery_order_code', type: 'text', operators: ORDER_BULK_SEARCH_OPERATORS, defaultOperator: 'eq' })
|
||||
/** ScanBox:外部订单号(待处理订单专用,模糊匹配发货单号,替代表格右上角快捷搜索) */
|
||||
export const pendingOrderQuickSearchScanField = scanBasicField({ label: '外部订单号', value: 'delivery_order_code', type: 'text', operators: ORDER_BULK_SEARCH_OPERATORS, defaultOperator: 'like' })
|
||||
/** ScanBox:搜索订单号(模糊匹配发货单号,替代表格右上角快捷搜索) */
|
||||
export const orderQuickSearchScanField = scanBasicField({ label: '搜索订单号', value: 'delivery_order_code', type: 'text', operators: ORDER_BULK_SEARCH_OPERATORS, defaultOperator: 'like' })
|
||||
export const sourceOrderCodesScanField = scanBasicField({ label: '平台交易单号', value: 'source_order_codes', type: 'text', operators: ORDER_BULK_SEARCH_OPERATORS, defaultOperator: 'eq' })
|
||||
@ -1626,7 +1628,7 @@ export const pendingAvailableFields = [
|
||||
// 基础信息
|
||||
storeScanField,
|
||||
orderIdScanField,
|
||||
orderQuickSearchScanField,
|
||||
pendingOrderQuickSearchScanField,
|
||||
// pendingOrderCodeScanField,
|
||||
sourceOrderCodesScanField,
|
||||
orderFlagScanField,
|
||||
@ -1660,7 +1662,7 @@ export const pendingAvailableFields = [
|
||||
|
||||
export const pendingCloums = [
|
||||
{ prop: 'id', label: '订单ID', width: '80' },
|
||||
{ prop: 'delivery_order_code', label: '发货单号', width: '170' ,fixed: 'left'},
|
||||
{ prop: 'delivery_order_code', label: '外部订单号', width: '170' ,fixed: 'left'},
|
||||
{ prop: 'wave_no', label: '波次号', width: '170' },
|
||||
{ prop: 'order_flag', label: '订单标记', minWidth: '260' },
|
||||
{ prop: 'shop_nick', label: '店铺名称', width: '140' },
|
||||
@ -1743,7 +1745,7 @@ export function buildPendingStyleColumns(baseColumns: ReadonlyArray<{ prop: stri
|
||||
|
||||
export const pendingOrderDetail = [
|
||||
// 基础信息
|
||||
{ prop: 'delivery_order_code', label: '发货单号' },
|
||||
{ prop: 'delivery_order_code', label: '外部订单号' },
|
||||
{ prop: 'pre_delivery_order_code', label: '前置单号' },
|
||||
{ prop: 'order_type', label: '订单类型' },
|
||||
{ prop: 'order_flag', label: '订单标记' },
|
||||
|
||||
@ -94,8 +94,8 @@ export const comboGoodsScanFields = [
|
||||
label: '组合名称',
|
||||
type: 'text',
|
||||
placeholder: '模糊匹配',
|
||||
operators: ['contains', 'like'],
|
||||
defaultOperator: 'like'
|
||||
operators: ['contains', 'like', 'eq'],
|
||||
defaultOperator: 'eq'
|
||||
},
|
||||
{
|
||||
value: 'status',
|
||||
|
||||
@ -146,6 +146,10 @@ import {
|
||||
type ComboGoodsItemRow,
|
||||
type ComboGoodsRecord
|
||||
} from '../combo-stock-config'
|
||||
import {
|
||||
parseComboNameNotation,
|
||||
parseComboSimpleNotation
|
||||
} from '@/views/order/orderManagement/utils/stock-picker-helpers'
|
||||
import {
|
||||
extractStoreListFromResponse,
|
||||
mapStoreListToSelectOptions
|
||||
@ -228,7 +232,29 @@ function fillFromRecord(record: ComboGoodsRecord) {
|
||||
: undefined
|
||||
formData.remark = record.remark || ''
|
||||
formData.status = record.status === 0 ? 0 : 1
|
||||
formItems.value = mapComboGoodsItemsFromRecord(record.items)
|
||||
|
||||
// 解析 nameNotation / simpleNotation 以获取子商品名称和编码
|
||||
// (API 返回的 items 仅含 item_goods_sku_id/item_quantity/sort_order,不含 item_name/item_code)
|
||||
const nameByIndex = parseComboNameNotation(String(record.nameNotation ?? ''))
|
||||
const simpleByIndex = parseComboSimpleNotation(String(record.simpleNotation ?? ''))
|
||||
|
||||
const items = mapComboGoodsItemsFromRecord(record.items)
|
||||
formItems.value = items.map((item, index) => {
|
||||
const nameIndex = index + 1
|
||||
const sortOrder = Number(item.sort_order)
|
||||
return {
|
||||
...item,
|
||||
// 优先取 items 中的 item_name;其次从 nameNotation 按序号解析;再次按 sort_order 解析
|
||||
item_name: item.item_name
|
||||
|| nameByIndex.get(nameIndex)
|
||||
|| (Number.isFinite(sortOrder) ? nameByIndex.get(sortOrder) : undefined)
|
||||
|| undefined,
|
||||
// 优先取 items 中的 item_code;其次从 simpleNotation 按序号解析;最后用 SKU ID
|
||||
item_code: item.item_code
|
||||
|| simpleByIndex.get(nameIndex)
|
||||
|| String(item.item_goods_sku_id)
|
||||
}
|
||||
})
|
||||
formRef.value?.clearValidate()
|
||||
}
|
||||
|
||||
|
||||
@ -19,11 +19,12 @@
|
||||
<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>
|
||||
<div class="toolbar-right">
|
||||
<el-button size="small" type="primary" plain @click="searchDialogVisible = true">快速搜索</el-button>
|
||||
<el-button type="success" size="small" @click="openCreate">新增组合商品</el-button>
|
||||
</div>
|
||||
<div class="toolbar-right">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="upper-wrapper">
|
||||
|
||||
@ -1,22 +1,28 @@
|
||||
<template>
|
||||
<div class="stock-management-wrapper" :style="{ height: containerHeight }">
|
||||
<el-tabs
|
||||
v-model="activeTab"
|
||||
tab-position="top"
|
||||
type="border-card"
|
||||
class="tab-container"
|
||||
@tab-change="handleTabChange"
|
||||
>
|
||||
<el-tab-pane
|
||||
v-for="tab in tabs"
|
||||
:key="tab.name"
|
||||
:name="tab.name"
|
||||
:label="tab.label"
|
||||
:lazy="false"
|
||||
<!-- ===== 顶部多标签页区域(对齐 setting/encoding / waveOrder2 的 TabArea) ===== -->
|
||||
<div class="tab-section">
|
||||
<el-tabs
|
||||
v-model="activeTab"
|
||||
tab-position="top"
|
||||
type="border-card"
|
||||
class="tab-container"
|
||||
@tab-change="handleTabChange"
|
||||
>
|
||||
<component :is="tab.component" v-if="activeTab === tab.name" />
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
<el-tab-pane
|
||||
v-for="tab in tabs"
|
||||
:key="tab.name"
|
||||
:name="tab.name"
|
||||
:label="tab.label"
|
||||
:lazy="false"
|
||||
/>
|
||||
</el-tabs>
|
||||
</div>
|
||||
|
||||
<!-- ===== 主内容区容器(对齐 setting/encoding / waveOrder2 的 main-container) ===== -->
|
||||
<div class="main-container">
|
||||
<component :is="tabs.find(t => t.name === activeTab)?.component" :key="activeTab" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@ -107,16 +113,33 @@ const handleTabChange = (tabName: string | number) => {
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
/* ================================================================
|
||||
整体布局容器(对齐 setting/encoding / waveOrder2 的 wrapper)
|
||||
================================================================ */
|
||||
.stock-management-wrapper {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* ================================================================
|
||||
1. 顶部多标签页区域(对齐 setting/encoding / waveOrder2 的 tab-section)
|
||||
================================================================ */
|
||||
.tab-section {
|
||||
flex-shrink: 0;
|
||||
background: #fff;
|
||||
border: 1px solid #e8eef7;
|
||||
border-bottom: none;
|
||||
border-radius: 6px 6px 0 0;
|
||||
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.tab-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
|
||||
:deep(.el-tabs__header) {
|
||||
margin-bottom: 0;
|
||||
@ -171,14 +194,25 @@ const handleTabChange = (tabName: string | number) => {
|
||||
bottom: 0;
|
||||
}
|
||||
|
||||
/* 隐藏内容区,仅展示标签头(对齐 setting/encoding / waveOrder2 的 TabArea) */
|
||||
:deep(.el-tabs__content) {
|
||||
flex: 1;
|
||||
overflow: auto;
|
||||
position: relative;
|
||||
|
||||
.el-tab-pane {
|
||||
height: 100%;
|
||||
}
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================
|
||||
2. 主内容区容器(对齐 setting/encoding / waveOrder2 的 main-container)
|
||||
================================================================ */
|
||||
.main-container {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
background: #fff;
|
||||
border: 1px solid #e8eef7;
|
||||
border-top: none;
|
||||
border-radius: 0 0 6px 6px;
|
||||
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
|
||||
overflow: hidden;
|
||||
}
|
||||
</style>
|
||||
|
||||
@ -1613,7 +1613,7 @@ async function handleExport(mode: 'waybill' | 'item' = 'waybill') {
|
||||
}
|
||||
|
||||
.match-left-panel {
|
||||
width: 300px;
|
||||
width: 330px;
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
@ -1,26 +1,33 @@
|
||||
<template>
|
||||
<div class="encoding-wrapper" :style="{ height: containerHeight }">
|
||||
<el-tabs
|
||||
v-model="activeTab"
|
||||
tab-position="top"
|
||||
type="border-card"
|
||||
class="tab-container"
|
||||
@tab-change="handleTabChange"
|
||||
>
|
||||
<el-tab-pane
|
||||
v-for="tab in tabs"
|
||||
:key="tab.name"
|
||||
:name="tab.name"
|
||||
:lazy="false"
|
||||
<!-- ===== 顶部多标签页区域(对齐 waveOrder2 的 TabArea) ===== -->
|
||||
<div class="tab-section">
|
||||
<el-tabs
|
||||
v-model="activeTab"
|
||||
tab-position="top"
|
||||
type="border-card"
|
||||
class="tab-container"
|
||||
@tab-change="handleTabChange"
|
||||
>
|
||||
<template #label>
|
||||
<span class="custom-tab-label">{{ tab.label }}</span>
|
||||
</template>
|
||||
<keep-alive>
|
||||
<component :is="tab.component" v-if="activeTab === tab.name" />
|
||||
</keep-alive>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
<el-tab-pane
|
||||
v-for="tab in tabs"
|
||||
:key="tab.name"
|
||||
:name="tab.name"
|
||||
:lazy="false"
|
||||
>
|
||||
<template #label>
|
||||
<span class="custom-tab-label">{{ tab.label }}</span>
|
||||
</template>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</div>
|
||||
|
||||
<!-- ===== 主内容区容器(对齐 waveOrder2 的 main-container) ===== -->
|
||||
<div class="main-container">
|
||||
<keep-alive>
|
||||
<component :is="tabs.find(t => t.name === activeTab)?.component" :key="activeTab" />
|
||||
</keep-alive>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@ -101,16 +108,33 @@ const handleTabChange = (tabName: string | number) => {
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
/* ================================================================
|
||||
整体布局容器(对齐 waveOrder2 的 order-management-wrapper)
|
||||
================================================================ */
|
||||
.encoding-wrapper {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* ================================================================
|
||||
1. 顶部多标签页区域(对齐 waveOrder2 的 tab-section)
|
||||
================================================================ */
|
||||
.tab-section {
|
||||
flex-shrink: 0;
|
||||
background: #fff;
|
||||
border: 1px solid #e8eef7;
|
||||
border-bottom: none;
|
||||
border-radius: 6px 6px 0 0;
|
||||
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.tab-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
|
||||
:deep(.el-tabs__header) {
|
||||
margin-bottom: 0;
|
||||
@ -165,14 +189,9 @@ const handleTabChange = (tabName: string | number) => {
|
||||
bottom: 0;
|
||||
}
|
||||
|
||||
/* 隐藏内容区,仅展示标签头(对齐 waveOrder2 的 TabArea) */
|
||||
:deep(.el-tabs__content) {
|
||||
flex: 1;
|
||||
overflow: auto;
|
||||
position: relative;
|
||||
|
||||
.el-tab-pane {
|
||||
height: 100%;
|
||||
}
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
@ -181,4 +200,20 @@ const handleTabChange = (tabName: string | number) => {
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
/* ================================================================
|
||||
2. 主内容区容器(对齐 waveOrder2 的 main-container)
|
||||
================================================================ */
|
||||
.main-container {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
background: #fff;
|
||||
border: 1px solid #e8eef7;
|
||||
border-top: none;
|
||||
border-radius: 0 0 6px 6px;
|
||||
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
|
||||
overflow: hidden;
|
||||
}
|
||||
</style>
|
||||
|
||||
@ -4,6 +4,53 @@
|
||||
width: 100%;
|
||||
background-color: #f0f2f5;
|
||||
|
||||
:deep(.scan-box-container) {
|
||||
flex: 0 0 250px;
|
||||
flex-shrink: 0;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
:deep(.scan-box-container .scan-tabs) {
|
||||
flex-shrink: 0;
|
||||
border-bottom: 1px solid #ebeef5;
|
||||
background: #fafafa;
|
||||
}
|
||||
|
||||
:deep(.scan-box-container .scan-tabs .el-tabs__header) {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
:deep(.scan-box-container .scan-tabs .el-tabs__nav-wrap::after) {
|
||||
display: none;
|
||||
}
|
||||
|
||||
:deep(.scan-box-container .scan-tabs .el-tabs__active-bar) {
|
||||
display: none;
|
||||
}
|
||||
|
||||
:deep(.scan-box-container .scan-tabs .el-tabs__item) {
|
||||
height: 40px;
|
||||
line-height: 40px;
|
||||
font-size: 13px;
|
||||
padding: 0 12px;
|
||||
color: #606266;
|
||||
border: 1px solid transparent;
|
||||
border-bottom: none;
|
||||
border-radius: 4px 4px 0 0;
|
||||
transition: color 0.2s;
|
||||
}
|
||||
|
||||
:deep(.scan-box-container .scan-tabs .el-tabs__item:hover) {
|
||||
color: var(--el-color-primary);
|
||||
}
|
||||
|
||||
:deep(.scan-box-container .scan-tabs .el-tabs__item.is-active) {
|
||||
color: var(--el-color-primary);
|
||||
background-color: #fff;
|
||||
border-color: #ebeef5;
|
||||
border-bottom-color: #fff;
|
||||
}
|
||||
|
||||
.main-content {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
@ -19,14 +66,26 @@
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
background-color: #fff;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
|
||||
.toolbar-left {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.toolbar-right {
|
||||
flex: 0 0 auto;
|
||||
margin-left: 10px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
gap: 10px;
|
||||
}
|
||||
}
|
||||
|
||||
.upper-wrapper {
|
||||
|
||||
@ -0,0 +1,65 @@
|
||||
<!--
|
||||
ColumnCellRenderer — 通用表格列渲染器
|
||||
|
||||
根据传入的 ColumnSlotConfig 决定如何渲染单元格:
|
||||
- type='tag' → el-tag(支持 tagResolver / tagType 颜色映射)
|
||||
- type='text' → 纯文本(支持 datetime 格式化)
|
||||
- type='default' → 默认插槽渲染
|
||||
- type='operation' → 操作列(由 OperationCellRenderer 处理)
|
||||
-->
|
||||
<template>
|
||||
<template v-if="!config || config.type === 'default'">
|
||||
<slot />
|
||||
</template>
|
||||
<template v-else-if="config.type === 'tag'">
|
||||
<el-tag size="small" :type="resolvedTagType">
|
||||
{{ displayValue }}
|
||||
</el-tag>
|
||||
</template>
|
||||
<template v-else>
|
||||
<span>{{ displayValue }}</span>
|
||||
</template>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import type { ColumnSlotConfig } from '../config/template-config'
|
||||
import { TAG_RESOLVERS, translate, formatTime } from '../config/template-config'
|
||||
|
||||
defineOptions({ name: 'ColumnCellRenderer' })
|
||||
|
||||
const props = defineProps<{
|
||||
/** 列插槽渲染配置 */
|
||||
config: ColumnSlotConfig | undefined
|
||||
/** 单元格值 */
|
||||
value: any
|
||||
}>()
|
||||
|
||||
/** 显示文本:translateField 翻译 > format 格式化 > 原始值 */
|
||||
const displayValue = computed(() => {
|
||||
const v = props.value
|
||||
if (props.config?.translateField) {
|
||||
return translate(props.config.translateField, v)
|
||||
}
|
||||
if (props.config?.format === 'datetime') {
|
||||
return formatTime(v)
|
||||
}
|
||||
return v ?? '—'
|
||||
})
|
||||
|
||||
const resolvedTagType = computed(() => {
|
||||
if (!props.config || props.config.type !== 'tag') return ''
|
||||
const { tagType, tagResolver } = props.config
|
||||
// 优先使用 tagResolver(函数名映射)
|
||||
if (tagResolver && TAG_RESOLVERS[tagResolver]) {
|
||||
return TAG_RESOLVERS[tagResolver](props.value)
|
||||
}
|
||||
// 其次使用 tagType 映射表(用原始值查找)
|
||||
if (tagType && typeof tagType === 'object') {
|
||||
return tagType[String(props.value)] ?? 'info'
|
||||
}
|
||||
// 最后使用固定值
|
||||
return (typeof tagType === 'string' ? tagType : 'info')
|
||||
})
|
||||
</script>
|
||||
|
||||
@ -0,0 +1,175 @@
|
||||
<!--
|
||||
OperationCellRenderer — 表格操作列渲染组件
|
||||
|
||||
根据 operationButtons 配置渲染按钮列表。
|
||||
|
||||
支持的行为类型:
|
||||
- actionType='action' → 触发 @operation-action 事件(可选配置 confirmMessage 弹确认框)
|
||||
- actionType='form' → 打开 COMPONENT_REGISTRY 中注册的表单组件
|
||||
|
||||
使用方式:在 index.vue 中通过插槽 column-operation 引入:
|
||||
<OperationCellRenderer
|
||||
:buttons="currentTabConfig?.operationButtons"
|
||||
:row="row"
|
||||
@operation-action="handleOperationAction"
|
||||
/>
|
||||
-->
|
||||
<template>
|
||||
<div class="operation-cell">
|
||||
<template v-for="btn in buttons" :key="btn.key">
|
||||
<!-- action 按钮:支持确认弹窗 -->
|
||||
<el-button
|
||||
v-if="btn.actionType === 'action'"
|
||||
link
|
||||
:type="btn.type || 'primary'"
|
||||
size="small"
|
||||
:loading="actionLoadingMap[btn.key]"
|
||||
:disabled="isDisabled(btn)"
|
||||
@click.stop="handleActionClick(btn)"
|
||||
>
|
||||
{{ btn.label }}
|
||||
</el-button>
|
||||
|
||||
<!-- form 按钮:打开表单弹窗 -->
|
||||
<template v-else-if="btn.actionType === 'form'">
|
||||
<el-button
|
||||
link
|
||||
:type="btn.type || 'primary'"
|
||||
size="small"
|
||||
:disabled="isDisabled(btn)"
|
||||
@click.stop="openForm(btn)"
|
||||
>
|
||||
{{ btn.label }}
|
||||
</el-button>
|
||||
|
||||
<!-- 表单弹窗 -->
|
||||
<component
|
||||
:is="resolvedFormComponents[btn.key]"
|
||||
v-if="resolvedFormComponents[btn.key] && activeFormKey === btn.key"
|
||||
v-model:visible="formVisibleMap[btn.key]"
|
||||
v-bind="buildFormProps(btn)"
|
||||
@success="handleFormSuccess(btn.key)"
|
||||
/>
|
||||
</template>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, type Component } from 'vue'
|
||||
import { ElMessageBox } from 'element-plus'
|
||||
import { COMPONENT_REGISTRY } from '../config/template-config'
|
||||
import type { OperationButtonConfig } from '../config/template-config'
|
||||
|
||||
defineOptions({ name: 'OperationCellRenderer' })
|
||||
|
||||
const props = defineProps<{
|
||||
/** 操作按钮配置列表(来自 TabPageConfig.operationButtons) */
|
||||
buttons?: OperationButtonConfig[]
|
||||
/** 当前行数据 */
|
||||
row: Record<string, any>
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
/** action 按钮点击事件(key: 按钮标识, row: 行数据) */
|
||||
(e: 'operation-action', key: string, row: Record<string, any>): void
|
||||
}>()
|
||||
|
||||
// ===== form 弹窗管理 =====
|
||||
const activeFormKey = ref('')
|
||||
const formVisibleMap = reactive<Record<string, boolean>>({})
|
||||
const resolvedFormComponents = ref<Record<string, Component>>({})
|
||||
const actionLoadingMap = reactive<Record<string, boolean>>({})
|
||||
|
||||
// ============================================================
|
||||
// action 按钮:支持确认弹窗
|
||||
// ============================================================
|
||||
|
||||
async function handleActionClick(btn: OperationButtonConfig) {
|
||||
if (btn.confirmMessage) {
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
btn.confirmMessage,
|
||||
btn.confirmTitle || '确认操作',
|
||||
{
|
||||
confirmButtonText: btn.confirmButtonText || '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: (btn.confirmType || 'warning') as any
|
||||
}
|
||||
)
|
||||
} catch {
|
||||
return // 取消
|
||||
}
|
||||
}
|
||||
|
||||
actionLoadingMap[btn.key] = true
|
||||
try {
|
||||
emit('operation-action', btn.key, props.row)
|
||||
} finally {
|
||||
actionLoadingMap[btn.key] = false
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// form 按钮:打开表单弹窗
|
||||
// ============================================================
|
||||
|
||||
function openForm(btn: OperationButtonConfig) {
|
||||
if (!btn.formKey) return
|
||||
|
||||
const comp = COMPONENT_REGISTRY[btn.formKey]
|
||||
if (!comp) {
|
||||
console.warn(`[OperationCellRenderer] 未注册的表单组件: ${btn.formKey}`)
|
||||
return
|
||||
}
|
||||
|
||||
activeFormKey.value = btn.key
|
||||
resolvedFormComponents.value[btn.key] = comp
|
||||
formVisibleMap[btn.key] = true
|
||||
}
|
||||
|
||||
function buildFormProps(btn: OperationButtonConfig): Record<string, any> {
|
||||
const props: Record<string, any> = {}
|
||||
|
||||
// paramMap: { formProp: rowField } → 从行数据取值注入表单
|
||||
if (btn.paramMap) {
|
||||
for (const [formProp, rowField] of Object.entries(btn.paramMap)) {
|
||||
props[formProp] = props.row[rowField]
|
||||
}
|
||||
}
|
||||
|
||||
// extraParams: 固定参数直接注入
|
||||
if (btn.extraParams) {
|
||||
Object.assign(props, btn.extraParams)
|
||||
}
|
||||
|
||||
return props
|
||||
}
|
||||
|
||||
function handleFormSuccess(key: string) {
|
||||
emit('operation-action', key, props.row)
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 按钮禁用判断
|
||||
// ============================================================
|
||||
|
||||
function isDisabled(btn: OperationButtonConfig): boolean {
|
||||
if (btn.disabledOnField) {
|
||||
const val = props.row[btn.disabledOnField]
|
||||
if (val === undefined || val === null || val === '' || val === false) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.operation-cell {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 2px;
|
||||
justify-content: center;
|
||||
}
|
||||
</style>
|
||||
132
src/views/system/setting/encoding2/components/TabArea.vue
Normal file
132
src/views/system/setting/encoding2/components/TabArea.vue
Normal file
@ -0,0 +1,132 @@
|
||||
<template>
|
||||
<div class="tab-area-wrapper">
|
||||
<el-tabs
|
||||
v-model="activeTab"
|
||||
tab-position="top"
|
||||
type="border-card"
|
||||
class="tab-container"
|
||||
@tab-click="handleTabClick"
|
||||
>
|
||||
<el-tab-pane
|
||||
v-for="tab in tabs"
|
||||
:key="tab.name"
|
||||
:name="tab.name"
|
||||
:lazy="false"
|
||||
>
|
||||
<template #label>
|
||||
<span class="custom-tab-label">{{ tab.label }}</span>
|
||||
</template>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
|
||||
defineOptions({ name: 'TabArea' })
|
||||
|
||||
interface TabItem {
|
||||
name: string
|
||||
label: string
|
||||
}
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
tabs?: TabItem[]
|
||||
defaultActive?: string
|
||||
}>(),
|
||||
{
|
||||
tabs: () => [],
|
||||
defaultActive: ''
|
||||
}
|
||||
)
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'tab-change', tabName: string): void
|
||||
}>()
|
||||
|
||||
const activeTab = ref(props.defaultActive || props.tabs[0]?.name || '')
|
||||
|
||||
const handleTabClick = (pane: any) => {
|
||||
const name = pane?.name ?? pane?.props?.name ?? ''
|
||||
if (name) {
|
||||
activeTab.value = name
|
||||
emit('tab-change', name)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.tab-area-wrapper {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.tab-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
:deep(.el-tabs__header) {
|
||||
margin-bottom: 0;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
:deep(.el-tabs__header.is-top) {
|
||||
padding: 4px 12px 0;
|
||||
background: #f8fbff;
|
||||
border-bottom: 1px solid #e8eef7;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
:deep(.el-tabs__nav-wrap::after) {
|
||||
display: none;
|
||||
}
|
||||
|
||||
:deep(.el-tabs__item.is-top) {
|
||||
height: 38px;
|
||||
line-height: 38px;
|
||||
padding: 0 20px;
|
||||
border-radius: 6px 6px 0 0;
|
||||
color: #606266;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
transition: all 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
|
||||
border: 1px solid transparent;
|
||||
border-bottom: none;
|
||||
margin-right: 4px;
|
||||
}
|
||||
|
||||
:deep(.el-tabs__item.is-top:hover) {
|
||||
color: #409eff;
|
||||
background-color: rgba(64, 158, 255, 0.05);
|
||||
}
|
||||
|
||||
:deep(.el-tabs__item.is-top.is-active) {
|
||||
color: #409eff;
|
||||
font-weight: 600;
|
||||
background: #ffffff;
|
||||
border-color: #e8eef7;
|
||||
border-bottom: 2px solid #ffffff;
|
||||
margin-bottom: -1px;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
:deep(.el-tabs__active-bar) {
|
||||
height: 2px;
|
||||
border-radius: 2px;
|
||||
background-color: #409eff;
|
||||
bottom: 0;
|
||||
}
|
||||
|
||||
:deep(.el-tabs__content) {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.custom-tab-label {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
</style>
|
||||
@ -0,0 +1,159 @@
|
||||
<!--
|
||||
DetailPanel — 明细面板(通用)
|
||||
|
||||
根据 detailConfig 配置的 sections 渲染 el-descriptions 分区。
|
||||
支持 text、tag、pre 三种渲染类型。
|
||||
支持 translateField + tagResolver 集中式翻译。
|
||||
支持 apiMethod 自动获取详情数据。
|
||||
-->
|
||||
<template>
|
||||
<div class="detail-panel">
|
||||
<div v-if="!row" class="empty-tip">请从上方列表中选择一项查看明细</div>
|
||||
<template v-else>
|
||||
<div v-for="(section, si) in detailConfig" :key="si" class="section">
|
||||
<div class="section-title">{{ section.title }}</div>
|
||||
<el-descriptions :column="section.columnCount" border size="small" class="detail-descriptions">
|
||||
<el-descriptions-item
|
||||
v-for="(field, fi) in section.fields"
|
||||
:key="fi"
|
||||
:label="field.label"
|
||||
:span="field.span ?? 1"
|
||||
>
|
||||
<!-- tag 渲染 -->
|
||||
<template v-if="field.renderType === 'tag'">
|
||||
<el-tag size="small" :type="resolveTagType(field, getRowData()?.[field.key])">
|
||||
{{ resolveDisplayValue(field, getRowData()?.[field.key]) }}
|
||||
</el-tag>
|
||||
</template>
|
||||
<!-- pre 渲染 -->
|
||||
<template v-else-if="field.renderType === 'pre'">
|
||||
<pre class="order-list-pre">{{ getRowData()?.[field.key] ?? '—' }}</pre>
|
||||
</template>
|
||||
<!-- 默认文本渲染 -->
|
||||
<template v-else>
|
||||
{{ resolveDisplayValue(field, getRowData()?.[field.key]) }}
|
||||
</template>
|
||||
</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, watch } from 'vue'
|
||||
import { TAG_RESOLVERS, translate } from '../template-config'
|
||||
import type { DetailSectionConfig, DetailFieldConfig } from '../template-config'
|
||||
|
||||
defineOptions({ name: 'DetailPanel' })
|
||||
|
||||
const props = defineProps<{
|
||||
row: Record<string, any> | null
|
||||
detailConfig: DetailSectionConfig[]
|
||||
/** 可选的 detail API 方法,传入后自动调用获取完整明细数据 */
|
||||
apiMethod?: (...args: any[]) => Promise<any>
|
||||
}>()
|
||||
|
||||
/** 通过 API 获取的增强数据(与 row 合并) */
|
||||
const enrichedData = ref<Record<string, any> | null>(null)
|
||||
|
||||
watch(() => props.row, async (newRow) => {
|
||||
if (newRow && props.apiMethod) {
|
||||
try {
|
||||
const res = await props.apiMethod({
|
||||
id: newRow.id,
|
||||
code: newRow.code
|
||||
})
|
||||
if (res && (res.code === 1 || res.code === 200)) {
|
||||
enrichedData.value = res.data ?? res
|
||||
} else {
|
||||
enrichedData.value = null
|
||||
}
|
||||
} catch {
|
||||
enrichedData.value = null
|
||||
}
|
||||
} else {
|
||||
enrichedData.value = null
|
||||
}
|
||||
}, { immediate: true })
|
||||
|
||||
/** 合并 row + API 增强数据 */
|
||||
function getRowData(): Record<string, any> | null {
|
||||
if (!props.row) return null
|
||||
if (enrichedData.value) {
|
||||
return { ...props.row, ...enrichedData.value }
|
||||
}
|
||||
return props.row
|
||||
}
|
||||
|
||||
/** 解析显示值:优先使用 translateField 翻译,否则显示原始值 */
|
||||
function resolveDisplayValue(field: DetailFieldConfig, value: any): string {
|
||||
if (field.translateField) {
|
||||
return translate(field.translateField, value)
|
||||
}
|
||||
return value ?? '—'
|
||||
}
|
||||
|
||||
/** 解析 tag 颜色 */
|
||||
function resolveTagType(field: DetailFieldConfig, value: any): string {
|
||||
if (field.tagResolver) {
|
||||
const resolver = TAG_RESOLVERS[field.tagResolver]
|
||||
if (resolver) return resolver(value)
|
||||
}
|
||||
if (field.tagType) {
|
||||
if (typeof field.tagType === 'object') {
|
||||
return field.tagType[String(value)] ?? 'info'
|
||||
}
|
||||
return field.tagType
|
||||
}
|
||||
return 'info'
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.detail-panel {
|
||||
padding: 8px 0;
|
||||
}
|
||||
|
||||
.empty-tip {
|
||||
text-align: center;
|
||||
font-size: 13px;
|
||||
color: #909399;
|
||||
padding: 40px 0;
|
||||
}
|
||||
|
||||
.section {
|
||||
margin-bottom: 12px;
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: #303133;
|
||||
margin-bottom: 10px;
|
||||
padding-left: 8px;
|
||||
border-left: 3px solid #409eff;
|
||||
line-height: 1.4;
|
||||
}
|
||||
}
|
||||
|
||||
.detail-descriptions {
|
||||
:deep(.el-descriptions__label) {
|
||||
width: 120px;
|
||||
background: #fafbfc;
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
|
||||
.order-list-pre {
|
||||
margin: 0;
|
||||
font-family: inherit;
|
||||
font-size: 13px;
|
||||
line-height: 1.8;
|
||||
white-space: pre-wrap;
|
||||
color: #606266;
|
||||
}
|
||||
</style>
|
||||
@ -0,0 +1,227 @@
|
||||
<!--
|
||||
LogPanel — 操作日志面板(通用)
|
||||
|
||||
支持两种数据来源:
|
||||
- apiMethod 传入 → 调用真实接口获取日志
|
||||
- 无 apiMethod → 基于 row 生成模拟日志(开发调试用)
|
||||
-->
|
||||
<template>
|
||||
<div class="log-panel">
|
||||
<div class="section-title">操作日志</div>
|
||||
<div v-if="apiLoading" v-loading="true" class="empty-tip">加载中…</div>
|
||||
<div v-else-if="!logs.length" class="empty-tip">暂无操作日志</div>
|
||||
<div v-else class="log-timeline">
|
||||
<div v-for="(log, i) in logs" :key="i" class="log-item">
|
||||
<div class="log-dot" :class="log.level" />
|
||||
<div class="log-content">
|
||||
<div class="log-header">
|
||||
<span class="log-operator">{{ log.operator }}</span>
|
||||
<span class="log-action">{{ log.action }}</span>
|
||||
<el-tag v-if="log.result === '成功'" size="small" type="success">成功</el-tag>
|
||||
<el-tag v-else-if="log.result === '失败'" size="small" type="danger">失败</el-tag>
|
||||
<el-tag v-else size="small" type="info">{{ log.result }}</el-tag>
|
||||
</div>
|
||||
<div v-if="log.detail" class="log-detail">{{ log.detail }}</div>
|
||||
<div class="log-time">{{ log.time }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from 'vue'
|
||||
|
||||
defineOptions({ name: 'LogPanel' })
|
||||
|
||||
interface LogItem {
|
||||
operator: string
|
||||
action: string
|
||||
result: string
|
||||
detail?: string
|
||||
time: string
|
||||
level: 'success' | 'info' | 'warning' | 'error'
|
||||
}
|
||||
|
||||
const props = defineProps<{
|
||||
/** 当前选中行数据(用于生成关联日志) */
|
||||
row: Record<string, any> | null
|
||||
/** 可选的日志 API 方法,传入后自动调用获取真实日志 */
|
||||
apiMethod?: (...args: any[]) => Promise<any>
|
||||
}>()
|
||||
|
||||
/** 通过 API 获取的真实日志列表 */
|
||||
const apiLogs = ref<LogItem[] | null>(null)
|
||||
const apiLoading = ref(false)
|
||||
|
||||
watch(() => props.row, async (newRow) => {
|
||||
if (newRow && props.apiMethod) {
|
||||
apiLoading.value = true
|
||||
try {
|
||||
const res = await props.apiMethod({
|
||||
id: newRow.id,
|
||||
code: newRow.code,
|
||||
page: 1,
|
||||
pageSize: 100
|
||||
})
|
||||
if (res && (res.code === 1 || res.code === 200)) {
|
||||
const list = res.data?.list ?? res.data?.logs ?? res.list ?? res.logs ?? []
|
||||
apiLogs.value = Array.isArray(list) ? list.map((item: any) => ({
|
||||
operator: item.operator ?? item.creator ?? '—',
|
||||
action: item.action ?? item.operation ?? '—',
|
||||
result: item.result ?? item.status ?? '—',
|
||||
detail: item.detail ?? item.description ?? '',
|
||||
time: item.time ?? item.create_time ?? '—',
|
||||
level: (item.result === '成功' || item.status === 'success') ? 'success'
|
||||
: (item.result === '失败' || item.status === 'error') ? 'error'
|
||||
: 'info'
|
||||
})) : []
|
||||
} else {
|
||||
apiLogs.value = []
|
||||
}
|
||||
} catch {
|
||||
apiLogs.value = []
|
||||
} finally {
|
||||
apiLoading.value = false
|
||||
}
|
||||
} else {
|
||||
apiLogs.value = null
|
||||
}
|
||||
}, { immediate: true })
|
||||
|
||||
/** 基于 row 生成模拟日志(无 apiMethod 时使用) */
|
||||
const mockLogs = computed<LogItem[]>(() => {
|
||||
if (!props.row) return []
|
||||
|
||||
const rowName = props.row.name ?? props.row.code ?? '—'
|
||||
const now = new Date()
|
||||
const pad = (n: number) => String(n).padStart(2, '0')
|
||||
const fmt = (d: Date) =>
|
||||
`${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`
|
||||
|
||||
return [
|
||||
{
|
||||
operator: '系统',
|
||||
action: `创建了「${rowName}」`,
|
||||
result: '成功',
|
||||
time: fmt(new Date(now.getTime() - 3600000 * 3)),
|
||||
level: 'success'
|
||||
},
|
||||
{
|
||||
operator: props.row.creator ?? '管理员',
|
||||
action: `更新了「${rowName}」`,
|
||||
result: '成功',
|
||||
detail: `修改了状态和相关配置`,
|
||||
time: fmt(new Date(now.getTime() - 3600000)),
|
||||
level: 'success'
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
/** 最终展示的日志:优先使用 API 日志,否则使用 mock 日志 */
|
||||
const logs = computed<LogItem[]>(() => {
|
||||
if (apiLogs.value !== null) {
|
||||
return apiLogs.value
|
||||
}
|
||||
return mockLogs.value
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.log-panel {
|
||||
padding: 8px 0;
|
||||
}
|
||||
|
||||
.empty-tip {
|
||||
text-align: center;
|
||||
font-size: 13px;
|
||||
color: #909399;
|
||||
padding: 40px 0;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: #303133;
|
||||
margin-bottom: 12px;
|
||||
padding-left: 4px;
|
||||
border-left: 3px solid #409eff;
|
||||
}
|
||||
|
||||
.log-timeline {
|
||||
padding-left: 8px;
|
||||
|
||||
.log-item {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
margin-bottom: 12px;
|
||||
padding-bottom: 8px;
|
||||
border-bottom: 1px dashed #ebeef5;
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.log-dot {
|
||||
flex-shrink: 0;
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
margin-top: 6px;
|
||||
border-radius: 50%;
|
||||
background: #c0c4cc;
|
||||
|
||||
&.success {
|
||||
background: #67c23a;
|
||||
}
|
||||
|
||||
&.warning {
|
||||
background: #e6a23c;
|
||||
}
|
||||
|
||||
&.error {
|
||||
background: #f56c6c;
|
||||
}
|
||||
|
||||
&.info {
|
||||
background: #409eff;
|
||||
}
|
||||
}
|
||||
|
||||
.log-content {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.log-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.log-operator {
|
||||
font-weight: 600;
|
||||
font-size: 13px;
|
||||
color: #303133;
|
||||
}
|
||||
|
||||
.log-action {
|
||||
font-size: 13px;
|
||||
color: #606266;
|
||||
}
|
||||
|
||||
.log-detail {
|
||||
margin-top: 4px;
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
}
|
||||
|
||||
.log-time {
|
||||
margin-top: 2px;
|
||||
font-size: 12px;
|
||||
color: #c0c4cc;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
727
src/views/system/setting/encoding2/config/template-config.ts
Normal file
727
src/views/system/setting/encoding2/config/template-config.ts
Normal file
@ -0,0 +1,727 @@
|
||||
/**
|
||||
* 【页面模板】配置文件 v2 — 基于 waveOrder2 架构设计
|
||||
*
|
||||
* ===== 核心设计 =====
|
||||
*
|
||||
* 1. FIELD_DICT — 全局字段预设表,每个字段拥有唯一翻译(label)和完整元数据
|
||||
* 2. VALUE_MAPS — 值翻译映射表(select options 和 tag 翻译共用)
|
||||
* 3. TAG_RESOLVERS — 标签颜色解析器(集中管理 tag 颜色逻辑)
|
||||
* 4. 各标签页通过 key 引用所需字段(scanBoxFieldKeys / tableColumnKeys)
|
||||
* 5. resolveTabConfig() — 加载时将 key 列表展开为完整配置
|
||||
*
|
||||
* ===== 快速上手 =====
|
||||
* 1. 复制整个 views/mode/ 文件夹,重命名为你的页面名
|
||||
* 2. 在 FIELD_DICT 中添加你需要的字段定义
|
||||
* 3. 在 tabPages 中配置标签页(引用 FIELD_DICT 的 key)
|
||||
* 4. 在 TabPageApiConfig 中接入真实接口
|
||||
* 5. 在 router/map.ts 中添加路由
|
||||
*/
|
||||
|
||||
import type { Component } from 'vue'
|
||||
import DetailPanel from './components/DetailPanel.vue'
|
||||
import LogPanel from './components/LogPanel.vue'
|
||||
|
||||
// ============================================================
|
||||
// 〇、全局页面配置
|
||||
// ============================================================
|
||||
export const PAGE_CONFIG = {
|
||||
/** 是否显示顶部多标签栏 */
|
||||
showTabArea: true,
|
||||
/** 单页模式:不显示标签栏,仅一个标签页内容 */
|
||||
singlePage: false,
|
||||
/** 是否启用详情面板(底部分栏 + 显示/隐藏详情按钮),false 时表格占满全高 */
|
||||
enableDetailPanel: true
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 〇-A、组件注册表 — 所有可复用组件在此注册
|
||||
// ============================================================
|
||||
export const COMPONENT_REGISTRY: Record<string, Component> = {
|
||||
DetailPanel,
|
||||
LogPanel
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 〇-B、SCANBOX_GROUPS — ScanBox 分组名称
|
||||
// ============================================================
|
||||
export const SCANBOX_GROUPS = {
|
||||
basic: '基础信息',
|
||||
process: '流程状态',
|
||||
time: '时间范围',
|
||||
custom: '自定义字段'
|
||||
} as const
|
||||
|
||||
// ============================================================
|
||||
// 一、FIELD_DICT — 全局字段预设表(唯一真相来源)
|
||||
// ============================================================
|
||||
// 每个字段拥有:
|
||||
// label — 唯一翻译文本
|
||||
// scanBox — ScanBox 渲染配置(type/options/group)
|
||||
// table — 表格列配置(minWidth/fixed/align/sortable)
|
||||
// slot — 单元格渲染配置(tag/tagResolver/translateField)
|
||||
// detailLabel — 明细面板中的标签文本(可选,默认用 label)
|
||||
// filterParamMap — ScanBox 筛选值 → API 传参值映射
|
||||
|
||||
export interface FieldDefinition {
|
||||
key: string
|
||||
label: string
|
||||
scanBox: {
|
||||
type: 'text' | 'select' | 'daterange' | 'number'
|
||||
group?: string
|
||||
options?: { label: string; value: any }[]
|
||||
} | null
|
||||
table: {
|
||||
minWidth?: number
|
||||
width?: number
|
||||
fixed?: 'left' | 'right' | boolean
|
||||
align?: 'left' | 'center' | 'right'
|
||||
sortable?: boolean
|
||||
showOverflowTooltip?: boolean
|
||||
copyAction?: 'copy' | 'copyQr'
|
||||
copyValue?: (row: any) => any
|
||||
} | null
|
||||
slot: {
|
||||
type: 'tag' | 'text' | 'default' | 'operation'
|
||||
tagType?: string | Record<string, string>
|
||||
tagResolver?: string
|
||||
translateField?: string
|
||||
format?: 'datetime'
|
||||
} | null
|
||||
detailLabel?: string
|
||||
filterParamMap?: Record<string, string>
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// VALUE_MAPS — 值翻译映射(select options 和 tag 翻译共用)
|
||||
// ============================================================
|
||||
export const VALUE_MAPS: Record<string, Record<string, string>> = {
|
||||
status: { 'pending': '待处理', 'processing': '处理中', 'done': '已完成', '待处理': '待处理', '处理中': '处理中', '已完成': '已完成' },
|
||||
type: { 'A': '类型A', 'B': '类型B', 'C': '类型C', '类型A': '类型A', '类型B': '类型B', '类型C': '类型C' },
|
||||
bool: { '1': '是', '0': '否', '是': '是', '否': '否' }
|
||||
}
|
||||
|
||||
/** 从 VALUE_MAPS 衍生 options(优先取中文值作为 option value) */
|
||||
export function getOptions(field: string): { label: string; value: string }[] {
|
||||
const map = VALUE_MAPS[field]
|
||||
if (!map) return []
|
||||
const seen = new Set<string>()
|
||||
const opts: { label: string; value: string }[] = []
|
||||
const chineseKeys: [string, string][] = []
|
||||
const otherKeys: [string, string][] = []
|
||||
for (const [v, l] of Object.entries(map)) {
|
||||
if (/^[\u4e00-\u9fa5]/.test(v)) {
|
||||
chineseKeys.push([v, l])
|
||||
} else {
|
||||
otherKeys.push([v, l])
|
||||
}
|
||||
}
|
||||
for (const [v, l] of [...chineseKeys, ...otherKeys]) {
|
||||
if (!seen.has(l)) {
|
||||
seen.add(l)
|
||||
opts.push({ label: l, value: v })
|
||||
}
|
||||
}
|
||||
return opts
|
||||
}
|
||||
|
||||
/** 翻译 value → label */
|
||||
export function translate(field: string, value: any): string {
|
||||
const map = VALUE_MAPS[field]
|
||||
if (!map) return String(value ?? '—')
|
||||
return map[String(value)] ?? String(value ?? '—')
|
||||
}
|
||||
|
||||
/** 格式化时间戳为 YYYY-MM-DD HH:mm:ss */
|
||||
export function formatTime(value: any): string {
|
||||
if (!value) return '—'
|
||||
try {
|
||||
const d = new Date(value)
|
||||
if (isNaN(d.getTime())) return String(value)
|
||||
const pad = (n: number) => String(n).padStart(2, '0')
|
||||
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`
|
||||
} catch {
|
||||
return String(value)
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// TAG_RESOLVERS — 标签颜色解析器
|
||||
// ============================================================
|
||||
// 颜色规则:未xx=info(灰) 已xx=success(绿) xx中/部分xx=warning(黄) 错误=danger(红)
|
||||
export const TAG_RESOLVERS: Record<string, (val: any) => string> = {
|
||||
resolveStatusTag(v) {
|
||||
if (!v) return 'info'
|
||||
if (v === '已完成' || v === 'done') return 'success'
|
||||
if (v === '处理中' || v === 'processing') return 'warning'
|
||||
return 'info'
|
||||
},
|
||||
resolveBoolTag(v) {
|
||||
if (v === undefined || v === null) return 'info'
|
||||
if (v === '是' || v === true || v === 1 || v === '1') return 'success'
|
||||
return 'info'
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 二、FIELD_DICT 实例 — 在此定义页面所需的所有字段
|
||||
// ============================================================
|
||||
export const FIELD_DICT: Record<string, FieldDefinition> = {
|
||||
code: {
|
||||
key: 'code',
|
||||
label: '编号',
|
||||
scanBox: { type: 'text', group: SCANBOX_GROUPS.basic },
|
||||
table: { minWidth: 160, fixed: 'left', copyAction: 'copy', showOverflowTooltip: true },
|
||||
slot: null,
|
||||
detailLabel: '编号'
|
||||
},
|
||||
name: {
|
||||
key: 'name',
|
||||
label: '名称',
|
||||
scanBox: { type: 'text', group: SCANBOX_GROUPS.basic },
|
||||
table: { minWidth: 150, showOverflowTooltip: true },
|
||||
slot: null,
|
||||
detailLabel: '名称'
|
||||
},
|
||||
type: {
|
||||
key: 'type',
|
||||
label: '类型',
|
||||
scanBox: { type: 'select', group: SCANBOX_GROUPS.basic, options: getOptions('type') },
|
||||
table: { minWidth: 100, align: 'center' },
|
||||
slot: { type: 'tag', tagType: 'info', translateField: 'type' },
|
||||
detailLabel: '类型',
|
||||
filterParamMap: { '类型A': 'A', '类型B': 'B', '类型C': 'C' }
|
||||
},
|
||||
status: {
|
||||
key: 'status',
|
||||
label: '状态',
|
||||
scanBox: { type: 'select', group: SCANBOX_GROUPS.process, options: getOptions('status') },
|
||||
table: { minWidth: 100, align: 'center' },
|
||||
slot: { type: 'tag', tagResolver: 'resolveStatusTag', translateField: 'status' },
|
||||
detailLabel: '状态',
|
||||
filterParamMap: { '待处理': 'pending', '处理中': 'processing', '已完成': 'done' }
|
||||
},
|
||||
count: {
|
||||
key: 'count',
|
||||
label: '数量',
|
||||
scanBox: null,
|
||||
table: { minWidth: 80, align: 'center', sortable: true },
|
||||
slot: null
|
||||
},
|
||||
amount: {
|
||||
key: 'amount',
|
||||
label: '金额(元)',
|
||||
scanBox: null,
|
||||
table: { minWidth: 110, align: 'center', sortable: true },
|
||||
slot: null
|
||||
},
|
||||
creator: {
|
||||
key: 'creator',
|
||||
label: '创建人',
|
||||
scanBox: { type: 'text', group: SCANBOX_GROUPS.basic },
|
||||
table: { minWidth: 100 },
|
||||
slot: null,
|
||||
detailLabel: '创建人'
|
||||
},
|
||||
create_time: {
|
||||
key: 'create_time',
|
||||
label: '创建时间',
|
||||
scanBox: { type: 'daterange', group: SCANBOX_GROUPS.time },
|
||||
table: { minWidth: 170, sortable: true },
|
||||
slot: { type: 'text', format: 'datetime' },
|
||||
detailLabel: '创建时间'
|
||||
},
|
||||
update_time: {
|
||||
key: 'update_time',
|
||||
label: '更新时间',
|
||||
scanBox: { type: 'daterange', group: SCANBOX_GROUPS.time },
|
||||
table: { minWidth: 170, sortable: true },
|
||||
slot: { type: 'text', format: 'datetime' },
|
||||
detailLabel: '更新时间'
|
||||
},
|
||||
/** 操作列(虚拟字段,仅用于表格列渲染) */
|
||||
operation: {
|
||||
key: 'operation',
|
||||
label: '操作',
|
||||
scanBox: null,
|
||||
table: { minWidth: 180, fixed: 'right', align: 'center' },
|
||||
slot: { type: 'operation' }
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 三、ColumnSlotConfig — 列单元格渲染配置
|
||||
// ============================================================
|
||||
export interface ColumnSlotConfig {
|
||||
type: 'tag' | 'text' | 'default' | 'operation'
|
||||
tagType?: string | Record<string, string>
|
||||
tagResolver?: string
|
||||
translateField?: string
|
||||
format?: 'datetime'
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 三-A、OperationButtonConfig — 操作列按钮配置
|
||||
// ============================================================
|
||||
export interface OperationButtonConfig {
|
||||
key: string
|
||||
label: string
|
||||
type?: 'primary' | 'success' | 'warning' | 'danger' | 'info' | ''
|
||||
actionType: 'form' | 'action'
|
||||
formKey?: string
|
||||
formTitle?: string
|
||||
formWidth?: string
|
||||
paramMap?: Record<string, string>
|
||||
extraParams?: Record<string, any>
|
||||
disabledOnField?: string
|
||||
confirmMessage?: string
|
||||
confirmTitle?: string
|
||||
confirmType?: 'warning' | 'danger' | 'info'
|
||||
confirmButtonText?: string
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 四、DetailFieldConfig / DetailSectionConfig — 明细面板配置
|
||||
// ============================================================
|
||||
export interface DetailFieldConfig {
|
||||
key: string
|
||||
label?: string
|
||||
span?: number
|
||||
renderType?: 'text' | 'tag' | 'pre'
|
||||
tagType?: string | Record<string, string>
|
||||
tagResolver?: string
|
||||
translateField?: string
|
||||
}
|
||||
|
||||
export interface DetailSectionConfig {
|
||||
title: string
|
||||
columnCount: number
|
||||
fields: DetailFieldConfig[]
|
||||
}
|
||||
|
||||
export interface DetailTabConfig {
|
||||
name: string
|
||||
label: string
|
||||
componentKey: string
|
||||
component?: Component
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 五、TabPageApiConfig — 标签页接口插槽配置
|
||||
// ============================================================
|
||||
export type ApiMethod = (...args: any[]) => Promise<any>
|
||||
export type ApiSource = 'api' | 'list'
|
||||
export type ComponentApiConfig = { source: 'list' } | ApiMethod
|
||||
|
||||
export interface TabPageApiConfig {
|
||||
/** 列表查询接口 */
|
||||
list: ApiMethod
|
||||
/** 明细面板接口(可选,不配则用 row 数据) */
|
||||
detail?: ComponentApiConfig
|
||||
/** 操作日志接口(可选) */
|
||||
log?: ComponentApiConfig
|
||||
/** 导出接口(可选) */
|
||||
export?: ApiMethod
|
||||
/** 导出进度查询接口(可选) */
|
||||
exportProgress?: ApiMethod
|
||||
/** ScanBox 下拉选项数据源接口(可选) */
|
||||
scanBoxOptions?: Record<string, ApiMethod>
|
||||
/** 工具栏按钮 → API 方法映射(可选) */
|
||||
toolbar?: Record<string, ApiMethod>
|
||||
/** 列表响应解析器 */
|
||||
parseListResponse?: (res: any) => { list: any[]; total: number }
|
||||
/** 构建列表请求参数 */
|
||||
buildListParams?: (params: {
|
||||
pagination: { page: number; pageSize: number }
|
||||
conditions: Record<string, any>
|
||||
sort?: { prop: string; order: string }
|
||||
}) => Record<string, any>
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 六、TabPageRawConfig — 标签页声明配置(仅用 key 引用)
|
||||
// ============================================================
|
||||
export interface TabPageRawConfig {
|
||||
name: string
|
||||
label: string
|
||||
scanBoxCacheKey: string
|
||||
/** ScanBox 需要的字段 key 列表(从 FIELD_DICT 中查找) */
|
||||
scanBoxFieldKeys: string[]
|
||||
/** 表格需要的列 key 列表(从 FIELD_DICT 中查找) */
|
||||
tableColumnKeys: string[]
|
||||
upperTableDefaults: {
|
||||
title: string
|
||||
enableColumnConfig?: boolean
|
||||
showIndex?: boolean
|
||||
showSelection?: boolean
|
||||
emptyText?: string
|
||||
}
|
||||
/** 明细面板标签页配置 */
|
||||
detailTabs?: { name: string; label: string; componentKey: string }[]
|
||||
/** 明细面板分区配置(字段 key 列表,resolveTabConfig 展开) */
|
||||
detailSections: {
|
||||
title: string
|
||||
columnCount: number
|
||||
fieldKeys: string[]
|
||||
}[]
|
||||
/** 接口配置(有 api 时启用真实接口) */
|
||||
api?: TabPageApiConfig
|
||||
/** 操作列按钮配置(需 tableColumnKeys 包含 'operation') */
|
||||
operationButtons?: OperationButtonConfig[]
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 七、TabPageConfig — 展开后的完整配置(给 index.vue 使用)
|
||||
// ============================================================
|
||||
export interface TabPageConfig {
|
||||
name: string
|
||||
label: string
|
||||
scanBoxCacheKey: string
|
||||
scanBoxFields: Record<string, any>[]
|
||||
upperTable: {
|
||||
title: string
|
||||
enableColumnConfig: boolean
|
||||
showIndex: boolean
|
||||
showSelection: boolean
|
||||
emptyText: string
|
||||
columns: Record<string, any>[]
|
||||
}
|
||||
columnSlots: Record<string, ColumnSlotConfig>
|
||||
detailConfig: DetailSectionConfig[]
|
||||
detailTabs: DetailTabConfig[]
|
||||
api?: TabPageApiConfig
|
||||
operationButtons?: OperationButtonConfig[]
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 八、resolveTabConfig — 加载时将 RawConfig 展开为完整配置
|
||||
// ============================================================
|
||||
export function resolveTabConfig(raw: TabPageRawConfig): TabPageConfig {
|
||||
// 展开 ScanBox 字段
|
||||
const scanBoxFields: Record<string, any>[] = []
|
||||
for (const key of raw.scanBoxFieldKeys) {
|
||||
const def = FIELD_DICT[key]
|
||||
if (!def || !def.scanBox) continue
|
||||
scanBoxFields.push({
|
||||
label: def.label,
|
||||
value: def.key,
|
||||
type: def.scanBox.type,
|
||||
options: def.scanBox.options ? [...def.scanBox.options] : undefined,
|
||||
group: def.scanBox.group,
|
||||
required: (def.scanBox as any).required
|
||||
})
|
||||
}
|
||||
|
||||
// 展开表格列
|
||||
const columns: Record<string, any>[] = []
|
||||
for (const key of raw.tableColumnKeys) {
|
||||
const def = FIELD_DICT[key]
|
||||
if (!def || !def.table) continue
|
||||
columns.push({
|
||||
prop: def.key,
|
||||
label: def.label,
|
||||
...def.table
|
||||
})
|
||||
}
|
||||
|
||||
// 展开列插槽
|
||||
const columnSlots: Record<string, ColumnSlotConfig> = {}
|
||||
for (const key of raw.tableColumnKeys) {
|
||||
const def = FIELD_DICT[key]
|
||||
if (!def || !def.slot) continue
|
||||
columnSlots[def.key] = { ...def.slot }
|
||||
}
|
||||
|
||||
// 展开明细面板配置
|
||||
const detailConfig: DetailSectionConfig[] = raw.detailSections.map((sec) => ({
|
||||
title: sec.title,
|
||||
columnCount: sec.columnCount,
|
||||
fields: sec.fieldKeys
|
||||
.map((key): DetailFieldConfig | null => {
|
||||
const def = FIELD_DICT[key]
|
||||
if (!def) return null
|
||||
return {
|
||||
key: def.key,
|
||||
label: def.detailLabel ?? def.label,
|
||||
translateField: def.slot?.translateField,
|
||||
tagResolver: def.slot?.tagResolver,
|
||||
tagType: def.slot?.tagType,
|
||||
renderType: def.slot?.type === 'tag' ? 'tag' : 'text'
|
||||
}
|
||||
})
|
||||
.filter((f): f is DetailFieldConfig => f !== null)
|
||||
}))
|
||||
|
||||
// 展开明细标签页(解析 componentKey → Component)
|
||||
const detailTabs: DetailTabConfig[] = raw.detailTabs
|
||||
? raw.detailTabs.map((tab) => ({
|
||||
name: tab.name,
|
||||
label: tab.label,
|
||||
componentKey: tab.componentKey,
|
||||
component: COMPONENT_REGISTRY[tab.componentKey]
|
||||
}))
|
||||
: [{ name: 'detail', label: '明细', componentKey: 'DetailPanel', component: COMPONENT_REGISTRY['DetailPanel'] }]
|
||||
|
||||
return {
|
||||
name: raw.name,
|
||||
label: raw.label,
|
||||
scanBoxCacheKey: raw.scanBoxCacheKey,
|
||||
scanBoxFields,
|
||||
upperTable: {
|
||||
title: raw.upperTableDefaults.title,
|
||||
enableColumnConfig: raw.upperTableDefaults.enableColumnConfig ?? true,
|
||||
showIndex: raw.upperTableDefaults.showIndex ?? true,
|
||||
showSelection: raw.upperTableDefaults.showSelection ?? true,
|
||||
emptyText: raw.upperTableDefaults.emptyText ?? '暂无数据',
|
||||
columns
|
||||
},
|
||||
columnSlots,
|
||||
detailConfig,
|
||||
detailTabs,
|
||||
api: raw.api,
|
||||
operationButtons: raw.operationButtons
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 九、buildWhereConditions — 将 ScanBox 条件转为 API where 参数
|
||||
// ============================================================
|
||||
export function buildWhereConditions(rawConditions: Record<string, any>): Record<string, any> {
|
||||
const where: Record<string, any> = {}
|
||||
for (const [key, cond] of Object.entries(rawConditions || {})) {
|
||||
let value: any = undefined
|
||||
if (cond && typeof cond === 'object' && 'operator' in cond) {
|
||||
value = (cond as any).value
|
||||
} else if (cond !== undefined && cond !== null && cond !== '') {
|
||||
value = Array.isArray(cond) ? cond[0] ?? '' : cond
|
||||
}
|
||||
if (value === undefined || value === null || value === '' || (Array.isArray(value) && value.length === 0)) {
|
||||
continue
|
||||
}
|
||||
const def = FIELD_DICT[key]
|
||||
if (def?.filterParamMap) {
|
||||
const mapped = def.filterParamMap[String(value)]
|
||||
if (mapped !== undefined) {
|
||||
where[key] = mapped
|
||||
continue
|
||||
}
|
||||
}
|
||||
where[key] = value
|
||||
}
|
||||
return where
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 十、工具栏按钮系统
|
||||
// ============================================================
|
||||
// 按钮分为三类:
|
||||
// common — 公共按钮(刷新、导出)
|
||||
// function — 功能按钮(打开表单/确认窗口)
|
||||
// basic — 基础操作(字段设置、隐藏详情)
|
||||
|
||||
export interface ToolbarButtonConfig {
|
||||
key: string
|
||||
label: string
|
||||
category: 'common' | 'function' | 'basic'
|
||||
size?: '' | 'default' | 'small' | 'large'
|
||||
type?: '' | 'primary' | 'success' | 'warning' | 'info' | 'danger'
|
||||
plain?: boolean
|
||||
loadingKey?: string
|
||||
disabledKey?: string
|
||||
action: string
|
||||
dynamicLabelKey?: string
|
||||
onlyForTabs?: string[]
|
||||
buttonType?: 'default' | 'dropdown'
|
||||
dropdownOptions?: Array<{ label: string; action: string; divided?: boolean }>
|
||||
formKey?: string
|
||||
}
|
||||
|
||||
export const TOOLBAR_BUTTONS: Record<string, ToolbarButtonConfig> = {
|
||||
// ===== 公共按钮 =====
|
||||
refresh: {
|
||||
key: 'refresh',
|
||||
label: '刷新',
|
||||
category: 'common',
|
||||
type: 'primary',
|
||||
size: 'small',
|
||||
loadingKey: 'loading',
|
||||
action: 'loadData'
|
||||
},
|
||||
export: {
|
||||
key: 'export',
|
||||
label: '导出',
|
||||
category: 'common',
|
||||
size: 'small',
|
||||
loadingKey: 'exportLoading',
|
||||
action: 'handleExport',
|
||||
buttonType: 'dropdown',
|
||||
dropdownOptions: [
|
||||
{ label: '不含明细', action: 'handleExport' },
|
||||
{ label: '含明细', action: 'handleExportItem', divided: true }
|
||||
]
|
||||
},
|
||||
// ===== 基础操作 =====
|
||||
columnConfig: {
|
||||
key: 'columnConfig',
|
||||
label: '字段设置',
|
||||
category: 'basic',
|
||||
size: 'small',
|
||||
action: 'openColumnConfigPanel'
|
||||
},
|
||||
toggleDetail: {
|
||||
key: 'toggleDetail',
|
||||
label: '显示详情',
|
||||
category: 'basic',
|
||||
dynamicLabelKey: 'detailToggleLabel',
|
||||
size: 'small',
|
||||
action: 'toggleDetailVisible'
|
||||
}
|
||||
// ★ 在此添加功能按钮(如批量操作)★
|
||||
}
|
||||
|
||||
/** 按标签页名称获取工具栏按钮列表(自动根据 PAGE_CONFIG 过滤) */
|
||||
export function getTabToolbarButtons(tabName: string): ToolbarButtonConfig[] {
|
||||
return Object.values(TOOLBAR_BUTTONS).filter((btn) => {
|
||||
if (btn.onlyForTabs && !btn.onlyForTabs.includes(tabName)) return false
|
||||
// 详情面板禁用时,隐藏「显示/隐藏详情」按钮
|
||||
if (!PAGE_CONFIG.enableDetailPanel && btn.key === 'toggleDetail') return false
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 十一、批量操作配置(可选,接入 BatchOperationForm 时使用)
|
||||
// ============================================================
|
||||
export interface BatchOperationConfig {
|
||||
action: string
|
||||
title: string
|
||||
confirmText: string
|
||||
confirmType?: 'warning' | 'error' | 'info' | 'success'
|
||||
confirmButtonText: string
|
||||
successText: string
|
||||
failText: string
|
||||
apiMethod: (...args: any[]) => Promise<any>
|
||||
payloadKey?: string
|
||||
idField?: string | string[]
|
||||
payloadBuilder?: (rows: Record<string, any>[]) => Record<string, any>
|
||||
useProgress?: boolean
|
||||
progressApiMethod?: (...args: any[]) => Promise<any>
|
||||
}
|
||||
|
||||
/** ★ 在此配置批量操作 */
|
||||
export const BATCH_OPERATION_CONFIGS: Record<string, BatchOperationConfig> = {
|
||||
// batchExample: {
|
||||
// action: 'batchExample',
|
||||
// title: '批量操作示例',
|
||||
// confirmText: '确定对选中的 {count} 项执行操作吗?',
|
||||
// confirmType: 'warning',
|
||||
// confirmButtonText: '确认操作',
|
||||
// successText: '批量操作成功',
|
||||
// failText: '批量操作失败',
|
||||
// apiMethod: yourBatchApi,
|
||||
// payloadKey: 'ids',
|
||||
// idField: 'id'
|
||||
// }
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 十二、标签页注册表 — 在此定义你的页面标签页
|
||||
// ============================================================
|
||||
export const tabPages: TabPageRawConfig[] = [
|
||||
// ===== 示例标签页一 =====
|
||||
{
|
||||
name: 'tab1',
|
||||
label: '标签页一',
|
||||
scanBoxCacheKey: 'template-tab1',
|
||||
scanBoxFieldKeys: ['code', 'type', 'status', 'creator', 'create_time'],
|
||||
tableColumnKeys: ['code', 'name', 'type', 'status', 'count', 'amount', 'creator', 'create_time', 'operation'],
|
||||
upperTableDefaults: {
|
||||
title: '示例列表一',
|
||||
showSelection: true
|
||||
},
|
||||
detailTabs: [
|
||||
{ name: 'detail', label: '明细', componentKey: 'DetailPanel' },
|
||||
{ name: 'log', label: '操作日志', componentKey: 'LogPanel' }
|
||||
],
|
||||
detailSections: [
|
||||
{
|
||||
title: '基础信息',
|
||||
columnCount: 3,
|
||||
fieldKeys: ['code', 'name', 'type', 'status', 'count', 'amount', 'creator']
|
||||
},
|
||||
{
|
||||
title: '时间信息',
|
||||
columnCount: 2,
|
||||
fieldKeys: ['create_time', 'update_time']
|
||||
}
|
||||
],
|
||||
/** ★ 接入真实接口时取消注释 */
|
||||
// api: {
|
||||
// list: yourListApi,
|
||||
// detail: { source: 'list' },
|
||||
// parseListResponse(res) {
|
||||
// return { list: res.data?.list ?? [], total: res.data?.pagination?.total ?? 0 }
|
||||
// },
|
||||
// buildListParams({ pagination, conditions, sort }) {
|
||||
// return {
|
||||
// page: pagination.page,
|
||||
// pageSize: pagination.pageSize,
|
||||
// where: buildWhereConditions(conditions),
|
||||
// ...(sort?.prop ? { sortField: sort.prop, sortOrder: sort.order === 'ascending' ? 'ASC' : 'DESC' } : {})
|
||||
// }
|
||||
// }
|
||||
// },
|
||||
operationButtons: [
|
||||
{
|
||||
key: 'viewDetail',
|
||||
label: '查看详情',
|
||||
actionType: 'action',
|
||||
type: 'primary'
|
||||
},
|
||||
{
|
||||
key: 'edit',
|
||||
label: '编辑',
|
||||
actionType: 'action',
|
||||
type: 'warning'
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
// ===== 示例标签页二 =====
|
||||
{
|
||||
name: 'tab2',
|
||||
label: '标签页二',
|
||||
scanBoxCacheKey: 'template-tab2',
|
||||
scanBoxFieldKeys: ['code', 'status', 'create_time'],
|
||||
tableColumnKeys: ['code', 'name', 'status', 'count', 'creator', 'create_time', 'operation'],
|
||||
upperTableDefaults: {
|
||||
title: '示例列表二',
|
||||
showSelection: true
|
||||
},
|
||||
detailSections: [
|
||||
{
|
||||
title: '基础信息',
|
||||
columnCount: 3,
|
||||
fieldKeys: ['code', 'name', 'status', 'count', 'creator']
|
||||
},
|
||||
{
|
||||
title: '时间信息',
|
||||
columnCount: 2,
|
||||
fieldKeys: ['create_time', 'update_time']
|
||||
}
|
||||
],
|
||||
operationButtons: [
|
||||
{
|
||||
key: 'viewDetail',
|
||||
label: '查看详情',
|
||||
actionType: 'action',
|
||||
type: 'primary'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
// ============================================================
|
||||
// 十三、向后兼容导出
|
||||
// ============================================================
|
||||
export const templateTabs = tabPages.map((t) => ({ name: t.name, label: t.label, scanBoxCacheKey: t.scanBoxCacheKey }))
|
||||
|
||||
1014
src/views/system/setting/encoding2/index.vue
Normal file
1014
src/views/system/setting/encoding2/index.vue
Normal file
File diff suppressed because it is too large
Load Diff
107
src/views/system/setting/encoding2/pages/ExampleFormDialog.vue
Normal file
107
src/views/system/setting/encoding2/pages/ExampleFormDialog.vue
Normal file
@ -0,0 +1,107 @@
|
||||
<!--
|
||||
ExampleFormDialog — 示例表单弹窗(模板)
|
||||
|
||||
功能按钮对应的表单组件放在 pages/ 目录下。
|
||||
|
||||
使用方式:
|
||||
1. 在 template-config.ts 的 COMPONENT_REGISTRY 中注册
|
||||
2. 在 template-config.ts 的 TOOLBAR_BUTTONS 中添加功能按钮,设置 formKey
|
||||
3. index.vue 中通过工具栏按钮触发打开
|
||||
-->
|
||||
<template>
|
||||
<el-dialog
|
||||
:model-value="visible"
|
||||
title="示例操作"
|
||||
width="500px"
|
||||
align-center
|
||||
destroy-on-close
|
||||
:close-on-click-modal="false"
|
||||
@closed="handleClosed"
|
||||
>
|
||||
<div class="form-body">
|
||||
<el-form ref="formRef" :model="form" label-width="100px" size="small">
|
||||
<el-form-item label="名称" prop="name">
|
||||
<el-input v-model="form.name" placeholder="请输入名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="描述" prop="description">
|
||||
<el-input
|
||||
v-model="form.description"
|
||||
type="textarea"
|
||||
:rows="3"
|
||||
placeholder="请输入描述"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
<el-button size="small" @click="handleClosed">取消</el-button>
|
||||
<el-button size="small" type="primary" :loading="submitting" @click="handleSubmit">
|
||||
确认
|
||||
</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { reactive, ref, watch } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
|
||||
defineOptions({ name: 'ExampleFormDialog' })
|
||||
|
||||
const props = defineProps<{
|
||||
visible: boolean
|
||||
/** 从行数据注入的初始值(由 OperationCellRenderer 的 paramMap 传递) */
|
||||
id?: string | number
|
||||
code?: string
|
||||
name?: string
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:visible', v: boolean): void
|
||||
(e: 'success'): void
|
||||
}>()
|
||||
|
||||
const formRef = ref<any>(null)
|
||||
const submitting = ref(false)
|
||||
|
||||
const form = reactive({
|
||||
name: '',
|
||||
description: ''
|
||||
})
|
||||
|
||||
// 重置表单
|
||||
watch(() => props.visible, (v) => {
|
||||
if (v) {
|
||||
form.name = props.name ?? ''
|
||||
form.description = ''
|
||||
}
|
||||
})
|
||||
|
||||
function handleClosed() {
|
||||
emit('update:visible', false)
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
submitting.value = true
|
||||
try {
|
||||
// ★ 替换为真实 API 调用
|
||||
// const res = await yourApi.submit({ id: props.id, ...form })
|
||||
await new Promise((r) => setTimeout(r, 500))
|
||||
|
||||
ElMessage.success('操作成功')
|
||||
emit('update:visible', false)
|
||||
emit('success')
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.message || '操作失败')
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.form-body {
|
||||
padding: 12px 0;
|
||||
}
|
||||
</style>
|
||||
@ -0,0 +1,65 @@
|
||||
<!--
|
||||
ColumnCellRenderer — 通用表格列渲染器
|
||||
|
||||
根据传入的 ColumnSlotConfig 决定如何渲染单元格:
|
||||
- type='tag' → el-tag(支持 tagResolver / tagType 颜色映射)
|
||||
- type='text' → 纯文本(支持 datetime 格式化)
|
||||
- type='default' → 默认插槽渲染
|
||||
- type='operation' → 操作列(由 OperationCellRenderer 处理)
|
||||
-->
|
||||
<template>
|
||||
<template v-if="!config || config.type === 'default'">
|
||||
<slot />
|
||||
</template>
|
||||
<template v-else-if="config.type === 'tag'">
|
||||
<el-tag size="small" :type="resolvedTagType">
|
||||
{{ displayValue }}
|
||||
</el-tag>
|
||||
</template>
|
||||
<template v-else>
|
||||
<span>{{ displayValue }}</span>
|
||||
</template>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import type { ColumnSlotConfig } from '../config/template-config'
|
||||
import { TAG_RESOLVERS, translate, formatTime } from '../config/template-config'
|
||||
|
||||
defineOptions({ name: 'ColumnCellRenderer' })
|
||||
|
||||
const props = defineProps<{
|
||||
/** 列插槽渲染配置 */
|
||||
config: ColumnSlotConfig | undefined
|
||||
/** 单元格值 */
|
||||
value: any
|
||||
}>()
|
||||
|
||||
/** 显示文本:translateField 翻译 > format 格式化 > 原始值 */
|
||||
const displayValue = computed(() => {
|
||||
const v = props.value
|
||||
if (props.config?.translateField) {
|
||||
return translate(props.config.translateField, v)
|
||||
}
|
||||
if (props.config?.format === 'datetime') {
|
||||
return formatTime(v)
|
||||
}
|
||||
return v ?? '—'
|
||||
})
|
||||
|
||||
const resolvedTagType = computed(() => {
|
||||
if (!props.config || props.config.type !== 'tag') return ''
|
||||
const { tagType, tagResolver } = props.config
|
||||
// 优先使用 tagResolver(函数名映射)
|
||||
if (tagResolver && TAG_RESOLVERS[tagResolver]) {
|
||||
return TAG_RESOLVERS[tagResolver](props.value)
|
||||
}
|
||||
// 其次使用 tagType 映射表(用原始值查找)
|
||||
if (tagType && typeof tagType === 'object') {
|
||||
return tagType[String(props.value)] ?? 'info'
|
||||
}
|
||||
// 最后使用固定值
|
||||
return (typeof tagType === 'string' ? tagType : 'info')
|
||||
})
|
||||
</script>
|
||||
|
||||
@ -0,0 +1,175 @@
|
||||
<!--
|
||||
OperationCellRenderer — 表格操作列渲染组件
|
||||
|
||||
根据 operationButtons 配置渲染按钮列表。
|
||||
|
||||
支持的行为类型:
|
||||
- actionType='action' → 触发 @operation-action 事件(可选配置 confirmMessage 弹确认框)
|
||||
- actionType='form' → 打开 COMPONENT_REGISTRY 中注册的表单组件
|
||||
|
||||
使用方式:在 index.vue 中通过插槽 column-operation 引入:
|
||||
<OperationCellRenderer
|
||||
:buttons="currentTabConfig?.operationButtons"
|
||||
:row="row"
|
||||
@operation-action="handleOperationAction"
|
||||
/>
|
||||
-->
|
||||
<template>
|
||||
<div class="operation-cell">
|
||||
<template v-for="btn in buttons" :key="btn.key">
|
||||
<!-- action 按钮:支持确认弹窗 -->
|
||||
<el-button
|
||||
v-if="btn.actionType === 'action'"
|
||||
link
|
||||
:type="btn.type || 'primary'"
|
||||
size="small"
|
||||
:loading="actionLoadingMap[btn.key]"
|
||||
:disabled="isDisabled(btn)"
|
||||
@click.stop="handleActionClick(btn)"
|
||||
>
|
||||
{{ btn.label }}
|
||||
</el-button>
|
||||
|
||||
<!-- form 按钮:打开表单弹窗 -->
|
||||
<template v-else-if="btn.actionType === 'form'">
|
||||
<el-button
|
||||
link
|
||||
:type="btn.type || 'primary'"
|
||||
size="small"
|
||||
:disabled="isDisabled(btn)"
|
||||
@click.stop="openForm(btn)"
|
||||
>
|
||||
{{ btn.label }}
|
||||
</el-button>
|
||||
|
||||
<!-- 表单弹窗 -->
|
||||
<component
|
||||
:is="resolvedFormComponents[btn.key]"
|
||||
v-if="resolvedFormComponents[btn.key] && activeFormKey === btn.key"
|
||||
v-model:visible="formVisibleMap[btn.key]"
|
||||
v-bind="buildFormProps(btn)"
|
||||
@success="handleFormSuccess(btn.key)"
|
||||
/>
|
||||
</template>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, type Component } from 'vue'
|
||||
import { ElMessageBox } from 'element-plus'
|
||||
import { COMPONENT_REGISTRY } from '../config/template-config'
|
||||
import type { OperationButtonConfig } from '../config/template-config'
|
||||
|
||||
defineOptions({ name: 'OperationCellRenderer' })
|
||||
|
||||
const props = defineProps<{
|
||||
/** 操作按钮配置列表(来自 TabPageConfig.operationButtons) */
|
||||
buttons?: OperationButtonConfig[]
|
||||
/** 当前行数据 */
|
||||
row: Record<string, any>
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
/** action 按钮点击事件(key: 按钮标识, row: 行数据) */
|
||||
(e: 'operation-action', key: string, row: Record<string, any>): void
|
||||
}>()
|
||||
|
||||
// ===== form 弹窗管理 =====
|
||||
const activeFormKey = ref('')
|
||||
const formVisibleMap = reactive<Record<string, boolean>>({})
|
||||
const resolvedFormComponents = ref<Record<string, Component>>({})
|
||||
const actionLoadingMap = reactive<Record<string, boolean>>({})
|
||||
|
||||
// ============================================================
|
||||
// action 按钮:支持确认弹窗
|
||||
// ============================================================
|
||||
|
||||
async function handleActionClick(btn: OperationButtonConfig) {
|
||||
if (btn.confirmMessage) {
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
btn.confirmMessage,
|
||||
btn.confirmTitle || '确认操作',
|
||||
{
|
||||
confirmButtonText: btn.confirmButtonText || '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: (btn.confirmType || 'warning') as any
|
||||
}
|
||||
)
|
||||
} catch {
|
||||
return // 取消
|
||||
}
|
||||
}
|
||||
|
||||
actionLoadingMap[btn.key] = true
|
||||
try {
|
||||
emit('operation-action', btn.key, props.row)
|
||||
} finally {
|
||||
actionLoadingMap[btn.key] = false
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// form 按钮:打开表单弹窗
|
||||
// ============================================================
|
||||
|
||||
function openForm(btn: OperationButtonConfig) {
|
||||
if (!btn.formKey) return
|
||||
|
||||
const comp = COMPONENT_REGISTRY[btn.formKey]
|
||||
if (!comp) {
|
||||
console.warn(`[OperationCellRenderer] 未注册的表单组件: ${btn.formKey}`)
|
||||
return
|
||||
}
|
||||
|
||||
activeFormKey.value = btn.key
|
||||
resolvedFormComponents.value[btn.key] = comp
|
||||
formVisibleMap[btn.key] = true
|
||||
}
|
||||
|
||||
function buildFormProps(btn: OperationButtonConfig): Record<string, any> {
|
||||
const props: Record<string, any> = {}
|
||||
|
||||
// paramMap: { formProp: rowField } → 从行数据取值注入表单
|
||||
if (btn.paramMap) {
|
||||
for (const [formProp, rowField] of Object.entries(btn.paramMap)) {
|
||||
props[formProp] = props.row[rowField]
|
||||
}
|
||||
}
|
||||
|
||||
// extraParams: 固定参数直接注入
|
||||
if (btn.extraParams) {
|
||||
Object.assign(props, btn.extraParams)
|
||||
}
|
||||
|
||||
return props
|
||||
}
|
||||
|
||||
function handleFormSuccess(key: string) {
|
||||
emit('operation-action', key, props.row)
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 按钮禁用判断
|
||||
// ============================================================
|
||||
|
||||
function isDisabled(btn: OperationButtonConfig): boolean {
|
||||
if (btn.disabledOnField) {
|
||||
const val = props.row[btn.disabledOnField]
|
||||
if (val === undefined || val === null || val === '' || val === false) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.operation-cell {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 2px;
|
||||
justify-content: center;
|
||||
}
|
||||
</style>
|
||||
132
src/views/system/setting/printcomputer/components/TabArea.vue
Normal file
132
src/views/system/setting/printcomputer/components/TabArea.vue
Normal file
@ -0,0 +1,132 @@
|
||||
<template>
|
||||
<div class="tab-area-wrapper">
|
||||
<el-tabs
|
||||
v-model="activeTab"
|
||||
tab-position="top"
|
||||
type="border-card"
|
||||
class="tab-container"
|
||||
@tab-click="handleTabClick"
|
||||
>
|
||||
<el-tab-pane
|
||||
v-for="tab in tabs"
|
||||
:key="tab.name"
|
||||
:name="tab.name"
|
||||
:lazy="false"
|
||||
>
|
||||
<template #label>
|
||||
<span class="custom-tab-label">{{ tab.label }}</span>
|
||||
</template>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
|
||||
defineOptions({ name: 'TabArea' })
|
||||
|
||||
interface TabItem {
|
||||
name: string
|
||||
label: string
|
||||
}
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
tabs?: TabItem[]
|
||||
defaultActive?: string
|
||||
}>(),
|
||||
{
|
||||
tabs: () => [],
|
||||
defaultActive: ''
|
||||
}
|
||||
)
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'tab-change', tabName: string): void
|
||||
}>()
|
||||
|
||||
const activeTab = ref(props.defaultActive || props.tabs[0]?.name || '')
|
||||
|
||||
const handleTabClick = (pane: any) => {
|
||||
const name = pane?.name ?? pane?.props?.name ?? ''
|
||||
if (name) {
|
||||
activeTab.value = name
|
||||
emit('tab-change', name)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.tab-area-wrapper {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.tab-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
:deep(.el-tabs__header) {
|
||||
margin-bottom: 0;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
:deep(.el-tabs__header.is-top) {
|
||||
padding: 4px 12px 0;
|
||||
background: #f8fbff;
|
||||
border-bottom: 1px solid #e8eef7;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
:deep(.el-tabs__nav-wrap::after) {
|
||||
display: none;
|
||||
}
|
||||
|
||||
:deep(.el-tabs__item.is-top) {
|
||||
height: 38px;
|
||||
line-height: 38px;
|
||||
padding: 0 20px;
|
||||
border-radius: 6px 6px 0 0;
|
||||
color: #606266;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
transition: all 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
|
||||
border: 1px solid transparent;
|
||||
border-bottom: none;
|
||||
margin-right: 4px;
|
||||
}
|
||||
|
||||
:deep(.el-tabs__item.is-top:hover) {
|
||||
color: #409eff;
|
||||
background-color: rgba(64, 158, 255, 0.05);
|
||||
}
|
||||
|
||||
:deep(.el-tabs__item.is-top.is-active) {
|
||||
color: #409eff;
|
||||
font-weight: 600;
|
||||
background: #ffffff;
|
||||
border-color: #e8eef7;
|
||||
border-bottom: 2px solid #ffffff;
|
||||
margin-bottom: -1px;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
:deep(.el-tabs__active-bar) {
|
||||
height: 2px;
|
||||
border-radius: 2px;
|
||||
background-color: #409eff;
|
||||
bottom: 0;
|
||||
}
|
||||
|
||||
:deep(.el-tabs__content) {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.custom-tab-label {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
</style>
|
||||
@ -0,0 +1,159 @@
|
||||
<!--
|
||||
DetailPanel — 明细面板(通用)
|
||||
|
||||
根据 detailConfig 配置的 sections 渲染 el-descriptions 分区。
|
||||
支持 text、tag、pre 三种渲染类型。
|
||||
支持 translateField + tagResolver 集中式翻译。
|
||||
支持 apiMethod 自动获取详情数据。
|
||||
-->
|
||||
<template>
|
||||
<div class="detail-panel">
|
||||
<div v-if="!row" class="empty-tip">请从上方列表中选择一项查看明细</div>
|
||||
<template v-else>
|
||||
<div v-for="(section, si) in detailConfig" :key="si" class="section">
|
||||
<div class="section-title">{{ section.title }}</div>
|
||||
<el-descriptions :column="section.columnCount" border size="small" class="detail-descriptions">
|
||||
<el-descriptions-item
|
||||
v-for="(field, fi) in section.fields"
|
||||
:key="fi"
|
||||
:label="field.label"
|
||||
:span="field.span ?? 1"
|
||||
>
|
||||
<!-- tag 渲染 -->
|
||||
<template v-if="field.renderType === 'tag'">
|
||||
<el-tag size="small" :type="resolveTagType(field, getRowData()?.[field.key])">
|
||||
{{ resolveDisplayValue(field, getRowData()?.[field.key]) }}
|
||||
</el-tag>
|
||||
</template>
|
||||
<!-- pre 渲染 -->
|
||||
<template v-else-if="field.renderType === 'pre'">
|
||||
<pre class="order-list-pre">{{ getRowData()?.[field.key] ?? '—' }}</pre>
|
||||
</template>
|
||||
<!-- 默认文本渲染 -->
|
||||
<template v-else>
|
||||
{{ resolveDisplayValue(field, getRowData()?.[field.key]) }}
|
||||
</template>
|
||||
</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, watch } from 'vue'
|
||||
import { TAG_RESOLVERS, translate } from '../template-config'
|
||||
import type { DetailSectionConfig, DetailFieldConfig } from '../template-config'
|
||||
|
||||
defineOptions({ name: 'DetailPanel' })
|
||||
|
||||
const props = defineProps<{
|
||||
row: Record<string, any> | null
|
||||
detailConfig: DetailSectionConfig[]
|
||||
/** 可选的 detail API 方法,传入后自动调用获取完整明细数据 */
|
||||
apiMethod?: (...args: any[]) => Promise<any>
|
||||
}>()
|
||||
|
||||
/** 通过 API 获取的增强数据(与 row 合并) */
|
||||
const enrichedData = ref<Record<string, any> | null>(null)
|
||||
|
||||
watch(() => props.row, async (newRow) => {
|
||||
if (newRow && props.apiMethod) {
|
||||
try {
|
||||
const res = await props.apiMethod({
|
||||
id: newRow.id,
|
||||
code: newRow.code
|
||||
})
|
||||
if (res && (res.code === 1 || res.code === 200)) {
|
||||
enrichedData.value = res.data ?? res
|
||||
} else {
|
||||
enrichedData.value = null
|
||||
}
|
||||
} catch {
|
||||
enrichedData.value = null
|
||||
}
|
||||
} else {
|
||||
enrichedData.value = null
|
||||
}
|
||||
}, { immediate: true })
|
||||
|
||||
/** 合并 row + API 增强数据 */
|
||||
function getRowData(): Record<string, any> | null {
|
||||
if (!props.row) return null
|
||||
if (enrichedData.value) {
|
||||
return { ...props.row, ...enrichedData.value }
|
||||
}
|
||||
return props.row
|
||||
}
|
||||
|
||||
/** 解析显示值:优先使用 translateField 翻译,否则显示原始值 */
|
||||
function resolveDisplayValue(field: DetailFieldConfig, value: any): string {
|
||||
if (field.translateField) {
|
||||
return translate(field.translateField, value)
|
||||
}
|
||||
return value ?? '—'
|
||||
}
|
||||
|
||||
/** 解析 tag 颜色 */
|
||||
function resolveTagType(field: DetailFieldConfig, value: any): string {
|
||||
if (field.tagResolver) {
|
||||
const resolver = TAG_RESOLVERS[field.tagResolver]
|
||||
if (resolver) return resolver(value)
|
||||
}
|
||||
if (field.tagType) {
|
||||
if (typeof field.tagType === 'object') {
|
||||
return field.tagType[String(value)] ?? 'info'
|
||||
}
|
||||
return field.tagType
|
||||
}
|
||||
return 'info'
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.detail-panel {
|
||||
padding: 8px 0;
|
||||
}
|
||||
|
||||
.empty-tip {
|
||||
text-align: center;
|
||||
font-size: 13px;
|
||||
color: #909399;
|
||||
padding: 40px 0;
|
||||
}
|
||||
|
||||
.section {
|
||||
margin-bottom: 12px;
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: #303133;
|
||||
margin-bottom: 10px;
|
||||
padding-left: 8px;
|
||||
border-left: 3px solid #409eff;
|
||||
line-height: 1.4;
|
||||
}
|
||||
}
|
||||
|
||||
.detail-descriptions {
|
||||
:deep(.el-descriptions__label) {
|
||||
width: 120px;
|
||||
background: #fafbfc;
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
|
||||
.order-list-pre {
|
||||
margin: 0;
|
||||
font-family: inherit;
|
||||
font-size: 13px;
|
||||
line-height: 1.8;
|
||||
white-space: pre-wrap;
|
||||
color: #606266;
|
||||
}
|
||||
</style>
|
||||
@ -0,0 +1,227 @@
|
||||
<!--
|
||||
LogPanel — 操作日志面板(通用)
|
||||
|
||||
支持两种数据来源:
|
||||
- apiMethod 传入 → 调用真实接口获取日志
|
||||
- 无 apiMethod → 基于 row 生成模拟日志(开发调试用)
|
||||
-->
|
||||
<template>
|
||||
<div class="log-panel">
|
||||
<div class="section-title">操作日志</div>
|
||||
<div v-if="apiLoading" v-loading="true" class="empty-tip">加载中…</div>
|
||||
<div v-else-if="!logs.length" class="empty-tip">暂无操作日志</div>
|
||||
<div v-else class="log-timeline">
|
||||
<div v-for="(log, i) in logs" :key="i" class="log-item">
|
||||
<div class="log-dot" :class="log.level" />
|
||||
<div class="log-content">
|
||||
<div class="log-header">
|
||||
<span class="log-operator">{{ log.operator }}</span>
|
||||
<span class="log-action">{{ log.action }}</span>
|
||||
<el-tag v-if="log.result === '成功'" size="small" type="success">成功</el-tag>
|
||||
<el-tag v-else-if="log.result === '失败'" size="small" type="danger">失败</el-tag>
|
||||
<el-tag v-else size="small" type="info">{{ log.result }}</el-tag>
|
||||
</div>
|
||||
<div v-if="log.detail" class="log-detail">{{ log.detail }}</div>
|
||||
<div class="log-time">{{ log.time }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from 'vue'
|
||||
|
||||
defineOptions({ name: 'LogPanel' })
|
||||
|
||||
interface LogItem {
|
||||
operator: string
|
||||
action: string
|
||||
result: string
|
||||
detail?: string
|
||||
time: string
|
||||
level: 'success' | 'info' | 'warning' | 'error'
|
||||
}
|
||||
|
||||
const props = defineProps<{
|
||||
/** 当前选中行数据(用于生成关联日志) */
|
||||
row: Record<string, any> | null
|
||||
/** 可选的日志 API 方法,传入后自动调用获取真实日志 */
|
||||
apiMethod?: (...args: any[]) => Promise<any>
|
||||
}>()
|
||||
|
||||
/** 通过 API 获取的真实日志列表 */
|
||||
const apiLogs = ref<LogItem[] | null>(null)
|
||||
const apiLoading = ref(false)
|
||||
|
||||
watch(() => props.row, async (newRow) => {
|
||||
if (newRow && props.apiMethod) {
|
||||
apiLoading.value = true
|
||||
try {
|
||||
const res = await props.apiMethod({
|
||||
id: newRow.id,
|
||||
code: newRow.code,
|
||||
page: 1,
|
||||
pageSize: 100
|
||||
})
|
||||
if (res && (res.code === 1 || res.code === 200)) {
|
||||
const list = res.data?.list ?? res.data?.logs ?? res.list ?? res.logs ?? []
|
||||
apiLogs.value = Array.isArray(list) ? list.map((item: any) => ({
|
||||
operator: item.operator ?? item.creator ?? '—',
|
||||
action: item.action ?? item.operation ?? '—',
|
||||
result: item.result ?? item.status ?? '—',
|
||||
detail: item.detail ?? item.description ?? '',
|
||||
time: item.time ?? item.create_time ?? '—',
|
||||
level: (item.result === '成功' || item.status === 'success') ? 'success'
|
||||
: (item.result === '失败' || item.status === 'error') ? 'error'
|
||||
: 'info'
|
||||
})) : []
|
||||
} else {
|
||||
apiLogs.value = []
|
||||
}
|
||||
} catch {
|
||||
apiLogs.value = []
|
||||
} finally {
|
||||
apiLoading.value = false
|
||||
}
|
||||
} else {
|
||||
apiLogs.value = null
|
||||
}
|
||||
}, { immediate: true })
|
||||
|
||||
/** 基于 row 生成模拟日志(无 apiMethod 时使用) */
|
||||
const mockLogs = computed<LogItem[]>(() => {
|
||||
if (!props.row) return []
|
||||
|
||||
const rowName = props.row.name ?? props.row.code ?? '—'
|
||||
const now = new Date()
|
||||
const pad = (n: number) => String(n).padStart(2, '0')
|
||||
const fmt = (d: Date) =>
|
||||
`${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`
|
||||
|
||||
return [
|
||||
{
|
||||
operator: '系统',
|
||||
action: `创建了「${rowName}」`,
|
||||
result: '成功',
|
||||
time: fmt(new Date(now.getTime() - 3600000 * 3)),
|
||||
level: 'success'
|
||||
},
|
||||
{
|
||||
operator: props.row.creator ?? '管理员',
|
||||
action: `更新了「${rowName}」`,
|
||||
result: '成功',
|
||||
detail: `修改了状态和相关配置`,
|
||||
time: fmt(new Date(now.getTime() - 3600000)),
|
||||
level: 'success'
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
/** 最终展示的日志:优先使用 API 日志,否则使用 mock 日志 */
|
||||
const logs = computed<LogItem[]>(() => {
|
||||
if (apiLogs.value !== null) {
|
||||
return apiLogs.value
|
||||
}
|
||||
return mockLogs.value
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.log-panel {
|
||||
padding: 8px 0;
|
||||
}
|
||||
|
||||
.empty-tip {
|
||||
text-align: center;
|
||||
font-size: 13px;
|
||||
color: #909399;
|
||||
padding: 40px 0;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: #303133;
|
||||
margin-bottom: 12px;
|
||||
padding-left: 4px;
|
||||
border-left: 3px solid #409eff;
|
||||
}
|
||||
|
||||
.log-timeline {
|
||||
padding-left: 8px;
|
||||
|
||||
.log-item {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
margin-bottom: 12px;
|
||||
padding-bottom: 8px;
|
||||
border-bottom: 1px dashed #ebeef5;
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.log-dot {
|
||||
flex-shrink: 0;
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
margin-top: 6px;
|
||||
border-radius: 50%;
|
||||
background: #c0c4cc;
|
||||
|
||||
&.success {
|
||||
background: #67c23a;
|
||||
}
|
||||
|
||||
&.warning {
|
||||
background: #e6a23c;
|
||||
}
|
||||
|
||||
&.error {
|
||||
background: #f56c6c;
|
||||
}
|
||||
|
||||
&.info {
|
||||
background: #409eff;
|
||||
}
|
||||
}
|
||||
|
||||
.log-content {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.log-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.log-operator {
|
||||
font-weight: 600;
|
||||
font-size: 13px;
|
||||
color: #303133;
|
||||
}
|
||||
|
||||
.log-action {
|
||||
font-size: 13px;
|
||||
color: #606266;
|
||||
}
|
||||
|
||||
.log-detail {
|
||||
margin-top: 4px;
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
}
|
||||
|
||||
.log-time {
|
||||
margin-top: 2px;
|
||||
font-size: 12px;
|
||||
color: #c0c4cc;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
682
src/views/system/setting/printcomputer/config/template-config.ts
Normal file
682
src/views/system/setting/printcomputer/config/template-config.ts
Normal file
@ -0,0 +1,682 @@
|
||||
/**
|
||||
* 【页面模板】配置文件 v2 — 基于 waveOrder2 架构设计
|
||||
*
|
||||
* ===== 核心设计 =====
|
||||
*
|
||||
* 1. FIELD_DICT — 全局字段预设表,每个字段拥有唯一翻译(label)和完整元数据
|
||||
* 2. VALUE_MAPS — 值翻译映射表(select options 和 tag 翻译共用)
|
||||
* 3. TAG_RESOLVERS — 标签颜色解析器(集中管理 tag 颜色逻辑)
|
||||
* 4. 各标签页通过 key 引用所需字段(scanBoxFieldKeys / tableColumnKeys)
|
||||
* 5. resolveTabConfig() — 加载时将 key 列表展开为完整配置
|
||||
*
|
||||
* ===== 快速上手 =====
|
||||
* 1. 复制整个 views/mode/ 文件夹,重命名为你的页面名
|
||||
* 2. 在 FIELD_DICT 中添加你需要的字段定义
|
||||
* 3. 在 tabPages 中配置标签页(引用 FIELD_DICT 的 key)
|
||||
* 4. 在 TabPageApiConfig 中接入真实接口
|
||||
* 5. 在 router/map.ts 中添加路由
|
||||
*/
|
||||
|
||||
import { list as printComputerList, update as printComputerUpdate, del as printComputerDel, setRecording as printComputerSetRecording, cancelRecording as printComputerCancelRecording } from '@/api/print_computer/print_computer'
|
||||
|
||||
// ============================================================
|
||||
// 〇、全局页面配置
|
||||
// ============================================================
|
||||
export const PAGE_CONFIG = {
|
||||
/** 是否显示顶部多标签栏 */
|
||||
showTabArea: false,
|
||||
/** 单页模式:不显示标签栏,仅一个标签页内容 */
|
||||
singlePage: true,
|
||||
/** 是否启用详情面板(底部分栏 + 显示/隐藏详情按钮),false 时表格占满全高 */
|
||||
enableDetailPanel: false
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 〇-A、组件注册表 — 所有可复用组件在此注册
|
||||
// ============================================================
|
||||
export const COMPONENT_REGISTRY: Record<string, any> = {}
|
||||
|
||||
// ============================================================
|
||||
// 〇-B、SCANBOX_GROUPS — ScanBox 分组名称
|
||||
// ============================================================
|
||||
export const SCANBOX_GROUPS = {
|
||||
basic: '基础信息',
|
||||
process: '流程状态',
|
||||
time: '时间范围',
|
||||
custom: '自定义字段'
|
||||
} as const
|
||||
|
||||
// ============================================================
|
||||
// 一、FIELD_DICT — 全局字段预设表(唯一真相来源)
|
||||
// ============================================================
|
||||
// 每个字段拥有:
|
||||
// label — 唯一翻译文本
|
||||
// scanBox — ScanBox 渲染配置(type/options/group)
|
||||
// table — 表格列配置(minWidth/fixed/align/sortable)
|
||||
// slot — 单元格渲染配置(tag/tagResolver/translateField)
|
||||
// detailLabel — 明细面板中的标签文本(可选,默认用 label)
|
||||
// filterParamMap — ScanBox 筛选值 → API 传参值映射
|
||||
|
||||
export interface FieldDefinition {
|
||||
key: string
|
||||
label: string
|
||||
scanBox: {
|
||||
type: 'text' | 'select' | 'daterange' | 'number'
|
||||
group?: string
|
||||
options?: { label: string; value: any }[]
|
||||
} | null
|
||||
table: {
|
||||
minWidth?: number
|
||||
width?: number
|
||||
fixed?: 'left' | 'right' | boolean
|
||||
align?: 'left' | 'center' | 'right'
|
||||
sortable?: boolean
|
||||
showOverflowTooltip?: boolean
|
||||
copyAction?: 'copy' | 'copyQr'
|
||||
copyValue?: (row: any) => any
|
||||
} | null
|
||||
slot: {
|
||||
type: 'tag' | 'text' | 'default' | 'operation'
|
||||
tagType?: string | Record<string, string>
|
||||
tagResolver?: string
|
||||
translateField?: string
|
||||
format?: 'datetime'
|
||||
} | null
|
||||
detailLabel?: string
|
||||
filterParamMap?: Record<string, string>
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// VALUE_MAPS — 值翻译映射(select options 和 tag 翻译共用)
|
||||
// ============================================================
|
||||
export const VALUE_MAPS: Record<string, Record<string, string>> = {
|
||||
onlineStatus: { '1': '在线', '0': '离线' },
|
||||
recordingStatus: { '1': '录制中', '0': '未录制', 'true': '录制中', 'false': '未录制' }
|
||||
}
|
||||
|
||||
/** 从 VALUE_MAPS 衍生 options(优先取中文值作为 option value) */
|
||||
export function getOptions(field: string): { label: string; value: string }[] {
|
||||
const map = VALUE_MAPS[field]
|
||||
if (!map) return []
|
||||
const seen = new Set<string>()
|
||||
const opts: { label: string; value: string }[] = []
|
||||
const chineseKeys: [string, string][] = []
|
||||
const otherKeys: [string, string][] = []
|
||||
for (const [v, l] of Object.entries(map)) {
|
||||
if (/^[\u4e00-\u9fa5]/.test(v)) {
|
||||
chineseKeys.push([v, l])
|
||||
} else {
|
||||
otherKeys.push([v, l])
|
||||
}
|
||||
}
|
||||
for (const [v, l] of [...chineseKeys, ...otherKeys]) {
|
||||
if (!seen.has(l)) {
|
||||
seen.add(l)
|
||||
opts.push({ label: l, value: v })
|
||||
}
|
||||
}
|
||||
return opts
|
||||
}
|
||||
|
||||
/** 翻译 value → label */
|
||||
export function translate(field: string, value: any): string {
|
||||
const map = VALUE_MAPS[field]
|
||||
if (!map) return String(value ?? '—')
|
||||
return map[String(value)] ?? String(value ?? '—')
|
||||
}
|
||||
|
||||
/** 格式化时间戳为 YYYY-MM-DD HH:mm:ss */
|
||||
export function formatTime(value: any): string {
|
||||
if (!value) return '—'
|
||||
try {
|
||||
const d = new Date(value)
|
||||
if (isNaN(d.getTime())) return String(value)
|
||||
const pad = (n: number) => String(n).padStart(2, '0')
|
||||
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`
|
||||
} catch {
|
||||
return String(value)
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// TAG_RESOLVERS — 标签颜色解析器
|
||||
// ============================================================
|
||||
// 颜色规则:未xx=info(灰) 已xx=success(绿) xx中/部分xx=warning(黄) 错误=danger(红)
|
||||
export const TAG_RESOLVERS: Record<string, (val: any) => string> = {
|
||||
resolveOnlineTag(v) {
|
||||
if (v === 1 || v === '1' || v === '在线') return 'success'
|
||||
return 'info'
|
||||
},
|
||||
resolveRecordingTag(v) {
|
||||
if (v === true || v === 'true' || v === 1 || v === '1' || v === '录制中') return 'warning'
|
||||
return 'info'
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 二、FIELD_DICT 实例 — 在此定义页面所需的所有字段
|
||||
// ============================================================
|
||||
export const FIELD_DICT: Record<string, FieldDefinition> = {
|
||||
name: {
|
||||
key: 'name',
|
||||
label: '电脑名称',
|
||||
scanBox: { type: 'text', group: SCANBOX_GROUPS.basic },
|
||||
table: { minWidth: 150, fixed: 'left', showOverflowTooltip: true, sortable: true },
|
||||
slot: null
|
||||
},
|
||||
id: {
|
||||
key: 'id',
|
||||
label: 'ID',
|
||||
scanBox: { type: 'number', group: SCANBOX_GROUPS.basic },
|
||||
table: { minWidth: 72, showOverflowTooltip: true, sortable: true },
|
||||
slot: null
|
||||
},
|
||||
is_online: {
|
||||
key: 'is_online',
|
||||
label: '在线状态',
|
||||
scanBox: { type: 'select', group: SCANBOX_GROUPS.process, options: getOptions('onlineStatus') },
|
||||
table: { minWidth: 90, align: 'center' },
|
||||
slot: { type: 'tag', tagResolver: 'resolveOnlineTag', translateField: 'onlineStatus' }
|
||||
},
|
||||
is_recording: {
|
||||
key: 'is_recording',
|
||||
label: '录制状态',
|
||||
scanBox: { type: 'select', group: SCANBOX_GROUPS.process, options: getOptions('recordingStatus') },
|
||||
table: { minWidth: 90, align: 'center' },
|
||||
slot: { type: 'tag', tagResolver: 'resolveRecordingTag', translateField: 'recordingStatus' }
|
||||
},
|
||||
last_login_time: {
|
||||
key: 'last_login_time',
|
||||
label: '最后登录',
|
||||
scanBox: null,
|
||||
table: { minWidth: 160, sortable: true },
|
||||
slot: { type: 'text', format: 'datetime' }
|
||||
},
|
||||
recording_size_value: {
|
||||
key: 'recording_size_value',
|
||||
label: '录制大小',
|
||||
scanBox: null,
|
||||
table: { minWidth: 110, showOverflowTooltip: true },
|
||||
slot: null
|
||||
},
|
||||
recording_directory: {
|
||||
key: 'recording_directory',
|
||||
label: '录制目录',
|
||||
scanBox: { type: 'text', group: SCANBOX_GROUPS.custom },
|
||||
table: { minWidth: 150, showOverflowTooltip: true },
|
||||
slot: null
|
||||
},
|
||||
remote_play_url: {
|
||||
key: 'remote_play_url',
|
||||
label: '远程播放地址',
|
||||
scanBox: null,
|
||||
table: { minWidth: 180, showOverflowTooltip: true },
|
||||
slot: null
|
||||
},
|
||||
create_at: {
|
||||
key: 'create_at',
|
||||
label: '创建时间',
|
||||
scanBox: { type: 'daterange', group: SCANBOX_GROUPS.time },
|
||||
table: { minWidth: 160, sortable: true },
|
||||
slot: { type: 'text', format: 'datetime' }
|
||||
},
|
||||
update_at: {
|
||||
key: 'update_at',
|
||||
label: '更新时间',
|
||||
scanBox: { type: 'daterange', group: SCANBOX_GROUPS.time },
|
||||
table: { minWidth: 160, sortable: true },
|
||||
slot: { type: 'text', format: 'datetime' }
|
||||
},
|
||||
operation: {
|
||||
key: 'operation',
|
||||
label: '操作',
|
||||
scanBox: null,
|
||||
table: { minWidth: 220, fixed: 'right', align: 'center' },
|
||||
slot: { type: 'operation' }
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 三、ColumnSlotConfig — 列单元格渲染配置
|
||||
// ============================================================
|
||||
export interface ColumnSlotConfig {
|
||||
type: 'tag' | 'text' | 'default' | 'operation'
|
||||
tagType?: string | Record<string, string>
|
||||
tagResolver?: string
|
||||
translateField?: string
|
||||
format?: 'datetime'
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 三-A、OperationButtonConfig — 操作列按钮配置
|
||||
// ============================================================
|
||||
export interface OperationButtonConfig {
|
||||
key: string
|
||||
label: string
|
||||
type?: 'primary' | 'success' | 'warning' | 'danger' | 'info' | ''
|
||||
actionType: 'form' | 'action'
|
||||
formKey?: string
|
||||
formTitle?: string
|
||||
formWidth?: string
|
||||
paramMap?: Record<string, string>
|
||||
extraParams?: Record<string, any>
|
||||
disabledOnField?: string
|
||||
confirmMessage?: string
|
||||
confirmTitle?: string
|
||||
confirmType?: 'warning' | 'danger' | 'info'
|
||||
confirmButtonText?: string
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 四、DetailFieldConfig / DetailSectionConfig — 明细面板配置
|
||||
// ============================================================
|
||||
export interface DetailFieldConfig {
|
||||
key: string
|
||||
label?: string
|
||||
span?: number
|
||||
renderType?: 'text' | 'tag' | 'pre'
|
||||
tagType?: string | Record<string, string>
|
||||
tagResolver?: string
|
||||
translateField?: string
|
||||
}
|
||||
|
||||
export interface DetailSectionConfig {
|
||||
title: string
|
||||
columnCount: number
|
||||
fields: DetailFieldConfig[]
|
||||
}
|
||||
|
||||
export interface DetailTabConfig {
|
||||
name: string
|
||||
label: string
|
||||
componentKey: string
|
||||
component?: any
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 五、TabPageApiConfig — 标签页接口插槽配置
|
||||
// ============================================================
|
||||
export type ApiMethod = (...args: any[]) => Promise<any>
|
||||
export type ApiSource = 'api' | 'list'
|
||||
export type ComponentApiConfig = { source: 'list' } | ApiMethod
|
||||
|
||||
export interface TabPageApiConfig {
|
||||
/** 列表查询接口 */
|
||||
list: ApiMethod
|
||||
/** 明细面板接口(可选,不配则用 row 数据) */
|
||||
detail?: ComponentApiConfig
|
||||
/** 操作日志接口(可选) */
|
||||
log?: ComponentApiConfig
|
||||
/** 导出接口(可选) */
|
||||
export?: ApiMethod
|
||||
/** 导出进度查询接口(可选) */
|
||||
exportProgress?: ApiMethod
|
||||
/** ScanBox 下拉选项数据源接口(可选) */
|
||||
scanBoxOptions?: Record<string, ApiMethod>
|
||||
/** 工具栏按钮 → API 方法映射(可选) */
|
||||
toolbar?: Record<string, ApiMethod>
|
||||
/** 列表响应解析器 */
|
||||
parseListResponse?: (res: any) => { list: any[]; total: number }
|
||||
/** 构建列表请求参数 */
|
||||
buildListParams?: (params: {
|
||||
pagination: { page: number; pageSize: number }
|
||||
conditions: Record<string, any>
|
||||
sort?: { prop: string; order: string }
|
||||
}) => Record<string, any>
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 六、TabPageRawConfig — 标签页声明配置(仅用 key 引用)
|
||||
// ============================================================
|
||||
export interface TabPageRawConfig {
|
||||
name: string
|
||||
label: string
|
||||
scanBoxCacheKey: string
|
||||
/** ScanBox 需要的字段 key 列表(从 FIELD_DICT 中查找) */
|
||||
scanBoxFieldKeys: string[]
|
||||
/** 表格需要的列 key 列表(从 FIELD_DICT 中查找) */
|
||||
tableColumnKeys: string[]
|
||||
upperTableDefaults: {
|
||||
title: string
|
||||
enableColumnConfig?: boolean
|
||||
showIndex?: boolean
|
||||
showSelection?: boolean
|
||||
emptyText?: string
|
||||
}
|
||||
/** 明细面板标签页配置 */
|
||||
detailTabs?: { name: string; label: string; componentKey: string }[]
|
||||
/** 明细面板分区配置(字段 key 列表,resolveTabConfig 展开) */
|
||||
detailSections: {
|
||||
title: string
|
||||
columnCount: number
|
||||
fieldKeys: string[]
|
||||
}[]
|
||||
/** 接口配置(有 api 时启用真实接口) */
|
||||
api?: TabPageApiConfig
|
||||
/** 操作列按钮配置(需 tableColumnKeys 包含 'operation') */
|
||||
operationButtons?: OperationButtonConfig[]
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 七、TabPageConfig — 展开后的完整配置(给 index.vue 使用)
|
||||
// ============================================================
|
||||
export interface TabPageConfig {
|
||||
name: string
|
||||
label: string
|
||||
scanBoxCacheKey: string
|
||||
scanBoxFields: Record<string, any>[]
|
||||
upperTable: {
|
||||
title: string
|
||||
enableColumnConfig: boolean
|
||||
showIndex: boolean
|
||||
showSelection: boolean
|
||||
emptyText: string
|
||||
columns: Record<string, any>[]
|
||||
}
|
||||
columnSlots: Record<string, ColumnSlotConfig>
|
||||
detailConfig: DetailSectionConfig[]
|
||||
detailTabs: DetailTabConfig[]
|
||||
api?: TabPageApiConfig
|
||||
operationButtons?: OperationButtonConfig[]
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 八、resolveTabConfig — 加载时将 RawConfig 展开为完整配置
|
||||
// ============================================================
|
||||
export function resolveTabConfig(raw: TabPageRawConfig): TabPageConfig {
|
||||
// 展开 ScanBox 字段
|
||||
const scanBoxFields: Record<string, any>[] = []
|
||||
for (const key of raw.scanBoxFieldKeys) {
|
||||
const def = FIELD_DICT[key]
|
||||
if (!def || !def.scanBox) continue
|
||||
scanBoxFields.push({
|
||||
label: def.label,
|
||||
value: def.key,
|
||||
type: def.scanBox.type,
|
||||
options: def.scanBox.options ? [...def.scanBox.options] : undefined,
|
||||
group: def.scanBox.group,
|
||||
required: (def.scanBox as any).required
|
||||
})
|
||||
}
|
||||
|
||||
// 展开表格列
|
||||
const columns: Record<string, any>[] = []
|
||||
for (const key of raw.tableColumnKeys) {
|
||||
const def = FIELD_DICT[key]
|
||||
if (!def || !def.table) continue
|
||||
columns.push({
|
||||
prop: def.key,
|
||||
label: def.label,
|
||||
...def.table
|
||||
})
|
||||
}
|
||||
|
||||
// 展开列插槽
|
||||
const columnSlots: Record<string, ColumnSlotConfig> = {}
|
||||
for (const key of raw.tableColumnKeys) {
|
||||
const def = FIELD_DICT[key]
|
||||
if (!def || !def.slot) continue
|
||||
columnSlots[def.key] = { ...def.slot }
|
||||
}
|
||||
|
||||
// 展开明细面板配置
|
||||
const detailConfig: DetailSectionConfig[] = raw.detailSections.map((sec) => ({
|
||||
title: sec.title,
|
||||
columnCount: sec.columnCount,
|
||||
fields: sec.fieldKeys
|
||||
.map((key): DetailFieldConfig | null => {
|
||||
const def = FIELD_DICT[key]
|
||||
if (!def) return null
|
||||
return {
|
||||
key: def.key,
|
||||
label: def.detailLabel ?? def.label,
|
||||
translateField: def.slot?.translateField,
|
||||
tagResolver: def.slot?.tagResolver,
|
||||
tagType: def.slot?.tagType,
|
||||
renderType: def.slot?.type === 'tag' ? 'tag' : 'text'
|
||||
}
|
||||
})
|
||||
.filter((f): f is DetailFieldConfig => f !== null)
|
||||
}))
|
||||
|
||||
// 展开明细标签页(解析 componentKey → Component)
|
||||
const detailTabs: DetailTabConfig[] = raw.detailTabs
|
||||
? raw.detailTabs.map((tab) => ({
|
||||
name: tab.name,
|
||||
label: tab.label,
|
||||
componentKey: tab.componentKey,
|
||||
component: COMPONENT_REGISTRY[tab.componentKey]
|
||||
}))
|
||||
: [{ name: 'detail', label: '明细', componentKey: 'DetailPanel', component: COMPONENT_REGISTRY['DetailPanel'] }]
|
||||
|
||||
return {
|
||||
name: raw.name,
|
||||
label: raw.label,
|
||||
scanBoxCacheKey: raw.scanBoxCacheKey,
|
||||
scanBoxFields,
|
||||
upperTable: {
|
||||
title: raw.upperTableDefaults.title,
|
||||
enableColumnConfig: raw.upperTableDefaults.enableColumnConfig ?? true,
|
||||
showIndex: raw.upperTableDefaults.showIndex ?? true,
|
||||
showSelection: raw.upperTableDefaults.showSelection ?? true,
|
||||
emptyText: raw.upperTableDefaults.emptyText ?? '暂无数据',
|
||||
columns
|
||||
},
|
||||
columnSlots,
|
||||
detailConfig,
|
||||
detailTabs,
|
||||
api: raw.api,
|
||||
operationButtons: raw.operationButtons
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 九、buildWhereConditions — 将 ScanBox 条件转为 API where 参数
|
||||
// ============================================================
|
||||
export function buildWhereConditions(rawConditions: Record<string, any>): Record<string, any> {
|
||||
const where: Record<string, any> = {}
|
||||
for (const [key, cond] of Object.entries(rawConditions || {})) {
|
||||
let value: any = undefined
|
||||
if (cond && typeof cond === 'object' && 'operator' in cond) {
|
||||
value = (cond as any).value
|
||||
} else if (cond !== undefined && cond !== null && cond !== '') {
|
||||
value = Array.isArray(cond) ? cond[0] ?? '' : cond
|
||||
}
|
||||
if (value === undefined || value === null || value === '' || (Array.isArray(value) && value.length === 0)) {
|
||||
continue
|
||||
}
|
||||
const def = FIELD_DICT[key]
|
||||
if (def?.filterParamMap) {
|
||||
const mapped = def.filterParamMap[String(value)]
|
||||
if (mapped !== undefined) {
|
||||
where[key] = mapped
|
||||
continue
|
||||
}
|
||||
}
|
||||
where[key] = value
|
||||
}
|
||||
return where
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 十、工具栏按钮系统
|
||||
// ============================================================
|
||||
// 按钮分为三类:
|
||||
// common — 公共按钮(刷新、导出)
|
||||
// function — 功能按钮(打开表单/确认窗口)
|
||||
// basic — 基础操作(字段设置、隐藏详情)
|
||||
|
||||
export interface ToolbarButtonConfig {
|
||||
key: string
|
||||
label: string
|
||||
category: 'common' | 'function' | 'basic'
|
||||
size?: '' | 'default' | 'small' | 'large'
|
||||
type?: '' | 'primary' | 'success' | 'warning' | 'info' | 'danger'
|
||||
plain?: boolean
|
||||
loadingKey?: string
|
||||
disabledKey?: string
|
||||
action: string
|
||||
dynamicLabelKey?: string
|
||||
onlyForTabs?: string[]
|
||||
buttonType?: 'default' | 'dropdown'
|
||||
dropdownOptions?: Array<{ label: string; action: string; divided?: boolean }>
|
||||
formKey?: string
|
||||
}
|
||||
|
||||
export const TOOLBAR_BUTTONS: Record<string, ToolbarButtonConfig> = {
|
||||
refresh: {
|
||||
key: 'refresh',
|
||||
label: '刷新',
|
||||
category: 'common',
|
||||
type: 'primary',
|
||||
size: 'small',
|
||||
loadingKey: 'loading',
|
||||
action: 'loadData'
|
||||
},
|
||||
batchDelete: {
|
||||
key: 'batchDelete',
|
||||
label: '批量删除',
|
||||
category: 'function',
|
||||
type: 'danger',
|
||||
size: 'small',
|
||||
disabledKey: 'noSelection',
|
||||
action: 'batchDelete'
|
||||
}
|
||||
}
|
||||
|
||||
/** 按标签页名称获取工具栏按钮列表(自动根据 PAGE_CONFIG 过滤) */
|
||||
export function getTabToolbarButtons(tabName: string): ToolbarButtonConfig[] {
|
||||
return Object.values(TOOLBAR_BUTTONS).filter((btn) => {
|
||||
if (btn.onlyForTabs && !btn.onlyForTabs.includes(tabName)) return false
|
||||
// 详情面板禁用时,隐藏「显示/隐藏详情」按钮
|
||||
if (!PAGE_CONFIG.enableDetailPanel && btn.key === 'toggleDetail') return false
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 十一、批量操作配置(可选,接入 BatchOperationForm 时使用)
|
||||
// ============================================================
|
||||
export interface BatchOperationConfig {
|
||||
action: string
|
||||
title: string
|
||||
confirmText: string
|
||||
confirmType?: 'warning' | 'error' | 'info' | 'success'
|
||||
confirmButtonText: string
|
||||
successText: string
|
||||
failText: string
|
||||
apiMethod: (...args: any[]) => Promise<any>
|
||||
payloadKey?: string
|
||||
idField?: string | string[]
|
||||
payloadBuilder?: (rows: Record<string, any>[]) => Record<string, any>
|
||||
useProgress?: boolean
|
||||
progressApiMethod?: (...args: any[]) => Promise<any>
|
||||
}
|
||||
|
||||
/** ★ 在此配置批量操作 */
|
||||
export const BATCH_OPERATION_CONFIGS: Record<string, BatchOperationConfig> = {
|
||||
// batchExample: {
|
||||
// action: 'batchExample',
|
||||
// title: '批量操作示例',
|
||||
// confirmText: '确定对选中的 {count} 项执行操作吗?',
|
||||
// confirmType: 'warning',
|
||||
// confirmButtonText: '确认操作',
|
||||
// successText: '批量操作成功',
|
||||
// failText: '批量操作失败',
|
||||
// apiMethod: yourBatchApi,
|
||||
// payloadKey: 'ids',
|
||||
// idField: 'id'
|
||||
// }
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 十二、标签页注册表 — 打印电脑管理(单页模式,无详情面板)
|
||||
// ============================================================
|
||||
export const tabPages: TabPageRawConfig[] = [
|
||||
{
|
||||
name: 'printcomputer',
|
||||
label: '打印电脑列表',
|
||||
scanBoxCacheKey: 'printcomputer-list',
|
||||
scanBoxFieldKeys: ['is_online', 'is_recording'],
|
||||
tableColumnKeys: ['name', 'id', 'is_online', 'is_recording', 'last_login_time', 'recording_size_value', 'recording_directory', 'remote_play_url', 'create_at', 'update_at', 'operation'],
|
||||
upperTableDefaults: {
|
||||
title: '打印电脑列表',
|
||||
showSelection: true,
|
||||
showIndex: true,
|
||||
emptyText: '暂无打印电脑数据'
|
||||
},
|
||||
detailSections: [],
|
||||
api: {
|
||||
list: printComputerList as any,
|
||||
parseListResponse(res) {
|
||||
// 兼容多种响应格式:res.data.list | res.data.data.list | res.list
|
||||
let rawList: any[] = []
|
||||
let total = 0
|
||||
const data = res.data || {}
|
||||
if (Array.isArray(data.list)) {
|
||||
rawList = data.list
|
||||
total = data.pagination?.total ?? data.total ?? rawList.length
|
||||
} else if (Array.isArray(data.data?.list)) {
|
||||
rawList = data.data.list
|
||||
total = data.data.pagination?.total ?? data.data.total ?? rawList.length
|
||||
} else if (Array.isArray(res.list)) {
|
||||
rawList = res.list
|
||||
total = res.pagination?.total ?? res.total ?? rawList.length
|
||||
}
|
||||
return { list: rawList, total }
|
||||
},
|
||||
buildListParams({ pagination, conditions }) {
|
||||
// 从 ScanBox 条件中提取值(兼容 operator 包装格式)
|
||||
const getVal = (raw: any): any => {
|
||||
if (raw == null || raw === '') return undefined
|
||||
if (typeof raw === 'object' && 'operator' in raw) return (raw as any).value
|
||||
return raw
|
||||
}
|
||||
const where: Record<string, any> = {}
|
||||
const online = getVal(conditions.is_online)
|
||||
if (online != null && online !== '') where.is_online = Number(online)
|
||||
const recording = getVal(conditions.is_recording)
|
||||
if (recording != null && recording !== '') where.is_recording = Number(recording)
|
||||
const payload: Record<string, any> = {
|
||||
pagination: { page: pagination.page, pageSize: pagination.pageSize }
|
||||
}
|
||||
if (Object.keys(where).length) {
|
||||
;(payload as any).where = where
|
||||
}
|
||||
return payload
|
||||
}
|
||||
},
|
||||
operationButtons: [
|
||||
{
|
||||
key: 'edit',
|
||||
label: '编辑',
|
||||
actionType: 'action',
|
||||
type: 'primary'
|
||||
},
|
||||
{
|
||||
key: 'setRecording',
|
||||
label: '设置录制',
|
||||
actionType: 'action',
|
||||
type: 'warning'
|
||||
},
|
||||
{
|
||||
key: 'cancelRecording',
|
||||
label: '取消录制',
|
||||
actionType: 'action',
|
||||
type: 'info'
|
||||
},
|
||||
{
|
||||
key: 'delete',
|
||||
label: '删除',
|
||||
actionType: 'action',
|
||||
type: 'danger'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
// ============================================================
|
||||
// 十三、向后兼容导出
|
||||
// ============================================================
|
||||
export const templateTabs = tabPages.map((t) => ({ name: t.name, label: t.label, scanBoxCacheKey: t.scanBoxCacheKey }))
|
||||
|
||||
1014
src/views/system/setting/printcomputer/index.vue
Normal file
1014
src/views/system/setting/printcomputer/index.vue
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,107 @@
|
||||
<!--
|
||||
ExampleFormDialog — 示例表单弹窗(模板)
|
||||
|
||||
功能按钮对应的表单组件放在 pages/ 目录下。
|
||||
|
||||
使用方式:
|
||||
1. 在 template-config.ts 的 COMPONENT_REGISTRY 中注册
|
||||
2. 在 template-config.ts 的 TOOLBAR_BUTTONS 中添加功能按钮,设置 formKey
|
||||
3. index.vue 中通过工具栏按钮触发打开
|
||||
-->
|
||||
<template>
|
||||
<el-dialog
|
||||
:model-value="visible"
|
||||
title="示例操作"
|
||||
width="500px"
|
||||
align-center
|
||||
destroy-on-close
|
||||
:close-on-click-modal="false"
|
||||
@closed="handleClosed"
|
||||
>
|
||||
<div class="form-body">
|
||||
<el-form ref="formRef" :model="form" label-width="100px" size="small">
|
||||
<el-form-item label="名称" prop="name">
|
||||
<el-input v-model="form.name" placeholder="请输入名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="描述" prop="description">
|
||||
<el-input
|
||||
v-model="form.description"
|
||||
type="textarea"
|
||||
:rows="3"
|
||||
placeholder="请输入描述"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
<el-button size="small" @click="handleClosed">取消</el-button>
|
||||
<el-button size="small" type="primary" :loading="submitting" @click="handleSubmit">
|
||||
确认
|
||||
</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { reactive, ref, watch } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
|
||||
defineOptions({ name: 'ExampleFormDialog' })
|
||||
|
||||
const props = defineProps<{
|
||||
visible: boolean
|
||||
/** 从行数据注入的初始值(由 OperationCellRenderer 的 paramMap 传递) */
|
||||
id?: string | number
|
||||
code?: string
|
||||
name?: string
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:visible', v: boolean): void
|
||||
(e: 'success'): void
|
||||
}>()
|
||||
|
||||
const formRef = ref<any>(null)
|
||||
const submitting = ref(false)
|
||||
|
||||
const form = reactive({
|
||||
name: '',
|
||||
description: ''
|
||||
})
|
||||
|
||||
// 重置表单
|
||||
watch(() => props.visible, (v) => {
|
||||
if (v) {
|
||||
form.name = props.name ?? ''
|
||||
form.description = ''
|
||||
}
|
||||
})
|
||||
|
||||
function handleClosed() {
|
||||
emit('update:visible', false)
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
submitting.value = true
|
||||
try {
|
||||
// ★ 替换为真实 API 调用
|
||||
// const res = await yourApi.submit({ id: props.id, ...form })
|
||||
await new Promise((r) => setTimeout(r, 500))
|
||||
|
||||
ElMessage.success('操作成功')
|
||||
emit('update:visible', false)
|
||||
emit('success')
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.message || '操作失败')
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.form-body {
|
||||
padding: 12px 0;
|
||||
}
|
||||
</style>
|
||||
Loading…
x
Reference in New Issue
Block a user