From efbb5ae569e7c40b5da427c0e85209b16562dcdb Mon Sep 17 00:00:00 2001
From: pengjun <158915633@qq.com>
Date: Fri, 3 Nov 2023 17:03:05 +0800
Subject: [PATCH] ente2tab
---
.../customerOrg/customerOrgEdit.vue | 28 +++++---
.../patientRegister/PatientRegisterEdit.vue | 52 +++++++-------
src/utlis/getKeyDown.js | 72 +++++++++++++++++++
3 files changed, 115 insertions(+), 37 deletions(-)
create mode 100644 src/utlis/getKeyDown.js
diff --git a/src/components/customerOrg/customerOrgEdit.vue b/src/components/customerOrg/customerOrgEdit.vue
index 695ba0f..5ac404e 100644
--- a/src/components/customerOrg/customerOrgEdit.vue
+++ b/src/components/customerOrg/customerOrgEdit.vue
@@ -15,12 +15,12 @@
-
+
-
+
@@ -45,7 +45,7 @@
-
-
+
-
+
-
+
@@ -112,17 +112,17 @@
-
+
-
+
-
+
@@ -130,7 +130,7 @@
-
-
+
@@ -207,6 +207,7 @@
import { mapState, mapMutations } from "vuex";
import { getapi, postapi, putapi, deletapi } from "@/api/api";
import { tcdate, objCopy, deepCopy, arrayExistObj } from "../../utlis/proFunc";
+import { getKeyDown } from '../../utlis/getKeyDown'
import { getTreeNode, getTreePids } from "../../utlis/tree";
export default {
@@ -260,6 +261,7 @@ export default {
},
created() {
+ getKeyDown('enterToTab')
this.peisid = window.sessionStorage.getItem("peisid");
if (!this.form.id) {
this.form.organizationUnitId = this.peisid;
@@ -408,6 +410,10 @@ export default {
}
},
+ onkeyup(e){
+ console.log('onkeyup e',e)
+ },
+
//提交
btnSubmit(formName) {
let body = {};
diff --git a/src/components/patientRegister/PatientRegisterEdit.vue b/src/components/patientRegister/PatientRegisterEdit.vue
index 29942cc..e4f5312 100644
--- a/src/components/patientRegister/PatientRegisterEdit.vue
+++ b/src/components/patientRegister/PatientRegisterEdit.vue
@@ -44,29 +44,29 @@
-
+
-
+
-
-
+
-
@@ -79,27 +79,27 @@
-
+
-
+
-
+
-
+
-
@@ -111,12 +111,12 @@
-
+
-
@@ -125,7 +125,7 @@
-
+
@@ -134,7 +134,7 @@
-
@@ -146,7 +146,7 @@
-
@@ -155,28 +155,28 @@
-
+
-
+
-
+
-
-
+
@@ -194,7 +194,7 @@
-
@@ -251,7 +251,7 @@
-
-
-
+
@@ -628,7 +628,7 @@ import moment from "moment";
import { mapState, mapActions } from "vuex";
import { getapi, postapi, putapi, deletapi } from "@/api/api";
import mm from "../../utlis/mm";
-
+import { getKeyDown } from '../../utlis/getKeyDown'
import { objCopy, setNull, dddw,checkIDCode, parseID, birthdayToAge,ageToBirthday, deepCopy, arrayFilter, arrayReduce,parsIcCardtoLocal, photoParse, savePeoplePhoto, arrayExistObj } from "../../utlis/proFunc";
import Camera from "./Camera.vue";
import PatientRegisterItem from "./PatientRegisterItem.vue";
@@ -750,7 +750,7 @@ export default {
},
created() {
-
+ getKeyDown('enterToTab')
},
//挂载完成
diff --git a/src/utlis/getKeyDown.js b/src/utlis/getKeyDown.js
new file mode 100644
index 0000000..018d2ea
--- /dev/null
+++ b/src/utlis/getKeyDown.js
@@ -0,0 +1,72 @@
+// 通过绑定输入框的 class 来实现enter 代替 tab 的功能
+/*
+ 示例:
+ import { getKeyUp } from '../../utlis/getKeyUp'
+
+ created() {
+ getKeyUp('enterToTab')
+ }
+
+*/
+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(); //for firefox
+ }
+ // 标记当前组件为true
+ if(e.target.tagName === 'INPUT'){
+ e.target.autofocus = true;
+ }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;
+ }
+ }
+ }
+ }
\ No newline at end of file