Kamixitong/app/web/templates/version/edit.html

226 lines
10 KiB
HTML
Raw Normal View History

2025-11-11 21:39:12 +08:00
{% extends "base.html" %}
{% block title %}编辑版本 - 软件授权管理系统{% endblock %}
{% block page_title %}编辑版本{% endblock %}
{% block page_actions %}
<a href="{{ url_for('web.version_detail', version_id=version.version_id) }}" class="btn btn-outline-secondary">
<i class="fas fa-arrow-left me-2"></i>
返回详情
</a>
{% endblock %}
{% block content %}
<div class="row">
<div class="col-lg-8">
<div class="card shadow">
<div class="card-body">
<form id="version-form">
<div class="mb-3">
<label for="product_id" class="form-label">产品</label>
<select class="form-select" id="product_id" name="product_id" {% if version.publish_status == 1 %}disabled{% endif %}>
<option value="">请选择产品</option>
{% for product in products %}
<option value="{{ product.product_id }}" {% if product.product_id == version.product_id %}selected{% endif %}>
{{ product.product_name }}
</option>
{% endfor %}
</select>
{% if version.publish_status == 1 %}
<div class="form-text text-warning">已发布的版本不能更改产品</div>
{% endif %}
</div>
<div class="mb-3">
<label for="version_num" class="form-label">版本号</label>
<input type="text" class="form-control" id="version_num" name="version_num" value="{{ version.version_num }}" {% if version.publish_status == 1 %}readonly{% endif %}>
{% if version.publish_status == 1 %}
<div class="form-text text-warning">已发布的版本不能更改版本号</div>
{% else %}
<div class="form-text">版本号格式建议使用 x.x.x 格式,如 1.0.0</div>
{% endif %}
</div>
<div class="mb-3">
<label for="platform" class="form-label">平台</label>
<input type="text" class="form-control" id="platform" name="platform" value="{{ version.platform or '' }}" placeholder="如: Windows, macOS, Linux">
</div>
<div class="mb-3">
<label for="description" class="form-label">版本描述</label>
<textarea class="form-control" id="description" name="description" rows="3">{{ version.description or '' }}</textarea>
</div>
<div class="mb-3">
<label for="update_log" class="form-label">更新日志</label>
<textarea class="form-control" id="update_log" name="update_log" rows="5">{{ version.update_log or '' }}</textarea>
</div>
<div class="mb-3">
<label for="min_license_version" class="form-label">最低卡密版本</label>
<input type="text" class="form-control" id="min_license_version" name="min_license_version" value="{{ version.min_license_version or '' }}" placeholder="如: 1.0.0">
<div class="form-text">设置使用此版本所需的最低卡密版本</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="mb-3">
<label for="force_update" class="form-label">强制更新</label>
<select class="form-select" id="force_update" name="force_update">
<option value="0" {% if version.force_update == 0 %}selected{% endif %}></option>
<option value="1" {% if version.force_update == 1 %}selected{% endif %}></option>
</select>
</div>
</div>
<div class="col-md-6">
<div class="mb-3">
<label for="download_status" class="form-label">下载状态</label>
<select class="form-select" id="download_status" name="download_status">
<option value="0" {% if version.download_status == 0 %}selected{% endif %}>禁用</option>
<option value="1" {% if version.download_status == 1 %}selected{% endif %}>启用</option>
</select>
</div>
</div>
</div>
<button type="submit" class="btn btn-primary" id="submit-btn">
<i class="fas fa-save me-2"></i>
<span id="submit-text">保存更改</span>
</button>
<a href="{{ url_for('web.version_detail', version_id=version.version_id) }}" class="btn btn-secondary">取消</a>
</form>
</div>
</div>
</div>
<div class="col-lg-4">
<div class="card shadow">
<div class="card-header">
<h6 class="mb-0">版本状态</h6>
</div>
<div class="card-body">
<ul class="list-unstyled">
<li class="mb-2">
<strong>当前状态:</strong>
<span class="badge {{ 'bg-success' if version.publish_status == 1 else 'bg-secondary' }}">
{{ version.publish_status_name }}
</span>
</li>
<li class="mb-2">
<strong>版本ID:</strong> {{ version.version_id }}
</li>
<li class="mb-2">
<strong>创建时间:</strong> {{ version.create_time.strftime('%Y-%m-%d %H:%M:%S') if version.create_time else '-' }}
</li>
<li class="mb-2">
<strong>更新时间:</strong> {{ version.update_time.strftime('%Y-%m-%d %H:%M:%S') if version.update_time else '-' }}
</li>
</ul>
</div>
</div>
<div class="card shadow mt-4">
<div class="card-header">
<h6 class="mb-0">编辑说明</h6>
</div>
<div class="card-body">
<ul class="list-unstyled">
<li class="mb-2">
<i class="fas fa-info-circle text-primary me-2"></i>
<small>已发布的版本只能修改描述信息</small>
</li>
<li class="mb-2">
<i class="fas fa-info-circle text-primary me-2"></i>
<small>未发布或已回滚的版本可以修改所有信息</small>
</li>
<li class="mb-2">
<i class="fas fa-info-circle text-primary me-2"></i>
<small>版本号和产品只能在未发布状态下修改</small>
</li>
</ul>
</div>
</div>
</div>
</div>
{% endblock %}
{% block extra_js %}
<script>
// 页面加载完成后初始化
document.addEventListener('DOMContentLoaded', function() {
initEventListeners();
});
// 初始化事件监听器
function initEventListeners() {
// 表单提交
document.getElementById('version-form').addEventListener('submit', function(e) {
e.preventDefault();
updateVersion();
});
}
// 更新版本
function updateVersion() {
const submitBtn = document.getElementById('submit-btn');
const submitText = document.getElementById('submit-text');
// 获取表单数据
const data = {
product_id: document.getElementById('product_id').value,
version_num: document.getElementById('version_num').value.trim(),
platform: document.getElementById('platform').value.trim(),
description: document.getElementById('description').value.trim(),
update_log: document.getElementById('update_log').value.trim(),
min_license_version: document.getElementById('min_license_version').value.trim(),
force_update: parseInt(document.getElementById('force_update').value),
download_status: parseInt(document.getElementById('download_status').value)
};
// 显示加载状态
submitBtn.disabled = true;
submitText.textContent = '保存中...';
// 发送请求
showLoading();
fetch(`/api/v1/versions/{{ version.version_id }}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
credentials: 'same-origin'
})
.then(response => {
hideLoading();
if (response.ok) {
return response.json();
} else {
throw new Error(`HTTP error! status: ${response.status}`);
}
})
.then(data => {
if (data.success) {
showNotification('版本信息更新成功', 'success');
// 延迟跳转到版本详情
setTimeout(() => {
window.location.href = '/versions/{{ version.version_id }}';
}, 1500);
} else {
showNotification(data.message || '更新失败', 'error');
}
})
.catch(error => {
hideLoading();
console.error('Failed to update version:', error);
showNotification('网络错误,请稍后重试', 'error');
})
.finally(() => {
// 恢复按钮状态
submitBtn.disabled = false;
submitText.textContent = '保存更改';
});
}
</script>
{% endblock %}