123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385 |
- import { NButton } from 'naive-ui';
- import {
- defineComponent,
- nextTick,
- onMounted,
- onUnmounted,
- reactive,
- ref,
- watch
- } from 'vue';
- import styles from './index.module.less';
- import { getImage } from './images';
- import { eventGlobal, px2vw, px2vwH } from '@/utils/index';
- import { getGuidance, setGuidance, setLocalGuidance } from './api';
- export default defineComponent({
- name: 'coai-guide',
- emits: ['close'],
- setup(props, { emit }) {
- const data = reactive({
- box: {
- height: '0px'
- } as any,
- show: false,
- /**
- *
- width: px2vw(840),
- height: px2vw(295)
- */
- steps: [
- {
- ele: '',
- eleRect: {} as DOMRect,
- img: getImage('home1.png'),
- handStyle: {
- top: '0.91rem'
- },
- imgStyle: {
- top: px2vw(-400 / 2),
- left: px2vw(-734 / 2),
- width: px2vw(734),
- height: px2vw(295)
- },
- btnsStyle: {
- bottom: px2vw(240),
- left: px2vw(-128)
- },
- boxStyle: {
- border: 'none',
- width: 0,
- height: 0,
- backgroundColor: 'transparent',
- position: 'fixed',
- top: `50%`,
- left: '50%'
- // visibility: 'hidden'
- },
- eleRectPadding: {
- left: 0,
- top: 0,
- width: 0,
- height: 0
- }
- },
- {
- ele: '',
- img: getImage('home2.png'),
- imgStyle: {
- top: '100%',
- left: px2vw(-290),
- width: px2vw(401),
- height: px2vw(227)
- },
- btnsStyle: {
- bottom: '30px',
- left: px2vw(-130)
- },
- boxStyle: {},
- eleRectPadding: {
- left: 7,
- top: 7,
- width: 14,
- height: 14
- }
- },
- {
- ele: '',
- img: getImage('home6.png'),
- imgStyle: {
- top: '100%',
- left: px2vw(-310),
- width: px2vw(477),
- height: px2vw(227)
- },
- btnsStyle: {
- bottom: '30px',
- left: px2vw(-150)
- },
- boxStyle: {},
- eleRectPadding: {
- left: 7,
- top: 7,
- width: 14,
- height: 14
- }
- },
- {
- ele: '',
- img: getImage('home4.png'),
- imgStyle: {
- top: '100%',
- left: px2vw(-310),
- width: px2vw(477),
- height: px2vw(227)
- },
- btnsStyle: {
- bottom: '30px',
- left: px2vw(-150)
- },
- boxStyle: {},
- eleRectPadding: {
- left: 7,
- top: 7,
- width: 14,
- height: 14
- }
- },
- {
- ele: '',
- img: getImage('home3.png'),
- handStyle: {
- top: '-1.39rem',
- left: '0.17rem',
- transform: 'rotate(180deg)'
- },
- imgStyle: {
- top: px2vw(-4),
- width: px2vw(454),
- height: px2vw(227),
- left: px2vw(-150)
- },
- btnsStyle: {
- bottom: '30px',
- left: px2vw(8)
- },
- boxStyle: {
- borderRadius: '30px'
- },
- eleRectPadding: {
- left: 7,
- top: 9,
- width: 14,
- height: 14
- }
- },
- {
- ele: '',
- img: getImage('home5.png'),
- handStyle: {
- top: '-1.39rem',
- left: '0.17rem',
- transform: 'rotate(180deg)'
- },
- imgStyle: {
- top: px2vw(-194),
- width: px2vw(621),
- height: px2vw(223),
- left: px2vw(-624)
- },
- btnsStyle: {
- top: px2vw(-42),
- left: px2vw(-460)
- },
- boxStyle: {},
- eleRectPadding: {
- left: 7,
- top: 7,
- width: 14,
- height: 14
- }
- }
- ],
- step: 0
- });
- const tipShow = ref(false);
- // const res = setGuidance({guideTag:'teacher-guideInfo',guideValue:'{}'})
- const guideInfo = ref({} as any);
- const getAllGuidance = async () => {
- try {
- // const res = await getGuidance({ guideTag: 'teacher-guideInfo' });
- // if (res.data) {
- // guideInfo.value = JSON.parse(res.data?.guideValue) || null;
- // } else {
- // guideInfo.value = {};
- // }
- const res = localStorage.getItem('teacher-guideInfo');
- if (res) {
- guideInfo.value = JSON.parse(res) || null;
- } else {
- guideInfo.value = {};
- }
- if (guideInfo.value && guideInfo.value.homeGuide) {
- tipShow.value = false;
- } else {
- tipShow.value = true;
- }
- } catch (e) {
- console.log(e);
- }
- // const guideInfo = localStorage.getItem('teacher-guideInfo');
- };
- getAllGuidance();
- const getStepELe = () => {
- const ele: HTMLElement = document.getElementById(
- data.step === data.steps.length - 1
- ? 'moveNPopover'
- : `home-${data.step}`
- )!;
- // console.log(`coai-${data.step}`, data.steps[data.step].eleRectPadding);
- if (ele) {
- const eleRect = ele.getBoundingClientRect();
- const left = data.steps[data.step].eleRectPadding?.left || 0;
- const top = data.steps[data.step].eleRectPadding?.top || 0;
- const width = data.steps[data.step].eleRectPadding?.width || 0;
- const height = data.steps[data.step].eleRectPadding?.height || 0;
- console.log(eleRect, height);
- data.box = {
- left: eleRect.x - left + 'px',
- top: eleRect.y - top + 'px',
- width: eleRect.width + width + 'px',
- height: eleRect.height + height + 'px'
- };
- } else {
- handleNext();
- }
- };
- const onResetGuide = async (name: string) => {
- try {
- if (name !== 'Home') return;
- if (!guideInfo.value) {
- guideInfo.value = { homeGuide: false };
- } else {
- guideInfo.value.homeGuide = false;
- }
- try {
- setLocalGuidance({
- guideTag: 'teacher-guideInfo',
- guideValue: JSON.stringify(guideInfo.value)
- });
- } catch (e) {
- console.log(e);
- }
- data.step = 0;
- getStepELe();
- tipShow.value = true;
- } catch {
- //
- }
- };
- onMounted(() => {
- getStepELe();
- window.addEventListener('resize', resetSize);
- eventGlobal.on('teacher-guideInfo', onResetGuide);
- });
- const resetSize = () => {
- getStepELe();
- };
- onUnmounted(() => {
- window.removeEventListener('resize', resetSize);
- eventGlobal.off('teacher-guideInfo', onResetGuide);
- });
- const handleNext = () => {
- if (data.step >= data.steps.length - 1) {
- endGuide();
- return;
- }
- data.step = data.step + 1;
- getStepELe();
- };
- const endGuide = async () => {
- // let guideInfo =
- // JSON.parse(localStorage.getItem('teacher-guideInfo') || '{}') || null;
- if (!guideInfo.value) {
- guideInfo.value = { homeGuide: true };
- } else {
- guideInfo.value.homeGuide = true;
- }
- try {
- setLocalGuidance({
- guideTag: 'teacher-guideInfo',
- guideValue: JSON.stringify(guideInfo.value)
- });
- } catch (e) {
- console.log(e);
- }
- // localStorage.setItem('teacher-guideInfo', JSON.stringify(guideInfo));
- tipShow.value = false;
- // localStorage.setItem('endC')
- };
- return () => (
- <>
- {tipShow.value ? (
- <div
- v-model:show={tipShow.value}
- class={['n-modal-mask', 'n-modal-mask-guide']}>
- <div class={styles.content} onClick={() => handleNext()}>
- <div
- class={styles.backBtn}
- onClick={(e: Event) => {
- e.stopPropagation();
- endGuide();
- }}>
- 跳过
- </div>
- <div
- class={styles.box}
- style={{ ...data.box, ...data.steps[data.step].boxStyle }}
- id={`modeType-${data.step}`}>
- {data.steps.map((item: any, index) => (
- <div
- onClick={(e: Event) => e.stopPropagation()}
- class={styles.item}
- style={
- item.type == 'bottom'
- ? {
- display: index === data.step ? '' : 'none',
- left: `${item.eleRect?.left}px`,
- top: `-${item.imgStyle?.height}`
- }
- : {
- display: index === data.step ? '' : 'none',
- left: `${item.eleRect?.left}px`,
- top: `${data.box?.height}`
- }
- }>
- <img
- class={styles.img}
- style={item.imgStyle}
- src={item.img}
- />
- {/* <img
- class={styles.iconHead}
- style={item.handStyle}
- src={getImage('indexDot.png')}
- /> */}
- <div class={styles.btns} style={item.btnsStyle}>
- {data.step + 1 == data.steps.length ? (
- <>
- <div
- class={[styles.endBtn]}
- onClick={() => endGuide()}>
- 完成
- </div>
- <div
- class={styles.nextBtn}
- onClick={() => {
- data.step = 0;
- getStepELe();
- }}>
- 再看一遍
- </div>
- </>
- ) : (
- <div class={styles.btn} onClick={() => handleNext()}>
- {data.step !== 0
- ? `下一步 ${data.step}/${data.steps.length - 1}`
- : '开始体验'}
- </div>
- )}
- </div>
- </div>
- ))}
- </div>
- </div>
- </div>
- ) : null}
- </>
- );
- }
- });
|