mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-16 07:57:33 +08:00
auto scroll to selected item
This commit is contained in:
@@ -8,7 +8,9 @@
|
||||
</f7-toolbar>
|
||||
<f7-page-content>
|
||||
<f7-block class="margin-vertical">
|
||||
<f7-row class="padding-vertical padding-horizontal-half" v-for="(row, idx) in allColorRows" :key="idx">
|
||||
<f7-row class="padding-vertical padding-horizontal-half"
|
||||
:class="{ 'row-has-selected-item': hasSelectedIcon(row) }"
|
||||
v-for="(row, idx) in allColorRows" :key="idx">
|
||||
<f7-col class="text-align-center" v-for="colorInfo in row" :key="colorInfo.color">
|
||||
<f7-icon f7="app_fill"
|
||||
:style="colorInfo.color | iconStyle('default', 'var(--default-icon-color)')"
|
||||
@@ -65,11 +67,46 @@ export default {
|
||||
this.$emit('input', this.currentValue);
|
||||
this.$emit('update:show', false);
|
||||
},
|
||||
onSheetOpen() {
|
||||
onSheetOpen(event) {
|
||||
this.currentValue = this.value;
|
||||
this.scrollToSelectedItem(event.$el);
|
||||
},
|
||||
onSheetClosed() {
|
||||
this.$emit('update:show', false);
|
||||
},
|
||||
hasSelectedIcon(row) {
|
||||
if (!this.currentValue || !row || !row.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (let i = 0; i < row.length; i++) {
|
||||
if (row[i].id === this.currentValue) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
scrollToSelectedItem(parent) {
|
||||
if (!parent || !parent.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
const container = parent.find('.page-content');
|
||||
const selectedItem = parent.find('.row.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,9 @@
|
||||
</f7-toolbar>
|
||||
<f7-page-content>
|
||||
<f7-block class="margin-vertical">
|
||||
<f7-row class="padding-vertical-half padding-horizontal-half" v-for="(row, idx) in allIconRows" :key="idx">
|
||||
<f7-row class="padding-vertical-half padding-horizontal-half"
|
||||
:class="{ 'row-has-selected-item': hasSelectedIcon(row) }"
|
||||
v-for="(row, idx) in allIconRows" :key="idx">
|
||||
<f7-col class="text-align-center" v-for="iconInfo in row" :key="iconInfo.id">
|
||||
<f7-icon :icon="iconInfo.icon"
|
||||
:style="color | iconStyle('default', 'var(--default-icon-color)')"
|
||||
@@ -79,11 +81,46 @@ export default {
|
||||
this.$emit('input', this.currentValue);
|
||||
this.$emit('update:show', false);
|
||||
},
|
||||
onSheetOpen() {
|
||||
onSheetOpen(event) {
|
||||
this.currentValue = this.value;
|
||||
this.scrollToSelectedItem(event.$el);
|
||||
},
|
||||
onSheetClosed() {
|
||||
this.$emit('update:show', false);
|
||||
},
|
||||
hasSelectedIcon(row) {
|
||||
if (!this.currentValue || !row || !row.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (let i = 0; i < row.length; i++) {
|
||||
if (row[i].id === this.currentValue) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
scrollToSelectedItem(parent) {
|
||||
if (!parent || !parent.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
const container = parent.find('.page-content');
|
||||
const selectedItem = parent.find('.row.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
<f7-list-item link="#" no-chevron
|
||||
v-for="(item, index) in items"
|
||||
:key="item | itemKeyValue(index, keyField, valueType)"
|
||||
:class="{ 'list-item-selected': isSelected(item, index) }"
|
||||
:value="item | itemKeyValue(index, valueField, valueType)"
|
||||
:title="item | itemFieldContent(titleField, item, titleI18n)"
|
||||
@click="onItemClicked(item, index)">
|
||||
@@ -67,8 +68,9 @@ export default {
|
||||
this.$emit('input', this.currentValue);
|
||||
this.$emit('update:show', false);
|
||||
},
|
||||
onSheetOpen() {
|
||||
onSheetOpen(event) {
|
||||
this.currentValue = this.value;
|
||||
this.scrollToSelectedItem(event.$el);
|
||||
},
|
||||
onSheetClosed() {
|
||||
this.$emit('update:show', false);
|
||||
@@ -83,6 +85,27 @@ export default {
|
||||
return this.currentValue === item;
|
||||
}
|
||||
}
|
||||
},
|
||||
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);
|
||||
}
|
||||
},
|
||||
filters: {
|
||||
|
||||
@@ -84,8 +84,9 @@ export default {
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
onSheetOpen() {
|
||||
onSheetOpen(event) {
|
||||
this.currentValue = this.value;
|
||||
this.scrollToSelectedItem(event.$el);
|
||||
},
|
||||
onSheetClosed() {
|
||||
this.$emit('update:show', false);
|
||||
@@ -119,6 +120,27 @@ 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
<f7-list-item link="#" no-chevron
|
||||
v-for="item in items"
|
||||
:key="item | itemFieldContent(primaryKeyField, item, false)"
|
||||
:class="{ 'primary-list-item-selected': item === selectedPrimaryItem }"
|
||||
:value="item | itemFieldContent(primaryValueField, item, false)"
|
||||
:title="item | itemFieldContent(primaryTitleField, null, primaryTitleI18n)"
|
||||
:header="item | itemFieldContent(primaryHeaderField, null, primaryHeaderI18n)"
|
||||
@@ -34,6 +35,7 @@
|
||||
<f7-list-item link="#" no-chevron
|
||||
v-for="subItem in selectedPrimaryItem[primarySubItemsField]"
|
||||
:key="subItem | itemFieldContent(secondaryKeyField, subItem, false)"
|
||||
:class="{ 'secondary-list-item-selected': isSecondarySelected(subItem) }"
|
||||
:value="subItem | itemFieldContent(secondaryValueField, subItem, false)"
|
||||
:title="subItem | itemFieldContent(secondaryTitleField, null, secondaryTitleI18n)"
|
||||
:header="subItem | itemFieldContent(secondaryHeaderField, null, secondaryHeaderI18n)"
|
||||
@@ -123,9 +125,11 @@ export default {
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
onSheetOpen() {
|
||||
onSheetOpen(event) {
|
||||
this.currentPrimaryValue = this.getPrimaryValueBySecondaryValue(this.value);
|
||||
this.currentSecondaryValue = this.value;
|
||||
this.scrollToSelectedItem(event.$el, '.primary-list-container', 'li.primary-list-item-selected');
|
||||
this.scrollToSelectedItem(event.$el, '.secondary-list-container', 'li.secondary-list-item-selected');
|
||||
},
|
||||
onSheetClosed() {
|
||||
this.$emit('update:show', false);
|
||||
@@ -201,6 +205,27 @@ 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user