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. class: {
  28. type: String,
  29. default: ''
  30. }
  31. },
  32. emits: ['close', 'confirm'],
  33. setup(props, { emit }) {
  34. const isStatus = ref(true)
  35. // 获取当前提示是否有缓存
  36. const getTypeIsCatch = () => {
  37. const localType = localStorage.getItem('teacher_home_local');
  38. const formatLocalType = localType ? JSON.parse(localType) : {}
  39. if(formatLocalType[props.type]) {
  40. return true
  41. } else {
  42. return false
  43. }
  44. }
  45. // 设置已知道
  46. const setTypeIsCatch = () => {
  47. const localType = localStorage.getItem('teacher_home_local');
  48. const formatLocalType = localType ? JSON.parse(localType) : {}
  49. formatLocalType[props.type] = 1
  50. localStorage.setItem('teacher_home_local', JSON.stringify(formatLocalType))
  51. }
  52. onMounted(() => {
  53. isStatus.value = !getTypeIsCatch()
  54. })
  55. return () => (
  56. isStatus.value ? <div class={[styles.tipSection, props.class]}>
  57. <Icon class={styles.iconCross} onClick={() => {
  58. emit('close')
  59. isStatus.value = false
  60. }} name="cross" />
  61. <div class={styles.tipTitle}>
  62. <img src={icon3} />
  63. {props.title}
  64. </div>
  65. <div class={styles.tipContent}>
  66. {props.content}
  67. </div>
  68. <div class={styles.tipFooter} onClick={() => {
  69. emit("confirm")
  70. setTypeIsCatch()
  71. isStatus.value = false
  72. }}>{props.btnTxt}</div>
  73. </div> : ''
  74. )
  75. }
  76. })