1class ScriptDetailLike extends Script { 2 constructor(params) { 3 super(params) 4 this.$dom = document.querySelector(`#${this.attrId}`) 5 this.$like = this.$dom.querySelector('.unit-detail-like') 6 this.$likeDom = this.$dom.querySelector('.unit-detail-like__item') 7 this.$likeDomText = this.$likeDom.querySelector('.unit-detail-like__num') 8 this.like_num = 0 9 this.proId = window.app.info.page.content_id 10 } 11 init() { 12 // æ¯å¦æ¶è 13 this._checkLike() 14 // è·åæ¶èæ° 15 this.initLikeNum() 16 // åå§åæ¶èåè½ 17 this._initLikeEvent() 18 } 19 /**æ£æ¥æ¯å¦æ¶è */ 20 _checkLike() { 21 if (window.app.info.user.is_login) { 22 LikeService.ins().checkLike(this.proId).then(res => { 23 if (res.data.result) { 24 this.$likeDom.classList.add('active') 25 this.$likeDom.querySelector('span').classList.add('icon-base-collect-fill') 26 } 27 }) 28 } 29 } 30 /**è·åæ¶èæ° */ 31 initLikeNum() { 32 if (Number(window.app.info.productDetail.favorite) > 0) this.$likeDomText.innerText = `(${window.app.info.productDetail.favorite})` 33 this.like_num = Number(window.app.info.productDetail.favorite) 34 } 35 /**åå§åæ¶èåè½ */ 36 _initLikeEvent() { 37 this.$likeDom.addEventListener('click', () => { 38 if (window.app.info.user.is_login) { 39 LikeService.ins().setLike(this.proId).then(res => { 40 if (!Utilts.ins().hasClass(this.$likeDom, 'active')) this.like_num++ 41 else this.like_num-- 42 if (this.like_num > 0) this.$likeDomText.innerText = `(${this.like_num})` 43 else this.$likeDomText.innerText = '' 44 Utilts.ins().toggleClass(this.$likeDom, 'active') 45 Utilts.ins().toggleClass(this.$likeDom.querySelector('span'), 'icon-base-collect-fill') 46 }).catch(err => console.log(err)) 47 } else { 48 new Modal().confirm(Utilts.ins().$t('Please login in first')) 49 .then(() => { 50 new Message().loading('Heading to the login page') 51 window.location.href = globalThis.Server.getRinseHref('/login.html', window.app.info.site) 52 }) 53 .catch(() => new Message().warn(Utilts.ins().$t('Cancel the login'))) 54 } 55 }) 56 } 57 58 /** åå§å¤ææ¯å¦æ¾ç¤ºæ¶è */ 59 initShowLike() { 60 // 妿å¼å¯äºæ¶èææ¾ç¤º 61 if (window.app.info.productDetail.config.display_favorite_number) { 62 this.$like.classList.remove('d-none') 63 } else { 64 this.$like.parentElement.classList.add('d-none') 65 } 66 } 67 68 render() { 69 this.initLikeNum() 70 this.initShowLike() 71 } 72} 73 74class LikeService { 75 constructor() { } 76 77 /** å便¨¡å¼ */ 78 static ins() { 79 if (!this.instance) { 80 return this.instance = new LikeService() 81 } 82 return this.instance 83 } 84 /**æ£æ¥è½å¦æ¶è */ 85 checkLike(pro_id) { 86 return new Promise((resolve, reject) => { 87 Utilts.ins().request({ 88 url: '/member-favorite/exists', 89 prefix: 'qqt', 90 method: 'GET', 91 params: { 92 site_id: window.app.info.site.site_id, 93 product_id: pro_id 94 } 95 }).then(res => { 96 if (res.code === 0) resolve(res) 97 else reject(res) 98 }).catch(err => reject(err)) 99 }) 100 } 101 /**æ¶è */ 102 setLike(pro_id) { 103 return new Promise((resolve, reject) => { 104 Utilts.ins().request({ 105 url: '/member-favorite/like-or-not', 106 prefix: 'qqt', 107 method: 'POST', 108 params: { 109 site_id: window.app.info.site.site_id, 110 product_id: pro_id 111 } 112 }).then(res => { 113 if (res.code === 0) resolve(res) 114 else reject(res) 115 }).catch(err => reject(err)) 116 }) 117 } 118}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.