index.vue 4.3 KB

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