index.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <script lang='ts' setup>
  2. import { submitSubscribeApi } from '~/api/model/common'
  3. import { PageSizeEnum } from '~/enums/sizeEnum'
  4. import { ConstKeys } from '~/enums/const-enums'
  5. import { Api } from '@/api/model/url'
  6. const list = ref<any>([])
  7. const currentPage = ref(PageSizeEnum.PAGE)
  8. const total = ref()
  9. const page_size = ref(9)
  10. const categories = ref(
  11. [
  12. {
  13. key: '',
  14. title: 'All',
  15. slug: 'all',
  16. },
  17. ],
  18. )
  19. const form = ref<any>({
  20. mail: '',
  21. })
  22. const params = ref({
  23. pageNo: currentPage.value,
  24. pageSize: page_size.value,
  25. categoryId: '',
  26. })
  27. const { data: res } = await useAsyncData(
  28. 'blog-category-list',
  29. () => $fetch(`${ConstKeys.DOMAINDEV}${Api.BlogsCategoryList}`, { params: { all: true } }),
  30. )
  31. // Ensure we have a valid array before spreading
  32. const arr = Array.isArray(res.value?.result) ? res.value.result : []
  33. categories.value = [
  34. ...categories.value,
  35. ...arr,
  36. ]
  37. params.value.categoryId = categories.value[0].key
  38. const { data: res2, pending, error, refresh } = await useAsyncData(
  39. 'blog-list',
  40. () => $fetch(`${ConstKeys.DOMAINDEV}${Api.BlogsList}`, { params: params.value }),
  41. )
  42. watch(() => res2.value, (newValue) => {
  43. if (newValue?.result) {
  44. total.value = newValue.result.total
  45. currentPage.value = newValue.result.current
  46. list.value = newValue.result.records
  47. }
  48. }, { immediate: true })
  49. async function submitSubscribe() {
  50. try {
  51. await submitSubscribeApi(form.value)
  52. ElMessage.success(`You've subscribed successfully.`)
  53. form.value.mail = ''
  54. }
  55. catch (error) {
  56. console.log(error)
  57. }
  58. }
  59. async function onSelectCategory(item: any) {
  60. params.value.categoryId = item.key
  61. currentPage.value = PageSizeEnum.PAGE
  62. params.value.pageNo = PageSizeEnum.PAGE
  63. await refresh()
  64. }
  65. async function changePage(current: number, _size: number) {
  66. params.value.pageNo = current
  67. currentPage.value = current
  68. await refresh()
  69. }
  70. const validateEmail = computed(() => {
  71. const emailReg = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/
  72. if (!form.value.mail)
  73. return true
  74. return emailReg.test(form.value.mail)
  75. })
  76. </script>
  77. <template>
  78. <div>
  79. <div class="pt-184px pb-50px bg-#F3F4FB text-center">
  80. <h2 class="text-60px fw-800 ls-2 text-#333 inline-block pos-relative custom-title-font">
  81. EJET Spark <span class="custom-title-bg03">Blog</span>
  82. <img src="@/assets/images/blog_icon05.png" class="w-90px h-90px pos-absolute top--10px left--120px" alt="" srcset="">
  83. <img src="@/assets/images/blog_icon06.png" class="w-70px h-70px pos-absolute top--20px right--100px" alt="" srcset="">
  84. </h2>
  85. <div class="pos-relative w-500px mx-auto mb-60px mt-40px">
  86. <el-input v-model.trim="form.mail" class="custom-input h-46px !b-rd-200px overflow-hidden" placeholder="Please enter your email address" />
  87. <el-button :disabled="!validateEmail || !form.mail" type="primary" class="!bg-#9B6CFF !disabled:bg-#9B6CFF/70 text-#fff pos-absolute !b-0px top-50% transform-translate-y--50% right-10px w-120px !text-16px !b-rd-150px" @click="submitSubscribe">
  88. Subscribe
  89. </el-button>
  90. </div>
  91. <div class="flex gap-30px justify-center">
  92. <div
  93. v-for="(item, index) in categories"
  94. :key="index"
  95. class="h-60px lh-60px px-30px b-rd-200px text-16px cursor-pointer hover:bg-#EAE5FA hover:text-#9B6CFF transition-all duration-300"
  96. :class="
  97. params.categoryId === item.key
  98. ? '!bg-#EAE5FA !text-#9B6CFF'
  99. : 'bg-#fff text-#333'
  100. "
  101. @click="onSelectCategory(item)"
  102. >
  103. {{ item.title }}
  104. </div>
  105. </div>
  106. </div>
  107. <div class="pt-120px w-1200-auto">
  108. <div class="grid grid-cols-3 gap-col-40px gap-row-60px ">
  109. <div v-for="item in list" :key="item.key">
  110. <common-blog-item :item="item" />
  111. </div>
  112. </div>
  113. <div class="mt-60px flex justify-center">
  114. <el-pagination
  115. v-model:current-page="currentPage" :page-size="page_size" :pager-count="10"
  116. layout="prev, pager, next" :total="total" @change="changePage"
  117. />
  118. </div>
  119. </div>
  120. <AppFooter />
  121. </div>
  122. </template>
  123. <style lang='less' scoped>
  124. ::v-deep(.custom-input){
  125. .el-input__wrapper{
  126. border-radius:4px!important;
  127. padding: 7px 10px!important;
  128. color: #999;
  129. font-size: 16px;
  130. box-shadow: unset!important;
  131. }
  132. }
  133. </style>