chore: 新增一批接口

This commit is contained in:
wangxuefeng
2025-02-28 17:14:32 +08:00
parent a835e266b5
commit 2fa8ed74e5
27 changed files with 482 additions and 29 deletions

View File

@@ -1,6 +1,22 @@
import instance from './instance';
export const getApplicationList = async () => {
const response = await instance.get('/application/list');
const response = await instance.get('/api/v1/applications');
return response.data;
};
export const createApplication = async (data: any) => {
const response = await instance.post('/api/v1/applications', data);
return response.data;
};
export const updateApplication = async (id: string, data: any) => {
const response = await instance.put(`/api/v1/applications/${id}`, data);
return response.data;
};
export const deleteApplication = async (id: string) => {
console.log(id);
const response = await instance.delete(`/api/v1/applications/${id}`);
return response.data;
};

View File

@@ -1 +1,3 @@
export * from './application';
export * from './project';
export * from './user';

View File

@@ -0,0 +1,21 @@
import instance from './instance';
export const getProjectList = async () => {
const response = await instance.get('/api/v1/projects');
return response.data;
};
export const createProject = async (data: any) => {
const response = await instance.post('/api/v1/projects', data);
return response.data;
};
export const updateProject = async (id: string, data: any) => {
const response = await instance.put(`/api/v1/projects/${id}`, data);
return response.data;
};
export const deleteProject = async (id: string) => {
const response = await instance.delete(`/api/v1/projects/${id}`);
return response.data;
};

View File

@@ -0,0 +1,11 @@
import instance from './instance';
export const login = async (data: { username: string; password: string }) => {
const response = await instance.post('/login', data);
return response.data;
};
export const logout = async () => {
const response = await instance.post('/logout');
return response.data;
};

View File

@@ -4,6 +4,8 @@ import dayjs from 'dayjs';
import customParseFormat from 'dayjs/plugin/customParseFormat';
import utc from 'dayjs/plugin/utc';
import timezone from 'dayjs/plugin/timezone';
import { VueQueryPlugin } from '@tanstack/vue-query';
import App from './App.vue';
import { setupRouter } from './router';
import { setupIcons } from './components/basic/icon';
@@ -17,6 +19,7 @@ dayjs.extend(timezone);
const app = createApp(App);
app.use(VueQueryPlugin);
function setupPlugins() {
// 安装图标
setupIcons();

View File

@@ -29,6 +29,16 @@ const routes: Array<RouteRecordRaw> = [
},
component: () => import('@/components/renderer-adapter/index.vue'),
},
{
path: 'add',
name: `${moduleName}-add`,
meta: {
title: '添加应用',
keepAlive: true,
icon: 'ant-design:list',
},
component: () => import('@/views/application/add.vue'),
},
],
},
];

View File

@@ -2,5 +2,6 @@ import dashboard from './dashboard';
import user from './user';
import micro from './micro';
import application from './application';
import project from './project';
export default [...dashboard, ...user, ...micro, ...application];
export default [...dashboard, ...user, ...micro, ...application, ...project];

View File

@@ -0,0 +1,29 @@
import type { RouteRecordRaw } from 'vue-router';
// 微前端路由
const moduleName = 'project';
const routes: Array<RouteRecordRaw> = [
{
path: '/project',
name: moduleName,
meta: {
title: '项目管理',
icon: 'ant-design:appstore-outlined',
},
children: [
{
path: 'add',
name: `${moduleName}-add`,
meta: {
title: '添加项目',
keepAlive: true,
icon: 'ant-design:list',
},
component: () => import('@/views/project/add.vue'),
},
],
},
];
export default routes;

View File

@@ -3,7 +3,8 @@ import { defineStore } from 'pinia';
import { useSSEStore } from './sse';
import { store } from '@/store';
import { resetRouter } from '@/router';
import { userLogin, userLogout } from '@/io';
import { login, logout } from '@/io';
export const useUserStore = defineStore(
'user',
() => {
@@ -28,7 +29,7 @@ export const useUserStore = defineStore(
};
/** 登录 */
const login = async (params: any) => {
const data = await userLogin(params);
const data = await login(params);
console.log('data', data);
// @ts-ignore
setToken(data.msg);
@@ -36,7 +37,7 @@ export const useUserStore = defineStore(
/** 登出 */
const logout = async () => {
sseStore.closeEventSource();
await userLogout();
await logout();
clearLoginStatus();
};

View File

@@ -0,0 +1,51 @@
<script setup lang="ts">
import { useQuery, useMutation } from '@tanstack/vue-query';
import { getApplicationList, createApplication, deleteApplication } from '@/io';
const addData = {
name: 'test',
active: true,
};
const {
data: appList,
isError,
isLoading,
refetch,
} = useQuery({
queryKey: ['applicationList'],
queryFn: getApplicationList,
enabled: true,
});
const { mutate: createApp, isLoading: isCreating } = useMutation({
mutationFn: createApplication,
onSuccess: () => {
refetch();
},
});
const {
mutate: deleteApp,
isLoading: isDeleting,
error: deleteError,
} = useMutation({
mutationFn: deleteApplication,
onSuccess: () => {
refetch();
},
});
</script>
<template>
<div style="display: flex; flex-direction: column; gap: 10px">
<div v-if="isLoading">加载中...</div>
<div v-else-if="isError">加载失败</div>
<div v-else>
{{ appList }}
</div>
<Button type="primary" :loading="isCreating" @click="createApp(addData)"> 添加应用 </Button>
<Button type="primary" @click="refetch">重新获取</Button>
<Button type="primary" :loading="isDeleting" @click="deleteApp('3')"> 删除应用 </Button>
</div>
</template>

View File

@@ -0,0 +1,53 @@
<script setup lang="ts">
import { useQuery, useMutation } from '@tanstack/vue-query';
import { getProjectList, createProject, deleteProject } from '@/io';
const addData = {
application_id: 3,
description: 'test project',
name: 'test project',
platform: 'web',
};
const {
data: projectList,
isError,
isLoading,
refetch,
} = useQuery({
queryKey: ['getProjectList'],
queryFn: getProjectList,
enabled: true,
});
const { mutate: createProjectMutation, isLoading: isCreating } = useMutation({
mutationFn: createProject,
onSuccess: () => {
refetch();
},
});
const { mutate: deleteProjectMutation, isLoading: isDeleting } = useMutation({
mutationFn: deleteProject,
onSuccess: () => {
refetch();
},
});
</script>
<template>
<div style="display: flex; flex-direction: column; gap: 10px">
<div v-if="isLoading">加载中...</div>
<div v-else-if="isError">加载失败</div>
<div v-else>
{{ projectList }}
</div>
<Button type="primary" :loading="isCreating" @click="createProjectMutation(addData)">
添加项目
</Button>
<Button type="primary" @click="refetch">重新获取</Button>
<Button type="primary" :loading="isDeleting" @click="deleteProjectMutation('3')">
删除项目
</Button>
</div>
</template>