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 @@ } }); } - } } },