1 2class ScriptProductMightLike extends Script{ 3 constructor(params) { 4 super(params) 5 this.product_ids = JSON.parse(params.product_id) 6 this.likeService = ListLikeService.ins() 7 this.$dom = document.querySelector(`#${this.attrId}`) 8 this.$like = this.$dom.querySelectorAll('.unit-list__like') 9 this.$item = this.$dom.querySelectorAll('.unit-list__item') 10 this.isLogin = !!window.app.info.user.is_login 11 } 12 async init() { 13 if (this.isLogin) this.checkLikeStatus() 14 this.initNodeEvent() 15 } 16 /** ç»å®ç¹èµäºä»¶ */ 17 initNodeEvent() { 18 Array.from(this.$like).forEach(($el, index) => { 19 $el.addEventListener('click', (e) => { 20 e.preventDefault() 21 e.stopPropagation() 22 if (this.isLogin) { 23 this.likeService.setLike(this.product_ids[index]).then(res => { 24 Utilts.ins().toggleClass($el, 'active') 25 Utilts.ins().toggleClass($el.querySelector('i'), 'icon-base-collection-fill') 26 }) 27 } else window.location.href = globalThis.Server.getRinseHref('/login.html', window.app.info.site) 28 }) 29 }) 30 } 31 /** 夿ç¹èµç¶æ */ 32 checkLikeStatus() { 33 this.likeService.checkLike(this.product_ids.join(',')).then(res => { 34 const ids = res.data.map((item) => item.product_id) 35 for (let $el of this.$like) { 36 if (ids.includes(Number($el.getAttribute('data-id')))) { 37 Utilts.ins().toggleClass($el, 'active') 38 Utilts.ins().toggleClass($el.querySelector('i'), 'icon-base-collect-fill') 39 } 40 } 41 }) 42 } 43} 44 45class ListLikeService { 46 constructor() {} 47 /** å便¨¡å¼ */ 48 static ins() { 49 if (!this.instance) { 50 return this.instance = new ListLikeService() 51 } 52 return this.instance 53 } 54 /** ç¹èµåè½ */ 55 setLike(id) { 56 return new Promise((resolve, reject) => { 57 Utilts.ins().request({ 58 url: '/member-favorite/like-or-not', 59 prefix: 'qqt', 60 method: 'POST', 61 params: { 62 site_id: window.app.info.site.site_id, 63 product_id: id 64 } 65 }).then(res => { 66 if(res.code === 0) resolve(res) 67 else reject(res) 68 }).catch(err =>reject(err)) 69 }) 70 } 71 /** æ£æ¥æ¯å¦ç¹èµ */ 72 checkLike(ids) { 73 return new Promise((resolve, reject) => { 74 Utilts.ins().request({ 75 url: '/member-favorite/exists-by-product', 76 prefix: 'qqt', 77 params: { 78 site_id: window.app.info.site.site_id, 79 product_id: ids 80 } 81 }).then(res => { 82 if(res.code === 0) resolve(res) 83 else reject(res) 84 }).catch(err =>reject(err)) 85 }) 86 } 87}
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.