vuepress-theme-uniapp-official 1.4.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/README.md +22 -0
  2. package/components/AlgoliaSearchBox.vue +130 -0
  3. package/components/DcloudSearchPage/components/Result.vue +160 -0
  4. package/components/DcloudSearchPage/components/Results.vue +66 -0
  5. package/components/DcloudSearchPage/components/pagination.vue +155 -0
  6. package/components/DcloudSearchPage/index.styl +183 -0
  7. package/components/DcloudSearchPage/index.vue +500 -0
  8. package/components/DcloudSearchPage/styles/ask.styl +272 -0
  9. package/components/DcloudSearchPage/styles/ext.styl +68 -0
  10. package/components/DcloudSearchPage/utils/Base64.js +134 -0
  11. package/components/DcloudSearchPage/utils/mock.js +434 -0
  12. package/components/DcloudSearchPage/utils/postDcloudServer.js +141 -0
  13. package/components/DcloudSearchPage/utils/searchClient.js +101 -0
  14. package/components/DcloudSearchPage/utils/searchUtils.js +52 -0
  15. package/components/Footer.vue +142 -0
  16. package/components/MainNavbarLink.vue +57 -0
  17. package/components/NavLink.vue +95 -0
  18. package/components/NavLinks.vue +173 -0
  19. package/components/Navbar.vue +322 -0
  20. package/components/NavbarLogo.vue +24 -0
  21. package/components/OutboundLink.vue +45 -0
  22. package/components/SearchBox/dist/match-query.dev.js +61 -0
  23. package/components/SearchBox/index.vue +337 -0
  24. package/components/SearchBox/match-query.js +51 -0
  25. package/components/SearchBox/search.svg +1 -0
  26. package/components/SidebarGroup.vue +141 -0
  27. package/components/SidebarLink.vue +152 -0
  28. package/components/SidebarLinks.vue +106 -0
  29. package/components/SiderBarBottom.vue +134 -0
  30. package/components/Sticker.vue +64 -0
  31. package/components/Toc-top.vue +95 -0
  32. package/components/Toc.vue +165 -0
  33. package/config/copy.js +7 -0
  34. package/config/footer.js +195 -0
  35. package/config/i18n/index.js +2 -0
  36. package/config/navbar.js +163 -0
  37. package/config/redirectRouter.js +120 -0
  38. package/config/searchPage.js +48 -0
  39. package/config/siderbar/index.js +8 -0
  40. package/config/siderbar/uni-app.js +210 -0
  41. package/config/siderbar/uniCloud.js +55 -0
  42. package/config/toc.js +5 -0
  43. package/enhanceApp.js +142 -0
  44. package/global-components/CodeSimulator.vue +211 -0
  45. package/global-components/icons.js +647 -0
  46. package/global-components/iconsLayouts.vue +117 -0
  47. package/global-components/uniIcon.vue +85 -0
  48. package/global-components/uniicons.css +656 -0
  49. package/global-components/uniicons.ttf +0 -0
  50. package/index.js +152 -0
  51. package/layouts/404.vue +22 -0
  52. package/layouts/Layout.vue +238 -0
  53. package/layouts/SimpleLayout.vue +18 -0
  54. package/mixin/navInject.js +21 -0
  55. package/mixin/navProvider.js +65 -0
  56. package/mixin/toc.js +36 -0
  57. package/package.json +50 -0
  58. package/styles/custom-block.styl +336 -0
  59. package/styles/footer.styl +248 -0
  60. package/styles/index.styl +197 -0
  61. package/styles/navbar.styl +293 -0
  62. package/styles/palette.styl +9 -0
  63. package/util/index.js +317 -0
@@ -0,0 +1,500 @@
1
+ <template>
2
+ <div v-if="openSearch" id="search-container" ref="pageContainer">
3
+ <div class="search-navbar">
4
+ <div class="search-navbar-header navbar">
5
+ <div class="main-navbar">
6
+ <NavbarLogo />
7
+ <div class="main-navbar-links can-hide">
8
+ <div class="main-navbar-item active"></div>
9
+ </div>
10
+ </div>
11
+ <div class="sub-navbar">
12
+ <div class="search-wrap">
13
+ <div class="input-wrap">
14
+ <input
15
+ ref="searchInput"
16
+ class="search-input"
17
+ :placeholder="placeholder"
18
+ type="text"
19
+ @keydown.enter="
20
+ () => {
21
+ resetSearchPage();
22
+ search();
23
+ }
24
+ "
25
+ v-model="searchValue"
26
+ />
27
+ <span class="search-input-btn">
28
+ <button
29
+ @click="
30
+ () => {
31
+ resetSearchPage();
32
+ search();
33
+ }
34
+ "
35
+ >
36
+ <svg
37
+ width="16"
38
+ height="16"
39
+ viewBox="0 0 16 16"
40
+ xmlns="http://www.w3.org/2000/svg"
41
+ >
42
+ <path
43
+ d="M11.33 10.007l4.273 4.273a.502.502 0 0 1 .005.709l-.585.584a.499.499 0 0 1-.709-.004L10.046 11.3a6.278 6.278 0 1 1 1.284-1.294zm.012-3.729a5.063 5.063 0 1 0-10.127 0 5.063 5.063 0 0 0 10.127 0z"
44
+ ></path>
45
+ </svg>
46
+ </button>
47
+ </span>
48
+ <a href="javascript:;" class="search-back__btn" @click="onSearchClose">
49
+ {{ buttonText }}
50
+ </a>
51
+ </div>
52
+
53
+ <div class="search-category">
54
+ <div class="navbar">
55
+ <div class="main-navbar">
56
+ <div class="main-navbar-links">
57
+ <template v-for="(item, index) in category">
58
+ <div :class="mainNavLinkClass(index)" :key="item.text">
59
+ <MainNavbarLink
60
+ v-if="item.link"
61
+ :key="item.text"
62
+ :item="{
63
+ ...item,
64
+ link: createLink(item),
65
+ }"
66
+ />
67
+ <a v-else href="javascript:;" @click="switchCategory(index)">
68
+ {{ item.text }}
69
+ </a>
70
+ </div>
71
+ </template>
72
+ </div>
73
+ </div>
74
+ </div>
75
+ </div>
76
+ </div>
77
+ </div>
78
+ </div>
79
+ </div>
80
+
81
+ <div class="result-number">
82
+ <span v-if="showLoading" class="uni-loading"></span>
83
+ <span v-else>{{ resultText }}</span>
84
+ </div>
85
+
86
+ <div class="search-result">
87
+ <div class="result-wrap">
88
+ <template v-if="isAlgolia">
89
+ <template v-for="item in resultList">
90
+ <Results
91
+ :key="item.sourceId"
92
+ :title="item.title"
93
+ :results="item.items"
94
+ :onSelect="item.onSelect"
95
+ />
96
+ </template>
97
+ </template>
98
+
99
+ <template v-else>
100
+ <div
101
+ class="markdown-section search-result-list"
102
+ v-if="serverHtml"
103
+ v-html="serverHtml"
104
+ ></div>
105
+ </template>
106
+ </div>
107
+
108
+ <div v-if="isAlgolia" class="algolia-logo">
109
+ <div class="DocSearch-Logo">
110
+ <a
111
+ href="https://www.algolia.com/ref/docsearch/?utm_source=uniapp.dcloud.io&amp;utm_medium=referral&amp;utm_content=powered_by&amp;utm_campaign=docsearch"
112
+ target="_blank"
113
+ rel="noopener noreferrer"
114
+ >
115
+ <span class="DocSearch-Label">{{ searchBy }}</span>
116
+ <svg width="77" height="19" aria-label="Algolia" role="img">
117
+ <path
118
+ d="M2.5067 0h14.0245c1.384.001 2.5058 1.1205 2.5068 2.5017V16.5c-.0014 1.3808-1.1232 2.4995-2.5068 2.5H2.5067C1.1232 18.9995.0014 17.8808 0 16.5V2.4958A2.495 2.495 0 01.735.7294 2.505 2.505 0 012.5068 0zM37.95 15.0695c-3.7068.0168-3.7068-2.986-3.7068-3.4634L34.2372.3576 36.498 0v11.1794c0 .2715 0 1.9889 1.452 1.994v1.8961zm-9.1666-1.8388c.694 0 1.2086-.0397 1.5678-.1088v-2.2934a5.3639 5.3639 0 00-1.3303-.1679 4.8283 4.8283 0 00-.758.0582 2.2845 2.2845 0 00-.688.2024c-.2029.0979-.371.2362-.4919.4142-.1268.1788-.185.2826-.185.5533 0 .5297.185.8359.5205 1.0375.3355.2016.7928.3053 1.365.3053v-.0008zm-.1969-8.1817c.7463 0 1.3768.092 1.8856.2767.5088.1838.9195.4428 1.2204.7717.3068.334.5147.7777.6423 1.251.1327.4723.196.991.196 1.5603v5.798c-.5235.1036-1.05.192-1.5787.2649-.7048.1037-1.4976.156-2.3774.156-.5832 0-1.1215-.0582-1.6016-.167a3.385 3.385 0 01-1.2432-.5364 2.6034 2.6034 0 01-.8037-.9565c-.191-.3922-.29-.9447-.29-1.5208 0-.5533.11-.905.3246-1.2863a2.7351 2.7351 0 01.8849-.9329c.376-.242.8029-.415 1.2948-.5187a7.4517 7.4517 0 011.5381-.156 7.1162 7.1162 0 011.6667.2024V8.886c0-.259-.0296-.5061-.093-.7372a1.5847 1.5847 0 00-.3245-.6158 1.5079 1.5079 0 00-.6119-.4158 2.6788 2.6788 0 00-.966-.173c-.5206 0-.9948.0634-1.4283.1384a6.5481 6.5481 0 00-1.065.259l-.2712-1.849c.2831-.0986.7048-.1964 1.2491-.2943a9.2979 9.2979 0 011.752-.1501v.0008zm44.6597 8.1193c.6947 0 1.2086-.0405 1.567-.1097v-2.2942a5.3743 5.3743 0 00-1.3303-.1679c-.2485 0-.503.0177-.7573.0582a2.2853 2.2853 0 00-.688.2024 1.2333 1.2333 0 00-.4918.4142c-.1268.1788-.1843.2826-.1843.5533 0 .5297.1843.8359.5198 1.0375.3414.2066.7927.3053 1.365.3053v.0009zm-.191-8.1767c.7463 0 1.3768.0912 1.8856.2759.5087.1847.9195.4436 1.2204.7717.3.329.5147.7786.6414 1.251a5.7248 5.7248 0 01.197 1.562v5.7972c-.3466.0742-.874.1602-1.5788.2648-.7049.1038-1.4976.1552-2.3774.1552-.5832 0-1.1215-.0573-1.6016-.167a3.385 3.385 0 01-1.2432-.5356 2.6034 2.6034 0 01-.8038-.9565c-.191-.3922-.2898-.9447-.2898-1.5216 0-.5533.1098-.905.3245-1.2854a2.7373 2.7373 0 01.8849-.9338c.376-.2412.8029-.4141 1.2947-.5178a7.4545 7.4545 0 012.325-.1097c.2781.0287.5672.081.879.156v-.3686a2.7781 2.7781 0 00-.092-.738 1.5788 1.5788 0 00-.3246-.6166 1.5079 1.5079 0 00-.612-.415 2.6797 2.6797 0 00-.966-.1729c-.5205 0-.9947.0633-1.4282.1384a6.5608 6.5608 0 00-1.065.259l-.2712-1.8498c.283-.0979.7048-.1957 1.2491-.2935a9.8597 9.8597 0 011.752-.1494zm-6.79-1.072c-.7576.001-1.373-.6103-1.3759-1.3664 0-.755.6128-1.3664 1.376-1.3664.764 0 1.3775.6115 1.3775 1.3664s-.6195 1.3664-1.3776 1.3664zm1.1393 11.1507h-2.2726V5.3409l2.2734-.3568v10.0845l-.0008.0017zm-3.984 0c-3.707.0168-3.707-2.986-3.707-3.4642L59.7069.3576 61.9685 0v11.1794c0 .2715 0 1.9889 1.452 1.994V15.0703zm-7.3512-4.979c0-.975-.2138-1.7873-.6305-2.3516-.4167-.571-.9998-.852-1.747-.852-.7454 0-1.3302.281-1.7452.852-.4166.5702-.6195 1.3765-.6195 2.3516 0 .9851.208 1.6473.6254 2.2183.4158.576.9998.8587 1.7461.8587.7454 0 1.3303-.2885 1.747-.8595.4158-.5761.6237-1.2315.6237-2.2184v.0009zm2.3132-.006c0 .7609-.1099 1.3361-.3356 1.9654a4.654 4.654 0 01-.9533 1.6076A4.214 4.214 0 0155.613 14.69c-.579.2412-1.4697.3795-1.9143.3795-.4462-.005-1.3303-.1324-1.9033-.3795a4.307 4.307 0 01-1.474-1.0316c-.4115-.4445-.7293-.9801-.9609-1.6076a5.3423 5.3423 0 01-.3465-1.9653c0-.7608.104-1.493.3356-2.1155a4.683 4.683 0 01.9719-1.5958 4.3383 4.3383 0 011.479-1.0257c.5739-.242 1.2043-.3567 1.8864-.3567.6829 0 1.3125.1197 1.8906.3567a4.1245 4.1245 0 011.4816 1.0257 4.7587 4.7587 0 01.9592 1.5958c.2426.6225.3643 1.3547.3643 2.1155zm-17.0198 0c0 .9448.208 1.9932.6238 2.431.4166.4386.955.6579 1.6142.6579.3584 0 .6998-.0523 1.0176-.1502.3186-.0978.5721-.2134.775-.3517V7.0784a8.8706 8.8706 0 00-1.4926-.1906c-.8206-.0236-1.4452.312-1.8847.8468-.4335.5365-.6533 1.476-.6533 2.3516v-.0008zm6.2863 4.4485c0 1.5385-.3938 2.662-1.1866 3.3773-.791.7136-2.0005 1.0712-3.6308 1.0712-.5958 0-1.834-.1156-2.8228-.334l.3643-1.7865c.8282.173 1.9202.2193 2.4932.2193.9077 0 1.555-.1847 1.943-.5533.388-.3686.578-.916.578-1.643v-.3687a6.8289 6.8289 0 01-.8848.3349c-.3634.1096-.786.167-1.261.167-.6246 0-1.1917-.0979-1.7055-.2944a3.5554 3.5554 0 01-1.3244-.8645c-.3642-.3796-.6541-.8579-.8561-1.4289-.2028-.571-.3068-1.59-.3068-2.339 0-.7034.1099-1.5856.3245-2.1735.2198-.5871.5316-1.0949.9542-1.515.4167-.42.9255-.743 1.5213-.98a5.5923 5.5923 0 012.052-.3855c.7353 0 1.4114.092 2.0707.2024.6592.1088 1.2204.2236 1.6776.35v8.945-.0008zM11.5026 4.2418v-.6511c-.0005-.4553-.3704-.8241-.8266-.8241H8.749c-.4561 0-.826.3688-.8265.824v.669c0 .0742.0693.1264.1445.1096a6.0346 6.0346 0 011.6768-.2362 6.125 6.125 0 011.6202.2185.1116.1116 0 00.1386-.1097zm-5.2806.852l-.3296-.3282a.8266.8266 0 00-1.168 0l-.393.3922a.8199.8199 0 000 1.164l.3237.323c.0524.0515.1268.0397.1733-.0117.191-.259.3989-.507.6305-.7372.2374-.2362.48-.4437.7462-.6335.0575-.0354.0634-.1155.017-.1687zm3.5159 2.069v2.818c0 .081.0879.1392.1622.0987l2.5102-1.2964c.0574-.0287.0752-.0987.0464-.1552a3.1237 3.1237 0 00-2.603-1.574c-.0575 0-.115.0456-.115.1097l-.0008-.0009zm.0008 6.789c-2.0933.0005-3.7915-1.6912-3.7947-3.7804C5.9468 8.0821 7.6452 6.39 9.7387 6.391c2.0932-.0005 3.7911 1.6914 3.794 3.7804a3.7783 3.7783 0 01-1.1124 2.675 3.7936 3.7936 0 01-2.6824 1.1054h.0008zM9.738 4.8002c-1.9218 0-3.6975 1.0232-4.6584 2.6841a5.359 5.359 0 000 5.3683c.9609 1.661 2.7366 2.6841 4.6584 2.6841a5.3891 5.3891 0 003.8073-1.5725 5.3675 5.3675 0 001.578-3.7987 5.3574 5.3574 0 00-1.5771-3.797A5.379 5.379 0 009.7387 4.801l-.0008-.0008z"
119
+ fill="currentColor"
120
+ fill-rule="evenodd"
121
+ ></path>
122
+ </svg>
123
+ </a>
124
+ </div>
125
+ </div>
126
+
127
+ <div class="search-pagination">
128
+ <pagination
129
+ v-show="showPagination"
130
+ @research="research"
131
+ :totalPage="totalPage"
132
+ :curPage="curPage"
133
+ :pageSize="pageSize"
134
+ />
135
+ <a v-if="showMoreAsk" class="search-more" @click="moreAskResult">
136
+ <span v-if="showServerLoading" class="uni-loading"></span>
137
+ <span v-else>{{ hasNoMoreServerResult ? '没有更多了' : '更多...' }}</span>
138
+ </a>
139
+ </div>
140
+ </div>
141
+ </div>
142
+ </template>
143
+
144
+ <script>
145
+ import NavbarLogo from '../NavbarLogo.vue';
146
+ import Results from './components/Results.vue';
147
+ import pagination from './components/pagination.vue';
148
+ import MainNavbarLink from '../MainNavbarLink.vue';
149
+ import { search as searchClient } from './utils/searchClient';
150
+ import { postExt, postAsk } from './utils/postDcloudServer';
151
+ import { forbidScroll, debounce } from '../../util';
152
+ import { removeHighlightTags, isEditingContent } from './utils/searchUtils';
153
+ import searchPageConfig from '@theme-config/searchPage';
154
+ import Base64 from './utils/Base64';
155
+
156
+ const {
157
+ category,
158
+ translations: {
159
+ searchBox: { placeholder, buttonText, searchBy },
160
+ resultsScreen: { resultsText, noResultsText, askNoResultsText },
161
+ },
162
+ } = searchPageConfig;
163
+
164
+ const resolveRoutePathFromUrl = (url, base = '/') =>
165
+ url
166
+ // remove url origin
167
+ .replace(/^(https?:)?\/\/[^/]*/, '');
168
+
169
+ export default {
170
+ name: 'DcloudSearchPage',
171
+
172
+ props: ['options'],
173
+
174
+ components: { NavbarLogo, Results, pagination, MainNavbarLink },
175
+
176
+ data() {
177
+ return {
178
+ openSearch: false,
179
+ placeholder,
180
+ buttonText,
181
+ searchBy,
182
+ snippetLength: 30,
183
+ searchValue: '',
184
+ category: Object.freeze(category),
185
+ categoryIndex: 0,
186
+ resultList: [],
187
+ noResult: false,
188
+ serverHtml: '',
189
+ showLoading: false,
190
+ showServerLoading: false,
191
+ hasNoMoreServerResult: false,
192
+
193
+ searchPage: 0, // 跳转页数
194
+ curHits: 0, // 当前搜索结果总条数
195
+ totalPage: 0, // 搜索结果总共页数
196
+ curPage: 1, // 当前页
197
+ pageSize: 0, // 每页条数
198
+ };
199
+ },
200
+
201
+ computed: {
202
+ currentCategory() {
203
+ return this.category[this.categoryIndex];
204
+ },
205
+ isAlgolia() {
206
+ return this.currentCategory.type === 'algolia';
207
+ },
208
+ isAsk() {
209
+ return this.currentCategory.tag === 'ask';
210
+ },
211
+ showPagination() {
212
+ return !!(this.resultList.length && this.totalPage > 1 && this.isAlgolia);
213
+ },
214
+ showMoreAsk() {
215
+ return this.isAsk && this.serverHtml;
216
+ },
217
+ resultText() {
218
+ return this.noResult
219
+ ? noResultsText.replace('${categoryText}', this.currentCategory.text)
220
+ : !this.isAsk
221
+ ? resultsText.replace('${resultHits}', this.curHits)
222
+ : askNoResultsText.replace('${categoryText}', this.currentCategory.text);
223
+ },
224
+ },
225
+
226
+ mounted() {
227
+ window.addEventListener('keydown', this.onKeyDown);
228
+ window.addEventListener('resize', () => {
229
+ this.initSnippetLength();
230
+ this.initResultWrapHeight();
231
+ });
232
+ if (this.$route.query.s) {
233
+ this.searchValue = this.$route.query.s;
234
+ this.onSearchOpen();
235
+ }
236
+ },
237
+
238
+ watch: {
239
+ resultList() {
240
+ this.$refs.pageContainer.scrollTop = 0;
241
+ },
242
+
243
+ openSearch(val) {
244
+ this.$nextTick(() => {
245
+ if (val) {
246
+ forbidScroll();
247
+ document.body.appendChild(this.$el);
248
+ this.$nextTick(() => {
249
+ this.$refs.searchInput.focus();
250
+ this.initResultWrapHeight();
251
+ });
252
+ } else {
253
+ this.cancel();
254
+ forbidScroll(false);
255
+ document.body.removeChild(this.$el);
256
+ }
257
+ });
258
+ },
259
+
260
+ searchValue: debounce(function () {
261
+ this.resetSearchPage();
262
+ this.search();
263
+ }, 300),
264
+
265
+ $route: {
266
+ immediate: true,
267
+ handler(route) {
268
+ this.categoryIndex = -1;
269
+ category
270
+ .map(item => {
271
+ return item.type === 'algolia' ? item.text : '';
272
+ })
273
+ .filter(Boolean)
274
+ .forEach((item, index) => {
275
+ if (route.path.indexOf('uni-app-x') !== -1 && item === 'uni-app x') {
276
+ this.categoryIndex = index;
277
+ } else if (route.path.indexOf(item) !== -1) {
278
+ this.categoryIndex = index;
279
+ }
280
+ });
281
+
282
+ if (this.categoryIndex === -1) this.categoryIndex = 0;
283
+ },
284
+ },
285
+ },
286
+
287
+ methods: {
288
+ initResultWrapHeight() {
289
+ if (!this.$el) return;
290
+
291
+ const pageHeight = this.$el.clientHeight;
292
+ const searchNavbar = document.querySelector('.search-navbar');
293
+ const resultNumber = document.querySelector('.result-number');
294
+ const alogliaLogo = document.querySelector('.algolia-logo');
295
+ const resultWrap = document.querySelector('.result-wrap');
296
+
297
+ const searchNavbarHeight = (searchNavbar || { clientHeight: 209 }).clientHeight;
298
+ const resultNumberHeight = (resultNumber || { clientHeight: 47 }).clientHeight;
299
+ const algoliaLogoHeight = (alogliaLogo || { clientHeight: 49 }).clientHeight;
300
+ const searchPagination = 36;
301
+
302
+ if (resultWrap)
303
+ resultWrap.style.minHeight =
304
+ pageHeight -
305
+ searchNavbarHeight -
306
+ resultNumberHeight -
307
+ algoliaLogoHeight -
308
+ searchPagination -
309
+ 20 +
310
+ 'px';
311
+ },
312
+
313
+ resetSearchPage() {
314
+ this.searchPage = 0;
315
+ },
316
+
317
+ research(curPage) {
318
+ this.searchPage = curPage - 1;
319
+ this.search();
320
+ },
321
+
322
+ search() {
323
+ if (!this.searchValue || !this.searchValue.trim().length) return;
324
+ const { type } = this.currentCategory;
325
+ switch (type) {
326
+ case 'algolia':
327
+ this.showLoading = true;
328
+ this.searchByAlgolia()
329
+ .then(({ hitsPerPage, nbHits, nbPages, page, hits }) => {
330
+ this.resultList = hits.map(item => {
331
+ const items = item.getItems();
332
+ return {
333
+ ...item,
334
+ title: removeHighlightTags(items[0]),
335
+ items,
336
+ };
337
+ });
338
+ this.noResult = !this.resultList.length;
339
+ this.curHits = nbHits;
340
+ this.pageSize = hitsPerPage;
341
+ this.totalPage = nbPages;
342
+ this.curPage = page + 1;
343
+ })
344
+ .finally(() => (this.showLoading = false));
345
+ break;
346
+ case 'server':
347
+ this.showLoading = true;
348
+ this.searchByServer().finally(() => (this.showLoading = false));
349
+ break;
350
+ }
351
+ },
352
+
353
+ searchByAlgolia() {
354
+ const { searchParameters = {} } = this.options;
355
+ let categoryArr = [`category:${this.currentCategory.text}`];
356
+ if (this.currentCategory.text === 'uni-app') {
357
+ // category:uni-app OR tag:UTS OR tag:插件
358
+ categoryArr.push('tag:UTS', 'tag:插件')
359
+ categoryArr = [categoryArr];
360
+ }
361
+ return searchClient(
362
+ Object.assign({}, this.options, {
363
+ query: `'${this.searchValue}'`,
364
+ page: this.searchPage,
365
+ snippetLength: this.snippetLength,
366
+ searchParameters: {
367
+ ...searchParameters,
368
+ facetFilters: [`lang:${this.$lang}`].concat(
369
+ searchParameters.facetFilters || [],
370
+ categoryArr
371
+ ),
372
+ },
373
+ transformItems: items =>
374
+ items.map(item => {
375
+ // the `item.url` is full url with protocol and hostname
376
+ // so we have to transform it to vue-router path
377
+ return {
378
+ ...item,
379
+ url: resolveRoutePathFromUrl(item.url, this.$site.base),
380
+ };
381
+ }),
382
+ onClose: this.onSearchClose,
383
+ })
384
+ );
385
+ },
386
+
387
+ searchByServer(append = false) {
388
+ const { tag } = this.currentCategory;
389
+ const query = this.searchValue || '';
390
+
391
+ switch (tag) {
392
+ case 'ext':
393
+ return postExt(query).then(({ html, hits }) => {
394
+ this.serverHtml = html;
395
+ this.curHits = hits;
396
+ this.noResult = !hits;
397
+ });
398
+ case 'ask':
399
+ append && (this.showServerLoading = true);
400
+ this.searchPage === 0 && (this.searchPage = 1);
401
+ return postAsk(query, this.searchPage)
402
+ .then(res => {
403
+ if (res) {
404
+ const { html = '', hits } = res;
405
+ if (append) {
406
+ this.serverHtml += html;
407
+ } else {
408
+ this.hasNoMoreServerResult = false;
409
+ this.serverHtml = html;
410
+ }
411
+ this.noResult = !this.serverHtml.length;
412
+ } else {
413
+ if (append) {
414
+ this.hasNoMoreServerResult = true;
415
+ } else {
416
+ this.serverHtml = '';
417
+ this.noResult = true;
418
+ }
419
+ }
420
+ })
421
+ .finally(() => (this.showServerLoading = false));
422
+ }
423
+ },
424
+
425
+ moreAskResult() {
426
+ if (this.hasNoMoreServerResult) return;
427
+ this.searchPage === 0 ? (this.searchPage = 2) : this.searchPage++;
428
+ this.searchByServer(true);
429
+ },
430
+
431
+ mainNavLinkClass(index) {
432
+ return ['main-navbar-item', this.categoryIndex === index ? 'active' : ''];
433
+ },
434
+
435
+ initSnippetLength() {
436
+ if (window.matchMedia('(max-width: 980px)').matches) {
437
+ this.snippetLength = 20;
438
+ }
439
+
440
+ if (window.matchMedia('(max-width: 600px)').matches) {
441
+ this.snippetLength = 15;
442
+ }
443
+
444
+ if (this.$refs.pageContainer) {
445
+ this.$refs.pageContainer.style.maxHeight = document.documentElement.clientHeight;
446
+ this.$refs.pageContainer.style.maxWidth = document.documentElement.clientWidth;
447
+ }
448
+ },
449
+
450
+ switchCategory(index) {
451
+ this.categoryIndex = index;
452
+ this.research(1);
453
+ },
454
+
455
+ cancel() {
456
+ this.resultList.length = 0;
457
+ this.searchValue = '';
458
+ this.curHits = 0;
459
+ this.totalPage = 0;
460
+ this.serverHtml = '';
461
+ this.noResult = false;
462
+ },
463
+
464
+ onSearchOpen() {
465
+ this.openSearch = true;
466
+ },
467
+
468
+ onSearchClose() {
469
+ this.openSearch = false;
470
+ },
471
+
472
+ onKeyDown(event) {
473
+ if (
474
+ (event.keyCode === 27 && this.openSearch) ||
475
+ // The `Cmd+K` shortcut both opens and closes the modal.
476
+ (event.key === 'k' && (event.metaKey || event.ctrlKey)) ||
477
+ // The `/` shortcut opens but doesn't close the modal because it's
478
+ // a character.
479
+ (!isEditingContent(event) && event.key === '/' && !this.openSearch)
480
+ ) {
481
+ event.preventDefault();
482
+
483
+ if (this.openSearch) {
484
+ this.onSearchClose();
485
+ } else {
486
+ this.onSearchOpen();
487
+ }
488
+ }
489
+ },
490
+
491
+ createLink({ link, tag }) {
492
+ return link + (tag === 'ask' ? Base64.encode(this.searchValue) : this.searchValue);
493
+ },
494
+ },
495
+ };
496
+ </script>
497
+
498
+ <style lang="stylus">
499
+ @import './index'
500
+ </style>