Commit b0c415e006ec6064296f1666a8463ca4287c72b6
1 parent
4d5e105e
Exists in
master
feat:切换用户
Showing
6 changed files
with
121 additions
and
12 deletions
Show diff stats
3.13 KB
303 Bytes
src/router/index.js
| ... | ... | @@ -44,6 +44,7 @@ import ans_rank from '@/views/answerRank/ans_rank.vue' //答题排行榜 |
| 44 | 44 | import brush_questions from '@/views/answerRank/brush_questions.vue' //刷题记录 |
| 45 | 45 | import stars from '@/views/answerRank/stars.vue' //五星少年 |
| 46 | 46 | import ans_question from '@/views/answerRank/ans_question.vue' //答题 |
| 47 | +import switchUser from '@/views/answerRank/switchUser.vue' //切换 | |
| 47 | 48 | |
| 48 | 49 | Vue.use(VueRouter) |
| 49 | 50 | const [routerPush, routerReplace] = [VueRouter.prototype.push, VueRouter.prototype.replace]; |
| ... | ... | @@ -343,6 +344,14 @@ const routes = [{ |
| 343 | 344 | } |
| 344 | 345 | }, |
| 345 | 346 | { |
| 347 | + path: '/switchUser', | |
| 348 | + name: 'switchUser', | |
| 349 | + component: switchUser, | |
| 350 | + meta: { | |
| 351 | + title: '切换用户' | |
| 352 | + } | |
| 353 | + }, | |
| 354 | + { | |
| 346 | 355 | path: '/YanxueDetail', |
| 347 | 356 | name: 'YanxueDetail', |
| 348 | 357 | component: YanxueDetail, | ... | ... |
src/views/answerRank/ans_question.vue
| ... | ... | @@ -149,15 +149,21 @@ export default { |
| 149 | 149 | ) |
| 150 | 150 | .then((res) => { |
| 151 | 151 | if (res.data.code == 200) { |
| 152 | - this.$dialog.alert({ | |
| 153 | - title: "完成答题", | |
| 154 | - message: "您的分数是:" + res.data.data, | |
| 155 | - theme: "round-button", | |
| 156 | - }).then(() => { | |
| 157 | - this.$router.push({ | |
| 158 | - name: 'stars' | |
| 152 | + this.$dialog | |
| 153 | + .alert({ | |
| 154 | + title: "完成答题", | |
| 155 | + message: "您的分数是:" + res.data.data, | |
| 156 | + theme: "round-button", | |
| 159 | 157 | }) |
| 160 | - }); | |
| 158 | + .then(() => { | |
| 159 | + let index = this.$route.query.index | |
| 160 | + this.$router.push({ | |
| 161 | + name: "stars", | |
| 162 | + query: { | |
| 163 | + index: index, | |
| 164 | + }, | |
| 165 | + }); | |
| 166 | + }); | |
| 161 | 167 | } else { |
| 162 | 168 | this.$toast.fail(res.data.message); |
| 163 | 169 | } | ... | ... |
src/views/answerRank/stars.vue
| ... | ... | @@ -7,8 +7,9 @@ |
| 7 | 7 | <img src="@/assets/rank/tx.png" /> |
| 8 | 8 | </div> |
| 9 | 9 | <div class="font_box"> |
| 10 | - <div class="font_name" @click="getUser"> | |
| 10 | + <div class="font_name" @click="switchUser"> | |
| 11 | 11 | {{ user.travelerName }} |
| 12 | + <img src="@/assets/rank/qh1.png" /> | |
| 12 | 13 | </div> |
| 13 | 14 | <div class="font_sch">{{ user.schoolName }}</div> |
| 14 | 15 | </div> |
| ... | ... | @@ -113,10 +114,27 @@ export default { |
| 113 | 114 | //获取用户信息 |
| 114 | 115 | getUser() { |
| 115 | 116 | this.userInfo = JSON.parse(localStorage.getItem("userInfo")); |
| 116 | - console.log(this.userInfo); | |
| 117 | + | |
| 117 | 118 | if (!this.userInfo.subUsers || this.userInfo.subUsers.length == 0) { |
| 118 | 119 | return this.$toast.fail("暂无绑定出行人"); |
| 119 | 120 | } |
| 121 | + | |
| 122 | + //选择了用户 | |
| 123 | + if (this.$route.query.index) { | |
| 124 | + let index = this.$route.query.index; | |
| 125 | + localStorage.setItem( | |
| 126 | + "travelerNum", | |
| 127 | + this.userInfo.subUsers[index].travelerNum | |
| 128 | + ); | |
| 129 | + this.user = { | |
| 130 | + travelerNum: this.userInfo.subUsers[index].travelerNum, | |
| 131 | + travelerName: this.userInfo.subUsers[index].travelerName, | |
| 132 | + schoolName: this.userInfo.subUsers[index].schoolName, | |
| 133 | + }; | |
| 134 | + return; | |
| 135 | + } | |
| 136 | + //未选择用户 - 默认第一个 | |
| 137 | + | |
| 120 | 138 | localStorage.setItem( |
| 121 | 139 | "travelerNum", |
| 122 | 140 | this.userInfo.subUsers[0].travelerNum |
| ... | ... | @@ -128,11 +146,20 @@ export default { |
| 128 | 146 | schoolName: this.userInfo.subUsers[0].schoolName, |
| 129 | 147 | }; |
| 130 | 148 | }, |
| 149 | + //切换用户 | |
| 150 | + switchUser() { | |
| 151 | + this.$router.push({ | |
| 152 | + name: "switchUser", | |
| 153 | + }); | |
| 154 | + }, | |
| 131 | 155 | //开始答题 |
| 132 | 156 | toAns(val) { |
| 133 | 157 | this.$router.push({ |
| 134 | 158 | name: "ans_question", |
| 135 | - query: {categoryId:val.itemCategoryId} | |
| 159 | + query: { | |
| 160 | + categoryId: val.itemCategoryId, | |
| 161 | + index: this.$route.query.index, | |
| 162 | + }, | |
| 136 | 163 | }); |
| 137 | 164 | }, |
| 138 | 165 | //获取类型 |
| ... | ... | @@ -144,7 +171,7 @@ export default { |
| 144 | 171 | ) |
| 145 | 172 | .then((res) => { |
| 146 | 173 | if (res.data.code == 200) { |
| 147 | - this.libraryList = res.data.data | |
| 174 | + this.libraryList = res.data.data; | |
| 148 | 175 | } else { |
| 149 | 176 | this.$toast.fail(res.data.message); |
| 150 | 177 | } |
| ... | ... | @@ -207,6 +234,12 @@ export default { |
| 207 | 234 | .font_name { |
| 208 | 235 | font-size: 30px; |
| 209 | 236 | color: #333333; |
| 237 | + | |
| 238 | + img { | |
| 239 | + margin-top: 5px; | |
| 240 | + width: 30px; | |
| 241 | + height: 25px; | |
| 242 | + } | |
| 210 | 243 | } |
| 211 | 244 | .font_sch { |
| 212 | 245 | font-size: 27px; | ... | ... |
| ... | ... | @@ -0,0 +1,61 @@ |
| 1 | +<template> | |
| 2 | + <div class="card"> | |
| 3 | + <div class="cardBox" v-for="(v, i) in travelerList" :key="i"> | |
| 4 | + <div class="cardItem" @click="checkUser(v, i)"> | |
| 5 | + <div>{{ v.travelerName }}</div> | |
| 6 | + <div class="schoolCss">{{ v.schoolName }}</div> | |
| 7 | + </div> | |
| 8 | + </div> | |
| 9 | + </div> | |
| 10 | +</template> | |
| 11 | + | |
| 12 | +<script> | |
| 13 | +export default { | |
| 14 | + data() { | |
| 15 | + return { | |
| 16 | + travelerList: [], | |
| 17 | + }; | |
| 18 | + }, | |
| 19 | + methods: { | |
| 20 | + getData() { | |
| 21 | + const userInfo = JSON.parse(localStorage.getItem("userInfo")); | |
| 22 | + | |
| 23 | + this.travelerList = userInfo.subUsers; | |
| 24 | + }, | |
| 25 | + //选择 | |
| 26 | + checkUser(v, i) { | |
| 27 | + this.$router.push({ | |
| 28 | + name: "stars", | |
| 29 | + query: { | |
| 30 | + index: i, | |
| 31 | + }, | |
| 32 | + }); | |
| 33 | + }, | |
| 34 | + }, | |
| 35 | + mounted() { | |
| 36 | + this.getData(); | |
| 37 | + }, | |
| 38 | +}; | |
| 39 | +</script> | |
| 40 | + | |
| 41 | +<style lang="scss" scoped> | |
| 42 | +.card { | |
| 43 | + padding: 7vw; | |
| 44 | + box-sizing: border-box; | |
| 45 | + | |
| 46 | + .cardBox { | |
| 47 | + .cardItem { | |
| 48 | + padding: 70px 0; | |
| 49 | + box-sizing: border-box; | |
| 50 | + font-size: 40px; | |
| 51 | + display: flex; | |
| 52 | + justify-content: space-between; | |
| 53 | + border-bottom: 1px solid rgb(236, 233, 233); | |
| 54 | + | |
| 55 | + .schoolCss { | |
| 56 | + font-size: 32px; | |
| 57 | + } | |
| 58 | + } | |
| 59 | + } | |
| 60 | +} | |
| 61 | +</style> | |
| 0 | 62 | \ No newline at end of file | ... | ... |