Skip to content

Commit f663327

Browse files
author
zhongchubing
committed
refactor: 优化移动端响应式
1 parent 4a91357 commit f663327

File tree

13 files changed

+249
-131
lines changed

13 files changed

+249
-131
lines changed

.idea/watcherTasks.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

geekape-nav-main/components/Affiche.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,16 @@ export default {
4848

4949
<style lang="scss" scoped>
5050
.affiche {
51-
width: 100%;
51+
width: auto;
5252
font-size: 14px;
5353
background: #fff;
5454
border-radius: 5px;
5555
padding: 5px 15px;
5656
display: flex;
5757
align-items: center;
58+
p.medium {
59+
margin: 0;
60+
}
5861
i {
5962
font-size: 18px;
6063
font-weight: bold;

geekape-nav-main/components/AppHeader.vue

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
<template>
22
<el-header>
3-
<AppSearch />
4-
5-
6-
<el-row type="flex">
7-
<el-col>
8-
<el-tooltip content="推荐网站"><i class="el-icon-circle-plus" @click="$emit('showPopup')"></i></el-tooltip>
9-
</el-col>
10-
</el-row>
3+
<div>
4+
<img class="header-logo" src="/logo-nav.png" />
5+
</div>
6+
<el-row type="flex">
7+
<el-col>
8+
<el-tooltip content="推荐网站"><i class="el-icon-circle-plus" @click="$emit('handleShowPopup')"></i></el-tooltip>
9+
</el-col>
10+
<el-col class="menu-toggle-btn">
11+
<i class="el-icon-menu" @click="$emit('handleShowMenu')"></i>
12+
</el-col>
13+
</el-row>
1114
</el-header>
1215
</template>
1316

@@ -17,6 +20,7 @@ export default {
1720
name: "AppHeader",
1821
components: {AppSearch},
1922
props: {
23+
2024
dialogFormVisible: {
2125
type: Boolean,
2226
default: false
@@ -55,6 +59,11 @@ export default {
5559
color: #999;
5660
cursor: pointer;
5761
}
62+
63+
.header-logo {
64+
width: 150px;
65+
filter: invert(1);
66+
}
5867
}
5968
6069
@@ -64,12 +73,22 @@ export default {
6473
display: none;
6574
}
6675
}
76+
77+
.header-logo,
78+
.menu-toggle-btn {
79+
display: block;
80+
}
6781
}
6882
@media screen and (min-width: 569px) {
6983
.app-search {
7084
/deep/ .el-select {
7185
display: block;
7286
}
7387
}
88+
89+
.header-logo,
90+
.menu-toggle-btn {
91+
display: none;
92+
}
7493
}
7594
</style>

geekape-nav-main/components/AppNavItem.vue

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ export default {
7070
views[id] = view + 1;
7171
this.$storage.set("VIEWS", views);
7272
// window.open(href, "_blank");
73-
this.$router.push({
74-
path: `/nav/${id}`
75-
})
73+
await this.$router.push(`/nav/${id}`)
7674
},
7775
async handleStar() {
7876
const stars = this.$storage.get("STARS") || {};
@@ -91,13 +89,7 @@ export default {
9189
</script>
9290

9391
<style lang="scss">
94-
@mixin text-overflow($line) {
95-
overflow: hidden;
96-
text-overflow: ellipsis;
97-
display: -webkit-box;
98-
-webkit-box-orient: vertical;
99-
-webkit-line-clamp: $line;
100-
}
92+
10193
.website-item {
10294
font-size: 12px;
10395
margin-bottom: 20px;

geekape-nav-main/components/AppNavMenus.vue

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
>
77
<nuxt-link class="title" to="/">
88
<img
9-
v-if="!isCollapse"
9+
v-show="!isCollapse"
1010
class="icon-logo"
1111
width="180"
1212
src="/logo-nav.png"
1313
/>
14-
<img v-else class="icon-logo" width="45" src="/logo-nav-icon.png"/>
14+
<img v-show="isCollapse" class="icon-logo" width="45" src="/logo-nav-icon.png"/>
1515

1616
<!-- <span>猿梦极客导航后台</span> -->
1717
</nuxt-link>
@@ -75,13 +75,17 @@
7575
export default {
7676
name: "AppNavMenus",
7777
props: {
78+
show: {
79+
type: Boolean,
80+
default: true,
81+
},
7882
categorys: {
7983
type: Array,
8084
default: () => []
8185
},
82-
isCollapse: {
83-
type: Boolean,
84-
default: false
86+
showMenuType: {
87+
type: String,
88+
default: 'half'
8589
}
8690
},
8791
data() {
@@ -93,7 +97,16 @@ export default {
9397
},
9498
computed: {
9599
sideBarWidth() {
96-
return !this.isCollapse ? "220px" : "70px";
100+
if (this.showMenuType == 'half') {
101+
return '70px'
102+
} else if (this.showMenuType == 'all') {
103+
return '220px'
104+
} else {
105+
return 0
106+
}
107+
},
108+
isCollapse() {
109+
return this.showMenuType === 'half'
97110
}
98111
},
99112
methods: {
@@ -147,7 +160,6 @@ $sidebar-w: auto;
147160
148161
.el-aside {
149162
overflow: hidden;
150-
151163
.el-menu-vertical-demo.el-menu {
152164
height: 100vh;
153165
overflow-y: auto;
@@ -221,14 +233,20 @@ $sidebar-w: auto;
221233
}
222234
}
223235
224-
225236
@media screen and (max-width: 568px) {
237+
.el-aside {
238+
width: 0;
239+
}
240+
226241
.app-search,
227242
.sidebar-fix {
228243
display: none;
229244
}
230245
}
231246
@media screen and (min-width: 569px) {
247+
.el-aside {
248+
width: 70px;
249+
}
232250
.app-search,
233251
.sidebar-fix {
234252
display: block;

geekape-nav-main/layouts/default.vue

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,16 @@
44
</div>
55
</template>
66

7-
<style>
7+
<script>
8+
import AppNavMenus from "../components/AppNavMenus";
9+
import AppHeader from "../components/AppHeader";
10+
import { mapState } from "vuex";
11+
export default {
12+
13+
}
14+
</script>
15+
16+
<style lang="scss" scoped>
817
html {
918
font-family: 'Source Sans Pro', -apple-system, BlinkMacSystemFont, 'Segoe UI',
1019
Roboto, 'Helvetica Neue', Arial, sans-serif;
@@ -24,32 +33,5 @@ html {
2433
margin: 0;
2534
}
2635
27-
.button--green {
28-
display: inline-block;
29-
border-radius: 4px;
30-
border: 1px solid #3b8070;
31-
color: #3b8070;
32-
text-decoration: none;
33-
padding: 10px 30px;
34-
}
3536
36-
.button--green:hover {
37-
color: #fff;
38-
background-color: #3b8070;
39-
}
40-
41-
.button--grey {
42-
display: inline-block;
43-
border-radius: 4px;
44-
border: 1px solid #35495e;
45-
color: #35495e;
46-
text-decoration: none;
47-
padding: 10px 30px;
48-
margin-left: 15px;
49-
}
50-
51-
.button--grey:hover {
52-
color: #fff;
53-
background-color: #35495e;
54-
}
5537
</style>
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import {mapState} from "vuex";
2+
import AppHeader from "../components/AppHeader";
3+
import AppNavMenus from "../components/AppNavMenus";
4+
import {throttle} from "../utils/utils";
5+
6+
const layoutMixin = {
7+
components: {AppHeader, AppNavMenus},
8+
data() {
9+
return {
10+
isCollapse: true,
11+
showPopup: false,
12+
showLog: false,
13+
// none, half, all
14+
showMenuType: 'half',
15+
}
16+
},
17+
computed: {
18+
...mapState(['category']),
19+
isMobile() {
20+
const width = window.innerWidth || document.body.clientWidth
21+
return width < 568
22+
},
23+
sideBarWidth() {
24+
if (this.showMenuType == 'half') {
25+
return '70px'
26+
} else if (this.showMenuType == 'all') {
27+
return '220px'
28+
} else {
29+
return 0
30+
}
31+
},
32+
contentMarginLeft() {
33+
if (this.showMenuType == 'half') {
34+
return '70px'
35+
} else if (this.showMenuType == 'all') {
36+
const width = window.innerWidth || document.body.clientWidth
37+
38+
if (this.isMobile) {
39+
return 0
40+
} else {
41+
return '220px'
42+
}
43+
} else {
44+
return 0
45+
}
46+
},
47+
},
48+
methods: {
49+
async findNav(id) {
50+
this.loading = true;
51+
const { data } = await this.$api.findNav(id);
52+
this.data = data;
53+
this.loading = false;
54+
},
55+
async handleSubMenuClick(parentId, id) {
56+
await this.findNav(parentId);
57+
},
58+
toggleMenu() {
59+
this.showMenuType = this.showMenuType === 'none' ? 'all' : 'none'
60+
},
61+
toggleMenu2() {
62+
this.showMenuType = this.showMenuType === 'all' ? 'half' : 'all'
63+
}
64+
},
65+
66+
mounted() {
67+
this.showMenuType = this.isMobile ? 'none' : 'half'
68+
}
69+
}
70+
71+
72+
export default layoutMixin

geekape-nav-main/nuxt.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ module.exports = {
8383
*/
8484
build: {
8585
transpile: [/^element-ui/],
86+
styleResources: {
87+
scss: './static/styles/mixin.scss',
88+
},
8689
/*
8790
** You can extend webpack config here
8891
*/

0 commit comments

Comments
 (0)