addStudentModel.tsx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. import {
  2. NButton,
  3. NSpace,
  4. useMessage,
  5. NForm,
  6. NFormItem,
  7. NSelect,
  8. NImage
  9. } from 'naive-ui';
  10. import { defineComponent, onMounted, reactive, ref } from 'vue';
  11. import styles from '../index.module.less';
  12. import CSelect from '/src/components/CSelect';
  13. import stunentStart from '../images/studentStart.png';
  14. import studentCLose from '../images/studentClose.png';
  15. import { useUserStore } from '@/store/modules/users';
  16. import TheQrCode from '/src/components/TheQrCode';
  17. import { vaildUrl } from '@/utils/urlUtils';
  18. import logo from '@/common/images/logo.png';
  19. import studentTitle from '../images/studentTitle.png';
  20. import studentInfo from '../images/strudentCore.png';
  21. import btnBg from '../images/btnBg.png';
  22. import html2canvas from 'html2canvas';
  23. import codewrap from '../images/cordWrap.png';
  24. export default defineComponent({
  25. props: {
  26. activeRow: {
  27. type: Object,
  28. default: () => ({ id: '' })
  29. },
  30. gradeNumList: {
  31. type: Array,
  32. default: () => []
  33. },
  34. classArray: {
  35. type: Array,
  36. default: () => []
  37. }
  38. },
  39. name: 'resetStudent',
  40. emits: ['close', 'getList'],
  41. setup(props, { emit }) {
  42. const data = reactive({
  43. uploading: false
  44. });
  45. const message = useMessage();
  46. const userStore = useUserStore();
  47. const foemsRef = ref();
  48. // const url = ref(
  49. // vaildUrl() +
  50. // `/classroom-app/#/student-register?sId=${userStore.getUserInfo.schoolInfos[0].id}`
  51. // );
  52. const url = ref(
  53. vaildUrl() + `/classroom-app/#/student-register?sId=${props.activeRow.id}`
  54. );
  55. if (props.activeRow.registerType != 'BUG_GOODS') {
  56. url.value =
  57. vaildUrl() +
  58. `/classroom-app/#/register-member?sId=${props.activeRow.id}`;
  59. }
  60. const imgs = reactive({
  61. saveLoading: false,
  62. image: null as any,
  63. shareLoading: false
  64. });
  65. const downImg = () => {
  66. if (imgs.saveLoading) {
  67. return;
  68. }
  69. imgs.saveLoading = true;
  70. // 判断是否已经生成图片
  71. if (imgs.image) {
  72. saveImg();
  73. } else {
  74. const container: any = document.getElementById(`preview-container`);
  75. html2canvas(container, {
  76. allowTaint: true,
  77. useCORS: true,
  78. backgroundColor: null
  79. })
  80. .then(async canvas => {
  81. const url = canvas.toDataURL('image/png');
  82. imgs.image = url;
  83. saveImg();
  84. })
  85. .catch(() => {
  86. imgs.saveLoading = false;
  87. });
  88. }
  89. };
  90. const saveImg = async () => {
  91. // showLoadingToast({ message: '图片生成中...', forbidClick: true });
  92. setTimeout(() => {
  93. imgs.saveLoading = false;
  94. }, 100);
  95. const link = document.createElement('a');
  96. link.setAttribute('download', '报名图片' + '.png');
  97. // 添加时间戳,防止浏览器缓存图片
  98. // console.log(imgUrl,'imgUrl')
  99. link.href = imgs.image;
  100. link.click();
  101. // const res = await promisefiyPostMessage({
  102. // api: 'savePicture',
  103. // content: {
  104. // base64: imgs.image
  105. // }
  106. // });
  107. // if (res?.content?.status === 'success') {
  108. // showSuccessToast('保存成功');
  109. // } else {
  110. // showFailToast('保存失败');
  111. // }
  112. };
  113. return () => (
  114. <div class={[styles.addStudentWrap]}>
  115. <div
  116. onClick={() => {
  117. console.log('点击');
  118. emit('close');
  119. }}>
  120. <NImage
  121. src={studentCLose}
  122. previewDisabled
  123. class={styles.studentCLose}></NImage>
  124. </div>
  125. <NImage
  126. previewDisabled
  127. class={styles.stunentStart}
  128. src={stunentStart}></NImage>
  129. <NImage
  130. class={styles.addTitle}
  131. previewDisabled
  132. src={studentTitle}></NImage>
  133. <div class={styles.addStudentInfo} id="preview-container">
  134. <NImage
  135. class={styles.studentInfoBg}
  136. previewDisabled
  137. src={studentInfo}></NImage>
  138. <div class={styles.studentCore}>
  139. <img
  140. alt="img"
  141. crossorigin="anonymous"
  142. class={styles.schoolLogo}
  143. src={
  144. userStore.getUserInfo.schoolInfos[0].logo +
  145. `?some=${new Date().getTime()}`
  146. }></img>
  147. <div class={styles.studentCoreInfo}>
  148. <h2>{userStore.getUserInfo.schoolInfos[0].name}</h2>
  149. <p class={styles.studentCoreInfoSubtitle}>
  150. {/* 邀请您的孩子加入
  151. <span>音乐数字课堂</span> */}
  152. 乐器Ai学练工具<span>购买通道</span>
  153. </p>
  154. <div class={styles.codewrap}>
  155. <TheQrCode margin={0} text={url.value} size={119} />
  156. {/* <img src={codewrap} class={styles.codewrapBg} alt="" /> */}
  157. </div>
  158. <div class={styles.codewrapSubmit}>
  159. <NImage previewDisabled src={btnBg}></NImage>
  160. 请使用微信扫码
  161. {/* <span>完成报名</span>{' '} */}
  162. </div>
  163. </div>
  164. </div>
  165. </div>
  166. <div class={styles.studentBottom}>
  167. <p>请将二维码图片发送给学生家长,扫码完成报名</p>
  168. <div class={styles.downBtn} onClick={downImg}>
  169. 下载图片
  170. </div>
  171. </div>
  172. </div>
  173. );
  174. }
  175. });