155 lines
5.6 KiB
HTML
155 lines
5.6 KiB
HTML
<!DOCTYPE html>
|
|
{% load static %}
|
|
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<title>Excel解析工具</title>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
|
|
|
<!-- Favicon icon -->
|
|
<link rel="icon" href="{% static 'images/favicon.svg' %}" type="image/x-icon">
|
|
<!-- fontawesome icon -->
|
|
<link rel="stylesheet" href="{% static 'fonts/fontawesome/css/fontawesome-all.min.css' %}">
|
|
<!-- animation css -->
|
|
<link rel="stylesheet" href="{% static 'plugins/animation/css/animate.min.css' %}">
|
|
<!-- vendor css -->
|
|
<link rel="stylesheet" href="{% static 'css/style.css' %}">
|
|
<style>
|
|
.table-container {
|
|
position: relative;
|
|
max-height: 80vh; /* 设置为占视口高度的80% */
|
|
overflow-y: auto;
|
|
}
|
|
table {
|
|
width: 100%;
|
|
border-collapse: collapse;
|
|
}
|
|
thead th {
|
|
position: sticky;
|
|
top: 0;
|
|
background: white;
|
|
z-index: 1;
|
|
}
|
|
th, td {
|
|
border: 1px solid #ddd;
|
|
padding: 8px;
|
|
}
|
|
th {
|
|
background-color: #f2f2f2;
|
|
}
|
|
.error-cell {
|
|
background-color: #f8d7da; /* 红色背景 */
|
|
border-color: #f5c2c7; /* 红色边框 */
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<div id="alertContainer" style="position: fixed; top: 10px; right: 10px; z-index: 9999; width: 300px;"></div>
|
|
<div class="page-wrapper">
|
|
<form id="preview-form" method="post">
|
|
<input type="hidden" name="csrfmiddlewaretoken" value="{{ csrf_token }}">
|
|
<div class="modal-header">
|
|
<h3 class="modal-title" id="excelPreviewModalTitle">上传文件预览</h3>
|
|
<a href="javascript:void(0);" class="btn btn-primary" data-bs-toggle="tooltip" data-bs-original-title="返回" onclick="history.back(); ">返回</a>
|
|
</div>
|
|
<div class="modal-body">
|
|
<div class="table-container">
|
|
<table id="form-input-table" class="table table-striped table-bordered nowrap">
|
|
<thead>
|
|
<tr>
|
|
<th>序号</th>
|
|
{% for column in columns %}
|
|
<th>{{ column }}</th>
|
|
{% endfor %}
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{% for row in table_data %}
|
|
<tr>
|
|
<td>{{ forloop.counter }}</td>
|
|
{% for cell in row %}
|
|
<td>
|
|
<input type="text" class="form-control" style="width: 180px;" name="cell_{{ forloop.parentloop.counter0 }}_{{ forloop.counter0 }}" value="{{ cell }}">
|
|
</td>
|
|
{% endfor %}
|
|
</tr>
|
|
{% endfor %}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<div id="pagination">
|
|
<span id="totalData" class="mx-2">数据总数: {{ table_data|length }}</span>
|
|
</div>
|
|
<div id="actions">
|
|
<button id="saveButton" type="button" class="btn btn-primary">保存</button>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
|
|
<script src="{% static 'js/vendor-all.min.js' %}"></script>
|
|
<script src="{% static 'plugins/bootstrap/js/bootstrap.min.js' %}"></script>
|
|
<script src="{% static 'js/custom.js' %}"></script>
|
|
<script>
|
|
document.getElementById('saveButton').addEventListener('click', function() {
|
|
const table = document.getElementById('form-input-table');
|
|
const headers = Array.from(table.rows[0].cells).map(cell => cell.textContent);
|
|
const data = [];
|
|
|
|
// 清除之前的错误标记
|
|
const inputs = table.querySelectorAll('input');
|
|
inputs.forEach(input => {
|
|
input.classList.remove('error-cell');
|
|
});
|
|
|
|
for (let i = 1; i < table.rows.length; i++) {
|
|
const row = table.rows[i];
|
|
const rowData = {};
|
|
for (let j = 1; j < row.cells.length; j++) { // 跳过序号列
|
|
rowData[headers[j]] = row.cells[j].querySelector('input').value;
|
|
}
|
|
data.push(rowData);
|
|
}
|
|
|
|
fetch("{% url 'ep_common_save' %}", {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'X-CSRFToken': '{{ csrf_token }}'
|
|
},
|
|
body: JSON.stringify({ data: data })
|
|
})
|
|
.then(response => response.json())
|
|
.then(result => {
|
|
if (result.status === 'success') {
|
|
showAlert('success', result.message);
|
|
} else {
|
|
const errorMessage = result.message + '<br>' + result.errors.join('<br>');
|
|
showAlert('danger', errorMessage);
|
|
result.errors.forEach(error => {
|
|
const regex = /第【(\d+)】行【(.+?)】字段输入错误/;
|
|
const matches = error.match(regex);
|
|
if (matches) {
|
|
const row = parseInt(matches[1], 10);
|
|
const field = matches[2];
|
|
const column = Array.from(table.rows[0].cells).findIndex(cell => cell.textContent.trim() === field.trim());
|
|
|
|
if (column !== -1 && table.rows[row] && table.rows[row].cells[column]) {
|
|
table.rows[row].cells[column].querySelector('input').classList.add('error-cell');
|
|
}
|
|
}
|
|
});
|
|
}
|
|
});
|
|
});
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|