Browse Source

红头文件

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

34
index.html

@ -206,13 +206,6 @@
</div>
<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){
p1449927427387301888.setData(e);
})
@ -425,20 +418,21 @@
// 渲染模板数据
renderTempData() {
let that = this;
let html = '';
for (let i = 0; i < this.tempData.length; i++) {
let data = this.tempData[i];
for (let i = 0; i < that.tempData.length; i++) {
let data = that.tempData[i];
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}">
<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>
<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>`;
} 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}">
<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>`;
} 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}">`;
@ -480,17 +474,18 @@
<p class="file-name text-gray-400">文件上传</p>
<div class="relative flex items-center">
<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>`;
}
}
this.dom.querySelector('.temp-box').innerHTML = html;
that.dom.querySelector('.temp-box').innerHTML = html;
},
// 监听input框的值
setData(e) {
let that = this;
var event = e || window.event;
var tar = event.target || event.srcElement;
let id = tar.getAttribute("data-id");
@ -499,10 +494,17 @@
let arr = this.tempData;
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) {
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;
fetch(`https://test.tall.wiki/gateway/sports/file/upload`, {
headers: new Headers({
@ -555,6 +557,8 @@
that.filePath = data.path;
let fileName = that.dom.querySelector('.file-name');
fileName.innerHTML = data.name;
that.tempData[index].answer = data.path;
console.log("that.tempData", that.tempData)
} else {
console.log('msg: ', msg);
}

Loading…
Cancel
Save