fix: 调整插件项目主页链接逻辑,优化下拉菜单项顺序

This commit is contained in:
jxxghp
2026-06-02 13:10:14 +08:00
parent aa12f4b6b6
commit 285ddab45a
2 changed files with 48 additions and 14 deletions

View File

@@ -8,7 +8,9 @@ import { useI18n } from 'vue-i18n'
import { openSharedDialog } from '@/composables/useSharedDialog'
const PluginMarketDetailDialog = defineAsyncComponent(() => import('@/components/dialog/PluginMarketDetailDialog.vue'))
const PluginVersionHistoryDialog = defineAsyncComponent(() => import('@/components/dialog/PluginVersionHistoryDialog.vue'))
const PluginVersionHistoryDialog = defineAsyncComponent(
() => import('@/components/dialog/PluginVersionHistoryDialog.vue'),
)
// 输入参数
const props = defineProps({
@@ -119,15 +121,6 @@ function showPluginDetail() {
// 弹出菜单
const dropdownItems = ref([
{
title: t('plugin.projectHome'),
value: 1,
show: true,
props: {
prependIcon: 'mdi-github',
click: visitPluginPage,
},
},
{
title: t('plugin.versionHistory'),
value: 2,
@@ -137,8 +130,16 @@ const dropdownItems = ref([
click: showUpdateHistory,
},
},
{
title: t('plugin.projectHome'),
value: 1,
show: true,
props: {
prependIcon: 'mdi-github',
click: visitPluginPage,
},
},
])
</script>
<template>

View File

@@ -274,18 +274,42 @@ function normalizePluginRepoUrl(repoUrl?: string) {
return repoUrl
}
/** 判断插件当前是否已经有可用的远程项目地址。 */
function hasRemoteRepoUrl(plugin?: Plugin) {
return Boolean(plugin?.repo_url && !plugin.repo_url.startsWith('local://'))
}
/** 优先解析插件仓库地址,本地插件或缺少仓库地址时回退到作者主页。 */
function resolvePluginPageUrl(plugin?: Plugin) {
if (!plugin) return ''
const repoUrl =
plugin.is_local || plugin.repo_url?.startsWith('local://')
? plugin.author_url
: normalizePluginRepoUrl(plugin.repo_url)
hasRemoteRepoUrl(plugin)
? normalizePluginRepoUrl(plugin.repo_url)
: plugin.author_url
return repoUrl || plugin.author_url || ''
}
/** 从插件市场中查找同 ID 插件,补齐已安装插件缺失的 repo_url。 */
async function fetchMarketPlugin(pluginId?: string) {
if (!pluginId) return null
try {
const marketPlugins: Plugin[] = await api.get('plugin/', {
params: {
state: 'market',
force: false,
},
})
return marketPlugins.find(plugin => plugin.id === pluginId) || null
} catch (error) {
console.error(error)
return null
}
}
// 访问插件项目主页
async function visitPluginPage() {
const popup = window.open('about:blank', '_blank')
@@ -308,6 +332,15 @@ async function visitPluginPage() {
console.error(error)
}
if (!hasRemoteRepoUrl(pluginDetail)) {
const marketPlugin = await fetchMarketPlugin(props.plugin?.id)
if (marketPlugin) {
// 插件市场条目通常包含真实仓库地址,优先使用它来对齐市场卡片跳转。
pluginDetail = { ...(pluginDetail || {}), ...marketPlugin } as Plugin
}
}
const repoUrl = resolvePluginPageUrl(pluginDetail)
if (repoUrl) {