|
@@ -1,9 +1,8 @@
|
|
|
<script lang='ts' setup>
|
|
|
import { submitSubscribeApi } from '~/api/model/common'
|
|
|
import { PageSizeEnum } from '~/enums/sizeEnum'
|
|
|
-import {
|
|
|
- getBlogsListApi,
|
|
|
-} from '~/api/model/blogs'
|
|
|
+import { ConstKeys } from '~/enums/const-enums'
|
|
|
+import { Api } from '@/api/model/url'
|
|
|
|
|
|
const list = ref<any>([])
|
|
|
const currentPage = ref(PageSizeEnum.PAGE)
|
|
@@ -16,36 +15,39 @@ const categories = ref(
|
|
|
title: 'All',
|
|
|
slug: 'all',
|
|
|
},
|
|
|
- {
|
|
|
- key: 'instructions',
|
|
|
- title: 'Security settings instructions',
|
|
|
- slug: 'instructions',
|
|
|
- },
|
|
|
- {
|
|
|
- key: 'settings',
|
|
|
- title: 'Multiple account settings',
|
|
|
- slug: 'settings',
|
|
|
- },
|
|
|
],
|
|
|
)
|
|
|
-const category = ref('')
|
|
|
const form = ref<any>({
|
|
|
mail: '',
|
|
|
})
|
|
|
-async function getVideoOrBlogsList(pageNo = currentPage.value, pageSize = page_size.value) {
|
|
|
- const params = {
|
|
|
- pageNo,
|
|
|
- pageSize,
|
|
|
- categoryId: category.value,
|
|
|
- orderBy: 'createTime',
|
|
|
- orderType: 'desc',
|
|
|
+const params = ref({
|
|
|
+ pageNo: currentPage.value,
|
|
|
+ pageSize: page_size.value,
|
|
|
+ categoryId: '',
|
|
|
+})
|
|
|
+const { data: res } = await useAsyncData(
|
|
|
+ 'blog-category-list',
|
|
|
+ () => $fetch(`${ConstKeys.DOMAINDEV}${Api.BlogsCategoryList}`, { params: { all: true } }),
|
|
|
+)
|
|
|
+// Ensure we have a valid array before spreading
|
|
|
+const arr = Array.isArray(res.value?.result) ? res.value.result : []
|
|
|
+categories.value = [
|
|
|
+ ...categories.value,
|
|
|
+ ...arr,
|
|
|
+]
|
|
|
+params.value.categoryId = categories.value[0].key
|
|
|
+const { data: res2, pending, error, refresh } = await useAsyncData(
|
|
|
+ 'blog-list',
|
|
|
+ () => $fetch(`${ConstKeys.DOMAINDEV}${Api.BlogsList}`, { params: params.value }),
|
|
|
+)
|
|
|
+watch(() => res2.value, (newValue) => {
|
|
|
+ if (newValue?.result) {
|
|
|
+ total.value = newValue.result.total
|
|
|
+ currentPage.value = newValue.result.current
|
|
|
+ list.value = newValue.result.records
|
|
|
}
|
|
|
- const res: any = await getBlogsListApi(params)
|
|
|
- total.value = res.total
|
|
|
- currentPage.value = res.current
|
|
|
- list.value = res.records
|
|
|
-}
|
|
|
-getVideoOrBlogsList()
|
|
|
+}, { immediate: true })
|
|
|
+
|
|
|
async function submitSubscribe() {
|
|
|
try {
|
|
|
await submitSubscribeApi(form.value)
|
|
@@ -56,13 +58,16 @@ async function submitSubscribe() {
|
|
|
console.log(error)
|
|
|
}
|
|
|
}
|
|
|
-function onSelectCategory(item: any) {
|
|
|
- category.value = item.key
|
|
|
+async function onSelectCategory(item: any) {
|
|
|
+ params.value.categoryId = item.key
|
|
|
currentPage.value = PageSizeEnum.PAGE
|
|
|
- getVideoOrBlogsList(currentPage.value, page_size.value)
|
|
|
+ params.value.pageNo = PageSizeEnum.PAGE
|
|
|
+ await refresh()
|
|
|
}
|
|
|
-function changePage(current: number, size: number) {
|
|
|
- getVideoOrBlogsList(current, size)
|
|
|
+async function changePage(current: number, _size: number) {
|
|
|
+ params.value.pageNo = current
|
|
|
+ currentPage.value = current
|
|
|
+ await refresh()
|
|
|
}
|
|
|
const validateEmail = computed(() => {
|
|
|
const emailReg = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/
|
|
@@ -82,7 +87,7 @@ const validateEmail = computed(() => {
|
|
|
</h2>
|
|
|
<div class="pos-relative w-500px mx-auto mb-60px mt-40px">
|
|
|
<el-input v-model.trim="form.mail" class="custom-input h-46px !b-rd-200px overflow-hidden" placeholder="Please enter your email address" />
|
|
|
- <el-button :disabled="!validateEmail || !form.mail" type="primary" class="!bg-#9B6CFF text-#fff pos-absolute !b-0px top-50% transform-translate-y--50% right-10px w-120px !text-16px !b-rd-150px" @click="submitSubscribe">
|
|
|
+ <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">
|
|
|
Subscribe
|
|
|
</el-button>
|
|
|
</div>
|
|
@@ -93,7 +98,7 @@ const validateEmail = computed(() => {
|
|
|
:key="index"
|
|
|
class="h-60px lh-60px px-30px b-rd-200px text-16px cursor-pointer hover:bg-#EAE5FA hover:text-#9B6CFF transition-all duration-300"
|
|
|
:class="
|
|
|
- category === item.key
|
|
|
+ params.categoryId === item.key
|
|
|
? '!bg-#EAE5FA !text-#9B6CFF'
|
|
|
: 'bg-#fff text-#333'
|
|
|
"
|
|
@@ -105,7 +110,7 @@ const validateEmail = computed(() => {
|
|
|
</div>
|
|
|
<div class="pt-120px w-1200-auto">
|
|
|
<div class="grid grid-cols-3 gap-col-40px gap-row-60px ">
|
|
|
- <div v-for="item, index in list" :key="index">
|
|
|
+ <div v-for="item in list" :key="item.key">
|
|
|
<common-blog-item :item="item" />
|
|
|
</div>
|
|
|
</div>
|