index.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { Button, Popup } from 'vant'
  2. import {} from 'vant'
  3. import { defineComponent, nextTick, onMounted, reactive, ref, watch } from 'vue'
  4. import state from '/src/pages/detail/state'
  5. import styles from './index.module.less'
  6. import Tip1 from './tip1'
  7. import Tip2 from './tip2'
  8. import { modelType } from '../buttons'
  9. export default defineComponent({
  10. name: 'tips-step',
  11. setup(props, ctx) {
  12. const tipShow = ref(false)
  13. const guide = reactive({
  14. tip1: false,
  15. tip2: false,
  16. })
  17. watch(
  18. () => state.initRendered,
  19. () => {
  20. const isFirstTip = localStorage.getItem('isFirstTip')
  21. if (state.initRendered && modelType.value === 'init' && !isFirstTip) {
  22. tipShow.value = true
  23. guide.tip1 = true
  24. guide.tip2 = false
  25. console.log('首次渲染结束')
  26. }
  27. }
  28. )
  29. watch(modelType, () => {
  30. console.log(modelType.value)
  31. const isFirstModel = localStorage.getItem('isFirstModel')
  32. if (state.initRendered && modelType.value === 'practice' && !isFirstModel) {
  33. tipShow.value = true
  34. guide.tip1 = false
  35. guide.tip2 = true
  36. console.log('模式更改')
  37. }
  38. })
  39. const setLocalData = (key: string) => {
  40. localStorage.setItem(key, 'ok')
  41. }
  42. return () => (
  43. <Popup teleport="body" closeOnClickOverlay={false} class={styles.tipsContainer} v-model:show={tipShow.value}>
  44. {guide.tip1 && (
  45. <Tip1
  46. onHanldeStop={() => {
  47. tipShow.value = false
  48. setLocalData('isFirstTip')
  49. }}
  50. />
  51. )}
  52. {guide.tip2 && (
  53. <Tip2
  54. onHanldeStop={() => {
  55. tipShow.value = false
  56. setLocalData('isFirstModel')
  57. }}
  58. />
  59. )}
  60. </Popup>
  61. )
  62. },
  63. })