refactor: api client

Signed-off-by: Ryan Wang <i@ryanc.cc>
pull/3445/head
Ryan Wang 2022-07-13 15:36:21 +08:00
parent a023974db8
commit 728dab4b74
22 changed files with 178 additions and 130 deletions

View File

@ -33,8 +33,10 @@
"@formkit/vue": "1.0.0-beta.9", "@formkit/vue": "1.0.0-beta.9",
"@halo-dev/admin-api": "^1.1.0", "@halo-dev/admin-api": "^1.1.0",
"@halo-dev/admin-shared": "workspace:*", "@halo-dev/admin-shared": "workspace:*",
"@halo-dev/api-client": "^0.0.0",
"@halo-dev/components": "workspace:*", "@halo-dev/components": "workspace:*",
"@vueuse/core": "^8.9.2", "@vueuse/core": "^8.9.2",
"axios": "^0.27.2",
"filepond": "^4.30.4", "filepond": "^4.30.4",
"filepond-plugin-image-preview": "^4.6.11", "filepond-plugin-image-preview": "^4.6.11",
"floating-vue": "2.0.0-beta.16", "floating-vue": "2.0.0-beta.16",

View File

@ -36,6 +36,7 @@
"homepage": "https://github.com/halo-dev/halo-admin/tree/next/shared/components#readme", "homepage": "https://github.com/halo-dev/halo-admin/tree/next/shared/components#readme",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@halo-dev/api-client": "^0.0.0",
"@halo-dev/components": "workspace:*", "@halo-dev/components": "workspace:*",
"axios": "^0.27.2" "axios": "^0.27.2"
}, },

View File

@ -3,8 +3,8 @@ import { BasicLayout } from "@/layouts";
import { IconUpload, VButton, VTabbar } from "@halo-dev/components"; import { IconUpload, VButton, VTabbar } from "@halo-dev/components";
import { onMounted, provide, ref, watch } from "vue"; import { onMounted, provide, ref, watch } from "vue";
import { useRoute, useRouter } from "vue-router"; import { useRoute, useRouter } from "vue-router";
import { axiosInstance } from "@/utils/api-client"; import { apiClient } from "@/utils/api-client";
import type { User } from "@/types/extension"; import type { User } from "@halo-dev/api-client";
const tabs = [ const tabs = [
{ {
@ -35,8 +35,8 @@ const { params } = useRoute();
const handleFetchUser = async () => { const handleFetchUser = async () => {
try { try {
const { data } = await axiosInstance.get( const { data } = await apiClient.extension.user.getv1alpha1User(
`/api/v1alpha1/users/${params.name}` params.name as string
); );
user.value = data; user.value = data;
} catch (e) { } catch (e) {

View File

@ -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"; import axios from "axios";
const baseUrl = "http://localhost:8090";
const axiosInstance = axios.create({ const axiosInstance = axios.create({
baseURL: "http://localhost:8090", baseURL: "http://localhost:8090",
withCredentials: true, 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 };

View File

@ -31,6 +31,7 @@ importers:
'@vue/tsconfig': ^0.1.3 '@vue/tsconfig': ^0.1.3
'@vueuse/core': ^8.9.2 '@vueuse/core': ^8.9.2
autoprefixer: ^10.4.7 autoprefixer: ^10.4.7
axios: ^0.27.2
c8: ^7.11.3 c8: ^7.11.3
cypress: ^9.7.0 cypress: ^9.7.0
eslint: ^8.19.0 eslint: ^8.19.0
@ -77,6 +78,7 @@ importers:
'@halo-dev/admin-shared': link:packages/shared '@halo-dev/admin-shared': link:packages/shared
'@halo-dev/components': link:packages/components '@halo-dev/components': link:packages/components
'@vueuse/core': 8.9.2_vue@3.2.37 '@vueuse/core': 8.9.2_vue@3.2.37
axios: 0.27.2
filepond: 4.30.4 filepond: 4.30.4
filepond-plugin-image-preview: 4.6.11_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 floating-vue: 2.0.0-beta.16_vue@3.2.37

View File

@ -3,7 +3,7 @@ import type {
ExtensionPointName, ExtensionPointName,
ExtensionPointState, ExtensionPointState,
} from "@halo-dev/admin-shared"; } from "@halo-dev/admin-shared";
import type { Plugin } from "@/types/extension"; import type { Plugin } from "@halo-dev/api-client";
import type { Ref } from "vue"; import type { Ref } from "vue";
export function useExtensionPointsState( export function useExtensionPointsState(
@ -13,9 +13,11 @@ export function useExtensionPointsState(
const { plugins } = usePluginStore(); const { plugins } = usePluginStore();
plugins.forEach((plugin: Plugin) => { plugins.forEach((plugin: Plugin) => {
// @ts-ignore
if (!plugin.spec.module?.extensionPoints?.[point]) { if (!plugin.spec.module?.extensionPoints?.[point]) {
return; return;
} }
// @ts-ignore
plugin.spec.module.extensionPoints[point]?.(state); plugin.spec.module.extensionPoints[point]?.(state);
}); });
} }

View File

@ -7,7 +7,7 @@ import type {
MenuItemType, MenuItemType,
Plugin, Plugin,
} from "@halo-dev/admin-shared"; } 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"; import { menus, minimenus, registerMenu } from "./router/menus.config";
// setup // setup
import "./setup/setupStyles"; import "./setup/setupStyles";
@ -17,7 +17,7 @@ import { setupComponents } from "./setup/setupComponents";
import { coreModules } from "./modules"; import { coreModules } from "./modules";
import { useScriptTag } from "@vueuse/core"; import { useScriptTag } from "@vueuse/core";
import { usePluginStore } from "@/stores/plugin"; import { usePluginStore } from "@/stores/plugin";
import type { User } from "@/types/extension"; import type { User } from "@halo-dev/api-client";
const app = createApp(App); const app = createApp(App);
@ -97,21 +97,23 @@ function loadStyle(href: string) {
} }
async function loadPluginModules() { async function loadPluginModules() {
const response = await axiosInstance.get( const response =
`/apis/plugin.halo.run/v1alpha1/plugins` await apiClient.extension.plugin.listpluginHaloRunV1alpha1Plugin();
);
// Get all started plugins // Get all started plugins
const plugins = response.data.filter( 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) { for (const plugin of plugins) {
const { entry, stylesheet } = plugin.status; const { entry, stylesheet } = plugin.status || {
entry: "",
stylesheet: "",
};
if (entry) { if (entry) {
const { load } = useScriptTag( const { load } = useScriptTag(
`http://localhost:8090${plugin.status.entry}` `http://localhost:8090${plugin.status?.entry}`
); );
await load(); await load();
const pluginModule = window[plugin.metadata.name]; const pluginModule = window[plugin.metadata.name];
@ -132,9 +134,7 @@ async function loadPluginModules() {
} }
async function loadCurrentUser() { async function loadCurrentUser() {
const response = await axiosInstance.get( const response = await apiClient.user.getCurrentUserDetail();
`/apis/api.halo.run/v1alpha1/users/-`
);
app.provide<User>("currentUser", response.data); app.provide<User>("currentUser", response.data);
} }

View File

@ -21,8 +21,8 @@ import vueFilePond from "vue-filepond";
import "filepond/dist/filepond.min.css"; import "filepond/dist/filepond.min.css";
import FilePondPluginImagePreview from "filepond-plugin-image-preview"; import FilePondPluginImagePreview from "filepond-plugin-image-preview";
import "filepond-plugin-image-preview/dist/filepond-plugin-image-preview.min.css"; import "filepond-plugin-image-preview/dist/filepond-plugin-image-preview.min.css";
import type { User } from "@/types/extension"; import type { User } from "@halo-dev/api-client";
import { axiosInstance } from "@halo-dev/admin-shared"; import { apiClient } from "@halo-dev/admin-shared";
const viewTypes = [ const viewTypes = [
{ {
@ -81,7 +81,7 @@ const attachments = Array.from(new Array(50), (_, index) => index).map(
const handleFetchUsers = async () => { const handleFetchUsers = async () => {
try { try {
const { data } = await axiosInstance.get("/api/v1alpha1/users"); const { data } = await apiClient.extension.user.listv1alpha1User();
users.value = data; users.value = data;
} catch (e) { } catch (e) {
console.error(e); console.error(e);

View File

@ -14,9 +14,9 @@ import {
} from "@halo-dev/components"; } from "@halo-dev/components";
import { onMounted, ref } from "vue"; import { onMounted, ref } from "vue";
import type { PagesPublicState } from "@halo-dev/admin-shared"; 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 { useExtensionPointsState } from "@/composables/usePlugins";
import type { User } from "@/types/extension"; import type { User } from "@halo-dev/api-client";
const pagesRef = ref([ const pagesRef = ref([
{ {
@ -52,7 +52,7 @@ useExtensionPointsState("PAGES", pagesPublicState);
const handleFetchUsers = async () => { const handleFetchUsers = async () => {
try { try {
const { data } = await axiosInstance.get("/api/v1alpha1/users"); const { data } = await apiClient.extension.user.listv1alpha1User();
users.value = data; users.value = data;
} catch (e) { } catch (e) {
console.error(e); console.error(e);

View File

@ -17,8 +17,8 @@ import { posts } from "./posts-mock";
import { computed, onMounted, ref } from "vue"; import { computed, onMounted, ref } from "vue";
import { useRouter } from "vue-router"; import { useRouter } from "vue-router";
import type { Post } from "@halo-dev/admin-api"; import type { Post } from "@halo-dev/admin-api";
import { axiosInstance } from "@halo-dev/admin-shared"; import { apiClient } from "@halo-dev/admin-shared";
import type { User } from "@/types/extension"; import type { User } from "@halo-dev/api-client";
const postsRef = ref( const postsRef = ref(
// eslint-disable-next-line // eslint-disable-next-line
@ -43,7 +43,7 @@ const checkedCount = computed(() => {
const handleFetchUsers = async () => { const handleFetchUsers = async () => {
try { try {
const { data } = await axiosInstance.get("/api/v1alpha1/users"); const { data } = await apiClient.extension.user.listv1alpha1User();
users.value = data; users.value = data;
} catch (e) { } catch (e) {
console.error(e); console.error(e);

View File

@ -1,14 +1,14 @@
<script lang="ts" name="RecentLoginWidget" setup> <script lang="ts" name="RecentLoginWidget" setup>
import { VCard } from "@halo-dev/components"; import { VCard } from "@halo-dev/components";
import { onMounted, ref } from "vue"; import { onMounted, ref } from "vue";
import type { User } from "@/types/extension"; import { apiClient } from "@halo-dev/admin-shared";
import { axiosInstance } from "@halo-dev/admin-shared"; import type { User } from "@halo-dev/api-client";
const users = ref<User[]>([]); const users = ref<User[]>([]);
const handleFetchUsers = async () => { const handleFetchUsers = async () => {
try { try {
const { data } = await axiosInstance.get("/api/v1alpha1/users"); const { data } = await apiClient.extension.user.listv1alpha1User();
users.value = data; users.value = data;
} catch (e) { } catch (e) {
console.error(e); console.error(e);

View File

@ -4,26 +4,34 @@ import {
VButton, VButton,
VCard, VCard,
VPageHeader, VPageHeader,
VSpace,
VSwitch, VSwitch,
VTabbar, VTabbar,
VTag, VTag,
} from "@halo-dev/components"; } from "@halo-dev/components";
import { useRoute } from "vue-router"; import { useRoute } from "vue-router";
import { computed, onMounted, ref } from "vue"; import { computed, onMounted, ref } from "vue";
import { apiClient } from "@halo-dev/admin-shared";
import type { import type {
ConfigMap,
Plugin, Plugin,
ConfigMap,
Setting, Setting,
SettingSpec, SettingSpec,
} from "@/types/extension"; } from "@halo-dev/api-client";
import { axiosInstance } from "@halo-dev/admin-shared";
import cloneDeep from "lodash.clonedeep"; import cloneDeep from "lodash.clonedeep";
import type { FormKitSchemaCondition, FormKitSchemaNode } from "@formkit/core";
interface FormKitSettingSpec extends Omit<SettingSpec, "formSchema"> {
formSchema: FormKitSchemaCondition | FormKitSchemaNode[];
}
interface FormKitSetting extends Omit<Setting, "spec"> {
spec: Array<FormKitSettingSpec>;
}
const pageTabs = ref([{ id: "detail", label: "详情" }]); const pageTabs = ref([{ id: "detail", label: "详情" }]);
const activeTabId = ref(pageTabs.value[0].id); const activeTabId = ref(pageTabs.value[0].id);
const plugin = ref<Plugin>({} as Plugin); const plugin = ref<Plugin>({} as Plugin);
const settings = ref<Setting>({} as Setting); const settings = ref<FormKitSetting>({} as FormKitSetting);
const configmapFormData = ref<Record<string, Record<string, string>>>({}); const configmapFormData = ref<Record<string, Record<string, string>>>({});
const configmap = ref<ConfigMap>({ const configmap = ref<ConfigMap>({
@ -41,9 +49,10 @@ const dialog = useDialog();
const handleFetchPlugin = async () => { const handleFetchPlugin = async () => {
try { try {
const response = await axiosInstance.get( const response =
`/apis/plugin.halo.run/v1alpha1/plugins/${params.pluginName}` await apiClient.extension.plugin.getpluginHaloRunV1alpha1Plugin(
); params.pluginName as string
);
plugin.value = response.data; plugin.value = response.data;
await handleFetchSettings(); await handleFetchSettings();
@ -55,25 +64,25 @@ const handleFetchPlugin = async () => {
const handleFetchSettings = async () => { const handleFetchSettings = async () => {
try { try {
const response = await axiosInstance.get( const response = await apiClient.extension.setting.getv1alpha1Setting(
`/api/v1alpha1/settings/${plugin.value.spec.settingName}` plugin.value.spec.settingName as string
); );
settings.value = response.data; settings.value = response.data as FormKitSetting;
const { spec } = settings.value; const { spec } = settings.value;
if (spec) { if (spec) {
pageTabs.value = [ pageTabs.value = [
...pageTabs.value, ...pageTabs.value,
...spec.map((item: SettingSpec) => { ...spec.map((item: FormKitSettingSpec) => {
return { return {
id: item.group, id: item.group,
label: item.label, label: item.label || "",
}; };
}), }),
]; ];
spec.forEach((item: SettingSpec) => { spec.forEach((item: FormKitSettingSpec) => {
configmapFormData.value[item.group] = {}; configmapFormData.value[item.group] = {};
}); });
} }
@ -84,16 +93,18 @@ const handleFetchSettings = async () => {
const handleFetchConfigMap = async () => { const handleFetchConfigMap = async () => {
try { try {
const response = await axiosInstance.get( const response = await apiClient.extension.configMap.getv1alpha1ConfigMap(
`/api/v1alpha1/configmaps/${plugin.value.spec.configMapName}` plugin.value.spec.configMapName as string
); );
configmap.value = response.data; configmap.value = response.data;
const { data } = configmap.value; const { data } = configmap.value;
Object.keys(data).forEach((key) => { if (data) {
configmapFormData.value[key] = JSON.parse(data[key]); Object.keys(data).forEach((key) => {
}); configmapFormData.value[key] = JSON.parse(data[key]);
});
}
} catch (e) { } catch (e) {
console.error(e); console.error(e);
} }
@ -107,17 +118,20 @@ const handleSaveConfigMap = async () => {
configmap.value.metadata.name = plugin.value.spec.configMapName; configmap.value.metadata.name = plugin.value.spec.configMapName;
} }
settings.value.spec.forEach((item: SettingSpec) => { settings.value.spec.forEach((item: FormKitSettingSpec) => {
// @ts-ignore
configmap.value.data[item.group] = JSON.stringify( configmap.value.data[item.group] = JSON.stringify(
configmapFormData.value[item.group] configmapFormData.value[item.group]
); );
}); });
if (!configmap.value.metadata.creationTimestamp) { if (!configmap.value.metadata.creationTimestamp) {
await axiosInstance.post(`/api/v1alpha1/configmaps`, configmap.value); await apiClient.extension.configMap.createv1alpha1ConfigMap(
configmap.value
);
} else { } else {
await axiosInstance.put( await apiClient.extension.configMap.updatev1alpha1ConfigMap(
`/api/v1alpha1/configmaps/${configmap.value.metadata.name}`, configmap.value.metadata.name,
configmap.value configmap.value
); );
} }
@ -141,8 +155,8 @@ const handleChangePluginStatus = async () => {
onConfirm: async () => { onConfirm: async () => {
try { try {
pluginToUpdate.spec.enabled = !pluginToUpdate.spec.enabled; pluginToUpdate.spec.enabled = !pluginToUpdate.spec.enabled;
await axiosInstance.put( await apiClient.extension.plugin.updatepluginHaloRunV1alpha1Plugin(
`/apis/plugin.halo.run/v1alpha1/plugins/${plugin.value.metadata.name}`, plugin.value.metadata.name,
pluginToUpdate pluginToUpdate
); );
} catch (e) { } catch (e) {
@ -264,31 +278,7 @@ onMounted(handleFetchPlugin);
> >
<dt class="text-sm font-medium text-gray-900">模型定义</dt> <dt class="text-sm font-medium text-gray-900">模型定义</dt>
<dd class="mt-1 sm:col-span-2 sm:mt-0"> <dd class="mt-1 sm:col-span-2 sm:mt-0">
<ul v-if="plugin?.extensions" class="space-y-2"> <span></span>
<li
v-for="(extension, index) in plugin?.extensions"
:key="index"
>
<div
class="inline-flex w-96 cursor-pointer flex-row flex-col gap-y-3 rounded border p-5 hover:border-themeable-primary"
>
<span class="font-medium text-gray-900">
{{ extension.name }}
</span>
<div class="text-xs text-gray-400">
<VSpace>
<VTag
v-for="(field, fieldIndex) in extension.fields"
:key="fieldIndex"
>
{{ field }}
</VTag>
</VSpace>
</div>
</div>
</li>
</ul>
<span v-else></span>
</dd> </dd>
</div> </div>
<div <div

View File

@ -15,8 +15,8 @@ import {
} from "@halo-dev/components"; } from "@halo-dev/components";
import { onMounted, ref, watch } from "vue"; import { onMounted, ref, watch } from "vue";
import { useRouter } from "vue-router"; import { useRouter } from "vue-router";
import type { Plugin } from "@/types/extension"; import { apiClient } from "@halo-dev/admin-shared";
import { axiosInstance } from "@halo-dev/admin-shared"; import type { Plugin } from "@halo-dev/api-client";
import cloneDeep from "lodash.clonedeep"; import cloneDeep from "lodash.clonedeep";
const checkedAll = ref(false); const checkedAll = ref(false);
@ -46,9 +46,8 @@ const isStarted = (plugin: Plugin) => {
const handleFetchPlugins = async () => { const handleFetchPlugins = async () => {
try { try {
const response = await axiosInstance.get( const response =
`/apis/plugin.halo.run/v1alpha1/plugins` await apiClient.extension.plugin.listpluginHaloRunV1alpha1Plugin();
);
plugins.value = response.data; plugins.value = response.data;
} catch (e) { } catch (e) {
console.error("Fail to fetch plugins", e); console.error("Fail to fetch plugins", e);
@ -63,8 +62,8 @@ const handleChangeStatus = (plugin: Plugin) => {
onConfirm: async () => { onConfirm: async () => {
try { try {
pluginToUpdate.spec.enabled = !pluginToUpdate.spec.enabled; pluginToUpdate.spec.enabled = !pluginToUpdate.spec.enabled;
await axiosInstance.put( await apiClient.extension.plugin.updatepluginHaloRunV1alpha1Plugin(
`/apis/plugin.halo.run/v1alpha1/plugins/${plugin.metadata.name}`, pluginToUpdate.metadata.name,
pluginToUpdate pluginToUpdate
); );
} catch (e) { } catch (e) {
@ -102,8 +101,8 @@ const handleChangeStatusInBatch = (enable: boolean) => {
try { try {
for (const plugin of pluginsToUpdate) { for (const plugin of pluginsToUpdate) {
plugin.spec.enabled = enable; plugin.spec.enabled = enable;
await axiosInstance.put( await apiClient.extension.plugin.updatepluginHaloRunV1alpha1Plugin(
`/apis/plugin.halo.run/v1alpha1/plugins/${plugin.metadata.name}`, plugin.metadata.name,
plugin plugin
); );
} }

View File

@ -11,8 +11,8 @@ import {
} from "@halo-dev/components"; } from "@halo-dev/components";
import { useRoute, useRouter } from "vue-router"; import { useRoute, useRouter } from "vue-router";
import { computed, onMounted, ref } from "vue"; import { computed, onMounted, ref } from "vue";
import { axiosInstance } from "@halo-dev/admin-shared"; import { apiClient } from "@halo-dev/admin-shared";
import type { Role, User } from "@/types/extension"; import type { Role, User } from "@halo-dev/api-client";
interface RoleTemplateGroup { interface RoleTemplateGroup {
name: string | null | undefined; name: string | null | undefined;
@ -42,6 +42,7 @@ const formState = ref<FormState>({
"plugin.halo.run/display-name": "", "plugin.halo.run/display-name": "",
}, },
}, },
rules: [],
}, },
selectedRoleTemplates: [], selectedRoleTemplates: [],
saving: false, saving: false,
@ -74,8 +75,8 @@ const roleTemplateGroups = computed<RoleTemplateGroup[]>(() => {
const handleFetchRole = async () => { const handleFetchRole = async () => {
try { try {
const response = await axiosInstance.get<Role>( const response = await apiClient.extension.role.getv1alpha1Role(
`/api/v1alpha1/roles/${route.params.name}` route.params.name as string
); );
formState.value.role = response.data; formState.value.role = response.data;
formState.value.selectedRoleTemplates = JSON.parse( formState.value.selectedRoleTemplates = JSON.parse(
@ -89,7 +90,7 @@ const handleFetchRole = async () => {
const handleFetchRoles = async () => { const handleFetchRoles = async () => {
try { try {
const { data } = await axiosInstance.get("/api/v1alpha1/roles"); const { data } = await apiClient.extension.role.listv1alpha1Role();
roles.value = data; roles.value = data;
} catch (e) { } catch (e) {
console.error(e); console.error(e);
@ -98,7 +99,7 @@ const handleFetchRoles = async () => {
const handleFetchUsers = async () => { const handleFetchUsers = async () => {
try { try {
const { data } = await axiosInstance.get("/api/v1alpha1/users"); const { data } = await apiClient.extension.user.listv1alpha1User();
users.value = data; users.value = data;
} catch (e) { } catch (e) {
console.error(e); console.error(e);
@ -113,8 +114,8 @@ const handleUpdateRole = async () => {
"plugin.halo.run/dependencies" "plugin.halo.run/dependencies"
] = JSON.stringify(formState.value.selectedRoleTemplates); ] = JSON.stringify(formState.value.selectedRoleTemplates);
} }
await axiosInstance.put<Role>( await apiClient.extension.role.updatev1alpha1Role(
`/api/v1alpha1/roles/${route.params.name}`, route.params.name as string,
formState.value.role formState.value.role
); );
} catch (e) { } catch (e) {

View File

@ -14,8 +14,8 @@ import {
import RoleCreationModal from "./components/RoleCreationModal.vue"; import RoleCreationModal from "./components/RoleCreationModal.vue";
import { useRouter } from "vue-router"; import { useRouter } from "vue-router";
import { computed, onMounted, ref } from "vue"; import { computed, onMounted, ref } from "vue";
import type { Role } from "@/types/extension"; import type { Role } from "@halo-dev/api-client";
import { axiosInstance } from "@halo-dev/admin-shared"; import { apiClient } from "@halo-dev/admin-shared";
const createVisible = ref(false); const createVisible = ref(false);
const roles = ref<Role[]>([]); const roles = ref<Role[]>([]);
@ -31,7 +31,7 @@ const router = useRouter();
const handleFetchRoles = async () => { const handleFetchRoles = async () => {
try { try {
const { data } = await axiosInstance.get("/api/v1alpha1/roles"); const { data } = await apiClient.extension.role.listv1alpha1Role();
roles.value = data; roles.value = data;
} catch (e) { } catch (e) {
console.error(e); console.error(e);

View File

@ -1,8 +1,8 @@
<script lang="ts" setup> <script lang="ts" setup>
import { VButton, VModal, VTabItem, VTabs } from "@halo-dev/components"; import { VButton, VModal, VTabItem, VTabs } from "@halo-dev/components";
import { computed, ref, watch } from "vue"; import { computed, ref, watch } from "vue";
import type { Role } from "@/types/extension"; import { apiClient } from "@halo-dev/admin-shared";
import { axiosInstance } from "@halo-dev/admin-shared"; import type { Role } from "@halo-dev/api-client";
interface RoleTemplateGroup { interface RoleTemplateGroup {
name: string | null | undefined; name: string | null | undefined;
@ -71,7 +71,7 @@ const roleTemplateGroups = computed<RoleTemplateGroup[]>(() => {
const handleFetchRoles = async () => { const handleFetchRoles = async () => {
try { try {
const { data } = await axiosInstance.get("/api/v1alpha1/roles"); const { data } = await apiClient.extension.role.listv1alpha1Role();
roles.value = data; roles.value = data;
} catch (e) { } catch (e) {
console.error(e); console.error(e);
@ -86,8 +86,7 @@ const handleCreateRole = async () => {
"plugin.halo.run/dependencies" "plugin.halo.run/dependencies"
] = JSON.stringify(creationFormState.value.selectedRoleTemplates); ] = JSON.stringify(creationFormState.value.selectedRoleTemplates);
} }
await axiosInstance.post<Role>( await apiClient.extension.role.createv1alpha1Role(
"/api/v1alpha1/roles",
creationFormState.value.role creationFormState.value.role
); );
handleVisibleChange(false); handleVisibleChange(false);

View File

@ -5,12 +5,17 @@ import {
VButton, VButton,
} from "@halo-dev/components"; } from "@halo-dev/components";
import { v4 as uuid } from "uuid"; import { v4 as uuid } from "uuid";
import { axiosInstance } from "@halo-dev/admin-shared"; import axios from "axios";
import qs from "qs"; import qs from "qs";
import logo from "../../../assets/logo.svg"; import logo from "../../../assets/logo.svg";
import { onMounted, ref } from "vue"; import { onMounted, ref } from "vue";
import { submitForm } from "@formkit/vue"; import { submitForm } from "@formkit/vue";
const axiosInstance = axios.create({
baseURL: "http://localhost:8090",
withCredentials: true,
});
interface LoginForm { interface LoginForm {
_csrf: string; _csrf: string;
username: string; username: string;

View File

@ -10,8 +10,8 @@ import {
VTabs, VTabs,
} from "@halo-dev/components"; } from "@halo-dev/components";
import { onMounted, ref } from "vue"; import { onMounted, ref } from "vue";
import type { PersonalAccessToken } from "@/types/extension"; import { apiClient } from "@halo-dev/admin-shared";
import { axiosInstance } from "@halo-dev/admin-shared"; import type { PersonalAccessToken } from "@halo-dev/api-client";
const createVisible = ref(false); const createVisible = ref(false);
const createActiveId = ref("general"); const createActiveId = ref("general");
@ -20,9 +20,8 @@ const personalAccessTokens = ref<PersonalAccessToken[]>([]);
const handleFetchPersonalAccessTokens = async () => { const handleFetchPersonalAccessTokens = async () => {
try { try {
const response = await axiosInstance.get( const response =
"/api/v1alpha1/personalaccesstokens" await apiClient.extension.personalAccessToken.listv1alpha1PersonalAccessToken();
);
personalAccessTokens.value = response.data; personalAccessTokens.value = response.data;
} catch (e) { } catch (e) {
console.error(e); console.error(e);

View File

@ -1,7 +1,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import { VButton } from "@halo-dev/components"; import { VButton } from "@halo-dev/components";
import { inject } from "vue"; import { inject } from "vue";
import type { User } from "@/types/extension"; import type { User } from "@halo-dev/api-client";
const user = inject<User>("user"); const user = inject<User>("user");
</script> </script>

View File

@ -3,7 +3,7 @@ import { IconUserSettings, VTag } from "@halo-dev/components";
import type { Ref } from "vue"; import type { Ref } from "vue";
import { computed, inject } from "vue"; import { computed, inject } from "vue";
import { useRouter } from "vue-router"; import { useRouter } from "vue-router";
import type { User } from "@/types/extension"; import type { User } from "@halo-dev/api-client";
const user = inject<Ref<User>>("user"); const user = inject<Ref<User>>("user");

View File

@ -14,8 +14,8 @@ import {
} from "@halo-dev/components"; } from "@halo-dev/components";
import UserCreationModal from "./components/UserCreationModal.vue"; import UserCreationModal from "./components/UserCreationModal.vue";
import { onMounted, ref } from "vue"; import { onMounted, ref } from "vue";
import { axiosInstance } from "@halo-dev/admin-shared"; import { apiClient } from "@halo-dev/admin-shared";
import type { User } from "@/types/extension"; import type { User } from "@halo-dev/api-client";
const checkAll = ref(false); const checkAll = ref(false);
const creationModal = ref<boolean>(false); const creationModal = ref<boolean>(false);
@ -33,7 +33,7 @@ const pagination = ref<{
const handleFetchUsers = async () => { const handleFetchUsers = async () => {
try { try {
const { data } = await axiosInstance.get("/api/v1alpha1/users"); const { data } = await apiClient.extension.user.listv1alpha1User();
users.value = data; users.value = data;
} catch (e) { } catch (e) {
console.error(e); console.error(e);

View File

@ -1,9 +1,9 @@
<script lang="ts" name="UserCreationModal" setup> <script lang="ts" name="UserCreationModal" setup>
import type { PropType } from "vue"; import type { PropType } from "vue";
import { computed, onMounted, ref, watch } from "vue"; import { computed, onMounted, ref, watch } from "vue";
import { axiosInstance } from "@halo-dev/admin-shared"; import { apiClient } from "@halo-dev/admin-shared";
import type { Role, User } from "@halo-dev/api-client";
import { IconSave, VButton, VModal } from "@halo-dev/components"; import { IconSave, VButton, VModal } from "@halo-dev/components";
import type { Role, User } from "@/types/extension";
import { v4 as uuid } from "uuid"; import { v4 as uuid } from "uuid";
const props = defineProps({ const props = defineProps({
@ -70,7 +70,7 @@ watch(props, (newVal) => {
const handleFetchRoles = async () => { const handleFetchRoles = async () => {
try { try {
const { data } = await axiosInstance.get("/api/v1alpha1/roles"); const { data } = await apiClient.extension.role.listv1alpha1Role();
roles.value = data; roles.value = data;
} catch (e) { } catch (e) {
console.error(e); console.error(e);
@ -90,27 +90,26 @@ const handleCreateUser = async () => {
let user: User; let user: User;
if (isUpdateMode.value) { if (isUpdateMode.value) {
const response = await axiosInstance.put( const response = await apiClient.extension.user.updatev1alpha1User(
`/api/v1alpha1/users/${creationForm.value.user.metadata.name}`, creationForm.value.user.metadata.name,
creationForm.value.user creationForm.value.user
); );
user = response.data; user = response.data;
} else { } else {
const response = await axiosInstance.post( const response = await apiClient.extension.user.createv1alpha1User(
"/api/v1alpha1/users",
creationForm.value.user creationForm.value.user
); );
user = response.data; user = response.data;
} }
if (selectedRole.value) { // if (selectedRole.value) {
await axiosInstance.post( // await apiClient.user.(
`/apis/api.halo.run/v1alpha1/users/${user.metadata.name}/permissions`, // `/apis/api.halo.run/v1alpha1/users/${user.metadata.name}/permissions`,
{ // {
roles: [selectedRole.value], // roles: [selectedRole.value],
} // }
); // );
} // }
handleVisibleChange(false); handleVisibleChange(false);
} catch (e) { } catch (e) {