2026-01-19 23:45:08 +08:00
|
|
|
|
<!--
|
2026-01-20 08:51:04 +08:00
|
|
|
|
RequestResponseFlow.vue - 简化版
|
|
|
|
|
|
目标:用简单的动画展示请求-响应流程
|
2026-01-19 23:45:08 +08:00
|
|
|
|
-->
|
|
|
|
|
|
<template>
|
2026-01-20 08:51:04 +08:00
|
|
|
|
<div class="demo">
|
|
|
|
|
|
<div class="title">🔄 一次 API 调用的流程</div>
|
|
|
|
|
|
<p class="subtitle">点一下按钮,看请求怎么飞过去再飞回来</p>
|
2026-01-19 23:45:08 +08:00
|
|
|
|
|
2026-01-20 08:51:04 +08:00
|
|
|
|
<div class="flow-container">
|
|
|
|
|
|
<div class="side you">
|
2026-01-19 23:45:08 +08:00
|
|
|
|
<div class="window">
|
2026-01-20 08:51:04 +08:00
|
|
|
|
<div class="window-header">👤 你这边</div>
|
|
|
|
|
|
<div class="window-body">
|
|
|
|
|
|
<div class="message">我想调用 API</div>
|
2026-01-19 23:45:08 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
2026-01-20 08:51:04 +08:00
|
|
|
|
<div class="middle">
|
|
|
|
|
|
<div class="arrow" :class="{ animating: isAnimating }">➔</div>
|
|
|
|
|
|
<button class="send-btn" :disabled="isAnimating" @click="send">
|
|
|
|
|
|
{{ isAnimating ? '发送中...' : '🚀 发送请求' }}
|
|
|
|
|
|
</button>
|
2026-01-19 23:45:08 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
|
2026-01-20 08:51:04 +08:00
|
|
|
|
<div class="side server">
|
2026-01-19 23:45:08 +08:00
|
|
|
|
<div class="window">
|
2026-01-20 08:51:04 +08:00
|
|
|
|
<div class="window-header">🖥️ 对方服务器</div>
|
|
|
|
|
|
<div class="window-body">
|
|
|
|
|
|
<div class="message">{{ serverMessage }}</div>
|
2026-01-19 23:45:08 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
2026-01-20 08:51:04 +08:00
|
|
|
|
<div class="result" v-if="result">
|
|
|
|
|
|
<div class="result-box" :class="result.type">
|
|
|
|
|
|
{{ result.text }}
|
2026-01-19 23:45:08 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup>
|
2026-01-20 08:51:04 +08:00
|
|
|
|
import { ref } from 'vue'
|
|
|
|
|
|
|
|
|
|
|
|
const isAnimating = ref(false)
|
|
|
|
|
|
const serverMessage = ref('等待请求...')
|
|
|
|
|
|
const result = ref(null)
|
|
|
|
|
|
|
|
|
|
|
|
function send() {
|
|
|
|
|
|
isAnimating.value = true
|
|
|
|
|
|
serverMessage.value = '收到请求,处理中...'
|
|
|
|
|
|
result.value = null
|
|
|
|
|
|
|
|
|
|
|
|
// 模拟请求流程
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
serverMessage.value = '处理完成!'
|
|
|
|
|
|
result.value = {
|
|
|
|
|
|
type: 'success',
|
|
|
|
|
|
text: '✅ 请求成功!服务器返回了数据'
|
|
|
|
|
|
}
|
|
|
|
|
|
isAnimating.value = false
|
|
|
|
|
|
}, 1500)
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
2026-01-20 08:51:04 +08:00
|
|
|
|
.demo {
|
2026-01-19 23:45:08 +08:00
|
|
|
|
border: 1px solid var(--vp-c-divider);
|
2026-01-20 08:51:04 +08:00
|
|
|
|
border-radius: 12px;
|
|
|
|
|
|
padding: 20px;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
background: var(--vp-c-bg-soft);
|
2026-01-20 08:51:04 +08:00
|
|
|
|
margin: 16px 0;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.title {
|
2026-01-20 08:51:04 +08:00
|
|
|
|
font-size: 18px;
|
|
|
|
|
|
font-weight: bold;
|
|
|
|
|
|
margin-bottom: 8px;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
color: var(--vp-c-text-1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-20 08:51:04 +08:00
|
|
|
|
.subtitle {
|
2026-01-19 23:45:08 +08:00
|
|
|
|
color: var(--vp-c-text-2);
|
2026-01-20 08:51:04 +08:00
|
|
|
|
margin-bottom: 20px;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-20 08:51:04 +08:00
|
|
|
|
.flow-container {
|
2026-01-19 23:45:08 +08:00
|
|
|
|
display: flex;
|
2026-01-20 08:51:04 +08:00
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
|
gap: 16px;
|
|
|
|
|
|
margin-bottom: 20px;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-20 08:51:04 +08:00
|
|
|
|
.side {
|
|
|
|
|
|
flex: 1;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.window {
|
|
|
|
|
|
background: var(--vp-c-bg);
|
2026-01-20 08:51:04 +08:00
|
|
|
|
border: 2px solid var(--vp-c-divider);
|
|
|
|
|
|
border-radius: 12px;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-20 08:51:04 +08:00
|
|
|
|
.window-header {
|
2026-01-19 23:45:08 +08:00
|
|
|
|
background: var(--vp-c-bg-soft);
|
|
|
|
|
|
padding: 12px;
|
2026-01-20 08:51:04 +08:00
|
|
|
|
font-weight: bold;
|
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
|
border-bottom: 1px solid var(--vp-c-divider);
|
|
|
|
|
|
text-align: center;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-20 08:51:04 +08:00
|
|
|
|
.window-body {
|
|
|
|
|
|
padding: 20px;
|
|
|
|
|
|
min-height: 80px;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: center;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-20 08:51:04 +08:00
|
|
|
|
.message {
|
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
|
color: var(--vp-c-text-1);
|
|
|
|
|
|
text-align: center;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-20 08:51:04 +08:00
|
|
|
|
.middle {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
gap: 12px;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-20 08:51:04 +08:00
|
|
|
|
.arrow {
|
|
|
|
|
|
font-size: 32px;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
color: var(--vp-c-brand-1);
|
2026-01-20 08:51:04 +08:00
|
|
|
|
transition: transform 0.3s;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-20 08:51:04 +08:00
|
|
|
|
.arrow.animating {
|
|
|
|
|
|
animation: pulse 0.5s ease-in-out infinite;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-20 08:51:04 +08:00
|
|
|
|
@keyframes pulse {
|
|
|
|
|
|
0%, 100% { transform: scale(1); }
|
|
|
|
|
|
50% { transform: scale(1.2); }
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-20 08:51:04 +08:00
|
|
|
|
.send-btn {
|
|
|
|
|
|
background: var(--vp-c-brand-1);
|
|
|
|
|
|
color: white;
|
|
|
|
|
|
border: none;
|
|
|
|
|
|
padding: 10px 20px;
|
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
|
font-weight: bold;
|
|
|
|
|
|
border-radius: 8px;
|
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
transition: all 0.2s;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-20 08:51:04 +08:00
|
|
|
|
.send-btn:hover:not(:disabled) {
|
|
|
|
|
|
opacity: 0.9;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-20 08:51:04 +08:00
|
|
|
|
.send-btn:disabled {
|
|
|
|
|
|
opacity: 0.6;
|
|
|
|
|
|
cursor: not-allowed;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-20 08:51:04 +08:00
|
|
|
|
.result {
|
|
|
|
|
|
margin-top: 16px;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-20 08:51:04 +08:00
|
|
|
|
.result-box {
|
|
|
|
|
|
padding: 12px 16px;
|
|
|
|
|
|
border-radius: 8px;
|
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
|
font-weight: 500;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-20 08:51:04 +08:00
|
|
|
|
.result-box.success {
|
|
|
|
|
|
background: #dcfce7;
|
|
|
|
|
|
color: #166534;
|
|
|
|
|
|
border: 1px solid #86efac;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-20 08:51:04 +08:00
|
|
|
|
.result-box.error {
|
|
|
|
|
|
background: #fee2e2;
|
|
|
|
|
|
color: #991b1b;
|
|
|
|
|
|
border: 1px solid #fca5a5;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@media (max-width: 720px) {
|
2026-01-20 08:51:04 +08:00
|
|
|
|
.flow-container {
|
|
|
|
|
|
flex-direction: column;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
2026-01-20 08:51:04 +08:00
|
|
|
|
|
|
|
|
|
|
.middle {
|
|
|
|
|
|
flex-direction: row;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|