diff --git a/src/core/main/custom/danmaku.ts b/src/core/main/custom/danmaku.ts index 6007a95..f2e7a4c 100644 --- a/src/core/main/custom/danmaku.ts +++ b/src/core/main/custom/danmaku.ts @@ -26,6 +26,7 @@ interface DanmakuInfo { comment: string; tags: string; love: number; + my_love_type: boolean; } interface DanmakuPostInfo extends Partial { @@ -379,7 +380,11 @@ export class Danmaku extends EventEmitter { id: this.id }; - const res = await axios.post(Danmaku.backend, post); + const form = toFormData(post); + /* @__PURE__ */ form.append('userid', id); + /* @__PURE__ */ form.append('password', password); + + const res = await axios.post(Danmaku.backend, form); if (res.data.code !== 0) { logger.severe( 2, @@ -451,6 +456,8 @@ export class Danmaku extends EventEmitter { * 拉取本塔所有弹幕 */ static async fetch() { + Danmaku.all.clear(); + Danmaku.allInPos = {}; const form = toFormData({ type: 1, towername: 'HumanBreak' @@ -463,6 +470,7 @@ export class Danmaku extends EventEmitter { const dan = new Danmaku(); dan.id = v.id; dan.likedNum = v.love; + dan.liked = v.my_love_type; dan.decode(v); dan.posted = true; dan.addToList(); diff --git a/src/ui/danmaku.vue b/src/ui/danmaku.vue index c677bd7..22ca102 100644 --- a/src/ui/danmaku.vue +++ b/src/ui/danmaku.vue @@ -12,10 +12,12 @@ - {{ one.likedNum }} + {{ + Math.abs(likedMap[one.id]) + }} @@ -26,7 +28,6 @@ import { nextTick, onUnmounted, reactive, watch } from 'vue'; import { Danmaku } from '../core/main/custom/danmaku'; import { LikeFilled } from '@ant-design/icons-vue'; -import { Ticker } from 'mutate-animate'; import { mainSetting } from '@/core/main/setting'; import { debounce } from 'lodash-es'; @@ -38,6 +39,8 @@ interface ElementMap { style: CSSStyleDeclaration; } +const likedMap: Record = reactive({}); + const map = Danmaku.showMap; const eleMap: Map = new Map(); const liked = reactive>({}); @@ -79,15 +82,18 @@ function addElement(id: number) { div.style.setProperty('--end', `${-div.scrollWidth}px`); div.style.setProperty( '--duration', - `${Math.floor((window.innerWidth + div.scrollWidth) / speed)}s` + `${Math.floor((window.innerWidth + div.scrollWidth + 100) / speed)}s` ); div.style.setProperty('left', ele.style.left); div.addEventListener('animationend', () => { danmaku.showEnd(); eleMap.delete(id); + delete likedMap[id]; }); eleMap.set(id, ele); + likedMap[id] = danmaku.liked ? -danmaku.likedNum : danmaku.likedNum; + calTop(id); } @@ -137,6 +143,13 @@ function calTop(id: number) { } } +async function postLike(danmaku: Danmaku) { + const res = await danmaku.triggerLike(); + + const liked = res.data.liked; + likedMap[danmaku.id] = liked ? -danmaku.likedNum : danmaku.likedNum; +} + onUnmounted(() => {}); @@ -200,6 +213,7 @@ onUnmounted(() => {}); .danmaku-like-icon { transition: color 0.1s linear; + color: white; } .danmaku-like-icon[liked='true'],