许昌做网站公司专业做网站哪家好,私人接做网站违法么,西安商城网站开发制作,黑色asp企业网站源码P6. 对局列表和排行榜功能 0 概述1 对局列表功能1.1 分页配置1.2 后端按页获取对局列表接口1.3 前端展示传回来的对局列表1.4 录像回放功能1.4.1 录像回放的流程1.4.2 录像回放的实现 1.5 前端分页展示 2 排行榜功能2.1 排行榜的实现 0 概述
本节主要介绍了如何实现对局列表和… P6. 对局列表和排行榜功能 0 概述1 对局列表功能1.1 分页配置1.2 后端按页获取对局列表接口1.3 前端展示传回来的对局列表1.4 录像回放功能1.4.1 录像回放的流程1.4.2 录像回放的实现 1.5 前端分页展示 2 排行榜功能2.1 排行榜的实现 0 概述
本节主要介绍了如何实现对局列表和排行榜对局列表包含对局录像的回放的实现最重要的是掌握怎么写分页功能。 1 对局列表功能
1.1 分页配置
由于对局数量很多不可能放在同一页上展示因此要实现分页功能。后端的 Mybatis 分页配置:
MybatisConfig:
Configuration
public class MybatisConfig {Beanpublic MybatisPlusInterceptor mybatisPlusInterceptor() {MybatisPlusInterceptor interceptor new MybatisPlusInterceptor();interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));return interceptor;}
}1.2 后端按页获取对局列表接口
service.impl 需要传入参数 page表示当前要获取的是哪一页的列表。 通过 MyBatis 提供的 API 来实现分页查询的功能查询的页面按最新对局顺序排列。
Override
public JSONObject getRecordList(Integer page) {IPageRecord recordIPage new Page(page, 8); // 每页展示8条QueryWrapperRecord queryWrapper new QueryWrapper();queryWrapper.orderByDesc(id);ListRecord records recordMapper.selectPage(recordIPage, queryWrapper).getRecords();ListJSONObject items new ArrayList();for (Record record : records) {JSONObject item new JSONObject();User userA userMapper.selectById(record.getAId());User userB userMapper.selectById(record.getBId());item.put(a_photo, userA.getPhoto());item.put(a_username, userA.getUsername());item.put(b_photo, userB.getPhoto());item.put(b_username, userB.getUsername());item.put(record, record);String result Draw;if (A.equals(record.getLoser())) result B Win;else if (B.equals(record.getLoser())) result A Win;item.put(result, result);items.add(item);}JSONObject resp new JSONObject();resp.put(records, items);resp.put(records_count, recordMapper.selectCount(null));return resp;
}1.3 前端展示传回来的对局列表
写一个表格来展示每个对局的信息先获取一页的信息进行调试:
templateContentFieldtable classtable table-striped table-hover styletext-align: center;theadtrthA/ththB/thth对战结果/thth对战时间/thth操作/th/tr/theadtbodytr v-forrecord in records :keyrecord.record.idtdsimg :srcrecord.a_photo alt classrecord-user-photonbsp;span classrecord-user-username{{ record.a_username }}/span/tdtdimg :srcrecord.b_photo alt classrecord-user-photonbsp;span classrecord-user-username{{ record.b_username }}/span/tdtd{{ record.result }}/tdtd{{ record.record.createtime }}/tdtdbutton typebutton classbtn btn-secondary查看录像/button/td/tr/tbody/table/ContentField
/templatescript
import ContentField from ../../components/ContentField.vue
import { useStore } from vuex;
import { ref } from vue;
import $ from jquery;export default {components: {ContentField},setup() {const store useStore();let records ref([]);let current_page 1;let total_records 0;console.log(total_records);const pull_page page {current_page page;$.ajax({url: http://127.0.0.1:3000/record/getlist/,data: {page,},type: get,headers: {Authorization: Bearer store.state.user.token,},success(resp) {records.value resp.records;total_records resp.records_count;},error(resp) {console.log(resp);}})}pull_page(current_page);return {records,}}
}
/scriptstyle scoped
img.record-user-photo {width: 4vh;border-radius: 50%;
}
/style1.4 录像回放功能
1.4.1 录像回放的流程
首先要明确录像回放需要哪些参数将这些参数从后端获取后保存在前端。之后要明确前端在哪展示录像以及如何展示录像。
后端传来的参数已在 1.2 节中说明并且前端保存在 records 数组中records 中的每个 record.record 包含了录像的具体信息包括地图、双方玩家的操作信息、败者等。前端需要开一个全局变量 record.js 进行保存并且决定在 PlayGround 中进行录像回放因此需要一个变量记录当前是在 pk 还是在播放 record。另外它们共用的 GameMap.js 也需要根据是 record 还是 pk 进行相应的判断如果是 pk 那就是前几节实现的如果是 record 则要播放录像。 1.4.2 录像回放的实现 首先在前端 record.js 记录全局变量在点击播放录像按钮之后应该将对应录像的信息保存到 Game, Record并且跳转到新的页面播放对应录像因此需要添加对应的路由(路由中带上对应录像的 id): path: /record/:recordId/,
name: record_content,
component: RecordContentView,
meta: {requestAuth: true,
}const open_record_content recordId {for (const record of records.value) {if (record.record.id recordId) {store.commit(updateIsRecord, true);store.commit(updateGame, {map: stringTo2D(record.record.map),a_id: record.record.aid,a_sx: record.record.asx,a_sy: record.record.asy,b_id: record.record.bid,b_sx: record.record.bsx,b_sy: record.record.bsy,});store.commit(updateSteps, {a_steps: record.record.asteps,b_steps: record.record.bsteps,});store.commit(updateRecordLoser, record.record.loser);router.push({name: record_content,params: {recordId}})break;}}
}在 GameMap.js 中实现录像回放: add_listening_events() {if (this.store.state.record.is_record) {let k 0;const a_steps this.store.state.record.a_steps;const b_steps this.store.state.record.b_steps;const loser this.store.state.record.record_loser;const [snake0, snake1] this.snakes;const interval_id setInterval(() {if (k a_steps.length - 1) {if (loser all || loser A) {snake0.status die;}if (loser all || loser B) {snake1.status die;}clearInterval(interval_id);} else {snake0.set_direction(parseInt(a_steps[k]));snake1.set_direction(parseInt(b_steps[k]));}k ;}, 300);} else {/* pk页面的操作 */}
}1.5 前端分页展示
分页要满足以下几点:
(1) 当前页高亮并且返回当前页的对局列表。
(2) 展示前面2页和后面2页的信息如果页数不存在就不展示。
(3) 点击对应编号之后会跳转到对应的页面。
templateContentFieldnav aria-label...ul classpagination stylefloat: right;li classpage-item clickclick_page(-2)a classpage-link href#前一页/a/lili :classpage-item page.is_active v-forpage in pages :keypage.number clickclick_page(page.number)a classpage-link href#{{ page.number }}/a/lili classpage-item clickclick_page(-1)a classpage-link href#后一页/a/li/ul/nav/ContentField
/templatescript
export default {setup() {let current_page 1;let total_records 0;let pages ref([]); // pages 记录当前要展示的所有页面const click_page page {if (page -2) page current_page - 1;else if (page -1) page current_page 1;let max_pages parseInt(Math.ceil(total_records / 8));if (page 1 page max_pages) {pull_page(page);}}const udpate_pages () {let max_pages parseInt(Math.ceil(total_records / 8)); // 除的是每页展示多少个录像let new_pages [];for (let i current_page - 2; i current_page 2; i ) {if (i 1 i max_pages) {new_pages.push({number: i,is_active: i current_page ? active : ,});}}pages.value new_pages;}/* 每次 pull_page 之后都要记得 update_pages */return {pages,click_page}}
}
/script2 排行榜功能
2.1 排行榜的实现
排行榜相对就简单多得多了和对局列表功能相同就是查出来用户列表再在前端展示即可(前端和上面的差不多不赘述了)。
Override
public JSONObject getRanklist(Integer page) {IPageUser userIPage new Page(page, 8);QueryWrapperUser queryWrapper new QueryWrapper();queryWrapper.orderByDesc(rating);ListUser users userMapper.selectPage(userIPage, queryWrapper).getRecords();JSONObject resp new JSONObject();for (User user : users) user.setPassword(); // 记得传回去之前要把密码清空resp.put(users, users);resp.put(users_count, userMapper.selectCount(null));return resp;
}
文章转载自: http://www.morning.blqgc.cn.gov.cn.blqgc.cn http://www.morning.rptdz.cn.gov.cn.rptdz.cn http://www.morning.fdwlg.cn.gov.cn.fdwlg.cn http://www.morning.bzlgb.cn.gov.cn.bzlgb.cn http://www.morning.nynyj.cn.gov.cn.nynyj.cn http://www.morning.jjzxn.cn.gov.cn.jjzxn.cn http://www.morning.mlnbd.cn.gov.cn.mlnbd.cn http://www.morning.pjbhk.cn.gov.cn.pjbhk.cn http://www.morning.rfzbm.cn.gov.cn.rfzbm.cn http://www.morning.xltwg.cn.gov.cn.xltwg.cn http://www.morning.wrlff.cn.gov.cn.wrlff.cn http://www.morning.rlhgx.cn.gov.cn.rlhgx.cn http://www.morning.tralution.cn.gov.cn.tralution.cn http://www.morning.rbbzn.cn.gov.cn.rbbzn.cn http://www.morning.kmqlf.cn.gov.cn.kmqlf.cn http://www.morning.drswd.cn.gov.cn.drswd.cn http://www.morning.sqqkr.cn.gov.cn.sqqkr.cn http://www.morning.lrjtx.cn.gov.cn.lrjtx.cn http://www.morning.srzhm.cn.gov.cn.srzhm.cn http://www.morning.wzyfk.cn.gov.cn.wzyfk.cn http://www.morning.cpctr.cn.gov.cn.cpctr.cn http://www.morning.qlbmc.cn.gov.cn.qlbmc.cn http://www.morning.jcxqc.cn.gov.cn.jcxqc.cn http://www.morning.cmrfl.cn.gov.cn.cmrfl.cn http://www.morning.wjlrw.cn.gov.cn.wjlrw.cn http://www.morning.xxsrm.cn.gov.cn.xxsrm.cn http://www.morning.bkqw.cn.gov.cn.bkqw.cn http://www.morning.wnbqy.cn.gov.cn.wnbqy.cn http://www.morning.jokesm.com.gov.cn.jokesm.com http://www.morning.nfyc.cn.gov.cn.nfyc.cn http://www.morning.sypby.cn.gov.cn.sypby.cn http://www.morning.gnmhy.cn.gov.cn.gnmhy.cn http://www.morning.gbcnz.cn.gov.cn.gbcnz.cn http://www.morning.hctgn.cn.gov.cn.hctgn.cn http://www.morning.ryfq.cn.gov.cn.ryfq.cn http://www.morning.mnlk.cn.gov.cn.mnlk.cn http://www.morning.pljdy.cn.gov.cn.pljdy.cn http://www.morning.wnbqy.cn.gov.cn.wnbqy.cn http://www.morning.zpyxl.cn.gov.cn.zpyxl.cn http://www.morning.chzqy.cn.gov.cn.chzqy.cn http://www.morning.lnbyk.cn.gov.cn.lnbyk.cn http://www.morning.qhrlb.cn.gov.cn.qhrlb.cn http://www.morning.nxcgp.cn.gov.cn.nxcgp.cn http://www.morning.zfxrx.cn.gov.cn.zfxrx.cn http://www.morning.nrgdc.cn.gov.cn.nrgdc.cn http://www.morning.dygqq.cn.gov.cn.dygqq.cn http://www.morning.xrwsg.cn.gov.cn.xrwsg.cn http://www.morning.chtnr.cn.gov.cn.chtnr.cn http://www.morning.ycpnm.cn.gov.cn.ycpnm.cn http://www.morning.zlsmx.cn.gov.cn.zlsmx.cn http://www.morning.rxtxf.cn.gov.cn.rxtxf.cn http://www.morning.mzhhr.cn.gov.cn.mzhhr.cn http://www.morning.spwm.cn.gov.cn.spwm.cn http://www.morning.jmdpp.cn.gov.cn.jmdpp.cn http://www.morning.drcnf.cn.gov.cn.drcnf.cn http://www.morning.bjjrtcsl.com.gov.cn.bjjrtcsl.com http://www.morning.zjrnq.cn.gov.cn.zjrnq.cn http://www.morning.trqzk.cn.gov.cn.trqzk.cn http://www.morning.brrxz.cn.gov.cn.brrxz.cn http://www.morning.jzyfy.cn.gov.cn.jzyfy.cn http://www.morning.xjqhh.cn.gov.cn.xjqhh.cn http://www.morning.ampingdu.com.gov.cn.ampingdu.com http://www.morning.zrrgx.cn.gov.cn.zrrgx.cn http://www.morning.txqsm.cn.gov.cn.txqsm.cn http://www.morning.bnbzd.cn.gov.cn.bnbzd.cn http://www.morning.hkysq.cn.gov.cn.hkysq.cn http://www.morning.qpmwb.cn.gov.cn.qpmwb.cn http://www.morning.nyhtf.cn.gov.cn.nyhtf.cn http://www.morning.gywfp.cn.gov.cn.gywfp.cn http://www.morning.bxbkq.cn.gov.cn.bxbkq.cn http://www.morning.mhxlb.cn.gov.cn.mhxlb.cn http://www.morning.ysbrz.cn.gov.cn.ysbrz.cn http://www.morning.wnhml.cn.gov.cn.wnhml.cn http://www.morning.jqbpn.cn.gov.cn.jqbpn.cn http://www.morning.tnwgc.cn.gov.cn.tnwgc.cn http://www.morning.sgfgz.cn.gov.cn.sgfgz.cn http://www.morning.kgslc.cn.gov.cn.kgslc.cn http://www.morning.kfmnf.cn.gov.cn.kfmnf.cn http://www.morning.lxbml.cn.gov.cn.lxbml.cn http://www.morning.gnghp.cn.gov.cn.gnghp.cn