feat: complete English translation of AI IDE introduction including Appendix 2

This commit is contained in:
sanbuphy
2026-02-26 12:17:40 +08:00
parent 7cd26c59d8
commit b2e3ffa1fd
23 changed files with 3762 additions and 2087 deletions
@@ -0,0 +1,275 @@
<script setup>
import { ref, computed } from 'vue'
const activeOp = ref('groupBy')
const rawOrders = [
{ userId: 'U001', orderId: 'ORD001', amount: 100, date: '2024-01-01' },
{ userId: 'U001', orderId: 'ORD002', amount: 200, date: '2024-01-02' },
{ userId: 'U002', orderId: 'ORD003', amount: 150, date: '2024-01-01' },
{ userId: 'U002', orderId: 'ORD004', amount: 300, date: '2024-01-03' },
{ userId: 'U003', orderId: 'ORD005', amount: 250, date: '2024-01-02' },
{ userId: 'U001', orderId: 'ORD006', amount: 180, date: '2024-01-04' }
]
const ops = {
groupBy: {
name: '按用户分组',
sql: `SELECT user_id, COUNT(*) as order_count, SUM(amount) as total
FROM orders GROUP BY user_id;`,
columns: ['用户 ID', '订单数', '总金额'],
data: [
{ '用户 ID': 'U001', 订单数: 3, 总金额: 480 },
{ '用户 ID': 'U002', 订单数: 2, 总金额: 450 },
{ '用户 ID': 'U003', 订单数: 1, 总金额: 250 }
]
},
sum: {
name: '总销售额',
sql: `SELECT SUM(amount) as total_sales FROM orders;`,
columns: ['总销售额'],
data: [{ 总销售额: 1180 }]
},
avg: {
name: '平均订单额',
sql: `SELECT AVG(amount) as avg_amount FROM orders;`,
columns: ['平均订单额'],
data: [{ 平均订单额: 196.67 }]
},
max: {
name: '最大订单额',
sql: `SELECT MAX(amount) as max_amount FROM orders;`,
columns: ['最大订单额'],
data: [{ 最大订单额: 300 }]
}
}
const opKeys = Object.keys(ops)
const currentOp = computed(() => ops[activeOp.value])
</script>
<template>
<div class="agg-demo">
<div class="demo-header">
<span class="icon">🧮</span>
<span class="title">数据聚合演示</span>
<span class="subtitle">拆分-计算-组合</span>
</div>
<div class="intro-text">
"所有用户平均转化率 5%" 往往毫无意义通过
<span class="hl">分组聚合</span>
把数据"切开"才能发现不同用户之间的真实差异点击下方操作观察同一份原始数据如何产生不同的
<span class="hl">聚合视角</span>
</div>
<!-- 原始数据表 -->
<div class="section">
<div class="section-label">原始订单数据</div>
<div class="table-wrap">
<table class="data-table">
<thead>
<tr>
<th>用户 ID</th>
<th>订单号</th>
<th>金额</th>
<th>日期</th>
</tr>
</thead>
<tbody>
<tr v-for="r in rawOrders" :key="r.orderId">
<td>{{ r.userId }}</td>
<td>{{ r.orderId }}</td>
<td>{{ r.amount }}</td>
<td>{{ r.date }}</td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- 操作按钮 -->
<div class="ops-row">
<button
v-for="k in opKeys"
:key="k"
:class="['op-btn', { active: activeOp === k }]"
@click="activeOp = k"
>
{{ ops[k].name }}
</button>
</div>
<!-- 聚合结果 -->
<div class="section result-section">
<div class="section-label">{{ currentOp.name }} 结果</div>
<div class="table-wrap">
<table class="data-table">
<thead>
<tr>
<th v-for="col in currentOp.columns" :key="col">{{ col }}</th>
</tr>
</thead>
<tbody>
<tr v-for="(row, i) in currentOp.data" :key="i">
<td v-for="col in currentOp.columns" :key="col">
{{ row[col] }}
</td>
</tr>
</tbody>
</table>
</div>
<div class="sql-block">
<div class="sql-label">SQL 示例</div>
<pre class="sql-code">{{ currentOp.sql }}</pre>
</div>
</div>
</div>
</template>
<style scoped>
.agg-demo {
border: 1px solid var(--vp-c-divider);
border-radius: 12px;
background: var(--vp-c-bg-soft);
margin: 24px 0;
overflow: hidden;
}
.demo-header {
padding: 14px 20px;
background: var(--vp-c-bg);
border-bottom: 1px solid var(--vp-c-divider);
display: flex;
align-items: center;
gap: 8px;
}
.icon {
font-size: 18px;
}
.title {
font-weight: 600;
font-size: 15px;
}
.subtitle {
font-size: 12px;
color: var(--vp-c-text-3);
margin-left: auto;
}
.intro-text {
padding: 16px 20px;
font-size: 13px;
color: var(--vp-c-text-2);
line-height: 1.7;
border-bottom: 1px solid var(--vp-c-divider);
}
.hl {
color: var(--vp-c-brand);
font-weight: 600;
}
.section {
padding: 16px 20px;
}
.section-label {
font-weight: 600;
font-size: 13px;
margin-bottom: 10px;
}
.table-wrap {
border: 1px solid var(--vp-c-divider);
border-radius: 8px;
overflow: hidden;
}
.data-table {
width: 100%;
border-collapse: collapse;
font-size: 12px;
}
.data-table th,
.data-table td {
padding: 10px 12px;
text-align: left;
border-bottom: 1px solid var(--vp-c-divider);
}
.data-table th {
background: var(--vp-c-bg-alt);
font-weight: 600;
}
.data-table tbody tr:hover {
background: var(--vp-c-bg-soft);
}
.ops-row {
display: flex;
gap: 8px;
padding: 0 20px 16px;
flex-wrap: wrap;
}
.op-btn {
padding: 8px 14px;
border: 1px solid var(--vp-c-divider);
border-radius: 6px;
background: var(--vp-c-bg);
font-size: 13px;
font-weight: 500;
cursor: pointer;
transition: all 0.2s;
}
.op-btn:hover {
border-color: var(--vp-c-brand);
}
.op-btn.active {
background: var(--vp-c-brand);
border-color: var(--vp-c-brand);
color: white;
}
.result-section {
border-top: 1px solid var(--vp-c-divider);
}
.sql-block {
margin-top: 12px;
}
.sql-label {
font-size: 12px;
font-weight: 600;
color: var(--vp-c-text-3);
margin-bottom: 6px;
}
.sql-code {
margin: 0;
padding: 10px 12px;
background: var(--vp-c-bg);
border: 1px solid var(--vp-c-divider);
border-radius: 6px;
font-family: 'Menlo', 'Monaco', monospace;
font-size: 11px;
line-height: 1.6;
overflow-x: auto;
}
@media (max-width: 768px) {
.ops-row {
flex-direction: column;
}
}
</style>
File diff suppressed because it is too large Load Diff
@@ -1,124 +1,95 @@
<template>
<div class="demo data-tracking-demo">
<div class="header">
<span class="title">数据埋点与采集演示</span>
</div>
<!-- Overview Diagram -->
<div v-if="activeTab === 'overview'" class="content">
<div class="overview-container">
<div class="app-screen">
<div class="app-header">电商 App</div>
<div class="app-body">
<div class="product-card">
<div class="product-img"></div>
<div class="product-info">新款手机</div>
<div class="product-btn">点击购买</div>
</div>
<!-- Animated click cursor and ripple -->
<div class="animation-cursor"></div>
<div class="animation-ripple"></div>
</div>
</div>
<div class="data-flow">
<div class="flow-line"></div>
<div class="data-packet">
<span class="bracket">{</span>
<div class="packet-lines">
<div class="pline">e: "click_buy"</div>
<div class="pline">u: "user123"</div>
</div>
<span class="bracket">}</span>
</div>
</div>
<div class="server-db">
<div class="server-header">后端分析系统</div>
<div class="server-body">
<div class="db-row">user123 | click_buy | 10:05</div>
<div class="db-row skeleton"></div>
<div class="db-row skeleton"></div>
</div>
</div>
</div>
<p class="desc">用户每一次关键操作都在底层触发了一个埋点事件飞掠网络被永远记录在案</p>
</div>
<!-- Methods Compare -->
<!-- Methods: 同一场景三种方式各自捕获到什么 -->
<div v-if="activeTab === 'methods'" class="content">
<div class="methods-compare">
<div class="method-card">
<div class="method-title">代码埋点 (Code)</div>
<div class="method-body">
<div class="code-block">tracker.track('buy', { price: 299 })</div>
<div class="method-pro">极度精准深入业务字段</div>
<div class="method-con">需要开发排期成本高</div>
</div>
</div>
<div class="method-card">
<div class="method-title">可视化埋点 (Visual)</div>
<div class="method-body">
<div class="visual-tool">
<div class="v-box selected"></div>
<div class="v-box"></div>
</div>
<div class="method-pro">产品经理可自行圈选</div>
<div class="method-con">只能抓取表层点击无法获取深层属性</div>
</div>
</div>
<div class="method-card">
<div class="method-title">全埋点 (Auto)</div>
<div class="method-body">
<div class="auto-tool">
<div class="noise-line"></div>
<div class="noise-line"></div>
<div class="noise-line"></div>
</div>
<div class="method-pro">无死角全量捕捉</div>
<div class="method-con">数据如同雪花般庞大无用噪音极多</div>
</div>
</div>
<div class="scenario-bar">场景用户在电商 App 点击了加入购物车按钮</div>
<table class="capture-table">
<thead>
<tr>
<th class="col-dim">捕获到的信息</th>
<th>代码埋点</th>
<th>可视化埋点</th>
<th>全埋点</th>
</tr>
</thead>
<tbody>
<tr v-for="row in captureRows" :key="row.label">
<td class="col-dim">{{ row.label }}</td>
<td><span :class="row.code ? 'yes' : 'no'">{{ row.code ? '✔' : '✘' }}</span></td>
<td><span :class="row.visual ? 'yes' : 'no'">{{ row.visual ? '✔' : '✘' }}</span></td>
<td><span :class="row.auto ? 'yes' : 'no'">{{ row.auto ? '✔' : '✘' }}</span></td>
</tr>
</tbody>
</table>
<div class="capture-footer">
<span class="cf-item"><span class="yes"></span> 能捕获</span>
<span class="cf-item"><span class="no"></span> 无法捕获</span>
</div>
</div>
<!-- Event Model -->
<!-- Model: 点击模拟 JSON 逐行组装 -->
<div v-if="activeTab === 'model'" class="content">
<div class="model-container">
<div class="json-code">
{
<span class="key">"event_name"</span>: <span class="string">"add_to_cart"</span>, <span class="comment">// 发生了什么 (What)</span>
<span class="key">"timestamp"</span>: <span class="number">1723456789000</span>, <span class="comment">// 什么时候 (When)</span>
<span class="key">"user_id"</span>: <span class="string">"u_98765"</span>, <span class="comment">// 是谁 (Who)</span>
<span class="key">"common_props"</span>: { <span class="comment">// 在哪里/环境 (Where & How)</span>
<span class="key">"device"</span>: <span class="string">"iPhone 15Pro"</span>,
<span class="key">"network"</span>: <span class="string">"5G"</span>,
<span class="key">"os"</span>: <span class="string">"iOS 17"</span>
},
<span class="key">"custom_props"</span>: { <span class="comment">// 业务详情 (Details)</span>
<span class="key">"product_id"</span>: <span class="string">"p_001"</span>,
<span class="key">"price"</span>: <span class="number">7999.00</span>
}
}
<div class="sim-header">
<button class="sim-btn" @click="runSimulation" :disabled="simRunning">
{{ simRunning ? '记录生成中...' : '模拟:用户点击「加入购物车」' }}
</button>
</div>
<div class="json-build">
<div class="json-line" v-for="(line, i) in jsonLines" :key="i"
:class="{ visible: simStep > i, highlight: simStep === i + 1 }">
<span class="line-tag" :style="{ background: line.color }">{{ line.tag }}</span>
<code>{{ line.code }}</code>
</div>
</div>
<p class="desc">每一个标准事件都必须回答 4W1HWho, What, When, Where, How</p>
<div class="sim-hint" v-if="simStep === 0">点击上方按钮观察一条埋点记录是如何被组装出来的</div>
</div>
<!-- Data Pipeline -->
<!-- Pipeline: 动画数据流 -->
<div v-if="activeTab === 'pipeline'" class="content">
<div class="pipeline-flow">
<div class="pipe-node">App 客户端</div>
<div class="pipe-arrow">本地缓存<br>批量上报</div>
<div class="pipe-node server">接入网关</div>
<div class="pipe-arrow">消息队列</div>
<div class="pipe-node etl">清洗 (ETL)</div>
<div class="pipe-arrow">入库</div>
<div class="pipe-node db">数据仓库</div>
</div>
<p class="desc">数据并非立刻入库为了抵御高并发和弱网环境它必须经历缓存打包列队和清洗的漫长流水线</p>
<div class="pipe-visual">
<div class="pipe-stage" v-for="(s, i) in pipeStages" :key="i">
<div class="stage-icon" :style="{ background: s.bg }">{{ s.icon }}</div>
<div class="stage-name">{{ s.name }}</div>
</div>
<div class="pipe-track">
<div class="packet" :class="{ flying: pipeFlying }"
v-for="n in 3" :key="n"
:style="{ animationDelay: (n - 1) * 0.6 + 's' }">
</div>
</div>
</div>
<button class="sim-btn pipe-btn" @click="startPipeAnim">
{{ pipeFlying ? '传输中...' : '模拟发送一批数据' }}
</button>
<div class="pipe-legend">
<span v-for="(s, i) in pipeStages" :key="i" class="legend-item">
<span class="legend-dot" :style="{ background: s.bg }"></span>{{ s.label }}
</span>
</div>
</div>
<!-- ETL: before / after 数据对比 -->
<div v-if="activeTab === 'overview'" class="content">
<div class="etl-compare">
<div class="etl-side etl-before">
<div class="etl-side-title">原始数据服务器收到的</div>
<div class="etl-row-data" v-for="(r, i) in rawData" :key="i" :class="r.issue">
<code>{{ r.text }}</code>
<span class="issue-tag" v-if="r.tag">{{ r.tag }}</span>
</div>
</div>
<div class="etl-arrow-col">
<div class="etl-arrow-label">ETL 清洗</div>
<div class="etl-arrow-icon"></div>
</div>
<div class="etl-side etl-after">
<div class="etl-side-title">清洗后写入数据仓库的</div>
<div class="etl-row-data clean" v-for="(r, i) in cleanData" :key="i">
<code>{{ r }}</code>
</div>
</div>
</div>
</div>
</div>
@@ -128,13 +99,77 @@
import { ref } from 'vue'
const props = defineProps({
tab: {
type: String,
default: 'overview'
}
tab: { type: String, default: 'overview' }
})
const activeTab = ref(props.tab)
// === Methods tab: 同一场景,三种方式各自能捕获什么 ===
const captureRows = [
{ label: '点击了哪个按钮', code: true, visual: true, auto: true },
{ label: '点击发生的时间', code: true, visual: true, auto: true },
{ label: '用户停留了多久', code: false, visual: false, auto: true },
{ label: '商品名称 / 价格', code: true, visual: false, auto: false },
{ label: '用了哪张优惠券', code: true, visual: false, auto: false },
{ label: '账户余额', code: true, visual: false, auto: false },
{ label: '页面滑动轨迹', code: false, visual: false, auto: true }
]
// === Model tab: 模拟 JSON 逐行组装 ===
const simStep = ref(0)
const simRunning = ref(false)
const jsonLines = [
{ tag: 'What', color: '#10b981', code: '"event": "add_to_cart"' },
{ tag: 'Who', color: '#3b82f6', code: '"user_id": "u_98765"' },
{ tag: 'When', color: '#8b5cf6', code: '"time": "2025-08-12T10:33:09Z"' },
{ tag: 'Where', color: '#f59e0b', code: '"device": "iPhone 15", "network": "5G"' },
{ tag: 'What', color: '#10b981', code: '"product": "新款手机", "price": 2999' }
]
function runSimulation() {
if (simRunning.value) return
simRunning.value = true
simStep.value = 0
let i = 0
const timer = setInterval(() => {
i++
simStep.value = i
if (i >= jsonLines.length) {
clearInterval(timer)
simRunning.value = false
}
}, 600)
}
// === Pipeline tab: 动画数据流 ===
const pipeFlying = ref(false)
const pipeStages = [
{ icon: '📱', name: '手机', label: '产生数据', bg: '#e0f2fe' },
{ icon: '📦', name: '打包', label: '攒一批', bg: '#fef08a' },
{ icon: '🌐', name: '发送', label: '网络传输', bg: '#fed7aa' },
{ icon: '🚦', name: '排队', label: '消息队列', bg: '#fecaca' },
{ icon: '🗄️', name: '入库', label: '数据仓库', bg: '#bbf7d0' }
]
function startPipeAnim() {
if (pipeFlying.value) return
pipeFlying.value = true
setTimeout(() => { pipeFlying.value = false }, 3000)
}
// === ETL tab: before / after 对比 ===
const rawData = [
{ text: 'id-001 userId: "zhang" add_to_cart ¥2999', issue: '', tag: '' },
{ text: 'id-001 userId: "zhang" add_to_cart ¥2999', issue: 'dup', tag: '重复' },
{ text: 'id-002 user_id: "li" click_buy ¥0', issue: '', tag: '' },
{ text: 'id-003 userId: "wang" pay 1970-01-01', issue: 'bad', tag: '时间异常' },
{ text: 'id-004 user_id: "zhao" click_buy ¥599', issue: '', tag: '' }
]
const cleanData = [
'id-001 user_id: "zhang" add_to_cart ¥2999',
'id-002 user_id: "li" click_buy ¥0',
'id-004 user_id: "zhao" click_buy ¥599'
]
</script>
<style scoped>
@@ -144,20 +179,6 @@ const activeTab = ref(props.tab)
background: var(--vp-c-bg-soft);
margin: 24px 0;
overflow: hidden;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
.header {
padding: 14px 20px;
background: var(--vp-c-bg);
border-bottom: 1px solid var(--vp-c-divider);
display: flex;
align-items: center;
}
.title {
font-weight: 600;
font-size: 15px;
}
.content {
@@ -165,326 +186,348 @@ const activeTab = ref(props.tab)
background: #f8fafc;
}
.desc {
margin-top: 16px;
font-size: 13px;
color: #64748b;
text-align: center;
.dark .content {
background: var(--vp-c-bg-soft);
}
/* Overview Styles & Animations */
.overview-container {
display: flex;
justify-content: space-between;
align-items: center;
max-width: 600px;
margin: 0 auto;
}
.app-screen {
width: 140px;
height: 220px;
background: white;
border-radius: 12px;
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
border: 4px solid #333;
position: relative;
overflow: hidden;
}
.app-header {
.sim-btn {
display: block;
margin: 0 auto 20px;
padding: 10px 24px;
background: #3b82f6;
color: white;
border: none;
border-radius: 8px;
font-size: 14px;
cursor: pointer;
transition: background 0.2s;
}
.sim-btn:hover:not(:disabled) { background: #2563eb; }
.sim-btn:disabled { opacity: 0.6; cursor: not-allowed; }
/* === Methods: Capture Table === */
.scenario-bar {
text-align: center;
font-size: 10px;
padding: 8px 0;
}
.app-body {
padding: 10px;
}
.product-card {
border: 1px solid #eee;
border-radius: 6px;
padding: 8px;
text-align: center;
}
.product-img {
height: 60px;
background: #e2e8f0;
border-radius: 4px;
margin-bottom: 8px;
}
.product-info {
font-size: 10px;
margin-bottom: 8px;
}
.product-btn {
background: #ef4444;
color: white;
font-size: 10px;
padding: 4px;
border-radius: 4px;
}
@keyframes cursor-move {
0% { transform: translate(60px, 180px); opacity: 0; }
20% { opacity: 1; }
40% { transform: translate(60px, 120px); }
50% { transform: translate(60px, 120px) scale(0.9); }
60% { transform: translate(60px, 120px); }
80% { opacity: 1; }
100% { transform: translate(60px, 180px); opacity: 0; }
}
@keyframes ripple-effect {
0% { transform: scale(0.5); opacity: 1; }
100% { transform: scale(2); opacity: 0; }
}
@keyframes packet-fly {
0% { left: 0; opacity: 0; }
10% { opacity: 1; left: 0;}
90% { left: 100%; opacity: 1; }
100% { left: 100%; opacity: 0; }
}
.animation-cursor {
position: absolute;
top: 0; left: 0;
width: 12px; height: 12px;
background: #1e293b;
border-radius: 50%;
animation: cursor-move 3s infinite;
}
.animation-ripple {
position: absolute;
top: 120px; left: 60px;
width: 20px; height: 20px;
border: 2px solid #ef4444;
border-radius: 50%;
opacity: 0;
animation: ripple-effect 3s infinite;
animation-delay: 1.5s;
}
.data-flow {
flex: 1;
height: 60px;
position: relative;
margin: 0 20px;
}
.flow-line {
position: absolute;
top: 50%;
left: 0; right: 0;
height: 2px;
background: dashed 2px #cbd5e1;
}
.data-packet {
position: absolute;
top: 0;
transform: translateY(-5px);
display: flex;
align-items: center;
font-size: 14px;
font-weight: 600;
color: #1e293b;
background: #e0f2fe;
padding: 4px 8px;
border-radius: 6px;
font-family: monospace;
font-size: 10px;
color: #0369a1;
animation: packet-fly 3s infinite;
animation-delay: 1.5s;
padding: 10px 16px;
border-radius: 8px;
margin-bottom: 16px;
}
.server-db {
width: 160px;
background: #1e293b;
.capture-table {
width: 100%;
border-collapse: collapse;
background: white;
border-radius: 8px;
overflow: hidden;
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.server-header {
background: #334155;
color: white;
text-align: center;
font-size: 12px;
padding: 8px 0;
}
.server-body {
padding: 12px;
}
.db-row {
background: #475569;
color: #94a3b8;
padding: 4px;
margin-bottom: 6px;
font-size: 8px;
border-radius: 4px;
font-family: monospace;
}
.db-row.skeleton {
height: 14px;
background: #334155;
}
/* Methods Compare */
.methods-compare {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 16px;
}
.method-card {
background: white;
border: 1px solid #e2e8f0;
border-radius: 8px;
padding: 16px;
font-size: 13px;
}
.method-title {
font-weight: 600;
font-size: 14px;
margin-bottom: 12px;
color: #1e293b;
.capture-table th,
.capture-table td {
padding: 10px 14px;
text-align: center;
border-bottom: 1px solid #f1f5f9;
padding-bottom: 8px;
}
.code-block {
background: #1e293b;
color: #cbd5e1;
padding: 8px;
border-radius: 4px;
font-family: monospace;
font-size: 10px;
margin-bottom: 12px;
.capture-table th {
background: #f8fafc;
font-weight: 600;
color: #475569;
font-size: 13px;
}
.visual-tool {
background: #f1f5f9;
height: 40px;
border-radius: 4px;
margin-bottom: 12px;
.col-dim {
text-align: left !important;
font-weight: 500;
color: #1e293b;
}
.yes { color: #16a34a; font-weight: 700; }
.no { color: #dc2626; opacity: 0.4; }
.capture-footer {
display: flex;
gap: 8px;
align-items: center;
padding: 8px;
gap: 20px;
justify-content: center;
margin-top: 12px;
font-size: 12px;
color: #64748b;
}
.v-box {
width: 20px; height: 20px;
background: #cbd5e1;
border-radius: 2px;
.cf-item { display: flex; align-items: center; gap: 4px; }
/* === Model: JSON 逐行组装 === */
.sim-header {
text-align: center;
}
.v-box.selected {
border: 2px dashed #ef4444;
background: #fee2e2;
}
.auto-tool {
background: #f1f5f9;
height: 40px;
border-radius: 4px;
margin-bottom: 12px;
padding: 8px;
display: flex;
flex-direction: column;
gap: 4px;
}
.noise-line {
height: 4px;
background: #cbd5e1;
width: 100%;
}
.method-pro, .method-con {
font-size: 11px;
margin-bottom: 4px;
}
.method-pro {
color: #16a34a;
}
.method-pro::before { content: "优势:"; font-weight: bold; }
.method-con {
color: #dc2626;
}
.method-con::before { content: "劣势:"; font-weight: bold; }
/* JSON Model */
.model-container {
.json-build {
background: #1e293b;
border-radius: 8px;
padding: 24px;
overflow-x: auto;
padding: 20px 24px;
min-height: 180px;
}
.json-code {
.json-line {
display: flex;
align-items: center;
gap: 10px;
padding: 6px 0;
opacity: 0;
transform: translateY(8px);
transition: all 0.4s ease;
}
.json-line.visible {
opacity: 1;
transform: translateY(0);
}
.json-line.highlight {
background: rgba(56, 189, 248, 0.08);
border-radius: 4px;
margin: 0 -8px;
padding: 6px 8px;
}
.line-tag {
font-size: 11px;
font-weight: 700;
color: white;
padding: 2px 8px;
border-radius: 4px;
flex-shrink: 0;
min-width: 44px;
text-align: center;
}
.json-line code {
font-family: 'Monaco', 'Menlo', monospace;
font-size: 13px;
color: #cbd5e1;
line-height: 1.6;
white-space: pre;
}
.key { color: #38bdf8; }
.string { color: #a3e635; }
.number { color: #f472b6; }
.comment { color: #64748b; font-style: italic; }
.sim-hint {
text-align: center;
font-size: 13px;
color: #94a3b8;
margin-top: 12px;
}
/* Pipeline */
.pipeline-flow {
/* === Pipeline: 动画数据流 === */
.pipe-visual {
position: relative;
display: flex;
justify-content: space-between;
align-items: center;
background: white;
border: 1px solid #e2e8f0;
border-radius: 10px;
padding: 28px 24px;
margin-bottom: 16px;
}
.pipe-stage {
display: flex;
flex-direction: column;
align-items: center;
gap: 6px;
z-index: 1;
}
.stage-icon {
width: 44px;
height: 44px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: space-between;
background: white;
padding: 24px;
border-radius: 8px;
border: 1px solid #e2e8f0;
overflow-x: auto;
justify-content: center;
font-size: 20px;
}
.pipe-node {
padding: 12px 16px;
background: #e0f2fe;
color: #0369a1;
border-radius: 8px;
font-size: 13px;
font-weight: 500;
border: 1px solid #bae6fd;
text-align: center;
.stage-name {
font-size: 12px;
font-weight: 600;
color: #475569;
}
.pipe-node.server { background: #fef08a; color: #854d0e; border-color: #fde047; }
.pipe-node.etl { background: #fed7aa; color: #9a3412; border-color: #fdba74; }
.pipe-node.db { background: #bbf7d0; color: #166534; border-color: #86efac; }
.pipe-track {
position: absolute;
top: 50%;
left: 60px;
right: 60px;
height: 3px;
background: #e2e8f0;
transform: translateY(-8px);
}
.pipe-arrow {
position: relative;
font-size: 10px;
.packet {
position: absolute;
width: 10px;
height: 10px;
background: #3b82f6;
border-radius: 50%;
top: -3.5px;
left: 0;
opacity: 0;
}
.packet.flying {
animation: fly-across 2.4s ease-in-out forwards;
}
@keyframes fly-across {
0% { left: 0; opacity: 0; }
5% { opacity: 1; }
90% { opacity: 1; }
100% { left: 100%; opacity: 0; }
}
.pipe-btn {
margin-bottom: 12px;
}
.pipe-legend {
display: flex;
justify-content: center;
gap: 20px;
font-size: 12px;
color: #64748b;
text-align: center;
}
.pipe-arrow::after {
content: "→";
display: block;
font-size: 16px;
.legend-item {
display: flex;
align-items: center;
gap: 5px;
}
.legend-dot {
width: 10px;
height: 10px;
border-radius: 50%;
display: inline-block;
}
/* === ETL: Before / After 对比 === */
.etl-compare {
display: flex;
gap: 0;
align-items: stretch;
border: 1px solid #e2e8f0;
border-radius: 10px;
overflow: hidden;
background: white;
}
.etl-side {
flex: 1;
padding: 16px;
}
.etl-before {
background: #fefce8;
}
.etl-after {
background: #f0fdf4;
}
.etl-side-title {
font-size: 13px;
font-weight: 600;
margin-bottom: 12px;
padding-bottom: 8px;
border-bottom: 1px solid rgba(0,0,0,0.06);
}
.etl-before .etl-side-title { color: #854d0e; }
.etl-after .etl-side-title { color: #166534; }
.etl-arrow-col {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 0 8px;
gap: 4px;
flex-shrink: 0;
background: #f1f5f9;
}
.etl-arrow-label {
font-size: 11px;
font-weight: 600;
color: #64748b;
white-space: nowrap;
}
.etl-arrow-icon {
font-size: 22px;
color: #94a3b8;
}
.etl-row-data {
font-family: 'Monaco', 'Menlo', monospace;
font-size: 11px;
padding: 6px 8px;
border-radius: 4px;
margin-bottom: 4px;
display: flex;
align-items: center;
gap: 8px;
color: #475569;
}
.etl-row-data:last-child { margin-bottom: 0; }
.etl-row-data.dup {
background: #fef2f2;
text-decoration: line-through;
color: #991b1b;
opacity: 0.7;
}
.etl-row-data.bad {
background: #fff7ed;
color: #9a3412;
opacity: 0.7;
}
.etl-row-data.clean {
color: #166534;
}
.issue-tag {
font-family: sans-serif;
font-size: 10px;
font-weight: 600;
padding: 1px 6px;
border-radius: 3px;
flex-shrink: 0;
background: #fecaca;
color: #991b1b;
}
/* Responsive */
@media (max-width: 640px) {
.capture-table { font-size: 12px; }
.capture-table th,
.capture-table td { padding: 8px 8px; }
.etl-compare { flex-direction: column; }
.etl-arrow-col {
flex-direction: row;
padding: 8px;
}
.pipe-visual { padding: 20px 12px; }
.stage-name { font-size: 10px; }
}
</style>
@@ -0,0 +1,316 @@
<script setup>
import { ref, computed } from 'vue'
const dataInput = ref('23, 45, 67, 89, 12, 34, 56, 78, 90, 21')
const rawData = computed(() =>
dataInput.value
.split(',')
.map((s) => parseFloat(s.trim()))
.filter((n) => !isNaN(n))
)
const sortedData = computed(() => [...rawData.value].sort((a, b) => a - b))
const count = computed(() => rawData.value.length)
const mean = computed(() => {
if (!count.value) return 0
return (rawData.value.reduce((a, b) => a + b, 0) / count.value).toFixed(2)
})
const median = computed(() => {
const s = sortedData.value
const n = s.length
if (!n) return 0
return n % 2 === 0
? ((s[n / 2 - 1] + s[n / 2]) / 2).toFixed(2)
: s[Math.floor(n / 2)].toFixed(2)
})
const mode = computed(() => {
const freq = {}
let maxFreq = 0
rawData.value.forEach((n) => {
freq[n] = (freq[n] || 0) + 1
if (freq[n] > maxFreq) maxFreq = freq[n]
})
if (maxFreq === 1) return '无'
return Object.keys(freq)
.filter((k) => freq[k] === maxFreq)
.join(', ')
})
const stdDev = computed(() => {
if (!count.value) return 0
const m = parseFloat(mean.value)
const variance =
rawData.value.reduce((sum, n) => sum + Math.pow(n - m, 2), 0) /
count.value
return Math.sqrt(variance).toFixed(2)
})
const stats = computed(() => [
{ label: '样本数', value: count.value, desc: '数据点总数', color: '#3b82f6' },
{
label: '均值',
value: mean.value,
desc: '所有数值的平均值',
color: '#22c55e'
},
{
label: '中位数',
value: median.value,
desc: '排序后中间位置的值',
color: '#f59e0b'
},
{
label: '众数',
value: mode.value,
desc: '出现次数最多的值',
color: '#8b5cf6'
},
{
label: '标准差',
value: stdDev.value,
desc: '数据离散程度',
color: '#06b6d4'
}
])
function generateRandom() {
dataInput.value = Array.from(
{ length: 10 },
() => Math.floor(Math.random() * 100) + 1
).join(', ')
}
function getBarHeight(val) {
const max = Math.max(...sortedData.value)
const min = Math.min(...sortedData.value)
const range = max - min || 1
return ((val - min) / range) * 80 + 20 + '%'
}
const barColors = ['#3b82f6', '#22c55e', '#f59e0b', '#8b5cf6', '#ec4899']
</script>
<template>
<div class="stats-demo">
<div class="demo-header">
<span class="icon">📊</span>
<span class="title">描述性统计演示</span>
<span class="subtitle">输入数据实时计算统计指标</span>
</div>
<div class="intro-text">
面对大量数据时我们需要用少数
<span class="hl">代表性指标</span>
来概括全貌输入一组数字观察均值中位数标准差等指标如何描述数据的
<span class="hl">集中趋势</span>
<span class="hl">离散程度</span>
</div>
<div class="input-area">
<div class="input-row">
<input
v-model="dataInput"
class="data-input"
placeholder="用逗号分隔,例如:1, 2, 3, 4, 5"
/>
<button class="btn-random" @click="generateRandom">随机生成</button>
</div>
</div>
<div class="stats-grid">
<div v-for="s in stats" :key="s.label" class="stat-card">
<div class="stat-label">{{ s.label }}</div>
<div class="stat-value" :style="{ color: s.color }">{{ s.value }}</div>
<div class="stat-desc">{{ s.desc }}</div>
</div>
</div>
<div class="chart-area">
<div class="chart-title">数据分布升序排列</div>
<div class="bar-chart">
<div
v-for="(val, i) in sortedData"
:key="i"
class="bar"
:style="{
height: getBarHeight(val),
background: barColors[i % barColors.length]
}"
>
<span class="bar-label">{{ val }}</span>
</div>
</div>
</div>
</div>
</template>
<style scoped>
.stats-demo {
border: 1px solid var(--vp-c-divider);
border-radius: 12px;
background: var(--vp-c-bg-soft);
margin: 24px 0;
overflow: hidden;
}
.demo-header {
padding: 14px 20px;
background: var(--vp-c-bg);
border-bottom: 1px solid var(--vp-c-divider);
display: flex;
align-items: center;
gap: 8px;
}
.icon {
font-size: 18px;
}
.title {
font-weight: 600;
font-size: 15px;
}
.subtitle {
font-size: 12px;
color: var(--vp-c-text-3);
margin-left: auto;
}
.intro-text {
padding: 16px 20px;
font-size: 13px;
color: var(--vp-c-text-2);
line-height: 1.7;
border-bottom: 1px solid var(--vp-c-divider);
}
.hl {
color: var(--vp-c-brand);
font-weight: 600;
}
.input-area {
padding: 16px 20px;
}
.input-row {
display: flex;
gap: 10px;
}
.data-input {
flex: 1;
padding: 10px 12px;
border: 1px solid var(--vp-c-divider);
border-radius: 6px;
background: var(--vp-c-bg);
font-size: 13px;
font-family: 'Menlo', 'Monaco', monospace;
}
.btn-random {
padding: 10px 16px;
border: none;
border-radius: 6px;
background: var(--vp-c-brand);
color: white;
font-size: 13px;
font-weight: 500;
cursor: pointer;
transition: opacity 0.2s;
white-space: nowrap;
}
.btn-random:hover {
opacity: 0.85;
}
.stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
gap: 10px;
padding: 0 20px 16px;
}
.stat-card {
border: 1px solid var(--vp-c-divider);
border-radius: 8px;
padding: 12px;
background: var(--vp-c-bg);
}
.stat-label {
font-size: 12px;
color: var(--vp-c-text-3);
margin-bottom: 4px;
}
.stat-value {
font-size: 20px;
font-weight: 700;
margin-bottom: 4px;
}
.stat-desc {
font-size: 11px;
color: var(--vp-c-text-3);
}
.chart-area {
padding: 16px 20px 20px;
border-top: 1px solid var(--vp-c-divider);
}
.chart-title {
font-weight: 600;
font-size: 13px;
margin-bottom: 12px;
}
.bar-chart {
display: flex;
align-items: flex-end;
justify-content: space-around;
height: 160px;
gap: 6px;
background: var(--vp-c-bg);
border-radius: 8px;
padding: 20px 12px 8px;
}
.bar {
flex: 1;
max-width: 50px;
border-radius: 4px 4px 0 0;
position: relative;
transition: height 0.3s;
}
.bar-label {
position: absolute;
top: -18px;
left: 50%;
transform: translateX(-50%);
font-size: 10px;
font-weight: 600;
color: var(--vp-c-text-2);
white-space: nowrap;
}
@media (max-width: 768px) {
.stats-grid {
grid-template-columns: repeat(2, 1fr);
}
.bar-chart {
gap: 3px;
}
.bar-label {
font-size: 8px;
}
}
</style>
@@ -0,0 +1,238 @@
<script setup>
import { computed } from 'vue'
const steps = [
{ name: '访问商品页', count: 10000 },
{ name: '加入购物车', count: 6000 },
{ name: '进入结算页', count: 4000 },
{ name: '完成支付', count: 2500 }
]
const total = steps[0].count
function stepRate(i) {
if (i === 0) return '100%'
return ((steps[i].count / steps[i - 1].count) * 100).toFixed(1) + '%'
}
function overallRate(i) {
return ((steps[i].count / total) * 100).toFixed(1) + '%'
}
function barWidth(i) {
return Math.max(30, (steps[i].count / total) * 100) + '%'
}
const worstIdx = computed(() => {
let min = 100
let idx = 1
for (let i = 1; i < steps.length; i++) {
const r = (steps[i].count / steps[i - 1].count) * 100
if (r < min) {
min = r
idx = i
}
}
return idx
})
const overallConversion = computed(() =>
((steps[steps.length - 1].count / total) * 100).toFixed(1)
)
</script>
<template>
<div class="funnel-demo">
<div class="demo-header">
<span class="icon">🔻</span>
<span class="title">漏斗分析演示</span>
<span class="subtitle">定位转化链的"出血点"</span>
</div>
<div class="intro-text">
用户从进入到完成目标是一个层层筛选的过程漏斗模型不只看最终转化率更要找到
<span class="hl">在哪里丢了人</span>
在最窄的地方投入优化收益通常最大
</div>
<div class="funnel-body">
<div
v-for="(step, i) in steps"
:key="step.name"
:class="['funnel-step', { worst: i === worstIdx }]"
:style="{ width: barWidth(i) }"
>
<div class="step-top">
<span class="step-name">{{ step.name }}</span>
<span class="step-count">{{ step.count.toLocaleString() }} </span>
</div>
<div class="step-bar"></div>
<div class="step-rates">
<span>总转化 {{ overallRate(i) }}</span>
<span v-if="i > 0" class="step-conv">
步骤转化 {{ stepRate(i) }}
</span>
</div>
</div>
</div>
<div class="insights">
<div class="insight-title">洞察</div>
<div class="insight-items">
<div class="insight-item">
最低转化步骤
<strong>{{ steps[worstIdx].name }}</strong>
{{ stepRate(worstIdx) }}
</div>
<div class="insight-item">
整体转化率<strong>{{ overallConversion }}%</strong>
</div>
<div class="insight-item">
建议优先优化
<strong>{{ steps[worstIdx].name }}</strong>
环节减少体验摩擦
</div>
</div>
</div>
</div>
</template>
<style scoped>
.funnel-demo {
border: 1px solid var(--vp-c-divider);
border-radius: 12px;
background: var(--vp-c-bg-soft);
margin: 24px 0;
overflow: hidden;
}
.demo-header {
padding: 14px 20px;
background: var(--vp-c-bg);
border-bottom: 1px solid var(--vp-c-divider);
display: flex;
align-items: center;
gap: 8px;
}
.icon {
font-size: 18px;
}
.title {
font-weight: 600;
font-size: 15px;
}
.subtitle {
font-size: 12px;
color: var(--vp-c-text-3);
margin-left: auto;
}
.intro-text {
padding: 16px 20px;
font-size: 13px;
color: var(--vp-c-text-2);
line-height: 1.7;
border-bottom: 1px solid var(--vp-c-divider);
}
.hl {
color: var(--vp-c-brand);
font-weight: 600;
}
.funnel-body {
padding: 20px;
display: flex;
flex-direction: column;
align-items: center;
gap: 10px;
}
.funnel-step {
background: var(--vp-c-bg);
border: 1px solid var(--vp-c-divider);
border-radius: 8px;
padding: 12px 16px;
transition: all 0.3s;
}
.funnel-step.worst {
border-color: #ef4444;
background: rgba(239, 68, 68, 0.05);
}
.step-top {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 8px;
}
.step-name {
font-weight: 600;
font-size: 13px;
}
.step-count {
font-size: 12px;
color: var(--vp-c-text-3);
}
.step-bar {
height: 20px;
background: linear-gradient(90deg, var(--vp-c-brand), #60a5fa);
border-radius: 4px;
margin-bottom: 6px;
}
.worst .step-bar {
background: linear-gradient(90deg, #ef4444, #f87171);
}
.step-rates {
display: flex;
justify-content: space-between;
font-size: 12px;
color: var(--vp-c-text-3);
}
.step-conv {
font-weight: 600;
}
.worst .step-conv {
color: #ef4444;
}
.insights {
padding: 16px 20px 20px;
border-top: 1px solid var(--vp-c-divider);
}
.insight-title {
font-weight: 600;
font-size: 13px;
margin-bottom: 10px;
}
.insight-items {
display: flex;
flex-direction: column;
gap: 8px;
}
.insight-item {
font-size: 13px;
color: var(--vp-c-text-2);
line-height: 1.6;
}
@media (max-width: 768px) {
.funnel-step {
width: 100% !important;
}
}
</style>
@@ -0,0 +1,232 @@
<script setup>
const retentionData = [
{ date: '2024-01-01', users: 1000, day1: 45, day7: 32, day30: 18 },
{ date: '2024-01-02', users: 1200, day1: 42, day7: 28, day30: 15 },
{ date: '2024-01-03', users: 950, day1: 40, day7: 25, day30: 12 },
{ date: '2024-01-04', users: 1100, day1: 38, day7: 30, day30: 14 },
{ date: '2024-01-05', users: 1050, day1: 41, day7: 33, day30: 16 },
{ date: '2024-01-06', users: 1300, day1: 43, day7: 29, day30: 13 },
{ date: '2024-01-07', users: 1150, day1: 40, day7: 31, day30: 15 }
]
const curves = [
{
label: '次日留存',
color: '#3b82f6',
data: retentionData.map((r) => r.day1)
},
{
label: '7日留存',
color: '#22c55e',
data: retentionData.map((r) => r.day7)
},
{
label: '30日留存',
color: '#f59e0b',
data: retentionData.map((r) => r.day30)
}
]
function points(data) {
return data.map((v, i) => `${60 + i * 50},${180 - v * 1.6}`).join(' ')
}
function rateClass(rate) {
if (rate >= 40) return 'high'
if (rate >= 25) return 'mid'
return 'low'
}
</script>
<template>
<div class="retention-demo">
<div class="demo-header">
<span class="icon">📈</span>
<span class="title">留存分析演示</span>
<span class="subtitle">产品的"硬核"体检</span>
</div>
<div class="intro-text">
拉新是给桶加水留存是看桶漏不漏留存曲线若
<span class="hl">趋于平稳</span>说明产品已获得 PMF
<span class="hl">持续跌落至零</span>说明核心价值未被验证
</div>
<!-- 留存数据表 -->
<div class="section">
<div class="section-label">留存数据</div>
<div class="table-wrap">
<table class="r-table">
<thead>
<tr>
<th>注册日期</th>
<th>注册人数</th>
<th>次日留存</th>
<th>7日留存</th>
<th>30日留存</th>
</tr>
</thead>
<tbody>
<tr v-for="r in retentionData" :key="r.date">
<td>{{ r.date }}</td>
<td>{{ r.users }}</td>
<td :class="rateClass(r.day1)">{{ r.day1 }}%</td>
<td :class="rateClass(r.day7)">{{ r.day7 }}%</td>
<td :class="rateClass(r.day30)">{{ r.day30 }}%</td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- 留存曲线 -->
<div class="section">
<div class="section-label">留存曲线</div>
<div class="chart-wrap">
<svg viewBox="0 0 400 210" class="curve-svg">
<!-- 坐标轴 -->
<line x1="40" y1="180" x2="380" y2="180" stroke="#666" stroke-width="1" />
<line x1="40" y1="20" x2="40" y2="180" stroke="#666" stroke-width="1" />
<!-- Y轴标签 -->
<text x="12" y="30" font-size="10" fill="#999">100%</text>
<text x="17" y="100" font-size="10" fill="#999">50%</text>
<text x="25" y="183" font-size="10" fill="#999">0</text>
<!-- 曲线 -->
<template v-for="c in curves" :key="c.label">
<polyline
:points="points(c.data)"
fill="none"
:stroke="c.color"
stroke-width="2"
/>
<circle
v-for="(v, i) in c.data"
:key="i"
:cx="60 + i * 50"
:cy="180 - v * 1.6"
r="3.5"
:fill="c.color"
/>
</template>
<!-- X轴标签 -->
<text
v-for="(d, i) in ['D1','D2','D3','D4','D5','D6','D7']"
:key="d"
:x="60 + i * 50"
y="196"
font-size="10"
fill="#999"
text-anchor="middle"
>{{ d }}</text>
</svg>
<div class="legend">
<div v-for="c in curves" :key="c.label" class="legend-item">
<span class="legend-dot" :style="{ background: c.color }"></span>
<span class="legend-text">{{ c.label }}</span>
</div>
</div>
</div>
</div>
</div>
</template>
<style scoped>
.retention-demo {
border: 1px solid var(--vp-c-divider);
border-radius: 12px;
background: var(--vp-c-bg-soft);
margin: 24px 0;
overflow: hidden;
}
.demo-header {
padding: 14px 20px;
background: var(--vp-c-bg);
border-bottom: 1px solid var(--vp-c-divider);
display: flex;
align-items: center;
gap: 8px;
}
.icon { font-size: 18px; }
.title { font-weight: 600; font-size: 15px; }
.subtitle { font-size: 12px; color: var(--vp-c-text-3); margin-left: auto; }
.intro-text {
padding: 16px 20px;
font-size: 13px;
color: var(--vp-c-text-2);
line-height: 1.7;
border-bottom: 1px solid var(--vp-c-divider);
}
.hl { color: var(--vp-c-brand); font-weight: 600; }
.section { padding: 16px 20px; }
.section-label { font-weight: 600; font-size: 13px; margin-bottom: 10px; }
.table-wrap {
border: 1px solid var(--vp-c-divider);
border-radius: 8px;
overflow: hidden;
}
.r-table {
width: 100%;
border-collapse: collapse;
font-size: 12px;
}
.r-table th,
.r-table td {
padding: 10px 12px;
text-align: left;
border-bottom: 1px solid var(--vp-c-divider);
}
.r-table th {
background: var(--vp-c-bg-alt);
font-weight: 600;
}
.r-table tbody tr:hover { background: var(--vp-c-bg-soft); }
.high { color: #22c55e; font-weight: 600; }
.mid { color: #f59e0b; font-weight: 600; }
.low { color: #ef4444; font-weight: 600; }
.chart-wrap {
background: var(--vp-c-bg);
border: 1px solid var(--vp-c-divider);
border-radius: 8px;
padding: 16px;
}
.curve-svg { width: 100%; height: auto; }
.legend {
display: flex;
gap: 16px;
justify-content: center;
margin-top: 10px;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
font-size: 12px;
}
.legend-dot {
width: 10px;
height: 10px;
border-radius: 2px;
}
.legend-text { color: var(--vp-c-text-2); }
</style>