diff --git a/package.json b/package.json index 6484b69cd..ba5c2578c 100644 --- a/package.json +++ b/package.json @@ -33,8 +33,10 @@ "@formkit/vue": "1.0.0-beta.9", "@halo-dev/admin-api": "^1.1.0", "@halo-dev/admin-shared": "workspace:*", + "@halo-dev/api-client": "^0.0.0", "@halo-dev/components": "workspace:*", "@vueuse/core": "^8.9.2", + "axios": "^0.27.2", "filepond": "^4.30.4", "filepond-plugin-image-preview": "^4.6.11", "floating-vue": "2.0.0-beta.16", diff --git a/packages/shared/package.json b/packages/shared/package.json index 4c2392b01..f517b4041 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -36,6 +36,7 @@ "homepage": "https://github.com/halo-dev/halo-admin/tree/next/shared/components#readme", "license": "MIT", "dependencies": { + "@halo-dev/api-client": "^0.0.0", "@halo-dev/components": "workspace:*", "axios": "^0.27.2" }, diff --git a/packages/shared/src/layouts/UserProfileLayout.vue b/packages/shared/src/layouts/UserProfileLayout.vue index 0e7501aae..521062f34 100644 --- a/packages/shared/src/layouts/UserProfileLayout.vue +++ b/packages/shared/src/layouts/UserProfileLayout.vue @@ -3,8 +3,8 @@ import { BasicLayout } from "@/layouts"; import { IconUpload, VButton, VTabbar } from "@halo-dev/components"; import { onMounted, provide, ref, watch } from "vue"; import { useRoute, useRouter } from "vue-router"; -import { axiosInstance } from "@/utils/api-client"; -import type { User } from "@/types/extension"; +import { apiClient } from "@/utils/api-client"; +import type { User } from "@halo-dev/api-client"; const tabs = [ { @@ -35,8 +35,8 @@ const { params } = useRoute(); const handleFetchUser = async () => { try { - const { data } = await axiosInstance.get( - `/api/v1alpha1/users/${params.name}` + const { data } = await apiClient.extension.user.getv1alpha1User( + params.name as string ); user.value = data; } catch (e) { diff --git a/packages/shared/src/utils/api-client.ts b/packages/shared/src/utils/api-client.ts index 7212d8c83..d8419b2eb 100644 --- a/packages/shared/src/utils/api-client.ts +++ b/packages/shared/src/utils/api-client.ts @@ -1,5 +1,20 @@ +import { + PluginHaloRunV1alpha1PluginApi, + V1alpha1UserApi, + ApiHaloRunV1alpha1UserApi, + V1alpha1ConfigMapApi, + V1alpha1PersonalAccessTokenApi, + V1alpha1RoleBindingApi, + V1alpha1RoleApi, + V1alpha1SettingApi, + PluginHaloRunV1alpha1ReverseProxyApi, + CoreHaloRunV1alpha1LinkApi, + CoreHaloRunV1alpha1LinkGroupApi, +} from "@halo-dev/api-client"; import axios from "axios"; +const baseUrl = "http://localhost:8090"; + const axiosInstance = axios.create({ baseURL: "http://localhost:8090", withCredentials: true, @@ -18,4 +33,38 @@ axiosInstance.interceptors.response.use( } ); -export { axiosInstance }; +const apiClient = { + extension: { + configMap: new V1alpha1ConfigMapApi(undefined, baseUrl, axiosInstance), + personalAccessToken: new V1alpha1PersonalAccessTokenApi( + undefined, + baseUrl, + axiosInstance + ), + roleBinding: new V1alpha1RoleBindingApi(undefined, baseUrl, axiosInstance), + role: new V1alpha1RoleApi(undefined, baseUrl, axiosInstance), + setting: new V1alpha1SettingApi(undefined, baseUrl, axiosInstance), + reverseProxy: new PluginHaloRunV1alpha1ReverseProxyApi( + undefined, + baseUrl, + axiosInstance + ), + plugin: new PluginHaloRunV1alpha1PluginApi( + undefined, + baseUrl, + axiosInstance + ), + user: new V1alpha1UserApi(undefined, baseUrl, axiosInstance), + + // TODO optional + link: new CoreHaloRunV1alpha1LinkApi(undefined, baseUrl, axiosInstance), + linkGroup: new CoreHaloRunV1alpha1LinkGroupApi( + undefined, + baseUrl, + axiosInstance + ), + }, + user: new ApiHaloRunV1alpha1UserApi(undefined, baseUrl, axiosInstance), +}; + +export { apiClient }; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 641566836..3c58b5032 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -31,6 +31,7 @@ importers: '@vue/tsconfig': ^0.1.3 '@vueuse/core': ^8.9.2 autoprefixer: ^10.4.7 + axios: ^0.27.2 c8: ^7.11.3 cypress: ^9.7.0 eslint: ^8.19.0 @@ -77,6 +78,7 @@ importers: '@halo-dev/admin-shared': link:packages/shared '@halo-dev/components': link:packages/components '@vueuse/core': 8.9.2_vue@3.2.37 + axios: 0.27.2 filepond: 4.30.4 filepond-plugin-image-preview: 4.6.11_filepond@4.30.4 floating-vue: 2.0.0-beta.16_vue@3.2.37 diff --git a/src/composables/usePlugins.ts b/src/composables/usePlugins.ts index 3324977d3..bb8e3203e 100644 --- a/src/composables/usePlugins.ts +++ b/src/composables/usePlugins.ts @@ -3,7 +3,7 @@ import type { ExtensionPointName, ExtensionPointState, } from "@halo-dev/admin-shared"; -import type { Plugin } from "@/types/extension"; +import type { Plugin } from "@halo-dev/api-client"; import type { Ref } from "vue"; export function useExtensionPointsState( @@ -13,9 +13,11 @@ export function useExtensionPointsState( const { plugins } = usePluginStore(); plugins.forEach((plugin: Plugin) => { + // @ts-ignore if (!plugin.spec.module?.extensionPoints?.[point]) { return; } + // @ts-ignore plugin.spec.module.extensionPoints[point]?.(state); }); } diff --git a/src/main.ts b/src/main.ts index e16e69c97..b0df8bd4e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -7,7 +7,7 @@ import type { MenuItemType, Plugin, } from "@halo-dev/admin-shared"; -import { axiosInstance } from "@halo-dev/admin-shared"; +import { apiClient } from "@halo-dev/admin-shared"; import { menus, minimenus, registerMenu } from "./router/menus.config"; // setup import "./setup/setupStyles"; @@ -17,7 +17,7 @@ import { setupComponents } from "./setup/setupComponents"; import { coreModules } from "./modules"; import { useScriptTag } from "@vueuse/core"; import { usePluginStore } from "@/stores/plugin"; -import type { User } from "@/types/extension"; +import type { User } from "@halo-dev/api-client"; const app = createApp(App); @@ -97,21 +97,23 @@ function loadStyle(href: string) { } async function loadPluginModules() { - const response = await axiosInstance.get( - `/apis/plugin.halo.run/v1alpha1/plugins` - ); + const response = + await apiClient.extension.plugin.listpluginHaloRunV1alpha1Plugin(); // Get all started plugins const plugins = response.data.filter( - (plugin) => plugin.status.phase === "STARTED" && plugin.spec.enabled + (plugin) => plugin.status?.phase === "STARTED" && plugin.spec.enabled ); for (const plugin of plugins) { - const { entry, stylesheet } = plugin.status; + const { entry, stylesheet } = plugin.status || { + entry: "", + stylesheet: "", + }; if (entry) { const { load } = useScriptTag( - `http://localhost:8090${plugin.status.entry}` + `http://localhost:8090${plugin.status?.entry}` ); await load(); const pluginModule = window[plugin.metadata.name]; @@ -132,9 +134,7 @@ async function loadPluginModules() { } async function loadCurrentUser() { - const response = await axiosInstance.get( - `/apis/api.halo.run/v1alpha1/users/-` - ); + const response = await apiClient.user.getCurrentUserDetail(); app.provide("currentUser", response.data); } diff --git a/src/modules/contents/attachments/AttachmentList.vue b/src/modules/contents/attachments/AttachmentList.vue index c0ab0d6e0..3fbd329a2 100644 --- a/src/modules/contents/attachments/AttachmentList.vue +++ b/src/modules/contents/attachments/AttachmentList.vue @@ -21,8 +21,8 @@ import vueFilePond from "vue-filepond"; import "filepond/dist/filepond.min.css"; import FilePondPluginImagePreview from "filepond-plugin-image-preview"; import "filepond-plugin-image-preview/dist/filepond-plugin-image-preview.min.css"; -import type { User } from "@/types/extension"; -import { axiosInstance } from "@halo-dev/admin-shared"; +import type { User } from "@halo-dev/api-client"; +import { apiClient } from "@halo-dev/admin-shared"; const viewTypes = [ { @@ -81,7 +81,7 @@ const attachments = Array.from(new Array(50), (_, index) => index).map( const handleFetchUsers = async () => { try { - const { data } = await axiosInstance.get("/api/v1alpha1/users"); + const { data } = await apiClient.extension.user.listv1alpha1User(); users.value = data; } catch (e) { console.error(e); diff --git a/src/modules/contents/pages/PageList.vue b/src/modules/contents/pages/PageList.vue index 34d443305..27671ea1b 100644 --- a/src/modules/contents/pages/PageList.vue +++ b/src/modules/contents/pages/PageList.vue @@ -14,9 +14,9 @@ import { } from "@halo-dev/components"; import { onMounted, ref } from "vue"; import type { PagesPublicState } from "@halo-dev/admin-shared"; -import { axiosInstance } from "@halo-dev/admin-shared"; +import { apiClient } from "@halo-dev/admin-shared"; import { useExtensionPointsState } from "@/composables/usePlugins"; -import type { User } from "@/types/extension"; +import type { User } from "@halo-dev/api-client"; const pagesRef = ref([ { @@ -52,7 +52,7 @@ useExtensionPointsState("PAGES", pagesPublicState); const handleFetchUsers = async () => { try { - const { data } = await axiosInstance.get("/api/v1alpha1/users"); + const { data } = await apiClient.extension.user.listv1alpha1User(); users.value = data; } catch (e) { console.error(e); diff --git a/src/modules/contents/posts/PostList.vue b/src/modules/contents/posts/PostList.vue index 088c6d633..96682766a 100644 --- a/src/modules/contents/posts/PostList.vue +++ b/src/modules/contents/posts/PostList.vue @@ -17,8 +17,8 @@ import { posts } from "./posts-mock"; import { computed, onMounted, ref } from "vue"; import { useRouter } from "vue-router"; import type { Post } from "@halo-dev/admin-api"; -import { axiosInstance } from "@halo-dev/admin-shared"; -import type { User } from "@/types/extension"; +import { apiClient } from "@halo-dev/admin-shared"; +import type { User } from "@halo-dev/api-client"; const postsRef = ref( // eslint-disable-next-line @@ -43,7 +43,7 @@ const checkedCount = computed(() => { const handleFetchUsers = async () => { try { - const { data } = await axiosInstance.get("/api/v1alpha1/users"); + const { data } = await apiClient.extension.user.listv1alpha1User(); users.value = data; } catch (e) { console.error(e); diff --git a/src/modules/dashboard/widgets/RecentLoginWidget.vue b/src/modules/dashboard/widgets/RecentLoginWidget.vue index 61c31a2b3..e3cdc0727 100644 --- a/src/modules/dashboard/widgets/RecentLoginWidget.vue +++ b/src/modules/dashboard/widgets/RecentLoginWidget.vue @@ -1,14 +1,14 @@ diff --git a/src/modules/system/users/UserDetail.vue b/src/modules/system/users/UserDetail.vue index 905de6a66..9e80b9712 100644 --- a/src/modules/system/users/UserDetail.vue +++ b/src/modules/system/users/UserDetail.vue @@ -3,7 +3,7 @@ import { IconUserSettings, VTag } from "@halo-dev/components"; import type { Ref } from "vue"; import { computed, inject } from "vue"; import { useRouter } from "vue-router"; -import type { User } from "@/types/extension"; +import type { User } from "@halo-dev/api-client"; const user = inject>("user"); diff --git a/src/modules/system/users/UserList.vue b/src/modules/system/users/UserList.vue index b3ab41072..1e1bd798c 100644 --- a/src/modules/system/users/UserList.vue +++ b/src/modules/system/users/UserList.vue @@ -14,8 +14,8 @@ import { } from "@halo-dev/components"; import UserCreationModal from "./components/UserCreationModal.vue"; import { onMounted, ref } from "vue"; -import { axiosInstance } from "@halo-dev/admin-shared"; -import type { User } from "@/types/extension"; +import { apiClient } from "@halo-dev/admin-shared"; +import type { User } from "@halo-dev/api-client"; const checkAll = ref(false); const creationModal = ref(false); @@ -33,7 +33,7 @@ const pagination = ref<{ const handleFetchUsers = async () => { try { - const { data } = await axiosInstance.get("/api/v1alpha1/users"); + const { data } = await apiClient.extension.user.listv1alpha1User(); users.value = data; } catch (e) { console.error(e); diff --git a/src/modules/system/users/components/UserCreationModal.vue b/src/modules/system/users/components/UserCreationModal.vue index 27c9d3353..1511a6a4d 100644 --- a/src/modules/system/users/components/UserCreationModal.vue +++ b/src/modules/system/users/components/UserCreationModal.vue @@ -1,9 +1,9 @@