|
@@ -436,10 +436,52 @@ let searchTop = new Vue({
|
|
|
searchKeys: "",
|
|
|
right_drawer: false,
|
|
|
activeNames: '', // active names
|
|
|
+ keywords: '',
|
|
|
+ keywordsList: [],
|
|
|
+ selectUlKeys: null,
|
|
|
},
|
|
|
mounted() {
|
|
|
},
|
|
|
+ watch: {
|
|
|
+ // 关键词搜索
|
|
|
+ keywords(val) {
|
|
|
+ if (val) {
|
|
|
+ setTimeout(() => {
|
|
|
+ this.getKeywordsList(val)
|
|
|
+ }, 500)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ },
|
|
|
methods: {
|
|
|
+ async getKeywordsList(key) {
|
|
|
+ const {data} = await PublicApi.fetchQueryKeywordList({keyword: key})
|
|
|
+ this.keywordsList = data
|
|
|
+ this.selectUlKeys = document.getElementsByClassName('auto-select-list')[0]
|
|
|
+ if (data.length > 0) {
|
|
|
+ this.renderList()
|
|
|
+ this.selectUlKeys.style.display = 'block'
|
|
|
+ } else {
|
|
|
+ this.selectUlKeys.style.display = 'none'
|
|
|
+ }
|
|
|
+ },
|
|
|
+ renderList() {
|
|
|
+ this.selectUlKeys.innerHTML = ''
|
|
|
+ this.keywordsList.forEach((text) => {
|
|
|
+ const li = document.createElement('li');
|
|
|
+ li.innerHTML = text.keyword.replace(new RegExp(this.keywords, 'ig'), (match)=> '<span style="color: #FF5B00;">' + match + '</span>');
|
|
|
+ li.addEventListener('click', () => this.listItemClick(text));
|
|
|
+ this.selectUlKeys.appendChild(li);
|
|
|
+ })
|
|
|
+ },
|
|
|
+ listItemClick(text) {
|
|
|
+ this.keywords = text.keyword
|
|
|
+ this.selectUlKeys.innerHTML = ''
|
|
|
+ this.selectUlKeys.style.display = 'none'
|
|
|
+ this.itemClick(text.keyword)
|
|
|
+ },
|
|
|
+ itemClick: function (keyword) {
|
|
|
+ window.location.href = '/info/search-1.html?keyword='+keyword + '&linkageFlag=1';
|
|
|
+ },
|
|
|
// h5弹窗搜索
|
|
|
handlerH5Search() {
|
|
|
let tip = this.searchKeys === '' ? '请输入文章关键字!' : this.searchKeys.length < 2 ? '请至少输入两个关键字!' : true;
|