Implement Django backend and Vue frontend structure

- Django backend with projects, templates, exports apps
- SQLite database models for Project, Asset, CardLayer
- REST API endpoints for project management
- Vue frontend with Vite, Element Plus, Fabric.js
- Home page for project selection
- Editor page with Fabric.js canvas integration
This commit is contained in:
Poker Design Developer
2026-05-31 14:55:01 +08:00
parent 00ac63b85c
commit 48629736f4
31 changed files with 1737 additions and 0 deletions

View File

@@ -0,0 +1 @@
# apps/templates/__init__.py

View File

@@ -0,0 +1,38 @@
from django.db import models
import uuid
class CardTemplate(models.Model):
"""扑克牌模板模型"""
id = models.CharField(max_length=50, primary_key=True) # 'classic', 'modern', etc.
name = models.CharField(max_length=100)
description = models.TextField()
preview_image = models.ImageField(upload_to='templates/previews/', null=True)
# 默认配色方案
color_spade = models.CharField(max_length=20, default='#000000')
color_heart = models.CharField(max_length=20, default='#FF0000')
color_club = models.CharField(max_length=20, default='#000000')
color_diamond = models.CharField(max_length=20, default='#FF0000')
color_background = models.CharField(max_length=20, default='#FFFFFF')
# 默认素材路径JSON
default_assets = models.JSONField(default=dict)
created_at = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.name
class Meta:
ordering = ['name']
class SuitSymbol(models.Model):
"""花色图案模板"""
template = models.ForeignKey(CardTemplate, on_delete=models.CASCADE, related_name='suit_symbols')
suit_name = models.CharField(max_length=20) # 'spade', 'heart', 'club', 'diamond'
svg_path = models.TextField() # SVG路径数据
color = models.CharField(max_length=20)
def __str__(self):
return f"{self.template.name} - {self.suit_name}"

View File

@@ -0,0 +1,58 @@
from rest_framework.decorators import api_view
from rest_framework.response import Response
from rest_framework import status
from .models import CardTemplate
@api_view(['GET'])
def template_list(request):
"""获取所有模板列表"""
templates = CardTemplate.objects.all()
data = []
for template in templates:
data.append({
'id': template.id,
'name': template.name,
'description': template.description,
'preview_image': template.preview_image.url if template.preview_image else None,
'colors': {
'spade': template.color_spade,
'heart': template.color_heart,
'club': template.color_club,
'diamond': template.color_diamond,
'background': template.color_background,
},
})
return Response(data)
@api_view(['GET'])
def template_detail(request, pk):
"""获取模板详情"""
try:
template = CardTemplate.objects.get(pk=pk)
except CardTemplate.DoesNotExist:
return Response({'error': 'Template not found'}, status=status.HTTP_404_NOT_FOUND)
data = {
'id': template.id,
'name': template.name,
'description': template.description,
'preview_image': template.preview_image.url if template.preview_image else None,
'colors': {
'spade': template.color_spade,
'heart': template.color_heart,
'club': template.color_club,
'diamond': template.color_diamond,
'background': template.color_background,
},
'default_assets': template.default_assets,
'suit_symbols': {
ss.suit_name: {
'svg_path': ss.svg_path,
'color': ss.color,
}
for ss in template.suit_symbols.all()
}
}
return Response(data)