diff --git a/console/docs/extension-points/theme-list-tabs.md b/console/docs/extension-points/theme-list-tabs.md new file mode 100644 index 000000000..e668bf525 --- /dev/null +++ b/console/docs/extension-points/theme-list-tabs.md @@ -0,0 +1,54 @@ +# 主题管理界面选项卡扩展点 + +## 原由 + +目前在 Halo 的主题管理中原生支持本地上传和远程下载的方式安装主题,此扩展点用于扩展主题管理界面的选项卡,以支持更多的安装方式。 + +## 定义方式 + +> 此示例为添加一个安装选项卡用于从 GitHub 上下载主题。 + +```ts +import { definePlugin } from "@halo-dev/console-shared"; +import { markRaw } from "vue"; +import GitHubDownloadTab from "./components/GitHubDownloadTab.vue"; + +export default definePlugin({ + extensionPoints: { + "theme:list:tabs:create": () => { + return [ + { + id: "github", + label: "GitHub", + component: markRaw(GitHubDownload), + props: { + foo: "bar", + }, + priority: 11, + }, + ]; + }, + }, +}); +``` + +扩展点类型: + +```ts +"theme:list:tabs:create"?: () => + | ThemeListTab[] + | Promise; +``` + +`ThemeListTab`: + +```ts +export interface ThemeListTab { + id: string; // 选项卡的唯一标识 + label: string; // 选项卡的名称 + component: Raw; // 选项卡面板的组件 + props?: Record; // 选项卡组件的 props + permissions?: string[]; // 权限 + priority: number; // 优先级 +} +``` diff --git a/console/packages/shared/src/index.ts b/console/packages/shared/src/index.ts index 76e755922..605e66554 100644 --- a/console/packages/shared/src/index.ts +++ b/console/packages/shared/src/index.ts @@ -9,3 +9,4 @@ export * from "./states/comment-subject-ref"; export * from "./states/backup"; export * from "./states/plugin-installation-tabs"; export * from "./states/entity"; +export * from "./states/theme-list-tabs"; diff --git a/console/packages/shared/src/states/theme-list-tabs.ts b/console/packages/shared/src/states/theme-list-tabs.ts new file mode 100644 index 000000000..82e913e33 --- /dev/null +++ b/console/packages/shared/src/states/theme-list-tabs.ts @@ -0,0 +1,10 @@ +import type { Component, Raw } from "vue"; + +export interface ThemeListTab { + id: string; + label: string; + component: Raw; + props?: Record; + permissions?: string[]; + priority: number; +} diff --git a/console/packages/shared/src/types/plugin.ts b/console/packages/shared/src/types/plugin.ts index 87b38ca2c..99601b59e 100644 --- a/console/packages/shared/src/types/plugin.ts +++ b/console/packages/shared/src/types/plugin.ts @@ -8,6 +8,7 @@ import type { CommentSubjectRefProvider } from "@/states/comment-subject-ref"; import type { BackupTab } from "@/states/backup"; import type { PluginInstallationTab } from "@/states/plugin-installation-tabs"; import type { EntityDropdownItem } from "@/states/entity"; +import type { ThemeListTab } from "@/states/theme-list-tabs"; import type { Backup, ListedPost, Plugin } from "@halo-dev/api-client"; export interface RouteRecordAppend { @@ -50,6 +51,8 @@ export interface ExtensionPoint { "backup:list-item:operation:create"?: () => | EntityDropdownItem[] | Promise[]>; + + "theme:list:tabs:create"?: () => ThemeListTab[] | Promise; } export interface PluginModule { diff --git a/console/src/locales/en.yaml b/console/src/locales/en.yaml index eb5e8448a..b014d9c0a 100644 --- a/console/src/locales/en.yaml +++ b/console/src/locales/en.yaml @@ -609,27 +609,18 @@ core: remote_download: title: Remote download address detected, do you want to download? description: "Please carefully verify whether this address can be trusted: {url}" - upload_modal: - titles: - install: Install theme - upgrade: Upgrade theme ({display_name}) - operations: - existed_during_installation: - title: The theme already exists. - description: The currently installed theme already exists, do you want to upgrade? - tabs: - local: Local - remote: - title: Remote - fields: - url: Remote URL + existed_during_installation: + title: The theme already exists. + description: The currently installed theme already exists, do you want to upgrade? list_modal: - titles: - installed_themes: Installed Themes - not_installed_themes: Not installed Themes tabs: installed: Installed not_installed: Not installed + local_upload: Local install / upgrade + remote_download: + title: Remote + fields: + url: Remote URL empty: title: There are no installed themes currently. message: There are currently no installed themes, you can try refreshing or installing a new theme. @@ -1220,6 +1211,7 @@ core: add: Add submit: Submit detail: Detail + select: Select radio: "yes": Yes "no": No diff --git a/console/src/locales/zh-CN.yaml b/console/src/locales/zh-CN.yaml index 1aa0c6660..8cffb00ca 100644 --- a/console/src/locales/zh-CN.yaml +++ b/console/src/locales/zh-CN.yaml @@ -609,27 +609,18 @@ core: remote_download: title: 检测到了远程下载地址,是否需要下载? description: 请仔细鉴别此地址是否可信:{url} - upload_modal: - titles: - install: 安装主题 - upgrade: 升级主题({display_name}) - operations: - existed_during_installation: - title: 主题已存在 - description: 当前安装的主题已存在,是否升级? - tabs: - local: 本地上传 - remote: - title: 远程下载 - fields: - url: 下载地址 + existed_during_installation: + title: 主题已存在 + description: 当前安装的主题已存在,是否升级? list_modal: - titles: - installed_themes: 已安装的主题 - not_installed_themes: 未安装的主题 tabs: installed: 已安装 - not_installed: 未安装 + not_installed: 本地未安装 + local_upload: 上传安装 / 升级 + remote_download: + label: 远程下载 + fields: + url: 下载地址 empty: title: 当前没有已安装的主题 message: 当前没有已安装的主题,你可以尝试刷新或者安装新主题 @@ -1220,6 +1211,7 @@ core: add: 添加 submit: 提交 detail: 详情 + select: 选择 radio: "yes": 是 "no": 否 diff --git a/console/src/locales/zh-TW.yaml b/console/src/locales/zh-TW.yaml index 05ee9a5ca..713eb82b5 100644 --- a/console/src/locales/zh-TW.yaml +++ b/console/src/locales/zh-TW.yaml @@ -609,27 +609,18 @@ core: remote_download: title: 偵測到遠端下載地址,是否需要下載? description: 請仔細鑑別此地址是否可信:{url} - upload_modal: - titles: - install: 安裝主題 - upgrade: 升級主題({display_name}) - operations: - existed_during_installation: - title: 主題已存在 - description: 當前安裝的主題已存在,是否升級? - tabs: - local: 本地上傳 - remote: - title: 遠端下載 - fields: - url: 下載地址 + existed_during_installation: + title: 主題已存在 + description: 當前安裝的主題已存在,是否升級? list_modal: - titles: - installed_themes: 已安裝的主題 - not_installed_themes: 未安裝的主題 tabs: installed: 已安裝 - not_installed: 未安裝 + not_installed: 本地未安裝 + local_upload: 上傳安裝 / 升級 + remote_download: + label: 遠端下載 + fields: + url: 下載地址 empty: title: 當前沒有已安裝的主題 message: 當前沒有已安裝的主題,你可以嘗試刷新或者安裝新主題 @@ -1220,6 +1211,7 @@ core: add: 添加 submit: 提交 detail: 詳情 + select: 選擇 radio: "yes": 是 "no": 否 diff --git a/console/src/modules/interface/themes/ThemeDetail.vue b/console/src/modules/interface/themes/ThemeDetail.vue index b5ab21e33..d0b66cf1e 100644 --- a/console/src/modules/interface/themes/ThemeDetail.vue +++ b/console/src/modules/interface/themes/ThemeDetail.vue @@ -17,7 +17,6 @@ import { VDescription, VDescriptionItem, } from "@halo-dev/components"; -import ThemeUploadModal from "./components/ThemeUploadModal.vue"; // types import type { Ref } from "vue"; @@ -29,7 +28,7 @@ import { useI18n } from "vue-i18n"; const { t } = useI18n(); const selectedTheme = inject>("selectedTheme", ref()); -const upgradeModal = ref(false); +const themesModal = inject>("themesModal"); const { isActivated, getFailedMessage, handleResetSettingConfig } = useThemeLifeCycle(selectedTheme); @@ -59,12 +58,6 @@ const handleReloadTheme = async () => { }, }); }; - -const onUpgradeModalClose = () => { - setTimeout(() => { - window.location.reload(); - }, 200); -};