music-guide.tsx 7.7 KB

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