music-guide.tsx 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. import { NButton } from 'naive-ui';
  2. import {
  3. defineComponent,
  4. nextTick,
  5. onMounted,
  6. onUnmounted,
  7. reactive,
  8. ref,
  9. watch
  10. } from 'vue';
  11. import styles from './index.module.less';
  12. import { getImage } from './images';
  13. import {px2vw,px2vwH} from '@/utils/index'
  14. export default defineComponent({
  15. name: 'music-guide',
  16. emits: ['close'],
  17. setup(props, { emit }) {
  18. const data = reactive({
  19. box: {
  20. height:'0px',
  21. } as any,
  22. show: false,
  23. /**
  24. *
  25. width: px2vw(840),
  26. height: px2vw(295)
  27. */
  28. steps: [
  29. {
  30. ele: '',
  31. eleRect: {} as DOMRect,
  32. img: getImage('music1.png'),
  33. handStyle: {
  34. top: '0.91rem'
  35. },
  36. imgStyle: {
  37. left: '-4.4em',
  38. width: '534px',
  39. height: '228px'
  40. },
  41. btnsStyle: {
  42. bottom:'30px',
  43. left: '90px',
  44. },
  45. eleRectPadding:{
  46. left:7,
  47. top:7,
  48. width:14,
  49. height:14
  50. }
  51. },
  52. {
  53. ele: '',
  54. img: getImage('music2.png'),
  55. imgStyle: {
  56. top: '100%',
  57. left: '-205px',
  58. width: '420px',
  59. height:'228px'
  60. },
  61. btnsStyle: {
  62. bottom: '30px',
  63. left: px2vw(-60),
  64. },
  65. boxStyle:{
  66. borderRadius: '25px'
  67. },
  68. eleRectPadding:{
  69. left:7,
  70. top:7,
  71. width:14,
  72. height:14
  73. }
  74. },
  75. {
  76. ele: '',
  77. img: getImage('music3.png'),
  78. imgStyle: {
  79. top: '100%',
  80. left: '-130px',
  81. width: px2vw(401),
  82. height: px2vw(304)
  83. },
  84. btnsStyle: {
  85. bottom: '90px',
  86. left:px2vw(20),
  87. },
  88. eleRectPadding:{
  89. left:7,
  90. top:7,
  91. width:14,
  92. height:14
  93. },
  94. type:'bottom'
  95. },
  96. ],
  97. step: 0
  98. });
  99. const tipShow = ref(false);
  100. const guideInfo = localStorage.getItem('teacher-guideInfo');
  101. if (guideInfo && JSON.parse(guideInfo).musicGuide) {
  102. tipShow.value = false;
  103. } else {
  104. tipShow.value = true;
  105. }
  106. const getStepELe = () => {
  107. const ele: HTMLElement = document.getElementById(`music-${data.step}`)!;
  108. if (ele ) {
  109. const eleRect = ele.getBoundingClientRect();
  110. console.log(ele.style.display,'ele')
  111. if(ele.style.display == 'none'){
  112. handleNext()
  113. return
  114. }
  115. const left = data.steps[data.step].eleRectPadding?.left || 0;
  116. const top = data.steps[data.step].eleRectPadding?.top || 0;
  117. const width = data.steps[data.step].eleRectPadding?.width || 0;
  118. const height = data.steps[data.step].eleRectPadding?.height || 0
  119. data.box = {
  120. left: eleRect.x - left+ 'px',
  121. top: eleRect.y - top +'px',
  122. width: eleRect.width + width+'px',
  123. height: eleRect.height +height+ 'px'
  124. };
  125. console.log(`coai-${data.step}`,data.box);
  126. }else{
  127. handleNext()
  128. }
  129. };
  130. onMounted(() => {
  131. getStepELe();
  132. window.addEventListener("resize", resetSize);
  133. });
  134. const resetSize = ()=>{
  135. getStepELe();
  136. }
  137. onUnmounted(()=>{
  138. window.removeEventListener("resize", resetSize);
  139. })
  140. const handleNext = () => {
  141. if (data.step >= 3) {
  142. endGuide();
  143. return;
  144. }
  145. data.step = data.step + 1;
  146. getStepELe();
  147. };
  148. const endGuide = () => {
  149. let guideInfo =
  150. JSON.parse(localStorage.getItem('teacher-guideInfo')|| '{}') || null;
  151. if (!guideInfo) {
  152. guideInfo = { musicGuide: true };
  153. } else {
  154. guideInfo.musicGuide = true;
  155. }
  156. localStorage.setItem('teacher-guideInfo', JSON.stringify(guideInfo));
  157. tipShow.value = false;
  158. // localStorage.setItem('endC')
  159. };
  160. return () => (
  161. <>
  162. {tipShow.value ? (
  163. <div
  164. v-model:show={tipShow.value}
  165. class={['n-modal-mask', 'n-modal-mask-guide']}>
  166. <div class={styles.content} onClick={() => handleNext()}>
  167. <div
  168. class={styles.backBtn}
  169. onClick={(e: Event) => {
  170. e.stopPropagation();
  171. endGuide();
  172. }}>
  173. 跳过
  174. </div>
  175. <div
  176. class={styles.box}
  177. style={{...data.box,...data.steps[data.step].boxStyle}}
  178. id={`modeType-${data.step}`}>
  179. {data.steps.map((item: any, index) => (
  180. <div
  181. onClick={(e: Event) => e.stopPropagation()}
  182. class={styles.item}
  183. style={ item.type=='bottom'? {
  184. display: index === data.step ? '' : 'none',
  185. left: `${item.eleRect?.left}px`,
  186. top:`-${item.imgStyle?.height}`
  187. }:{
  188. display: index === data.step ? '' : 'none',
  189. left: `${item.eleRect?.left}px`,
  190. top: `${data.box?.height}`,
  191. }}>
  192. <img
  193. class={styles.img}
  194. style={item.imgStyle}
  195. src={item.img}
  196. />
  197. {/* <img
  198. class={styles.iconHead}
  199. style={item.handStyle}
  200. src={getImage('indexDot.png')}
  201. /> */}
  202. <div class={styles.btns} style={item.btnsStyle}>
  203. {data.step + 1 == data.steps.length ? (
  204. <>
  205. <div
  206. class={[styles.endBtn]}
  207. onClick={() => endGuide()}>
  208. 完成
  209. </div>
  210. <div
  211. class={styles.nextBtn}
  212. onClick={() => {
  213. data.step = 0;
  214. getStepELe();
  215. }}>
  216. 再看一遍
  217. </div>
  218. </>
  219. ) : (
  220. <div class={styles.btn} onClick={() => handleNext()}>
  221. 下一步 ({data.step + 1}/{data.steps.length})
  222. </div>
  223. )}
  224. </div>
  225. </div>
  226. ))}
  227. </div>
  228. </div>
  229. </div>
  230. ) : null}
  231. </>
  232. );
  233. }
  234. });