Fix orders of login-required items (fix #5099)

This commit is contained in:
the1812 2025-02-19 08:07:38 +08:00
parent f0b40d4da1
commit 1ce2da6a62
3 changed files with 14 additions and 22 deletions

View File

@ -10,7 +10,6 @@
<script lang="ts">
import { addComponentListener } from '@/core/settings'
import { getUID } from '@/core/utils'
import { ascendingSort } from '@/core/utils/sort'
import { registerAndGetData } from '@/plugins/data'
import { getBuiltInItems } from './built-in-items'
@ -28,14 +27,7 @@ const [renderedItems] = registerAndGetData(CustomNavbarRenderedItems, {
items: [] as CustomNavbarItem[],
})
const getItems = () => {
const isLogin = Boolean(getUID())
const items = (initItems as CustomNavbarItemInit[])
.filter(it => {
if (it.loginRequired && !isLogin) {
return false
}
return true
})
.map(it => new CustomNavbarItem(it))
.sort(ascendingSort(it => it.order))
renderedItems.items = items

View File

@ -2,6 +2,7 @@ import { createPopper, Instance as Popper } from '@popperjs/core'
import { VueModule, Executable } from '@/core/common-types'
import { getComponentSettings, addComponentListener } from '@/core/settings'
import type { CustomNavbarOptions } from '.'
import { getUID } from '@/core/utils'
export const CustomNavbarItems = 'customNavbar.items'
export const CustomNavbarRenderedItems = 'customNavbar.renderedItems'
@ -90,7 +91,8 @@ export class CustomNavbarItem implements Required<CustomNavbarItemInit> {
},
true,
)
this.hidden = CustomNavbarItem.navbarOptions.hidden.includes(this.name)
this.hidden =
CustomNavbarItem.navbarOptions.hidden.includes(this.name) || (!getUID() && init.loginRequired)
const orderMap = CustomNavbarItem.navbarOptions.order
this.order = orderMap[this.name] || 0
this.requestedPopup = !this.lazy

View File

@ -118,20 +118,18 @@ export default Vue.extend({
}
})
const list: HTMLElement = this.$refs.navbarSortList
const Sortable = await SortableJSLibrary
Sortable.create(list, {
delay: 100,
forceFallback: true,
onEnd: (e: SortableEvent) => {
this.onSort(e)
},
})
checkSequentialOrder(rendered.items)
if (list) {
const Sortable = await SortableJSLibrary
Sortable.create(list, {
delay: 100,
forceFallback: true,
onEnd: (e: SortableEvent) => {
this.onSort(e)
},
})
checkSequentialOrder(rendered.items)
}
this.loaded = true
// unsafeWindow.nsTest = {
// list,
// Sortable,
// }
},
methods: {
toggle() {