AI实验室前端
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import { pyRequestClient } from '#/api/request';
|
||||
/**
|
||||
* 获取所有年会互换数据
|
||||
*/
|
||||
export async function getExchangeListApi() {
|
||||
return pyRequestClient.get<any>('/am/ExGetList');
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置所有年会互换状态
|
||||
*/
|
||||
export async function resetAllExchangeStatusApi() {
|
||||
return pyRequestClient.get<any>('/am/ExReset');
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置指定用户的年会互换状态
|
||||
* @param targetUserId 指定用户的 UUID
|
||||
*/
|
||||
export async function resetUserStatusApi(targetUserId: string) {
|
||||
return pyRequestClient.put<any>('/am/ExResetTargetStatus', null,{
|
||||
params: { target_user_id: targetUserId },
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './exchange';
|
||||
export * from './lottery';
|
||||
@@ -0,0 +1,85 @@
|
||||
import { pyRequestClient } from '#/api/request';
|
||||
|
||||
/**
|
||||
* 上传
|
||||
*/
|
||||
export async function getLotteryUploadUrl(filename: string) {
|
||||
return pyRequestClient.get('/am/Lottery/getUploadUrl', {
|
||||
params: { filename },
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 获取年会礼品列表
|
||||
*/
|
||||
export async function getLotteryList() {
|
||||
return pyRequestClient.get('/am/Lottery/List');
|
||||
}
|
||||
/**
|
||||
* 新增礼品(内部自动类型转换)
|
||||
*/
|
||||
export async function addLottery(
|
||||
oss: string,
|
||||
data: {
|
||||
is_opened: boolean | number;
|
||||
name: string;
|
||||
oss?: string;
|
||||
remark?: string;
|
||||
sort: number | string;
|
||||
},
|
||||
) {
|
||||
delete data.oss_url;
|
||||
// 自动类型转换
|
||||
const payload = {
|
||||
oss,
|
||||
...data,
|
||||
is_opened: Boolean(data.is_opened), // 0/1/true/false 都能转换成布尔
|
||||
sort: Number(data.sort), // "1" / 1 都能转成数字
|
||||
};
|
||||
|
||||
return pyRequestClient.post('/am/Lottery/Add', payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改礼品(内部自动类型转换)
|
||||
*/
|
||||
export async function updateLottery(
|
||||
id: string,
|
||||
oss: string,
|
||||
data: {
|
||||
is_opened?: boolean | number;
|
||||
name?: string;
|
||||
oss?: string;
|
||||
remark?: string;
|
||||
sort?: number | string;
|
||||
},
|
||||
) {
|
||||
delete data.oss_url;
|
||||
const payload: any = { id, oss, ...data };
|
||||
|
||||
// 仅对存在的字段做转换
|
||||
if ('is_opened' in payload) payload.is_opened = Boolean(payload.is_opened);
|
||||
if ('sort' in payload) payload.sort = Number(payload.sort);
|
||||
|
||||
return pyRequestClient.put('/am/Lottery/Update', payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除礼品
|
||||
*/
|
||||
export async function deleteLottery(id: string) {
|
||||
return pyRequestClient.delete('/am/Lottery/Delete', {
|
||||
params: { id },
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 标记某个奖品为已开启
|
||||
*/
|
||||
export async function openLotteryItem(id: string) {
|
||||
return pyRequestClient.patch(`/am/Lottery/open/${id}`);
|
||||
}
|
||||
/**
|
||||
* 重置所有奖品为未开启
|
||||
*/
|
||||
export async function resetAllLottery() {
|
||||
return pyRequestClient.patch('/am/Lottery/resetAll');
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
export * from './annual_meeting';
|
||||
export * from './core';
|
||||
export * from './cv';
|
||||
export * from './iot';
|
||||
export * from './llm';
|
||||
export * from './manager';
|
||||
export * from './sentinel';
|
||||
export * from './ws';
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
export * from './monitor';
|
||||
export * from './record';
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import { pyRequestClient } from '#/api/request';
|
||||
|
||||
/**
|
||||
* 获取记录列表数据
|
||||
*/
|
||||
export async function getSentinelMonitorPromotionalList() {
|
||||
return pyRequestClient.get<Array<SentinelApi.Record>>(
|
||||
'/iot/sentinel/monitor/promotional/list',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取记录列表数据
|
||||
*/
|
||||
export async function getSentinelMonitorList() {
|
||||
return pyRequestClient.get<Array<SentinelApi.Record>>(
|
||||
'/iot/sentinel/monitor/list',
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
import { useAccessStore } from '@vben/stores';
|
||||
|
||||
import { getActivePinia } from 'pinia';
|
||||
|
||||
function getAccessStore() {
|
||||
const pinia = getActivePinia();
|
||||
if (!pinia) return null;
|
||||
return useAccessStore(pinia);
|
||||
}
|
||||
|
||||
type WsOptions = {
|
||||
maxReconnect?: number;
|
||||
onClose?: () => void;
|
||||
onError?: () => void;
|
||||
onMessage?: (data: any) => void;
|
||||
onOpen?: () => void;
|
||||
path: (() => string) | string;
|
||||
reconnectInterval?: number;
|
||||
};
|
||||
const BASE_WS_URL = 'wss://ai.ronsunny.cn:8090/ai/';
|
||||
// const BASE_WS_URL = 'ws://127.0.0.1:13011/';
|
||||
export function createAutoReconnectWs(options: WsOptions) {
|
||||
let ws: null | WebSocket = null;
|
||||
let reconnectTimer: null | number = null;
|
||||
let reconnectCount = 0;
|
||||
|
||||
const {
|
||||
path,
|
||||
maxReconnect = 5,
|
||||
reconnectInterval = 2000,
|
||||
onMessage,
|
||||
onOpen,
|
||||
onClose,
|
||||
onError,
|
||||
} = options;
|
||||
|
||||
function getUrl() {
|
||||
const p = typeof path === 'function' ? path() : path;
|
||||
const token = getAccessStore().accessToken;
|
||||
return `${BASE_WS_URL}${p}?token=${token}`;
|
||||
}
|
||||
|
||||
function connect() {
|
||||
if (ws) {
|
||||
ws.close();
|
||||
ws = null;
|
||||
}
|
||||
|
||||
ws = new WebSocket(getUrl());
|
||||
|
||||
ws.addEventListener('open', () => {
|
||||
reconnectCount = 0;
|
||||
onOpen?.();
|
||||
});
|
||||
|
||||
ws.addEventListener('message', (e) => {
|
||||
try {
|
||||
const data = JSON.parse(e.data);
|
||||
onMessage?.(data);
|
||||
} catch {
|
||||
console.warn('ws message parse error');
|
||||
}
|
||||
});
|
||||
|
||||
ws.addEventListener('error', () => {
|
||||
onError?.();
|
||||
tryReconnect();
|
||||
});
|
||||
|
||||
ws.addEventListener('close', () => {
|
||||
onClose?.();
|
||||
tryReconnect();
|
||||
});
|
||||
}
|
||||
|
||||
function tryReconnect() {
|
||||
if (reconnectTimer) return;
|
||||
if (reconnectCount >= maxReconnect) return;
|
||||
|
||||
reconnectCount++;
|
||||
|
||||
reconnectTimer = window.setTimeout(() => {
|
||||
reconnectTimer = null;
|
||||
connect();
|
||||
}, reconnectInterval * reconnectCount);
|
||||
}
|
||||
|
||||
function close() {
|
||||
reconnectTimer && clearTimeout(reconnectTimer);
|
||||
reconnectTimer = null;
|
||||
reconnectCount = 0;
|
||||
ws?.close();
|
||||
ws = null;
|
||||
}
|
||||
|
||||
return { connect, close };
|
||||
}
|
||||
Reference in New Issue
Block a user