2026-02-03 01:46:03 +08:00
|
|
|
|
<template>
|
2026-02-06 03:34:50 +08:00
|
|
|
|
<div class="quick-start-demo">
|
|
|
|
|
|
<div class="preset-row">
|
|
|
|
|
|
<div
|
|
|
|
|
|
v-for="(preset, index) in presets"
|
|
|
|
|
|
:key="index"
|
|
|
|
|
|
class="preset-card"
|
|
|
|
|
|
:class="{ active: selectedPreset === index }"
|
|
|
|
|
|
@click="selectPreset(index)"
|
|
|
|
|
|
>
|
|
|
|
|
|
<span class="preset-icon">{{ preset.icon }}</span>
|
|
|
|
|
|
<span class="preset-name">{{ preset.name }}</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2026-02-03 01:46:03 +08:00
|
|
|
|
|
2026-02-06 03:34:50 +08:00
|
|
|
|
<div class="preview-area">
|
|
|
|
|
|
<div class="canvas-wrapper">
|
|
|
|
|
|
<canvas ref="canvasRef" width="400" height="300"></canvas>
|
|
|
|
|
|
<div v-if="!isGenerating && !hasGenerated" class="placeholder-text">
|
|
|
|
|
|
👈 点击上方风格,开始创作
|
2026-02-03 01:46:03 +08:00
|
|
|
|
</div>
|
2026-02-06 03:34:50 +08:00
|
|
|
|
<div v-if="isGenerating" class="loading-overlay">
|
|
|
|
|
|
<div class="spinner"></div>
|
|
|
|
|
|
<div>AI 正在绘制 {{ presets[selectedPreset].name }}...</div>
|
2026-02-03 01:46:03 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2026-02-06 03:34:50 +08:00
|
|
|
|
</div>
|
2026-02-03 01:46:03 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup>
|
|
|
|
|
|
import { ref, onMounted } from 'vue'
|
|
|
|
|
|
|
|
|
|
|
|
const canvasRef = ref(null)
|
|
|
|
|
|
const isGenerating = ref(false)
|
|
|
|
|
|
const hasGenerated = ref(false)
|
2026-02-06 03:34:50 +08:00
|
|
|
|
const selectedPreset = ref(-1)
|
2026-02-03 01:46:03 +08:00
|
|
|
|
|
2026-02-06 03:34:50 +08:00
|
|
|
|
const presets = [
|
|
|
|
|
|
{ name: '赛博朋克 (Cyberpunk)', icon: '🌃', color: ['#2b0055', '#ff00aa', '#00ffff'] },
|
|
|
|
|
|
{ name: '油画风景 (Oil Painting)', icon: '🎨', color: ['#556b2f', '#8b4513', '#ffdead'] },
|
|
|
|
|
|
{ name: '二次元 (Anime)', icon: '🌸', color: ['#ffb7c5', '#87ceeb', '#ffffff'] }
|
2026-02-03 01:46:03 +08:00
|
|
|
|
]
|
|
|
|
|
|
|
2026-02-06 03:34:50 +08:00
|
|
|
|
const selectPreset = (index) => {
|
|
|
|
|
|
if (isGenerating.value) return
|
|
|
|
|
|
selectedPreset.value = index
|
|
|
|
|
|
generate(presets[index])
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const generate = (preset) => {
|
2026-02-03 01:46:03 +08:00
|
|
|
|
isGenerating.value = true
|
|
|
|
|
|
hasGenerated.value = false
|
2026-02-06 03:34:50 +08:00
|
|
|
|
const ctx = canvasRef.value.getContext('2d')
|
|
|
|
|
|
|
|
|
|
|
|
// Clear
|
|
|
|
|
|
ctx.fillStyle = '#000'
|
|
|
|
|
|
ctx.fillRect(0, 0, 400, 300)
|
|
|
|
|
|
|
|
|
|
|
|
let progress = 0
|
|
|
|
|
|
const totalSteps = 60
|
|
|
|
|
|
|
|
|
|
|
|
const animate = () => {
|
|
|
|
|
|
progress++
|
|
|
|
|
|
|
|
|
|
|
|
// Draw Noise mixed with colors
|
|
|
|
|
|
const noiseLevel = 1 - (progress / totalSteps)
|
|
|
|
|
|
|
|
|
|
|
|
// Draw base colors (simple composition)
|
|
|
|
|
|
const gradient = ctx.createLinearGradient(0, 0, 400, 300)
|
|
|
|
|
|
gradient.addColorStop(0, preset.color[0])
|
|
|
|
|
|
gradient.addColorStop(0.5, preset.color[1])
|
|
|
|
|
|
gradient.addColorStop(1, preset.color[2])
|
|
|
|
|
|
ctx.fillStyle = gradient
|
|
|
|
|
|
ctx.fillRect(0, 0, 400, 300)
|
|
|
|
|
|
|
|
|
|
|
|
// Add noise overlay
|
|
|
|
|
|
if (noiseLevel > 0) {
|
|
|
|
|
|
const imgData = ctx.getImageData(0, 0, 400, 300)
|
|
|
|
|
|
const data = imgData.data
|
|
|
|
|
|
for(let i=0; i<data.length; i+=4) {
|
|
|
|
|
|
if (Math.random() < noiseLevel) {
|
|
|
|
|
|
const gray = Math.random() * 255
|
|
|
|
|
|
data[i] = (data[i] + gray) / 2
|
|
|
|
|
|
data[i+1] = (data[i+1] + gray) / 2
|
|
|
|
|
|
data[i+2] = (data[i+2] + gray) / 2
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
ctx.putImageData(imgData, 0, 0)
|
2026-02-03 01:46:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-06 03:34:50 +08:00
|
|
|
|
if (progress < totalSteps) {
|
|
|
|
|
|
requestAnimationFrame(animate)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
isGenerating.value = false
|
|
|
|
|
|
hasGenerated.value = true
|
|
|
|
|
|
}
|
2026-02-03 01:46:03 +08:00
|
|
|
|
}
|
2026-02-06 03:34:50 +08:00
|
|
|
|
|
|
|
|
|
|
animate()
|
2026-02-03 01:46:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
2026-02-06 03:34:50 +08:00
|
|
|
|
.quick-start-demo {
|
|
|
|
|
|
margin: 20px 0;
|
|
|
|
|
|
font-family: var(--vp-font-family-base);
|
2026-02-03 01:46:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-06 03:34:50 +08:00
|
|
|
|
.preset-row {
|
2026-02-03 01:46:03 +08:00
|
|
|
|
display: flex;
|
2026-02-06 03:34:50 +08:00
|
|
|
|
gap: 12px;
|
|
|
|
|
|
margin-bottom: 16px;
|
|
|
|
|
|
overflow-x: auto;
|
|
|
|
|
|
padding-bottom: 4px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.preset-card {
|
|
|
|
|
|
flex: 1;
|
|
|
|
|
|
min-width: 120px;
|
|
|
|
|
|
background: var(--vp-c-bg-soft);
|
|
|
|
|
|
border: 1px solid var(--vp-c-divider);
|
|
|
|
|
|
border-radius: 12px;
|
|
|
|
|
|
padding: 12px;
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
transition: all 0.2s;
|
2026-02-03 01:46:03 +08:00
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
2026-02-06 03:34:50 +08:00
|
|
|
|
align-items: center;
|
2026-02-03 01:46:03 +08:00
|
|
|
|
gap: 8px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-06 03:34:50 +08:00
|
|
|
|
.preset-card:hover {
|
2026-02-03 01:46:03 +08:00
|
|
|
|
transform: translateY(-2px);
|
2026-02-06 03:34:50 +08:00
|
|
|
|
border-color: var(--vp-c-brand);
|
2026-02-03 01:46:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-06 03:34:50 +08:00
|
|
|
|
.preset-card.active {
|
|
|
|
|
|
background: var(--vp-c-brand-dimm);
|
|
|
|
|
|
border-color: var(--vp-c-brand);
|
|
|
|
|
|
color: var(--vp-c-brand-dark);
|
2026-02-03 01:46:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-06 03:34:50 +08:00
|
|
|
|
.preset-icon {
|
|
|
|
|
|
font-size: 24px;
|
2026-02-03 01:46:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-06 03:34:50 +08:00
|
|
|
|
.preset-name {
|
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
|
font-weight: 600;
|
2026-02-03 01:46:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-06 03:34:50 +08:00
|
|
|
|
.preview-area {
|
|
|
|
|
|
border-radius: 12px;
|
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
border: 1px solid var(--vp-c-divider);
|
|
|
|
|
|
background: #000;
|
2026-02-03 01:46:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-06 03:34:50 +08:00
|
|
|
|
.canvas-wrapper {
|
2026-02-03 01:46:03 +08:00
|
|
|
|
position: relative;
|
|
|
|
|
|
width: 100%;
|
2026-02-06 03:34:50 +08:00
|
|
|
|
height: 300px;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: center;
|
2026-02-03 01:46:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-06 03:34:50 +08:00
|
|
|
|
canvas {
|
2026-02-03 01:46:03 +08:00
|
|
|
|
width: 100%;
|
|
|
|
|
|
height: 100%;
|
2026-02-06 03:34:50 +08:00
|
|
|
|
object-fit: cover;
|
2026-02-03 01:46:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-06 03:34:50 +08:00
|
|
|
|
.placeholder-text {
|
2026-02-03 01:46:03 +08:00
|
|
|
|
position: absolute;
|
2026-02-06 03:34:50 +08:00
|
|
|
|
color: rgba(255, 255, 255, 0.5);
|
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
|
pointer-events: none;
|
2026-02-03 01:46:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-06 03:34:50 +08:00
|
|
|
|
.loading-overlay {
|
|
|
|
|
|
position: absolute;
|
|
|
|
|
|
background: rgba(0, 0, 0, 0.6);
|
|
|
|
|
|
backdrop-filter: blur(2px);
|
2026-02-03 01:46:03 +08:00
|
|
|
|
color: white;
|
2026-02-06 03:34:50 +08:00
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
gap: 12px;
|
|
|
|
|
|
padding: 20px;
|
|
|
|
|
|
border-radius: 8px;
|
2026-02-03 01:46:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-06 03:34:50 +08:00
|
|
|
|
.spinner {
|
|
|
|
|
|
width: 24px;
|
|
|
|
|
|
height: 24px;
|
|
|
|
|
|
border: 3px solid rgba(255,255,255,0.3);
|
|
|
|
|
|
border-top-color: #fff;
|
|
|
|
|
|
border-radius: 50%;
|
|
|
|
|
|
animation: spin 1s linear infinite;
|
2026-02-03 01:46:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-06 03:34:50 +08:00
|
|
|
|
@keyframes spin {
|
|
|
|
|
|
to { transform: rotate(360deg); }
|
2026-02-03 01:46:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
</style>
|