style: 💄 格式化代码

This commit is contained in:
log1997
2026-01-04 11:21:49 +08:00
parent 9e25b02d9c
commit a9462fa119
110 changed files with 2146 additions and 2149 deletions

View File

@@ -1,3 +1,3 @@
export function getToken() {
return window.localStorage.getItem('userToken')
return window.localStorage.getItem('userToken')
}

View File

@@ -42,32 +42,32 @@ export function rgba(color: string, opacity: number) {
export function rgbToHex(color: string) {
// 去掉字符串中的空格
color = color.replace(/\s+/g, '');
color = color.replace(/\s+/g, '')
if (isHex(color)) {
return color
}
// 匹配rgba或rgb格式的字符串
const rgbaMatch = color.match(/^rgba?\((\d+),(\d+),(\d+),?(\d*\.?\d+)?\)$/i);
const rgbaMatch = color.match(/^rgba?\((\d+),(\d+),(\d+),?(\d+(?:\.\d+)?|\.\d+)?\)$/i)
if (!rgbaMatch) {
throw new Error('Invalid color format');
throw new Error('Invalid color format')
}
const r = parseInt(rgbaMatch[1], 10);
const g = parseInt(rgbaMatch[2], 10);
const b = parseInt(rgbaMatch[3], 10);
const a = rgbaMatch[4] !== undefined ? parseFloat(rgbaMatch[4]) : undefined;
const r = Number.parseInt(rgbaMatch[1], 10)
const g = Number.parseInt(rgbaMatch[2], 10)
const b = Number.parseInt(rgbaMatch[3], 10)
const a = rgbaMatch[4] !== undefined ? Number.parseFloat(rgbaMatch[4]) : undefined
// 将RGB值转换为十六进制
let hex = "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1).toUpperCase();
let hex = `#${((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1).toUpperCase()}`
// 如果提供了alpha值则将其转换为十六进制并附加到结果中
if (a !== undefined) {
let alphaHex = Math.round(a * 255).toString(16).toUpperCase();
let alphaHex = Math.round(a * 255).toString(16).toUpperCase()
if (alphaHex.length === 1) {
alphaHex = "0" + alphaHex; // 确保alpha值是两位数
alphaHex = `0${alphaHex}` // 确保alpha值是两位数
}
hex += alphaHex;
hex += alphaHex
}
return hex;
}
return hex
}

View File

@@ -20,19 +20,19 @@ export function readFileData(file: File): Promise<{ data: string, fileName: stri
export function readFileDataAsBlob(file: File): Promise<{ data: Blob, fileName: string }> {
return new Promise((resolve, reject) => {
const reader = new FileReader();
const reader = new FileReader()
reader.onload = () => {
// 直接使用原始文件作为 Blob
resolve({ data: file, fileName: file.name });
};
resolve({ data: file, fileName: file.name })
}
reader.onerror = () => {
reject(new Error('文件读取失败'));
};
reject(new Error('文件读取失败'))
}
reader.readAsArrayBuffer(file);
});
reader.readAsArrayBuffer(file)
})
}
export async function readLocalFileAsArraybuffer(path: string): Promise<ArrayBuffer> {
@@ -53,4 +53,4 @@ export async function readFileAsJsonData(file: File | Blob): Promise<any> {
export function getBlobObjectUrl(blob: Blob): string {
return URL.createObjectURL(blob)
}
}

View File

@@ -1,3 +1,3 @@
/**
* @description 用于将平铺的数组组合到树形数组中
*/
*/

View File

@@ -1,10 +1,10 @@
// 提取有哪些字段
export function extractFields(data: any) {
const item = data[0]
// 排除id x y其他都加入数组
const keys = Object.keys(item).filter(key => key !== 'id' && key !== 'x' && key !== 'y')
if (keys.length > 0) {
const item = data[0]
// 排除id x y其他都加入数组
const keys = Object.keys(item).filter(key => key !== 'id' && key !== 'x' && key !== 'y')
if (keys.length > 0) {
// 返回数组key value
return keys.map(key => ({ label: key, value: true }))
}
return keys.map(key => ({ label: key, value: true }))
}
}