Browse Source

add neew

master
panda 8 months ago
parent
commit
00866a5ba1
  1. 22
      src/components/blogs/header/NavigateMenu.vue
  2. 19
      src/stores/index.ts
  3. 31
      src/views/blog/HomePageView.vue

22
src/components/blogs/header/NavigateMenu.vue

@ -2,7 +2,7 @@
<div class="menu" v-if="show_menu">
<a-menu v-model:selectedKeys="current" mode="horizontal" :items="items" style="border-bottom: none;"
@click="jumpMenu" />
<a-input-search v-model:value="searchValue" placeholder="search" style="width: 200px" @search="onSearch" />
<a-input-search v-model:value="searchValue" placeholder="search" style="width: 200px" @search="onSearch" :disabled="isDisabled"/>
</div>
</template>
@ -16,14 +16,15 @@ import { HomeOutlined, HighlightOutlined, ProfileOutlined, CameraOutlined, Userg
import type { MenuProps } from 'ant-design-vue';
import { get } from '@/tools/request';
const props = defineProps(["items", "updateCarouselVisibility"])
const { idShow,fetchHomePageList } = homePageStore()
const { idShow,fetchHomePageList,setEmpty } = homePageStore()
const { show_menu } = toRefs(idShow)
const store = useContentStore();
const searchValue = ref("")
const articleTitle = ref<string>('');
const route = useRoute()
const onSearch =async (searchValue: string) => {
await fetchHomePageList(searchValue);
const isDisabled=ref(false)
const onSearch =(searchValue: string) => {
fetchHomePageList(searchValue)
};
const current = ref<string[]>(['home']);
const items = ref<MenuProps['items']>([
@ -111,7 +112,20 @@ watch(
},
{ immediate: true }
);
watch(searchValue, (newValue) => {
if (newValue === "") {
fetchHomePageList("");
}
});
router.beforeEach((to, _, next) => {
if (to.name !== 'home') {
isDisabled.value=true;
} else {
isDisabled.value=false;
}
next();
});
</script>
<style scoped>

19
src/stores/index.ts

@ -12,12 +12,24 @@ export const homePageStore = defineStore("homePage", () => {
show_author: true,
show_anchornDown: true
})
const isEmpty=ref(false)
const homepagelist = ref<homePageInterface[]>([]);
const fetchHomePageList = async (query: string="") => {
const response = await get(`/statistics/homepage?title=${query}`);
homepagelist.value = response.data.data;
// const response = await get(`/statistics/searchtitle?title=${query}`);
// homepagelist.value = response.data.data;
get(`/statistics/searchtitle?title=${query}`).then(res => {
homepagelist.value = res.data.data;
if (res.data.data.length === 0) {
isEmpty.value=true
}else{
isEmpty.value=false
}
})
};
return { idShow, homepagelist,fetchHomePageList }
return { idShow, homepagelist,isEmpty,fetchHomePageList }
})
export const blogStore = defineStore("blog", () => {
@ -43,7 +55,6 @@ export const useContentStore = defineStore('content', () => {
return { content, titles, setContent, setTitles, getTitle, showCatalogue };
});
export const diaryStore = defineStore("diary", () => {
const delControl = reactive({
open: false,

31
src/views/blog/HomePageView.vue

@ -94,16 +94,24 @@
</a-badge-ribbon>
</div>
</div>
<div class="loadbutton">
<a-button v-if="showLoadMoreButton" @click="loadMore" class="ripple-button" :loading="loading" type="primary">
<a-button v-if="showLoadMoreButton" @click="loadMore" class="ripple-button" :loading="loading"
type="primary">
{{ loading ? '加载中...' : '加载更多' }}
</a-button>
</div>
<div class="is-null" v-if="homepageStore.isEmpty">
<a-card hoverable>
<a-empty />
</a-card>
</div>
</div>
</template>
<script setup lang='ts'>
import { onMounted, ref,watch } from 'vue';
import { onMounted, ref, watch } from 'vue';
import type { homePageInterface } from '@/api';
import iconComponents from "@/assets/index"
import { get } from '@/tools/request';
@ -138,13 +146,13 @@ const showNextBatch = () => {
const showLoadMoreButton = ref<boolean>(true);
//
const loading=ref(false)
const loading = ref(false)
const loadMore = () => {
loading.value=true
setTimeout(()=>{
loading.value=false
loading.value = true
setTimeout(() => {
loading.value = false
showNextBatch();
},1500)
}, 1500)
};
@ -164,7 +172,7 @@ watch(() => homepageStore.homepagelist, () => {
// homepagelist
currentIndex = 0;
showNextBatch();
});
},);
</script>
<style scoped>
@ -258,14 +266,9 @@ watch(() => homepageStore.homepagelist, () => {
}
.loadbutton{
.loadbutton {
display: flex;
justify-content: right;
margin-bottom: 24px;
}
</style>
Loading…
Cancel
Save