🎉 重构前端代码.

This commit is contained in:
lijiahangmax
2025-06-25 14:49:36 +08:00
parent 5183b7ccb4
commit 6149010bf4
49 changed files with 564 additions and 573 deletions

View File

@@ -14,7 +14,7 @@ export const isStandaloneMode = (() => (
// http base url
export const httpBaseUrl = (() => {
const configBase = import.meta.env.VITE_API_BASE_URL;
const configBase = import.meta.env.VITE_API_BASE_URL || '';
if (configBase.startsWith('http')) {
// 固定
return configBase;
@@ -28,7 +28,7 @@ export const httpBaseUrl = (() => {
// websocket base url
export const webSocketBaseUrl = (() => {
const configBase = import.meta.env.VITE_WS_BASE_URL;
const configBase = import.meta.env.VITE_WS_BASE_URL || '';
if (configBase.startsWith('ws')) {
// 固定
return configBase;

View File

@@ -1,6 +1,6 @@
// 添加事件监听器
import type { Ref } from 'vue';
// 添加事件监听器
export function addEventListen(
target: Window | HTMLElement,
event: string,

View File

@@ -27,7 +27,11 @@ export function readBlobText(blob: Blob) {
export function readFileText(e: File, encoding = 'UTF-8'): Promise<string> {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsText(e, encoding);
if (encoding === 'base64') {
reader.readAsDataURL(e);
} else {
reader.readAsText(e, encoding);
}
reader.onload = res => {
resolve(res.target?.result as string);
};

View File

@@ -167,6 +167,11 @@ export const sleep = (ms: number) => {
return new Promise(resolve => setTimeout(resolve, ms));
};
// ansi 着色
export const ansi = (code: number | string, msg: string, newLine: boolean = true) => {
return `[${code}m${msg}${newLine ? '\r\n' : ''}`;
};
// 添加后缀
export const addSuffix = (value: any, suffix: string) => {
if (value === undefined || value === '') {
@@ -206,7 +211,7 @@ export function getUUID() {
/**
* 获取会话id
*/
export const nextId = (len: number): string => {
export const nextId = (len: number = 10): string => {
return getUUID().replaceAll('-', '').substring(0, len);
};

View File

@@ -1,4 +1,4 @@
import { App, ComponentPublicInstance } from 'vue';
import type { App, ComponentPublicInstance } from 'vue';
import axios from 'axios';
export default function handleError(Vue: App, baseUrl: string) {