Skip to content

Commit

Permalink
feat: show plugin settings modal when share url is not config
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Wang <[email protected]>
  • Loading branch information
ruibaby committed Jul 2, 2024
1 parent db027db commit 48c7fe7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 74 deletions.
3 changes: 2 additions & 1 deletion console/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"type": "module",
"scripts": {
"dev": "vite build --watch",
"dev": "vite build --watch --mode=development",
"build": "vite build",
"preview": "vite preview --port 4173",
"test:unit": "vitest --environment jsdom",
Expand Down
49 changes: 26 additions & 23 deletions console/src/views/UmamiView.vue
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>
62 changes: 12 additions & 50 deletions console/vite.config.ts
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,
},
});

0 comments on commit 48c7fe7

Please sign in to comment.