From 82b98a26316d50a543142583262b9479c7586cfe Mon Sep 17 00:00:00 2001 From: xuesinan <1404152492@qq.com> Date: Thu, 28 Oct 2021 14:16:15 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BA=A2=E5=A4=B4=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 217 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 161 insertions(+), 56 deletions(-) diff --git a/index.html b/index.html index d45c870..0c89767 100644 --- a/index.html +++ b/index.html @@ -105,17 +105,17 @@ -->
-
+

选择模板

- 模板1 + 请选择红头文件模板
-
+
-
+
@@ -227,6 +235,7 @@ curStatus: 0, // 当前状态 0 未提交 1 已提交待审核 curIndex: 0, // 当前选择的模板 tempList: [{name: '模板1', organizer: '国家体育总局社会体育指导中心', title: ''}, {name: '模板2', organizer: '', title: ''}, {name: '模板3', organizer: '', title: ''}], + tempData: {}, init() { this.dom = document.querySelector("div[data-root=p1449927427387301888]"); @@ -305,6 +314,7 @@ // that.showOrHide(2, 0, 0, 0); // } // } + that.tempData = data; } else { console.log('msg: ', msg); } @@ -316,61 +326,156 @@ */ getAllTemp() { var that = this; - // fetch(`https://test.tall.wiki/gateway/sports/training/template`, { - // headers: new Headers({ - // 'Authorization': 'Bearer ' + that.token, - // 'Content-Type': 'application/json; charset=utf-8' - // }), - // method: 'POST', - // body: JSON.stringify({ - // param: {projectId: that.projectId} - // }) - // }) - // .then(function(response) { - // return response.json(); - // }) - // .then(function(res) { - // const { success, code, data, msg } = res; - // if (success && code === 200) { - // for (let i = 0; i < data.length; i++) { - // if (data[i].type === 0) { - // that.tempList = data[i].templateList; - // } - // } - - // let html = ''; - - // for (let j = 0; j < that.tempList.length; j++) { - // html += `
- // - //
`; - // } - - // that.dom.querySelector('.temp-list').html = html; - - // html += `
- // - //
`; - - // } else { - // console.log('msg: ', msg); - // } - // }); + fetch(`https://test.tall.wiki/gateway/sports/training/template`, { + headers: new Headers({ + 'Authorization': 'Bearer ' + that.token, + 'Content-Type': 'application/json; charset=utf-8' + }), + method: 'POST', + body: JSON.stringify({ + param: {projectId: that.projectId} + }) + }) + .then(function(response) { + return response.json(); + }) + .then(function(res) { + const { success, code, data, msg } = res; + if (success && code === 200) { + for (let i = 0; i < data.length; i++) { + if (data[i].type === 0) { + that.tempList = data[i].templateList; + } + } + + that.renderTemp(); // 渲染模板 + } else { + console.log('msg: ', msg); + } + }); }, /** * 选择模板 */ selTemp(index) { + let obj = this.tempList[index]; let tempName = document.querySelector('.sel-temp-name'); - tempName.innerHTML = this.tempList[index - 1].name; + tempName.innerHTML = obj.name; let temps = document.querySelectorAll('.temp-item'); for (let i = 0; i < temps.length; i++) { temps[i].classList.remove("border-blue-400"); temps[i].classList.add("border-gray-200"); } - temps[index - 1].classList.add("border-blue-400"); - this.curIndex = index - 1; + temps[index].classList.add("border-blue-400"); + this.curIndex = index; + this.getTempData(obj.id); + }, + + // 根据模板id获取模板数据 + getTempData(id) { + var that = this; + fetch(`https://test.tall.wiki/gateway/sports/training/templateId`, { + headers: new Headers({ + 'Authorization': 'Bearer ' + that.token, + 'Content-Type': 'application/json; charset=utf-8' + }), + method: 'POST', + body: JSON.stringify({ + param: {id: id} + }) + }) + .then(function(response) { + return response.json(); + }) + .then(function(res) { + const { success, code, data, msg } = res; + if (success && code === 200) { + for (let i = 0; i < data.length; i++) { + if (data[i].type === 0) { + that.tempList = data[i].templateList; + } + } + that.tempData = data; + that.renderTempData(); // 渲染模板数据 + } else { + console.log('msg: ', msg); + } + }); + }, + + // 渲染模板 + renderTemp() { + let that = this; + // this.tempList + + let html = ''; + + for (let j = 0; j < that.tempList.length; j++) { + html += `
+ +
`; + } + + that.dom.querySelector('.temp-list').innerHTML = html; + }, + + // 渲染模板数据 + renderTempData() { + let html = ''; + for (let i = 0; i < this.tempData.length; i++) { + let data = this.tempData[i]; + if (data.type === 1) { + html += `
+
+

${data.question}

+ +
+
`; + } else if (data.type === 2) { + html += `
+

${data.question}

+ +
`; + } else if (data.type === 3) { + html += `
`; + html += `

${data.question}

`; + + html += `
`; + for (let j = 0; j < data.optionList.length; j++) { + html += ``; + } + html += `
`; + html += `
`; + } else if (data.type === 4) { + html += `
+

${data.question}

+
+ <% for (let j = 0; j < data.optionList.length; j++) { %> + + <% } %> +
+
`; + } else if (data.type === 5) { + html += `
+

${data.question}

+ +
`; + } else if (data.type === 6) { + html += `
+
+

${data.question}

+ +
+
`; + } + } + + this.dom.querySelector('.temp-box').innerHTML = html; }, // 预览