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

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"
: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
v-for="tag in allQuickCommandTags"
v-for="tag in fixedTags"
:key="tag"
:name="tag"
:data-search-result="tag === '搜索结果'"
:data-active-panel="activatedQuickPanels.includes(tag)"
class="fixed-tag"
>
{{ tag }}
<q-tooltip v-if="tag === '未分类'">
@ -36,8 +58,17 @@
</template>
<script>
import draggable from "vuedraggable";
const FIXED_TAGS = ["未分类", "默认", "搜索结果"];
const TAG_ORDER_KEY = "cfg_tagOrder";
export default {
name: "TagBar",
components: {
draggable,
},
emits: ["update:modelValue", "tags-reordered"],
props: {
tabBarWidth: {
type: String,
@ -60,6 +91,19 @@ export default {
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: {
currentTag: {
get() {
@ -69,6 +113,56 @@ export default {
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>
@ -156,8 +250,21 @@ export default {
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;
}
.fixed-tag {
cursor: default;
}
</style>

View File

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