hookehuyr

fix 弹出框功能适配

...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
13 </div> 13 </div>
14 <van-field 14 <van-field
15 v-model="item.value" 15 v-model="item.value"
16 + :id="item.name"
16 :name="item.name" 17 :name="item.name"
17 :placeholder="item.component_props.placeholder" 18 :placeholder="item.component_props.placeholder"
18 :rules="rules" 19 :rules="rules"
...@@ -36,15 +37,33 @@ ...@@ -36,15 +37,33 @@
36 37
37 <script setup> 38 <script setup>
38 import $ from "jquery"; 39 import $ from "jquery";
40 +import { storeToRefs, mainStore } from "@/utils/generatePackage";
39 41
40 const props = defineProps({ 42 const props = defineProps({
41 item: Object, 43 item: Object,
42 }); 44 });
43 45
44 const show = ref(false); 46 const show = ref(false);
47 +let content = "";
48 +
49 +const store = mainStore();
50 +const { fieldName } = storeToRefs(store);
51 +
52 +// 监听字段变化
53 +watch(
54 + () => fieldName.value,
55 + (v) => {
56 + // 如果不是点击本输入框
57 + if (v !== props.item.name) {
58 + // 还原border颜色
59 + $(`#${props.item.name}`).parent().css("border-color", "#eaeaea");
60 + show.value = false;
61 + document.getElementById("app").style.paddingBottom = "0";
62 + }
63 + }
64 +);
45 65
46 const openKeyboard = (e) => { 66 const openKeyboard = (e) => {
47 - show.value = true;
48 // 键盘上移动 67 // 键盘上移动
49 const target_to_view_height = window.innerHeight - e.target.getBoundingClientRect().y; // 元素到适口高度 68 const target_to_view_height = window.innerHeight - e.target.getBoundingClientRect().y; // 元素到适口高度
50 const target_top = document.body.scrollHeight - $(e.target).offset().top; // 元素到正文高度 69 const target_top = document.body.scrollHeight - $(e.target).offset().top; // 元素到正文高度
...@@ -53,12 +72,24 @@ const openKeyboard = (e) => { ...@@ -53,12 +72,24 @@ const openKeyboard = (e) => {
53 document.getElementById("app").style.paddingBottom = "244px"; 72 document.getElementById("app").style.paddingBottom = "244px";
54 window.scrollTo(0, $("#app").height()); 73 window.scrollTo(0, $("#app").height());
55 } else { 74 } else {
75 + // 向上滚动位置
56 document.documentElement.scrollTop = target_top + 244; 76 document.documentElement.scrollTop = target_top + 244;
57 } 77 }
78 + // 选中添加border颜色
79 + content = $(e.target).parent();
80 + // TAG: 自定义主题颜色
81 + content.css("border-color", "#c2915f");
82 + setTimeout(() => {
83 + show.value = true;
84 + }, 300);
85 + // 记录点击field名
86 + store.changeFieldName(props.item.name);
58 }; 87 };
59 const blurKeyboard = () => { 88 const blurKeyboard = () => {
60 show.value = false; 89 show.value = false;
61 document.getElementById("app").style.paddingBottom = "0"; 90 document.getElementById("app").style.paddingBottom = "0";
91 + // 还原border颜色
92 + content.css("border-color", "#eaeaea");
62 }; 93 };
63 94
64 // 校验函数返回 true 表示校验通过,false 表示不通过 95 // 校验函数返回 true 表示校验通过,false 表示不通过
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
13 </div> 13 </div>
14 <van-field 14 <van-field
15 v-model="item.value" 15 v-model="item.value"
16 + :id="item.name"
16 :name="item.name" 17 :name="item.name"
17 :placeholder="item.component_props.placeholder" 18 :placeholder="item.component_props.placeholder"
18 :rules="item.rules" 19 :rules="item.rules"
...@@ -44,19 +45,37 @@ ...@@ -44,19 +45,37 @@
44 45
45 <script setup> 46 <script setup>
46 import $ from "jquery"; 47 import $ from "jquery";
48 +import { storeToRefs, mainStore } from "@/utils/generatePackage";
47 49
48 const props = defineProps({ 50 const props = defineProps({
49 item: Object, 51 item: Object,
50 }); 52 });
53 +let content = "";
51 54
52 -const showKeyboard = (e) => { 55 +const store = mainStore();
53 - if (props.item.component_props.type === "decimal") { 56 +const { fieldName } = storeToRefs(store);
54 - // 显示小数键盘 57 +
55 - showDecimal.value = true; 58 +// 监听字段变化
56 - } else { 59 +watch(
57 - // 显示整数键盘 60 + () => fieldName.value,
58 - showInteger.value = true; 61 + (v) => {
62 + // 如果不是点击本输入框
63 + if (v !== props.item.name) {
64 + // 还原border颜色
65 + $(`#${props.item.name}`).parent().css("border-color", "#eaeaea");
66 + if (props.item.component_props.type === "decimal") {
67 + // 显示小数键盘
68 + showDecimal.value = false;
69 + } else {
70 + // 显示整数键盘
71 + showInteger.value = false;
72 + }
73 + document.getElementById("app").style.paddingBottom = "0";
74 + }
59 } 75 }
76 +);
77 +
78 +const showKeyboard = (e) => {
60 // 键盘上移动 79 // 键盘上移动
61 // const target_to_view_height = window.innerHeight - e.target.getBoundingClientRect().y; // 元素到适口高度 80 // const target_to_view_height = window.innerHeight - e.target.getBoundingClientRect().y; // 元素到适口高度
62 const target_top = document.body.scrollHeight - $(e.target).offset().top; // 元素到正文高度 81 const target_top = document.body.scrollHeight - $(e.target).offset().top; // 元素到正文高度
...@@ -65,8 +84,24 @@ const showKeyboard = (e) => { ...@@ -65,8 +84,24 @@ const showKeyboard = (e) => {
65 if (target_top < 244) { 84 if (target_top < 244) {
66 window.scrollTo(0, $("#app").height()); 85 window.scrollTo(0, $("#app").height());
67 } else { 86 } else {
87 + // 向上滚动位置
68 document.documentElement.scrollTop = target_top + 244; 88 document.documentElement.scrollTop = target_top + 244;
69 } 89 }
90 + // 选中添加border颜色
91 + content = $(e.target).parent();
92 + // TAG: 自定义主题颜色
93 + content.css("border-color", "#c2915f");
94 + setTimeout(() => {
95 + if (props.item.component_props.type === "decimal") {
96 + // 显示小数键盘
97 + showDecimal.value = true;
98 + } else {
99 + // 显示整数键盘
100 + showInteger.value = true;
101 + }
102 + }, 300);
103 + // 记录点击field名
104 + store.changeFieldName(props.item.name);
70 }; 105 };
71 const blurKeyboard = () => { 106 const blurKeyboard = () => {
72 if (props.item.component_props.type === "decimal") { 107 if (props.item.component_props.type === "decimal") {
...@@ -77,6 +112,8 @@ const blurKeyboard = () => { ...@@ -77,6 +112,8 @@ const blurKeyboard = () => {
77 showInteger.value = false; 112 showInteger.value = false;
78 } 113 }
79 document.getElementById("app").style.paddingBottom = "0"; 114 document.getElementById("app").style.paddingBottom = "0";
115 + // 还原border颜色
116 + content.css("border-color", "#eaeaea");
80 }; 117 };
81 118
82 const showDecimal = ref(false); 119 const showDecimal = ref(false);
...@@ -123,4 +160,8 @@ const onDelete = () => {}; ...@@ -123,4 +160,8 @@ const onDelete = () => {};
123 border-radius: 0.25rem; 160 border-radius: 0.25rem;
124 padding: 0.25rem 0.5rem; 161 padding: 0.25rem 0.5rem;
125 } 162 }
163 +
164 +:deep(.van-number-keyboard__title) {
165 + font-size: 1.05rem;
166 +}
126 </style> 167 </style>
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
12 <span v-if="item.component_props.required">&nbsp;*</span> 12 <span v-if="item.component_props.required">&nbsp;*</span>
13 </div> 13 </div>
14 <van-field 14 <van-field
15 + :id="item.name"
15 v-model="item.value" 16 v-model="item.value"
16 :name="item.name" 17 :name="item.name"
17 type="digit" 18 type="digit"
...@@ -36,6 +37,7 @@ ...@@ -36,6 +37,7 @@
36 <script setup> 37 <script setup>
37 import { wxInfo } from "@/utils/tools"; 38 import { wxInfo } from "@/utils/tools";
38 import $ from "jquery"; 39 import $ from "jquery";
40 +import { storeToRefs, mainStore } from "@/utils/generatePackage";
39 41
40 const props = defineProps({ 42 const props = defineProps({
41 item: Object, 43 item: Object,
...@@ -64,9 +66,26 @@ const validatorMessage = (val, rule) => { ...@@ -64,9 +66,26 @@ const validatorMessage = (val, rule) => {
64 const rules = [{ validator, message: validatorMessage }]; 66 const rules = [{ validator, message: validatorMessage }];
65 67
66 const show = ref(false); 68 const show = ref(false);
69 +let content = "";
70 +
71 +const store = mainStore();
72 +const { fieldName } = storeToRefs(store);
73 +
74 +// 监听字段变化
75 +watch(
76 + () => fieldName.value,
77 + (v) => {
78 + // 如果不是点击本输入框
79 + if (v !== props.item.name) {
80 + // 还原border颜色
81 + $(`#${props.item.name}`).parent().css("border-color", "#eaeaea");
82 + show.value = false;
83 + document.getElementById("app").style.paddingBottom = "0";
84 + }
85 + }
86 +);
67 87
68 const openKeyboard = (e) => { 88 const openKeyboard = (e) => {
69 - show.value = true;
70 // 键盘上移动 89 // 键盘上移动
71 const target_to_view_height = window.innerHeight - e.target.getBoundingClientRect().y; // 元素到适口高度 90 const target_to_view_height = window.innerHeight - e.target.getBoundingClientRect().y; // 元素到适口高度
72 const target_top = document.body.scrollHeight - $(e.target).offset().top; // 元素到正文高度 91 const target_top = document.body.scrollHeight - $(e.target).offset().top; // 元素到正文高度
...@@ -75,12 +94,24 @@ const openKeyboard = (e) => { ...@@ -75,12 +94,24 @@ const openKeyboard = (e) => {
75 document.getElementById("app").style.paddingBottom = "244px"; 94 document.getElementById("app").style.paddingBottom = "244px";
76 window.scrollTo(0, $("#app").height()); 95 window.scrollTo(0, $("#app").height());
77 } else { 96 } else {
97 + // 向上滚动位置
78 document.documentElement.scrollTop = target_top + 244; 98 document.documentElement.scrollTop = target_top + 244;
79 } 99 }
100 + // 选中添加border颜色
101 + content = $(e.target).parent();
102 + // TAG: 自定义主题颜色
103 + content.css("border-color", "#c2915f");
104 + setTimeout(() => {
105 + show.value = true;
106 + }, 300);
107 + // 记录点击field名
108 + store.changeFieldName(props.item.name);
80 }; 109 };
81 const blurKeyboard = () => { 110 const blurKeyboard = () => {
82 show.value = false; 111 show.value = false;
83 document.getElementById("app").style.paddingBottom = "0"; 112 document.getElementById("app").style.paddingBottom = "0";
113 + // 还原border颜色
114 + content.css("border-color", "#eaeaea");
84 }; 115 };
85 </script> 116 </script>
86 117
......
1 /* 1 /*
2 * @Date: 2022-04-18 15:59:42 2 * @Date: 2022-04-18 15:59:42
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2022-06-13 11:30:40 4 + * @LastEditTime: 2022-11-29 22:37:01
5 - * @FilePath: /tswj/src/store/index.js 5 + * @FilePath: /data-table/src/store/index.js
6 * @Description: 文件描述 6 * @Description: 文件描述
7 */ 7 */
8 import { defineStore } from 'pinia'; 8 import { defineStore } from 'pinia';
...@@ -23,6 +23,7 @@ export const mainStore = defineStore('main', { ...@@ -23,6 +23,7 @@ export const mainStore = defineStore('main', {
23 scrollTopLike: 0, 23 scrollTopLike: 0,
24 scrollTopPerson: 0, 24 scrollTopPerson: 0,
25 keepPages: ['default'], // 很坑爹,空值全部都缓存 25 keepPages: ['default'], // 很坑爹,空值全部都缓存
26 + fieldName: ''
26 }; 27 };
27 }, 28 },
28 getters: { 29 getters: {
...@@ -67,6 +68,9 @@ export const mainStore = defineStore('main', { ...@@ -67,6 +68,9 @@ export const mainStore = defineStore('main', {
67 const $router = useRouter(); 68 const $router = useRouter();
68 const page = $router.currentRoute.value.meta.name; 69 const page = $router.currentRoute.value.meta.name;
69 _.remove(this.keepPages, item => item === page) 70 _.remove(this.keepPages, item => item === page)
71 + },
72 + changeFieldName (v) {
73 + this.fieldName = v;
70 } 74 }
71 }, 75 },
72 }); 76 });
......