Browse Source

红头文件

tiaosheng-ms
xuesinan 4 years ago
parent
commit
c99e403893
  1. 34
      index.html

34
index.html

@ -206,13 +206,6 @@
</div> </div>
<script> <script>
document.getElementById('file').addEventListener('change', function(event) {
var files = event.target.files;
var formData = new FormData();
formData.append('param', files[0]);
p1449927427387301888.upload(formData)
}, false);
document.getElementById("form").addEventListener("input", function(e){ document.getElementById("form").addEventListener("input", function(e){
p1449927427387301888.setData(e); p1449927427387301888.setData(e);
}) })
@ -425,20 +418,21 @@
// 渲染模板数据 // 渲染模板数据
renderTempData() { renderTempData() {
let that = this;
let html = ''; let html = '';
for (let i = 0; i < this.tempData.length; i++) { for (let i = 0; i < that.tempData.length; i++) {
let data = this.tempData[i]; let data = that.tempData[i];
if (data.type === 1) { if (data.type === 1) {
html += `<div class="ques-box mt-2.5 px-2 py-1.5 w-full border border-gray-200 rounded-sm text-sm" data-id="${data.questionId}"> html += `<div class="ques-box mt-2.5 px-2 py-1.5 w-full border border-gray-200 rounded-sm text-sm" data-id="${data.questionId}">
<div class="flex justify-between items-center w-full" style="height: 20px;"> <div class="flex justify-between items-center w-full" style="height: 20px;">
<p class="w-20 flex-shrink-0 text-gray-400">${data.question}</p> <p class="w-20 flex-shrink-0 text-gray-400">${data.question}</p>
<input data-id="${data.questionId}" class="ques-${data.questionId} train-name text-right outline-none" style="width: calc(100% - 6rem)" type="text" placeholder="请输入${data.question}" /> <input data-id="${data.questionId}" class="train-name text-right outline-none" style="width: calc(100% - 6rem)" type="text" placeholder="请输入${data.question}" />
</div> </div>
</div>`; </div>`;
} else if (data.type === 2) { } else if (data.type === 2) {
html += `<div class="mt-2.5 px-2 py-1.5 flex justify-between w-full h-16 border border-gray-200 rounded-sm text-sm" data-id="${data.questionId}"> html += `<div class="mt-2.5 px-2 py-1.5 flex justify-between w-full h-16 border border-gray-200 rounded-sm text-sm" data-id="${data.questionId}">
<p class="w-20 flex-shrink-0 text-gray-400">${data.question}</p> <p class="w-20 flex-shrink-0 text-gray-400">${data.question}</p>
<textarea class="ques-${data.questionId} train-desc text-right outline-none" style="width: calc(100% - 6rem)" placeholder="请输入${data.question}"></textarea> <textarea data-id="${data.questionId}" class="train-desc text-right outline-none" style="width: calc(100% - 6rem)" placeholder="请输入${data.question}"></textarea>
</div>`; </div>`;
} else if (data.type === 3) { } else if (data.type === 3) {
html += `<div class="mt-2.5 px-2 py-1.5 flex justify-between w-full border border-gray-200 rounded-sm text-sm" data-id="${data.questionId}">`; html += `<div class="mt-2.5 px-2 py-1.5 flex justify-between w-full border border-gray-200 rounded-sm text-sm" data-id="${data.questionId}">`;
@ -480,17 +474,18 @@
<p class="file-name text-gray-400">文件上传</p> <p class="file-name text-gray-400">文件上传</p>
<div class="relative flex items-center"> <div class="relative flex items-center">
<button>上传</button> <button>上传</button>
<input class="input-file absolute z-10 opacity-0" type="file" name="files" id="file" multiple> <input class="input-file absolute z-10 opacity-0" type="file" data-id="${data.questionId}" name="files" id="file" multiple>
</div> </div>
</div>`; </div>`;
} }
} }
this.dom.querySelector('.temp-box').innerHTML = html; that.dom.querySelector('.temp-box').innerHTML = html;
}, },
// 监听input框的值 // 监听input框的值
setData(e) { setData(e) {
let that = this;
var event = e || window.event; var event = e || window.event;
var tar = event.target || event.srcElement; var tar = event.target || event.srcElement;
let id = tar.getAttribute("data-id"); let id = tar.getAttribute("data-id");
@ -499,10 +494,17 @@
let arr = this.tempData; let arr = this.tempData;
arr.forEach(function(item, index) { arr.forEach(function(item, index) {
if (item.type === 1 || item.type === 3 || item.type === 6) { if (item.type === 1 || item.type === 2 || item.type === 3 || item.type === 6) {
if (item.questionId == id) { if (item.questionId == id) {
item.answer = tar.value; item.answer = tar.value;
} }
} else if (item.type === 7) {
tar.addEventListener('change', function(event) {
var files = event.target.files;
var formData = new FormData();
formData.append('param', files[0]);
that.upload(formData, index);
}, false);
} }
}); });
@ -536,7 +538,7 @@
}, },
// 文件上传 // 文件上传
upload(formData){ upload(formData, index){
var that = this; var that = this;
fetch(`https://test.tall.wiki/gateway/sports/file/upload`, { fetch(`https://test.tall.wiki/gateway/sports/file/upload`, {
headers: new Headers({ headers: new Headers({
@ -555,6 +557,8 @@
that.filePath = data.path; that.filePath = data.path;
let fileName = that.dom.querySelector('.file-name'); let fileName = that.dom.querySelector('.file-name');
fileName.innerHTML = data.name; fileName.innerHTML = data.name;
that.tempData[index].answer = data.path;
console.log("that.tempData", that.tempData)
} else { } else {
console.log('msg: ', msg); console.log('msg: ', msg);
} }

Loading…
Cancel
Save