<template>
  <!-- TODO: 设置默认图片 -->
  <image :src="src" mode="aspectFit" class="image" @click="getCode"></image>
</template>

<script>
export default {
  data() {
    return { src: '' };
  },

  created() {
    this.getCode();
  },

  methods: {
    // 获取图形验证码
    async getCode() {
      try {
        const data = await this.$u.api.getImageCode();
        const { imageBase64, verificationCodeId } = data;
        this.src = imageBase64;
        this.$emit('on-code', verificationCodeId);
      } catch (error) {
        console.error('error: ', error);
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.image {
  width: 100px !important;
  height: 35px !important;
}
</style>
