<template>
  <div>
    <avue-form ref="form" v-model="form" :option="option" @submit="submit">
      <template slot-scope="scope" slot="menuForm">
        <el-button @click="test1">test1</el-button>
        <el-button @click="test2">test2</el-button>
        <el-button @click="test3">test3</el-button>
      </template>
    </avue-form>
  </div>
</template>

<script>

  import {testLogin, findAllUser, findByCn} from "../../api/user";
  import {testNotice} from "../../api/desk/notice";

  export default {
      name: "login-test",
      data() {
        return {
          form: {},
          option: {
            column: [
              {
                label: "账号",
                prop: "account",
                span:8
              },
              {
                label: "密码",
                prop: "password",
                type:'password',
                span:8
              },
            ]
          }
        }
      },
      methods: {
        submit(){
          testLogin(this.form).then(res => {
            console.log('testLogin')
            this.$Log.primary('testLogin' + res)
            this.$alert("驗證成功！")
          });
        },
        test1(){
          findAllUser(this.form).then(res => {
            this.$Log.primary('findAllUser' + res)
          });
        },
        test2(){
          let account = this.encryptByDES(this.form.account, "cyzh2020");
          findByCn(account).then(res => {
            console.log('findByCn')
            console.log(res)
            this.$Log.primary('findByCn' + res)
          });
        },
        test3(){
          testNotice(this.form.account).then(res => {
            console.log('testNotice-test3');
            const data = res.data.data;
            if (res.data.code == 200){
              this.$message.success(data.msg);
            }
          });
        },
        encryptByDES(message, key){
          var keyHex = CryptoJS.enc.Utf8.parse(key);
          var encrypted = CryptoJS.DES.encrypt(message, keyHex, {
            mode: CryptoJS.mode.ECB,
            padding: CryptoJS.pad.Pkcs7
          });
          return encrypted.ciphertext.toString();
        },
        decryptByDES(ciphertext, key){
          var keyHex = CryptoJS.enc.Utf8.parse(key);
          var decrypted = CryptoJS.DES.decrypt({
            ciphertext: CryptoJS.enc.Hex.parse(ciphertext)
          }, keyHex, {
            mode: CryptoJS.mode.ECB,
            padding: CryptoJS.pad.Pkcs7
          });
          var result_value = decrypted.toString(CryptoJS.enc.Utf8);
          return result_value;
        }
      },
    }
</script>

<style scoped>

</style>
