|
|
@ -2,7 +2,86 @@ import { reactive, ref } from 'vue' |
|
|
|
import { defineStore } from 'pinia' |
|
|
|
import { get } from "@/tools/request" |
|
|
|
import dayjs from 'dayjs'; |
|
|
|
interface blogInterface { |
|
|
|
import { useRouter } from "vue-router" |
|
|
|
|
|
|
|
const router = useRouter() |
|
|
|
|
|
|
|
export const useAuthStore = defineStore("auth", () => { |
|
|
|
const tokenValue = ref("") |
|
|
|
function setToken(token: string) { |
|
|
|
tokenValue.value = token |
|
|
|
} |
|
|
|
function removeToken() { |
|
|
|
localStorage.removeItem('token'); |
|
|
|
} |
|
|
|
return { setToken, removeToken } |
|
|
|
}) |
|
|
|
|
|
|
|
// 语录列表接口
|
|
|
|
export const panelContentStore = defineStore("panel", () => { |
|
|
|
interface panelList { |
|
|
|
id: number, |
|
|
|
header: string, |
|
|
|
text: string |
|
|
|
} |
|
|
|
const panels = ref<panelList[]>([]) |
|
|
|
const panelData = async () => { |
|
|
|
try { |
|
|
|
const response = await get("/classtics/list"); |
|
|
|
if (response) { |
|
|
|
panels.value = response.data.data.map((item: any) => ({ |
|
|
|
id: item.id, |
|
|
|
header: item.header, |
|
|
|
text: item.text, |
|
|
|
})); |
|
|
|
} else { |
|
|
|
console.error("Response data structure is not as expected:"); |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
console.error("Failed to fetch data", error); |
|
|
|
} |
|
|
|
} |
|
|
|
return { panels, panelData } |
|
|
|
}) |
|
|
|
|
|
|
|
// 链接接口
|
|
|
|
export const comLinkContentStore = defineStore("comlink", () => { |
|
|
|
interface comlinkList { |
|
|
|
id: number, |
|
|
|
linktext: string, |
|
|
|
linkurl: string |
|
|
|
} |
|
|
|
const linkbuttons = ref<comlinkList[]>([]) |
|
|
|
const comLinkData = async () => { |
|
|
|
try { |
|
|
|
const response = await get("/comlink/list"); |
|
|
|
if (response) { |
|
|
|
linkbuttons.value = response.data.data.map((items: any) => ({ |
|
|
|
id: items.id, |
|
|
|
linktext: items.linktext, |
|
|
|
linkurl: items.linkurl |
|
|
|
})) |
|
|
|
} else { |
|
|
|
console.log("response data is not exist") |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
console.error("Failed to fetch data", error); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
const comLinkClick = (url: string) => { |
|
|
|
if (url.startsWith('http://') || url.startsWith('https://')) { |
|
|
|
window.open(url, "_blank"); // 使用 window.location.href 打开外部链接
|
|
|
|
} else { |
|
|
|
router.push(url); // 否则使用 Vue Router 的 push 方法导航
|
|
|
|
} |
|
|
|
} |
|
|
|
return {linkbuttons,comLinkData,comLinkClick} |
|
|
|
}) |
|
|
|
|
|
|
|
// 博客列表接口
|
|
|
|
export const blogContentStore = defineStore("blog", () => { |
|
|
|
interface blogInterface { |
|
|
|
key: string, |
|
|
|
blogtitle: string, |
|
|
|
create_at: Date, |
|
|
@ -13,127 +92,112 @@ interface blogInterface { |
|
|
|
blogcontent: string, |
|
|
|
typename: string, |
|
|
|
labelnames: string |
|
|
|
} |
|
|
|
const bloglist = ref<blogInterface[]>([]) |
|
|
|
|
|
|
|
export const useAuthStore = defineStore("auth", () => { |
|
|
|
const tokenValue = ref("") |
|
|
|
function setToken(token: string) { |
|
|
|
tokenValue.value = token |
|
|
|
} |
|
|
|
function removeToken() { |
|
|
|
localStorage.removeItem('token'); |
|
|
|
} |
|
|
|
const bloglist = ref<blogInterface[]>([]) |
|
|
|
async function blogList() { |
|
|
|
try { |
|
|
|
const response = await get("/blogs/list"); |
|
|
|
if (response) { |
|
|
|
bloglist.value = response.data.data.map((items: any, index: any) => ({ |
|
|
|
key: (index + 1).toString(), |
|
|
|
blogtitle: items.blogtitle, |
|
|
|
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'), |
|
|
|
readnum: items.readnum, |
|
|
|
readminite: items.readminite, |
|
|
|
wordcount: items.wordcount, |
|
|
|
img: items.img, |
|
|
|
blogcontent: items.blogcontent, |
|
|
|
typename: items.typename, |
|
|
|
labelnames: items.labelnames |
|
|
|
})) |
|
|
|
} else { |
|
|
|
console.log("bloglist is not exits") |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
console.log("bloglist is error") |
|
|
|
} |
|
|
|
return { setToken, removeToken } |
|
|
|
|
|
|
|
} |
|
|
|
return { blogList, bloglist } |
|
|
|
}) |
|
|
|
|
|
|
|
// 博客查询接口
|
|
|
|
export const blogSearchStore = defineStore('blogsearch', () => { |
|
|
|
const searchValue = reactive({ |
|
|
|
blogtitle: '', |
|
|
|
typename: '', |
|
|
|
start_date: '', |
|
|
|
end_date: '' |
|
|
|
}); |
|
|
|
|
|
|
|
// 博客列表接口
|
|
|
|
export const blogContentStore = defineStore("blog", () => { |
|
|
|
async function blogList() { |
|
|
|
try { |
|
|
|
const response = await get("/blogs/list"); |
|
|
|
if (response) { |
|
|
|
bloglist.value = response.data.data.map((items: any, index: any) => ({ |
|
|
|
key: (index + 1).toString(), |
|
|
|
blogtitle: items.blogtitle, |
|
|
|
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'), |
|
|
|
readnum: items.readnum, |
|
|
|
readminite: items.readminite, |
|
|
|
wordcount: items.wordcount, |
|
|
|
img: items.img, |
|
|
|
blogcontent: items.blogcontent, |
|
|
|
typename: items.typename, |
|
|
|
labelnames: items.labelnames |
|
|
|
})) |
|
|
|
} else { |
|
|
|
console.log("bloglist is not exits") |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
console.log("bloglist is error") |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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 = ''; |
|
|
|
} |
|
|
|
return { blogList, bloglist } |
|
|
|
}) |
|
|
|
console.log(dateString[0]); |
|
|
|
}; |
|
|
|
|
|
|
|
// 博客查询接口
|
|
|
|
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]; |
|
|
|
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 { |
|
|
|
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"); |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
console.error("request is exception", error); |
|
|
|
console.log("request has no data"); |
|
|
|
} |
|
|
|
}; |
|
|
|
return { searchValue, onChange, blogSearch }; |
|
|
|
}); |
|
|
|
} catch (error) { |
|
|
|
console.error("request is exception", error); |
|
|
|
} |
|
|
|
}; |
|
|
|
return { searchValue, onChange, blogSearch }; |
|
|
|
}); |
|
|
|
|
|
|
|
// 语录列表接口
|
|
|
|
// export const classticContentStore = defineStore("classtic", () => {
|
|
|
|
// interface classticInterface {
|
|
|
|
// key: string,
|
|
|
|
// header: string,
|
|
|
|
// text: string,
|
|
|
|
// descr: string
|
|
|
|
// }
|
|
|
|
// const classticlist = ref<classticInterface[]>([])
|
|
|
|
// 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 }
|
|
|
|
// })
|
|
|
|
export const classticContentStore = defineStore("classtic", () => { |
|
|
|
interface classticInterface { |
|
|
|
key: string, |
|
|
|
header: string, |
|
|
|
text: string, |
|
|
|
descr: string |
|
|
|
} |
|
|
|
const classticlist = ref<classticInterface[]>([]) |
|
|
|
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 } |
|
|
|
}) |