index.vue 4.4 KB

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