<!-- 登录页面 -->

<template>
  <div class="page page-login flex flex-v">
    <div class="form-wrap flex flex-1">
      <el-form @submit.prevent='onSubmit' ref="form" :model="form" label-width="80px" size="small">
        <h1>政务学习平台</h1>
        <el-form-item label="用户名">
          <el-input v-model="form.loginName"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="form.password" type='password'></el-input>
        </el-form-item>
        <el-form-item size="large">
          <el-button type="primary" native-type='submit' :loading='loading' @click='onSubmit'>登录</el-button>
        </el-form-item>
      </el-form>
    </div>

    <div class="footer">
      登陆 &copy; <a href="">信宏翔网络科技有限公司</a> 出品
    </div>

    <!-- <Map ref="map1" :markersData="originData" @choose="getDetailData" /> -->

    <!-- <el-card :body-style="{ padding: '5px' }" style="width: 300px">
      <el-row type="flex" class="row-bg" justify="space-around">
        <span style="font-size: 18px"><b>高新区政务服务中心</b></span>

        <el-button type="text" size="mini" class="button">查看详情</el-button>
      </el-row>
      <el-divider></el-divider>
      <el-row type="flex" justify="space-around">
        <el-col :span="4">
          <span style="font-size: 13px"><b>100</b></span
          ><br />
          <span style="font-size: 12px">设备总数</span>
        </el-col>
        <el-col :span="4">
          <span style="font-size: 13px"><b>100</b></span
          ><br />
          <span style="font-size: 12px">在线</span>
        </el-col>
        <el-col :span="4">
          <span style="font-size: 13px"><b>100</b></span
          ><br />
          <span style="font-size: 12px">离线</span>
        </el-col>
        <el-col :span="4">
          <span style="font-size: 13px"><b>100</b></span
          ><br />
          <span style="font-size: 12px">停用</span>
        </el-col>
        <el-col :span="4">
          <span style="font-size: 13px"><b>100</b></span
          ><br />
          <span style="font-size: 12px">待激活</span>
        </el-col>
      </el-row>
      <el-divider></el-divider>
      <el-descriptions :column="1" size="small">
        <el-descriptions-item label="站点编码"
          >kooriookami</el-descriptions-item
        >
        <el-descriptions-item label="站点地址"
          >18100000000</el-descriptions-item
        >
        <el-descriptions-item
          label="联系人"
          :labelStyle="{ 'text-align': 'right', width: '50px' }"
          >苏州市</el-descriptions-item
        >
        <el-descriptions-item label="联系电话">
          <el-tag size="small">学校</el-tag>
        </el-descriptions-item>
        <el-descriptions-item label="创建时间"
          >江苏省苏州市吴中区吴中大道 1188 号</el-descriptions-item
        >
      </el-descriptions>
    </el-card> -->
  </div>
</template>

<script>
import { createSocket } from "@/assets/utils/websocket";

export default {
  name: "login",
  created() {
    // let obj = {};
    // obj.lng = 104.21;
    // obj.lat = 30.56;
    // obj.address = "测试站点";
    // obj.siteId = 2;

    // this.originData.push(obj);
    // this.$nextTick(() => {
    //   this.$refs.map1.refresh(this.originData);
    // });

    // window.location.href=process.env.VUE_APP_PORTAL_URL=='undefined'?'http://192.168.0.98:11072':process.env.VUE_APP_PORTAL_URL
  },
  methods: {
    login() {
      this.loading = true;
      this.$post("/login/login", this.form)
        .then(this.loginSuccess)
        .catch(this.loginFail);
    },
    loginSuccess({ data }) {
      console.log("userData", data);
      console.log("redirect",this.redirect)
      this.$store.commit("setUserData", data);
      this.$router.replace({
        path: this.redirect,
      });

      //成功 创建websocket连接 process.env.VUE_WEBSOCKET_BASE_API +
      console.log("process", process.env);
      // createSocket("ws://"+process.env.VUE_APP_BASE_API +"/ws?accessToken="+data.id)
    },
    loginFail(error) {
      this.loading = false;
      //this.refreshCode();
      this.$message.error(error.message);
    },
    // refreshCode() {
    //   this.form.securityCode = '';
    //   this.securityCodeUrl = securityCodeUrl + Math.random();
    // },
    onSubmit(e) {
      e.preventDefault();

      if (!this.form.loginName.length) {
        return this.$message.warning("请输入用户名");
      }
      if (!this.form.password.length) {
        return this.$message.warning("请输入密码");
      }

      this.login();
    },
  },
  data() {
    return {
      originData: [],
      loading: false,
      redirect: this.$route.query.redirect || "/",
      form: {
        loginName: "",
        password: "",
      },
    };
  },
};
</script>

<style lang="less">
.el-divider--horizontal {
  margin: 5px 0;
  background: 0 0;
  border-top: 2px solid #e8eaec;
}
.page-login {
  background-image: linear-gradient(45deg, #333, #111);
  background-size: 40px 40px;
  margin: 0;
  height: 100%;
  .el-form {
    margin: auto;
    width: 400px;
    padding: 25px 25px 0 0;
    background: #fff;
    h1 {
      text-align: center;
      font-size: 20px;
      font-weight: 500;
      margin-bottom: 20px;
    }
    button {
      margin-top: 10px;
      width: 240px;
    }
    .el-input-group__append {
      padding: 0;
      font-size: 0;
    }
  }
  .footer {
    height: 80px;
    font-size: 12px;
    color: #999;
    text-align: center;
    line-height: 80px;
    a {
      color: #999;
    }
  }
}
</style>

