- 新增 SettingsDialog 及 registry 分区注册表,按「表格 / 显示与交互 / 性能 / 导航 / 数据与维护」分组,分区组件全部懒加载,支持关键字搜索与作用域提示 - 新增 10 个设置分区:列表字段(宿主插槽)、所有表格字段、界面显示、 设备与打印、表格与性能、页面与标签缓存、标签排序、快捷入口、 导出字段、导入/导出与维护(tbyc-config.json) - Navbar 头像下拉新增「设置」入口;UpperTable 工具栏的「更多设置 / 标签排序」 收敛为「字段设置」,通过 #field-section 插槽注入当前表格列配置 - TabOrderSettingsDialog 重命名为可复用面板 TabOrderPanel,接入设置中心 - 抽离 table-column-config 工具与 tableColumnConfig store,支持跨页面管理 所有表格列配置,修改后按 tableId 版本号通知已打开表格重建列配置 - tbyc-config 新增 experimental、printer、订单导出字段等分区, 导入/导出覆盖更多本地配置,并兼容旧版字段配置与 tabOrders 文件 - 移除 MoreSettingsDialog;OrderExportColumnsDialog 与设置中心共用导出字段 存储,区分「未配置」与「空选择」;订单各页清理重复的下拉选项映射逻辑 - 新增《设置中心-设计与实施》文档,更新标签排序与 tbyc-config 说明
528 lines
14 KiB
Vue
528 lines
14 KiB
Vue
<!--
|
||
TabOrderPanel — 全项目标签排序 / 默认页签管理面板(不含弹窗外壳)
|
||
|
||
用法:
|
||
- 设置中心 →「导航 → 标签排序」分区(推荐)
|
||
- 需要独立弹窗时可自行包一层 el-dialog
|
||
|
||
说明:
|
||
- 左侧只列出「标签数 ≥ 2」的页面(打开时并行懒加载标签数量)
|
||
- 右侧拖拽排序 + 圆点设为默认;标题栏常驻展示当前生效的默认标签
|
||
- 保存写入 userPreference 用户级 scope `tabOrder`,页面即时生效
|
||
-->
|
||
<template>
|
||
<div class="tab-order-panel-wrapper">
|
||
<div class="tab-order-panel">
|
||
<!-- 左侧:页面列表 -->
|
||
<div class="panel-left">
|
||
<el-input
|
||
v-model="keyword"
|
||
size="small"
|
||
placeholder="搜索页面名称"
|
||
clearable
|
||
class="panel-search"
|
||
/>
|
||
<div class="page-groups">
|
||
<div v-if="!itemsReady" class="panel-loading">加载中…</div>
|
||
<template v-else>
|
||
<div v-for="group in filteredGroups" :key="group.name" class="group">
|
||
<div class="group-title">{{ group.name }}</div>
|
||
<div
|
||
v-for="item in group.items"
|
||
:key="item.key"
|
||
class="page-item"
|
||
:class="{
|
||
'is-active': item.key === selectedKey,
|
||
'is-disabled': item.enabled === false,
|
||
'is-current': item.key === effectiveCurrentKey
|
||
}"
|
||
@click="selectPage(item)"
|
||
>
|
||
<span class="page-title">
|
||
{{ item.title }}
|
||
<span v-if="item.key === effectiveCurrentKey" class="current-dot" title="当前页面" />
|
||
</span>
|
||
<el-tag v-if="item.enabled === false" size="small" type="info" effect="plain">未接入</el-tag>
|
||
<el-tag v-else-if="isCustomized(item.key)" size="small" effect="plain">已自定义</el-tag>
|
||
</div>
|
||
</div>
|
||
<el-empty v-if="!filteredGroups.length" description="没有可排序的页面" :image-size="60" />
|
||
</template>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 右侧:当前页面的排序/默认设置 -->
|
||
<div class="panel-right">
|
||
<template v-if="currentItem">
|
||
<div class="panel-head">
|
||
<div class="panel-head-main">
|
||
<span class="current-title">{{ currentItem.title }}</span>
|
||
<span class="current-sub">{{ currentTabs.length }} 个标签</span>
|
||
</div>
|
||
<div class="panel-head-actions">
|
||
<span class="current-default">默认:{{ effectiveDefaultLabel }}</span>
|
||
<el-button size="small" link @click="resetCurrent">恢复本页默认</el-button>
|
||
</div>
|
||
</div>
|
||
|
||
<div v-if="loading" class="panel-loading">加载中…</div>
|
||
<template v-else-if="currentTabs.length > 1">
|
||
<div class="panel-tip">
|
||
拖动左侧把手调整标签顺序,右侧圆点选择打开页面时默认展示的标签。
|
||
</div>
|
||
<TabOrderDragList
|
||
v-model="currentOrder"
|
||
v-model:default-name="currentDefault"
|
||
:can-set-default="true"
|
||
/>
|
||
</template>
|
||
<div v-else class="panel-loading">
|
||
该页面当前只有 1 个标签,暂无需排序。
|
||
</div>
|
||
</template>
|
||
<el-empty v-else description="请从左侧选择一个页面" />
|
||
</div>
|
||
</div>
|
||
|
||
<div class="tab-order-actions">
|
||
<el-button size="small" @click="resetAll">全部恢复默认</el-button>
|
||
<el-button size="small" type="primary" :disabled="!isDirty" @click="handleSave">
|
||
保存
|
||
</el-button>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { computed, onMounted, reactive, ref } from 'vue'
|
||
import { useRoute } from 'vue-router'
|
||
import { ElMessage } from 'element-plus'
|
||
import TabOrderDragList from '@/components/TabOrderDragList.vue'
|
||
import {
|
||
TAB_ORDER_GROUPS,
|
||
TAB_ORDER_REGISTRY,
|
||
matchTabOrderPageKey,
|
||
type TabOrderRegistryItem
|
||
} from '@/config/tab-order-registry'
|
||
import {
|
||
applyTabOrder,
|
||
isValidTabName,
|
||
normalizeTabOrder,
|
||
readTabOrderDoc,
|
||
writeTabOrderDoc,
|
||
type TabOption
|
||
} from '@/utils/tab-order'
|
||
|
||
defineOptions({ name: 'TabOrderPanel' })
|
||
|
||
const props = withDefaults(
|
||
defineProps<{
|
||
/** 当前所在页面的注册表 key(用于高亮,可空) */
|
||
currentPageKey?: string
|
||
}>(),
|
||
{ currentPageKey: '' }
|
||
)
|
||
|
||
const keyword = ref('')
|
||
const selectedKey = ref('')
|
||
const loading = ref(false)
|
||
/** 标签数量预加载完成(未完成前不渲染页面列表,避免单标签页面闪入闪出) */
|
||
const itemsReady = ref(false)
|
||
const route = useRoute()
|
||
|
||
/** 当前页面 key:优先外部传入,其次按路由路径兜底匹配 */
|
||
const effectiveCurrentKey = computed(
|
||
() => props.currentPageKey || matchTabOrderPageKey(route.path)
|
||
)
|
||
|
||
/** 页面 key → 已加载的默认标签 */
|
||
const tabsCache = reactive<Record<string, TabOption[]>>({})
|
||
/** 页面 key → 草稿(顺序 + 默认标签) */
|
||
const drafts = reactive<Record<string, { order: TabOption[]; defaultName: string }>>({})
|
||
/** 「全部恢复默认」标记:保存时清空整个文档 */
|
||
const clearAll = ref(false)
|
||
|
||
const doc = computed(() => readTabOrderDoc())
|
||
|
||
const filteredGroups = computed(() => {
|
||
const kw = keyword.value.trim().toLowerCase()
|
||
return TAB_ORDER_GROUPS.map((name) => ({
|
||
name,
|
||
items: TAB_ORDER_REGISTRY.filter((item) => {
|
||
if (item.group !== name) return false
|
||
// 只有 1 个标签的页面无需排序,不展示
|
||
const tabs = tabsCache[item.key]
|
||
if (!tabs || tabs.length < 2) return false
|
||
if (!kw) return true
|
||
return item.title.toLowerCase().includes(kw) || item.key.toLowerCase().includes(kw)
|
||
})
|
||
})).filter((group) => group.items.length > 0)
|
||
})
|
||
|
||
const currentItem = computed(() =>
|
||
TAB_ORDER_REGISTRY.find((item) => item.key === selectedKey.value)
|
||
)
|
||
|
||
const currentTabs = computed<TabOption[]>(() => tabsCache[selectedKey.value] || [])
|
||
|
||
const currentOrder = computed<TabOption[]>({
|
||
get: () => drafts[selectedKey.value]?.order || [],
|
||
set: (value) => {
|
||
const draft = drafts[selectedKey.value]
|
||
if (draft) draft.order = value
|
||
clearAll.value = false
|
||
}
|
||
})
|
||
|
||
/** 页面兜底默认标签:注册表声明 > 默认顺序首个 */
|
||
function fallbackDefaultName(key: string): string {
|
||
const item = TAB_ORDER_REGISTRY.find((entry) => entry.key === key)
|
||
const tabs = tabsCache[key] || []
|
||
if (item?.defaultTabName && tabs.some((tab) => tab.name === item.defaultTabName)) {
|
||
return item.defaultTabName
|
||
}
|
||
return tabs[0]?.name || ''
|
||
}
|
||
|
||
/** 当前生效的默认标签:用户已设置 > 页面兜底(便于未设置时也能看出默认是哪个) */
|
||
const effectiveDefaultName = computed(() => {
|
||
const key = selectedKey.value
|
||
if (!key) return ''
|
||
return drafts[key]?.defaultName || fallbackDefaultName(key)
|
||
})
|
||
|
||
const effectiveDefaultLabel = computed(() => {
|
||
const name = effectiveDefaultName.value
|
||
return currentTabs.value.find((tab) => tab.name === name)?.label || '—'
|
||
})
|
||
|
||
const currentDefault = computed<string>({
|
||
get: () => effectiveDefaultName.value,
|
||
set: (value) => {
|
||
const draft = drafts[selectedKey.value]
|
||
if (draft) draft.defaultName = value || ''
|
||
clearAll.value = false
|
||
}
|
||
})
|
||
|
||
/** 是否已有自定义配置(用于列表标注) */
|
||
function isCustomized(key: string): boolean {
|
||
return !!doc.value.orders[key]?.length || !!doc.value.defaults[key]
|
||
}
|
||
|
||
function sameOrder(a: string[], b: string[]): boolean {
|
||
return a.length === b.length && a.every((name, index) => name === b[index])
|
||
}
|
||
|
||
function isPageDirty(key: string): boolean {
|
||
const draft = drafts[key]
|
||
const tabs = tabsCache[key]
|
||
if (!draft || !tabs) return false
|
||
const names = draft.order.map((tab) => tab.name)
|
||
const savedNames = normalizeTabOrder(doc.value.orders[key], tabs)
|
||
return (
|
||
!sameOrder(names, savedNames) || draft.defaultName !== (doc.value.defaults[key] || '')
|
||
)
|
||
}
|
||
|
||
const isDirty = computed(
|
||
() => clearAll.value || Object.keys(drafts).some((key) => isPageDirty(key))
|
||
)
|
||
|
||
function initDraft(item: TabOrderRegistryItem, tabs: TabOption[]) {
|
||
const savedOrder = doc.value.orders[item.key]
|
||
const order = savedOrder?.length ? applyTabOrder(savedOrder, tabs) : tabs.map((tab) => ({ ...tab }))
|
||
const savedDefault = doc.value.defaults[item.key] || ''
|
||
drafts[item.key] = {
|
||
order,
|
||
defaultName: isValidTabName(savedDefault, tabs) ? savedDefault : ''
|
||
}
|
||
}
|
||
|
||
async function ensureTabs(item: TabOrderRegistryItem) {
|
||
if (tabsCache[item.key]) return tabsCache[item.key]
|
||
loading.value = true
|
||
try {
|
||
const tabs = await item.loadTabs()
|
||
tabsCache[item.key] = tabs
|
||
initDraft(item, tabs)
|
||
return tabs
|
||
} catch (error) {
|
||
console.error('[TabOrderPanel] loadTabs failed:', item.key, error)
|
||
tabsCache[item.key] = []
|
||
drafts[item.key] = { order: [], defaultName: '' }
|
||
return []
|
||
} finally {
|
||
loading.value = false
|
||
}
|
||
}
|
||
|
||
async function loadAllTabs() {
|
||
await Promise.all(
|
||
TAB_ORDER_REGISTRY.map(async (item) => {
|
||
if (tabsCache[item.key]) return
|
||
try {
|
||
const tabs = await item.loadTabs()
|
||
tabsCache[item.key] = tabs
|
||
initDraft(item, tabs)
|
||
} catch (error) {
|
||
console.error('[TabOrderPanel] loadTabs failed:', item.key, error)
|
||
tabsCache[item.key] = []
|
||
}
|
||
})
|
||
)
|
||
}
|
||
|
||
async function selectPage(item: TabOrderRegistryItem) {
|
||
if (item.enabled === false) return
|
||
selectedKey.value = item.key
|
||
await ensureTabs(item)
|
||
}
|
||
|
||
function resetCurrent() {
|
||
const item = currentItem.value
|
||
const tabs = tabsCache[selectedKey.value]
|
||
if (!item || !tabs) return
|
||
drafts[item.key] = {
|
||
order: tabs.map((tab) => ({ ...tab })),
|
||
defaultName: ''
|
||
}
|
||
clearAll.value = false
|
||
}
|
||
|
||
function resetAll() {
|
||
Object.keys(drafts).forEach((key) => {
|
||
const tabs = tabsCache[key]
|
||
drafts[key] = {
|
||
order: (tabs || []).map((tab) => ({ ...tab })),
|
||
defaultName: ''
|
||
}
|
||
})
|
||
clearAll.value = true
|
||
}
|
||
|
||
async function initialize() {
|
||
keyword.value = ''
|
||
clearAll.value = false
|
||
itemsReady.value = false
|
||
Object.keys(drafts).forEach((key) => delete drafts[key])
|
||
Object.keys(tabsCache).forEach((key) => delete tabsCache[key])
|
||
|
||
await loadAllTabs()
|
||
itemsReady.value = true
|
||
|
||
const isSortable = (item: TabOrderRegistryItem) =>
|
||
item.enabled !== false && (tabsCache[item.key]?.length || 0) > 1
|
||
|
||
const preferred = TAB_ORDER_REGISTRY.find(
|
||
(item) => item.key === effectiveCurrentKey.value && isSortable(item)
|
||
)
|
||
const fallback = TAB_ORDER_REGISTRY.find(isSortable)
|
||
const target = preferred || fallback
|
||
if (target) {
|
||
await selectPage(target)
|
||
} else {
|
||
selectedKey.value = ''
|
||
}
|
||
}
|
||
|
||
function handleSave() {
|
||
const base = readTabOrderDoc()
|
||
const orders: Record<string, string[]> = clearAll.value ? {} : { ...base.orders }
|
||
const defaults: Record<string, string> = clearAll.value ? {} : { ...base.defaults }
|
||
|
||
Object.keys(drafts).forEach((key) => {
|
||
const draft = drafts[key]
|
||
const tabs = tabsCache[key]
|
||
if (!draft || !tabs || !tabs.length) return
|
||
const names = draft.order.map((tab) => tab.name)
|
||
const defaultNames = tabs.map((tab) => tab.name)
|
||
if (sameOrder(names, defaultNames)) {
|
||
delete orders[key]
|
||
} else {
|
||
orders[key] = normalizeTabOrder(names, tabs)
|
||
}
|
||
if (draft.defaultName) {
|
||
defaults[key] = draft.defaultName
|
||
} else {
|
||
delete defaults[key]
|
||
}
|
||
})
|
||
|
||
writeTabOrderDoc({ version: 1, orders, defaults })
|
||
ElMessage.success('标签排序已保存,页面已即时生效')
|
||
clearAll.value = false
|
||
// 保存后以最新文档刷新草稿基线,避免「保存」按钮持续可用
|
||
Object.keys(tabsCache).forEach((key) => {
|
||
const item = TAB_ORDER_REGISTRY.find((entry) => entry.key === key)
|
||
if (item && tabsCache[key]?.length) initDraft(item, tabsCache[key]!)
|
||
})
|
||
}
|
||
|
||
onMounted(() => {
|
||
void initialize()
|
||
})
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
.tab-order-panel-wrapper {
|
||
display: flex;
|
||
flex-direction: column;
|
||
height: 100%;
|
||
min-height: 0;
|
||
}
|
||
|
||
.tab-order-panel {
|
||
display: flex;
|
||
gap: 16px;
|
||
flex: 1;
|
||
min-height: 0;
|
||
}
|
||
|
||
.panel-left {
|
||
width: 260px;
|
||
flex-shrink: 0;
|
||
display: flex;
|
||
flex-direction: column;
|
||
border-right: 1px solid #e8eef7;
|
||
padding-right: 12px;
|
||
}
|
||
|
||
.panel-search {
|
||
margin-bottom: 8px;
|
||
}
|
||
|
||
.page-groups {
|
||
flex: 1;
|
||
overflow: auto;
|
||
}
|
||
|
||
.group + .group {
|
||
margin-top: 10px;
|
||
}
|
||
|
||
.group-title {
|
||
font-size: 12px;
|
||
color: #909399;
|
||
padding: 4px 8px;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.page-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;
|
||
}
|
||
|
||
&.is-disabled {
|
||
color: #c0c4cc;
|
||
cursor: not-allowed;
|
||
|
||
&:hover {
|
||
background: transparent;
|
||
}
|
||
}
|
||
|
||
.page-title {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
gap: 6px;
|
||
min-width: 0;
|
||
}
|
||
|
||
.current-dot {
|
||
width: 6px;
|
||
height: 6px;
|
||
border-radius: 50%;
|
||
background: #2f80ed;
|
||
flex-shrink: 0;
|
||
}
|
||
}
|
||
|
||
.panel-right {
|
||
flex: 1;
|
||
min-width: 0;
|
||
display: flex;
|
||
flex-direction: column;
|
||
}
|
||
|
||
.panel-head {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
margin-bottom: 8px;
|
||
|
||
.panel-head-main {
|
||
display: flex;
|
||
align-items: baseline;
|
||
gap: 8px;
|
||
}
|
||
|
||
.current-title {
|
||
font-size: 14px;
|
||
font-weight: 600;
|
||
color: #303133;
|
||
}
|
||
|
||
.current-sub {
|
||
font-size: 12px;
|
||
color: #909399;
|
||
}
|
||
|
||
.panel-head-actions {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 10px;
|
||
}
|
||
|
||
.current-default {
|
||
font-size: 12px;
|
||
color: #2f80ed;
|
||
background: rgba(47, 128, 237, 0.08);
|
||
border-radius: 10px;
|
||
padding: 2px 10px;
|
||
line-height: 18px;
|
||
}
|
||
}
|
||
|
||
.panel-tip {
|
||
font-size: 12px;
|
||
color: #909399;
|
||
line-height: 1.6;
|
||
margin-bottom: 10px;
|
||
}
|
||
|
||
.panel-loading {
|
||
padding: 40px 0;
|
||
text-align: center;
|
||
font-size: 13px;
|
||
color: #909399;
|
||
}
|
||
|
||
.tab-order-actions {
|
||
display: flex;
|
||
justify-content: flex-end;
|
||
gap: 8px;
|
||
padding-top: 12px;
|
||
margin-top: 8px;
|
||
border-top: 1px solid #e8eef7;
|
||
}
|
||
</style>
|