From dc6f31221935c79d8e6dc5a69a3ebc15d3de58a8 Mon Sep 17 00:00:00 2001 From: zjz1993 <1429595365@qq.com> Date: Wed, 24 Jul 2019 14:31:09 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E5=90=8E?= =?UTF-8?q?=E5=8F=B0=E6=93=8D=E4=BD=9C=E4=BA=A4=E4=BA=92=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/practice.js | 7 ++- views/admin_classify.ejs | 98 +++++++++++++++++++++------------------- 2 files changed, 58 insertions(+), 47 deletions(-) diff --git a/modules/practice.js b/modules/practice.js index 35b937d..66fadfe 100644 --- a/modules/practice.js +++ b/modules/practice.js @@ -28,6 +28,11 @@ app.get('/practice', async (req, res) => { // 用户第一次进入练习板块 await userQuery.update(User).set({current_p_id: 1}).where("id = :id", { id:userId }).execute(); currentPId = 1; + await result.forEachAsync(async resultItem => { + const c_id = resultItem.id; + let utopInfo = await utopQuery.where('c_id=:c_id',{c_id}).andWhere('u_id=:u_id',{u_id:userId}).andWhere("is_finished=1").getMany(); + resultItem.ac_num = utopInfo.length || 0; + }); } else { await result.forEachAsync(async resultItem => { const c_id = resultItem.id; @@ -294,7 +299,7 @@ app.put('/api/practice/classify/update/:id', async (req, res) => { app.get('/api/pagination/allproblem', async (req, res) => { try { let query = await Problem.createQueryBuilder(); - let problemInfo = await query.select('COUNT(*)', 'count').getRawOne(); + let problemInfo = await query.select('id').addSelect('title').getRawMany(); res.send({ problemInfo}); } catch(e) { res.send({ error_code: e.errno, error_msg: '失败' }); diff --git a/views/admin_classify.ejs b/views/admin_classify.ejs index 85f0bf8..06ed02e 100644 --- a/views/admin_classify.ejs +++ b/views/admin_classify.ejs @@ -11,6 +11,11 @@ height:85%; overflow: auto; } + .ui.modal>.close { + top: 1.0535rem; + right: 1rem; + color: rgba(0, 0, 0, .87); + }
+
+ + #{{item.id}}{{item.title}} +
- +
@@ -113,26 +122,32 @@ classifyIntro: '', classifyArray: [], classifyId: -1, - problemOptions: [], loading: false, problemList: [], + allproblemList: [], usedProblemId: [], multipleSelection: [], problemCount: -1, - currentPage:1 + currentPage:1, + disabledId: [], }, created: function() { this.getClassifyInfo(); this.getCount(); }, methods: { + handleClose(tag) { + const deleteItem = this.multipleSelection.splice(this.multipleSelection.indexOf(tag), 1); + this.toggleSelection(deleteItem) + }, getCount: function(){ let that = this; $.ajax({ url: '/api/pagination/allproblem', type: 'GET', success: function (data) { - that.problemCount = parseInt(data.problemInfo.count); + that.problemCount = parseInt(data.problemInfo.length); + that.allproblemList = data.problemInfo; }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert('创建失败'); @@ -140,52 +155,37 @@ }) }, disableCheckbox: function(row) { - const currentIdArray = this.problemIdArray.map((function(item){ - return item.id; - })); - function findDifference(source, target){ - return target.filter(function(item){ - return !source.includes(item); - }) - } - const disabledId = findDifference(currentIdArray, this.usedProblemId) - return !disabledId.includes(row.id); + return !this.disabledId.includes(row.id); }, toggleSelection(rows) { + console.log(rows); if (rows) { rows.forEach(row => { - this.$refs.multipleTable.toggleRowSelection(row); + this.$refs.multipleTable.toggleRowSelection(row, true); }); } else { this.$refs.multipleTable.clearSelection(); } }, handlePageChange(page) { - this.selectProblem(); + this.selectProblem(this.multipleSelection); this.getProblemPagination(page); - if (this.classifyId) { - this.getClassifyInfos(this.classifyId); - } }, getProblemPagination(page) { let that = this; - $.ajax({ - url: '/api/pagination', - type: 'GET', - data: { - pagesize: 10, - page: page - 1 - }, - success: function (data) { - that.problemList = data.problemInfo; - }, - error: function (XMLHttpRequest, textStatus, errorThrown) { - alert('创建失败'); - } + this.problemList = this.allproblemList.slice((page - 1)*10, (page - 1)*10+10); + this.$nextTick(function(){ + that.toggleSelection(that.multipleSelection); }) }, - handleSelectionChange(val) { - this.multipleSelection = this.multipleSelection.concat(val); + handleSelectionChange(val, row) { + console.log(val); + const multipleSelectionId = this.multipleSelection.map(item => item.id); + if (multipleSelectionId.includes(row.id)) { + this.multipleSelection.splice(this.multipleSelection.indexOf(row), 1) + } else { + this.multipleSelection.push(row); + } }, getClassifyInfo: function() { let that = this; @@ -204,13 +204,12 @@ resetModal: function() { this.classifyName = ''; this.classifyIntro = ''; - this.problemIdArray = []; + // this.problemIdArray = []; this.classifyId = -1; - this.problemOptions=[]; this.order = this.calcOrderMax; }, - selectProblem: function() { - this.toggleSelection(this.problemIdArray) + selectProblem: function(array) { + this.toggleSelection(array) }, getClassifyInfos: function(id){ let that = this; @@ -223,10 +222,20 @@ const {classifyInfo: {id, intro, name, order}, problem} = data; that.classifyName = name; that.classifyIntro = intro; - that.problemIdArray = that.problemList.filter(function(problemItem){ + that.problemIdArray = that.allproblemList.filter(function(problemItem){ return problem.includes(problemItem.id) }); - that.toggleSelection(that.problemIdArray) + const currentIdArray = that.problemIdArray.map((function(item){ + return item.id; + })); + function findDifference(source, target){ + return target.filter(function(item){ + return !source.includes(item); + }) + } + that.disabledId = findDifference(currentIdArray, that.usedProblemId); + that.multipleSelection = that.problemIdArray; + that.toggleSelection(that.multipleSelection) that.order = order; } }, @@ -238,7 +247,7 @@ }, show: function(id){ let that = this; - this.getProblemPagination(1) + this.getProblemPagination(1); if (id) { this.classifyId = id; this.getClassifyInfos(id); @@ -261,9 +270,7 @@ name: this.classifyName, intro: this.classifyIntro, order: this.order, - problemIdArray: [...new Set(this.multipleSelection.map(function(item){ - return item.id - }))] + problemIdArray: this.multipleSelection.map(item=>item.id) } console.log(obj.problemIdArray); if (this.classifyId === -1) { @@ -310,7 +317,6 @@ } }); } - } } }, From 49946d37a1de7ef76e039548ad7c5ba5a7ae5739 Mon Sep 17 00:00:00 2001 From: zjz1993 <1429595365@qq.com> Date: Wed, 24 Jul 2019 14:36:28 +0800 Subject: [PATCH 2/2] =?UTF-8?q?bugfix:=20=E4=BF=AE=E5=A4=8D=E4=B8=8D?= =?UTF-8?q?=E8=83=BD=E5=8F=96=E6=B6=88=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- views/admin_classify.ejs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/admin_classify.ejs b/views/admin_classify.ejs index 06ed02e..6310d9b 100644 --- a/views/admin_classify.ejs +++ b/views/admin_classify.ejs @@ -161,7 +161,7 @@ console.log(rows); if (rows) { rows.forEach(row => { - this.$refs.multipleTable.toggleRowSelection(row, true); + this.$refs.multipleTable.toggleRowSelection(row); }); } else { this.$refs.multipleTable.clearSelection();