Whalebird-desktop-client-ma.../src/renderer/components/Authorize.vue

150 lines
3.3 KiB
Vue
Raw Normal View History

2018-03-08 09:41:39 +01:00
<template>
<div id="authorize">
<div>
<el-header>
<el-row>
<el-col :span="24" class="close">
2022-04-19 14:05:32 +02:00
<el-button type="text" @click="close" class="close-button">
<font-awesome-icon icon="x-mark"></font-awesome-icon>
2022-04-18 15:41:52 +02:00
</el-button>
</el-col>
</el-row>
</el-header>
<el-main>
<div class="authorization-url">
<p>{{ $t('authorize.manually_1') }}</p>
<p>{{ $t('authorize.manually_2') }}</p>
<p class="url">{{ $route.query.url }}</p>
</div>
<el-form
ref="form"
:model="authorizeForm"
label-width="120px"
label-position="top"
class="authorize-form"
v-on:submit.prevent="authorizeSubmit"
>
<p v-if="sns === 'misskey'">{{ $t('authorize.misskey_label') }}</p>
<el-form-item :label="$t('authorize.code_label')" v-else>
<el-input v-model="authorizeForm.code"></el-input>
</el-form-item>
<!-- Dummy form to guard submitting with enter -->
<el-form-item class="hidden">
<el-input></el-input>
</el-form-item>
<el-form-item class="submit">
2022-04-19 14:05:32 +02:00
<el-button type="primary" @click="authorizeSubmit" v-loading="submitting" element-loading-background="rgba(0, 0, 0, 0.8)">
{{ $t('authorize.submit') }}
</el-button>
</el-form-item>
</el-form>
</el-main>
</div>
</div>
2018-03-08 09:41:39 +01:00
</template>
<script>
export default {
2022-04-18 15:41:52 +02:00
data() {
return {
authorizeForm: {
2022-04-19 14:05:32 +02:00
code: null
2022-04-18 15:41:52 +02:00
},
2022-04-19 14:05:32 +02:00
submitting: false
2022-04-18 15:41:52 +02:00
}
},
2018-03-08 09:41:39 +01:00
name: 'authorize',
props: {
url: {
type: String,
2022-04-19 14:05:32 +02:00
default: ''
},
sns: {
type: String,
2022-04-19 14:05:32 +02:00
default: 'mastodon'
}
2018-03-08 09:41:39 +01:00
},
mounted() {
console.log(this.url)
},
2018-03-08 09:41:39 +01:00
methods: {
authorizeSubmit() {
this.submitting = true
this.$store
.dispatch('Authorize/submit', {
code: this.authorizeForm.code,
2022-04-19 14:05:32 +02:00
sns: this.sns
})
.finally(() => {
this.submitting = false
})
2022-04-19 14:05:32 +02:00
.then(id => {
this.$router.push({ path: `/${id}/home` })
})
2022-04-19 14:05:32 +02:00
.catch(err => {
if (err.name === 'DuplicateRecordError') {
this.$message({
2018-08-13 08:27:53 +02:00
message: this.$t('message.authorize_duplicate_error'),
2022-04-19 14:05:32 +02:00
type: 'error'
})
} else {
this.$message({
2018-08-13 08:27:53 +02:00
message: this.$t('message.authorize_error'),
2022-04-19 14:05:32 +02:00
type: 'error'
})
}
2018-03-13 14:25:31 +01:00
})
},
close() {
return this.$router.push({ path: '/', query: { redirect: 'home' } })
2022-04-19 14:05:32 +02:00
}
}
2018-03-08 09:41:39 +01:00
}
</script>
<style lang="scss" scoped>
#authorize /deep/ {
2018-03-10 15:11:27 +01:00
background-color: #292f3f;
color: #ffffff;
2018-03-08 09:41:39 +01:00
text-align: center;
min-height: 100%;
2018-03-10 15:11:27 +01:00
.close {
text-align: right;
.close-button {
font-size: 24px;
}
}
.authorization-url {
margin: 0 auto 64px;
max-width: 80%;
.url {
color: #909399;
word-wrap: break-word;
}
}
2018-03-10 15:11:27 +01:00
.authorize-form {
width: 500px;
margin: 0 auto;
}
.el-form-item__label {
color: #f0f3f9;
}
.el-input__inner {
background-color: #373d48;
color: #ffffff;
border: 0;
}
.hidden {
display: none;
}
2018-03-08 09:41:39 +01:00
}
</style>