173 lines
4.4 KiB
Vue
173 lines
4.4 KiB
Vue
<!--
|
||
SortSettingDialog — 标签排序弹窗(通用)
|
||
作用:调整页面顶部多标签页的显示顺序(如把「待处理订单」拖到「待审核订单」前面)
|
||
存储:localStorage(key=user_prefs_{userId},scope 由调用方传入,value=tab.name 数组)
|
||
设计文档:docs/用户偏好配置-浏览器本地保存方案.md
|
||
用法:
|
||
<SortSettingDialog
|
||
v-model:visible="visible"
|
||
:tabs="DEFAULT_TAB_OPTIONS" // { name, label }[],顺序即默认顺序
|
||
:scope="'order.tabs.order'" // 存储 scope,按页面区分
|
||
@saved="handleSortSaved" // (order: string[])
|
||
/>
|
||
-->
|
||
<template>
|
||
<el-dialog
|
||
:model-value="visible"
|
||
title="标签排序"
|
||
width="520px"
|
||
align-center
|
||
destroy-on-close
|
||
:close-on-click-modal="false"
|
||
append-to-body
|
||
@update:model-value="(v: boolean) => emit('update:visible', v)"
|
||
@closed="handleClosed"
|
||
>
|
||
<div class="tab-order-tip">
|
||
拖动左侧把手调整标签页显示顺序,保存后刷新/重新登录仍生效(按当前账号保存在浏览器本地)。
|
||
</div>
|
||
|
||
<VueDraggable
|
||
v-model="orderList"
|
||
:animation="180"
|
||
handle=".tab-order-handle"
|
||
ghost-class="tab-order-ghost"
|
||
class="tab-order-list"
|
||
>
|
||
<div v-for="(tab, idx) in orderList" :key="tab.name" class="tab-order-row">
|
||
<span class="tab-order-handle">
|
||
<el-icon><Rank /></el-icon>
|
||
</span>
|
||
<span class="tab-order-index">{{ idx + 1 }}</span>
|
||
<span class="tab-order-label">{{ tab.label }}</span>
|
||
</div>
|
||
</VueDraggable>
|
||
|
||
<template #footer>
|
||
<el-button size="small" @click="handleClosed">取消</el-button>
|
||
<el-button size="small" @click="resetOrder">恢复默认</el-button>
|
||
<el-button size="small" type="primary" @click="handleSave">保存</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { ref, watch } from 'vue'
|
||
import { Rank } from '@element-plus/icons-vue'
|
||
import { VueDraggable } from 'vue-draggable-plus'
|
||
import { useUserPreferenceStore } from '@/stores/modules/userPreference'
|
||
|
||
defineOptions({ name: 'SortSettingDialog' })
|
||
|
||
export interface TabOrderOption {
|
||
name: string
|
||
label: string
|
||
}
|
||
|
||
const props = defineProps<{
|
||
visible: boolean
|
||
/** 该页面全部 tab(name + 中文 label),顺序即默认顺序 */
|
||
tabs: TabOrderOption[]
|
||
/** 存储 scope(如 order.tabs.order / stock.tabs.order) */
|
||
scope: string
|
||
}>()
|
||
|
||
const emit = defineEmits<{
|
||
(e: 'update:visible', v: boolean): void
|
||
(e: 'saved', order: string[]): void
|
||
}>()
|
||
|
||
const pref = useUserPreferenceStore()
|
||
|
||
const orderList = ref<TabOrderOption[]>([])
|
||
|
||
watch(
|
||
() => props.visible,
|
||
(v) => {
|
||
if (!v) return
|
||
orderList.value = buildOrderList()
|
||
}
|
||
)
|
||
|
||
/** 读取已保存顺序;非法项剔除,缺失的 tab 按 props.tabs 补在末尾(防新增 tab 丢项) */
|
||
function buildOrderList(): TabOrderOption[] {
|
||
const byName = new Map(props.tabs.map((t) => [t.name, t]))
|
||
const saved = pref.get(props.scope)
|
||
const names = Array.isArray(saved)
|
||
? saved.filter((n: unknown) => typeof n === 'string' && byName.has(n))
|
||
: []
|
||
const result = Array.from(new Set(names)).map((n) => byName.get(n)!)
|
||
for (const t of props.tabs) {
|
||
if (!result.some((r) => r.name === t.name)) result.push({ ...t })
|
||
}
|
||
return result
|
||
}
|
||
|
||
function resetOrder() {
|
||
orderList.value = props.tabs.map((t) => ({ ...t }))
|
||
}
|
||
|
||
function handleSave() {
|
||
const names = orderList.value.map((t) => t.name)
|
||
pref.set(props.scope, names)
|
||
emit('saved', names)
|
||
handleClosed()
|
||
}
|
||
|
||
function handleClosed() {
|
||
emit('update:visible', false)
|
||
}
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
.tab-order-tip {
|
||
font-size: 12px;
|
||
color: #909399;
|
||
margin-bottom: 12px;
|
||
line-height: 1.6;
|
||
}
|
||
|
||
.tab-order-list {
|
||
max-height: 320px;
|
||
overflow: auto;
|
||
}
|
||
|
||
.tab-order-row {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 10px;
|
||
padding: 9px 12px;
|
||
margin-bottom: 8px;
|
||
border: 1px solid #e8eef7;
|
||
border-radius: 6px;
|
||
background: #fafbfe;
|
||
|
||
.tab-order-handle {
|
||
cursor: grab;
|
||
color: #909399;
|
||
display: inline-flex;
|
||
&:active {
|
||
cursor: grabbing;
|
||
}
|
||
}
|
||
|
||
.tab-order-index {
|
||
width: 20px;
|
||
text-align: center;
|
||
font-size: 12px;
|
||
color: #909399;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.tab-order-label {
|
||
font-size: 13px;
|
||
color: #303133;
|
||
}
|
||
}
|
||
|
||
.tab-order-ghost {
|
||
opacity: 0.4;
|
||
border-style: dashed;
|
||
}
|
||
</style>
|