Whalebird-desktop-client-ma.../src/renderer/components/Login/LoginForm.vue

115 lines
2.9 KiB
Vue
Raw Normal View History

2018-03-10 14:44:15 +01:00
<template>
<div id="login_form">
<el-form ref="loginForm" label-width="120px" label-position="top" v-on:submit.prevent="login" class="login-form">
2018-03-10 14:44:15 +01:00
<el-form-item label="Select instance">
<el-radio-group v-model="loginForm.selectInstance" @change="changeInstance" class="instance-group">
<el-radio class="instance-list" v-for="instance in instances" v-bind:key="instance.id" :label="instance.name" border></el-radio>
</el-radio-group>
</el-form-item>
<template v-if="instances.length === 0">
<el-form-item label="Could not find instance, please write host name">
<el-input v-model="loginForm.domainName"></el-input>
</el-form-item>
<el-button type="primary" @click="confirm" v-if="selectedInstance === null">Search</el-button>
</template>
2018-03-10 14:44:15 +01:00
<el-form-item class="submit">
<el-button type="text" class="back" @click="back"><icon name="chevron-left"></icon></el-button>
<el-button type="primary" class="login" @click="login" v-if="selectedInstance !== null">Login</el-button>
</el-form-item>
</el-form>
</div>
</template>
<script>
import { mapState } from 'vuex'
export default {
name: 'login-form',
data () {
return {
loginForm: {
selectInstance: '',
domainName: ''
2018-03-10 14:44:15 +01:00
}
}
},
computed: {
...mapState({
instances: state => state.Login.instances,
selectedInstance: state => state.Login.selectedInstance
})
},
methods: {
login () {
2018-03-10 15:28:55 +01:00
const loading = this.$loading({
lock: true,
text: 'Loading',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.7)'
})
2018-03-10 14:44:15 +01:00
this.$store.dispatch('Login/fetchLogin', this.selectedInstance)
.then((url) => {
2018-03-10 15:28:55 +01:00
loading.close()
2018-03-10 14:44:15 +01:00
this.$router.push({ path: '/authorize' })
})
2018-03-10 15:28:55 +01:00
.catch(() => {
loading.close()
this.$message({
message: 'Could not get authorize url',
type: 'error'
})
})
2018-03-10 14:44:15 +01:00
},
changeInstance (value) {
this.$store.dispatch('Login/changeInstance', value)
},
back () {
this.$store.dispatch('Login/pageBack')
},
confirm () {
this.$store.dispatch('Login/confirmInstance', this.loginForm.domainName)
.then(() => {
this.$message({
message: `${this.loginForm.domainName} is confirmed, please login`,
type: 'success'
})
})
.catch(() => {
this.$message({
message: `${this.loginForm.domainName} does not exist`,
type: 'error'
})
})
2018-03-10 14:44:15 +01:00
}
}
}
</script>
<style lang="scss" scoped>
.login-form {
2018-03-10 14:44:15 +01:00
margin: 0 auto;
width: 300px;
.instance-group {
text-align: left;
margin: 0 auto;
}
2018-03-14 08:12:44 +01:00
.instance-list {
display: block;
margin-left: 0 !important;
border-color: #606266;
color: #dcdfe6;
margin-bottom: 10px;
}
.submit {
margin: 0;
}
.back {
margin-right: 20px;
}
2018-03-10 14:44:15 +01:00
}
</style>