Browse Source

侧边栏高亮优化

1205-rankList-fix
zq 3 days ago
parent
commit
229f9bcb12
  1. 287
      src/components/SetLeftMenu.vue
  2. 85
      src/store/index.js

287
src/components/SetLeftMenu.vue

@ -3,14 +3,17 @@
<ul style="margin: 0;"> <ul style="margin: 0;">
<li v-for="(item, index) in menuList" :key="item.path + random()"> <li v-for="(item, index) in menuList" :key="item.path + random()">
<div <div
:class="[($route.path == item.path) || (!item.path && curIndex == index) ? 'active' : '', 'flex', ($route.path == item.path) ? curIndex = index : '']" @click="gotoPath(item, index)"> :class="[curIndex === index ? 'active' : '','flex']" @click="gotoPath(item, index)">
<SvgIcon1 :iconPath="require(`@/assets/${item.img}`)" defaultColor="#8A9099" :size="16" activeColor="#006AFF" <SvgIcon1 :iconPath="require(`@/assets/${item.img}`)" defaultColor="#8A9099" :size="16" activeColor="#006AFF"
:isActive="($route.path == item.path || (!item.path && curIndex == index))" /> :isActive="curIndex === index" />
<span class="title_text">{{ item.name }}</span> <span class="title_text">{{ item.name }}</span>
</div> </div>
<p :class="['flex', (activeFloor && (activeFloor == item1.desc || activeFloor == item1.path)) ? 'curActive' : '']" v-for="(item1) in item.list" <p v-for="(item1) in item.list" :key="item1.name" :class="[
@click="setActiveCur(item1, item,index)" :key="item1.name">{{ item1.name }}</p> 'flex',
activeFloor === (item1.desc || item1.path || item1.componentsName) ? 'curActive' : ''
]" @click="setActiveCur(item1, item, index)">
{{ item1.name }}
</p>
</li> </li>
</ul> </ul>
</aside> </aside>
@ -18,22 +21,16 @@
<script> <script>
import SvgIcon1 from '@/components/SvgIcon1.vue'; import SvgIcon1 from '@/components/SvgIcon1.vue';
// :class="[$route.path != item.path ? 'not-point' : '', 'flex', activeFloor == item1.desc ? 'curActive' : '']"
import { mapState } from 'vuex'; import { mapState } from 'vuex';
import store from '../store'; import store from '../store';
export default { export default {
name: 'Sidebar', name: 'Sidebar',
props: { props: {
menuList: { menuList: {
type: Array, type: Array,
required: true required: true
}, }
// activeFloor:{
// type:String
// },
// curIndex:{
// type:Number
// }
}, },
components: { components: {
SvgIcon1, SvgIcon1,
@ -41,33 +38,31 @@ export default {
data() { data() {
return { return {
activeFloor: null, activeFloor: null,
curIndex: 0, curIndex: -1, // -1
scrollLock: false, scrollLock: false,
componentsName:'' componentsName: '',
//
pathToIndexMap: {}
} }
}, },
watch: { watch: {
'$route'() { '$route.path': {
// console.log(to, from); immediate: true, //
// handler(newPath) {
this.$nextTick(() => { this.updateActiveMenu(newPath);
this.calculateFloorOffsets(); }
this.handleScroll(); //
});
} }
}, },
mounted() { mounted() {
let curItem = this.menuList[this.curIndex]; //
// this.buildPathMap();
if(!curItem.list || !curItem.list.length){
this.activeFloor = curItem.path //
}else{ this.updateActiveMenu(this.$route.path);
this.activeFloor = curItem?.list?.[0]?.desc || curItem?.list?.[0]?.path;
}
this.componentsName = curItem?.list?.[0]?.componentsName;
this.$nextTick(() => { this.$nextTick(() => {
//
this.scrollContainer = document.querySelector('.main-content') || this.scrollContainer = document.querySelector('.main-content') ||
document.getElementById('main-content') || document.getElementById('main-content') ||
window; window;
@ -80,55 +75,117 @@ export default {
} }
}); });
}, },
beforeDestroy() { beforeDestroy() {
if (this.scrollContainer) { if (this.scrollContainer) {
this.scrollContainer.removeEventListener('scroll', this.handleScroll); this.scrollContainer.removeEventListener('scroll', this.handleScroll);
} }
}, },
created() {
// console.log(this.$parent.$refs.scrollContainer,'this.$refs.sc--rollContainer--');
},
computed: { computed: {
...mapState(['pageTitle', 'carryParam']) // VuexshowSidebar ...mapState(['pageTitle', 'carryParam'])
}, },
methods: { methods: {
//
buildPathMap() {
const map = {};
this.menuList.forEach((item, parentIndex) => {
if (item.list && item.list.length) {
item.list.forEach(subItem => {
if (subItem.path) {
map[subItem.path] = parentIndex;
}
});
}
});
this.pathToIndexMap = map;
},
//
updateActiveMenu(currentPath) {
// 1.
const parentIndex = this.pathToIndexMap[currentPath];
if (parentIndex !== undefined) {
this.curIndex = parentIndex;
//
const parentItem = this.menuList[parentIndex];
const subItem = parentItem.list.find(item => item.path === currentPath);
if (subItem) {
//
if (subItem.componentsName) {
this.activeFloor = subItem.componentsName;
store.commit('SET_COMPONENTS_NAME', subItem.componentsName);
} else {
//
this.activeFloor = subItem.desc || subItem.path;
}
return;
}
}
// 2.
for (let i = 0; i < this.menuList.length; i++) {
const item = this.menuList[i];
if (item.path && item.path === currentPath) {
this.curIndex = i;
this.activeFloor = item.path;
//
if (item.list && item.list.length) {
const firstSubItem = item.list[0];
if (firstSubItem.componentsName) {
store.commit('SET_COMPONENTS_NAME', firstSubItem.componentsName);
}
}
return;
}
}
// 3.
if (this.curIndex === -1 && this.menuList.length > 0) {
this.curIndex = 0;
const firstItem = this.menuList[0];
if (firstItem.list && firstItem.list.length) {
const firstSubItem = firstItem.list[0];
this.activeFloor = firstSubItem.desc || firstSubItem.path || firstSubItem.componentsName;
if (firstSubItem.componentsName) {
store.commit('SET_COMPONENTS_NAME', firstSubItem.componentsName);
}
} else {
this.activeFloor = firstItem.path;
}
}
},
random() { random() {
var randomNumber = Math.random(); return Math.random();
return randomNumber
}, },
calculateFloorOffsets() { calculateFloorOffsets() {
this.menuList.forEach(item => { if (this.curIndex === -1 || !this.menuList[this.curIndex]?.list) return;
item.list?.forEach(every => {
const el = document.getElementById(every.desc); this.menuList[this.curIndex].list?.forEach(every => {
if (el) { const el = document.getElementById(every.desc);
// if (el) {
every.offsetTop = el.getBoundingClientRect().top + window.pageYOffset; every.offsetTop = el.getBoundingClientRect().top + window.pageYOffset;
} }
});
}); });
}, },
handleScroll() { handleScroll() {
if (this.scrollLock || !this.menuList[this.curIndex]?.list) return; if (this.scrollLock || this.curIndex === -1 || !this.menuList[this.curIndex]?.list) return;
const scrollPosition = this.getScrollPosition(); const scrollPosition = this.getScrollPosition();
let activeFloor = null; let activeFloor = null;
console.log(this.curIndex,scrollPosition,'this.curIndex===');
//
//
// for (let i = this.menuList[this.curIndex].list.length - 1; i >= 0; i--) {
// const item = this.menuList[this.curIndex].list[i];
// if (scrollPosition + 100 >= (item.offsetTop || 0)) { // 100
// activeFloor = item.desc;
// break;
// }
// }
//
for (let i = 0; i < this.menuList[this.curIndex].list.length; i++) { for (let i = 0; i < this.menuList[this.curIndex].list.length; i++) {
const item = this.menuList[this.curIndex].list[i]; const item = this.menuList[this.curIndex].list[i];
if (scrollPosition + 100 >= (item.offsetTop || 0)) { // 100 if (item.offsetTop && scrollPosition + 100 >= item.offsetTop) {
activeFloor = item.desc; activeFloor = item.desc || item.componentsName;
break;
} }
} }
@ -143,93 +200,89 @@ export default {
} }
return this.scrollContainer.scrollTop; return this.scrollContainer.scrollTop;
}, },
// setActiveCur(dom, item) {
// if (this.$route.path != item.path) { gotoPath(item, index) {
// this.$router.push(item.path) this.curIndex = index;
// store.commit('SET_PAGETITLE', item.name);
// }
// setTimeout(() => {
// this.activeFloor = dom;
// this.setHighActive(dom)
// }, 500)
// },
// setHighActive(dom) {
// this.scrollLock = true;
// const ele = document.getElementById(dom)
// if (!ele) return
// ele.classList.add('ceshi')
// ele.scrollIntoView({ behavior: 'smooth', block: 'start' })
// setTimeout(() => {
// ele.classList.remove('ceshi')
// }, 1000)
// }
gotoPath(item) {
let path = item.path; let path = item.path;
this.activeFloor = path
if (!path) { // path
this.curIndex = 0; if (!path && item.list && item.list.length) {
return; const firstSubItem = item.list[0];
if (firstSubItem.componentsName) {
this.activeFloor = firstSubItem.componentsName;
store.commit('SET_COMPONENTS_NAME', firstSubItem.componentsName);
} else if (firstSubItem.path) {
//
this.setActiveCur(firstSubItem, item, index);
return;
}
} }
if (this.$route.path != path) {
this.curIndex = 0; this.activeFloor = path;
if (!path) {
this.scrollLock = false; this.scrollLock = false;
this.handleScroll(); this.handleScroll();
return;
// }
if (this.$route.path !== path) {
this.$router.push({ this.$router.push({
path: path, path: path,
query: { ...this.$route.query }, // query: { ...this.$route.query },
params: { ...this.$route.params } // params: { ...this.$route.params }
}); });
//
const dom = document.getElementById('main-content'); const dom = document.getElementById('main-content');
if (dom) dom.scrollTop = 0; if (dom) dom.scrollTop = 0;
} }
}, },
setActiveCur(item1, item,index) { setActiveCur(item1, item, index) {
this.curIndex = index; this.curIndex = index;
let componentsName = item1?.componentsName; let componentsName = item1?.componentsName;
//
if(componentsName){ //
if (componentsName) {
this.activeFloor = componentsName; this.activeFloor = componentsName;
//
store.commit('SET_COMPONENTS_NAME', componentsName); store.commit('SET_COMPONENTS_NAME', componentsName);
return return;
} }
// //
// //
// //
let path = item1.path || item.path; let path = item1.path || item.path;
if ( this.$route.path !== path) { if (path && this.$route.path !== path) {
if(this.carryParam){ if (this.carryParam) {
//
this.$router.push({ this.$router.push({
path: path, path: path,
query: { ...this.$route.query }, // query: { ...this.$route.query },
params: { ...this.$route.params } // params: { ...this.$route.params }
}); });
}else{ } else {
this.$router.push(path); this.$router.push(path);
} }
store.commit('SET_PAGETITLE', item.name); store.commit('SET_PAGETITLE', item.name);
//
const dom = document.getElementById('main-content');
if (dom) dom.scrollTop = 0;
} }
this.scrollLock = true; this.scrollLock = true;
if(item1.desc){ if (item1.desc) {
this.activeFloor = item1.desc; this.activeFloor = item1.desc;
} }
// if (item1.path) {
if(item1.path){
this.activeFloor = item1.path; this.activeFloor = item1.path;
return return;
} }
this.$nextTick(() => { this.$nextTick(() => {
this.setHighActive(item1.desc); if (item1.desc) {
this.setHighActive(item1.desc);
}
setTimeout(() => { setTimeout(() => {
this.scrollLock = false; this.scrollLock = false;
}, 1000); }, 1000);
@ -244,9 +297,9 @@ export default {
eles[i].classList.remove('siteMessage-active'); eles[i].classList.remove('siteMessage-active');
} }
ele.classList.add('siteMessage-active'); ele.classList.add('siteMessage-active');
setTimeout(function (){ setTimeout(() => {
ele.classList.remove('siteMessage-active'); ele.classList.remove('siteMessage-active');
},1000) }, 1000);
ele.scrollIntoView({ ele.scrollIntoView({
behavior: 'smooth', behavior: 'smooth',
block: 'start' block: 'start'
@ -265,10 +318,12 @@ export default {
background: #FFFFFF; background: #FFFFFF;
box-shadow: 0px 0px 11px 2px rgba(147, 147, 147, 0.11); box-shadow: 0px 0px 11px 2px rgba(147, 147, 147, 0.11);
} }
ul{
ul {
height: 100%; height: 100%;
overflow-y: auto; overflow-y: auto;
} }
.ceshi { .ceshi {
// animation: fadeInOut 2s infinite; // animation: fadeInOut 2s infinite;
} }

85
src/store/index.js

@ -402,91 +402,6 @@ export default new Vuex.Store({
] ]
} }
], ],
siteSettingData1: [{
name: '基本设置',
path: '/agent/siteBaseSetting',
img: 'site/sitebase.svg',
imgActive: require('@/assets/site/sitebase_active.svg'),
list: [{
name: '站点信息',
desc: 'siteMessage1'
},
{
name: '域名设置',
desc: 'siteMessage2'
},
{
name: '渠道设置',
desc: 'siteMessage14'
},
{
name: '收款方式',
desc: 'siteMessage3'
},
]
},
{
name: '个性化设置',
path: '/agent/sitePersonalization',
img: 'site/gexinghua.svg',
imgActive: require('@/assets/site/sitebase_active.svg'),
list: [{
name: '网页模板',
desc: 'siteMessage4'
},
{
name: '客服设置',
desc: 'siteMessage5'
},
{
name: '功能显隐',
desc: 'siteMessage6'
},
{
name: '安全提交',
desc: 'siteMessage7'
},
{
name: '初始订单数',
desc: 'siteMessage8'
},
]
},
{
name: '移动端设置',
path: '/agent/siteMobileSetting',
img: 'site/siteh5.svg',
imgActive: require('@/assets/site/sitebase_active.svg'),
list: [{
name: '微信H5',
desc: 'siteMessage9'
},
{
name: '小程序',
desc: 'siteMessage10'
},
]
},
{
name: '营销推广',
path: '/siteSetting/siteSem',
img: 'site/sitesem.svg',
imgActive: require('@/assets/site/sitebase_active.svg'),
list: [{
name: 'SEO设置',
desc: 'siteMessage11'
},
{
name: 'SEM设置',
desc: 'siteMessage12'
},
{
name: '访问统计',
desc: 'siteMessage13'
},
]
}
],
siteSettingData: [ //第二种侧边栏 -- 点击单项进行页面滚动 siteSettingData: [ //第二种侧边栏 -- 点击单项进行页面滚动
{ {
name: '基本设置', name: '基本设置',

Loading…
Cancel
Save