<template>
  <div class="authorization">
    <el-input v-model="license" type="textarea" rows="5" placeholder="请输入授权码" style="width: 300px; margin-bottom: 30px;" />
    <el-button @click="verifyLicense">授权确认</el-button>
  </div>
</template>

<script>
import { postLicenseValidate, postLicenseLocal } from '@/api/pushMessage';
export default {
    name: 'Authorization',
    data() {
        return {
            license: ''
        };
    },
    methods: {
        async verifyLicense() {
            try {
                const params = {
                    secretKey: 'joylink',
                    license: this.license
                };
                const res = await postLicenseValidate(params);
                if (res.code == 200 && res.data) {
                    const resLocal = await postLicenseLocal(params);
                    if (resLocal.code == 200) {
                        this.$router.push({ path: `/login` });
                    } else {
                        this.$messageBox('license无效！');
                    }
                } else {
                    this.$messageBox('license无效！');
                }
            } catch (error) {
                console.log(error);
            }
        }
    }
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.authorization{
	width: 100%;
	position: absolute;
	top: 30%;
	display: flex;
	align-items: center;
	flex-direction: column;
	justify-content: center;
}
</style>
