lint:fix all

This commit is contained in:
2025-07-29 00:32:57 +08:00
parent 7d2f57df97
commit 1745a54eb6
34 changed files with 820 additions and 606 deletions

View File

@@ -1,9 +1,16 @@
<template>
<UPage class="mt-4 mb-4 bg-white dark:bg-gray-900 rounded-xl border border-gray-300 dark:border-gray-700">
<div v-if="title" class="flex items-center font-mono text-base m-3 text-gray-700 dark:text-gray-300 rounded-xl ">
<Icon v-if="icon" :name="icon" class="mr-2" size="20" />
<div
v-if="title"
class="flex items-center font-mono text-base m-3 text-gray-700 dark:text-gray-300 rounded-xl "
>
<Icon
v-if="icon"
:name="icon"
class="mr-2"
size="20"
/>
<span>{{ title }}</span>
</div>
@@ -23,7 +30,7 @@
/>
</div>
</div>
<!-- 服务端渲染时的占位符 -->
<template #fallback>
<div class="space-y-1">
@@ -33,8 +40,11 @@
class="file-tree-item"
>
<div class="flex items-center py-1 px-2">
<div class="flex items-center" :style="{ marginLeft: '0px' }">
<Icon
<div
class="flex items-center"
:style="{ marginLeft: '0px' }"
>
<Icon
v-if="showIcon"
:name="item.icon || 'lucide-file'"
class="mr-2 text-gray-500 w-4 h-4"
@@ -45,7 +55,7 @@
'text-yellow-500': item.icon?.includes('json')
}"
/>
<span
<span
class="text-sm font-mono"
:class="{
'font-semibold': item.isFolder,
@@ -61,38 +71,38 @@
</template>
</ClientOnly>
</div>
</UPage>
</UPage>
</template>
<script setup lang="ts">
type InputTreeItem = string | {
[key: string]: InputTreeItem[];
};
[key: string]: InputTreeItem[]
}
type FileTreeItemDiff = 'none' | 'addition' | 'deletion';
type FileTreeItemDiff = 'none' | 'addition' | 'deletion'
interface FileTreeItem {
title: string;
icon?: string;
children?: FileTreeItem[];
highlighted?: boolean;
diff?: FileTreeItemDiff;
isFolder?: boolean;
title: string
icon?: string
children?: FileTreeItem[]
highlighted?: boolean
diff?: FileTreeItemDiff
isFolder?: boolean
}
const {
tree,
autoSlash = true,
showArrow = false,
showIcon = true,
showIcon = true
} = defineProps<{
title?: string;
icon?: string;
autoSlash?: boolean;
showArrow?: boolean;
showIcon?: boolean;
tree: InputTreeItem[];
}>();
title?: string
icon?: string
autoSlash?: boolean
showArrow?: boolean
showIcon?: boolean
tree: InputTreeItem[]
}>()
// 默认图标映射
const defaultIcons = {
@@ -103,38 +113,38 @@ const defaultIcons = {
json: 'simple-icons-json',
folder: 'lucide-folder',
file: 'lucide-file'
};
}
function getIcon(filename: string, type: 'folder' | 'file'): string {
if (filename === '...') return 'lucide-more-horizontal';
if (filename.endsWith('/')) return defaultIcons.folder;
if (filename === '...') return 'lucide-more-horizontal'
if (filename.endsWith('/')) return defaultIcons.folder
const parts = filename.split('.')
const extension = parts.length > 1 ? parts[parts.length - 1]?.toLowerCase() || '' : ''
const parts = filename.split('.');
const extension = parts.length > 1 ? parts[parts.length - 1]?.toLowerCase() || '' : '';
// 根据扩展名返回对应图标
switch (extension) {
case 'vue': return defaultIcons.vue;
case 'ts': return defaultIcons.ts;
case 'js': return defaultIcons.js;
case 'md': return defaultIcons.md;
case 'json': return defaultIcons.json;
default: return type === 'file' ? defaultIcons.file : defaultIcons.folder;
case 'vue': return defaultIcons.vue
case 'ts': return defaultIcons.ts
case 'js': return defaultIcons.js
case 'md': return defaultIcons.md
case 'json': return defaultIcons.json
default: return type === 'file' ? defaultIcons.file : defaultIcons.folder
}
}
function getItem(key: string, type: 'folder' | 'file', children?: InputTreeItem[]): FileTreeItem {
let title = key;
let highlighted = false;
let title = key
let highlighted = false
if (title.startsWith('^') && title.endsWith('^')) {
title = title.substring(1, title.length - 1);
highlighted = true;
title = title.substring(1, title.length - 1)
highlighted = true
}
let diff: FileTreeItemDiff = 'none';
if (title.startsWith('+')) diff = 'addition';
else if (title.startsWith('-')) diff = 'deletion';
let diff: FileTreeItemDiff = 'none'
if (title.startsWith('+')) diff = 'addition'
else if (title.startsWith('-')) diff = 'deletion'
if (type === 'file') {
return {
@@ -143,7 +153,7 @@ function getItem(key: string, type: 'folder' | 'file', children?: InputTreeItem[
highlighted,
diff,
isFolder: false
};
}
} else {
return {
title: `${title}${autoSlash ? '/' : ''}`,
@@ -152,35 +162,35 @@ function getItem(key: string, type: 'folder' | 'file', children?: InputTreeItem[
highlighted,
diff,
isFolder: true
};
}
}
}
function getTree(tree: InputTreeItem[]): FileTreeItem[] {
const res: FileTreeItem[] = [];
const res: FileTreeItem[] = []
for (const item of tree) {
if (typeof item === 'string') {
res.push(getItem(item, 'file'));
res.push(getItem(item, 'file'))
} else if (typeof item === 'object' && item !== null) {
for (const key of Object.keys(item)) {
const children = (item as Record<string, InputTreeItem[]>)[key];
const children = (item as Record<string, InputTreeItem[]>)[key]
if (children) {
res.push(getItem(key, 'folder', children));
res.push(getItem(key, 'folder', children))
}
}
}
}
return res;
return res
}
const parsedTree = computed(() => {
return getTree(tree);
});
return getTree(tree)
})
// 使用 provide/inject 来管理展开状态
const expandedState = ref(new Set<string>());
const expandedState = ref(new Set<string>())
provide('expandedState', expandedState);
provide('expandedState', expandedState)
</script>