index.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { Icon } from 'vant'
  2. import { defineComponent, onMounted, ref } from 'vue'
  3. import styles from './index.module.less'
  4. import icon3 from '../../images/icon3.png'
  5. export default defineComponent({
  6. name: 'tips',
  7. props: {
  8. /** 标题 */
  9. title: {
  10. type: String,
  11. default: '',
  12. },
  13. /** 内容 */
  14. content: {
  15. type: String,
  16. default: ''
  17. },
  18. /** 类型 */
  19. type: {
  20. type: String,
  21. default: ''
  22. },
  23. btnTxt: {
  24. type: String,
  25. default: '不再提醒'
  26. }
  27. },
  28. emits: ['close', 'confirm'],
  29. setup(props, { emit }) {
  30. const isStatus = ref(true)
  31. console.log(props.type, '1212')
  32. // 获取当前提示是否有缓存
  33. const getTypeIsCatch = () => {
  34. const localType = localStorage.getItem('teacher_home_local');
  35. const formatLocalType = localType ? JSON.parse(localType) : {}
  36. console.log(formatLocalType[props.type])
  37. if(formatLocalType[props.type]) {
  38. return true
  39. } else {
  40. return false
  41. }
  42. }
  43. // 设置已知道
  44. const setTypeIsCatch = () => {
  45. const localType = localStorage.getItem('teacher_home_local');
  46. const formatLocalType = localType ? JSON.parse(localType) : {}
  47. formatLocalType[props.type] = 1
  48. localStorage.setItem('teacher_home_local', JSON.stringify(formatLocalType))
  49. }
  50. onMounted(() => {
  51. isStatus.value = !getTypeIsCatch()
  52. })
  53. return () => (
  54. isStatus.value ? <div class={styles.tipSection}>
  55. <Icon class={styles.iconCross} onClick={() => {
  56. emit('close')
  57. isStatus.value = false
  58. }} name="cross" />
  59. <div class={styles.tipTitle}>
  60. <img src={icon3} />
  61. {props.title}
  62. </div>
  63. <div class={styles.tipContent}>
  64. {props.content}
  65. </div>
  66. <div class={styles.tipFooter} onClick={() => {
  67. emit("confirm")
  68. setTypeIsCatch()
  69. isStatus.value = false
  70. }}>{props.btnTxt}</div>
  71. </div> : ''
  72. )
  73. }
  74. })