fix: operation items render issue in theme list (#4563)

#### What type of PR is this?

/area console
/kind bug

#### What this PR does / why we need it:

修复主题管理列表的更多操作项在某些情况下无法打开的问题。

<img width="384" alt="image" src="https://github.com/halo-dev/halo/assets/21301288/2bbea045-2e04-46bc-be55-d9499c87624b">


#### Which issue(s) this PR fixes:

Fixes https://github.com/halo-dev/halo/issues/4559

#### Special notes for your reviewer:

测试方式:

1. 安装若干主题,测试每一项主题的更多操作按钮是否可以正常打开。
2. 删除某一个主题,测试每一项主题的更多操作按钮是否可以正常打开。

#### Does this PR introduce a user-facing change?

```release-note
修复 Console 端主题管理列表的更多操作项在某些情况下无法打开的问题。
```
pull/4552/head^2
Ryan Wang 2023-09-07 12:22:14 +08:00 committed by GitHub
parent a1ea355fdb
commit eea575c1e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 17 deletions

View File

@ -8,7 +8,6 @@ import {
VDropdownDivider, VDropdownDivider,
VButton, VButton,
VSpace, VSpace,
IconMore,
} from "@halo-dev/components"; } from "@halo-dev/components";
import type { Theme } from "@halo-dev/api-client"; import type { Theme } from "@halo-dev/api-client";
import { apiClient } from "@/utils/api-client"; import { apiClient } from "@/utils/api-client";
@ -19,10 +18,10 @@ import { useI18n } from "vue-i18n";
import { useQueryClient } from "@tanstack/vue-query"; import { useQueryClient } from "@tanstack/vue-query";
import { useOperationItemExtensionPoint } from "@/composables/use-operation-extension-points"; import { useOperationItemExtensionPoint } from "@/composables/use-operation-extension-points";
import { markRaw } from "vue"; import { markRaw } from "vue";
import { defineComponent } from "vue";
import UninstallOperationItem from "./operation/UninstallOperationItem.vue"; import UninstallOperationItem from "./operation/UninstallOperationItem.vue";
import { computed } from "vue"; import { computed } from "vue";
import type { OperationItem } from "@halo-dev/console-shared"; import type { OperationItem } from "@halo-dev/console-shared";
import MoreOperationItem from "./operation/MoreOperationItem.vue";
const { currentUserHasPermission } = usePermission(); const { currentUserHasPermission } = usePermission();
const { t } = useI18n(); const { t } = useI18n();
@ -112,15 +111,7 @@ const { operationItems } = useOperationItemExtensionPoint<Theme>(
}, },
{ {
priority: 30, priority: 30,
component: markRaw( component: markRaw(MoreOperationItem),
defineComponent({
components: {
VButton,
IconMore,
},
template: `<VButton size="sm"><IconMore /></VButton>`,
})
),
permissions: ["system:themes:manage"], permissions: ["system:themes:manage"],
children: [ children: [
{ {
@ -238,13 +229,14 @@ const { operationItems } = useOperationItemExtensionPoint<Theme>(
</div> </div>
<div> <div>
<VSpace v-if="installed"> <VSpace v-if="installed">
<template v-for="(item, index) in operationItems" :key="index"> <template v-for="item in operationItems">
<template v-if="!item.children?.length"> <template v-if="!item.children?.length">
<component <component
:is="item.component" :is="item.component"
v-if=" v-if="
!item.hidden && currentUserHasPermission(item.permissions) !item.hidden && currentUserHasPermission(item.permissions)
" "
:key="`${theme.metadata.name}-${item.label}-${item.priority}`"
v-bind="item.props" v-bind="item.props"
@click="item.action?.(theme)" @click="item.action?.(theme)"
> >
@ -256,6 +248,7 @@ const { operationItems } = useOperationItemExtensionPoint<Theme>(
v-if=" v-if="
!item.hidden && currentUserHasPermission(item.permissions) !item.hidden && currentUserHasPermission(item.permissions)
" "
:key="`${theme.metadata.name}-${item.label}-${item.priority}`"
> >
<component <component
:is="item.component" :is="item.component"
@ -265,16 +258,14 @@ const { operationItems } = useOperationItemExtensionPoint<Theme>(
{{ item.label }} {{ item.label }}
</component> </component>
<template #popper> <template #popper>
<template <template v-for="childItem in item.children">
v-for="(childItem, childIndex) in item.children"
:key="`child-${childIndex}`"
>
<component <component
:is="childItem.component" :is="childItem.component"
v-if=" v-if="
!childItem.hidden && !childItem.hidden &&
currentUserHasPermission(childItem.permissions) currentUserHasPermission(childItem.permissions)
" "
:key="`${theme.metadata.name}-${childItem.label}-${childItem.priority}`"
v-bind="childItem.props" v-bind="childItem.props"
@click="childItem.action?.(theme)" @click="childItem.action?.(theme)"
> >

View File

@ -95,7 +95,7 @@ const handleOpenPreview = (theme: Theme) => {
</Transition> </Transition>
<Transition v-else appear name="fade"> <Transition v-else appear name="fade">
<ul class="box-border h-full w-full space-y-3" role="list"> <ul class="box-border h-full w-full space-y-3" role="list">
<li v-for="(theme, index) in themes" :key="index"> <li v-for="theme in themes" :key="theme.metadata.name">
<ThemeListItem <ThemeListItem
:theme="theme" :theme="theme"
:is-selected="theme.metadata.name === selectedTheme?.metadata?.name" :is-selected="theme.metadata.name === selectedTheme?.metadata?.name"

View File

@ -0,0 +1,7 @@
<script lang="ts" setup>
import { VButton, IconMore } from "@halo-dev/components";
</script>
<template>
<VButton size="sm"><IconMore /></VButton>
</template>