diff --git a/frontend/src/components/ChatRenderer/index.vue b/frontend/src/components/ChatRenderer/index.vue index a374cb1..7ae6cc4 100644 --- a/frontend/src/components/ChatRenderer/index.vue +++ b/frontend/src/components/ChatRenderer/index.vue @@ -73,7 +73,6 @@ export default { PaidMessage }, props: { - css: String, maxNumber: { type: Number, default: chatConfig.DEFAULT_CONFIG.maxNumber @@ -84,15 +83,12 @@ export default { } }, data() { - let styleElement = document.createElement('style') - document.head.appendChild(styleElement) return { MESSAGE_TYPE_TEXT: constants.MESSAGE_TYPE_TEXT, MESSAGE_TYPE_GIFT: constants.MESSAGE_TYPE_GIFT, MESSAGE_TYPE_MEMBER: constants.MESSAGE_TYPE_MEMBER, MESSAGE_TYPE_SUPER_CHAT: constants.MESSAGE_TYPE_SUPER_CHAT, - styleElement, messages: [], // 显示的消息 paidMessages: [], // 固定在上方的消息 @@ -122,19 +118,14 @@ export default { } }, watch: { - css(val) { - this.styleElement.innerText = val - }, canScrollToBottom(val) { this.cantScrollStartTime = val ? null : new Date() } }, mounted() { - this.styleElement.innerText = this.css this.scrollToBottom() }, beforeDestroy() { - document.head.removeChild(this.styleElement) if (this.emitSmoothedMessageTimerId) { window.clearTimeout(this.emitSmoothedMessageTimerId) this.emitSmoothedMessageTimerId = null diff --git a/frontend/src/main.js b/frontend/src/main.js index 9a19e49..14e9ca8 100644 --- a/frontend/src/main.js +++ b/frontend/src/main.js @@ -76,7 +76,7 @@ const router = new VueRouter({ {path: 'help', name: 'help', component: Help} ] }, - {path: '/room/test', name: 'test_room', component: Room, props: {roomId: null}}, + {path: '/room/test', name: 'test_room', component: Room}, { path: '/room/:roomId', name: 'room', @@ -86,7 +86,7 @@ const router = new VueRouter({ if (isNaN(roomId)) { roomId = null } - return {roomId} + return {roomId, strConfig: route.query} } }, {path: '*', component: NotFound} diff --git a/frontend/src/views/Room.vue b/frontend/src/views/Room.vue index 6d6baf0..e700c7e 100644 --- a/frontend/src/views/Room.vue +++ b/frontend/src/views/Room.vue @@ -18,7 +18,14 @@ export default { ChatRenderer }, props: { - roomId: Number + roomId: { + type: Number, + default: null + }, + strConfig: { + type: Object, + default: () => ({}) + } }, data() { return { @@ -58,9 +65,9 @@ export default { initConfig() { let cfg = {} // 留空的使用默认值 - for (let i in this.$route.query) { - if (this.$route.query[i] !== '') { - cfg[i] = this.$route.query[i] + for (let i in this.strConfig) { + if (this.strConfig[i] !== '') { + cfg[i] = this.strConfig[i] } } cfg = mergeConfig(cfg, chatConfig.DEFAULT_CONFIG) @@ -101,6 +108,13 @@ export default { this.chatClient.start() }, + start() { + this.chatClient.start() + }, + stop() { + this.chatClient.stop() + }, + onAddText(data) { if (!this.config.showDanmaku || !this.filterTextMessage(data) || this.mergeSimilarText(data.content)) { return diff --git a/frontend/src/views/StyleGenerator/Legacy.vue b/frontend/src/views/StyleGenerator/Legacy.vue index 8106360..3645946 100644 --- a/frontend/src/views/StyleGenerator/Legacy.vue +++ b/frontend/src/views/StyleGenerator/Legacy.vue @@ -340,9 +340,6 @@ - - {{$t('stylegen.playAnimation')}} - diff --git a/frontend/src/views/StyleGenerator/LineLike.vue b/frontend/src/views/StyleGenerator/LineLike.vue index 467cc1c..b2aad8d 100644 --- a/frontend/src/views/StyleGenerator/LineLike.vue +++ b/frontend/src/views/StyleGenerator/LineLike.vue @@ -290,9 +290,6 @@ - - {{$t('stylegen.playAnimation')}} - diff --git a/frontend/src/views/StyleGenerator/index.vue b/frontend/src/views/StyleGenerator/index.vue index 1095055..e0c2971 100644 --- a/frontend/src/views/StyleGenerator/index.vue +++ b/frontend/src/views/StyleGenerator/index.vue @@ -3,10 +3,10 @@ - + - + @@ -26,12 +26,17 @@
-

- -

+ + + + + + + +
- +
@@ -44,103 +49,16 @@ import _ from 'lodash' import Legacy from './Legacy' import LineLike from './LineLike' -import ChatRenderer from '@/components/ChatRenderer' -import * as constants from '@/components/ChatRenderer/constants' - -let time = new Date() -let textMessageTemplate = { - id: 0, - addTime: time, - type: constants.MESSAGE_TYPE_TEXT, - avatarUrl: 'https://static.hdslb.com/images/member/noface.gif', - time: time, - authorName: '', - authorType: constants.AUTHRO_TYPE_NORMAL, - content: '', - privilegeType: 0, - repeated: 1, - translation: '' -} -let membershipItemTemplate = { - id: 0, - addTime: time, - type: constants.MESSAGE_TYPE_MEMBER, - avatarUrl: 'https://static.hdslb.com/images/member/noface.gif', - time: time, - authorName: '', - privilegeType: 3, - title: 'New member' -} -let paidMessageTemplate = { - id: 0, - addTime: time, - type: constants.MESSAGE_TYPE_SUPER_CHAT, - avatarUrl: 'https://static.hdslb.com/images/member/noface.gif', - authorName: '', - price: 0, - time: time, - content: '', - translation: '' -} -let nextId = 0 -const EXAMPLE_MESSAGES = [ - { - ...textMessageTemplate, - id: (nextId++).toString(), - authorName: 'mob路人', - content: '8888888888', - repeated: 12 - }, - { - ...textMessageTemplate, - id: (nextId++).toString(), - authorName: 'member舰长', - authorType: constants.AUTHRO_TYPE_MEMBER, - content: '草', - privilegeType: 3, - repeated: 3 - }, - { - ...textMessageTemplate, - id: (nextId++).toString(), - authorName: 'admin房管', - authorType: constants.AUTHRO_TYPE_ADMIN, - content: 'kksk' - }, - { - ...membershipItemTemplate, - id: (nextId++).toString(), - authorName: 'xfgryujk' - }, - { - ...paidMessageTemplate, - id: (nextId++).toString(), - authorName: '小陈', - price: 66600, - content: 'Sent 小电视飞船x100' - }, - { - ...textMessageTemplate, - id: (nextId++).toString(), - authorName: 'streamer主播', - authorType: constants.AUTHRO_TYPE_OWNER, - content: '老板大气,老板身体健康' - }, - { - ...paidMessageTemplate, - id: (nextId++).toString(), - authorName: '叔叔 / おじさん', - price: 30, - content: '言いたいことがあるんだよ!' - } -] +import Room from '@/views/Room' export default { name: 'StyleGenerator', components: { - Legacy, LineLike, ChatRenderer + Legacy, LineLike, Room }, data() { + let styleElement = document.createElement('style') + document.head.appendChild(styleElement) // 数据流: // 输入框 --\ // 子组件 -> subComponentResults -> subComponentResult -> inputResult -> 防抖延迟0.5s后 -> debounceResult -> exampleCss @@ -156,7 +74,9 @@ export default { // 防抖后延迟变化的结果 debounceResult: '', + styleElement, exampleTop: 0, + playAnimation: true, exampleBgLight: false } }, @@ -176,17 +96,20 @@ export default { }, inputResult: _.debounce(function(val) { this.debounceResult = val - }, 500) + }, 500), + exampleCss(val) { + this.styleElement.innerText = val + } }, mounted() { this.debounceResult = this.inputResult = this.subComponentResult - this.$refs.renderer.addMessages(EXAMPLE_MESSAGES) - this.$parent.$el.addEventListener('scroll', this.onParentScroll) }, beforeDestroy() { this.$parent.$el.removeEventListener('scroll', this.onParentScroll) + + document.head.removeChild(this.styleElement) }, methods: { onParentScroll(event) { @@ -196,10 +119,12 @@ export default { this.exampleTop = event.target.scrollTop } }, - async playAnimation() { - this.$refs.renderer.clearMessages() - await this.$nextTick() - this.$refs.renderer.addMessages(EXAMPLE_MESSAGES) + onPlayAnimationChange(value) { + if (value) { + this.$refs.room.start() + } else { + this.$refs.room.stop() + } }, copyResult() { this.$refs.result.select()