优化: 项目文件树/依赖图组件 + 灵感对抗校验 + 小程序脚本 + 模块管理
This commit is contained in:
@@ -39,28 +39,28 @@
|
||||
<div class="preview-placeholder-text">{{ $t('fileExplorer.selectFileHint') }}</div>
|
||||
</div>
|
||||
|
||||
<!-- 加载中 -->
|
||||
<div v-else-if="loading" class="preview-loading">
|
||||
<!-- 加载中(外部 diff 存在时让位于 diff 视图,历史提交的文件可能不在当前工作树) -->
|
||||
<div v-else-if="loading && !isExternalDiff" class="preview-loading">
|
||||
<span class="spinner"></span>
|
||||
{{ $t('fileExplorer.loadingFile') }}
|
||||
</div>
|
||||
|
||||
<!-- 错误 -->
|
||||
<div v-else-if="error" class="preview-error">⚠ {{ error }}</div>
|
||||
<!-- 错误(外部 diff 存在时同样让位:历史文件当前树不存在不应遮住 diff) -->
|
||||
<div v-else-if="error && !isExternalDiff" class="preview-error">⚠ {{ error }}</div>
|
||||
|
||||
<!-- 二进制 -->
|
||||
<div v-else-if="isBinary" class="preview-binary">
|
||||
<!-- 二进制(外部 diff 存在时让位) -->
|
||||
<div v-else-if="isBinary && !isExternalDiff" class="preview-binary">
|
||||
<span class="binary-icon">📄</span>
|
||||
<p>{{ $t('fileExplorer.binaryNotSupported') }}</p>
|
||||
</div>
|
||||
|
||||
<!-- 图片 -->
|
||||
<div v-else-if="isImage" class="preview-image">
|
||||
<!-- 图片(外部 diff 存在时让位) -->
|
||||
<div v-else-if="isImage && !isExternalDiff" class="preview-image">
|
||||
<img :src="imageUrl ?? ''" :alt="filePath ?? ''" />
|
||||
</div>
|
||||
|
||||
<!-- Diff 视图(切到 diff 模式时显示;置于 Markdown 之前,使 .md 文件也支持 Diff) -->
|
||||
<div v-else-if="showDiff && diffContent" class="preview-diff">
|
||||
<!-- Diff 视图(外部注入的 diff 优先展示;置于 Markdown 之前,使 .md 文件也支持 Diff) -->
|
||||
<div v-else-if="showDiff && diffViewContent" class="preview-diff">
|
||||
<div v-for="(ln, idx) in diffLines" :key="idx" class="diff-line" :class="'diff-' + ln.type">
|
||||
<span class="diff-line-num">{{ ln.oldNum || '' }}</span>
|
||||
<span class="diff-line-num">{{ ln.newNum || '' }}</span>
|
||||
@@ -98,6 +98,9 @@ const props = defineProps<{
|
||||
filePath: string | null
|
||||
moduleRootPath: string
|
||||
gitStatus?: string
|
||||
/** 外部注入的 diff(如 GitChanges 变更/提交历史点文件得到的该文件 diff,含历史提交的 diff)。
|
||||
* 非空时优先渲染此 diff(宽预览区),不发起重复的 git diff 请求。 */
|
||||
externalDiff?: string
|
||||
}>()
|
||||
|
||||
const { } = useMarkdown()
|
||||
@@ -127,6 +130,17 @@ const showDiff = ref(false)
|
||||
const diffContent = ref('')
|
||||
const diffLoading = ref(false)
|
||||
|
||||
/** 是否存在外部注入的 diff(非空即视为外部 diff 模式:默认展示 diff,且 diff 优先级最高)。 */
|
||||
const isExternalDiff = computed(() => !!props.externalDiff && props.externalDiff.trim().length > 0)
|
||||
|
||||
/** 实际展示的 diff 内容:外部注入优先,否则用本组件拉取的 git diff。 */
|
||||
const diffViewContent = computed(() => (isExternalDiff.value ? props.externalDiff! : diffContent.value))
|
||||
|
||||
/** 外部 diff 注入时默认切到 diff 视图(点文件即看变化,无需再点 📝);清空则回到内容视图。 */
|
||||
watch(() => props.externalDiff, (val) => {
|
||||
showDiff.value = !!(val && val.trim().length > 0)
|
||||
})
|
||||
|
||||
/** 请求序号守卫:loadFile/loadDiff 各自单调递增,await 返回后校验仍是"最新 seq"才写状态,
|
||||
* 否则丢弃(快速切文件/切视图时旧响应晚到不覆盖新内容)。
|
||||
* 注:loadFile 与 loadDiff 分用两个计数器 —— 若共用一个,loadDiff 自增会让在途的 loadFile
|
||||
@@ -152,11 +166,11 @@ function parseHunkHeader(line: string): { oldStart: number; newStart: number } {
|
||||
}
|
||||
|
||||
const diffLines = computed<DiffLine[]>(() => {
|
||||
if (!diffContent.value) return []
|
||||
if (!diffViewContent.value) return []
|
||||
const lines: DiffLine[] = []
|
||||
let oldNum = 0
|
||||
let newNum = 0
|
||||
for (const raw of diffContent.value.split('\n')) {
|
||||
for (const raw of diffViewContent.value.split('\n')) {
|
||||
if (raw.startsWith('@@')) {
|
||||
const h = parseHunkHeader(raw)
|
||||
oldNum = h.oldStart
|
||||
@@ -180,7 +194,8 @@ const diffLines = computed<DiffLine[]>(() => {
|
||||
|
||||
function toggleDiff() {
|
||||
showDiff.value = !showDiff.value
|
||||
if (showDiff.value && !diffContent.value) {
|
||||
// 外部 diff 已由调用方提供,无需再发 git diff;仅内部模式在首次切到 diff 时才拉取
|
||||
if (showDiff.value && !diffContent.value && !isExternalDiff.value) {
|
||||
loadDiff()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user