diff --git a/src/stores/index.ts b/src/stores/index.ts index ed2d74f..6ca32a1 100644 --- a/src/stores/index.ts +++ b/src/stores/index.ts @@ -2,6 +2,19 @@ import { reactive, ref } from 'vue' import { defineStore } from 'pinia' import { get } from "@/tools/request" import dayjs from 'dayjs'; +interface blogInterface { + key: string, + blogtitle: string, + create_at: Date, + readnum: number, + readminite: number, + wordcount: number, + img: string, + blogcontent: string, + typename: string, + labelnames: string +} +const bloglist = ref([]) export const useAuthStore = defineStore("auth", () => { const tokenValue = ref("") @@ -14,21 +27,9 @@ export const useAuthStore = defineStore("auth", () => { return { setToken, removeToken } }) + // 博客列表接口 export const blogContentStore = defineStore("blog", () => { - interface blogInterface { - key: string, - blogtitle: string, - create_at: Date, - readnum: number, - readminite: number, - wordcount: number, - img: string, - blogcontent: string, - typename: string, - labelnames: string - } - const bloglist = ref([]) async function blogList() { try { const response = await get("/blogs/list"); @@ -57,54 +58,82 @@ export const blogContentStore = defineStore("blog", () => { return { blogList, bloglist } }) -// 语录列表接口 -export const classticContentStore = defineStore("classtic", () => { - interface classticInterface { - key: string, - header: string, - text: string, - descr: string - } - const classticlist = ref([]) - async function classticList() { - try { - const response = await get("/classtics/list") - if (response) { - classticlist.value = response.data.data.map((items: any, index: any) => ({ - key: (index + 1).toString(), - header: items.header, - text: items.text, - descr: items.descr - })) - } else { - console.log("classtic is not exit") - } - } catch (error) { - console.log("classtic is error") +// 博客查询接口 +export const blogSearchStore = defineStore('blogsearch', () => { + const searchValue = reactive({ + blogtitle: '', + typename: '', + start_date: '', + end_date: '' + }); + + + + const onChange = (date: string, dateString: string[]) => { + if (date && dateString.length === 2) { + searchValue.start_date = dateString[0]; + searchValue.end_date = dateString[1]; + } else { + searchValue.start_date = ''; + searchValue.end_date = ''; + } + console.log(dateString[0]); + }; + + const blogSearch = async () => { + try { + const response = await get("/blogs/list/search", { + blogtitle: searchValue.blogtitle, + typename: searchValue.typename, + start_date: searchValue.start_date, + end_date: searchValue.end_date + }); + if (response && response.data) { + bloglist.value = response.data.data.map((items: any, index: any) => ({ + key: (index + 1).toString(), + blogtitle: items.blogtitle, + typename: items.typename, + blogcontent: items.blogcontent, + create_at: dayjs(items.create_at).format('YYYY-MM-DD HH:mm:ss'), + update_at: dayjs(items.update_at).format('YYYY-MM-DD HH:mm:ss'), + descr: items.descr + })); + console.log(response) + } else { + console.log("request has no data"); } - } - return { classticList, classticlist } -}) -// 语录单查询 -export const classticSearchStore = defineStore("classticSearch", () => { - const classticsearch = ref<{ header: string }>() + } catch (error) { + console.error("request is exception", error); + } + }; + return { searchValue, onChange, blogSearch }; + }); - async function classticSearch() { - try { - const response = get( - "/classtics/search", - classticsearch.value?.header - ) - if (response) { - classticsearch.value = (await response).data.data.map((items: any) => ({ - header: items.header - })) - } else { - console.log("header is not exit") - } - } catch (error) { - console.log("header is error") - } - } - return { classticsearch, classticSearch } -}) \ No newline at end of file +// 语录列表接口 +// export const classticContentStore = defineStore("classtic", () => { +// interface classticInterface { +// key: string, +// header: string, +// text: string, +// descr: string +// } +// const classticlist = ref([]) +// async function classticList() { +// try { +// const response = await get("/classtics/list") +// if (response) { +// classticlist.value = response.data.data.map((items: any, index: any) => ({ +// key: (index + 1).toString(), +// header: items.header, +// text: items.text, +// descr: items.descr +// })) +// } else { +// console.log("classtic is not exit") +// } +// } catch (error) { +// console.log("classtic is error") +// } +// } +// return { classticList, classticlist } +// }) diff --git a/src/views/admin/blogmange/BlogManageView.vue b/src/views/admin/blogmange/BlogManageView.vue index 959228e..7e60201 100644 --- a/src/views/admin/blogmange/BlogManageView.vue +++ b/src/views/admin/blogmange/BlogManageView.vue @@ -2,18 +2,20 @@