WEB/src/views/inbox/autoReply/components/FunctionPanel.vue
yin 6838d69788 perf(app): 详情面板统一迁移 UpperTable,路由按需加载并优化跨浏览器性能
- 新增 router/view-glob.ts,动态菜单兜底的全量 glob 表改为按需动态加载,
  入口 chunk 由 465KB 降至 393KB;Sidebar / TaskView 用 utils/path 的
  resolveRoutePath 替换 path-browserify 静态引用
- 新增 utils/perf-probe 轻量探针(?perf=1 或 localStorage 开启),输出导航耗时、
  资源分类统计、长任务与硬件信息;移除 text-rendering: optimizeLegibility,
  breadcrumb 过渡由 all 改为 opacity/transform,降低弱 CPU 与非 Chrome 内核开销
- Navbar 工单角标轮询在后台标签页跳过,通过 visibilitychange 回到前台补刷一次
- 库存详情、货位、条码、入库日志、出库日志与明细、收货日志、盘点记录等
  详情面板由 el-table 迁移到 UpperTable,统一展开行、分页、选择与列插槽
- 11 处模板配置及内嵌表格开启行选择;转储、转退货、批量复核弹窗改用
  SelectedTags 展示已选项并支持逐个移除,移除最后一个后自动关闭
- ImagesUpload 重构为「图库 + 上传区」面板,支持多选、最多 20 张、
  单张 10MB 校验与数量提示
- 新增《跨浏览器性能-分析与优化清单》文档
2026-11-11 18:00:42 +08:00

285 lines
7.8 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<div class="ar-panel">
<div class="ar-toolbar">
<div class="ar-toolbar__left">
<span class="ar-toolbar__title">处理函数</span>
<span class="ar-toolbar__sub">按顺序执行关联函数,可用性由代码注册表决定</span>
</div>
<div class="ar-toolbar__right">
<el-select
v-model="pendingFunctionId"
placeholder="选择函数加入关联"
filterable
clearable
size="small"
style="width: 220px"
:loading="libraryLoading"
:disabled="!writable"
>
<el-option
v-for="item in addableFunctions"
:key="item.id"
:label="`${item.name}(${item.function_code})`"
:value="item.id"
/>
</el-select>
<el-button size="small" type="primary" plain :disabled="!writable || !pendingFunctionId" @click="handleAddRow">
添加
</el-button>
<el-button size="small" type="primary" :loading="loading" @click="handleRefresh">刷新</el-button>
<el-button
size="small"
type="primary"
:loading="saving"
:disabled="!writable || !dirty"
@click="handleSave"
>
保存关联
</el-button>
</div>
</div>
<div class="ar-table-wrap">
<upper-table
table-id="inbox-auto-reply-function"
:data="rows"
:columns="columns"
:show-selection="true"
:loading="loading"
:show-pagination="false"
row-key="function_id"
empty-text="暂未关联处理函数"
>
<template #column-sort_order="{ index }">
{{ (index ?? 0) + 1 }}
</template>
<template #column-name="{ row }">
{{ row.function_name || row.function_code || '-' }}
</template>
<template #column-status="{ row }">
<span
v-if="row.in_registry === null || row.in_registry === undefined"
class="ut-status-text ut-status-text--info"
>未知</span>
<span
v-else
class="ut-status-text"
:class="row.in_registry ? 'ut-status-text--success' : 'ut-status-text--danger'"
>{{ row.in_registry ? '可用' : '代码已下线' }}</span>
</template>
<template #column-actions="{ index }">
<el-button size="small" type="primary" link :disabled="!writable || index === 0" @click="moveRow(index ?? 0, -1)">
上移
</el-button>
<el-button
size="small"
type="primary"
link
:disabled="!writable || index === rows.length - 1"
@click="moveRow(index ?? 0, 1)"
>
下移
</el-button>
<el-button size="small" type="danger" link :disabled="!writable" @click="removeRow(index ?? 0)">
移除
</el-button>
</template>
</upper-table>
</div>
</div>
</template>
<script setup lang="ts">
import { computed, ref, watch } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import {
inboxV2FunctionList,
inboxV2RelationFunctionList,
inboxV2RelationFunctionSet,
unwrapInboxV2Data,
type InboxV2FunctionItem,
} from '@/api/inbox-2/autoReply'
import { functionColumns } from '../autoReply-config'
import UpperTable from '@/components/UpperTable/index.vue'
const props = defineProps<{
subTypeId: number
writable: boolean
}>()
const emit = defineEmits<{
/** 未保存改动状态变化,供父级切换节点前拦截 */
'dirty-change': [value: boolean]
}>()
type RelationRow = {
function_id: number
function_name: string
function_code: string
/** 代码注册表是否存在该函数(可用性以此为准,只读展示) */
in_registry: boolean | null
}
const columns = functionColumns
const loading = ref(false)
const saving = ref(false)
const dirty = ref(false)
const rows = ref<RelationRow[]>([])
const pendingFunctionId = ref<number | null>(null)
const functionLibrary = ref<InboxV2FunctionItem[]>([])
const libraryLoading = ref(false)
const functionMap = computed(() => {
const map = new Map<number, InboxV2FunctionItem>()
for (const item of functionLibrary.value) map.set(item.id, item)
return map
})
const addableFunctions = computed(() => {
const used = new Set(rows.value.map((row) => row.function_id))
return functionLibrary.value.filter((item) => !used.has(item.id))
})
function buildRelationRows(
relations: Array<{ function_id: number; sort_order: number }>
): RelationRow[] {
return [...relations]
.sort((a, b) => (Number(a.sort_order) || 0) - (Number(b.sort_order) || 0))
.map((relation) => {
const fn = functionMap.value.get(Number(relation.function_id))
return {
function_id: Number(relation.function_id),
function_name: fn?.name ?? '',
function_code: fn?.function_code ?? '',
in_registry: fn ? fn.in_registry ?? null : false,
}
})
}
async function loadFunctions() {
libraryLoading.value = true
try {
const res = await inboxV2FunctionList()
const data = unwrapInboxV2Data(res)
functionLibrary.value = data?.list ?? []
} catch (error) {
console.error('加载处理函数列表失败:', error)
functionLibrary.value = []
} finally {
libraryLoading.value = false
}
}
async function loadRelations() {
if (!props.subTypeId) {
rows.value = []
return
}
const res = await inboxV2RelationFunctionList(props.subTypeId)
const data = unwrapInboxV2Data(res)
rows.value = buildRelationRows(data?.list ?? [])
dirty.value = false
}
/** 刷新前若有未保存改动先确认 */
async function handleRefresh() {
if (dirty.value) {
try {
await ElMessageBox.confirm('当前有未保存的关联修改,刷新后将被丢弃,是否继续?', '未保存修改', {
type: 'warning',
buttonSize: 'small',
confirmButtonText: '放弃修改并继续',
cancelButtonText: '取消',
})
} catch {
return
}
}
await loadAll()
}
async function loadAll() {
loading.value = true
try {
if (!functionLibrary.value.length) {
await loadFunctions()
}
await loadRelations()
} catch (error) {
console.error('加载函数关联失败:', error)
rows.value = []
} finally {
loading.value = false
}
}
function handleAddRow() {
const id = Number(pendingFunctionId.value)
if (!id) return
const fn = functionMap.value.get(id)
if (!fn) {
ElMessage.warning('函数不存在或已下线')
return
}
rows.value.push({
function_id: id,
function_name: fn.name,
function_code: fn.function_code,
in_registry: fn.in_registry ?? null,
})
pendingFunctionId.value = null
dirty.value = true
}
function removeRow(index: number) {
rows.value.splice(index, 1)
dirty.value = true
}
function moveRow(index: number, offset: number) {
const target = index + offset
if (target < 0 || target >= rows.value.length) return
const item = rows.value.splice(index, 1)[0]
if (!item) return
rows.value.splice(target, 0, item)
dirty.value = true
}
async function handleSave() {
if (!props.subTypeId) return
saving.value = true
try {
await inboxV2RelationFunctionSet(
props.subTypeId,
rows.value.map((row, index) => ({ functionId: row.function_id, sortOrder: index }))
)
dirty.value = false
ElMessage.success('处理函数关联已保存')
await loadRelations()
} catch (error) {
console.error('保存函数关联失败:', error)
} finally {
saving.value = false
}
}
// 未保存改动上报(父级切换节点前拦截)
watch(dirty, (value) => emit('dirty-change', value))
watch(
() => props.subTypeId,
() => {
pendingFunctionId.value = null
dirty.value = false
void loadAll()
},
{ immediate: true }
)
</script>
<style scoped lang="scss">
@use "./panel.scss";
</style>