Skip to content

Commit 1b23e14

Browse files
author
潘朝思
committed
feat: add pre and next button
1 parent 98aa5b4 commit 1b23e14

File tree

2 files changed

+96
-20
lines changed

2 files changed

+96
-20
lines changed

web/src/views/problem/daily.vue

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,24 @@
1212
<el-table-column prop="name" label="题目标题" min-width="56%"></el-table-column>
1313
<el-table-column label="操作" min-width="25%">
1414
<template slot-scope="scope">
15-
<el-button type="info" @click="jumpToLink(scope.row.link)" class="el-icon-paperclip">原题</el-button>
16-
<el-button type="info" @click="jumpToLocal(scope.row.ID)" class="el-icon-edit-outline">做题</el-button>
17-
<el-button type="info" @click="jumpToResult(scope.row.ID)" class="el-icon-document">答案</el-button>
18-
<el-button type="info" @click="finish(scope.$index)" class="el-icon-circle-check">完成</el-button>
15+
<!-- <el-button type="info" @click="jumpToLink(scope.row.link)" class="el-icon-paperclip">原题</el-button>-->
16+
<!-- <el-button type="info" @click="jumpToLocal(scope.row.ID)" class="el-icon-edit-outline">做题</el-button>-->
17+
<el-button type="primary" @click="jumpToResult(scope.$index, scope.row.ID)" class="el-icon-document"> 做题
18+
</el-button>
19+
<el-button type="info" @click="finish(scope.$index)" class="el-icon-circle-check"> 完成 </el-button>
1920
</template>
2021
</el-table-column>
2122
</el-table>
2223
<!-- 分页栏 -->
2324
<div class="block">
2425
<el-pagination style="padding-top: 14px"
25-
@size-change="handleSizeChange"
26-
@current-change="handleCurrentChange"
27-
:current-page="currentPage"
28-
:page-sizes="[5, 10, 20, 50]"
29-
:page-size="10"
30-
layout="total, sizes, prev, pager, next, jumper"
31-
:total="rawList.length"
26+
@size-change="handleSizeChange"
27+
@current-change="handleCurrentChange"
28+
:current-page="currentPage"
29+
:page-sizes="[5, 10, 20, 50]"
30+
:page-size="10"
31+
layout="total, sizes, prev, pager, next, jumper"
32+
:total="rawList.length"
3233
></el-pagination>
3334
</div>
3435
<!-- 再来几道 -->
@@ -81,6 +82,7 @@ export default {
8182
mounted() {
8283
dailyProblem().then(data => {
8384
this.rawList = data ? data : []
85+
console.log(data)
8486
this.currentChangePage(this.rawList, 1)
8587
})
8688
},
@@ -95,11 +97,13 @@ export default {
9597
this.$store.commit('SET_CUR_DO_PROBLEM', id)
9698
this.$router.push({path: "/problemDo"})
9799
},
98-
jumpToResult: function (id) {
100+
jumpToResult: function (idxOfPage, id) {
99101
let cur = this.$store.state.curProblem
100102
cur.id = id
103+
cur.idx = (this.currentPage - 1) * this.pageSize + idxOfPage
101104
cur.isInPlan = true
102105
cur.isInToday = true
106+
cur.rawList = this.rawList
103107
this.$store.commit('SET_CUR_PROBLEM', cur)
104108
this.$router.push({path: "/problemInfo"})
105109
},
@@ -168,10 +172,18 @@ export default {
168172
<style lang="scss" scoped>
169173
.el-button--info {
170174
width: auto;
171-
height: 25px;
172-
font-size: 10px;
173-
padding: 3px 6px;
174-
margin: 2px 5px;
175+
height: 30px;
176+
font-size: 12px;
177+
padding: 3px 8px;
178+
margin: 3px 7px;
179+
}
180+
181+
.el-button--primary {
182+
width: auto;
183+
height: 30px;
184+
font-size: 12px;
185+
padding: 3px 8px;
186+
margin: 3px 7px;
175187
}
176188
177189
.type-big {

web/src/views/problem/info.vue

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div class="mavonEditor">
3-
<el-row type="flex" justify="end">
3+
<el-row type="flex" justify="end" class="title-btn">
44
<el-button icon="el-icon-edit" @click="edit" v-if="isCreator">编辑</el-button>
55
<el-button icon="el-icon-circle-check" @click="finish" v-if="isInToday">完成</el-button>
66
<el-button icon="el-icon-delete" @click="removePlan" v-if="isInPlan">移出学习计划</el-button>
@@ -18,12 +18,23 @@
1818
style="border: 0"
1919
v-model="content"
2020
/>
21+
22+
<el-row type="flex" justify="end" class="bottom-btn">
23+
<el-button icon="el-icon-arrow-left" @click="pre" v-if="JSON.stringify(preProblem)!=='{}'">
24+
上一题:{{ preProblem.name }}
25+
</el-button>
26+
<el-button @click="next" v-if="JSON.stringify(nextProblem)!=='{}'">
27+
下一题:{{ nextProblem.name }}
28+
<i class="el-icon-arrow-right"/>
29+
</el-button>
30+
</el-row>
31+
2132
</div>
2233
</template>
2334

2435

2536
<script>
26-
import {addToProblemPlan, getProblemByID, finishProblem, removeFromProblemPlan} from '@api'
37+
import {addToProblemPlan, finishProblem, getProblemByID, removeFromProblemPlan} from '@api'
2738
2839
export default {
2940
name: "info-problem",
@@ -33,6 +44,8 @@ export default {
3344
isInToday: false,
3445
content: "",
3546
isCreator: false,
47+
preProblem: {},
48+
nextProblem: {}
3649
};
3750
},
3851
computed: {
@@ -43,6 +56,16 @@ export default {
4356
mounted() {
4457
this.problemId = this.$store.state.curProblem.id
4558
this.isInToday = this.$store.state.curProblem.isInToday
59+
if (this.isInToday) {
60+
let idx = this.$store.state.curProblem.idx
61+
let len = this.$store.state.curProblem.rawList.length
62+
if (idx - 1 >= 0) {
63+
this.preProblem = this.$store.state.curProblem.rawList[idx - 1]
64+
}
65+
if (idx + 1 < len) {
66+
this.nextProblem = this.$store.state.curProblem.rawList[idx + 1]
67+
}
68+
}
4669
getProblemByID({problem_id: this.problemId}).then(data => {
4770
this.content = "## " + data.name + "\n[OJ链接](" + data.link + ")\n\n" + data.content + "\n### 解答\n" + data.result
4871
this.isCreator = (this.$store.state.user.ID === data.creator_id)
@@ -84,13 +107,39 @@ export default {
84107
})
85108
});
86109
},
87-
addPlan: function (){
110+
addPlan: function () {
88111
addToProblemPlan({problem_id: this.problemId}).then(() => {
89112
let cur = this.$store.state.curProblem
90113
cur.isInPlan = true
91114
this.$store.commit('SET_CUR_PROBLEM', cur)
92115
this.$messages('success', 'success')
93116
})
117+
},
118+
pre: function () {
119+
let cur = this.$store.state.curProblem
120+
if (!cur.isInToday || !cur.isInPlan) {
121+
cur.rawList.splice(cur.idx, 1)
122+
}
123+
cur.id = this.preProblem.ID
124+
cur.idx = (cur.idx - 1) % cur.rawList.length
125+
cur.isInPlan = true
126+
cur.isInToday = true
127+
this.$store.commit('SET_CUR_PROBLEM', cur)
128+
location.reload()
129+
},
130+
next: function () {
131+
let cur = this.$store.state.curProblem
132+
if (!cur.isInToday || !cur.isInPlan) {
133+
cur.rawList.splice(cur.idx, 1)
134+
cur.idx = cur.idx % cur.rawList.length
135+
} else {
136+
cur.idx = (cur.idx + 1) % cur.rawList.length
137+
}
138+
cur.id = this.nextProblem.ID
139+
cur.isInPlan = true
140+
cur.isInToday = true
141+
this.$store.commit('SET_CUR_PROBLEM', cur)
142+
location.reload()
94143
}
95144
}
96145
};
@@ -104,10 +153,25 @@ export default {
104153
border-radius: 6px;
105154
}
106155
107-
.mavonEditor >>> .el-button {
156+
.title-btn >>> .el-button {
108157
width: auto;
109158
height: 30px;
110159
font-size: 12px;
111160
padding: 6px 10px;
112161
}
162+
163+
.bottom-btn >>> .el-button {
164+
width: auto;
165+
height: 40px;
166+
font-size: 13px;
167+
padding: 10px 10px;
168+
margin-top: 20px;;
169+
max-width: 500px;
170+
text-overflow: ellipsis;
171+
overflow: hidden;
172+
white-space: nowrap;
173+
display: block;
174+
}
175+
176+
113177
</style>

0 commit comments

Comments
 (0)