$(function () { // 搜索结果页 function getSearchList (keyword) { const val = keyword $('#result-input').val(val) $('.keyword').text(`“${val}”`) $.ajax({ url: `/console/v1/help?keywords=${val}`, method: 'get', success: function (res) { const temp = res.data.list.reduce((all, cur) => { const helps = cur.helps.filter(fil => fil.search) all.push(...helps) return all }, []) $('.search-result').html('') if (temp.length > 0) { temp.forEach((item, index) => { $('.keyword-box').show() $('.search-result').append( `
${item.title}

${item.des || ''}

来自: 产品 > 帮助中心
` ) }) } else { $('.search-result').append( `

抱歉,没有搜索到,请重新搜索

` ) $('.keyword-box').hide() } } }) } getSearchList(decodeURI(location.search.split('?')[1]?.split('=')[1])); $('#search-btn').click(function () { const keyword = $('#result-input').val() getSearchList(keyword) }) })