提交 d0ea2a29 编写于 作者: D DCloud_LXH

wip: dcloud search page

上级 6b977787
......@@ -107,7 +107,7 @@ $svg-hover-color = #9b9b9b
display flex
justify-content center
align-items center
margin-top 20px
padding-top 20px
font-size 20px
.DocSearch-Logo
......@@ -124,6 +124,11 @@ $svg-hover-color = #9b9b9b
margin 0
padding 0
.algolia-logo
display flex
justify-content center
padding 10px 0 20px
@media (max-width $MQMobile)
#search-container
.search-navbar-header>.main-navbar
......
......@@ -42,14 +42,7 @@
<div class="main-navbar-links">
<template v-for="(item, index) in category">
<div :class="mainNavLinkClass(index)" :key="item.text">
<MainNavbarLink
:key="item.text"
v-if="item.link"
:item="{
...item,
link: searchLink(item.link),
}"
/>
<MainNavbarLink v-if="item.link" :key="item.text" :item="item" />
<a v-else href="javascript:;" @click="switchCategory(index)">
{{ item.text }}
</a>
......@@ -85,7 +78,7 @@
</template>
</div>
<div v-if="isAlgolia" style="display: flex; justify-content: center; margin: 10px 0 20px">
<div v-if="isAlgolia" class="algolia-logo">
<div class="DocSearch-Logo">
<a
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"
......@@ -124,13 +117,7 @@
import MainNavbarLink from '../MainNavbarLink.vue';
import { search as searchClient } from './searchClient';
import { postExt, postAsk } from './postDcloudServer';
import {
forbidScroll,
removeHighlightTags,
debounce,
isEditingContent,
Base64Encode,
} from '../../util';
import { forbidScroll, removeHighlightTags, debounce, isEditingContent } from '../../util';
const resolveRoutePathFromUrl = (url, base = '/') =>
url
......@@ -173,11 +160,6 @@
tag: 'ext',
type: 'server',
},
{
text: 'DCloud 社区',
type: 'link',
link: 'https://ask.dcloud.net.cn/search/q-',
},
{
text: '原生开发文档',
type: 'link',
......@@ -229,7 +211,10 @@
if (val) {
forbidScroll();
document.body.appendChild(this.$el);
this.$nextTick(() => this.$refs.searchInput.focus());
this.$nextTick(() => {
this.$refs.searchInput.focus();
this.initResultWrapHeight();
});
} else {
this.cancel();
forbidScroll(false);
......@@ -245,8 +230,14 @@
},
methods: {
searchLink(link) {
return link + (link.includes('ask') ? Base64Encode(this.searchValue) : this.searchValue);
initResultWrapHeight() {
const pageHeight = this.$el.clientHeight;
const searchNavbarHeight = document.querySelector('.search-navbar').clientHeight;
const resultNumberHeight = document.querySelector('.result-number').clientHeight;
const algoliaLogoHeight = document.querySelector('.algolia-logo').clientHeight;
document.querySelector('.result-wrap').style.minHeight =
pageHeight - searchNavbarHeight - resultNumberHeight - algoliaLogoHeight - 20 + 'px';
},
resetSearchPage() {
......@@ -349,7 +340,6 @@
},
switchCategory(index) {
this.curHits = 0;
this.categoryIndex = index;
this.research(1);
},
......@@ -359,6 +349,7 @@
this.searchValue = '';
this.curHits = 0;
this.totalPage = 0;
this.serverHtml = '';
},
onSearchOpen() {
......
var validBitList = [
[7],
[5, 6],
[4, 6, 6],
[3, 6, 6, 6],
[2, 6, 6, 6, 6],
[1, 6, 6, 6, 6, 6]
]
var otherByteBase = 1 << 7
var b64Info = new Array(6)
for (var i = 0; i < validBitList.length; i++) {
var validBit = validBitList[i]
var firstByteBase
if (i === 0) {
firstByteBase = 0
}
var fillLength = validBit[0] + 1
firstByteBase = 255 >> fillLength << fillLength
b64Info[i] = {
validBit,
firstByteBase,
otherByteBase,
maxValue: Math.pow(2, sum(validBit)) - 1 // 移位会溢出,使用Math.pow计算
}
}
function sum(arr) {
return arr.reduce(function (total, value) {
return total + value
}, 0)
}
function Encoder() {
this.remainder = 0
this.remainderBit = 0
this.utf8ArrLength = 0
this.result = ''
}
Encoder.prototype.push = function (utf8Code) {
this.utf8ArrLength++
var remainderMoveBit = (6 - this.remainderBit)
this.remainderBit = 8 - remainderMoveBit
var b64Value1 = this.remainder << remainderMoveBit
var b64Value2 = utf8Code >> this.remainderBit
var b64Value = b64Value1 + b64Value2
this.remainder = utf8Code - (b64Value2 << this.remainderBit)
this.result += b64CodeToString(b64Value)
if (this.remainderBit === 6) {
this.result += b64CodeToString(this.remainder)
this.remainder = 0
this.remainderBit = 0
}
}
Encoder.prototype.flush = function () {
if (this.remainderBit) {
var b64Value = this.remainder << (6 - this.remainderBit)
this.result += b64CodeToString(b64Value)
}
var eqLength = (3 - (this.utf8ArrLength % 3)) % 3
this.result += '='.repeat(eqLength)
}
function charCodeToUtf8(code) {
var lengthIndex
for (var i = 0; i < b64Info.length; i++) {
var maxValue = b64Info[i].maxValue;
if (code <= maxValue) {
lengthIndex = i
break;
}
}
if (lengthIndex === undefined) {
throw new Error('invalid char code')
}
var {
validBit,
firstByteBase,
otherByteBase,
} = b64Info[lengthIndex]
var result = []
for (var i = validBit.length - 1; i >= 0; i--) {
var base = i === 0 ? firstByteBase : otherByteBase
var tempCode = code >>> validBit[i]
result.unshift(base + code - (tempCode << validBit[i]))
code = tempCode
}
return result
}
export function Base64Encode(str) {
// 一次循环计算出结果,减少内存占用
var encoder = new Encoder()
for (var i = 0; i < str.length; i++) {
var charCode = str.charCodeAt(i);
var utf8Arr = charCodeToUtf8(charCode)
utf8Arr.forEach(function (item) {
encoder.push(item)
});
}
encoder.flush()
return encoder.result
}
function b64CodeToString(code) {
return String.fromCharCode(uint6ToB64(code))
}
/**
* 将base64 code转换为字符对应的char code
*/
function uint6ToB64(nUint6) {
return nUint6 < 26 ?
nUint6 + 65 :
nUint6 < 52 ?
nUint6 + 71 :
nUint6 < 62 ?
nUint6 - 4 :
nUint6 === 62 ?
43 :
nUint6 === 63 ?
47 :
65;
}
\ No newline at end of file
import Vue from 'vue';
export * from './searchUtils';
export * from './base64Encode';
export const isServer = Vue.prototype.$isServer
export const hashRE = /#.*$/
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册