样式生成器预览内容自动生成

This commit is contained in:
John Smith 2021-04-05 20:55:31 +08:00
parent e8f77cd2e0
commit e2f925426a
6 changed files with 49 additions and 125 deletions

View File

@ -73,7 +73,6 @@ export default {
PaidMessage PaidMessage
}, },
props: { props: {
css: String,
maxNumber: { maxNumber: {
type: Number, type: Number,
default: chatConfig.DEFAULT_CONFIG.maxNumber default: chatConfig.DEFAULT_CONFIG.maxNumber
@ -84,15 +83,12 @@ export default {
} }
}, },
data() { data() {
let styleElement = document.createElement('style')
document.head.appendChild(styleElement)
return { return {
MESSAGE_TYPE_TEXT: constants.MESSAGE_TYPE_TEXT, MESSAGE_TYPE_TEXT: constants.MESSAGE_TYPE_TEXT,
MESSAGE_TYPE_GIFT: constants.MESSAGE_TYPE_GIFT, MESSAGE_TYPE_GIFT: constants.MESSAGE_TYPE_GIFT,
MESSAGE_TYPE_MEMBER: constants.MESSAGE_TYPE_MEMBER, MESSAGE_TYPE_MEMBER: constants.MESSAGE_TYPE_MEMBER,
MESSAGE_TYPE_SUPER_CHAT: constants.MESSAGE_TYPE_SUPER_CHAT, MESSAGE_TYPE_SUPER_CHAT: constants.MESSAGE_TYPE_SUPER_CHAT,
styleElement,
messages: [], // messages: [], //
paidMessages: [], // paidMessages: [], //
@ -122,19 +118,14 @@ export default {
} }
}, },
watch: { watch: {
css(val) {
this.styleElement.innerText = val
},
canScrollToBottom(val) { canScrollToBottom(val) {
this.cantScrollStartTime = val ? null : new Date() this.cantScrollStartTime = val ? null : new Date()
} }
}, },
mounted() { mounted() {
this.styleElement.innerText = this.css
this.scrollToBottom() this.scrollToBottom()
}, },
beforeDestroy() { beforeDestroy() {
document.head.removeChild(this.styleElement)
if (this.emitSmoothedMessageTimerId) { if (this.emitSmoothedMessageTimerId) {
window.clearTimeout(this.emitSmoothedMessageTimerId) window.clearTimeout(this.emitSmoothedMessageTimerId)
this.emitSmoothedMessageTimerId = null this.emitSmoothedMessageTimerId = null

View File

@ -76,7 +76,7 @@ const router = new VueRouter({
{path: 'help', name: 'help', component: Help} {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', path: '/room/:roomId',
name: 'room', name: 'room',
@ -86,7 +86,7 @@ const router = new VueRouter({
if (isNaN(roomId)) { if (isNaN(roomId)) {
roomId = null roomId = null
} }
return {roomId} return {roomId, strConfig: route.query}
} }
}, },
{path: '*', component: NotFound} {path: '*', component: NotFound}

View File

@ -18,7 +18,14 @@ export default {
ChatRenderer ChatRenderer
}, },
props: { props: {
roomId: Number roomId: {
type: Number,
default: null
},
strConfig: {
type: Object,
default: () => ({})
}
}, },
data() { data() {
return { return {
@ -58,9 +65,9 @@ export default {
initConfig() { initConfig() {
let cfg = {} let cfg = {}
// 使 // 使
for (let i in this.$route.query) { for (let i in this.strConfig) {
if (this.$route.query[i] !== '') { if (this.strConfig[i] !== '') {
cfg[i] = this.$route.query[i] cfg[i] = this.strConfig[i]
} }
} }
cfg = mergeConfig(cfg, chatConfig.DEFAULT_CONFIG) cfg = mergeConfig(cfg, chatConfig.DEFAULT_CONFIG)
@ -101,6 +108,13 @@ export default {
this.chatClient.start() this.chatClient.start()
}, },
start() {
this.chatClient.start()
},
stop() {
this.chatClient.stop()
},
onAddText(data) { onAddText(data) {
if (!this.config.showDanmaku || !this.filterTextMessage(data) || this.mergeSimilarText(data.content)) { if (!this.config.showDanmaku || !this.filterTextMessage(data) || this.mergeSimilarText(data.content)) {
return return

View File

@ -340,9 +340,6 @@
</el-form-item> </el-form-item>
</el-col> </el-col>
</el-row> </el-row>
<el-form-item>
<el-button type="primary" @click="$emit('playAnimation')">{{$t('stylegen.playAnimation')}}</el-button>
</el-form-item>
</el-card> </el-card>
</el-form> </el-form>
</div> </div>

View File

@ -290,9 +290,6 @@
</el-form-item> </el-form-item>
</el-col> </el-col>
</el-row> </el-row>
<el-form-item>
<el-button type="primary" @click="$emit('playAnimation')">{{$t('stylegen.playAnimation')}}</el-button>
</el-form-item>
</el-card> </el-card>
</el-form> </el-form>
</div> </div>

View File

@ -3,10 +3,10 @@
<el-col :sm="24" :md="16"> <el-col :sm="24" :md="16">
<el-tabs v-model="activeTab"> <el-tabs v-model="activeTab">
<el-tab-pane :label="$t('stylegen.legacy')" name="legacy"> <el-tab-pane :label="$t('stylegen.legacy')" name="legacy">
<legacy ref="legacy" v-model="subComponentResults.legacy" @playAnimation="playAnimation"></legacy> <legacy ref="legacy" v-model="subComponentResults.legacy"></legacy>
</el-tab-pane> </el-tab-pane>
<el-tab-pane :label="$t('stylegen.lineLike')" name="lineLike"> <el-tab-pane :label="$t('stylegen.lineLike')" name="lineLike">
<line-like ref="lineLike" v-model="subComponentResults.lineLike" @playAnimation="playAnimation"></line-like> <line-like ref="lineLike" v-model="subComponentResults.lineLike"></line-like>
</el-tab-pane> </el-tab-pane>
</el-tabs> </el-tabs>
@ -26,12 +26,17 @@
<el-col :sm="24" :md="8"> <el-col :sm="24" :md="8">
<div :style="{position: 'relative', top: `${exampleTop}px`}"> <div :style="{position: 'relative', top: `${exampleTop}px`}">
<p> <el-form inline style="height: 40px">
<el-form-item :label="$t('stylegen.playAnimation')">
<el-switch v-model="playAnimation" @change="onPlayAnimationChange"></el-switch>
</el-form-item>
<el-form-item :label="$t('stylegen.backgrounds')" style="margin-left: 20px">
<el-switch v-model="exampleBgLight" :active-text="$t('stylegen.light')" :inactive-text="$t('stylegen.dark')"></el-switch> <el-switch v-model="exampleBgLight" :active-text="$t('stylegen.light')" :inactive-text="$t('stylegen.dark')"></el-switch>
</p> </el-form-item>
</el-form>
<div id="example-container" :class="{light: exampleBgLight}"> <div id="example-container" :class="{light: exampleBgLight}">
<div id="fakebody"> <div id="fakebody">
<chat-renderer ref="renderer" :css="exampleCss"></chat-renderer> <room ref="room"></room>
</div> </div>
</div> </div>
</div> </div>
@ -44,103 +49,16 @@ import _ from 'lodash'
import Legacy from './Legacy' import Legacy from './Legacy'
import LineLike from './LineLike' import LineLike from './LineLike'
import ChatRenderer from '@/components/ChatRenderer' import Room from '@/views/Room'
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: '言いたいことがあるんだよ!'
}
]
export default { export default {
name: 'StyleGenerator', name: 'StyleGenerator',
components: { components: {
Legacy, LineLike, ChatRenderer Legacy, LineLike, Room
}, },
data() { data() {
let styleElement = document.createElement('style')
document.head.appendChild(styleElement)
// //
// --\ // --\
// -> subComponentResults -> subComponentResult -> inputResult -> 0.5s -> debounceResult -> exampleCss // -> subComponentResults -> subComponentResult -> inputResult -> 0.5s -> debounceResult -> exampleCss
@ -156,7 +74,9 @@ export default {
// //
debounceResult: '', debounceResult: '',
styleElement,
exampleTop: 0, exampleTop: 0,
playAnimation: true,
exampleBgLight: false exampleBgLight: false
} }
}, },
@ -176,17 +96,20 @@ export default {
}, },
inputResult: _.debounce(function(val) { inputResult: _.debounce(function(val) {
this.debounceResult = val this.debounceResult = val
}, 500) }, 500),
exampleCss(val) {
this.styleElement.innerText = val
}
}, },
mounted() { mounted() {
this.debounceResult = this.inputResult = this.subComponentResult this.debounceResult = this.inputResult = this.subComponentResult
this.$refs.renderer.addMessages(EXAMPLE_MESSAGES)
this.$parent.$el.addEventListener('scroll', this.onParentScroll) this.$parent.$el.addEventListener('scroll', this.onParentScroll)
}, },
beforeDestroy() { beforeDestroy() {
this.$parent.$el.removeEventListener('scroll', this.onParentScroll) this.$parent.$el.removeEventListener('scroll', this.onParentScroll)
document.head.removeChild(this.styleElement)
}, },
methods: { methods: {
onParentScroll(event) { onParentScroll(event) {
@ -196,10 +119,12 @@ export default {
this.exampleTop = event.target.scrollTop this.exampleTop = event.target.scrollTop
} }
}, },
async playAnimation() { onPlayAnimationChange(value) {
this.$refs.renderer.clearMessages() if (value) {
await this.$nextTick() this.$refs.room.start()
this.$refs.renderer.addMessages(EXAMPLE_MESSAGES) } else {
this.$refs.room.stop()
}
}, },
copyResult() { copyResult() {
this.$refs.result.select() this.$refs.result.select()