index.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import { Button, Popup } from "vant";
  2. import styles from "./index.module.less";
  3. import { defineComponent, onMounted, onUnmounted, reactive, ref } from "vue";
  4. import { api_toggleTune, removeResult, sendResult } from "/src/helpers/communication";
  5. import { Vue3Lottie } from "vue3-lottie";
  6. import bg from "./json/bg.json";
  7. import bg1 from "./json/bg1.json";
  8. import f1 from "./json/f1.json";
  9. import f2 from "./json/f2.json";
  10. import f3 from "./json/f3.json";
  11. import f4 from "./json/f4.json";
  12. import f5 from "./json/f5.json";
  13. import f6 from "./json/f6.json";
  14. import f7 from "./json/f7.json";
  15. export default defineComponent({
  16. name: "delay-check",
  17. setup() {
  18. const anim = ref();
  19. const data = reactive({
  20. show: false,
  21. /** 检测状态 */
  22. checkStatus: "init" as "init" | "ing" | "error",
  23. count: 0,
  24. step: 1,
  25. });
  26. const listenerResult = () => {
  27. if (data.checkStatus !== "ing") return;
  28. data.count++;
  29. if (data.count >= 2) {
  30. toggleTune("finishTune");
  31. return;
  32. }
  33. setTimeout(() => {
  34. toggleTune("start");
  35. }, 100);
  36. };
  37. onMounted(() => {
  38. data.show = true;
  39. sendResult(listenerResult);
  40. console.log(anim.value);
  41. });
  42. onUnmounted(() => {
  43. removeResult(listenerResult);
  44. });
  45. const toggleTune = async (state: "start" | "stop" | "finishTune") => {
  46. if (state === "start") {
  47. api_toggleTune("start", data.count);
  48. setTimeout(() => {
  49. api_toggleTune("stop");
  50. }, 1500);
  51. } else if (state === "finishTune") {
  52. api_toggleTune("finishTune");
  53. }
  54. };
  55. const list = [
  56. {
  57. id: 1,
  58. json: f1,
  59. },
  60. {
  61. id: 2,
  62. json: f2,
  63. },
  64. {
  65. id: 3,
  66. json: f3,
  67. },
  68. {
  69. id: 4,
  70. json: f4,
  71. },
  72. {
  73. id: 5,
  74. json: f5,
  75. },
  76. {
  77. id: 6,
  78. json: f6,
  79. },
  80. {
  81. id: 7,
  82. json: f7,
  83. },
  84. ];
  85. return () => (
  86. <Popup
  87. teleport="body"
  88. overlay={false}
  89. class={["popup-custom", styles.popup]}
  90. transition="van-fade"
  91. v-model:show={data.show}
  92. >
  93. <div class={styles.delayBox}>
  94. <div class={[styles.item, data.step !== 7 && styles.show]}>
  95. <Vue3Lottie animationData={bg}></Vue3Lottie>
  96. </div>
  97. <div class={[styles.item, data.step === 7 && styles.show]}>
  98. <Vue3Lottie animationData={bg1}></Vue3Lottie>
  99. </div>
  100. <div class={[styles.item, data.step === 7 && styles.show]}>
  101. <Vue3Lottie
  102. ref={anim}
  103. animationData={bg1}
  104. onOnComplete={() => {
  105. console.log(123, anim.value);
  106. }}
  107. ></Vue3Lottie>
  108. </div>
  109. {list.map((item, index) => {
  110. return (
  111. <div class={[styles.item, data.step === item.id && styles.show]}>
  112. <Vue3Lottie animationData={item.json} loop={false}></Vue3Lottie>
  113. </div>
  114. );
  115. })}
  116. <Button
  117. class={styles.btn}
  118. disabled={data.checkStatus !== "init"}
  119. onClick={() => {
  120. data.checkStatus = "ing";
  121. toggleTune("start");
  122. }}
  123. >
  124. 开始检测
  125. </Button>
  126. </div>
  127. </Popup>
  128. );
  129. },
  130. });