music-guide.tsx 7.5 KB

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