xyyd-fatfox/src/utils/tool.ts

59 lines
1.7 KiB
TypeScript
Raw Normal View History

2024-11-12 18:32:36 +08:00
import useLayoutStore from "@/layout/useLayoutStore";
import request from "./request";
2024-10-23 14:57:27 +08:00
/**
*
* @param min
* @param max
* @returns
*/
export function randomNum(min: number, max: number) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
/**
* 0 n
* @param n
* @returns
*/
export function generateRandomString(n: number): string {
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
const length = Math.floor(Math.random() * (n + 1));
let result = '';
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * characters.length));
}
return result;
2024-11-04 14:45:25 +08:00
}
/**
* :
* @param seconds -
* @returns MM:SS
*/
export function formatSeconds(seconds: number): string {
// 计算分钟数
const minutes = Math.floor(seconds / 60);
// 计算剩余的秒数
const remainingSeconds = seconds % 60;
2024-11-12 18:32:36 +08:00
2024-11-04 14:45:25 +08:00
// 返回格式化后的字符串,确保分钟和秒数都是两位数
return `${String(minutes).padStart(2, '0')}:${String(remainingSeconds).padStart(2, '0')}`;
}
2024-11-12 18:32:36 +08:00
export function sendEvent(list: {
widget: string;
space?: string;
action: string;
key: string;
}[]) {
const store = useLayoutStore()
request('POST', '/api/app/statistics', {
data: list.map((item) => ({
widget: item.widget,
space: item.space || store.state.current === 0 ? 'TAB_GAME' : store.state.current === 1 ? 'TAB_WORK' : 'TAB_EAZY',
action: item.action,
key: item.key
}))
})
}