1. layout(管理控制台 dashboard.vue): main bg-[#09090b] text-zinc-100 → bg-[#f8fafc] text-zinc-900; header bg-zinc-950/60 border-zinc-800 → bg-white/80 border-zinc-200; 移动菜单按钮/新手引导按钮 text-zinc-300/400 hover:bg-zinc-800 → text-zinc-600 hover:bg-zinc-100 border-zinc-200
2. Admin/Sidebar.vue: bg-[#09090b] border-zinc-800 → bg-white border-zinc-200 + shadow-sm; 标题 text-zinc-100 → 900; activeTab bg-blue-600/10 text-blue-400 → bg-blue-50 text-blue-700 border-blue-200; 未选中 text-zinc-500 hover:text-zinc-200 hover:bg-zinc-800/40 → text-zinc-600 hover:text-zinc-900 hover:bg-zinc-100; 用户卡 avatar/首字母 bg-white/70 border-zinc-200 + 退出按钮 hover:bg-red-50 text-red-600
3. 批量 33 个 Admin 组件硬编码深色原子类 1414 处替换(bg-zinc-9xx / border-zinc-8xx / text-zinc-100,200,300 / shadow-black/ -> 对应 light 版本) + style 块原生 CSS rgba(255,255,255,x) 16 处改为 rgba(0,0,0,x) / var 浅色主题 + 硬编码 bg-[#0c0c0e] / border-white/10 / color:white / surface-primary fallback 对应浅色修正
4. 二轮批量追加: bg-zinc-950 + opacity 变体(80/60/50/40/30/20/10) 共 431 处 → bg-white 对应 opacity 版本;placeholder:text-zinc-800 → 500;text-blue/red/emerald/amber/rose/purple 400 版 → 700/600 深浅一致版;border color /500 /30 → 200;focus:ring /20 → /30;shadow color 阴影降低强度
5. hover:text-white 扫尾: 13 处 DataAnalysisPanel/DatabaseManager/NotificationSender/SemesterManager/SongManagement/UserSongsModal hover 文本从 white → zinc-900;按钮三态从 hover:bg-*600 白字 → hover:bg-*-100/200 对应深字色,和前台 indigo/浅色体系保持一致
6. BlacklistManager 前台可见提示 💡→ <Icon lightbulb amber-600 size=13>;ChangelogManager 徽章色从 emerald-300/blue-300/zinc-400 → emerald-700/blue-700/zinc-600 可读;Icon.vue 新增 lightbulb 分支 stroke 图标
7. 受影响文件: dashboard.vue + Sidebar.vue + Icon.vue + Admin/* (33个组件共 1874 处批量替换 + 20 处手工精细化修正)
332 lines
10 KiB
Vue
332 lines
10 KiB
Vue
<template>
|
||
<Transition name="fade">
|
||
<div
|
||
v-if="show"
|
||
class="fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm"
|
||
@click="$emit('close')"
|
||
>
|
||
<Transition name="scale">
|
||
<div
|
||
v-if="show"
|
||
class="bg-white border border-zinc-200 rounded-2xl shadow-2xl w-full max-w-sm overflow-hidden flex flex-col"
|
||
@click.stop
|
||
>
|
||
<div class="flex items-center justify-between p-4 border-b border-zinc-200">
|
||
<h3 class="text-sm font-black text-zinc-900 uppercase tracking-widest">生成歌单卡片</h3>
|
||
<button
|
||
class="text-zinc-500 hover:text-zinc-600 transition-colors"
|
||
@click="$emit('close')"
|
||
>
|
||
<svg class="w-5 h-5" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path d="M18 6L6 18M6 6l12 12"/></svg>
|
||
</button>
|
||
</div>
|
||
|
||
<div class="p-6 flex flex-col items-center gap-4">
|
||
<!-- 标题输入 -->
|
||
<div class="w-full space-y-2">
|
||
<label class="text-[11px] font-black uppercase text-zinc-600 tracking-wider">歌单标题</label>
|
||
<input
|
||
v-model="cardTitle"
|
||
type="text"
|
||
placeholder="例如: 2026-03-21 校园午间广播"
|
||
class="w-full bg-white border border-zinc-200 rounded-lg px-3 py-2 text-sm text-zinc-600 focus:outline-none focus:border-blue-500/50 transition-colors"
|
||
@input="drawCanvas"
|
||
>
|
||
</div>
|
||
|
||
<!-- Canvas 预览 -->
|
||
<div class="relative w-full aspect-[2/3] max-w-[280px] bg-white rounded-xl overflow-hidden border border-zinc-200 shadow-inner flex items-center justify-center">
|
||
<canvas ref="canvasRef" width="400" :height="canvasHeight" class="w-full h-full object-contain bg-white"></canvas>
|
||
</div>
|
||
|
||
<p class="text-[10px] text-zinc-500 text-center">宽度 400 像素,高度自适应,适合在手机端查看和分享</p>
|
||
</div>
|
||
|
||
<div class="p-4 border-t border-zinc-200 bg-zinc-50/50 flex gap-3">
|
||
<button
|
||
class="flex-1 py-2.5 bg-zinc-100 hover:bg-zinc-200 text-zinc-600 text-xs font-bold rounded-xl transition-colors uppercase tracking-wider"
|
||
@click="$emit('close')"
|
||
>
|
||
取消
|
||
</button>
|
||
<button
|
||
class="flex-1 py-2.5 bg-blue-600 hover:bg-blue-500 text-white text-xs font-bold rounded-xl shadow-lg shadow-blue-900/20 transition-colors uppercase tracking-wider"
|
||
@click="downloadCard"
|
||
>
|
||
下载图片
|
||
</button>
|
||
</div>
|
||
</div>
|
||
</Transition>
|
||
</div>
|
||
</Transition>
|
||
</template>
|
||
|
||
<script setup>
|
||
import { ref, onMounted, watch, nextTick, computed } from 'vue'
|
||
|
||
const props = defineProps({
|
||
show: Boolean,
|
||
songs: {
|
||
type: Array,
|
||
default: () => []
|
||
},
|
||
defaultTitle: {
|
||
type: String,
|
||
default: '校园广播歌单'
|
||
}
|
||
})
|
||
|
||
const emit = defineEmits(['close'])
|
||
|
||
const canvasRef = ref(null)
|
||
const cardTitle = ref(props.defaultTitle)
|
||
|
||
const aiPrompt = ref('anime style school campus sunset beautiful sky highly detailed')
|
||
const isGeneratingAi = ref(false)
|
||
const bgImageObj = ref(null)
|
||
|
||
const maxDisplaySongs = 200
|
||
const songLeftX = 44
|
||
const songRightX = 360
|
||
const songAreaWidth = songRightX - songLeftX
|
||
|
||
const isBrowser = typeof document !== 'undefined'
|
||
|
||
let _sharedCtx = null
|
||
const getSharedCtx = () => {
|
||
if (!isBrowser) return null
|
||
if (_sharedCtx) return _sharedCtx
|
||
try {
|
||
const c = document.createElement('canvas')
|
||
_sharedCtx = c.getContext('2d')
|
||
} catch { _sharedCtx = null }
|
||
return _sharedCtx
|
||
}
|
||
|
||
const fitText = (ctx, text, fontSize, maxWidth, lineHeight) => {
|
||
const hasCtx = !!ctx
|
||
const fontFamily = `"Inter", "system-ui", "PingFang SC", "Microsoft YaHei", sans-serif`
|
||
const avgCharWidth = fontSize * 0.55
|
||
const cjkCharWidth = fontSize * 1.05
|
||
const splitLines = String(text || '').split(/\r?\n/)
|
||
const lines = []
|
||
for (const rawLine of splitLines) {
|
||
if (hasCtx) {
|
||
ctx.font = `${fontSize}px ${fontFamily}`
|
||
const chars = Array.from(rawLine)
|
||
let current = ''
|
||
for (const ch of chars) {
|
||
const tryStr = current + ch
|
||
const w = ctx.measureText(tryStr).width
|
||
if (w > maxWidth && current) {
|
||
lines.push(current)
|
||
current = ch
|
||
} else {
|
||
current = tryStr
|
||
}
|
||
}
|
||
if (current) lines.push(current)
|
||
} else {
|
||
const chars = Array.from(rawLine)
|
||
let current = ''
|
||
let curW = 0
|
||
for (const ch of chars) {
|
||
const code = ch.codePointAt(0) || 0
|
||
const isCJK = code > 0x2e80
|
||
const w = isCJK ? cjkCharWidth : avgCharWidth
|
||
if (curW + w > maxWidth && current) {
|
||
lines.push(current)
|
||
current = ch
|
||
curW = w
|
||
} else {
|
||
current += ch
|
||
curW += w
|
||
}
|
||
}
|
||
if (current) lines.push(current)
|
||
}
|
||
}
|
||
return { lines, lineHeight }
|
||
}
|
||
|
||
const canvasHeight = computed(() => {
|
||
const count = Math.min(props.songs.length, maxDisplaySongs)
|
||
if (!count) return 600
|
||
const ctx = getSharedCtx()
|
||
let totalH = 0
|
||
const maxWidthTitle = songAreaWidth
|
||
const maxWidthArtist = Math.max(100, songAreaWidth - 10)
|
||
for (let i = 0; i < count; i++) {
|
||
const s = props.songs[i]
|
||
const song = s?.song || s || {}
|
||
const title = song.title || '未知歌曲'
|
||
const artist = song.artist || '未知歌手'
|
||
const t1 = fitText(ctx, title, 16, maxWidthTitle, 22)
|
||
const t2 = fitText(ctx, `- ${artist}`, 13, maxWidthArtist, 18)
|
||
totalH += Math.max(28, (t1.lines.length * t1.lineHeight) + (t2.lines.length * t2.lineHeight) + 10)
|
||
}
|
||
return 240 + totalH
|
||
})
|
||
|
||
|
||
|
||
const drawCanvas = () => {
|
||
if (!canvasRef.value) return
|
||
const canvas = canvasRef.value
|
||
const ctx = canvas.getContext('2d')
|
||
if (!ctx) return
|
||
|
||
const height = canvasHeight.value
|
||
|
||
// 清空画布
|
||
if (bgImageObj.value) {
|
||
ctx.drawImage(bgImageObj.value, 0, 0, 400, height)
|
||
// 增加一层半透明黑色遮罩,确保文字和列表框可见
|
||
ctx.fillStyle = 'rgba(0, 0, 0, 0.15)'
|
||
ctx.fillRect(0, 0, 400, height)
|
||
} else {
|
||
ctx.fillStyle = '#F8FAFC' // Background color
|
||
ctx.fillRect(0, 0, 400, height)
|
||
}
|
||
|
||
// 绘制渐变头部
|
||
const gradient = ctx.createLinearGradient(0, 0, 400, 0)
|
||
if (bgImageObj.value) {
|
||
gradient.addColorStop(0, 'rgba(0, 0, 0, 0.7)')
|
||
gradient.addColorStop(1, 'rgba(0, 0, 0, 0.4)')
|
||
} else {
|
||
gradient.addColorStop(0, '#2563eb') // Primary Blue
|
||
gradient.addColorStop(1, '#3b82f6')
|
||
}
|
||
ctx.fillStyle = gradient
|
||
ctx.fillRect(0, 0, 400, 100)
|
||
|
||
// 绘制标题
|
||
ctx.fillStyle = '#FFFFFF'
|
||
ctx.font = 'bold 24px "Inter", "system-ui", sans-serif'
|
||
ctx.textAlign = 'center'
|
||
ctx.fillText(cardTitle.value || '校园广播歌单', 200, 50)
|
||
|
||
// 绘制副标题(日期)
|
||
ctx.font = '14px "Inter", "system-ui", sans-serif'
|
||
ctx.fillStyle = 'rgba(0, 0, 0, 0.75)'
|
||
ctx.fillText(new Date().toLocaleDateString('zh-CN'), 200, 80)
|
||
|
||
// 绘制列表背景
|
||
if (bgImageObj.value) {
|
||
ctx.fillStyle = 'rgba(255, 255, 255, 0.85)' // 半透明白色背景
|
||
} else {
|
||
ctx.fillStyle = '#FFFFFF'
|
||
}
|
||
ctx.shadowColor = 'rgba(0,0,0,0.05)'
|
||
ctx.shadowBlur = 10
|
||
ctx.shadowOffsetY = 4
|
||
ctx.beginPath()
|
||
ctx.roundRect(20, 120, 360, height - 180, 12)
|
||
ctx.fill()
|
||
ctx.shadowColor = 'transparent'
|
||
|
||
// 绘制歌曲列表
|
||
ctx.textAlign = 'left'
|
||
ctx.textBaseline = 'top'
|
||
let y = 160
|
||
|
||
const displaySongs = props.songs.slice(0, maxDisplaySongs)
|
||
displaySongs.forEach((schedule, index) => {
|
||
const song = schedule.song || schedule
|
||
|
||
// 序号
|
||
ctx.fillStyle = '#2563eb'
|
||
ctx.font = 'bold 16px "Inter", "system-ui", "PingFang SC", "Microsoft YaHei", sans-serif'
|
||
ctx.textBaseline = 'top'
|
||
ctx.fillText(`${index + 1}.`, 40, y)
|
||
|
||
const maxWidthTitle = songAreaWidth
|
||
const maxWidthArtist = Math.max(120, songAreaWidth - 10)
|
||
const title = song.title || '未知歌曲'
|
||
const artist = song.artist || '未知歌手'
|
||
|
||
const t1 = fitText(ctx, title, 16, maxWidthTitle, 22)
|
||
ctx.fillStyle = '#0F172A'
|
||
ctx.font = `bold 16px "Inter", "system-ui", "PingFang SC", "Microsoft YaHei", sans-serif`
|
||
let ty = y
|
||
for (const line of t1.lines) {
|
||
ctx.fillText(line, songLeftX, ty)
|
||
ty += t1.lineHeight
|
||
}
|
||
|
||
const t2 = fitText(ctx, `- ${artist}`, 13, maxWidthArtist, 18)
|
||
ctx.fillStyle = '#64748B'
|
||
ctx.font = `13px "Inter", "system-ui", "PingFang SC", "Microsoft YaHei", sans-serif`
|
||
let ay = ty + 4
|
||
for (const line of t2.lines) {
|
||
ctx.fillText(line, songLeftX, ay)
|
||
ay += t2.lineHeight
|
||
}
|
||
|
||
const songBlockHeight = Math.max(28, (ty - y) + (ay - ty) + 4)
|
||
y += songBlockHeight + 8
|
||
})
|
||
|
||
if (props.songs.length > maxDisplaySongs) {
|
||
ctx.fillStyle = '#94A3B8'
|
||
ctx.font = '14px "Inter", "system-ui", sans-serif'
|
||
ctx.textAlign = 'center'
|
||
ctx.fillText(`...及其他 ${props.songs.length - maxDisplaySongs} 首歌曲`, 200, y + 10)
|
||
}
|
||
|
||
// 绘制底部水印
|
||
if (bgImageObj.value) {
|
||
ctx.fillStyle = 'rgba(0, 0, 0, 0.55)'
|
||
} else {
|
||
ctx.fillStyle = '#CBD5E1'
|
||
}
|
||
ctx.font = '12px "Inter", "system-ui", sans-serif'
|
||
ctx.textAlign = 'center'
|
||
ctx.fillText('Generated by VoiceHub', 200, height - 20)
|
||
}
|
||
|
||
const downloadCard = () => {
|
||
if (!canvasRef.value) return
|
||
const dataUrl = canvasRef.value.toDataURL('image/png')
|
||
const link = document.createElement('a')
|
||
link.download = `歌单卡片_${new Date().toISOString().split('T')[0]}.png`
|
||
link.href = dataUrl
|
||
link.click()
|
||
|
||
if (window.$showNotification) {
|
||
window.$showNotification('图片导出成功', 'success')
|
||
}
|
||
}
|
||
|
||
watch(() => props.show, (newVal) => {
|
||
if (newVal) {
|
||
cardTitle.value = props.defaultTitle
|
||
nextTick(() => {
|
||
drawCanvas()
|
||
})
|
||
}
|
||
})
|
||
</script>
|
||
|
||
<style scoped>
|
||
.fade-enter-active,
|
||
.fade-leave-active {
|
||
transition: opacity 0.2s ease;
|
||
}
|
||
.fade-enter-from,
|
||
.fade-leave-to {
|
||
opacity: 0;
|
||
}
|
||
.scale-enter-active,
|
||
.scale-leave-active {
|
||
transition: transform 0.2s ease, opacity 0.2s ease;
|
||
}
|
||
.scale-enter-from,
|
||
.scale-leave-to {
|
||
transform: scale(0.95);
|
||
opacity: 0;
|
||
}
|
||
</style>
|