mirror of
https://github.com/xfgryujk/blivechat.git
synced 2025-02-06 01:30:21 +08:00
添加前端获取后端配置
This commit is contained in:
parent
34f0effb6a
commit
d5b885aab4
17
api/main.py
17
api/main.py
@ -2,9 +2,24 @@
|
|||||||
|
|
||||||
import tornado.web
|
import tornado.web
|
||||||
|
|
||||||
|
import api.base
|
||||||
|
import config
|
||||||
|
import update
|
||||||
|
|
||||||
|
|
||||||
# noinspection PyAbstractClass
|
|
||||||
class MainHandler(tornado.web.StaticFileHandler):
|
class MainHandler(tornado.web.StaticFileHandler):
|
||||||
"""为了使用Vue Router的history模式,把所有请求转发到index.html"""
|
"""为了使用Vue Router的history模式,把所有请求转发到index.html"""
|
||||||
async def get(self, *args, **kwargs):
|
async def get(self, *args, **kwargs):
|
||||||
await super().get('index.html', *args, **kwargs)
|
await super().get('index.html', *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
# noinspection PyAbstractClass
|
||||||
|
class ServerInfoHandler(api.base.ApiHandler):
|
||||||
|
async def get(self):
|
||||||
|
cfg = config.get_config()
|
||||||
|
self.write({
|
||||||
|
'version': update.VERSION,
|
||||||
|
'config': {
|
||||||
|
'enableTranslate': cfg.enable_translate
|
||||||
|
}
|
||||||
|
})
|
||||||
|
@ -53,7 +53,7 @@
|
|||||||
|
|
||||||
<el-tab-pane :label="$t('home.advanced')">
|
<el-tab-pane :label="$t('home.advanced')">
|
||||||
<el-form-item :label="$t('home.autoTranslate')">
|
<el-form-item :label="$t('home.autoTranslate')">
|
||||||
<el-switch v-model="form.autoTranslate"></el-switch>
|
<el-switch v-model="form.autoTranslate" :disabled="!serverConfig.enableTranslate"></el-switch>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-tab-pane>
|
</el-tab-pane>
|
||||||
</el-tabs>
|
</el-tabs>
|
||||||
@ -73,6 +73,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
|
import axios from 'axios'
|
||||||
import download from 'downloadjs'
|
import download from 'downloadjs'
|
||||||
|
|
||||||
import {mergeConfig} from '@/utils'
|
import {mergeConfig} from '@/utils'
|
||||||
@ -82,6 +83,9 @@ export default {
|
|||||||
name: 'Home',
|
name: 'Home',
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
serverConfig: {
|
||||||
|
enableTranslate: true
|
||||||
|
},
|
||||||
form: {
|
form: {
|
||||||
roomId: parseInt(window.localStorage.roomId || '1'),
|
roomId: parseInt(window.localStorage.roomId || '1'),
|
||||||
...config.getLocalConfig()
|
...config.getLocalConfig()
|
||||||
@ -105,7 +109,17 @@ export default {
|
|||||||
config.setLocalConfig(this.form)
|
config.setLocalConfig(this.form)
|
||||||
}, 500)
|
}, 500)
|
||||||
},
|
},
|
||||||
|
mounted() {
|
||||||
|
this.updateServerConfig()
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
async updateServerConfig() {
|
||||||
|
try {
|
||||||
|
this.serverConfig = (await axios.get(`/server_info`)).data.config
|
||||||
|
} catch (e) {
|
||||||
|
this.$message.error('Failed to fetch server information: ' + e)
|
||||||
|
}
|
||||||
|
},
|
||||||
enterRoom() {
|
enterRoom() {
|
||||||
window.open(this.roomUrl, `room ${this.form.roomId}`, 'menubar=0,location=0,scrollbars=0,toolbar=0,width=600,height=600')
|
window.open(this.roomUrl, `room ${this.form.roomId}`, 'menubar=0,location=0,scrollbars=0,toolbar=0,width=600,height=600')
|
||||||
},
|
},
|
||||||
|
1
main.py
1
main.py
@ -21,6 +21,7 @@ logger = logging.getLogger(__name__)
|
|||||||
WEB_ROOT = os.path.join(os.path.dirname(__file__), 'frontend', 'dist')
|
WEB_ROOT = os.path.join(os.path.dirname(__file__), 'frontend', 'dist')
|
||||||
|
|
||||||
routes = [
|
routes = [
|
||||||
|
(r'/server_info', api.main.ServerInfoHandler),
|
||||||
(r'/chat', api.chat.ChatHandler),
|
(r'/chat', api.chat.ChatHandler),
|
||||||
|
|
||||||
(r'/((css|fonts|img|js|static)/.*)', tornado.web.StaticFileHandler, {'path': WEB_ROOT}),
|
(r'/((css|fonts|img|js|static)/.*)', tornado.web.StaticFileHandler, {'path': WEB_ROOT}),
|
||||||
|
Loading…
Reference in New Issue
Block a user