Skip to content

Commit 28186f1

Browse files
committed
update: 二级导航
1 parent 50c4a04 commit 28186f1

File tree

1 file changed

+68
-61
lines changed

1 file changed

+68
-61
lines changed

src/pages/Index.vue

Lines changed: 68 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,25 @@
88
</div>
99
<el-row>
1010
<el-col :span="24">
11-
<el-menu
11+
<el-menu
1212
:default-active="active"
1313
class="el-menu-vertical-demo"
1414
background-color="#30333c"
1515
text-color="#6b7386"
1616
active-text-color="#fff"
1717
>
18-
<el-menu-item
19-
:index="index"
20-
v-for="(item,index) in data"
21-
:key="item._id"
22-
@click="jump(index)"
23-
>
24-
<i :class="item.icon"></i>
25-
<span slot="title">{{item.classify}}</span>
26-
</el-menu-item>
18+
<el-submenu :index="item.name" v-for="(item,index) in newDataList" :key="item.name">
19+
<template slot="title">
20+
<i :class="item.icon"></i>
21+
<span slot="title">{{item.name}}</span>
22+
</template>
23+
<el-menu-item :index="nav._id" v-for="(nav,idx) in item.data" :key="nav._id">
24+
<a :href="`#${nav.classify}`">
25+
<i :class="nav.icon"></i>
26+
<span slot="title">{{nav.classify}}</span>
27+
</a>
28+
</el-menu-item>
29+
</el-submenu>
2730
</el-menu>
2831
</el-col>
2932
</el-row>
@@ -42,8 +45,8 @@
4245
</div>
4346
</div>
4447
<!-- 开发社区 -->
45-
<div class="box" v-for="(item,index) in data" :key="index" :ref="`box-${index}`">
46-
<a href="#" :name="item.classify"></a>
48+
<div class="box" v-for="(item,index) in data" :key="index">
49+
<a :id="`#${item.classify}`" :name="item.classify"></a>
4750
<div class="sub-category">
4851
<div>
4952
<i :class="item.icon" class="icon"></i>
@@ -57,8 +60,8 @@
5760
<div class="copyright">
5861
<div>
5962
Copyright © 2019- 2050
60-
<a href="https://github.com/geekape/blog"> 钟储兵博客</a>
61-
<a href="https://github.com/geekape/geek-navigation"> 导航源码下载</a>
63+
<a href="https://github.com/geekape/blog">钟储兵博客</a>
64+
<a href="https://github.com/geekape/geek-navigation">导航源码下载</a>
6265
</div>
6366
</div>
6467
</footer>
@@ -77,7 +80,6 @@ export default {
7780
return {
7881
active: "0",
7982
data: [],
80-
scroll: 0,
8183
selfIndex: 0,
8284
isLeftbar: true
8385
};
@@ -87,39 +89,45 @@ export default {
8789
AddNavBtn,
8890
NavItem
8991
},
90-
watch: {
91-
active () {
92-
const leftBarTop = document.querySelector('.left-bar').scrollTop
93-
const num = this.active
94-
const length = this.data.length
95-
if (num >= 10 && num <= length) {
96-
document.querySelector('.left-bar').scrollTop = leftBarTop + 60
97-
}
98-
if (num < 10 && num >= 0) {
99-
document.querySelector('.left-bar').scrollTop = leftBarTop - 60
100-
}
92+
computed: {
93+
newDataList() {
94+
const arr = [];
95+
let product = {};
96+
let operation = {};
97+
let design = {};
98+
let web = {};
99+
// 产品
100+
product.name = "产品";
101+
product.icon = "csz czs-circle";
102+
product.data = this.data.filter(
103+
item => item.classify.indexOf("[产品]") != -1
104+
);
105+
arr.push(product);
106+
// 运营
107+
operation.name = "运营";
108+
operation.icon = "csz czs-square";
109+
operation.data = this.data.filter(
110+
item => item.classify.indexOf("[运营]") != -1
111+
);
112+
arr.push(operation);
113+
// 设计
114+
design.name = "设计";
115+
design.icon = "csz czs-triangle";
116+
design.data = this.data.filter(
117+
item => item.classify.indexOf("[设计]") != -1
118+
);
119+
arr.push(design);
120+
// 前端
121+
web.name = "前端";
122+
web.icon = "csz czs-camber";
123+
web.data = this.data.filter(
124+
item => item.classify.indexOf("[前端]") != -1
125+
);
126+
arr.push(web);
127+
return arr;
101128
}
102129
},
103130
methods: {
104-
jump(idx) {
105-
this.selfIndex = idx;
106-
107-
// 跳转
108-
let allSite = document.querySelectorAll(".box");
109-
let selfOffsetTop = allSite[idx].offsetTop - 10;
110-
// 判断是否是在手机上
111-
window.screenWidth = document.body.clientWidth;
112-
if (window.screenWidth < 481) {
113-
selfOffsetTop -= 50;
114-
}
115-
// Chrome
116-
document.body.scrollTop = selfOffsetTop;
117-
// Firefox
118-
document.documentElement.scrollTop = selfOffsetTop;
119-
// Safari
120-
window.pageYOffset = selfOffsetTop;
121-
},
122-
123131
async getData() {
124132
const res = await this.$api.getHome();
125133
this.data = res.data;
@@ -134,23 +142,8 @@ export default {
134142
that.selfIndex = i;
135143
}
136144
}
137-
},
138-
handleScroll () {
139-
const that = this
140-
const length = that.data.length
141-
const content = document.querySelectorAll('.box')
142-
const top = document.body.scrollTop || document.documentElement.scrollTop
143-
for (let i=length-1; i>=0; i--) {
144-
if (top >= content[i].offsetTop - 20) {
145-
that.active = i.toString()
146-
break
147-
}
148-
}
149145
}
150146
},
151-
mounted (){
152-
window.addEventListener('scroll', this.handleScroll);
153-
},
154147
created() {
155148
const that = this;
156149
this.getData();
@@ -175,5 +168,19 @@ export default {
175168
.el-dialog {
176169
min-width: 320px;
177170
}
178-
171+
.el-submenu .el-menu-item {
172+
padding: 0;
173+
}
174+
.el-menu-item > a {
175+
color: rgb(107, 115, 134);
176+
display: block;
177+
width:100%;
178+
height: 100%;
179+
}
180+
.el-menu-item.is-active > a {
181+
color:#fff;
182+
}
183+
.csz {
184+
margin-right: 5px;
185+
}
179186
</style>

0 commit comments

Comments
 (0)