fix(like): 点赞文章调整

This commit is contained in:
nineya 2023-05-30 17:09:36 +08:00
parent dca8f6d745
commit 5492cd9dc1
4 changed files with 12 additions and 4 deletions

View File

@ -108,6 +108,7 @@ const Utils = {
headers = {}, headers = {},
timeout = 10000, timeout = 10000,
returnRaw = false, returnRaw = false,
contentType,
}) { }) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
method = method.toUpperCase() method = method.toUpperCase()
@ -120,6 +121,7 @@ const Utils = {
}, },
async: true, async: true,
dataType: 'json', dataType: 'json',
contentType,
timeout, timeout,
data, data,
success(res) { success(res) {
@ -171,8 +173,14 @@ const Utils = {
let $this = $(this) let $this = $(this)
let id = $this.attr('data-id') let id = $this.attr('data-id')
Utils.request({ Utils.request({
url: '/api/content/' + type + '/' + id + '/likes', url: '/apis/api.halo.run/v1alpha1/trackers/upvote',
method: 'POST', method: 'POST',
contentType: 'application/json;charset=UTF-8',
data: JSON.stringify({
group: 'moment.halo.run',
plural: 'moments',
name: id
})
}) })
.then((_res) => { .then((_res) => {
let agrees = localStorage.getItem(name) let agrees = localStorage.getItem(name)

File diff suppressed because one or more lines are too long

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,s={"M+":e.getMonth()+1,"d+":e.getDate(),"h+":e.getHours(),"m+":e.getMinutes(),"s+":e.getSeconds()};for(a in s)new RegExp(`(${a})`).test(t)&&(r=s[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:s,headers:o={},timeout:n=1e4,returnRaw:i=!1})=>new Promise((t,a)=>{r=r.toUpperCase(),$.ajax({url:e,type:r,headers:{"API-Authorization":DreamConfig.access_key||"dream",...o},async:!0,dataType:"json",timeout:n,data:s,success(e){i?t(e):200===e.status?t(e.data||""):a(e)},error(e){e=e&&e.responseJSON?e.responseJSON.message:"请求失败";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 n=encrypt("agree-"+t);$("body").on("click",e,function(e){e.stopPropagation();let r=$(this),s=r.attr("data-id");a.request({url:"/api/content/"+t+"/"+s+"/likes",method:"POST"}).then(e=>{var t=(t=localStorage.getItem(n))?JSON.parse(decrypt(t)):[],a=+(r.attr("data-likes")||0)+1,t=(t.push(s),r.removeClass("like"),encrypt(JSON.stringify(t)));localStorage.setItem(n,t),o(r).html(a),Qmsg.success("点赞成功")})})},baiduPush(){var e=document.createElement("script"),t=window.location.protocol.split(":")[0],t=(e.src="https"===t?"https://zz.bdstatic.com/linksubmit/push.js":"http://push.zhanzhang.baidu.com/push.js",$(`script[src="${e.src}"]`).remove(),document.getElementsByTagName("script")[0]);t.parentNode.insertBefore(e,t)},toutiaoPush(){var e=document.createElement("script"),t=(e.src="https://lf1-cdn-tos.bytegoofy.com/goofy/ttzz/push.js?0fbcfbb1ed642c21419d5be02d56ade7d6ee5372ca221d12ba35df110760b2a830632485602430134f60bc55ca391050b680e2741bf7233a8f1da9902314a3fa",e.id="ttzz",$(`script[src="${e.src}"]`).remove(),document.getElementsByTagName("script")[0]);t.parentNode.insertBefore(e,t)},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 s,o=e.getBoundingClientRect(),n=window.scrollY,i=n+o.top-a,c=(i-n)/t,l=n>i?-1:1;s=window.requestAnimationFrame(function e(){(n+=c)*l<i*l?(window.scrollTo(0,n),s=window.requestAnimationFrame(e)):(window.scrollTo(0,i),window.cancelAnimationFrame(s),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,o={"M+":e.getMonth()+1,"d+":e.getDate(),"h+":e.getHours(),"m+":e.getMinutes(),"s+":e.getSeconds()};for(a in o)new RegExp(`(${a})`).test(t)&&(r=o[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:o,headers:s={},timeout:n=1e4,returnRaw:i=!1,contentType:c})=>new Promise((t,a)=>{r=r.toUpperCase(),$.ajax({url:e,type:r,headers:{"API-Authorization":DreamConfig.access_key||"dream",...s},async:!0,dataType:"json",contentType:c,timeout:n,data:o,success(e){i?t(e):200===e.status?t(e.data||""):a(e)},error(e){logger(e);e=e&&e.responseJSON?e.responseJSON.message:"请求失败";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,s){let n=encrypt("agree-"+t);$("body").on("click",e,function(e){e.stopPropagation();let r=$(this),o=r.attr("data-id");a.request({url:"/apis/api.halo.run/v1alpha1/trackers/upvote",method:"POST",contentType:"application/json;charset=UTF-8",data:JSON.stringify({group:"moment.halo.run",plural:"moments",name:o})}).then(e=>{var t=(t=localStorage.getItem(n))?JSON.parse(decrypt(t)):[],a=+(r.attr("data-likes")||0)+1,t=(t.push(o),r.removeClass("like"),encrypt(JSON.stringify(t)));localStorage.setItem(n,t),s(r).html(a),Qmsg.success("点赞成功")})})},baiduPush(){var e=document.createElement("script"),t=window.location.protocol.split(":")[0],t=(e.src="https"===t?"https://zz.bdstatic.com/linksubmit/push.js":"http://push.zhanzhang.baidu.com/push.js",$(`script[src="${e.src}"]`).remove(),document.getElementsByTagName("script")[0]);t.parentNode.insertBefore(e,t)},toutiaoPush(){var e=document.createElement("script"),t=(e.src="https://lf1-cdn-tos.bytegoofy.com/goofy/ttzz/push.js?0fbcfbb1ed642c21419d5be02d56ade7d6ee5372ca221d12ba35df110760b2a830632485602430134f60bc55ca391050b680e2741bf7233a8f1da9902314a3fa",e.id="ttzz",$(`script[src="${e.src}"]`).remove(),document.getElementsByTagName("script")[0]);t.parentNode.insertBefore(e,t)},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 o,s=e.getBoundingClientRect(),n=window.scrollY,i=n+s.top-a,c=(i-n)/t,l=n>i?-1:1;o=window.requestAnimationFrame(function e(){(n+=c)*l<i*l?(window.scrollTo(0,n),o=window.requestAnimationFrame(e)):(window.scrollTo(0,i),window.cancelAnimationFrame(o),r&&r())})}};window.Utils=a})();

View File

@ -15,7 +15,7 @@
</div> </div>
</button> </button>
<button th:if="${type == 'Post'}" class="agree like" th:data-id="${post.metadata.name}" <button th:if="${type == 'Post'}" class="agree like" th:data-id="${post.metadata.name}"
data-likes="${(post.likes!0)?c}"> th:data-likes="${post.stats.upvote}">
<i class="fa fa-thumbs-o-up"></i> <i class="fa fa-thumbs-o-up"></i>
<span><span th:text="${post.stats.upvote}"></span></span> <span><span th:text="${post.stats.upvote}"></span></span>
</button> </button>