4
4
</div >
5
5
</template >
6
6
<script >
7
- import { mapState , mapMutations } from ' vuex'
8
- import { getScrollTop } from ' @/utils/getScrollTop'
9
- import { getElementTop } from ' @/utils/getElementTop'
7
+ import { mapMutations } from ' vuex'
10
8
11
9
export default {
12
10
components: {},
@@ -17,131 +15,41 @@ export default {
17
15
showBackTop: true
18
16
}
19
17
},
20
- watch: {
21
- $route () {
22
- // scrollTo(0)
23
- if (this .$route .name === ' home' ) {
24
- this .location = []
25
- }
26
- this .currentLocation (this .$route )
27
- },
28
- // 当articleShow组件的标题变化时,刷新当前位置的文章标题,防止当前文章显示上一篇文章的标题
29
- currentTitle () {
30
- this .currentLocation (this .$route )
31
- }
32
- },
18
+ watch: {},
33
19
mounted () {
34
- // this.currentLocation(this.$route)
35
- // this.scrollCotainer()
36
- // //页面重载计算锚点距离并判断tab的背景样式
37
- // this.positionTop(getElementTop(this.$refs.container) - 50)
38
- // this.getTop()
39
- },
40
- computed: {
41
- ... mapState ([' currentTitle' ])
20
+ this .initPannel ()
42
21
},
22
+ computed: {},
43
23
methods: {
44
- ... mapMutations ([' addTabBg' , ' positionTop' ]),
45
- scrollCotainer : function () {
46
- window .addEventListener (' scroll' , this .scroll_resize )
47
- // 改变窗口大小后对导航栏状态重新进行确认
48
- window .addEventListener (' resize' , this .scroll_resize )
49
- },
50
- scroll_resize : function () {
51
- this .debounce (this .getTop , 500 )
52
- },
53
- getAT : function () {
54
- let top = getScrollTop () - getElementTop (this .$refs .container )
55
- this .positionTop (top)
56
- },
57
- getTop : function () {
58
- // 计算document需要滚动的距离
59
- let tabOffsetTop = getElementTop (this .$refs .container ) - 50
60
- let move = Math .abs (getScrollTop () - tabOffsetTop)
61
- if (getScrollTop () > 0 ) {
62
- this .showBackTop = true
63
- } else {
64
- this .showBackTop = false
65
- }
66
- if (getScrollTop () > tabOffsetTop) {
67
- this .addTabBg (true )
68
- } else {
69
- this .addTabBg (false )
70
- }
71
- // 计算路由改变需要滚动的距离
72
- this .positionTop ({ top: tabOffsetTop, move: move })
73
- },
74
- // 函数去抖,防止scroll和resize频繁触发
75
- debounce : function (func , delay ) {
76
- let context = this
77
- let args = arguments
78
- if (this .timer ) {
79
- clearTimeout (this .timer )
80
- }
81
- this .timer = setTimeout (function () {
82
- func .apply (context, args)
83
- }, delay)
84
- },
85
- back : function (item ) {
86
- let name = item .pathName
87
- if (name === ' techincal' ) {
88
- this .$router .push ({ name: name, params: { articleList: item .params .tag } })
89
- } else if (name === ' articleShow' ) {
90
- this .$router .push ({ name: name, params: { articleList: item .params .tag , id: item .params .id } })
91
- } else if (name === ' lifeShow' ) {
92
- this .$router .push ({ name: name, params: { id: item .params .id } })
93
- } else {
94
- this .$router .push ({ name: name })
95
- }
96
- },
97
- backTop : function () {
98
- document .documentElement .scrollTop = 0
99
- document .body .scrollTop = 0
100
- },
101
- backHome : function () {
102
- this .location = []
103
- this .$router .push ({ name: ' home' })
104
- },
105
- // 当前位置的路由信息表
106
- currentLocation : function (to ) {
107
- switch (to .name ) {
108
- case ' article' :
109
- this .location = [{ pathName: ' article' , showName: ' 技术文章' }]
110
- break
111
- case ' techincal' :
112
- let tag = to .params .articleList
113
- this .location = [
114
- { pathName: ' article' , showName: ' 技术文章' },
115
- { pathName: ' techincal' , showName: tag, params: { tag: tag } }
116
- ]
117
- break
118
- case ' articleShow' :
119
- let _tag = to .params .articleList
120
- this .location = [
121
- { pathName: ' article' , showName: ' 技术文章' },
122
- { pathName: ' techincal' , showName: _tag, params: { tag: _tag } },
123
- { pathName: ' articleShow' , showName: this .currentTitle , params: { tag: _tag, id: to .params .id } }
124
- ]
125
- break
126
- case ' life' :
127
- this .location = [{ pathName: ' life' , showName: ' 生活' }]
128
- break
129
- case ' lifeShow' :
130
- this .location = [
131
- { pathName: ' life' , showName: ' 生活' },
132
- { pathName: ' lifeShow' , showName: this .currentTitle , params: { id: to .params .id } }
133
- ]
134
- console .log (this .currentTitle )
135
- break
136
- case ' msgboard' :
137
- this .location = [{ pathName: ' msgboard' , showName: ' 留言板' }]
138
- break
139
- case ' search' :
140
- this .location = [{ pathName: ' search' , showName: ' 搜索' }]
141
- break
142
- case ' timeLine' :
143
- this .location = [{ pathName: ' timeLine' , showName: ' 时间轴' }]
144
- }
24
+ ... mapMutations ([' setArchives' , ' setCategory' , ' setTags' , ' setNewComments' , ' setNewArticles' ]),
25
+ initPannel () {
26
+ this .$api .getArchives ({ countType: ' month' , page: 1 , limit: 1000 }).then (res => {
27
+ if (res .status === 200 ) this .setArchives (res .data )
28
+ })
29
+ this .$api .getCategory ().then (res => {
30
+ if (res .status === 200 ) this .setCategory (res .data )
31
+ })
32
+ this .$api .getTags ().then (res => {
33
+ if (res .status === 200 ) this .setTags (res .data )
34
+ })
35
+ this .$api
36
+ .getArticleComments ({
37
+ page: 1 ,
38
+ limit: 5
39
+ })
40
+ .then (res => {
41
+ if (res .status === 200 ) this .setNewComments (res .data )
42
+ })
43
+ this .$api
44
+ .getArticles ({
45
+ publish: 1 ,
46
+ page: 1 ,
47
+ limit: 5 ,
48
+ content: 0
49
+ })
50
+ .then (res => {
51
+ if (res .status === 200 ) this .setNewArticles (res .data )
52
+ })
145
53
}
146
54
}
147
55
}
0 commit comments