generated from halo-dev/plugin-starter
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: show plugin settings modal when share url is not config
Signed-off-by: Ryan Wang <[email protected]>
- Loading branch information
Showing
3 changed files
with
40 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,42 @@ | ||
<script lang="ts" setup> | ||
import { onMounted } from "vue"; | ||
import type { ConfigMap } from "@halo-dev/api-client"; | ||
import { Dialog } from "@halo-dev/components"; | ||
import { ref } from "vue"; | ||
import { useRouter } from "vue-router"; | ||
import axios from "axios"; | ||
import { coreApiClient } from "@halo-dev/api-client"; | ||
import { Toast } from "@halo-dev/components"; | ||
import { onMounted, ref } from "vue"; | ||
const shareUrl = ref(""); | ||
const router = useRouter(); | ||
const pluginDetailModal = ref(false); | ||
const handleFetchUmamiShareUrl = async () => { | ||
try { | ||
const { data: configMap } = await axios.get<ConfigMap>( | ||
"/api/v1alpha1/configmaps/plugin-umami-configMap" | ||
); | ||
const { data: configMap } = await coreApiClient.configMap.getConfigMap({ | ||
name: "plugin-umami-configMap", | ||
}); | ||
const url = JSON.parse(configMap.data?.basic || "{ url: '' }").url; | ||
shareUrl.value = JSON.parse(configMap.data?.basic || "{ url: '' }").url; | ||
if (!url) { | ||
throw new Error("Umami share url is empty"); | ||
} | ||
shareUrl.value = url; | ||
} catch (error) { | ||
Dialog.warning({ | ||
title: "未正确配置 Umami 的共享链接", | ||
description: | ||
"当前没有正确配置 Umami 的共享链接,可以点击下方按钮进入设置。", | ||
confirmText: "进入设置", | ||
showCancel: false, | ||
onConfirm: () => { | ||
router.push(`/plugins/PluginUmami/settings/basic`); | ||
}, | ||
}); | ||
console.error(error); | ||
Toast.success("未正确配置 Umami 共享链接,请先配置"); | ||
pluginDetailModal.value = true; | ||
} | ||
}; | ||
onMounted(handleFetchUmamiShareUrl); | ||
function onPluginDetailModalClose() { | ||
pluginDetailModal.value = false; | ||
handleFetchUmamiShareUrl(); | ||
} | ||
</script> | ||
<template> | ||
<PluginDetailModal | ||
v-if="pluginDetailModal" | ||
name="PluginUmami" | ||
@close="onPluginDetailModalClose" | ||
/> | ||
<iframe :src="shareUrl" style="width: 100%; height: 100vh; border: none" /> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,18 @@ | ||
import { fileURLToPath, URL } from "url"; | ||
|
||
import { defineConfig } from "vite"; | ||
import { HaloUIPluginBundlerKit } from "@halo-dev/ui-plugin-bundler-kit"; | ||
import Vue from "@vitejs/plugin-vue"; | ||
import Icons from "unplugin-icons/vite"; | ||
import { defineConfig } from "vite"; | ||
|
||
export default ({ mode }: { mode: string }) => { | ||
const isProduction = mode === "production"; | ||
const outDir = isProduction | ||
? "../src/main/resources/console" | ||
: "../build/resources/main/console"; | ||
|
||
return defineConfig({ | ||
plugins: [Vue(), Icons({ compiler: "vue3" })], | ||
resolve: { | ||
alias: { | ||
"@": fileURLToPath(new URL("./src", import.meta.url)), | ||
}, | ||
}, | ||
define: { | ||
"process.env": process.env, | ||
}, | ||
build: { | ||
outDir, | ||
emptyOutDir: true, | ||
lib: { | ||
entry: "src/index.ts", | ||
name: "PluginUmami", | ||
formats: ["iife"], | ||
fileName: () => "main.js", | ||
}, | ||
rollupOptions: { | ||
external: [ | ||
"vue", | ||
"vue-router", | ||
"@vueuse/core", | ||
"@vueuse/components", | ||
"@vueuse/router", | ||
"@halo-dev/shared", | ||
"@halo-dev/components", | ||
], | ||
output: { | ||
globals: { | ||
vue: "Vue", | ||
"vue-router": "VueRouter", | ||
"@vueuse/core": "VueUse", | ||
"@vueuse/components": "VueUse", | ||
"@vueuse/router": "VueUse", | ||
"@halo-dev/console-shared": "HaloConsoleShared", | ||
"@halo-dev/components": "HaloComponents", | ||
}, | ||
}, | ||
}, | ||
export default defineConfig({ | ||
plugins: [Vue(), Icons({ compiler: "vue3" }), HaloUIPluginBundlerKit()], | ||
resolve: { | ||
alias: { | ||
"@": fileURLToPath(new URL("./src", import.meta.url)), | ||
}, | ||
}); | ||
}; | ||
}, | ||
define: { | ||
"process.env": process.env, | ||
}, | ||
}); |