index.vue 4.3 KB

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