WEB/src/components/settings/SettingsDialog.vue
yin b37ebdba46 feat(scanbox): 新增自定义过滤条件预设,并在设置中心集中管理
- ScanBox「过滤」页签新增预设树:系统条件 + 我的自定义条件,支持一键应用、
  取消应用、条件追加合并,以及把当前筛选条件「存为过滤条件」并自动切换页签
- 新增 scan-filter-presets 工具与 scanFilterPresets store:条件按账号保存
  (用户级 scope,不随仓库隔离),页面字段元数据由 ScanBox 挂载时自动登记,
  预设固定输出扁平结构,页面查询构建无需区分条件来源
- 设置中心新增「自定义过滤条件」分区:左侧页面列表、右侧条件管理,
  支持启用/排序/编辑/复制/删除/恢复默认
- 设置中心分组重组为「字段与列 / 筛选与查询 / 系统设置 / 设备与打印 /
  导航与入口 / 数据与维护」,原「表格与性能」「页面与标签缓存」合并为
  「基础设置」,单条目分组不再重复显示分组标题
- tbyc-config 新增 scanFilterPresets 分区,支持随统一配置导入导出;
  stockQueryBuilder 兼容预设条件信封结构并跳过元数据键
- 新增《自定义过滤条件-设计与实施》文档,更新设置中心设计文档
2026-11-09 18:00:15 +08:00

361 lines
8.6 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.

<!--
SettingsDialog — 设置中心(项目内所有"本机可修改配置"的总入口)
入口:
1. 列表页工具栏「字段设置」→ initialSection = 'field'(由 UpperTable 通过 #field-section 注入内容)
2. Navbar 头像下拉「设置」→ 无表上下文,自动隐藏「当前页面」分组
约定:
· 所有分区即时生效(各自写对应 store),不提供全局保存/取消
· 分区元数据见 ./registry.ts;新增设置 = 注册一条 + 新建 section 组件
-->
<template>
<el-dialog
:model-value="visible"
class="settings-dialog"
width="1280px"
align-center
append-to-body
destroy-on-close
:show-close="false"
:close-on-click-modal="false"
@update:model-value="(v: boolean) => emit('update:visible', v)"
>
<div class="settings-shell">
<!-- 头部(对齐 task-panel:18px 标题 + 12px 说明 + 24px 关闭) -->
<header class="task-panel__head">
<div class="task-panel__titles">
<h2>设置</h2>
<p>当前账号 · 仅保存在本机浏览器</p>
</div>
<button class="task-panel__close" type="button" aria-label="关闭" @click="handleClose">
<svg viewBox="0 0 12 12" fill="none">
<path
d="M1 1L11 11M11 1L1 11"
stroke="currentColor"
stroke-width="1.4"
stroke-linecap="round"
/>
</svg>
</button>
</header>
<!-- 主体:左导航 + 右内容 -->
<div class="settings-body">
<aside class="settings-nav">
<el-input
v-model="keyword"
size="small"
placeholder="搜索设置项"
clearable
class="settings-search"
/>
<div class="settings-nav-list">
<template v-for="group in groups" :key="group.name">
<div v-if="group.items.length" class="settings-group">
<!-- 单条目且条目名与分组名相同(如「基础设置」)时不重复显示分组标题 -->
<div v-if="!isSingleSelfNamedGroup(group)" class="settings-group-title">
{{ group.name }}
</div>
<div
v-for="item in group.items"
:key="item.key"
class="settings-nav-item"
:class="{ 'is-active': item.key === currentKey }"
@click="currentKey = item.key"
>
<span class="settings-nav-title">{{ item.title }}</span>
<span v-if="item.scopeLabel" class="settings-nav-scope">{{ item.scopeLabel }}</span>
</div>
</div>
</template>
<el-empty v-if="!groups.length" description="没有匹配的设置项" :image-size="60" />
</div>
</aside>
<section class="settings-content">
<template v-if="currentSection">
<component
:is="currentSection.component"
v-if="currentSection.component"
@columns-changed="emit('columns-changed')"
/>
<slot v-else name="field-section" />
</template>
<el-empty v-else description="请选择左侧设置项" />
</section>
</div>
<!-- 底部 -->
<footer class="settings-footer">
<span class="settings-footer-tip">修改即时保存 · 仅保存在当前浏览器</span>
<div class="settings-footer-actions">
<el-button size="small" @click="handleClose">关闭</el-button>
</div>
</footer>
</div>
</el-dialog>
</template>
<script setup lang="ts">
import { computed, ref, useSlots, watch } from 'vue'
import {
SETTINGS_GROUPS,
SETTINGS_SECTIONS,
type SettingsSectionMeta
} from './registry'
defineOptions({ name: 'SettingsDialog' })
const props = withDefaults(
defineProps<{
visible: boolean
/** 打开时定位的分区 key(非法/不可见时回落到第一个) */
initialSection?: string
}>(),
{ initialSection: '' }
)
const emit = defineEmits<{
(e: 'update:visible', v: boolean): void
/** 字段配置发生变化(导入/重置/故障修复),由宿主重建列配置 */
(e: 'columns-changed'): void
}>()
const slots = useSlots()
const keyword = ref('')
const currentKey = ref('')
const hasFieldSlot = computed(() => !!slots['field-section'])
/** 当前入口下可见的分区(无插槽时隐藏表级「列表字段」) */
const availableSections = computed<SettingsSectionMeta[]>(() =>
SETTINGS_SECTIONS.filter((section) => !section.slot || hasFieldSlot.value)
)
const groups = computed(() => {
const kw = keyword.value.trim().toLowerCase()
return SETTINGS_GROUPS.map((name) => ({
name,
items: availableSections.value.filter((section) => {
if (section.group !== name) return false
if (!kw) return true
return (
section.title.toLowerCase().includes(kw) || section.key.toLowerCase().includes(kw)
)
})
})).filter((group) => group.items.length > 0)
})
const currentSection = computed(() =>
availableSections.value.find((section) => section.key === currentKey.value)
)
/** 单条目且条目名 = 分组名时省略分组标题(避免「基础设置 / 基础设置」重复) */
function isSingleSelfNamedGroup(group: { name: string; items: SettingsSectionMeta[] }): boolean {
return group.items.length === 1 && group.items[0]?.title === group.name
}
watch(
() => props.visible,
(visible) => {
if (!visible) return
keyword.value = ''
const preferred = availableSections.value.find((section) => section.key === props.initialSection)
currentKey.value = preferred?.key || availableSections.value[0]?.key || ''
},
{ immediate: true }
)
function handleClose() {
emit('update:visible', false)
}
</script>
<style lang="scss" scoped>
.settings-shell {
display: flex;
flex-direction: column;
background: #fff;
}
/* ===== 头部(对齐 task-panel) ===== */
.task-panel__head {
display: flex;
align-items: flex-start;
gap: 12px;
padding: 16px;
}
.task-panel__titles {
flex: 1;
min-width: 0;
h2 {
margin: 0;
font-size: 18px;
line-height: 24px;
font-weight: 400;
color: #303133;
}
p {
margin: 4px 0 0;
font-size: 12px;
line-height: 18px;
color: #909399;
}
}
.task-panel__close {
width: 24px;
height: 24px;
flex: none;
display: inline-flex;
align-items: center;
justify-content: center;
border: none;
border-radius: 4px;
background: transparent;
color: #909399;
cursor: pointer;
transition: color 0.2s;
svg {
width: 12px;
height: 12px;
}
&:hover {
color: #409eff;
}
}
/* ===== 主体 ===== */
.settings-body {
display: flex;
height: min(560px, calc(100vh - 220px));
min-height: 380px;
padding: 4px 16px 0;
}
.settings-nav {
width: 208px;
flex-shrink: 0;
display: flex;
flex-direction: column;
padding-right: 12px;
border-right: 1px solid #ebeef5;
}
.settings-search {
margin-bottom: 8px;
}
.settings-nav-list {
flex: 1;
overflow: auto;
padding-right: 2px;
}
.settings-group + .settings-group {
margin-top: 10px;
}
.settings-group-title {
font-size: 12px;
line-height: 20px;
color: #909399;
font-weight: 600;
padding: 4px 2px;
}
.settings-nav-item {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
min-height: 32px;
padding: 0 10px;
border-radius: 4px;
font-size: 13px;
color: #606266;
cursor: pointer;
transition: background-color 0.2s, color 0.2s;
&:hover {
background: #f5f7fa;
}
&.is-active {
background: #ecf5ff;
color: #409eff;
font-weight: 600;
}
}
.settings-nav-title {
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.settings-nav-scope {
font-size: 11px;
color: #c0c4cc;
flex-shrink: 0;
}
.settings-content {
flex: 1;
min-width: 0;
overflow: auto;
padding: 4px 0 0 16px;
}
/* ===== 底部(对齐 task-panel__foot) ===== */
.settings-footer {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 16px;
}
.settings-footer-tip {
font-size: 12px;
color: #909399;
}
.settings-footer-actions {
display: flex;
align-items: center;
gap: 6px;
}
</style>
<style lang="scss">
/*
el-dialog 会被 append 到 body,scoped 选择器命中不到;
沿用项目内统一做法:全局块 + 自定义头部(隐藏默认头部)
*/
.el-dialog.settings-dialog {
padding: 0;
overflow: hidden;
border-radius: 4px;
.el-dialog__header {
display: none;
}
.el-dialog__body {
padding: 0;
}
.el-dialog__footer {
padding: 0;
}
}
</style>