<script setup lang="ts">
import type { UserModel } from '@/model/system.model';


const props = defineProps<{ dataset: UserModel }>();
const loading = ref(false);

async function handle() {
  loading.value = true;
  try {
    const response = await fetch(props.dataset.appletImg);
    const blob = await response.blob();
    const url = window.URL.createObjectURL(blob);
    const link = document.createElement('a');

    link.href = url;
    link.download = `${ props.dataset.nickName }专属小程序码.png`;
    link.click();

    setTimeout(() => window.URL.revokeObjectURL(url), 20);
  } catch ( e ) {}
  loading.value = false;
}
</script>
<template>
  <div class="text-center" style="padding: 12px">
    <a-image
      :src="props.dataset?.appletImg" :width="256" :height="256" :preview="false"
      style="object-fit: scale-down;"
    />
    <a-button type="primary" block style="margin-top: 12px;" :loading="loading" @click="handle()">下载</a-button>
  </div>
</template>
<style scoped lang="scss"></style>
