index.tsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { Snackbar } from "@varlet/ui";
  2. import { defineComponent, onMounted, ref } from "vue";
  3. import styles from "./index.module.less";
  4. import { api_shareAchievements } from "/src/helpers/communication";
  5. import state from "/src/state";
  6. import { storeData } from "/src/store";
  7. import { evaluatingData } from "/src/view/evaluating";
  8. import qs from 'query-string'
  9. export default defineComponent({
  10. name: "evaluat-share",
  11. emits: ["close"],
  12. setup(props, { emit }) {
  13. const src = ref("");
  14. const shareLoadedPngData = ref("");
  15. const shareDisabeled = ref(true);
  16. const getShareUrl = () => {
  17. const data: any = {
  18. name: storeData.user?.username || "",
  19. subjectName: (storeData.user?.subjectNames || "").split(",")[0] || "",
  20. avatar: encodeURIComponent(storeData.user?.avatar || ""),
  21. score: evaluatingData.resultData?.score || 0,
  22. examSongName: state.examSongName || "",
  23. };
  24. if (!state.isPercussion) {
  25. data.intonation = evaluatingData.resultData?.intonation;
  26. data.cadence = evaluatingData.resultData?.cadence;
  27. data.integrity = evaluatingData.resultData?.integrity;
  28. }
  29. // src.value = `${location.origin}/accompany/share-evaluating/index.html?${qs.stringify(data)}`;
  30. src.value = `${location.origin}/share-evaluating/index.html?${qs.stringify(data)}`;
  31. };
  32. const shareLoaded = (evt: Event) => {
  33. const el = evt.target as HTMLIFrameElement;
  34. if (el) {
  35. // @ts-ignore
  36. el.contentWindow.setPng = (data: string) => {
  37. shareLoadedPngData.value = data;
  38. shareDisabeled.value = false
  39. };
  40. }
  41. };
  42. const shareNext = async () => {
  43. const res = await api_shareAchievements({
  44. title: "分享我的乐器练习进度,一起见证我的成长!",
  45. desc: "晒一下我的评测分数,快来“云教练”上和我PK一下吧!",
  46. image: shareLoadedPngData.value,
  47. video: "",
  48. type: "image",
  49. });
  50. if (!res?.content?.status && res?.content?.message) {
  51. Snackbar(res?.content?.message);
  52. }
  53. emit("close");
  54. };
  55. onMounted(() => {
  56. getShareUrl();
  57. });
  58. return () => (
  59. <div>
  60. <div class={styles.btns}>
  61. <div class={styles.sbtn} onClick={() => emit("close")}>
  62. 取消
  63. </div>
  64. <div class={[styles.sbtn, shareDisabeled.value && styles.disabled]} onClick={shareNext}>
  65. 继续
  66. </div>
  67. </div>
  68. <iframe class={styles.iframe} src={src.value} onLoad={shareLoaded} />
  69. </div>
  70. );
  71. },
  72. });