2019-05-21 19:15:12 +08:00
|
|
|
<template>
|
2019-06-11 18:52:00 +08:00
|
|
|
<el-form :model="form" ref="form" label-width="150px" :rules="{
|
2019-06-11 12:51:25 +08:00
|
|
|
roomId: [
|
2019-07-08 11:42:35 +08:00
|
|
|
{required: true, message: $t('home.roomIdEmpty'), trigger: 'blur'},
|
|
|
|
{type: 'integer', min: 1, message: $t('home.roomIdInteger'), trigger: 'blur'}
|
2019-06-11 12:51:25 +08:00
|
|
|
]
|
|
|
|
}">
|
2019-06-11 18:52:00 +08:00
|
|
|
<el-tabs>
|
2019-07-08 11:42:35 +08:00
|
|
|
<el-tab-pane :label="$t('home.general')">
|
|
|
|
<el-form-item :label="$t('home.roomId')" required prop="roomId">
|
2019-06-11 18:52:00 +08:00
|
|
|
<el-input v-model.number="form.roomId" type="number" min="1"></el-input>
|
|
|
|
</el-form-item>
|
2019-07-08 11:42:35 +08:00
|
|
|
<el-form-item :label="$t('home.showDanmaku')">
|
2019-06-20 23:53:34 +08:00
|
|
|
<el-switch v-model="form.showDanmaku"></el-switch>
|
|
|
|
</el-form-item>
|
2019-07-08 11:42:35 +08:00
|
|
|
<el-form-item :label="$t('home.showGift')">
|
2019-06-20 23:53:34 +08:00
|
|
|
<el-switch v-model="form.showGift"></el-switch>
|
2019-06-11 18:52:00 +08:00
|
|
|
</el-form-item>
|
2019-07-08 11:42:35 +08:00
|
|
|
<el-form-item :label="$t('home.mergeSimilarDanmaku')">
|
2019-06-11 18:52:00 +08:00
|
|
|
<el-switch v-model="form.mergeSimilarDanmaku"></el-switch>
|
|
|
|
</el-form-item>
|
2019-07-08 11:42:35 +08:00
|
|
|
<el-form-item :label="$t('home.minGiftPrice')">
|
2019-06-20 23:53:34 +08:00
|
|
|
<el-input v-model.number="form.minGiftPrice" type="number" min="0"></el-input>
|
|
|
|
</el-form-item>
|
2019-09-16 22:15:32 +08:00
|
|
|
<el-form-item :label="$t('home.maxNumber')">
|
|
|
|
<el-input v-model.number="form.maxNumber" type="number" min="1"></el-input>
|
|
|
|
</el-form-item>
|
2019-06-11 18:52:00 +08:00
|
|
|
</el-tab-pane>
|
2019-06-16 23:04:30 +08:00
|
|
|
|
2019-07-08 11:42:35 +08:00
|
|
|
<el-tab-pane :label="$t('home.block')">
|
|
|
|
<el-form-item :label="$t('home.giftDanmaku')">
|
2019-06-11 18:52:00 +08:00
|
|
|
<el-switch v-model="form.blockGiftDanmaku"></el-switch>
|
|
|
|
</el-form-item>
|
2019-07-08 11:42:35 +08:00
|
|
|
<el-form-item :label="$t('home.blockLevel')">
|
2019-06-11 18:52:00 +08:00
|
|
|
<el-slider v-model="form.blockLevel" show-input :min="0" :max="60"></el-slider>
|
|
|
|
</el-form-item>
|
2019-07-08 11:42:35 +08:00
|
|
|
<el-form-item :label="$t('home.informalUser')">
|
2019-06-11 18:52:00 +08:00
|
|
|
<el-switch v-model="form.blockNewbie"></el-switch>
|
|
|
|
</el-form-item>
|
2019-07-08 11:42:35 +08:00
|
|
|
<el-form-item :label="$t('home.unverifiedUser')">
|
2019-06-11 18:52:00 +08:00
|
|
|
<el-switch v-model="form.blockNotMobileVerified"></el-switch>
|
|
|
|
</el-form-item>
|
2019-07-08 11:42:35 +08:00
|
|
|
<el-form-item :label="$t('home.blockKeywords')">
|
|
|
|
<el-input v-model="form.blockKeywords" type="textarea" :rows="5" :placeholder="$t('home.onePerLine')"></el-input>
|
2019-06-11 18:52:00 +08:00
|
|
|
</el-form-item>
|
2019-07-08 11:42:35 +08:00
|
|
|
<el-form-item :label="$t('home.blockUsers')">
|
|
|
|
<el-input v-model="form.blockUsers" type="textarea" :rows="5" :placeholder="$t('home.onePerLine')"></el-input>
|
2019-06-11 18:52:00 +08:00
|
|
|
</el-form-item>
|
2019-07-08 11:42:35 +08:00
|
|
|
<el-form-item :label="$t('home.blockMedalLevel')">
|
2019-06-21 17:38:22 +08:00
|
|
|
<el-slider v-model="form.blockMedalLevel" show-input :min="0" :max="20"></el-slider>
|
|
|
|
</el-form-item>
|
2019-06-11 18:52:00 +08:00
|
|
|
</el-tab-pane>
|
2019-06-16 23:04:30 +08:00
|
|
|
|
2019-07-08 11:42:35 +08:00
|
|
|
<el-tab-pane :label="$t('home.style')">
|
2019-06-20 23:53:34 +08:00
|
|
|
<el-form-item label="CSS">
|
2019-06-11 18:52:00 +08:00
|
|
|
<el-input v-model="form.css" type="textarea" :rows="20"></el-input>
|
|
|
|
</el-form-item>
|
|
|
|
</el-tab-pane>
|
|
|
|
</el-tabs>
|
2019-06-16 23:04:30 +08:00
|
|
|
|
2019-06-12 13:55:49 +08:00
|
|
|
<el-divider></el-divider>
|
2019-07-08 11:42:35 +08:00
|
|
|
<el-form-item :label="$t('home.roomUrl')" v-show="roomUrl">
|
2019-06-12 13:55:49 +08:00
|
|
|
<el-input ref="roomUrlInput" readonly :value="roomUrl" style="width: calc(100% - 6em); margin-right: 1em;"></el-input>
|
2019-07-08 11:42:35 +08:00
|
|
|
<el-button type="primary" @click="copyUrl">{{$t('home.copy')}}</el-button>
|
2019-06-12 13:55:49 +08:00
|
|
|
</el-form-item>
|
2019-06-11 12:51:25 +08:00
|
|
|
<el-form-item>
|
2019-07-08 11:42:35 +08:00
|
|
|
<el-button type="primary" @click="saveConfig">{{$t('home.saveConfig')}}</el-button>
|
|
|
|
<el-button type="primary" :disabled="!roomUrl" @click="enterRoom">{{$t('home.enterRoom')}}</el-button>
|
|
|
|
<el-button type="primary" @click="exportConfig">{{$t('home.exportConfig')}}</el-button>
|
|
|
|
<el-button type="primary" @click="importConfig">{{$t('home.importConfig')}}</el-button>
|
2019-06-11 12:51:25 +08:00
|
|
|
</el-form-item>
|
|
|
|
</el-form>
|
2019-05-21 19:15:12 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2019-07-04 18:56:27 +08:00
|
|
|
import download from 'downloadjs'
|
|
|
|
|
|
|
|
import {mergeConfig} from '@/utils'
|
2019-06-12 13:55:49 +08:00
|
|
|
import config from '@/api/config'
|
|
|
|
|
2019-05-21 19:15:12 +08:00
|
|
|
export default {
|
|
|
|
name: 'Home',
|
|
|
|
data() {
|
|
|
|
return {
|
2019-06-10 18:38:21 +08:00
|
|
|
form: {
|
2019-06-11 18:52:00 +08:00
|
|
|
roomId: parseInt(window.localStorage.roomId || '1'),
|
2019-06-12 13:55:49 +08:00
|
|
|
...config.getLocalConfig()
|
|
|
|
},
|
|
|
|
roomUrl: ''
|
2019-05-21 19:15:12 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2019-06-12 13:55:49 +08:00
|
|
|
saveConfig() {
|
|
|
|
this.$refs.form.validate(async valid => {
|
2019-06-10 18:38:21 +08:00
|
|
|
if (!valid) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
window.localStorage.roomId = this.form.roomId
|
2019-06-12 13:55:49 +08:00
|
|
|
config.setLocalConfig(this.form)
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (window.localStorage.configId) {
|
|
|
|
try {
|
|
|
|
await config.setRemoteConfig(window.localStorage.configId, this.form)
|
|
|
|
} catch (e) { // 404
|
|
|
|
window.localStorage.configId = (await config.createRemoteConfig(this.form)).id
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
window.localStorage.configId = (await config.createRemoteConfig(this.form)).id
|
|
|
|
}
|
|
|
|
} catch (e) {
|
2019-07-08 11:42:35 +08:00
|
|
|
this.$message.error(this.$t('home.failedToSave') + e)
|
2019-06-12 13:55:49 +08:00
|
|
|
return
|
|
|
|
}
|
2019-07-08 11:42:35 +08:00
|
|
|
this.$message({message: this.$t('home.successfullySaved'), type: 'success'})
|
2019-06-12 13:55:49 +08:00
|
|
|
|
|
|
|
let resolved = this.$router.resolve({name: 'room', params: {roomId: this.form.roomId},
|
|
|
|
query: {config_id: window.localStorage.configId}})
|
|
|
|
this.roomUrl = `http://${window.location.host}${resolved.href}`
|
2019-06-11 18:52:00 +08:00
|
|
|
})
|
|
|
|
},
|
|
|
|
enterRoom() {
|
2019-06-12 13:55:49 +08:00
|
|
|
window.open(this.roomUrl, `room ${this.form.roomId}`, 'menubar=0,location=0,scrollbars=0,toolbar=0,width=600,height=600')
|
2019-06-11 18:52:00 +08:00
|
|
|
},
|
2019-06-12 13:55:49 +08:00
|
|
|
copyUrl() {
|
|
|
|
this.$refs.roomUrlInput.select()
|
|
|
|
document.execCommand('Copy')
|
2019-07-04 18:56:27 +08:00
|
|
|
},
|
|
|
|
exportConfig() {
|
|
|
|
let cfg = mergeConfig(this.form, config.DEFAULT_CONFIG)
|
|
|
|
download(JSON.stringify(cfg, null, 2), 'blivechat.json', 'application/json')
|
|
|
|
},
|
|
|
|
importConfig() {
|
|
|
|
let input = document.createElement('input')
|
|
|
|
input.type = 'file'
|
|
|
|
input.accept = 'application/json'
|
|
|
|
input.onchange = () => {
|
|
|
|
let reader = new window.FileReader()
|
|
|
|
reader.onload = () => {
|
|
|
|
let cfg
|
|
|
|
try {
|
|
|
|
cfg = JSON.parse(reader.result)
|
|
|
|
} catch (e) {
|
2019-07-08 11:42:35 +08:00
|
|
|
this.$message.error(this.$t('home.failedToParseConfig') + e)
|
2019-07-04 18:56:27 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
cfg = mergeConfig(cfg, config.DEFAULT_CONFIG)
|
|
|
|
this.form = {roomId: this.form.roomId, ...cfg}
|
|
|
|
}
|
|
|
|
reader.readAsText(input.files[0])
|
|
|
|
}
|
|
|
|
input.click()
|
2019-05-21 19:15:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
2019-06-11 18:52:00 +08:00
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
.el-form {
|
|
|
|
max-width: 800px;
|
|
|
|
}
|
|
|
|
</style>
|