mirror of
https://github.com/lzh-1625/go_process_manager.git
synced 2025-10-05 16:06:51 +08:00
add api file
This commit is contained in:
@@ -138,7 +138,7 @@ func routePathInit(r *gin.Engine) {
|
|||||||
{
|
{
|
||||||
configGroup.GET("", bind(api.ConfigApi.GetSystemConfiguration, None))
|
configGroup.GET("", bind(api.ConfigApi.GetSystemConfiguration, None))
|
||||||
configGroup.PUT("", bind(api.ConfigApi.SetSystemConfiguration, None))
|
configGroup.PUT("", bind(api.ConfigApi.SetSystemConfiguration, None))
|
||||||
configGroup.PUT("/log", bind(api.ConfigApi.LogConfigReload, None))
|
configGroup.GET("/reload", bind(api.ConfigApi.LogConfigReload, None))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
3
resources/.vite/deps_temp_61bc278e/package.json
Normal file
3
resources/.vite/deps_temp_61bc278e/package.json
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"type": "module"
|
||||||
|
}
|
102
resources/src/api/api.ts
Normal file
102
resources/src/api/api.ts
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
import axios, {
|
||||||
|
AxiosInstance,
|
||||||
|
AxiosError,
|
||||||
|
AxiosRequestConfig,
|
||||||
|
AxiosResponse,
|
||||||
|
} from "axios";
|
||||||
|
import { useSnackbarStore } from "@/stores/snackbarStore";
|
||||||
|
import router from "../router";
|
||||||
|
|
||||||
|
const snackbarStore = useSnackbarStore();
|
||||||
|
|
||||||
|
interface Result {
|
||||||
|
code: number;
|
||||||
|
msg: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 请求响应参数,包含data
|
||||||
|
interface ResultData<T = any> extends Result {
|
||||||
|
data?: T;
|
||||||
|
}
|
||||||
|
const URL: string = "";
|
||||||
|
enum RequestEnums {
|
||||||
|
TIMEOUT = 20000,
|
||||||
|
}
|
||||||
|
const config = {
|
||||||
|
// 默认地址
|
||||||
|
baseURL: URL as string,
|
||||||
|
// 设置超时时间
|
||||||
|
timeout: RequestEnums.TIMEOUT as number,
|
||||||
|
// 跨域时候允许携带凭证
|
||||||
|
withCredentials: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
class RequestHttp {
|
||||||
|
service: AxiosInstance;
|
||||||
|
public constructor(config: AxiosRequestConfig) {
|
||||||
|
// 实例化axios
|
||||||
|
this.service = axios.create(config);
|
||||||
|
|
||||||
|
this.service.interceptors.request.use(
|
||||||
|
(config) => {
|
||||||
|
const token = localStorage.getItem("token") || "";
|
||||||
|
config.headers.Authorization = token;
|
||||||
|
config.url = "/api" + config.url;
|
||||||
|
return config;
|
||||||
|
},
|
||||||
|
(error: AxiosError) => {
|
||||||
|
snackbarStore.showErrorMessage(error);
|
||||||
|
return Promise.reject(error);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 响应拦截器
|
||||||
|
* 服务器换返回信息 -> [拦截统一处理] -> 客户端JS获取到信息
|
||||||
|
*/
|
||||||
|
this.service.interceptors.response.use(
|
||||||
|
(response: AxiosResponse) => {
|
||||||
|
const { data } = response; // 解构
|
||||||
|
if (data.code !== 0) {
|
||||||
|
snackbarStore.showErrorMessage(data.message);
|
||||||
|
return Promise.reject(data);
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
(error: AxiosError) => {
|
||||||
|
const { response } = error;
|
||||||
|
if (response) {
|
||||||
|
this.handleCode(response.status);
|
||||||
|
}
|
||||||
|
//@ts-ignore
|
||||||
|
snackbarStore.showErrorMessage(response.data.message);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
handleCode(code: number): void {
|
||||||
|
switch (code) {
|
||||||
|
case 401:
|
||||||
|
router.replace("/login");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 常用方法封装
|
||||||
|
get<T>(url: string, params?: object): Promise<ResultData<T>> {
|
||||||
|
return this.service.get(url, { params });
|
||||||
|
}
|
||||||
|
post<T>(url: string, params?: object): Promise<ResultData<T>> {
|
||||||
|
return this.service.post(url, params);
|
||||||
|
}
|
||||||
|
put<T>(url: string, params?: object): Promise<ResultData<T>> {
|
||||||
|
return this.service.put(url, params);
|
||||||
|
}
|
||||||
|
delete<T>(url: string, params?: object): Promise<ResultData<T>> {
|
||||||
|
return this.service.delete(url, { params });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 导出一个实例对象
|
||||||
|
export default new RequestHttp(config);
|
13
resources/src/api/config.ts
Normal file
13
resources/src/api/config.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import api from "./api";
|
||||||
|
|
||||||
|
export function getConfig() {
|
||||||
|
return api.get("/config", undefined).then((res) => res);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setConfig(data) {
|
||||||
|
return api.put("/config", data).then((res) => res);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function esReload() {
|
||||||
|
return api.put("/config/reload").then((res) => res);
|
||||||
|
}
|
5
resources/src/api/log.ts
Normal file
5
resources/src/api/log.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import api from "./api";
|
||||||
|
|
||||||
|
export function getLog(data: any) {
|
||||||
|
return api.post("/log", data).then((res) => res);
|
||||||
|
}
|
5
resources/src/api/login.ts
Normal file
5
resources/src/api/login.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import api from "./api";
|
||||||
|
|
||||||
|
export const login = (query: any) => {
|
||||||
|
return api.post("/user/login", query).then((res) => res);
|
||||||
|
};
|
49
resources/src/api/process.ts
Normal file
49
resources/src/api/process.ts
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
import api from "./api";
|
||||||
|
|
||||||
|
export function getProcessList() {
|
||||||
|
return api.get("/process", undefined).then((res) => res);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getProcessListWait() {
|
||||||
|
return api.get("/process/wait", undefined).then((res) => res);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function killProcessAll(uuid) {
|
||||||
|
return api.delete("/process/all", { uuid }).then((res) => res);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function startProcessAll(uuid) {
|
||||||
|
return api.put("/process/all", { uuid }).then((res) => res);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function killProcess(uuid) {
|
||||||
|
return api.delete("/process", { uuid }).then((res) => res);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function startProcess(uuid) {
|
||||||
|
return api.put("/process", { uuid }).then((res) => res);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getContorl(uuid) {
|
||||||
|
return api.get("/process/control", { uuid }).then((res) => res);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getProcessConfig(uuid) {
|
||||||
|
return api.get("/process/config", { uuid }).then((res) => res);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function deleteProcessConfig(uuid) {
|
||||||
|
return api.delete("/process/config", { uuid }).then((res) => res);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function putProcessConfig(data) {
|
||||||
|
return api.put("/process/config", data).then((res) => res);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function postProcessConfig(data) {
|
||||||
|
return api.post("/process/config", data).then((res) => res);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createProcessShare(data) {
|
||||||
|
return api.post("/process/share", data).then((res) => res);
|
||||||
|
}
|
21
resources/src/api/push.ts
Normal file
21
resources/src/api/push.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import api from "./api";
|
||||||
|
|
||||||
|
export function createPush(data) {
|
||||||
|
return api.post("/push", data).then((res) => res);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getPushList() {
|
||||||
|
return api.get("/push/list", undefined).then((res) => res);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function deletePush(id) {
|
||||||
|
return api.delete("/push", { id }).then((res) => res);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getPush(id) {
|
||||||
|
return api.get("/push", { id }).then((res) => res);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function editPush(data) {
|
||||||
|
return api.put("/push", data).then((res) => res);
|
||||||
|
}
|
41
resources/src/api/task.ts
Normal file
41
resources/src/api/task.ts
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import api from "./api";
|
||||||
|
|
||||||
|
export function getTaskAll() {
|
||||||
|
return api.get("/task/all", undefined).then((res) => res);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getTaskAllWait() {
|
||||||
|
return api.get("/task/all/wait", undefined).then((res) => res);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getTaskById(id) {
|
||||||
|
return api.get("/task", { id }).then((res) => res);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function startTaskById(id) {
|
||||||
|
return api.get("/task/start", { id }).then((res) => res);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function stopTaskById(id) {
|
||||||
|
return api.get("/task/stop", { id }).then((res) => res);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function editTaskEnable(body) {
|
||||||
|
return api.put("/task/enable", body).then((res) => res);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function editTask(body) {
|
||||||
|
return api.put("/task", body).then((res) => res);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function addTask(body) {
|
||||||
|
return api.post("/task", body).then((res) => res);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function deleteTaskById(id) {
|
||||||
|
return api.delete("/task", { id }).then((res) => res);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function changeTaskKey(id) {
|
||||||
|
return api.post("/task/key", { id }).then((res) => res);
|
||||||
|
}
|
39
resources/src/api/user.ts
Normal file
39
resources/src/api/user.ts
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import api from "./api";
|
||||||
|
|
||||||
|
// 登录方法
|
||||||
|
export function login(data) {
|
||||||
|
return api.post("/user/login", {
|
||||||
|
account: data.account,
|
||||||
|
password: data.password,
|
||||||
|
}).then((res) => res);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createUser(data) {
|
||||||
|
return api.post("/user", data).then((res) => res);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function deleteUser(account) {
|
||||||
|
return api.delete("/user", { account }).then((res) => res);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function changePassword(data) {
|
||||||
|
return api.put("/user/password", data).then((res) => res);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function registerAdmin(password) {
|
||||||
|
return api.get("/user/register/admin", { password }).then((res) => res);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getUserList() {
|
||||||
|
return api.get("/user", undefined).then((res) => res);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getPermission(account, pid) {
|
||||||
|
return api.get("/permission/list", { account, pid }).then((res) => res);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export function editPermission(data) {
|
||||||
|
return api.put("/permission", data).then((res) => res);
|
||||||
|
}
|
@@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { login } from "~/src/api/login";
|
import { login } from "@/api/login";
|
||||||
import router from "~/src/router";
|
import router from "~/src/router";
|
||||||
|
|
||||||
const isLoading = ref(false);
|
const isLoading = ref(false);
|
||||||
|
Reference in New Issue
Block a user