<commit_before><template>
  <div class="login">

    <div class="login_bg">
      <!--<i @click="returnI" class="returnI iconfont gj-back"></i>-->
      <svg @click="returnI" class="returnI icon" aria-hidden="true">
        <use xlink:href="#icon-fanhui"></use>
      </svg>
      <div class="login_con">
        <div class="div_gorund1">
          <img class="login_img" src="../../../static/images/women.jpeg" alt="">
        </div>
        <div class="div_gorund">
          <svg class="icon" aria-hidden="true">
            <use xlink:href="#icon-user-boy"></use>
          </svg>
          <input type="text" v-model="userName" class="username" placeholder="Username">
          <p :style="userNameDis" class="redText">{{userNameText}}</p>
        </div>
        <div class="div_gorund">
          <!--<i class="iconfont gj-daishouhuo"></i>-->
          <svg class="icon" aria-hidden="true">
            <use xlink:href="#icon-pc"></use>
          </svg>
          <input type="password" v-model="passWord" class="password" placeholder="Password">
          <p :style="passWordDis" class="redText">请输入正确的登录密码</p>
        </div>
        <div class="div_gorund">
          <div class="title">
            <span>忘记密码?</span>
            <router-link to="/login/register"><span>注册</span></router-link>
            <router-view></router-view>
          </div>
        </div>
        <div class="div_gorund">
          <button @click="loginBtn" type="button">登 陆</button>
        </div>

        <div class="login_quick">
          <div class="quick_div">
            <svg class="icon" aria-hidden="true">
              <use xlink:href="#icon-qq"></use>
            </svg>
            <span id="qqLoginBtn"></span>

          </div>
          <div class="quick_div">
            <svg class="icon" aria-hidden="true">
              <use xlink:href="#icon-qzone"></use>
            </svg>
          </div>
          <div class="quick_div">
            <svg class="icon" aria-hidden="true">
              <use xlink:href="#icon-wechat"></use>
            </svg>
          </div>
        </div>
      </div>


    </div>

  </div>
</template>

<script>
  import * as _fetch from '../../config/fetch'
  import {mapState, mapGetters, mapActions} from 'vuex'

  export default {
    name: 'login',
    data() {
      return {
        userName: "",

        userNameDis: {
          display: "none"
        },
        userNameText: "请输入您的用户名",

        passWord: "",
        passWordDis: {
          display: "none"
        },
      }
    },
    computed: {
      ...mapState({
        user: state => state.User.user,
      })

    },
    methods: {
      returnI() {
        this.$router.go(-1);
      },
      returnMain() {
        this.$router.push({path: '/'})
      },
      loginBtn() {
        var self = this
        console.log(this.userName)
        console.log(this.passWord)

        if (!this.userName) {
          this.userNameDis.display = "block";
        }
        if (!this.passWord) {
          this.passWordDis.display = "block";
        }

        if (this.userName && this.passWord) {
          $.ajax({
            type: "POST",
            url: "http://localhost:3000/timorsLogin",
            data: {
              username: this.userName,
              password: this.passWord
            },
            success: function (data) {
              switch (data) {
                case "1":
                  self.userNameDis.display = "block";
                  self.userNameText = "请输入正确的用户名"
                  break;
                case "2":
                  console.log("登陆失败")
                  break;
                default :
                  console.log(data)
                  console.log(JSON.stringify(data.data))
                  sessionStorage.setItem('user', JSON.stringify(data.data));
                  self.$store.commit('setUserDate', {
                    userDate: data.data
                  })
                  self.$router.push({path: '/'})
                  break;
              }
            }

          })
        }

      },
    },
    watch: {
      userName(val) {
        if (val)
          this.userNameDis.display = "none";
        else
          this.userNameDis.display = "block";
      },
      passWord(val) {
        if (val)
          this.passWordDis.display = "none";
        else
          this.passWordDis.display = "block";
      },
    },
    mounted() {
      this.$nextTick(() => {

        //qq登录
        QC.Login({
          btnId: "qqLoginBtn",    //插入按钮的节点id
          //用户需要确认的scope授权项，可选，默认all
          scope: "all",
          //按钮尺寸，可用值[A_XL| A_L| A_M| A_S|  B_M| B_S| C_S]，可选，默认B_S
          size: "C_S"
        });

        if (QC.Login.check()) {//如果已登录成功
          console.log("")
          QC.Login.getMe(function (openId, accessToken) {
            console.log(["当前登录用户的", "openId为：" + openId, "accessToken为：" + accessToken].join("\n"));
          });
        }

        QC.api("get_user_info", {})
          .success(function($res){
            console.log($res);

            _fetch.fetch("/registerUser", {
              user_name: $res.data.nickname,
              user_headImg: $res.data.figureurl_2,
              user_gender: $res.data.gender,
            }).then((data) => {
              console.log(data)

              console.log(JSON.stringify(data.data))
              sessionStorage.setItem('user', JSON.stringify(data.data));

              self.$store.commit('setUserDate', {
                userDate: data.data
              })
              self.$router.push({path: '/'})

            }).catch((error) => {
              console.log(error)
            })
          })
          //指定接口访问失败的接收函数，f为失败返回Response对象
          .error(function(f){
            alert("获取用户信息失败！");
          })
          .complete(function(c){
            alert("获取用户信息完成！");
          });

//检查是否登录<commit_msg>no message<commit_after><template>
  <div class="login">

    <div class="login_bg">
      <!--<i @click="returnI" class="returnI iconfont gj-back"></i>-->
      <svg @click="returnI" class="returnI icon" aria-hidden="true">
        <use xlink:href="#icon-fanhui"></use>
      </svg>
      <div class="login_con">
        <div class="div_gorund1">
          <img class="login_img" src="../../../static/images/women.jpeg" alt="">
        </div>
        <div class="div_gorund">
          <svg class="icon" aria-hidden="true">
            <use xlink:href="#icon-user-boy"></use>
          </svg>
          <input type="text" v-model="userName" class="username" placeholder="Username">
          <p :style="userNameDis" class="redText">{{userNameText}}</p>
        </div>
        <div class="div_gorund">
          <!--<i class="iconfont gj-daishouhuo"></i>-->
          <svg class="icon" aria-hidden="true">
            <use xlink:href="#icon-pc"></use>
          </svg>
          <input type="password" v-model="passWord" class="password" placeholder="Password">
          <p :style="passWordDis" class="redText">请输入正确的登录密码</p>
        </div>
        <div class="div_gorund">
          <div class="title">
            <span>忘记密码?</span>
            <router-link to="/login/register"><span>注册</span></router-link>
            <router-view></router-view>
          </div>
        </div>
        <div class="div_gorund">
          <button @click="loginBtn" type="button">登 陆</button>
        </div>

        <div class="login_quick">
          <div class="quick_div">
            <svg class="icon" aria-hidden="true">
              <use xlink:href="#icon-qq"></use>
            </svg>
            <span id="qqLoginBtn"></span>

          </div>
          <div class="quick_div">
            <svg class="icon" aria-hidden="true">
              <use xlink:href="#icon-qzone"></use>
            </svg>
          </div>
          <div class="quick_div">
            <svg class="icon" aria-hidden="true">
              <use xlink:href="#icon-wechat"></use>
            </svg>
          </div>
        </div>
      </div>


    </div>

  </div>
</template>

<script>
  import * as _fetch from '../../config/fetch'
  import {mapState, mapGetters, mapActions} from 'vuex'

  export default {
    name: 'login',
    data() {
      return {
        userName: "",

        userNameDis: {
          display: "none"
        },
        userNameText: "请输入您的用户名",

        passWord: "",
        passWordDis: {
          display: "none"
        },
      }
    },
    computed: {
      ...mapState({
        user: state => state.User.user,
      })

    },
    methods: {
      returnI() {
        this.$router.go(-1);
      },
      returnMain() {
        this.$router.push({path: '/'})
      },
      loginBtn() {
        var self = this
        console.log(this.userName)
        console.log(this.passWord)

        if (!this.userName) {
          this.userNameDis.display = "block";
        }
        if (!this.passWord) {
          this.passWordDis.display = "block";
        }

        if (this.userName && this.passWord) {
          $.ajax({
            type: "POST",
            url: "http://localhost:3000/timorsLogin",
            data: {
              username: this.userName,
              password: <PASSWORD>
            },
            success: function (data) {
              switch (data) {
                case "1":
                  self.userNameDis.display = "block";
                  self.userNameText = "请输入正确的用户名"
                  break;
                case "2":
                  console.log("登陆失败")
                  break;
                default :
                  console.log(data)
                  console.log(JSON.stringify(data.data))
                  sessionStorage.setItem('user', JSON.stringify(data.data));

                  self.$store.commit('setUserDate', {
                    userDate: data.data
                  })
                  self.$router.push({path: '/'})
                  break;
              }
            }

          })
        }

      },
    },
    watch: {
      userName(val) {
        if (val)
          this.userNameDis.display = "none";
        else
          this.userNameDis.display = "block";
      },
      passWord(val) {
        if (val)
          this.passWordDis.display = "none";
        else
          this.passWordDis.display = "block";
      },
    },
    mounted() {
      this.$nextTick(() => {
        var self = this;
        //qq登录
        QC.Login({
          btnId: "qqLoginBtn",    //插入按钮的节点id
          //用户需要确认的scope授权项，可选，默认all
          scope: "all",
          //按钮尺寸，可用值[A_XL| A_L| A_M| A_S|  B_M| B_S| C_S]，可选，默认B_S
          size: "C_S"
        });

        if (QC.Login.check()) {//如果已登录成功
          console.log("")
          QC.Login.getMe(function (openId, accessToken) {
            console.log(["当前登录用户的", "openId为：" + openId, "accessToken为：" + accessToken].join("\n"));
          });
        }

        QC.api("get_user_info", {})
          .success(function($res){
            console.log($res);

            _fetch.fetch("/registerUser", {
              user_name: $res.data.nickname,
              user_headImg: $res.data.figureurl_2,
              user_gender: $res.data.gender,
            }).then((data) => {
              console.log(data)

              console.log(JSON.stringify(data.data))
              sessionStorage.setItem('user', JSON.stringify(data.data));
              
              self.$store.commit('setUserDate', {
                userDate: data.data
              })
              self.$router.push({path: '/'})

            }).catch((error) => {
              console.log(error)
            })
          })
          //指定接口访问失败的接收函数，f为失败返回Response对象
          .error(function(f){
            alert("获取用户信息失败！");
          })
          .complete(function(c){
            alert("获取用户信息完成！");
          });

//检查是否登录
{'fraction_non_alphanumeric': 0.16309412861137, 'fraction_numerical': 0.0015250360077946285, 'mean_word_length': 1.459679099812461, 'pattern_counts': {'":': 4, '<': 160, '<?xml version=': 0, '>': 168, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7232396', 'n_tokens_mistral': 3738, 'n_tokens_neox': 3758, 'n_words': 569}