From fb17e53f117a87d86206ca4d7be237ab3177ab1c Mon Sep 17 00:00:00 2001 From: pengjun <158915633@qq.com> Date: Mon, 6 Nov 2023 11:09:43 +0800 Subject: [PATCH] outshell --- .../patientRegister/PatientRegisterEdit.vue | 2 +- src/utlis/getKeyDown.js | 83 ++++++++++++++++++- src/views/login/Login.vue | 7 +- 3 files changed, 87 insertions(+), 5 deletions(-) diff --git a/src/components/patientRegister/PatientRegisterEdit.vue b/src/components/patientRegister/PatientRegisterEdit.vue index e4f5312..fbf3b39 100644 --- a/src/components/patientRegister/PatientRegisterEdit.vue +++ b/src/components/patientRegister/PatientRegisterEdit.vue @@ -271,7 +271,7 @@ - + diff --git a/src/utlis/getKeyDown.js b/src/utlis/getKeyDown.js index 018d2ea..a936ad0 100644 --- a/src/utlis/getKeyDown.js +++ b/src/utlis/getKeyDown.js @@ -8,8 +8,81 @@ } */ -export function getKeyDown(className){ +export function getKeyDown(className) { //当前页面监视键盘输入 onkeyup /onkeydown + document.onkeydown = function (e) { + //e.keyCode === 13 + if(e.key == 'Enter'){ + // 阻止文本框的换行 + // if(window.event){ + // window.event.returnValue = false; + // }else{ + // e.preventDefault(); // 阻止默认行为 + // } + + // 标记当前组件为true + if(e.target.tagName === 'INPUT'){ + e.target.autofocus = true; + + e.preventDefault(); // 阻止默认行为 + } + // else if(e.target.tagName === 'TEXTAREA'){ + // e.target.autofocus = true; + // }else{ + // e.target.firstChild.autofocus = true; + // } + + // 获取所有需要定位的组件 + let arr = document.querySelectorAll("."+className); + let index2 = -1; + arr.forEach((i,index) => { + if(i.querySelectorAll("input")[0]){ + if(i.querySelectorAll("input")[0].autofocus){ + index2 = index; + } + } + // else if(i.querySelectorAll("textarea")[0]){ + // if(i.querySelectorAll("textarea")[0].autofocus){ + // index2 = index; + // } + // }else{ + // // 暂无其他 + // } + }) + // 超出返回第一个组件 + if(index2 + 1 >= arr.length){ + index2 = -1; + } + // 聚焦到下一个组件中 + if(arr[index2 + 1].querySelectorAll("input")[0]){ + if(arr[index2 + 1].querySelectorAll("input")[0].type === 'hidden'){ + arr[index2 + 1].querySelectorAll("input")[0].parentElement.focus(); + }else{ + arr[index2 + 1].querySelectorAll("input")[0].focus(); + } + } + // else if(arr[index2 + 1].querySelectorAll("textarea")[0]){ + // arr[index2 + 1].querySelectorAll("textarea")[0].focus(); + // }else{ + // // 暂无其他 + // } + + // 重置当前组件为false + if(e.target.tagName === 'INPUT'){ + e.target.autofocus = false; + } + // else if(e.target.tagName === 'TEXTAREA'){ + // e.target.autofocus = false; + // }else{ + // e.target.firstChild.autofocus = false; + // } + } + } +} + +/* +export function getKeyDown(className){ + //当前页面监视键盘输入 onkeyup /onkeydown document.activeElement document.onkeydown = function(e) { //e.keyCode === 13 if(e.key == 'Enter'){ @@ -17,8 +90,9 @@ export function getKeyDown(className){ if(window.event){ window.event.returnValue = false; }else{ - e.preventDefault(); //for firefox + e.preventDefault(); // 阻止默认行为 } + // 标记当前组件为true if(e.target.tagName === 'INPUT'){ e.target.autofocus = true; @@ -27,6 +101,7 @@ export function getKeyDown(className){ }else{ e.target.firstChild.autofocus = true; } + // 获取所有需要定位的组件 let arr = document.querySelectorAll("."+className); let index2 = -1; @@ -59,6 +134,7 @@ export function getKeyDown(className){ }else{ // 暂无其他 } + // 重置当前组件为false if(e.target.tagName === 'INPUT'){ e.target.autofocus = false; @@ -69,4 +145,5 @@ export function getKeyDown(className){ } } } - } \ No newline at end of file +} +*/ \ No newline at end of file diff --git a/src/views/login/Login.vue b/src/views/login/Login.vue index bf6b7ca..91d01b4 100644 --- a/src/views/login/Login.vue +++ b/src/views/login/Login.vue @@ -65,7 +65,12 @@ export default { }, methods: { onSubmit() { - // + + // 壳程序懒加载通讯组件 + if(this.$peisAPI){ + this.$peisAPI.lazyLoad(); + } + this.$refs.form.validate((valid) => { if (valid) { var msgs = "";