You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
bililive_webapp/src/components/TelegramBot.vue

85 lines
2.3 KiB

<!--telegram bot-->
<template>
<el-row type="flex" justify="center">
<el-col :span="12">
<el-input v-model="newBotToken">
<template v-slot:prepend>机器人Api Token</template>
</el-input>
</el-col>
</el-row>
<el-row type="flex" justify="center" class="mt-1">
<el-col :span="2">
<el-button type="primary" class="btn-block" @click="openBot" v-loading.fullscreen.lock="fullscreenLoading">
测试token
</el-button>
</el-col>
</el-row>
<template v-if="botName!==''">
<el-row type="flex" justify="center" class="mt-1">
<el-col :span="12">
<el-input v-model="botName" :disabled="true">
<template v-slot:prepend>即将绑定的机器人</template>
</el-input>
</el-col>
</el-row>
<el-row type="flex" justify="center" class="mt-1">
<el-col :span="2">
<el-button type="primary" class="btn-block" @click="bindBot">绑定</el-button>
</el-col>
</el-row>
</template>
</template>
<script lang="ts">
import {defineComponent, ref} from "vue";
import {updateRoute} from "../router";
import {bindTelegramBot, JSONResponse, message, testTelegramBot} from "../request";
import {useRouter} from "vue-router";
//@ts-ignore
import crumbs from 'crumbsjs';
import {email_cookie_key} from "../global";
export default defineComponent({
name: "TelegramBot",
setup() {
updateRoute()
const fullscreenLoading = ref<boolean>(false)
const newBotToken = ref<string>('')
const botName = ref<string>('')
const openBot = () => {
fullscreenLoading.value = true
testTelegramBot(newBotToken.value)
.then(res => res.json()).then((res: JSONResponse) => {
fullscreenLoading.value = false
if (res.ok) {
botName.value = res.result.username
} else {
message({result: 'FAIL', message: '无法获取机器人信息,请确认token输入正确'})
}
})
}
const router = useRouter()
const bindBot = () => bindTelegramBot(crumbs.get(email_cookie_key), newBotToken.value)
.then(res => res.json())
.then(res => {
message(res)
if (res.result === 'OK') {
router.replace('/config')
}
})
return {newBotToken, openBot, botName, fullscreenLoading, bindBot}
}
})
</script>
<style scoped>
</style>