code refactor

This commit is contained in:
MaysWind
2023-08-06 23:43:55 +08:00
parent 9b2fba9600
commit c6d38bb3d7
8 changed files with 40 additions and 150 deletions
+3 -22
View File
@@ -28,6 +28,8 @@
</template>
<script>
import { scrollToSelectedItem } from '@/lib/ui.mobile.js';
export default {
props: [
'modelValue',
@@ -72,7 +74,7 @@ export default {
},
onSheetOpen(event) {
this.currentValue = this.modelValue;
this.scrollToSelectedItem(event.$el);
scrollToSelectedItem(event.$el, '.page-content', '.row-has-selected-item');
},
onSheetClosed() {
this.$emit('update:show', false);
@@ -89,27 +91,6 @@ export default {
}
return false;
},
scrollToSelectedItem(parent) {
if (!parent || !parent.length) {
return;
}
const container = parent.find('.page-content');
const selectedItem = parent.find('.row-has-selected-item');
if (!container.length || !selectedItem.length) {
return;
}
let targetPos = selectedItem.offset().top - container.offset().top - parseInt(container.css('padding-top'), 10)
- (container.outerHeight() - selectedItem.outerHeight()) / 2;
if (targetPos <= 0) {
return;
}
container.scrollTop(targetPos);
}
}
}
+3 -22
View File
@@ -28,6 +28,8 @@
</template>
<script>
import { scrollToSelectedItem } from '@/lib/ui.mobile.js';
export default {
props: [
'modelValue',
@@ -92,7 +94,7 @@ export default {
},
onSheetOpen(event) {
this.currentValue = this.modelValue;
this.scrollToSelectedItem(event.$el);
scrollToSelectedItem(event.$el, '.page-content', '.row-has-selected-item');
},
onSheetClosed() {
this.$emit('update:show', false);
@@ -109,27 +111,6 @@ export default {
}
return false;
},
scrollToSelectedItem(parent) {
if (!parent || !parent.length) {
return;
}
const container = parent.find('.page-content');
const selectedItem = parent.find('.row-has-selected-item');
if (!container.length || !selectedItem.length) {
return;
}
let targetPos = selectedItem.offset().top - container.offset().top - parseInt(container.css('padding-top'), 10)
- (container.outerHeight() - selectedItem.outerHeight()) / 2;
if (targetPos <= 0) {
return;
}
container.scrollTop(targetPos);
}
}
}
@@ -31,6 +31,8 @@
</template>
<script>
import { scrollToSelectedItem } from '@/lib/ui.mobile.js';
export default {
props: [
'modelValue',
@@ -93,7 +95,7 @@ export default {
},
onSheetOpen(event) {
this.currentValue = this.modelValue;
this.scrollToSelectedItem(event.$el);
scrollToSelectedItem(event.$el, '.page-content', 'li.list-item-selected');
},
onSheetClosed() {
this.close();
@@ -109,27 +111,6 @@ export default {
}
}
},
scrollToSelectedItem(parent) {
if (!parent || !parent.length) {
return;
}
const container = parent.find('.page-content');
const selectedItem = parent.find('li.list-item-selected');
if (!container.length || !selectedItem.length) {
return;
}
let targetPos = selectedItem.offset().top - container.offset().top - parseInt(container.css('padding-top'), 10)
- (container.outerHeight() - selectedItem.outerHeight()) / 2;
if (targetPos <= 0) {
return;
}
container.scrollTop(targetPos);
},
close() {
this.$emit('update:show', false);
}
@@ -40,6 +40,7 @@
<script>
import { isArray } from '@/lib/common.js';
import { scrollToSelectedItem } from '@/lib/ui.mobile.js';
export default {
props: [
@@ -101,7 +102,7 @@ export default {
methods: {
onSheetOpen(event) {
this.currentValue = this.modelValue;
this.scrollToSelectedItem(event.$el);
scrollToSelectedItem(event.$el, '.page-content', '.treeview-item .treeview-item-selected');
},
onSheetClosed() {
this.$emit('update:show', false);
@@ -135,27 +136,6 @@ export default {
} else {
return this.currentValue === subItem;
}
},
scrollToSelectedItem(parent) {
if (!parent || !parent.length) {
return;
}
const container = parent.find('.page-content');
const selectedItem = parent.find('.treeview-item .treeview-item-selected');
if (!container.length || !selectedItem.length) {
return;
}
let targetPos = selectedItem.offset().top - container.offset().top - parseInt(container.css('padding-top'), 10)
- (container.outerHeight() - selectedItem.outerHeight()) / 2;
if (targetPos <= 0) {
return;
}
container.scrollTop(targetPos);
}
}
}
@@ -61,6 +61,7 @@
<script>
import { isArray } from '@/lib/common.js';
import { scrollToSelectedItem } from '@/lib/ui.mobile.js';
export default {
props: [
@@ -138,8 +139,8 @@ export default {
onSheetOpen(event) {
this.currentPrimaryValue = this.getPrimaryValueBySecondaryValue(this.modelValue);
this.currentSecondaryValue = this.modelValue;
this.scrollToSelectedItem(event.$el, '.primary-list-container', 'li.primary-list-item-selected');
this.scrollToSelectedItem(event.$el, '.secondary-list-container', 'li.secondary-list-item-selected');
scrollToSelectedItem(event.$el, '.primary-list-container', 'li.primary-list-item-selected');
scrollToSelectedItem(event.$el, '.secondary-list-container', 'li.secondary-list-item-selected');
},
onSheetClosed() {
this.close();
@@ -216,27 +217,6 @@ export default {
return null;
},
scrollToSelectedItem(parent, containerSelector, selectedItemSelector) {
if (!parent || !parent.length) {
return;
}
const container = parent.find(containerSelector);
const selectedItem = parent.find(selectedItemSelector);
if (!container.length || !selectedItem.length) {
return;
}
let targetPos = selectedItem.offset().top - container.offset().top - parseInt(container.css('padding-top'), 10)
- (container.outerHeight() - selectedItem.outerHeight()) / 2;
if (targetPos <= 0) {
return;
}
container.scrollTop(targetPos);
},
close() {
this.$emit('update:show', false);
}