完成一个基本的弹幕功能
This commit is contained in:
111
activity/templates/activity/admin_review.html
Normal file
111
activity/templates/activity/admin_review.html
Normal file
@@ -0,0 +1,111 @@
|
||||
{% extends 'base.html' %}
|
||||
|
||||
{% block css %}
|
||||
<style>
|
||||
body {
|
||||
background-color: #f8f9fa;
|
||||
font-family: Arial, sans-serif;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 1000px;
|
||||
margin: 50px auto;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin-bottom: 30px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.danmu-table {
|
||||
background-color: white;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.table th, .table td {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.danmu-content {
|
||||
max-width: 400px;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.danmu-image {
|
||||
max-width: 100px;
|
||||
max-height: 100px;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.action-buttons {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
text-align: center;
|
||||
padding: 50px 0;
|
||||
color: #6c757d;
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
<h1>弹幕审核</h1>
|
||||
|
||||
{% if danmus %}
|
||||
<div class="danmu-table">
|
||||
<table class="table table-bordered table-hover">
|
||||
<thead class="table-dark">
|
||||
<tr>
|
||||
<th>姓名</th>
|
||||
<th>内容</th>
|
||||
<th>图片</th>
|
||||
<th>创建时间</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for danmu in danmus %}
|
||||
<tr>
|
||||
<td>{{ danmu.name }}</td>
|
||||
<td class="danmu-content">{{ danmu.content }}</td>
|
||||
<td>
|
||||
{% if danmu.image %}
|
||||
<img src="{{ danmu.image.url }}" alt="图片" class="danmu-image">
|
||||
{% else %}
|
||||
-无-
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>{{ danmu.created_at|date:"Y-m-d H:i:s" }}</td>
|
||||
<td>
|
||||
<div class="action-buttons">
|
||||
<form method="post" style="margin: 0;">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="danmu_id" value="{{ danmu.id }}">
|
||||
<input type="hidden" name="action" value="approve">
|
||||
<button type="submit" class="btn btn-success btn-sm">通过</button>
|
||||
</form>
|
||||
<form method="post" style="margin: 0;">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="danmu_id" value="{{ danmu.id }}">
|
||||
<input type="hidden" name="action" value="reject">
|
||||
<button type="submit" class="btn btn-danger btn-sm">不通过</button>
|
||||
</form>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="empty-state">
|
||||
<h3>暂无待审核的弹幕</h3>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
279
activity/templates/activity/index.html
Normal file
279
activity/templates/activity/index.html
Normal file
@@ -0,0 +1,279 @@
|
||||
{% extends 'base.html' %}
|
||||
|
||||
{% block css %}
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
overflow: hidden;
|
||||
background-color: {{ setting.global_bg_color }};
|
||||
font-family: Arial, sans-serif;
|
||||
}
|
||||
|
||||
#background-container {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
z-index: -1;
|
||||
}
|
||||
|
||||
#background-image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
#background-video {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
#qr-code {
|
||||
position: fixed;
|
||||
{% if setting.qr_code_position == 'top-left' %}
|
||||
top: {{ setting.qr_code_margin_top }}px;
|
||||
left: {{ setting.qr_code_margin_left }}px;
|
||||
{% elif setting.qr_code_position == 'top-right' %}
|
||||
top: {{ setting.qr_code_margin_top }}px;
|
||||
right: {{ setting.qr_code_margin_right }}px;
|
||||
{% elif setting.qr_code_position == 'bottom-left' %}
|
||||
bottom: {{ setting.qr_code_margin_bottom }}px;
|
||||
left: {{ setting.qr_code_margin_left }}px;
|
||||
{% elif setting.qr_code_position == 'bottom-right' %}
|
||||
bottom: {{ setting.qr_code_margin_bottom }}px;
|
||||
right: {{ setting.qr_code_margin_right }}px;
|
||||
{% elif setting.qr_code_position == 'center' %}
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
{% endif %}
|
||||
width: 150px;
|
||||
height: 150px;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
#qr-code img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border: 2px solid white;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
#danmu-container {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
z-index: 50;
|
||||
}
|
||||
|
||||
.danmu-item {
|
||||
position: absolute;
|
||||
white-space: nowrap;
|
||||
padding: 12px 18px;
|
||||
border-radius: 25px;
|
||||
font-size: 20px;
|
||||
font-weight: bold;
|
||||
color: {{ setting.danmu_font_color }};
|
||||
background-color: rgba({{ setting.danmu_bg_color|slice:'1:3'|add:','|add:setting.danmu_bg_color|slice:'3:5'|add:','|add:setting.danmu_bg_color|slice:'5:7'|add:','|add:'0.8' }});
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
|
||||
animation: danmu-scroll 8s linear infinite;
|
||||
backdrop-filter: blur(2px);
|
||||
border: 1px solid rgba(255, 255, 255, 0.2);
|
||||
}
|
||||
|
||||
.danmu-item img {
|
||||
max-height: 100px;
|
||||
max-width: 200px;
|
||||
vertical-align: middle;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
@keyframes danmu-scroll {
|
||||
from { transform: translateX(100vw); }
|
||||
to { transform: translateX(-100%); }
|
||||
}
|
||||
|
||||
/* 响应式设计 */
|
||||
@media (max-width: 768px) {
|
||||
#qr-code {
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
}
|
||||
|
||||
.danmu-item {
|
||||
font-size: 16px;
|
||||
padding: 10px 15px;
|
||||
border-radius: 20px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div id="background-container">
|
||||
{% if setting.background_video %}
|
||||
<video id="background-video" autoplay loop muted playsinline>
|
||||
<source src="{{ setting.background_video.url }}" type="video/mp4">
|
||||
</video>
|
||||
{% elif setting.background_image %}
|
||||
<img id="background-image" src="{{ setting.background_image.url }}" alt="背景图片">
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div id="qr-code">
|
||||
{% if setting.qr_code_image %}
|
||||
<img src="{{ setting.qr_code_image.url }}" alt="二维码">
|
||||
{% else %}
|
||||
<!-- 默认二维码 -->
|
||||
<img src="https://api.qrserver.com/v1/create-qr-code/?size=150x150&data={{ request.build_absolute_uri }}{% url 'submit' %}" alt="默认二维码">
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div id="danmu-container">
|
||||
<!-- 初始弹幕 -->
|
||||
{% for danmu in danmus %}
|
||||
<div class="danmu-item">
|
||||
{{ danmu.name }}: {{ danmu.content }}
|
||||
{% if danmu.image %}
|
||||
<img src="{{ danmu.image.url }}" alt="图片">
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block js %}
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
// 获取弹幕容器
|
||||
const danmuContainer = $('#danmu-container');
|
||||
const containerHeight = danmuContainer.height();
|
||||
const containerWidth = danmuContainer.width();
|
||||
|
||||
// 弹幕高度(包含padding和margin)
|
||||
const DANMU_HEIGHT = 60;
|
||||
|
||||
// 上次获取弹幕的时间
|
||||
let lastTime = new Date().toISOString();
|
||||
|
||||
// 获取所有当前弹幕的位置信息
|
||||
function getCurrentDanmuPositions() {
|
||||
const positions = [];
|
||||
const danmus = danmuContainer.find('.danmu-item');
|
||||
danmus.each(function() {
|
||||
const $danmu = $(this);
|
||||
const top = parseInt($danmu.css('top')) || 0;
|
||||
positions.push({
|
||||
top: top,
|
||||
bottom: top + DANMU_HEIGHT
|
||||
});
|
||||
});
|
||||
return positions;
|
||||
}
|
||||
|
||||
// 检查位置是否与现有弹幕重叠
|
||||
function isPositionOverlapping(newTop) {
|
||||
const positions = getCurrentDanmuPositions();
|
||||
const newBottom = newTop + DANMU_HEIGHT;
|
||||
|
||||
for (const pos of positions) {
|
||||
// 检查是否有重叠
|
||||
if (!(newBottom <= pos.top || newTop >= pos.bottom)) {
|
||||
return true; // 重叠
|
||||
}
|
||||
}
|
||||
return false; // 不重叠
|
||||
}
|
||||
|
||||
// 生成随机且不重叠的位置
|
||||
function getRandomNonOverlappingTop() {
|
||||
let attempts = 0;
|
||||
const maxAttempts = 20;
|
||||
let newTop;
|
||||
|
||||
do {
|
||||
// 生成随机位置,考虑边距和弹幕高度
|
||||
newTop = Math.floor(Math.random() * (containerHeight - DANMU_HEIGHT - 20)) + 10;
|
||||
attempts++;
|
||||
} while (isPositionOverlapping(newTop) && attempts < maxAttempts);
|
||||
|
||||
// 如果尝试多次仍失败,返回一个安全位置
|
||||
if (attempts >= maxAttempts) {
|
||||
newTop = Math.floor(Math.random() * (containerHeight - DANMU_HEIGHT - 20)) + 10;
|
||||
}
|
||||
|
||||
return newTop;
|
||||
}
|
||||
|
||||
// 添加新弹幕
|
||||
function addDanmu(danmu) {
|
||||
// 获取随机且不重叠的位置
|
||||
const topPosition = getRandomNonOverlappingTop();
|
||||
|
||||
const danmuItem = $('<div>', {
|
||||
class: 'danmu-item',
|
||||
style: `top: ${topPosition}px;`,
|
||||
text: `${danmu.name}: ${danmu.content}`
|
||||
});
|
||||
|
||||
if (danmu.image) {
|
||||
const img = $('<img>', {
|
||||
src: danmu.image,
|
||||
alt: '图片',
|
||||
onload: function() {
|
||||
// 图片加载完成后重新计算宽度
|
||||
danmuItem.css('animation', 'danmu-scroll 8s linear infinite');
|
||||
}
|
||||
});
|
||||
danmuItem.append(' ').append(img);
|
||||
}
|
||||
|
||||
danmuContainer.append(danmuItem);
|
||||
|
||||
// 8秒后移除弹幕
|
||||
setTimeout(() => {
|
||||
danmuItem.remove();
|
||||
}, 8000);
|
||||
}
|
||||
|
||||
// 定时获取新弹幕
|
||||
setInterval(() => {
|
||||
$.ajax({
|
||||
url: '{% url 'api_danmu' %}',
|
||||
type: 'GET',
|
||||
dataType: 'json',
|
||||
success: function(data) {
|
||||
const newDanmus = data.danmus.filter(danmu => new Date(danmu.created_at) > new Date(lastTime));
|
||||
|
||||
if (newDanmus.length > 0) {
|
||||
newDanmus.forEach(danmu => {
|
||||
addDanmu(danmu);
|
||||
});
|
||||
|
||||
// 更新最后时间
|
||||
lastTime = new Date().toISOString();
|
||||
}
|
||||
}
|
||||
});
|
||||
}, 2000); // 每2秒获取一次
|
||||
|
||||
// 初始弹幕位置处理
|
||||
function initDanmuPositions() {
|
||||
const danmus = danmuContainer.find('.danmu-item');
|
||||
danmus.each(function() {
|
||||
const topPosition = getRandomNonOverlappingTop();
|
||||
$(this).css('top', topPosition + 'px');
|
||||
});
|
||||
}
|
||||
|
||||
// 初始化弹幕位置
|
||||
initDanmuPositions();
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
193
activity/templates/activity/setting.html
Normal file
193
activity/templates/activity/setting.html
Normal file
@@ -0,0 +1,193 @@
|
||||
{% extends 'base.html' %}
|
||||
|
||||
{% block css %}
|
||||
<style>
|
||||
body {
|
||||
background-color: #f8f9fa;
|
||||
font-family: Arial, sans-serif;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 800px;
|
||||
margin: 50px auto;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin-bottom: 30px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.setting-form {
|
||||
background-color: white;
|
||||
padding: 30px;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 25px;
|
||||
}
|
||||
|
||||
.preview-section {
|
||||
background-color: #e9ecef;
|
||||
padding: 20px;
|
||||
border-radius: 5px;
|
||||
margin-top: 30px;
|
||||
}
|
||||
|
||||
.preview-title {
|
||||
margin-bottom: 20px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.color-preview {
|
||||
display: inline-block;
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
border-radius: 50%;
|
||||
margin-left: 10px;
|
||||
vertical-align: middle;
|
||||
border: 1px solid #dee2e6;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
padding: 12px 30px;
|
||||
font-size: 16px;
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
<h1>活动设置</h1>
|
||||
|
||||
<div class="setting-form">
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
|
||||
<div class="form-group">
|
||||
{{ form.background_image.label_tag }}
|
||||
{{ form.background_image }}
|
||||
{% if form.background_image.errors %}
|
||||
<div class="text-danger">{{ form.background_image.errors }}</div>
|
||||
{% endif %}
|
||||
{% if setting.background_image %}
|
||||
<div class="mt-2">
|
||||
<small class="text-muted">当前背景图片:</small>
|
||||
<img src="{{ setting.background_image.url }}" alt="当前背景图片" style="max-width: 200px; max-height: 100px; border-radius: 5px;">
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
{{ form.background_video.label_tag }}
|
||||
{{ form.background_video }}
|
||||
{% if form.background_video.errors %}
|
||||
<div class="text-danger">{{ form.background_video.errors }}</div>
|
||||
{% endif %}
|
||||
{% if setting.background_video %}
|
||||
<div class="mt-2">
|
||||
<small class="text-muted">当前背景视频:{{ setting.background_video.name }}</small>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
{{ form.qr_code_image.label_tag }}
|
||||
{{ form.qr_code_image }}
|
||||
{% if form.qr_code_image.errors %}
|
||||
<div class="text-danger">{{ form.qr_code_image.errors }}</div>
|
||||
{% endif %}
|
||||
{% if setting.qr_code_image %}
|
||||
<div class="mt-2">
|
||||
<small class="text-muted">当前二维码:</small>
|
||||
<img src="{{ setting.qr_code_image.url }}" alt="当前二维码" style="max-width: 100px; max-height: 100px; border-radius: 5px;">
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
{{ form.qr_code_position.label_tag }}
|
||||
{{ form.qr_code_position }}
|
||||
{% if form.qr_code_position.errors %}
|
||||
<div class="text-danger">{{ form.qr_code_position.errors }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="id_danmu_font_color">
|
||||
弹幕字体颜色
|
||||
<span class="color-preview" id="font-color-preview" style="background-color: {{ setting.danmu_font_color }};"></span>
|
||||
</label>
|
||||
{{ form.danmu_font_color }}
|
||||
{% if form.danmu_font_color.errors %}
|
||||
<div class="text-danger">{{ form.danmu_font_color.errors }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="id_danmu_bg_color">
|
||||
弹幕背景颜色
|
||||
<span class="color-preview" id="bg-color-preview" style="background-color: {{ setting.danmu_bg_color }};"></span>
|
||||
</label>
|
||||
{{ form.danmu_bg_color }}
|
||||
{% if form.danmu_bg_color.errors %}
|
||||
<div class="text-danger">{{ form.danmu_bg_color.errors }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="id_global_bg_color">
|
||||
全局背景颜色
|
||||
<span class="color-preview" id="global-color-preview" style="background-color: {{ setting.global_bg_color }};"></span>
|
||||
</label>
|
||||
{{ form.global_bg_color }}
|
||||
{% if form.global_bg_color.errors %}
|
||||
<div class="text-danger">{{ form.global_bg_color.errors }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary">保存设置</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="preview-section">
|
||||
<div class="preview-title">预览效果:</div>
|
||||
<div style="width: 100%; height: 200px; background-color: {{ setting.global_bg_color }}; border-radius: 5px; position: relative; overflow: hidden;">
|
||||
{% if setting.background_image %}
|
||||
<img src="{{ setting.background_image.url }}" alt="背景预览" style="width: 100%; height: 100%; object-fit: cover;">
|
||||
{% endif %}
|
||||
<div style="position: absolute; {{ setting.qr_code_position|safe }}: 10px; width: 80px; height: 80px;">
|
||||
{% if setting.qr_code_image %}
|
||||
<img src="{{ setting.qr_code_image.url }}" alt="二维码预览" style="width: 100%; height: 100%; border: 2px solid white; border-radius: 5px;">
|
||||
{% else %}
|
||||
<!-- 默认二维码预览 -->
|
||||
<img src="https://api.qrserver.com/v1/create-qr-code/?size=80x80&data={{ request.build_absolute_uri }}{% url 'submit' %}" alt="二维码预览" style="width: 100%; height: 100%; border: 2px solid white; border-radius: 5px;">
|
||||
{% endif %}
|
||||
</div>
|
||||
<div style="position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); padding: 10px 20px; border-radius: 20px; font-size: 16px; font-weight: bold; color: {{ setting.danmu_font_color }}; background-color: {{ setting.danmu_bg_color }}; opacity: 0.8;">
|
||||
示例弹幕
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block js %}
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
// 实时更新颜色预览
|
||||
$('#id_danmu_font_color').on('input', function() {
|
||||
$('#font-color-preview').css('background-color', $(this).val());
|
||||
});
|
||||
|
||||
$('#id_danmu_bg_color').on('input', function() {
|
||||
$('#bg-color-preview').css('background-color', $(this).val());
|
||||
});
|
||||
|
||||
$('#id_global_bg_color').on('input', function() {
|
||||
$('#global-color-preview').css('background-color', $(this).val());
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
123
activity/templates/activity/submit.html
Normal file
123
activity/templates/activity/submit.html
Normal file
@@ -0,0 +1,123 @@
|
||||
{% extends 'base.html' %}
|
||||
|
||||
{% block css %}
|
||||
<style>
|
||||
body {
|
||||
background-color: #f8f9fa;
|
||||
font-family: Arial, sans-serif;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 500px;
|
||||
margin: 50px auto;
|
||||
padding: 30px;
|
||||
background-color: white;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
h1 {
|
||||
text-align: center;
|
||||
margin-bottom: 30px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.blessing-list {
|
||||
background-color: #e9ecef;
|
||||
padding: 15px;
|
||||
border-radius: 5px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.blessing-item {
|
||||
margin-bottom: 10px;
|
||||
cursor: pointer;
|
||||
padding: 5px;
|
||||
border-radius: 3px;
|
||||
transition: background-color 0.3s;
|
||||
}
|
||||
|
||||
.blessing-item:hover {
|
||||
background-color: #dee2e6;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
width: 100%;
|
||||
padding: 12px;
|
||||
font-size: 16px;
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
<h1>发送祝福</h1>
|
||||
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
|
||||
<div class="form-group">
|
||||
{{ form.name.label_tag }}
|
||||
{{ form.name }}
|
||||
{% if form.name.errors %}
|
||||
<div class="text-danger">{{ form.name.errors }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
{{ form.content.label_tag }}
|
||||
{{ form.content }}
|
||||
{% if form.content.errors %}
|
||||
<div class="text-danger">{{ form.content.errors }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="blessing-list">
|
||||
<h5>推荐祝福语:</h5>
|
||||
<div class="row">
|
||||
{% for blessing in random_blessings %}
|
||||
<div class="col-12 blessing-item" onclick="fillBlessing('{{ blessing.content|escapejs }}')">
|
||||
{{ blessing.content }}
|
||||
</div>
|
||||
{% empty %}
|
||||
<div class="col-12 text-center text-muted">暂无推荐祝福语</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
{{ form.image.label_tag }}
|
||||
{{ form.image }}
|
||||
{% if form.image.errors %}
|
||||
<div class="text-danger">{{ form.image.errors }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary">发送</button>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block js %}
|
||||
<script>
|
||||
function fillBlessing(content) {
|
||||
document.getElementById('id_content').value = content;
|
||||
}
|
||||
|
||||
// 表单验证
|
||||
$(document).ready(function() {
|
||||
$('form').submit(function() {
|
||||
const name = $('#id_name').val();
|
||||
if (!name.trim()) {
|
||||
alert('请输入您的姓名');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
22
activity/templates/base.html
Normal file
22
activity/templates/base.html
Normal file
@@ -0,0 +1,22 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>弹幕活动</title>
|
||||
<!-- Bootstrap CSS -->
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
|
||||
<!-- 自定义CSS -->
|
||||
{% block css %}{% endblock %}
|
||||
</head>
|
||||
<body>
|
||||
{% block content %}{% endblock %}
|
||||
|
||||
<!-- jQuery -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js"></script>
|
||||
<!-- Bootstrap JS -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<!-- 自定义JS -->
|
||||
{% block js %}{% endblock %}
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user