/
Search.vue
228 lines (208 loc) · 5.21 KB
/
Search.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<template>
<div class="page-search">
<div class="search flex flex-middle">
<i class="iconfont icon-search"></i>
<input class="flex-item" type="text" placeholder="search" v-model="search" @input="onInput"/>
</div>
<div class="tips" v-if="archives.totalCount">
<p v-text="`共 ${archives.totalCount} 条搜索结果`"></p>
</div>
<ul class="archives">
<li class="archive" v-for="archive in archives.list" :key="archive.number">
<router-link :to="`/archives/${archive.number}`" v-text="archive.title" :title="archive.title"></router-link>
<p v-text="archive.bodyText"></p>
</li>
</ul>
<div class="auxi flex flex-middle flex-center" v-if="archives.none">
<i class="iconfont icon-none"></i>
<span>目前就这么多啦~</span>
</div>
<template v-else>
<template v-if="archives.loading">
<div class="auxi flex flex-middle flex-center">
<i class="iconfont icon-loading"></i>
<span>正在加载中</span>
</div>
</template>
<template v-else>
<div class="flex flex-middle flex-center" v-if="archives.totalCount">
<a class="btn-next flex flex-middle flex-center" href="javascript:;" @click="getData">加载更多</a>
</div>
</template>
</template>
</div>
</template>
<script>
import {
ref,
reactive,
} from '@vue/composition-api';
import { debounce } from '../utils/utils';
export default {
setup(props, context) {
const search = ref('');
const archives = reactive({
list: [],
labels: [],
totalCount: 0,
cursor: null,
loading: false,
none: false,
});
const getData = () => {
archives.loading = true;
const query = `query {
search(query: "${search.value} repo:ChenJiaH/blog", type: ISSUE, first: 10, after: ${archives.cursor}) {
issueCount
pageInfo {
endCursor
hasNextPage
}
nodes {
... on Issue {
title
bodyText
number
}
}
}
}`;
context.root.$http(query).then((res) => {
archives.loading = false;
const { nodes, pageInfo, issueCount } = res.search;
if (!pageInfo.hasNextPage) {
archives.none = true;
}
archives.cursor = `"${pageInfo.endCursor}"`;
archives.list = archives.list.concat(nodes);
archives.totalCount = issueCount;
});
};
const resetData = () => {
archives.cursor = null;
archives.loading = false;
archives.none = false;
archives.list = [];
archives.totalCount = 0;
};
const onInput = debounce(() => {
resetData();
if (search.value && !archives.loading) {
getData();
}
}, 300);
return {
getData,
onInput,
search,
archives,
};
},
};
</script>
<style lang="scss" scoped>
.pc-mode {
.page-search {
.search {
margin-left: 20px;
&:before {
content: '';
position: absolute;
left: -22px;
top: 50%;
margin-top: -4px;
width: 8px;
height: 8px;
border-radius: 50%;
background-color: #dddddd;
}
}
.archives {
padding-left: 20px;
.archive a {
&:before {
content: '';
position: absolute;
left: -22px;
top: 50%;
margin-top: -4px;
width: 8px;
height: 8px;
border-radius: 50%;
background-color: #dddddd;
}
}
}
}
}
.page-search {
.search {
position: relative;
max-width: 400px;
background-color: #f0f0f0;
height: 36px;
border-radius: 18px;
padding: 0 16px;
i {
font-size: $sizeMedium;
margin-left: -8px;
margin-right: 8px;
}
input {
position: relative;
height: 100%;
background-color: transparent;
border: none;
font-size: $sizeMedium;
color: $mainStrong;
}
}
.archives {
margin-top: 32px;
margin-bottom: 16px;
list-style: none;
.archive {
position: relative;
a {
display: block;
position: relative;
font-size: $sizeMedium;
font-weight: bold;
color: $mainStrong;
line-height: 1.5;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
transition: all 0.5s;
&:hover,&:active {
color: #1abc9c;
}
}
p {
color: #555555;
font-size: $sizeNormal;
line-height: 1.5;
max-height: 96px;
margin-top: 16px;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 4;
overflow: hidden;
word-break: break-all;
}
}
.archive + .archive {
margin-top: 32px;
}
}
.tips {
position: relative;
margin-left: 20px;
margin-top: 16px;
p {
font-size: $sizeNormal;
color: #999999;
}
}
}
</style>