<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<head>
  <meta charset="UTF-8">
  <title>授权中心</title>
  <script type="text/javascript" src="themes/js/vue.min.js"></script>
  <script type="text/javascript" src="themes/js/index.js"></script>
  <script type="text/javascript" src="themes/js/axios.min.js"></script>
  <script type="text/javascript" src="themes/js/jquery.js"></script>
  <script type="text/javascript" src="themes/js/moment.js"></script>
  <link rel="stylesheet" href="themes/css/index.css" type="text/css">
  <link rel="stylesheet" href="themes/css/main.css" type="text/css">
</head>
<body>
<div id="app">
  <div class="header">
    <div class="logo">
      <div class="logo-image"></div>
    </div>
  </div>
  <div class="no-license">
    <el-card class="box-card" shadow="never" style="width:640px;margin: 10px auto 0px auto;">
      <div slot="header" class="clearfix">
        <span>本机授权码</span>
        <el-button style="float: right; padding: 3px 0;" icon="el-icon-document-copy" @click="copy()" type="text">复制授权码</el-button>
      </div>
      <span class="tip">请联系您的商务经理或客服经理，并将下方框体内的本机授权码发送给Ta，以获取授权文件</span>
      <div class="demo-input-suffix">
        <el-input type="textarea" ref="copy" autosize="true" v-model="code" resize="none" readonly="true"></el-input>
      </div>
    </el-card>
    <el-card class="box-card" shadow="never" style="width:640px;margin: 10px auto 0px auto;">
      <div slot="header">
        <span>上传授权文件</span>
      </div>
      <span class="tip"></span>
      <div align="center">
        <el-upload class="upload-demo" accept enctype="multipart/form-data" drag action="/xinadmin/upload" multiple="false" show-file-list="false"
                   drag="true" auto-upload="true" limit="1" :on-success="Success">
          <i class="el-icon-upload" style="height: 10px;"></i>
          <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
          <div class="el-upload__tip" slot="tip">请将您获得的授权文件(LICENSE)传入系统进行校验</div>
        </el-upload>
      </div>
    </el-card>
  </div>
</div>
<script>
  Vue.filter("dateFilter", function (date, formatPattern) {
    return moment(date).format(formatPattern || "YYYY-MM-DD HH:mm:ss");
  });
  new Vue({
    el: '#app',
    beforeCreate:function(){
      const that = this;
      axios.get('/xinadmin/code', {}).then(function (res) {
        if (res.data) {
          if(res.data.license){
            location.href = "login.jsp"
          }else{
            that.code = res.data.code
          }

        }
      }).catch(function (error) {
        console.log(error)
      })
    },
    data() {
      return {
        code: "",
      }
    },
    //绑定方法
    methods: {
      copy() {
        this.$refs.copy.select()
        document.execCommand('Copy')
        this.$message.success('已复制到剪贴板')
      },
      uploadfile(){
        this.$refs.upload.submit()
      },
      Success(response, file, fileList) {
        if(response.state == "success"){
          this.dialogTableVisible = false;
          this.$notify({
            title: '成功',
            duration:2000,
            message: '上传成功',
            type: 'success'
          });
          const that = this;
          axios.get('/xinadmin/adminstarter', {}).then(function (res) {
            that.$notify({
              title: '重启中',
              duration:2000,
              message: '正在重启相关应用，请稍侯....',
              type: 'info'
            });
            setTimeout(() => {
              location.reload();
            }, 2000);

          }).catch(function (error) {
            console.log(error)
          })
        }else{
          this.$notify.error({
            title: '上传失败',
            message: response.error
          });
        }
      }

    }
  })
</script>
</body>
