945 lines
33 KiB
Vue
945 lines
33 KiB
Vue
<!--
|
||
╔══════════════════════════════════════════════════════════════╗
|
||
║ 【页面模板 v2】— 基于 waveOrder2 架构设计 ║
|
||
╚══════════════════════════════════════════════════════════════╝
|
||
|
||
===== 快速复制使用 =====
|
||
1. 复制整个 views/mode/ 文件夹 → 重命名为你的页面名(如 views/order/myPage/)
|
||
2. 修改 defineOptions name(如 'MyPage')
|
||
3. 编辑 config/template-config.ts:
|
||
a. 在 FIELD_DICT 中添加页面字段
|
||
b. 在 tabPages 中配置标签页(引用 FIELD_DICT 的 key)
|
||
c. 在 TabPageApiConfig 中接入真实接口
|
||
4. 在 router/map.ts 中添加路由
|
||
|
||
===== 页面结构 =====
|
||
┌─────────────────────────────────────────────────────────┐
|
||
│ TabArea(多标签页切换,可关闭) │
|
||
├──────────┬──────────────────────────────────────────────┤
|
||
│ ScanBox │ OrderToolbarButtonGroup(工具栏按钮组) │
|
||
│ 筛选面板 │ ┌──────────────────────────────────────────┐│
|
||
│ │ │ UpperTable(表格) ││
|
||
│ │ │ - OperationCellRenderer(操作列) ││
|
||
│ │ ├──────────────────────────────────────────┤│
|
||
│ │ │ 分隔条(可拖拽) ││
|
||
│ │ ├──────────────────────────────────────────┤│
|
||
│ │ │ DetailPanel / LogPanel(明细/日志面板) ││
|
||
│ │ └──────────────────────────────────────────┘│
|
||
└──────────┴──────────────────────────────────────────────┘
|
||
-->
|
||
<template>
|
||
<div class="page-wrapper" :style="{ height: containerHeight }">
|
||
<!-- ===== 多标签模式:显示顶部标签栏 ===== -->
|
||
<template v-if="PAGE_CONFIG.showTabArea && !PAGE_CONFIG.singlePage">
|
||
<div class="tab-section">
|
||
<!-- 标签排序入口(tab 区域左侧) -->
|
||
<div class="tab-sort-entry">
|
||
<el-tooltip content="标签排序" placement="bottom">
|
||
<el-button class="sort-entry-btn" size="small" link @click="openSortDialog">
|
||
<el-icon><Sort /></el-icon>
|
||
</el-button>
|
||
</el-tooltip>
|
||
</div>
|
||
<TabArea
|
||
:tabs="tabList"
|
||
:default-active="activeTabName"
|
||
:header-left-inset="46"
|
||
@tab-change="handleTabChange"
|
||
/>
|
||
</div>
|
||
</template>
|
||
|
||
<!-- ===== 主内容区 ===== -->
|
||
<div class="main-container">
|
||
<!-- 表单页形态:直接渲染表单项页面(不使用 scan-box / upper-table / 明细) -->
|
||
<div v-if="isFormView" :key="`form-${activeTabName}`" class="form-page-container">
|
||
<component :is="currentFormPage" />
|
||
</div>
|
||
|
||
<!-- 列表形态:scan-box + upper-table -->
|
||
<div v-else class="order-sub-container">
|
||
<!-- 左侧:ScanBox 筛选面板 -->
|
||
<ScanBox
|
||
ref="scanBoxRef"
|
||
:cache-key="currentScanBoxCacheKey"
|
||
width="220px"
|
||
:tree-props="{ children: 'children', label: 'label' }"
|
||
:auto-submit="false"
|
||
:preset-tree="presetTree"
|
||
:available-fields="currentScanBoxFields"
|
||
@condition-change="handleConditionChange"
|
||
@reset="handleConditionReset"
|
||
@condition-clear="handleConditionClear"
|
||
/>
|
||
|
||
<!-- 右侧:内容区 -->
|
||
<div class="main-content">
|
||
<transition name="tab-fade" mode="out-in">
|
||
<div :key="activeTabName" class="tab-content-inner">
|
||
<!-- 工具栏按钮组 -->
|
||
<div class="toolbar">
|
||
<div class="toolbar-left">
|
||
<OrderToolbarButtonGroup
|
||
:buttons="currentToolbarButtons"
|
||
:resolve-disabled="resolveButtonDisabled"
|
||
:resolve-loading="resolveButtonLoading"
|
||
:resolve-label="resolveButtonLabel"
|
||
:layout-key="toolbarLayoutKey"
|
||
@action="handleToolbarButtonClick"
|
||
/>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 上下分栏区域:详情面板启用时才显示分栏 + 详情 -->
|
||
<template v-if="PAGE_CONFIG.enableDetailPanel">
|
||
<div class="split-stack" ref="splitStackRef">
|
||
<!-- 上半:表格 -->
|
||
<div class="upper-wrapper" :style="detailVisible ? upperPaneStyle : upperPaneFullStyle">
|
||
<UpperTable
|
||
ref="upperTableRef"
|
||
:title="currentTabConfig?.upperTable.title ?? '列表'"
|
||
default-align="center"
|
||
:enable-column-config="currentTabConfig?.upperTable.enableColumnConfig ?? true"
|
||
:column-config-schema-version="1"
|
||
:table-id="`template-table-${activeTabName}`"
|
||
:data="listData"
|
||
:row-key="'id'"
|
||
:columns="currentColumns"
|
||
table-size="small"
|
||
:pagination="pagination"
|
||
:show-index="currentTabConfig?.upperTable.showIndex ?? true"
|
||
:show-selection="currentTabConfig?.upperTable.showSelection ?? true"
|
||
:loading="loading"
|
||
:query-time="queryTime"
|
||
@current-change="handleRowClick"
|
||
@row-click="handleRowClick"
|
||
@page-change="handlePageChange"
|
||
@page-size-change="handlePageSizeChange"
|
||
@refresh="loadData"
|
||
@sort-change="handleSortChange"
|
||
@selection-change="handleSelectionChange"
|
||
>
|
||
<!-- 动态列插槽:根据 columnSlots 配置自动渲染 -->
|
||
<template
|
||
v-for="(slotConfig, colProp) in currentColumnSlots"
|
||
:key="`columnSlots-${colProp}`"
|
||
#[`column-${colProp}`]="{ row }"
|
||
>
|
||
<!-- 操作列:渲染操作按钮 -->
|
||
<OperationCellRenderer
|
||
v-if="slotConfig.type === 'operation'"
|
||
:buttons="currentTabConfig?.operationButtons"
|
||
:row="row"
|
||
@operation-action="handleOperationAction"
|
||
/>
|
||
<!-- 其他列:标签/文本渲染 -->
|
||
<ColumnCellRenderer
|
||
v-else
|
||
:config="slotConfig"
|
||
:value="row[colProp]"
|
||
/>
|
||
</template>
|
||
|
||
<template #empty>
|
||
<div class="empty-tip">{{ currentTabConfig?.upperTable.emptyText ?? '暂无数据' }}</div>
|
||
</template>
|
||
</UpperTable>
|
||
</div>
|
||
|
||
<!-- 分隔条(可拖拽) -->
|
||
<template v-if="detailVisible">
|
||
<div
|
||
class="pane-resizer"
|
||
title="拖动调整列表与详情区域高度"
|
||
@mousedown="beginSplitDrag"
|
||
/>
|
||
|
||
<!-- 下半:明细面板 -->
|
||
<div v-if="selectedRow" class="lower-level" :style="lowerPaneStyle">
|
||
<div class="detail-header">
|
||
<el-tabs v-model="activeDetailTab" class="detail-tab">
|
||
<el-tab-pane
|
||
v-for="tab in currentDetailTabs"
|
||
:key="tab.name"
|
||
:label="tab.label"
|
||
:name="tab.name"
|
||
/>
|
||
</el-tabs>
|
||
</div>
|
||
<div class="detail-container">
|
||
<component
|
||
:is="activeDetailTabComponent"
|
||
:row="selectedDetail"
|
||
:detail-config="currentDetailConfig"
|
||
:api-method="currentDetailTabApiMethod"
|
||
/>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 未选中行时的占位 -->
|
||
<div v-else class="no-selection" :style="lowerPaneStyle">
|
||
<div class="empty-tip">
|
||
<p>请从上方列表中选择一项查看详情</p>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
</div>
|
||
</template>
|
||
|
||
<!-- 详情面板禁用:表格占满全高 -->
|
||
<template v-else>
|
||
<div class="upper-wrapper upper-wrapper--full">
|
||
<UpperTable
|
||
ref="upperTableRef"
|
||
:title="currentTabConfig?.upperTable.title ?? '列表'"
|
||
default-align="center"
|
||
:enable-column-config="currentTabConfig?.upperTable.enableColumnConfig ?? true"
|
||
:column-config-schema-version="1"
|
||
:table-id="`template-table-${activeTabName}`"
|
||
:data="listData"
|
||
:row-key="'id'"
|
||
:columns="currentColumns"
|
||
table-size="small"
|
||
:pagination="pagination"
|
||
:show-index="currentTabConfig?.upperTable.showIndex ?? true"
|
||
:show-selection="currentTabConfig?.upperTable.showSelection ?? false"
|
||
:loading="loading"
|
||
:query-time="queryTime"
|
||
@current-change="handleRowClick"
|
||
@row-click="handleRowClick"
|
||
@page-change="handlePageChange"
|
||
@page-size-change="handlePageSizeChange"
|
||
@refresh="loadData"
|
||
@sort-change="handleSortChange"
|
||
@selection-change="handleSelectionChange"
|
||
>
|
||
<template
|
||
v-for="(slotConfig, colProp) in currentColumnSlots"
|
||
:key="`columnSlots-${colProp}`"
|
||
#[`column-${colProp}`]="{ row }"
|
||
>
|
||
<OperationCellRenderer
|
||
v-if="slotConfig.type === 'operation'"
|
||
:buttons="currentTabConfig?.operationButtons"
|
||
:row="row"
|
||
@operation-action="handleOperationAction"
|
||
/>
|
||
<ColumnCellRenderer
|
||
v-else
|
||
:config="slotConfig"
|
||
:value="row[colProp]"
|
||
/>
|
||
</template>
|
||
|
||
<template #empty>
|
||
<div class="empty-tip">{{ currentTabConfig?.upperTable.emptyText ?? '暂无数据' }}</div>
|
||
</template>
|
||
</UpperTable>
|
||
</div>
|
||
</template>
|
||
</div>
|
||
</transition>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- ===== 功能按钮表单(pages/ 目录下的组件) ===== -->
|
||
<ApiAppFormDialog
|
||
v-model:visible="apiAppCreateVisible"
|
||
@success="handleApiAppDialogSuccess"
|
||
/>
|
||
<DeliveryPlanFormDialog
|
||
v-model:visible="createPlanVisible"
|
||
@success="handlePlanSaved"
|
||
/>
|
||
<DefinitionFormDialog
|
||
v-model:visible="definitionCreateVisible"
|
||
@success="handleDefinitionSaved"
|
||
/>
|
||
|
||
<SortSettingDialog
|
||
v-model:visible="sortDialogVisible"
|
||
:tabs="DEFAULT_TAB_OPTIONS"
|
||
:scope="TAB_ORDER_SCOPE"
|
||
@saved="handleSortSaved"
|
||
/>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
// ============================================================
|
||
// ★★★ 第一步:修改组件名 ★★★
|
||
// ============================================================
|
||
defineOptions({ name: 'BasicManagement' })
|
||
|
||
import { ref, computed, onMounted, reactive } from 'vue'
|
||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||
import { Sort } from '@element-plus/icons-vue'
|
||
import { useSettingsStore } from '@/stores/modules/settings'
|
||
import { useUserPreferenceStore } from '@/stores/modules/userPreference'
|
||
import SortSettingDialog from '@/components/SortSettingDialog.vue'
|
||
import { useVerticalSplitPane } from '@/composables/useVerticalSplitPane'
|
||
import ScanBox from '@/components/ScanBox/index.vue'
|
||
import UpperTable from '@/components/UpperTable/index.vue'
|
||
import TabArea from './components/TabArea.vue'
|
||
import ColumnCellRenderer from './components/ColumnCellRenderer.vue'
|
||
import OperationCellRenderer from './components/OperationCellRenderer.vue'
|
||
import OrderToolbarButtonGroup from '@/views/order/orderManagement/component/OrderToolbarButtonGroup.vue'
|
||
import type { ToolbarButtonConfig as OrderToolbarButtonConfig } from '@/views/order/orderManagement/config/order-common-config'
|
||
import {
|
||
PAGE_CONFIG,
|
||
tabPages,
|
||
resolveTabConfig,
|
||
getTabToolbarButtons,
|
||
loadStoreOptions,
|
||
loadReportTypeList,
|
||
loadReportDefinitions,
|
||
type TabPageConfig,
|
||
type DetailTabConfig,
|
||
type ToolbarButtonConfig,
|
||
} from './config/template-config'
|
||
import { apiAppDelete, apiAppRegenerateSecret } from '@/api/apiapp/apiapp'
|
||
import { deleteReportDefinition } from '@/api/report/report'
|
||
import ApiAppFormDialog from './pages/ApiAppFormDialog.vue'
|
||
import DeliveryPlanFormDialog from './pages/DeliveryPlanFormDialog.vue'
|
||
import DefinitionFormDialog from './pages/DefinitionFormDialog.vue'
|
||
|
||
// ============================================================
|
||
// 容器高度
|
||
// ============================================================
|
||
const settingsStore = useSettingsStore()
|
||
const shortcutExpanded = computed(() => settingsStore.shortcutExpanded)
|
||
const containerHeight = computed(() =>
|
||
shortcutExpanded.value ? 'calc(100vh - 150px)' : 'calc(100vh - 100px)'
|
||
)
|
||
|
||
// ============================================================
|
||
// 标签页
|
||
// ============================================================
|
||
/** 标签排序(浏览器本地保存,scope=setting.basicManagement.tabs.order) */
|
||
const TAB_ORDER_SCOPE = 'setting.basicManagement.tabs.order'
|
||
const preferenceStore = useUserPreferenceStore()
|
||
/** 当前标签显示顺序(默认 = tabPages 配置顺序) */
|
||
const tabPagesOrder = ref<string[]>(tabPages.map((t) => t.name))
|
||
|
||
/** 默认 tab 顺序(弹窗选项 / 恢复默认用) */
|
||
const DEFAULT_TAB_OPTIONS = tabPages.map((t) => ({ name: t.name, label: t.label }))
|
||
const sortDialogVisible = ref(false)
|
||
|
||
function openSortDialog() {
|
||
sortDialogVisible.value = true
|
||
}
|
||
|
||
/** 保存标签顺序:按新顺序重排 tabPagesOrder */
|
||
function handleSortSaved(order: string[]) {
|
||
applyTabOrder(order)
|
||
}
|
||
|
||
/** 读取本账号保存的标签顺序并应用;无配置时保持默认顺序 */
|
||
function applySavedTabOrder() {
|
||
const saved = preferenceStore.get(TAB_ORDER_SCOPE)
|
||
if (!Array.isArray(saved) || !saved.length) return
|
||
applyTabOrder(saved)
|
||
}
|
||
|
||
/** 按给定 tab.name 顺序重排;非法项剔除,缺失项按配置补在末尾 */
|
||
function applyTabOrder(order: string[]) {
|
||
const byName = new Map(tabPages.map((t) => [t.name, t]))
|
||
const ordered: string[] = []
|
||
for (const name of order) {
|
||
if (byName.has(name)) ordered.push(name)
|
||
}
|
||
for (const t of tabPages) {
|
||
if (!ordered.includes(t.name)) ordered.push(t.name)
|
||
}
|
||
tabPagesOrder.value = ordered
|
||
}
|
||
|
||
/** 标签列表(按 tabPagesOrder 排序,缺失 tab 按配置补在末尾) */
|
||
const tabList = computed(() => {
|
||
const byName = new Map(tabPages.map((t) => [t.name, t]))
|
||
const names: string[] = []
|
||
for (const name of tabPagesOrder.value) {
|
||
if (byName.has(name)) names.push(name)
|
||
}
|
||
for (const t of tabPages) {
|
||
if (!names.includes(t.name)) names.push(t.name)
|
||
}
|
||
return names.map((n) => ({ name: n, label: byName.get(n)!.label }))
|
||
})
|
||
const activeTabName = ref(tabPages[0]?.name ?? 'tab1')
|
||
|
||
/** 当前激活标签页的完整配置 */
|
||
const currentTabConfig = computed<TabPageConfig | undefined>(() => {
|
||
const raw = tabPages.find((t) => t.name === activeTabName.value)
|
||
if (!raw) return undefined
|
||
return resolveTabConfig(raw)
|
||
})
|
||
|
||
/** 是否为表单页形态(viewType === 'form') */
|
||
const isFormView = computed(
|
||
() => currentTabConfig.value?.viewType === 'form'
|
||
)
|
||
|
||
/** 当前表单页组件 */
|
||
const currentFormPage = computed(
|
||
() => currentTabConfig.value?.formPage
|
||
)
|
||
|
||
/** 当前 ScanBox 缓存 key */
|
||
const currentScanBoxCacheKey = computed(
|
||
() => currentTabConfig.value?.scanBoxCacheKey ?? 'template-default'
|
||
)
|
||
|
||
/** 当前 ScanBox 筛选字段 */
|
||
const currentScanBoxFields = computed(
|
||
() => currentTabConfig.value?.scanBoxFields ?? []
|
||
)
|
||
|
||
/** 当前表格列 */
|
||
const currentColumns = computed(
|
||
() => currentTabConfig.value?.upperTable.columns ?? []
|
||
)
|
||
|
||
/** 当前列插槽配置 */
|
||
const currentColumnSlots = computed(
|
||
() => currentTabConfig.value?.columnSlots ?? {}
|
||
)
|
||
|
||
/** 当前明细面板配置 */
|
||
const currentDetailConfig = computed(
|
||
() => currentTabConfig.value?.detailConfig ?? []
|
||
)
|
||
|
||
/** 当前明细标签页列表 */
|
||
const currentDetailTabs = computed<DetailTabConfig[]>(
|
||
() => currentTabConfig.value?.detailTabs ?? []
|
||
)
|
||
|
||
/** 当前激活的明细标签页组件 */
|
||
const activeDetailTabComponent = computed(() => {
|
||
const tab = currentDetailTabs.value.find(
|
||
(t) => t.name === activeDetailTab.value
|
||
)
|
||
return tab?.component ?? null
|
||
})
|
||
|
||
/** 当前激活明细标签页对应的 API 方法 */
|
||
const currentDetailTabApiMethod = computed(() => {
|
||
const cfg = currentTabConfig.value
|
||
if (!cfg?.api) return undefined
|
||
const tab = currentDetailTabs.value.find((t) => t.name === activeDetailTab.value)
|
||
if (!tab) return undefined
|
||
|
||
let componentCfg: unknown
|
||
switch (tab.componentKey) {
|
||
case 'DetailPanel':
|
||
componentCfg = cfg.api.detail
|
||
break
|
||
case 'LogPanel':
|
||
componentCfg = cfg.api.log
|
||
break
|
||
default:
|
||
return undefined
|
||
}
|
||
|
||
if (typeof componentCfg === 'function') {
|
||
return componentCfg
|
||
}
|
||
return undefined
|
||
})
|
||
|
||
// ============================================================
|
||
// 工具栏按钮系统
|
||
// ============================================================
|
||
|
||
/** 当前标签页的工具栏按钮列表 */
|
||
const currentToolbarButtons = computed<OrderToolbarButtonConfig[]>(() => {
|
||
const btns = getTabToolbarButtons(activeTabName.value)
|
||
return btns.map((btn: ToolbarButtonConfig) => ({
|
||
key: btn.key,
|
||
label: btn.label,
|
||
size: btn.size,
|
||
type: btn.type,
|
||
plain: btn.plain,
|
||
loadingKey: btn.loadingKey,
|
||
disabledKey: btn.disabledKey,
|
||
action: btn.action,
|
||
dynamicLabelKey: btn.dynamicLabelKey,
|
||
buttonType: btn.buttonType,
|
||
dropdownOptions: btn.dropdownOptions
|
||
}))
|
||
})
|
||
|
||
const buttonDisabledMap = computed<Record<string, boolean>>(() => ({
|
||
noSelection: selectedRows.value.length === 0
|
||
}))
|
||
|
||
const buttonLoadingMap = computed<Record<string, boolean>>(() => ({
|
||
loading: loading.value,
|
||
exportLoading: false
|
||
}))
|
||
|
||
const buttonLabelMap = computed<Record<string, string>>(() => ({
|
||
detailToggleLabel: detailVisible.value ? '隐藏详情' : '显示详情'
|
||
}))
|
||
|
||
const toolbarLayoutKey = computed(() =>
|
||
JSON.stringify({
|
||
loading: buttonLoadingMap.value,
|
||
disabled: buttonDisabledMap.value,
|
||
labels: buttonLabelMap.value
|
||
})
|
||
)
|
||
|
||
function resolveButtonLoading(loadingKey?: string) {
|
||
if (!loadingKey) return false
|
||
return Boolean(buttonLoadingMap.value[loadingKey])
|
||
}
|
||
|
||
function resolveButtonDisabled(disabledKey?: string) {
|
||
if (!disabledKey) return false
|
||
return Boolean(buttonDisabledMap.value[disabledKey])
|
||
}
|
||
|
||
function resolveButtonLabel(defaultLabel: string, dynamicLabelKey?: string) {
|
||
if (!dynamicLabelKey) return defaultLabel
|
||
return buttonLabelMap.value[dynamicLabelKey] || defaultLabel
|
||
}
|
||
|
||
// ============================================================
|
||
// 工具栏动作分发
|
||
// ============================================================
|
||
const toolbarActionMap: Record<string, () => void> = {
|
||
loadData: () => { void loadData() },
|
||
openColumnConfigPanel: () => { upperTableRef.value?.openColumnConfig?.() },
|
||
toggleDetailVisible: () => { detailVisible.value = !detailVisible.value },
|
||
openCreateApiApp: () => { apiAppCreateVisible.value = true },
|
||
openCreatePlan: () => { createPlanVisible.value = true },
|
||
openCreateDefinition: () => { definitionCreateVisible.value = true },
|
||
handleExport: () => { console.log('[BasicManagement] 导出(不含明细)', activeTabName.value) },
|
||
handleExportItem: () => { console.log('[BasicManagement] 导出(含明细)', activeTabName.value) }
|
||
}
|
||
|
||
function handleToolbarButtonClick(action: string) {
|
||
const handler = toolbarActionMap[action]
|
||
if (handler) {
|
||
handler()
|
||
return
|
||
}
|
||
// ★ 在此添加功能按钮分发
|
||
console.warn('[PageTemplate] 未处理的工具栏动作:', action)
|
||
}
|
||
|
||
// ============================================================
|
||
// 操作列按钮事件处理
|
||
// ============================================================
|
||
async function handleOperationAction(key: string, row: Record<string, any>) {
|
||
switch (key) {
|
||
case 'viewDetail':
|
||
// 已经通过行点击处理
|
||
break
|
||
case 'editApiApp':
|
||
// 编辑弹窗提交成功后触发,刷新列表
|
||
loadData()
|
||
break
|
||
case 'editPlan':
|
||
// 投递计划编辑弹窗提交成功后触发,刷新列表
|
||
loadData()
|
||
break
|
||
case 'copyPlan':
|
||
// 投递计划复制成功后刷新列表
|
||
loadData()
|
||
break
|
||
case 'regenerateSecret':
|
||
await handleRegenerateSecret(row)
|
||
break
|
||
case 'deleteApiApp':
|
||
await handleDeleteApiApp(row)
|
||
break
|
||
case 'deleteDefinition':
|
||
await handleDeleteReportDefinition(row)
|
||
break
|
||
default:
|
||
console.warn('[BasicManagement] 未处理的操作按钮:', key)
|
||
}
|
||
}
|
||
|
||
// ============================================================
|
||
// API 应用弹窗(创建 / 编辑)
|
||
// ============================================================
|
||
const apiAppCreateVisible = ref(false)
|
||
const createPlanVisible = ref(false)
|
||
const definitionCreateVisible = ref(false)
|
||
|
||
function handleApiAppDialogSuccess() {
|
||
loadData()
|
||
}
|
||
|
||
function handlePlanSaved() {
|
||
ElMessage.success('投递计划已保存')
|
||
loadData()
|
||
}
|
||
|
||
function handleDefinitionSaved() {
|
||
ElMessage.success('报表定义已保存')
|
||
loadData()
|
||
}
|
||
|
||
async function handleRegenerateSecret(row: Record<string, any>) {
|
||
try {
|
||
const res: any = await apiAppRegenerateSecret(row.id)
|
||
if (res && (res.code === 1 || res.code === 200)) {
|
||
const newSecret = res.self_app_secret || ''
|
||
ElMessageBox.alert(`新 AppSecret:${newSecret}`, '密钥已重置 — 请妥善保存', {
|
||
confirmButtonText: '我已保存',
|
||
type: 'warning'
|
||
})
|
||
loadData()
|
||
} else {
|
||
ElMessage.error(res?.message || '重置失败')
|
||
}
|
||
} catch (e: any) {
|
||
ElMessage.error(e?.message || '重置失败')
|
||
}
|
||
}
|
||
|
||
async function handleDeleteApiApp(row: Record<string, any>) {
|
||
try {
|
||
const res: any = await apiAppDelete(row.id)
|
||
if (res && (res.code === 1 || res.code === 200)) {
|
||
ElMessage.success('已停用')
|
||
loadData()
|
||
} else {
|
||
ElMessage.error(res?.message || '停用失败')
|
||
}
|
||
} catch (e: any) {
|
||
ElMessage.error(e?.message || '停用失败')
|
||
}
|
||
}
|
||
|
||
async function handleDeleteReportDefinition(row: Record<string, any>) {
|
||
const id = Number(row?.id)
|
||
if (!(id > 0)) {
|
||
ElMessage.warning('缺少报表定义ID')
|
||
return
|
||
}
|
||
try {
|
||
const res: any = await deleteReportDefinition({ id })
|
||
if (res && (res.code === 1 || res.code === 200)) {
|
||
ElMessage.success('已删除')
|
||
loadData()
|
||
} else {
|
||
ElMessage.error(res?.message || '删除失败')
|
||
}
|
||
} catch (e: any) {
|
||
ElMessage.error(e?.message || '删除失败')
|
||
}
|
||
}
|
||
|
||
// ============================================================
|
||
// ★★★ 第二步:接入真实接口 ★★★
|
||
// ============================================================
|
||
const listData = ref<Record<string, any>[]>([])
|
||
const loading = ref(false)
|
||
const queryTime = ref(0)
|
||
|
||
const pagination = reactive({
|
||
currentPage: 1,
|
||
pageSize: 20,
|
||
total: 0
|
||
})
|
||
|
||
const currentSort = reactive({ prop: '', order: '' })
|
||
|
||
const loadData = async () => {
|
||
const cfg = currentTabConfig.value
|
||
if (!cfg) return
|
||
// 表单页形态:由 formPage 组件自管理数据,不加载列表
|
||
if (cfg.viewType === 'form') return
|
||
loading.value = true
|
||
const startTime = performance.now()
|
||
|
||
try {
|
||
if (cfg.api) {
|
||
// 使用真实接口
|
||
const conditions = scanBoxRef.value?.getConditions?.() || {}
|
||
const params = cfg.api.buildListParams
|
||
? cfg.api.buildListParams({
|
||
pagination: { page: pagination.currentPage, pageSize: pagination.pageSize },
|
||
conditions,
|
||
sort: currentSort.prop ? { prop: currentSort.prop, order: currentSort.order } : undefined
|
||
})
|
||
: {
|
||
pagination: { page: pagination.currentPage, pageSize: pagination.pageSize },
|
||
where: conditions
|
||
}
|
||
|
||
const res = await cfg.api.list(params)
|
||
if (res && (res.code === 1 || res.code === 200)) {
|
||
const parsed = cfg.api.parseListResponse
|
||
? cfg.api.parseListResponse(res)
|
||
: { list: res.data?.list ?? res.list ?? [], total: res.data?.pagination?.total ?? res.total ?? 0 }
|
||
listData.value = parsed.list
|
||
pagination.total = parsed.total
|
||
} else {
|
||
throw new Error(res?.message || '接口返回异常')
|
||
}
|
||
} else {
|
||
// ★ 未配置 API 时使用模拟数据(替换为真实接口后删除)
|
||
console.log('[PageTemplate] 未配置 API,使用空数据。请在 tabPages 中配置 api 字段。')
|
||
listData.value = []
|
||
pagination.total = 0
|
||
}
|
||
} catch (e: any) {
|
||
console.error('[PageTemplate] 加载列表失败:', e)
|
||
ElMessage.error(e?.message || '获取列表数据失败')
|
||
listData.value = []
|
||
pagination.total = 0
|
||
} finally {
|
||
loading.value = false
|
||
queryTime.value = Math.round(performance.now() - startTime)
|
||
}
|
||
}
|
||
|
||
// ============================================================
|
||
// ScanBox 筛选事件
|
||
// ============================================================
|
||
const scanBoxRef = ref<any>(null)
|
||
const presetTree = ref<any[]>([])
|
||
|
||
const handleConditionChange = () => {
|
||
pagination.currentPage = 1
|
||
loadData()
|
||
}
|
||
const handleConditionReset = () => {
|
||
pagination.currentPage = 1
|
||
loadData()
|
||
}
|
||
const handleConditionClear = () => {
|
||
pagination.currentPage = 1
|
||
loadData()
|
||
}
|
||
|
||
// ============================================================
|
||
// UpperTable 事件
|
||
// ============================================================
|
||
const upperTableRef = ref<any>(null)
|
||
const selectedRows = ref<Record<string, any>[]>([])
|
||
|
||
const handleSortChange = ({ prop, order }: any) => {
|
||
currentSort.prop = prop
|
||
currentSort.order = order
|
||
pagination.currentPage = 1
|
||
loadData()
|
||
}
|
||
|
||
const handlePageChange = (page: number) => {
|
||
pagination.currentPage = page
|
||
loadData()
|
||
}
|
||
|
||
const handlePageSizeChange = (size: number) => {
|
||
pagination.pageSize = size
|
||
pagination.currentPage = 1
|
||
loadData()
|
||
}
|
||
|
||
const handleSelectionChange = (rows: Record<string, any>[]) => {
|
||
selectedRows.value = rows
|
||
}
|
||
|
||
// ============================================================
|
||
// 明细面板
|
||
// ============================================================
|
||
const detailVisible = ref(PAGE_CONFIG.enableDetailPanel)
|
||
const selectedRow = ref<Record<string, any> | null>(null)
|
||
const selectedDetail = ref<Record<string, any> | null>(null)
|
||
const activeDetailTab = ref('detail')
|
||
|
||
const handleRowClick = async (row: Record<string, any>) => {
|
||
if (!PAGE_CONFIG.enableDetailPanel) return
|
||
|
||
const cfg = currentTabConfig.value
|
||
if (!cfg) return
|
||
selectedRow.value = row
|
||
|
||
// 根据 DetailPanel 的 api 配置决定数据来源
|
||
const detailCfg = cfg.api?.detail
|
||
if (typeof detailCfg === 'function') {
|
||
try {
|
||
const detailRes = await detailCfg({ id: row.id, code: row.code })
|
||
if (detailRes && (detailRes.code === 1 || detailRes.code === 200)) {
|
||
selectedDetail.value = detailRes.data ?? detailRes
|
||
} else {
|
||
selectedDetail.value = { ...row }
|
||
}
|
||
} catch {
|
||
selectedDetail.value = { ...row }
|
||
}
|
||
} else {
|
||
// source='list' 或未配置:直接用行数据
|
||
selectedDetail.value = { ...row }
|
||
}
|
||
}
|
||
|
||
// ============================================================
|
||
// 标签页切换
|
||
// ============================================================
|
||
const handleTabChange = (tabName: string) => {
|
||
if (activeTabName.value === tabName) return
|
||
activeTabName.value = tabName
|
||
pagination.currentPage = 1
|
||
currentSort.prop = ''
|
||
currentSort.order = ''
|
||
selectedRow.value = null
|
||
selectedDetail.value = null
|
||
selectedRows.value = []
|
||
activeDetailTab.value = 'detail'
|
||
if (currentTabConfig.value?.viewType !== 'form') {
|
||
loadData()
|
||
}
|
||
}
|
||
|
||
// ============================================================
|
||
// 分栏拖拽
|
||
// ============================================================
|
||
const { splitStackRef, beginSplitDrag, lowerPaneStyle, upperPaneStyle } =
|
||
useVerticalSplitPane({ defaultLowerPercent: 38 })
|
||
|
||
const upperPaneFullStyle = computed(() => ({
|
||
flex: '1 1 auto',
|
||
minHeight: '0',
|
||
overflow: 'hidden' as const
|
||
}))
|
||
|
||
// ============================================================
|
||
// 初始化
|
||
// ============================================================
|
||
onMounted(() => {
|
||
applySavedTabOrder()
|
||
void loadStoreOptions()
|
||
// 预加载报表类型注册清单(报表定义页 type 筛选下拉与表单字段依赖)
|
||
void loadReportTypeList()
|
||
// 预加载报表定义选项(投递计划页报表筛选下拉与表单下拉依赖)
|
||
void loadReportDefinitions()
|
||
loadData()
|
||
})
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
/* 布局样式对齐 order/orderManagement(order-sub.scss) */
|
||
@use "../../../../order/orderManagement/styles/order-sub.scss";
|
||
|
||
/* ================================================================
|
||
整体布局
|
||
================================================================ */
|
||
.page-wrapper {
|
||
position: relative;
|
||
width: 100%;
|
||
display: flex;
|
||
flex-direction: column;
|
||
overflow: hidden;
|
||
}
|
||
|
||
/* ================================================================
|
||
1. 顶部多标签页
|
||
================================================================ */
|
||
.tab-section {
|
||
flex-shrink: 0;
|
||
position: relative;
|
||
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 区域左侧) */
|
||
.tab-sort-entry {
|
||
position: absolute;
|
||
top: 4px;
|
||
left: 12px;
|
||
height: 38px;
|
||
display: flex;
|
||
align-items: center;
|
||
z-index: 2;
|
||
|
||
.sort-entry-btn {
|
||
color: #606266;
|
||
font-size: 15px;
|
||
padding: 4px 6px;
|
||
border-radius: 4px;
|
||
transition: all 0.2s;
|
||
|
||
&:hover {
|
||
color: #409eff;
|
||
background-color: rgba(64, 158, 255, 0.08);
|
||
}
|
||
}
|
||
}
|
||
|
||
/* ================================================================
|
||
2. 主内容区
|
||
================================================================ */
|
||
.main-container {
|
||
flex: 1;
|
||
display: flex;
|
||
flex-direction: column;
|
||
min-height: 0;
|
||
background: #fff;
|
||
border: 1px solid #e8eef7;
|
||
border-radius: 0 0 6px 6px;
|
||
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
|
||
overflow: hidden;
|
||
}
|
||
|
||
/* 表单页形态:渲染 formPage 组件,填满内容区 */
|
||
.form-page-container {
|
||
flex: 1;
|
||
min-height: 0;
|
||
display: flex;
|
||
flex-direction: column;
|
||
overflow: auto;
|
||
background: #fff;
|
||
}
|
||
|
||
.tab-content-inner {
|
||
flex: 1;
|
||
display: flex;
|
||
flex-direction: column;
|
||
min-height: 0;
|
||
}
|
||
|
||
/* 分栏区域:布局样式由 order/orderManagement/styles/order-sub.scss 提供,此处仅补充模板特有规则 */
|
||
.split-stack {
|
||
:deep(.el-card__header) {
|
||
padding: 2px 12px;
|
||
font-size: 13px;
|
||
}
|
||
}
|
||
|
||
/* ================================================================
|
||
6. 过渡动画
|
||
================================================================ */
|
||
.tab-fade-enter-active,
|
||
.tab-fade-leave-active {
|
||
transition: opacity 0.2s ease;
|
||
opacity: 1;
|
||
}
|
||
|
||
.tab-fade-enter-from,
|
||
.tab-fade-leave-to {
|
||
opacity: 0;
|
||
}
|
||
|
||
/* ================================================================
|
||
7. 空状态
|
||
================================================================ */
|
||
.empty-tip {
|
||
font-size: 13px;
|
||
color: #909399;
|
||
}
|
||
</style>
|