MOD: 调整回车键逻辑

This commit is contained in:
yanglinbj01
2021-09-08 00:56:45 +08:00
parent 476cafdc4a
commit 96178012d4
2 changed files with 47 additions and 7 deletions

File diff suppressed because one or more lines are too long

View File

@@ -9,6 +9,7 @@ class App{
#life; #life;
#pages; #pages;
#currentPage;
#talentSelected = new Set(); #talentSelected = new Set();
#totalMax=20; #totalMax=20;
#isEnd = false; #isEnd = false;
@@ -23,6 +24,14 @@ class App{
window.onerror = (event, source, lineno, colno, error) => { window.onerror = (event, source, lineno, colno, error) => {
this.hint(`[ERROR] at (${source}:${lineno}:${colno})\n\n${error?.stack||error||'unknow Error'}`, 'error'); this.hint(`[ERROR] at (${source}:${lineno}:${colno})\n\n${error?.stack||error||'unknow Error'}`, 'error');
} }
const keyDownCallback = (keyboardEvent) => {
if (keyboardEvent.which === 13 || keyboardEvent.keyCode === 13) {
const pressEnterFunc = this.#pages[this.#currentPage]?.pressEnter;
pressEnterFunc && typeof pressEnterFunc === 'function' && pressEnterFunc();
}
}
window.removeEventListener('keydown', keyDownCallback);
window.addEventListener('keydown', keyDownCallback);
} }
initPages() { initPages() {
@@ -273,11 +282,11 @@ class App{
}); });
this.switch('trajectory'); this.switch('trajectory');
this.#pages.trajectory.born(); this.#pages.trajectory.born();
$(document).keydown(function(event){ // $(document).keydown(function(event){
if(event.which == 32 || event.which == 13){ // if(event.which == 32 || event.which == 13){
$('#lifeTrajectory').click(); // $('#lifeTrajectory').click();
} // }
}) // })
}); });
// Trajectory // Trajectory
@@ -391,7 +400,9 @@ class App{
this.#pages = { this.#pages = {
loading: { loading: {
page: loadingPage, page: loadingPage,
clear: ()=>{}, clear: ()=>{
this.#currentPage = 'loading';
},
}, },
index: { index: {
@@ -400,7 +411,11 @@ class App{
btnRestart: indexPage.find('#restart'), btnRestart: indexPage.find('#restart'),
hint: indexPage.find('.hint'), hint: indexPage.find('.hint'),
cnt: indexPage.find('#cnt'), cnt: indexPage.find('#cnt'),
pressEnter: ()=>{
this.#pages.index.btnRestart.click();
},
clear: ()=>{ clear: ()=>{
this.#currentPage = 'index';
indexPage.find('.hint').hide(); indexPage.find('.hint').hide();
const times = this.times; const times = this.times;
@@ -419,7 +434,21 @@ class App{
}, },
talent: { talent: {
page: talentPage, page: talentPage,
talentList: talentPage.find('#talents'),
btnRandom: talentPage.find('#random'),
btnNext: talentPage.find('#next'),
pressEnter: ()=>{
const talentList = this.#pages.talent.talentList;
const btnRandom = this.#pages.talent.btnRandom;
const btnNext = this.#pages.talent.btnNext;
if (talentList.children().length) {
btnNext.click();
} else {
btnRandom.click();
}
},
clear: ()=>{ clear: ()=>{
this.#currentPage = 'talent';
talentPage.find('ul.selectlist').empty(); talentPage.find('ul.selectlist').empty();
talentPage.find('#random').show(); talentPage.find('#random').show();
this.#totalMax = 20; this.#totalMax = 20;
@@ -427,7 +456,12 @@ class App{
}, },
property: { property: {
page: propertyPage, page: propertyPage,
btnStart: propertyPage.find('#start'),
pressEnter: ()=>{
this.#pages.property.btnStart.click();
},
clear: ()=>{ clear: ()=>{
this.#currentPage = 'property';
freshTotal(); freshTotal();
propertyPage propertyPage
.find('#talentSelectedView') .find('#talentSelectedView')
@@ -436,7 +470,12 @@ class App{
}, },
trajectory: { trajectory: {
page: trajectoryPage, page: trajectoryPage,
lifeTrajectory: trajectoryPage.find('#lifeTrajectory'),
pressEnter: ()=>{
this.#pages.trajectory.lifeTrajectory.click();
},
clear: ()=>{ clear: ()=>{
this.#currentPage = 'trajectory';
trajectoryPage.find('#lifeTrajectory').empty(); trajectoryPage.find('#lifeTrajectory').empty();
trajectoryPage.find('#summary').hide(); trajectoryPage.find('#summary').hide();
this.#isEnd = false; this.#isEnd = false;
@@ -448,6 +487,7 @@ class App{
summary: { summary: {
page: summaryPage, page: summaryPage,
clear: ()=>{ clear: ()=>{
this.#currentPage = 'summary';
const judge = summaryPage.find('#judge'); const judge = summaryPage.find('#judge');
const talents = summaryPage.find('#talents'); const talents = summaryPage.find('#talents');
judge.empty(); judge.empty();