diff --git a/build.gradle b/build.gradle index 3e274b8..a530635 100644 --- a/build.gradle +++ b/build.gradle @@ -52,6 +52,6 @@ build { } halo { - version = '2.17.0-beta.1' + version = '2.18.0' debug = true } diff --git a/ui/src/index.ts b/ui/src/index.ts index c7b9166..87e62e0 100644 --- a/ui/src/index.ts +++ b/ui/src/index.ts @@ -1,43 +1,53 @@ -import { axiosInstance } from "@halo-dev/api-client"; +import { axiosInstance, consoleApiClient } from "@halo-dev/api-client"; import { Dialog, Toast } from "@halo-dev/components"; import { definePlugin } from "@halo-dev/console-shared"; -const button = document.createElement("button"); -button.innerHTML = ``; -button.style.position = "fixed"; -button.style.right = "2rem"; -button.style.bottom = "5rem"; -button.style.width = "3rem"; -button.style.height = "3rem"; -button.style.borderRadius = "50%"; -button.style.backgroundColor = "rgba(0, 0, 0, 0.5)"; -button.style.display = "flex"; -button.style.alignItems = "center"; -button.style.justifyContent = "center"; -button.style.transition = "background-color 0.3s"; -button.title = "刷新页面缓存"; -button.addEventListener("click", () => { - Dialog.warning({ - title: "刷新页面缓存", - description: "此操作会清空所有页面的缓存。", - async onConfirm() { - await axiosInstance.delete( - "/apis/console.api.cache.halo.run/v1alpha1/caches/page" - ); +function createCleanupButton() { + const button = document.createElement("button"); + button.innerHTML = ``; + button.style.position = "fixed"; + button.style.right = "2rem"; + button.style.bottom = "5rem"; + button.style.width = "3rem"; + button.style.height = "3rem"; + button.style.borderRadius = "50%"; + button.style.backgroundColor = "rgba(0, 0, 0, 0.5)"; + button.style.display = "flex"; + button.style.alignItems = "center"; + button.style.justifyContent = "center"; + button.style.transition = "background-color 0.3s"; + button.title = "刷新页面缓存"; + button.addEventListener("click", () => { + Dialog.warning({ + title: "刷新页面缓存", + description: "此操作会清空所有页面的缓存。", + async onConfirm() { + await axiosInstance.delete( + "/apis/console.api.cache.halo.run/v1alpha1/caches/page" + ); - Toast.success("刷新成功"); - }, + Toast.success("刷新成功"); + }, + }); }); -}); -button.addEventListener("mouseover", () => { - button.style.backgroundColor = "rgba(0, 0, 0, 0.7)"; -}); + button.addEventListener("mouseover", () => { + button.style.backgroundColor = "rgba(0, 0, 0, 0.7)"; + }); -button.addEventListener("mouseout", () => { - button.style.backgroundColor = "rgba(0, 0, 0, 0.5)"; -}); + button.addEventListener("mouseout", () => { + button.style.backgroundColor = "rgba(0, 0, 0, 0.5)"; + }); + + document.body.appendChild(button); +} -document.body.appendChild(button); +if (location.pathname.startsWith("/console")) { + consoleApiClient.user.getPermissions({ name: "-" }).then((response) => { + if (response.data.uiPermissions.includes("*")) { + createCleanupButton(); + } + }); +} export default definePlugin({});