Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions demo/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const formState = reactive({
trim: false,
noDiffLineFeed: false,
filename: 'package.json',
hideHeader: false,
hideStat: false,
})

const oldString = ref(oldShortText.value)
Expand Down Expand Up @@ -104,6 +106,12 @@ function printEvent(e) {
<a-form-item label="不 diff 换行符(noDiffLineFeed)">
<a-switch v-model:checked="formState.noDiffLineFeed" />
</a-form-item>
<a-form-item label="隐藏首部(hide Header)">
<a-switch v-model:checked="formState.hideHeader" />
</a-form-item>
<a-form-item label="隐藏统计信息(hide Statistics)">
<a-switch v-model:checked="formState.hideStat" />
</a-form-item>
<a-form-item>
<a-button type="link" @click="resetText">
重置文本(reset text)
Expand All @@ -125,6 +133,8 @@ function printEvent(e) {
:trim="formState.trim"
:no-diff-line-feed="formState.noDiffLineFeed"
:filename="formState.filename"
:hide-header="formState.hideHeader"
:hide-stat="formState.hideStat"
@diff="printEvent"
/>
</template>
Expand Down
8 changes: 6 additions & 2 deletions src/CodeDiff.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ interface Props {
noDiffLineFeed?: boolean
maxHeight?: string
filename?: string
hideHeader: boolean
hideStat: boolean
}

interface DiffResult {
Expand All @@ -37,6 +39,8 @@ const props = withDefaults(defineProps<Props>(), {
noDiffLineFeed: false,
maxHeight: undefined,
filename: undefined,
hideHeader: false,
hideStat: false,
})

const emits = defineEmits<{
Expand Down Expand Up @@ -80,10 +84,10 @@ watch(() => props, () => {

<template>
<div class="code-diff-view" :style="{ maxHeight }">
<div class="file-header">
<div v-if="!hideHeader" class="file-header">
<div class="file-info">
<span class="filename">{{ filename }}</span>
<span class="diff-stat">
<span v-if="!hideStat" class="diff-stat">
<span class="diff-stat-added">+{{ diffChange.stat.additionsNum }} additions</span>
<span class="diff-stat-deleted" style="margin-left: 8px;">-{{ diffChange.stat.deletionsNum }} deletions</span>
</span>
Expand Down