更改搜索功能

This commit is contained in:
j m 2024-08-05 06:34:44 +08:00
parent 0f70eae333
commit a53a772ccc
4 changed files with 11 additions and 5 deletions

View File

@ -109,7 +109,8 @@ const Utils = {
timeout = 10000,
returnRaw = false,
contentType,
resultType = 'json'
resultType = 'json',
noErrorTip = false,
}) {
return new Promise((resolve, reject) => {
method = method.toUpperCase()
@ -142,7 +143,9 @@ const Utils = {
? err.responseJSON.title
: '请求失败'
: '请求失败'
Qmsg.error(errMsg)
if(!noErrorTip) {
Qmsg.error(errMsg)
}
reject(errMsg)
},
})

View File

@ -1 +1 @@
(()=>{const a={isMobile:()=>!!(navigator.userAgent.match(/Android/i)||navigator.userAgent.match(/webOS/i)||navigator.userAgent.match(/iPhone/i)||navigator.userAgent.match(/iPad/i)||navigator.userAgent.match(/iPod/i)||navigator.userAgent.match(/BlackBerry/i)||navigator.userAgent.match(/Windows Phone/i)),cachedScript:(e,t)=>$.ajax(jQuery.extend({url:e,type:"get",dataType:"script",cache:!0,success:t},$.isPlainObject(e)&&e)),formatDate(e,t="yyyy-MM-dd"){e=new Date(e),/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(e.getFullYear()+"").substr(4-RegExp.$1.length)));var a,r,n={"M+":e.getMonth()+1,"d+":e.getDate(),"h+":e.getHours(),"m+":e.getMinutes(),"s+":e.getSeconds()};for(a in n)new RegExp(`(${a})`).test(t)&&(r=n[a]+"",t=t.replace(RegExp.$1,1===RegExp.$1.length?r:r.padStart(2,"0")));return t},getUrlParams(){var e=location.search,e=(e="string"!=typeof e?e.toString():e).replace(/^[^\?]*\?/i,"").split(/&/),a={};return e.length<1||Array.isArray(e)&&e.forEach(function(e){if(!e)return!1;var t,e=e.split(/=/);2<=e.length&&(t=e.splice(0,1),a[t]=e.join("="))}),a},randomColor(e){var t=["#F8D800","#0396FF","#EA5455","#7367F0","#32CCBC","#F6416C","#28C76F","#9F44D3","#F55555","#736EFE","#E96D71","#DE4313","#D939CD","#4C83FF","#F072B6","#C346C2","#5961F9","#FD6585","#465EFB","#FFC600","#FA742B","#5151E5","#BB4E75","#FF52E5","#49C628","#00EAFF","#F067B4","#F067B4","#ff9a9e","#00f2fe","#4facfe","#f093fb","#6fa3ef","#bc99c4","#46c47c","#f9bb3c","#e8583d","#f68e5f"];return t[e%t.length]},request:({url:e="",method:r="GET",data:n,headers:o={},timeout:s=1e4,returnRaw:i=!1,contentType:l,resultType:c="json"})=>new Promise((t,a)=>{r=r.toUpperCase(),$.ajax({url:e,type:r,headers:{"API-Authorization":DreamConfig.access_key||"dream",...o},async:!0,dataType:c,contentType:l,timeout:s,data:n,success(e){i?t(e):200===e.status?t(e.data||""):a(e)},error(e){e=e&&e.responseJSON?e.responseJSON.title:"请求失败";Qmsg.error(e),a(e)}})}),initLikeButton(e,t){t=encrypt("agree-"+t);let a=localStorage.getItem(t);a=a?JSON.parse(decrypt(a)):[],$(e).each(function(){var e=$(this),t=e.attr("data-id");a.includes(t)&&e.removeClass("like")})},initLikeEvent(e,t,o){let s=encrypt("agree-"+t);$("body").on("click",e,function(e){e.stopPropagation();let r=$(this),n=r.attr("data-id");a.request({url:"/apis/api.halo.run/v1alpha1/trackers/upvote",method:"POST",contentType:"application/json;charset=UTF-8",returnRaw:!0,resultType:"text",data:JSON.stringify({group:"moments"===t?"moment.halo.run":"content.halo.run",plural:t,name:n})}).then(e=>{var t=(t=localStorage.getItem(s))?JSON.parse(decrypt(t)):[],a=+(r.attr("data-likes")||0)+1,t=(t.push(n),r.removeClass("like"),encrypt(JSON.stringify(t)));localStorage.setItem(s,t),o(r).html(a),Qmsg.success("点赞成功")})})},sleep:(t=250)=>new Promise(e=>setTimeout(e,t)),foldBlock(e){var t,a=e.height();e.is(".fold")?e.removeClass("fold").addClass("unfold"):(t=document.documentElement.scrollTop||document.body.scrollTop||window.pageYOffset,e.addClass("fold").removeClass("unfold"),$("body,html").scrollTop(t-a+e.height()))},removeClassByPrefix(e,t){var a=e.className.split(" ").filter(function(e){return 0!==e.lastIndexOf(t,0)});e.className=a.join(" ").trim()},animateScroll(e,t,a,r){let n,o=e.getBoundingClientRect(),s=window.scrollY,i=s+o.top-a,l=(i-s)/t,c=s>i?-1:1;n=window.requestAnimationFrame(function e(){(s+=l)*c<i*c?(window.scrollTo(0,s),n=window.requestAnimationFrame(e)):(window.scrollTo(0,i),window.cancelAnimationFrame(n),r&&r())})}};window.Utils=a})();
(()=>{const a={isMobile:()=>!!(navigator.userAgent.match(/Android/i)||navigator.userAgent.match(/webOS/i)||navigator.userAgent.match(/iPhone/i)||navigator.userAgent.match(/iPad/i)||navigator.userAgent.match(/iPod/i)||navigator.userAgent.match(/BlackBerry/i)||navigator.userAgent.match(/Windows Phone/i)),cachedScript:(e,t)=>$.ajax(jQuery.extend({url:e,type:"get",dataType:"script",cache:!0,success:t},$.isPlainObject(e)&&e)),formatDate(e,t="yyyy-MM-dd"){e=new Date(e),/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(e.getFullYear()+"").substr(4-RegExp.$1.length)));var a,r,n={"M+":e.getMonth()+1,"d+":e.getDate(),"h+":e.getHours(),"m+":e.getMinutes(),"s+":e.getSeconds()};for(a in n)new RegExp(`(${a})`).test(t)&&(r=n[a]+"",t=t.replace(RegExp.$1,1===RegExp.$1.length?r:r.padStart(2,"0")));return t},getUrlParams(){var e=location.search,e=(e="string"!=typeof e?e.toString():e).replace(/^[^\?]*\?/i,"").split(/&/),a={};return e.length<1||Array.isArray(e)&&e.forEach(function(e){if(!e)return!1;var t,e=e.split(/=/);2<=e.length&&(t=e.splice(0,1),a[t]=e.join("="))}),a},randomColor(e){var t=["#F8D800","#0396FF","#EA5455","#7367F0","#32CCBC","#F6416C","#28C76F","#9F44D3","#F55555","#736EFE","#E96D71","#DE4313","#D939CD","#4C83FF","#F072B6","#C346C2","#5961F9","#FD6585","#465EFB","#FFC600","#FA742B","#5151E5","#BB4E75","#FF52E5","#49C628","#00EAFF","#F067B4","#F067B4","#ff9a9e","#00f2fe","#4facfe","#f093fb","#6fa3ef","#bc99c4","#46c47c","#f9bb3c","#e8583d","#f68e5f"];return t[e%t.length]},request:({url:e="",method:r="GET",data:n,headers:o={},timeout:s=1e4,returnRaw:i=!1,contentType:l,resultType:c="json",noErrorTip:d=!1})=>new Promise((t,a)=>{r=r.toUpperCase(),$.ajax({url:e,type:r,headers:{"API-Authorization":DreamConfig.access_key||"dream",...o},async:!0,dataType:c,contentType:l,timeout:s,data:n,success(e){i?t(e):200===e.status?t(e.data||""):a(e)},error(e){e=e&&e.responseJSON?e.responseJSON.title:"请求失败";d||Qmsg.error(e),a(e)}})}),initLikeButton(e,t){t=encrypt("agree-"+t);let a=localStorage.getItem(t);a=a?JSON.parse(decrypt(a)):[],$(e).each(function(){var e=$(this),t=e.attr("data-id");a.includes(t)&&e.removeClass("like")})},initLikeEvent(e,t,o){let s=encrypt("agree-"+t);$("body").on("click",e,function(e){e.stopPropagation();let r=$(this),n=r.attr("data-id");a.request({url:"/apis/api.halo.run/v1alpha1/trackers/upvote",method:"POST",contentType:"application/json;charset=UTF-8",returnRaw:!0,resultType:"text",data:JSON.stringify({group:"moments"===t?"moment.halo.run":"content.halo.run",plural:t,name:n})}).then(e=>{var t=(t=localStorage.getItem(s))?JSON.parse(decrypt(t)):[],a=+(r.attr("data-likes")||0)+1,t=(t.push(n),r.removeClass("like"),encrypt(JSON.stringify(t)));localStorage.setItem(s,t),o(r).html(a),Qmsg.success("点赞成功")})})},sleep:(t=250)=>new Promise(e=>setTimeout(e,t)),foldBlock(e){var t,a=e.height();e.is(".fold")?e.removeClass("fold").addClass("unfold"):(t=document.documentElement.scrollTop||document.body.scrollTop||window.pageYOffset,e.addClass("fold").removeClass("unfold"),$("body,html").scrollTop(t-a+e.height()))},removeClassByPrefix(e,t){var a=e.className.split(" ").filter(function(e){return 0!==e.lastIndexOf(t,0)});e.className=a.join(" ").trim()},animateScroll(e,t,a,r){let n,o=e.getBoundingClientRect(),s=window.scrollY,i=s+o.top-a,l=(i-s)/t,c=s>i?-1:1;n=window.requestAnimationFrame(function e(){(s+=l)*c<i*c?(window.scrollTo(0,s),n=window.requestAnimationFrame(e)):(window.scrollTo(0,i),window.cancelAnimationFrame(n),r&&r())})}};window.Utils=a})();

View File

@ -53,7 +53,8 @@
limit: $('#halo-search-form-limit').val(),
highlightPreTag: '<mark>',
highlightPostTag: '</mark>'
}
},
noErrorTip: true
})
.then((_res) => {
if (_res.hits.length > 0) {
@ -89,6 +90,8 @@
}
})
.catch((err) => {
searchResultEmpty.hide()
searchResult.empty()
})
}

View File

@ -30,7 +30,7 @@ spec:
settingName: theme-dream2-plus-setting
configMapName: theme-dream2-plus-configMap
# 版本号
version: 1.2.7.beta3
version: 1.2.7.beta4
# 最低支持的 Halo 版本
require: ">=2.15.0"
# 许可