企业用户bug修复
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
<input class="uni-input searchinput" confirm-type="search" />
|
||||
</view>
|
||||
<view class="sex-content">
|
||||
<scroll-view :show-scrollbar="false" :scroll-y="true" class="sex-content-left">
|
||||
<scroll-view ref="leftScroll" :show-scrollbar="false" :scroll-y="true" class="sex-content-left">
|
||||
<view
|
||||
v-for="item in copyTree"
|
||||
:key="item.id"
|
||||
@@ -25,6 +25,7 @@
|
||||
@scroll="scrollTopBack"
|
||||
:scroll-y="true"
|
||||
class="sex-content-right"
|
||||
@wheel="handleWheel"
|
||||
>
|
||||
<view v-for="item in rightValue" :key="item.id">
|
||||
<view class="secondary-title">{{ item.label }}</view>
|
||||
@@ -94,9 +95,104 @@ export default {
|
||||
this.leftValue = item;
|
||||
this.rightValue = item.children;
|
||||
this.scrollTop = 0;
|
||||
|
||||
// 确保左侧列表滚动到正确位置,让当前选中的标签可见
|
||||
this.$nextTick(() => {
|
||||
const index = this.copyTree.findIndex(i => i.id === item.id);
|
||||
if (index !== -1 && this.$refs.leftScroll) {
|
||||
// 计算需要滚动的距离(每个选项高度约160rpx)
|
||||
const scrollTop = index * 160;
|
||||
|
||||
// 获取左侧列表的可见高度(假设可见区域能显示约3-4个选项)
|
||||
const visibleHeight = 4 * 160; // 约4个选项的高度
|
||||
|
||||
// 确保选中的标签在可见区域内
|
||||
let targetScrollTop = scrollTop;
|
||||
|
||||
// 如果选中的标签在底部,确保它不会滚动出可见区域
|
||||
if (scrollTop > this.$refs.leftScroll.scrollHeight - visibleHeight) {
|
||||
targetScrollTop = Math.max(0, this.$refs.leftScroll.scrollHeight - visibleHeight);
|
||||
}
|
||||
|
||||
this.$refs.leftScroll.scrollTo({
|
||||
top: targetScrollTop,
|
||||
duration: 300
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
scrollTopBack(e) {
|
||||
this.scrollTop = e.detail.scrollTop;
|
||||
|
||||
// 滚动时自动选中对应的左侧标签
|
||||
const scrollTop = e.detail.scrollTop;
|
||||
let currentSection = null;
|
||||
let minDistance = Infinity;
|
||||
|
||||
// 遍历所有右侧的二级标题,找到当前最接近顶部的那个
|
||||
this.rightValue.forEach((section, index) => {
|
||||
// 估算每个section的位置(假设每个section高度大约为 200rpx)
|
||||
const sectionTop = index * 200;
|
||||
const distance = Math.abs(sectionTop - scrollTop);
|
||||
|
||||
if (distance < minDistance) {
|
||||
minDistance = distance;
|
||||
currentSection = section;
|
||||
}
|
||||
});
|
||||
|
||||
// 如果找到了对应的section,并且不是当前选中的左侧标签,则切换左侧标签
|
||||
if (currentSection && this.leftValue.id !== currentSection.parentId) {
|
||||
const parentItem = this.copyTree.find(item => item.id === currentSection.parentId);
|
||||
if (parentItem) {
|
||||
this.leftValue = parentItem;
|
||||
|
||||
// 确保左侧列表滚动到正确位置,让当前选中的标签可见
|
||||
this.$nextTick(() => {
|
||||
const index = this.copyTree.findIndex(i => i.id === parentItem.id);
|
||||
if (index !== -1 && this.$refs.leftScroll) {
|
||||
// 计算需要滚动的距离(每个选项高度约160rpx)
|
||||
const scrollTop = index * 160;
|
||||
|
||||
// 获取左侧列表的可见高度(假设可见区域能显示约3-4个选项)
|
||||
const visibleHeight = 4 * 160; // 约4个选项的高度
|
||||
|
||||
// 确保选中的标签在可见区域内
|
||||
let targetScrollTop = scrollTop;
|
||||
|
||||
// 如果选中的标签在底部,确保它不会滚动出可见区域
|
||||
if (scrollTop > this.$refs.leftScroll.scrollHeight - visibleHeight) {
|
||||
targetScrollTop = Math.max(0, this.$refs.leftScroll.scrollHeight - visibleHeight);
|
||||
}
|
||||
|
||||
this.$refs.leftScroll.scrollTo({
|
||||
top: targetScrollTop,
|
||||
duration: 300
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
handleWheel(e) {
|
||||
// 处理鼠标滚轮事件,让右侧内容可以滚动
|
||||
e.preventDefault();
|
||||
const delta = e.deltaY || e.wheelDelta;
|
||||
|
||||
// 更平滑的滚动,根据滚轮速度调整滚动量
|
||||
const scrollAmount = Math.abs(delta) > 100 ? 80 : 40;
|
||||
const direction = delta > 0 ? 1 : -1;
|
||||
|
||||
// 更新scrollTop来模拟滚动
|
||||
this.scrollTop += scrollAmount * direction;
|
||||
|
||||
// 确保scrollTop在合理范围内
|
||||
this.scrollTop = Math.max(0, this.scrollTop);
|
||||
|
||||
// 触发scroll事件来更新左侧标签选中状态
|
||||
this.$nextTick(() => {
|
||||
this.scrollTopBack({ detail: { scrollTop: this.scrollTop } });
|
||||
});
|
||||
},
|
||||
addItem(item) {
|
||||
let titiles = [];
|
||||
|
||||
@@ -125,6 +125,12 @@ const cleanup = () => {
|
||||
};
|
||||
|
||||
const changeJobTitleId = (e) => {
|
||||
if (!e.ids) {
|
||||
count.value = 0;
|
||||
JobsIdsValue.value = '';
|
||||
JobsLabelValue.value = '';
|
||||
return;
|
||||
}
|
||||
const ids = e.ids.split(',').map((id) => Number(id));
|
||||
count.value = ids.length;
|
||||
JobsIdsValue.value = e.ids;
|
||||
@@ -147,9 +153,9 @@ function serchforIt(defaultId) {
|
||||
if (state.stations.length) {
|
||||
const ids = defaultId
|
||||
? defaultId.split(',').map((id) => Number(id))
|
||||
: userInfo.value.jobTitleId.split(',').map((id) => Number(id));
|
||||
: (userInfo.value.jobTitleId ? userInfo.value.jobTitleId.split(',').map((id) => Number(id)) : []);
|
||||
count.value = ids.length;
|
||||
state.jobTitleId = defaultId ? defaultId : userInfo.value.jobTitleId;
|
||||
state.jobTitleId = defaultId ? defaultId : (userInfo.value.jobTitleId || '');
|
||||
setCheckedNodes(state.stations, ids);
|
||||
state.visible = true;
|
||||
return;
|
||||
@@ -160,7 +166,7 @@ function serchforIt(defaultId) {
|
||||
count.value = ids.length;
|
||||
setCheckedNodes(resData.data, ids);
|
||||
}
|
||||
state.jobTitleId = userInfo.value.jobTitleId;
|
||||
state.jobTitleId = userInfo.value.jobTitleId || '';
|
||||
state.stations = resData.data;
|
||||
state.visible = true;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user