delEvnents
This commit is contained in:
parent
f0b6d900ac
commit
207913a253
|
@ -0,0 +1,59 @@
|
||||||
|
import {ref} from 'vue'
|
||||||
|
import { defineStore } from 'pinia';
|
||||||
|
|
||||||
|
// 定义回调类型
|
||||||
|
type TimerCallback = () => void;
|
||||||
|
|
||||||
|
export const useGlobalTimerStore = defineStore('globalTimer', () => {
|
||||||
|
const intervalId = ref<number | null>(null); // 定时器 ID
|
||||||
|
const refreshIntervalMs = ref(300000); // 默认刷新间隔(5 分钟)
|
||||||
|
const registeredCallbacks = ref<TimerCallback[]>([]); // 注册的回调函数列表
|
||||||
|
|
||||||
|
// 注册回调
|
||||||
|
const registerCallback = (callback: TimerCallback) => {
|
||||||
|
if (typeof callback === 'function' && !registeredCallbacks.value.includes(callback)) {
|
||||||
|
registeredCallbacks.value.push(callback);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 注销回调
|
||||||
|
const unregisterCallback = (callback: TimerCallback) => {
|
||||||
|
const index = registeredCallbacks.value.indexOf(callback);
|
||||||
|
if (index !== -1) {
|
||||||
|
registeredCallbacks.value.splice(index, 1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 启动定时器
|
||||||
|
const startTimer = () => {
|
||||||
|
if (!intervalId.value) {
|
||||||
|
intervalId.value = window.setInterval(() => {
|
||||||
|
registeredCallbacks.value.forEach((callback) => callback());
|
||||||
|
}, refreshIntervalMs.value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 停止定时器
|
||||||
|
const stopTimer = () => {
|
||||||
|
if (intervalId.value) {
|
||||||
|
clearInterval(intervalId.value);
|
||||||
|
intervalId.value = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 设置定时器间隔
|
||||||
|
const setRefreshInterval = (interval: number) => {
|
||||||
|
refreshIntervalMs.value = interval;
|
||||||
|
stopTimer();
|
||||||
|
startTimer();
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
refreshIntervalMs,
|
||||||
|
registerCallback,
|
||||||
|
unregisterCallback,
|
||||||
|
startTimer,
|
||||||
|
stopTimer,
|
||||||
|
setRefreshInterval,
|
||||||
|
};
|
||||||
|
});
|
|
@ -19,10 +19,7 @@ class BoxApi {
|
||||||
private readonly apiAllCameras: string = "/camera/cameras/get_all";
|
private readonly apiAllCameras: string = "/camera/cameras/get_all";
|
||||||
private readonly superCamera: string = "/camera/cameras";
|
private readonly superCamera: string = "/camera/cameras";
|
||||||
private readonly superRule: string = "/rules";
|
private readonly superRule: string = "/rules";
|
||||||
private readonly getEventByIdUrl: string = "/event/events/retrieves";
|
private readonly superEvents: string = "/event/events";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private readonly loginConfig: object = {
|
private readonly loginConfig: object = {
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -85,7 +82,7 @@ class BoxApi {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await this.axios.post(this.apiLogin, loginData, this.loginConfig)
|
const res = await this.axios.post(this.apiLogin, loginData, this.loginConfig)
|
||||||
console.log(res)
|
// console.log(res)
|
||||||
if (res.data.err.ec === 0) {
|
if (res.data.err.ec === 0) {
|
||||||
this.token = res.data.ret.token;
|
this.token = res.data.ret.token;
|
||||||
await this.updateCodemap(this.token);
|
await this.updateCodemap(this.token);
|
||||||
|
@ -253,7 +250,7 @@ class BoxApi {
|
||||||
public async updateCamera(token: string | null = null, cameraId: number, jsonData: CameraData): Promise<any> {
|
public async updateCamera(token: string | null = null, cameraId: number, jsonData: CameraData): Promise<any> {
|
||||||
const url = `${this.superCamera}/${cameraId}`;
|
const url = `${this.superCamera}/${cameraId}`;
|
||||||
// const { rules, ...cameraData } = jsonData;
|
// const { rules, ...cameraData } = jsonData;
|
||||||
console.log("接口接收的摄像设置>>>>>>>>>>>>>>", jsonData);
|
// console.log("接口接收的摄像设置>>>>>>>>>>>>>>", jsonData);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const newCamera = {
|
const newCamera = {
|
||||||
|
@ -277,7 +274,7 @@ class BoxApi {
|
||||||
// jsonData: CameraData
|
// jsonData: CameraData
|
||||||
// ): Promise<any> {
|
// ): Promise<any> {
|
||||||
// const url = `${this.superCamera}/${cameraId}`;
|
// const url = `${this.superCamera}/${cameraId}`;
|
||||||
|
|
||||||
// // 确保 mode 为小写
|
// // 确保 mode 为小写
|
||||||
// const cameraData = {
|
// const cameraData = {
|
||||||
// name: jsonData.name,
|
// name: jsonData.name,
|
||||||
|
@ -285,9 +282,9 @@ class BoxApi {
|
||||||
// ? jsonData.mode.toLowerCase()
|
// ? jsonData.mode.toLowerCase()
|
||||||
// : undefined, // 非法值转为 undefined
|
// : undefined, // 非法值转为 undefined
|
||||||
// };
|
// };
|
||||||
|
|
||||||
// console.log("接口接收的摄像头更新数据:", cameraData);
|
// console.log("接口接收的摄像头更新数据:", cameraData);
|
||||||
|
|
||||||
// try {
|
// try {
|
||||||
// const res = await this.axios.patch(url, cameraData, this._authHeader(token));
|
// const res = await this.axios.patch(url, cameraData, this._authHeader(token));
|
||||||
// if (res.data.err.ec === 0) {
|
// if (res.data.err.ec === 0) {
|
||||||
|
@ -300,7 +297,27 @@ class BoxApi {
|
||||||
// throw error;
|
// throw error;
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
public async delEvents(token: string | null = null, eventIds: number[]): Promise<{ id: number, success: boolean, message?: string }[]> {
|
||||||
|
const results: { id: number, success: boolean, message?: string }[] = [];
|
||||||
|
|
||||||
|
for (const eventId of eventIds) {
|
||||||
|
const url = `${this.superEvents}/${eventId}`;
|
||||||
|
try {
|
||||||
|
await this.axios.delete(url, this._authHeader(token));
|
||||||
|
results.push({ id: eventId, success: true });
|
||||||
|
} catch (error: any) {
|
||||||
|
results.push({
|
||||||
|
id: eventId,
|
||||||
|
success: false,
|
||||||
|
message: error.response?.data?.err?.dm || error.message
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public async updateRule(token: string | null = null, rules: RuleData[]): Promise<any[]> {
|
public async updateRule(token: string | null = null, rules: RuleData[]): Promise<any[]> {
|
||||||
const results: any[] = [];
|
const results: any[] = [];
|
||||||
|
@ -312,7 +329,7 @@ class BoxApi {
|
||||||
...rule,
|
...rule,
|
||||||
schedule: rule.schedule || {},
|
schedule: rule.schedule || {},
|
||||||
};
|
};
|
||||||
console.log("接口接收的规则设置>>>>>>>>>>>>>>", cleanedRule);
|
// console.log("接口接收的规则设置>>>>>>>>>>>>>>", cleanedRule);
|
||||||
const res = await this.axios.patch(url, cleanedRule, this._authHeader(token));
|
const res = await this.axios.patch(url, cleanedRule, this._authHeader(token));
|
||||||
if (res.data.err.ec === 0) {
|
if (res.data.err.ec === 0) {
|
||||||
results.push({ id: rule.id, success: true, data: res.data.ret });
|
results.push({ id: rule.id, success: true, data: res.data.ret });
|
||||||
|
@ -476,7 +493,7 @@ class BoxApi {
|
||||||
|
|
||||||
public async getEventById(id: number, token: string | null = null): Promise<any> {
|
public async getEventById(id: number, token: string | null = null): Promise<any> {
|
||||||
try {
|
try {
|
||||||
const url = `${this.getEventByIdUrl}`;
|
const url = `${this.superEvents}/retrieves`;
|
||||||
const params = { id };
|
const params = { id };
|
||||||
const res = await this.axios.get(url, {
|
const res = await this.axios.get(url, {
|
||||||
...this._authHeader(token),
|
...this._authHeader(token),
|
||||||
|
@ -493,6 +510,8 @@ class BoxApi {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// public async getOneEvent(token: string | null = null): Promise<any> {
|
// public async getOneEvent(token: string | null = null): Promise<any> {
|
||||||
// try {
|
// try {
|
||||||
// return await this.getEvents(1, 0, token);
|
// return await this.getEvents(1, 0, token);
|
||||||
|
|
Loading…
Reference in New Issue