Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: show plugin settings modal when share url is not config #24

Merged
merged 2 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
},
});
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ metadata:
spec:
enabled: true
version: 1.0.0
requires: ">=2.0.0"
requires: ">=2.17.0"
author:
name: Halo
website: https://github.com/halo-dev
Expand Down