Changed around line 1
+ document.addEventListener('DOMContentLoaded', function() {
+ const form = document.getElementById('worklog-form');
+ const testItemsContainer = document.getElementById('test-items');
+ const todoItemsContainer = document.getElementById('todo-items');
+ const outputSection = document.getElementById('output-section');
+ const jsonOutput = document.getElementById('json-output');
+ const copyButton = document.getElementById('copy-json');
+
+ // Add test item
+ document.getElementById('add-test-item').addEventListener('click', function() {
+ const newItem = testItemsContainer.firstElementChild.cloneNode(true);
+ newItem.querySelectorAll('input, textarea').forEach(input => input.value = '');
+ testItemsContainer.appendChild(newItem);
+ });
+
+ // Remove test item
+ testItemsContainer.addEventListener('click', function(e) {
+ if (e.target.classList.contains('remove-item')) {
+ if (testItemsContainer.children.length > 1) {
+ e.target.parentElement.remove();
+ }
+ }
+ });
+
+ // Add todo item
+ document.getElementById('add-todo').addEventListener('click', function() {
+ const newTodo = document.createElement('div');
+ newTodo.className = 'todo-item';
+ newTodo.innerHTML = `
+
+
+ `;
+ todoItemsContainer.appendChild(newTodo);
+ });
+
+ // Remove todo item
+ todoItemsContainer.addEventListener('click', function(e) {
+ if (e.target.classList.contains('remove-todo')) {
+ if (todoItemsContainer.children.length > 1) {
+ e.target.parentElement.remove();
+ }
+ }
+ });
+
+ // Form submission
+ form.addEventListener('submit', function(e) {
+ e.preventDefault();
+
+ const worklog = {
+ 汇报人: document.getElementById('reporter').value,
+ 日期: document.getElementById('date').value,
+ 测试项: Array.from(testItemsContainer.children).map(item => ({
+ 测试项目: item.querySelector('.test-project').value,
+ 软件版本: item.querySelector('.software-version').value,
+ 硬件版本: item.querySelector('.hardware-version').value,
+ 测试用例: item.querySelector('.test-case').value,
+ 测试内容: item.querySelector('.test-content').value,
+ 测试环境信息: item.querySelector('.test-environment').value,
+ 测试目的: item.querySelector('.test-purpose').value,
+ 是否成功: item.querySelector('.is-success').value,
+ 测试结果: item.querySelector('.test-result').value,
+ bug编号: item.querySelector('.bug-number').value,
+ 备注: item.querySelector('.remarks').value
+ })),
+ 待办事项: Array.from(todoItemsContainer.children).map(todo =>
+ todo.querySelector('.todo').value)
+ };
+
+ jsonOutput.textContent = JSON.stringify(worklog, null, 2);
+ outputSection.classList.remove('hidden');
+ });
+
+ // Copy JSON to clipboard
+ copyButton.addEventListener('click', function() {
+ navigator.clipboard.writeText(jsonOutput.textContent)
+ .then(() => alert('JSON已复制到剪贴板'))
+ .catch(() => alert('复制失败,请手动复制'));
+ });
+ });