ExerciseLink.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <!-- 练习题链接 -->
  2. <template>
  3. <el-dialog
  4. :visible="visible"
  5. title="练习题链接"
  6. :width="shareData.type === 1 ? '400px' : '600px'"
  7. :close-on-click-modal="false"
  8. @close="dialogClose"
  9. >
  10. <div v-if="shareData.type === 2" class="exercise-link" :title="shareData.share_url">
  11. <div>{{ $store.state.user.user_real_name }}邀请您完成练习题!</div>
  12. <div>链接:{{ shareData.share_url }}</div>
  13. <br />
  14. <div>复制此链接到浏览器打开</div>
  15. </div>
  16. <div v-if="shareData.type === 1" class="qr-code">
  17. <span>{{ $store.state.user.user_real_name }}邀请您完成练习题!</span>
  18. <span>请扫描二维码</span>
  19. <img :src="QRCodeImg" alt="二维码" />
  20. </div>
  21. <div slot="footer" class="footer">
  22. <el-button @click="dialogClose">取消</el-button>
  23. <el-button v-show="shareData.type === 1" type="primary" @click="downloadQRCode">下载二维码</el-button>
  24. <el-button v-show="shareData.type === 2" type="primary" @click="writeClipboard">复制</el-button>
  25. </div>
  26. </el-dialog>
  27. </template>
  28. <script>
  29. import { downloadFile } from '@/utils/index';
  30. export default {
  31. name: 'ExerciseLink',
  32. props: {
  33. visible: {
  34. type: Boolean,
  35. required: true,
  36. },
  37. shareData: {
  38. type: Object,
  39. default: () => ({
  40. type: '',
  41. image_content_base64: '',
  42. }),
  43. },
  44. },
  45. data() {
  46. return {};
  47. },
  48. computed: {
  49. // 二维码图片地址
  50. QRCodeImg() {
  51. return `data:image/jpg;base64,${this.shareData.image_content_base64}`;
  52. },
  53. },
  54. methods: {
  55. downloadQRCode() {
  56. const byteArray = new Uint8Array(
  57. atob(this.shareData.image_content_base64)
  58. .split('')
  59. .map((char) => char.charCodeAt(0)),
  60. );
  61. // 创建Blob对象
  62. const blob = new Blob([byteArray], { type: 'image/jpg' });
  63. // 创建URL
  64. const imageUrl = URL.createObjectURL(blob);
  65. downloadFile(imageUrl, '二维码.jpg');
  66. },
  67. async writeClipboard() {
  68. await navigator.clipboard.writeText(this.shareData.share_url);
  69. this.$message.success('复制成功');
  70. },
  71. dialogClose() {
  72. this.$emit('update:visible', false);
  73. },
  74. },
  75. };
  76. </script>
  77. <style lang="scss" scoped>
  78. .el-dialog {
  79. :deep &__header {
  80. padding: 16px;
  81. border-bottom: 1px solid #ebebeb;
  82. }
  83. :deep &__headerbtn &__close {
  84. color: #000;
  85. }
  86. :deep &__body {
  87. padding: 40px 24px;
  88. .exercise-link {
  89. font-size: 16px;
  90. color: #000;
  91. }
  92. .qr-code {
  93. display: flex;
  94. flex-direction: column;
  95. align-items: center;
  96. img {
  97. width: 200px;
  98. height: 200px;
  99. }
  100. }
  101. }
  102. :deep &__footer {
  103. margin-top: 16px;
  104. }
  105. .footer {
  106. display: flex;
  107. align-items: center;
  108. justify-content: center;
  109. .el-button {
  110. width: 200px;
  111. height: 34px;
  112. border-radius: 20px;
  113. + .el-button {
  114. margin-left: 16px;
  115. }
  116. &--default {
  117. color: $main-color;
  118. background-color: #f3f7ff;
  119. }
  120. }
  121. }
  122. }
  123. </style>