Files
test-repo/docs/.vitepress/theme/components/appendix/git-intro/GitRemoteDemo.vue
T
sanbuphy d35211071a style: update border-radius and padding values across components
- standardize border-radius from 8px to 6px for consistent styling
- adjust padding values from 1rem to 0.75rem for better visual hierarchy
- remove redundant overflow-y properties for cleaner code
2026-02-14 20:23:34 +08:00

222 lines
4.8 KiB
Vue
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<div class="remote-demo">
<div class="panel">
<div class="repos">
<div class="repo">
<div class="header">💻 本地</div>
<div class="meta">
<span class="badge">main</span>
<span class="hint"> Ahead {{ ahead }} / Behind {{ behind }} </span>
</div>
<div class="commits">
<div v-for="c in local" :key="c" class="commit-dot">
<span class="dot local"></span>
<span class="hash">{{ c.substring(0, 6) }}</span>
</div>
<div v-if="local.length === 0" class="empty"></div>
</div>
</div>
<div class="sync"></div>
<div class="repo">
<div class="header"> 远程</div>
<div class="meta">
<span class="badge">origin/main</span>
<span class="hint">模拟队友提交在这里发生</span>
</div>
<div class="commits">
<div v-for="c in remote" :key="c" class="commit-dot">
<span class="dot remote"></span>
<span class="hash">{{ c.substring(0, 6) }}</span>
</div>
<div v-if="remote.length === 0" class="empty"></div>
</div>
</div>
</div>
<div class="controls">
<button @click="localCommit" class="btn">本地提交</button>
<button @click="remoteCommit" class="btn">远程新增提交</button>
<button
@click="push"
:disabled="local.length <= remote.length"
class="btn"
>
git push
</button>
<button @click="pull" :disabled="behind === 0" class="btn">
git pull
</button>
<button @click="reset" class="btn secondary">重置</button>
</div>
</div>
<div class="info-box">
<p>
<strong>💡 远程协作:</strong> 你本地落后Behind
pull你本地领先Ahead push
</p>
</div>
</div>
</template>
<script setup>
import { ref, computed } from 'vue'
const local = ref([])
const remote = ref([])
const localCommit = () => {
local.value.push(Math.random().toString(16).substr(2, 7))
}
const remoteCommit = () => {
remote.value.push(Math.random().toString(16).substr(2, 7))
}
const push = () => {
remote.value = [...local.value]
}
const pull = () => {
local.value = [...remote.value]
}
const ahead = computed(() =>
Math.max(0, local.value.length - remote.value.length)
)
const behind = computed(() =>
Math.max(0, remote.value.length - local.value.length)
)
const reset = () => {
local.value = []
remote.value = []
}
</script>
<style scoped>
.remote-demo {
border: 1px solid var(--vp-c-divider);
border-radius: 6px;
background-color: var(--vp-c-bg-soft);
padding: 1.5rem;
margin: 0.5rem 0;
}
.repos {
display: grid;
grid-template-columns: 1fr auto 1fr;
gap: 1rem;
align-items: stretch;
margin-bottom: 1rem;
}
.repo {
border: 1px solid var(--vp-c-divider);
border-radius: 6px;
padding: 0.75rem;
background: var(--vp-c-bg);
}
.header {
font-weight: 600;
margin-bottom: 0.5rem;
}
.meta {
display: flex;
align-items: center;
justify-content: space-between;
gap: 0.75rem;
margin-bottom: 0.75rem;
}
.badge {
padding: 0.2rem 0.6rem;
border-radius: 999px;
border: 1px solid var(--vp-c-divider);
background: var(--vp-c-bg-alt);
color: var(--vp-c-text-2);
font-size: 0.75rem;
font-family: var(--vp-font-family-mono);
}
.hint {
color: var(--vp-c-text-3);
font-size: 0.75rem;
}
.commits {
min-height: 80px;
}
.commit-dot {
display: flex;
align-items: center;
gap: 0.5rem;
margin-bottom: 0.5rem;
}
.dot {
width: 10px;
height: 10px;
border-radius: 50%;
}
.dot.local {
background: var(--vp-c-brand);
}
.dot.remote {
background: rgba(var(--vp-c-brand-rgb), 0.5);
}
.hash {
font-family: var(--vp-font-family-mono);
font-size: 0.875rem;
color: var(--vp-c-text-2);
}
.sync {
font-size: 2rem;
text-align: center;
}
.empty {
color: var(--vp-c-text-3);
text-align: center;
padding: 0.75rem;
}
.controls {
display: flex;
gap: 0.5rem;
flex-wrap: wrap;
}
.btn {
padding: 0.5rem 1rem;
border: 1px solid var(--vp-c-brand);
background: var(--vp-c-bg);
color: var(--vp-c-brand);
border-radius: 6px;
cursor: pointer;
}
.btn:hover:not(:disabled) {
background: var(--vp-c-brand);
color: var(--vp-c-bg);
}
.btn:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.btn.secondary {
border-color: var(--vp-c-divider);
}
.info-box {
padding: 0.75rem;
background: var(--vp-c-bg);
border-left: 4px solid var(--vp-c-brand);
border-radius: 4px;
margin-top: 1rem;
}
.info-box p {
margin: 0;
color: var(--vp-c-text-1);
}
@media (max-width: 768px) {
.repos {
grid-template-columns: 1fr;
}
.sync {
transform: rotate(90deg);
}
}
</style>