shareResources-guide.tsx 7.2 KB

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