Skip to content

Commit 1fda9c3

Browse files
authored
feat: show plugin settings modal when share url is not config (#24)
支持在进入 Umami 页面时检查是否配置 Umami 共享链接,如果没有配置,则弹出插件设置界面引导用户设置。 <img width="1669" alt="image" src="https://github.com/halo-sigs/plugin-umami/assets/21301288/4d4bbba8-7166-440a-8e24-2a5b7645ea48"> /kind feature ```release-note 支持在未设置共享链接时,自动打开插件设置界面。 ```
1 parent db027db commit 1fda9c3

File tree

4 files changed

+41
-75
lines changed

4 files changed

+41
-75
lines changed

console/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
2+
"type": "module",
23
"scripts": {
3-
"dev": "vite build --watch",
4+
"dev": "vite build --watch --mode=development",
45
"build": "vite build",
56
"preview": "vite preview --port 4173",
67
"test:unit": "vitest --environment jsdom",

console/src/views/UmamiView.vue

+26-23
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,42 @@
11
<script lang="ts" setup>
2-
import { onMounted } from "vue";
3-
import type { ConfigMap } from "@halo-dev/api-client";
4-
import { Dialog } from "@halo-dev/components";
5-
import { ref } from "vue";
6-
import { useRouter } from "vue-router";
7-
import axios from "axios";
2+
import { coreApiClient } from "@halo-dev/api-client";
3+
import { Toast } from "@halo-dev/components";
4+
import { onMounted, ref } from "vue";
85
96
const shareUrl = ref("");
10-
11-
const router = useRouter();
7+
const pluginDetailModal = ref(false);
128
139
const handleFetchUmamiShareUrl = async () => {
1410
try {
15-
const { data: configMap } = await axios.get<ConfigMap>(
16-
"/api/v1alpha1/configmaps/plugin-umami-configMap"
17-
);
11+
const { data: configMap } = await coreApiClient.configMap.getConfigMap({
12+
name: "plugin-umami-configMap",
13+
});
14+
15+
const url = JSON.parse(configMap.data?.basic || "{ url: '' }").url;
1816
19-
shareUrl.value = JSON.parse(configMap.data?.basic || "{ url: '' }").url;
17+
if (!url) {
18+
throw new Error("Umami share url is empty");
19+
}
20+
21+
shareUrl.value = url;
2022
} catch (error) {
21-
Dialog.warning({
22-
title: "未正确配置 Umami 的共享链接",
23-
description:
24-
"当前没有正确配置 Umami 的共享链接,可以点击下方按钮进入设置。",
25-
confirmText: "进入设置",
26-
showCancel: false,
27-
onConfirm: () => {
28-
router.push(`/plugins/PluginUmami/settings/basic`);
29-
},
30-
});
31-
console.error(error);
23+
Toast.success("未正确配置 Umami 共享链接,请先配置");
24+
pluginDetailModal.value = true;
3225
}
3326
};
3427
3528
onMounted(handleFetchUmamiShareUrl);
29+
30+
function onPluginDetailModalClose() {
31+
pluginDetailModal.value = false;
32+
handleFetchUmamiShareUrl();
33+
}
3634
</script>
3735
<template>
36+
<PluginDetailModal
37+
v-if="pluginDetailModal"
38+
name="PluginUmami"
39+
@close="onPluginDetailModalClose"
40+
/>
3841
<iframe :src="shareUrl" style="width: 100%; height: 100vh; border: none" />
3942
</template>

console/vite.config.ts

+12-50
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,18 @@
11
import { fileURLToPath, URL } from "url";
22

3-
import { defineConfig } from "vite";
3+
import { HaloUIPluginBundlerKit } from "@halo-dev/ui-plugin-bundler-kit";
44
import Vue from "@vitejs/plugin-vue";
55
import Icons from "unplugin-icons/vite";
6+
import { defineConfig } from "vite";
67

7-
export default ({ mode }: { mode: string }) => {
8-
const isProduction = mode === "production";
9-
const outDir = isProduction
10-
? "../src/main/resources/console"
11-
: "../build/resources/main/console";
12-
13-
return defineConfig({
14-
plugins: [Vue(), Icons({ compiler: "vue3" })],
15-
resolve: {
16-
alias: {
17-
"@": fileURLToPath(new URL("./src", import.meta.url)),
18-
},
19-
},
20-
define: {
21-
"process.env": process.env,
22-
},
23-
build: {
24-
outDir,
25-
emptyOutDir: true,
26-
lib: {
27-
entry: "src/index.ts",
28-
name: "PluginUmami",
29-
formats: ["iife"],
30-
fileName: () => "main.js",
31-
},
32-
rollupOptions: {
33-
external: [
34-
"vue",
35-
"vue-router",
36-
"@vueuse/core",
37-
"@vueuse/components",
38-
"@vueuse/router",
39-
"@halo-dev/shared",
40-
"@halo-dev/components",
41-
],
42-
output: {
43-
globals: {
44-
vue: "Vue",
45-
"vue-router": "VueRouter",
46-
"@vueuse/core": "VueUse",
47-
"@vueuse/components": "VueUse",
48-
"@vueuse/router": "VueUse",
49-
"@halo-dev/console-shared": "HaloConsoleShared",
50-
"@halo-dev/components": "HaloComponents",
51-
},
52-
},
53-
},
8+
export default defineConfig({
9+
plugins: [Vue(), Icons({ compiler: "vue3" }), HaloUIPluginBundlerKit()],
10+
resolve: {
11+
alias: {
12+
"@": fileURLToPath(new URL("./src", import.meta.url)),
5413
},
55-
});
56-
};
14+
},
15+
define: {
16+
"process.env": process.env,
17+
},
18+
});

src/main/resources/plugin.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ metadata:
77
spec:
88
enabled: true
99
version: 1.0.0
10-
requires: ">=2.0.0"
10+
requires: ">=2.17.0"
1111
author:
1212
name: Halo
1313
website: https://github.com/halo-dev

0 commit comments

Comments
 (0)