shareResources-guide.tsx 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. if(res.data){
  89. guideInfo.value = JSON.parse(res.data?.guideValue) || null
  90. }else{
  91. guideInfo.value = {}
  92. }
  93. if (guideInfo.value && guideInfo.value.shareResourcesGuide) {
  94. tipShow.value = false;
  95. } else {
  96. tipShow.value = true;
  97. }
  98. }catch(e){
  99. console.log(e)
  100. }
  101. // const guideInfo = localStorage.getItem('teacher-guideInfo');
  102. }
  103. getAllGuidance()
  104. // const guideInfo = localStorage.getItem('teacher-guideInfo');
  105. // if (guideInfo && JSON.parse(guideInfo).shareResourcesGuide) {
  106. // tipShow.value = false;
  107. // } else {
  108. // tipShow.value = true;
  109. // }
  110. const getStepELe = () => {
  111. const ele: HTMLElement = document.getElementById(`shareResources-${data.step}`)!;
  112. if (ele) {
  113. const eleRect = ele.getBoundingClientRect();
  114. const left = data.steps[data.step].eleRectPadding?.left || 0;
  115. const top = data.steps[data.step].eleRectPadding?.top || 0;
  116. const width = data.steps[data.step].eleRectPadding?.width || 0;
  117. const height = data.steps[data.step].eleRectPadding?.height || 0
  118. if(`shareResources-${data.step}`=='shareResources-1'){
  119. data.box = {
  120. left: eleRect.x - left+ 'px',
  121. top: eleRect.y - top +'px',
  122. width: (eleRect.width + width)*2+width+'px',
  123. height: eleRect.height +height+ 'px'
  124. };
  125. console.log( data.box.width,'---',eleRect.width)
  126. }else{
  127. data.box = {
  128. left: eleRect.x - left+ 'px',
  129. top: eleRect.y - top +'px',
  130. width: eleRect.width + width+'px',
  131. height: eleRect.height +height+ 'px'
  132. };
  133. }
  134. console.log(`coai-${data.step}`,data.box);
  135. }else{
  136. handleNext()
  137. }
  138. };
  139. onMounted(() => {
  140. getStepELe();
  141. window.addEventListener("resize", resetSize);
  142. });
  143. const resetSize = ()=>{
  144. getStepELe();
  145. }
  146. onUnmounted(()=>{
  147. window.removeEventListener("resize", resetSize);
  148. })
  149. const handleNext = () => {
  150. if (data.step >= 4) {
  151. endGuide();
  152. return;
  153. }
  154. data.step = data.step + 1;
  155. getStepELe();
  156. };
  157. const endGuide = async() => {
  158. // let guideInfo =
  159. // JSON.parse(localStorage.getItem('teacher-guideInfo')||'{}') || null;
  160. if (!guideInfo.value) {
  161. guideInfo.value = { shareResourcesGuide: true };
  162. } else {
  163. guideInfo.value.shareResourcesGuide = true;
  164. }
  165. // localStorage.setItem('teacher-guideInfo', JSON.stringify(guideInfo));
  166. try{
  167. const res = await setGuidance({guideTag:'teacher-guideInfo',guideValue:JSON.stringify(guideInfo.value)})
  168. }catch(e){
  169. console.log(e)
  170. }
  171. tipShow.value = false;
  172. // localStorage.setItem('endC')
  173. };
  174. return () => (
  175. <>
  176. {tipShow.value ? (
  177. <div
  178. v-model:show={tipShow.value}
  179. class={['n-modal-mask', 'n-modal-mask-guide']}>
  180. <div class={styles.content} onClick={() => handleNext()}>
  181. <div
  182. class={styles.backBtn}
  183. onClick={(e: Event) => {
  184. e.stopPropagation();
  185. endGuide();
  186. }}>
  187. 跳过
  188. </div>
  189. <div
  190. class={styles.box}
  191. style={{...data.box,...data.steps[data.step].boxStyle}}
  192. id={`modeType-${data.step}`}>
  193. {data.steps.map((item: any, index) => (
  194. <div
  195. onClick={(e: Event) => e.stopPropagation()}
  196. class={styles.item}
  197. style={ item.type=='bottom'? {
  198. display: index === data.step ? '' : 'none',
  199. left: `${item.eleRect?.left}px`,
  200. top:`-${item.imgStyle?.height}`
  201. }:{
  202. display: index === data.step ? '' : 'none',
  203. left: `${item.eleRect?.left}px`,
  204. top: `${data.box?.height}`,
  205. }}>
  206. <img
  207. class={styles.img}
  208. style={item.imgStyle}
  209. src={item.img}
  210. />
  211. {/* <img
  212. class={styles.iconHead}
  213. style={item.handStyle}
  214. src={getImage('indexDot.png')}
  215. /> */}
  216. <div class={styles.btns} style={item.btnsStyle}>
  217. {data.step + 1 == data.steps.length ? (
  218. <>
  219. <div
  220. class={[styles.endBtn]}
  221. onClick={() => endGuide()}>
  222. 完成
  223. </div>
  224. <div
  225. class={styles.nextBtn}
  226. onClick={() => {
  227. data.step = 0;
  228. getStepELe();
  229. }}>
  230. 再看一遍
  231. </div>
  232. </>
  233. ) : (
  234. <div class={styles.btn} onClick={() => handleNext()}>
  235. 下一步 ({data.step + 1}/{data.steps.length})
  236. </div>
  237. )}
  238. </div>
  239. </div>
  240. ))}
  241. </div>
  242. </div>
  243. </div>
  244. ) : null}
  245. </>
  246. );
  247. }
  248. });