支持标签排序,默认标签放到最后面

This commit is contained in:
fofolee 2024-12-29 11:11:54 +08:00
parent bdffb7d681
commit 4d6b699b7d
2 changed files with 114 additions and 9 deletions

View File

@ -17,13 +17,35 @@
:key="denseTagBar" :key="denseTagBar"
:dense="denseTagBar" :dense="denseTagBar"
> >
<!-- 所有标签 --> <!-- 可拖拽标签 -->
<draggable
v-model="sortableTags"
:animation="200"
ghost-class="ghost"
tag="div"
item-key="tag"
class="draggable-container"
handle=".q-tab"
@change="handleTagsChange"
>
<template #item="{ element }">
<q-tab
:name="element"
:data-active-panel="activatedQuickPanels.includes(element)"
class="draggable-tag"
>
{{ element }}
</q-tab>
</template>
</draggable>
<!-- 固定标签不可拖拽 -->
<q-tab <q-tab
v-for="tag in allQuickCommandTags" v-for="tag in fixedTags"
:key="tag" :key="tag"
:name="tag" :name="tag"
:data-search-result="tag === '搜索结果'" :data-search-result="tag === '搜索结果'"
:data-active-panel="activatedQuickPanels.includes(tag)" :data-active-panel="activatedQuickPanels.includes(tag)"
class="fixed-tag"
> >
{{ tag }} {{ tag }}
<q-tooltip v-if="tag === '未分类'"> <q-tooltip v-if="tag === '未分类'">
@ -36,8 +58,17 @@
</template> </template>
<script> <script>
import draggable from "vuedraggable";
const FIXED_TAGS = ["未分类", "默认", "搜索结果"];
const TAG_ORDER_KEY = "cfg_tagOrder";
export default { export default {
name: "TagBar", name: "TagBar",
components: {
draggable,
},
emits: ["update:modelValue", "tags-reordered"],
props: { props: {
tabBarWidth: { tabBarWidth: {
type: String, type: String,
@ -60,6 +91,19 @@ export default {
default: false, default: false,
}, },
}, },
data() {
return {
savedTagOrder: null, //
};
},
created() {
//
this.savedTagOrder = this.$root.utools.getDB(TAG_ORDER_KEY);
if (!this.savedTagOrder.length) {
this.savedTagOrder = this.allQuickCommandTags;
}
this.currentTag = this.savedTagOrder[0];
},
computed: { computed: {
currentTag: { currentTag: {
get() { get() {
@ -69,6 +113,56 @@ export default {
this.$emit("update:modelValue", value); this.$emit("update:modelValue", value);
}, },
}, },
//
fixedTags() {
return FIXED_TAGS.filter((tag) => this.allQuickCommandTags.includes(tag));
},
//
sortableTags: {
get() {
const draggableTags = this.allQuickCommandTags.filter(
(tag) => !FIXED_TAGS.includes(tag)
);
//
const orderedTags = [];
//
this.savedTagOrder.forEach((tag) => {
if (draggableTags.includes(tag)) {
orderedTags.push(tag);
}
});
//
draggableTags.forEach((tag) => {
if (!orderedTags.includes(tag)) {
orderedTags.push(tag);
}
});
return orderedTags;
},
set(value) {
//
this.savedTagOrder = value;
//
this.$root.utools.putDB(value, TAG_ORDER_KEY);
//
this.$emit("tags-reordered", value);
},
},
},
methods: {
handleTagsChange(evt) {
if (evt.moved) {
const newOrder = [...this.sortableTags];
//
this.savedTagOrder = newOrder;
//
this.$root.utools.putDB(newOrder, TAG_ORDER_KEY);
//
this.$emit("tags-reordered", newOrder);
}
},
}, },
}; };
</script> </script>
@ -156,8 +250,21 @@ export default {
width: 0 !important; width: 0 !important;
} }
/* 暗色模式适配 */ /* 拖拽相关样式 */
:deep(.body--dark) .q-tab:hover::after { .draggable-container {
width: 100%;
}
.draggable-tag {
cursor: move;
touch-action: none;
}
.ghost {
opacity: 0.15; opacity: 0.15;
} }
.fixed-tag {
cursor: default;
}
</style> </style>

View File

@ -86,7 +86,7 @@ export default {
}, },
data() { data() {
return { return {
currentTag: "默认", currentTag: "",
lastTag: "", lastTag: "",
activatedQuickCommandFeatureCodes: [], activatedQuickCommandFeatureCodes: [],
activatedQuickPanels: [], activatedQuickPanels: [],
@ -205,13 +205,11 @@ export default {
this.getAllQuickCommandTags(); this.getAllQuickCommandTags();
}, },
getAllQuickCommandTags() { getAllQuickCommandTags() {
//
this.allQuickCommandTags = _.union( this.allQuickCommandTags = _.union(
...Object.values(this.allQuickCommands).map((x) => x.tags) ...Object.values(this.allQuickCommands).map((x) => x.tags)
) )
.concat([ .concat(["未分类"])
"未分类",
// ""
])
.filter((x) => x); .filter((x) => x);
}, },
// //