LearnPlanButton.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <template>
  2. <div class="learn-plan-button" @click="goPage" :style="styles" >
  3. <div class="icon" >
  4. <img :src="icon" alt="">
  5. </div>
  6. <div class="name" >
  7. <span style="" >{{title}} </span>
  8. <span v-if="props.type == 'forward'">{{countDown}}s </span>
  9. </div>
  10. </div>
  11. </template>
  12. <script lang="ts" setup >
  13. import { defineProps, ref, onMounted, onUnmounted } from 'vue'
  14. import { useRouter } from 'vue-router'
  15. import { useScheduler } from '@/hook/index'
  16. const staticImg = {
  17. forward: require('@LP/assets/forward.png'),
  18. reload: require('@LP/assets/reload.png')
  19. }
  20. interface IProps {
  21. title: string,
  22. type: 'normal' | 'forward',
  23. goPage: () => void
  24. }
  25. const router = useRouter()
  26. const props = defineProps<IProps>()
  27. const emit = defineEmits(['click'])
  28. const title = ref<string>('')
  29. const countDown = ref<number>(5)
  30. const icon = ref<string>('')
  31. const styles = props.type === 'normal' ? { background: '#fff', color: '#FF8A3F' } : { background: '#FF8A3F', color: '#fff' }
  32. onMounted(() => {
  33. console.log('onMounted')
  34. title.value = props.title
  35. if (props.type === 'normal') {
  36. icon.value = staticImg.reload
  37. } else {
  38. icon.value = staticImg.forward
  39. countDownFn()
  40. }
  41. })
  42. onUnmounted(() => {
  43. console.log('onUnmounted')
  44. })
  45. const countDownFn = () => {
  46. const [stx] = useScheduler({
  47. cb: () => {
  48. countDown.value--
  49. if (countDown.value <= 1) {
  50. stx.pause()
  51. }
  52. },
  53. delay: 1000
  54. })
  55. stx.start()
  56. }
  57. const goPage = () => props.goPage()
  58. </script>
  59. <style scoped lang="scss" >
  60. .learn-plan-button {
  61. width: 159px;
  62. height: 50px;
  63. border-radius: 15px;
  64. font-size: 18px;
  65. font-family: PingFangSC-Semibold, PingFang SC;
  66. font-weight: 600;
  67. display: flex;
  68. justify-content: center;
  69. align-items: center;
  70. border-radius: 29px;
  71. .icon {
  72. margin-right: 8px;
  73. img {
  74. width: 26px;
  75. height: 29px;
  76. display: block;
  77. }
  78. }
  79. }
  80. </style>