You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
194 lines
4.7 KiB
194 lines
4.7 KiB
import { reactive, ref } from 'vue'
|
|
import { defineStore } from 'pinia'
|
|
import type { homePageInterface } from '@/api'
|
|
import dayjs from 'dayjs';
|
|
import { get } from '@/tools/request'
|
|
export const mainWrapperStore = defineStore("mainWrapper", () => {
|
|
})
|
|
export const homePageStore = defineStore("homePage", () => {
|
|
const idShow = reactive({
|
|
show_menu: false,
|
|
show_carousel: true,
|
|
show_author: true,
|
|
show_anchornDown: true
|
|
})
|
|
const isEmpty=ref(false)
|
|
const homepagelist = ref<homePageInterface[]>([]);
|
|
const fetchHomePageList = async (query: string="") => {
|
|
// 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.map((items:any)=>({
|
|
...items,
|
|
imglink: items.imglink || 'https://www.wuruilin.cn/personself/暂无图片.jpg',
|
|
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'),
|
|
}));
|
|
if (res.data.data.length === 0) {
|
|
isEmpty.value=true
|
|
}else{
|
|
isEmpty.value=false
|
|
}
|
|
})
|
|
|
|
|
|
};
|
|
const fetchHomeLabelPageList= async (query:any) => {
|
|
// const response = await get(`/statistics/searchtitle?title=${query}`);
|
|
// homepagelist.value = response.data.data;
|
|
get(
|
|
"/blogs/search/label/",
|
|
{labelname:query}
|
|
).then(res => {
|
|
homepagelist.value = res.data.data.map((items:any)=>({
|
|
...items,
|
|
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'),
|
|
}));
|
|
if (res.data.data.length === 0) {
|
|
isEmpty.value=true
|
|
}else{
|
|
isEmpty.value=false
|
|
}
|
|
})
|
|
|
|
|
|
};
|
|
return { idShow, homepagelist,isEmpty,fetchHomePageList,fetchHomeLabelPageList }
|
|
})
|
|
|
|
export const blogStore = defineStore("blog", () => {
|
|
const delControl = reactive({
|
|
open: false,
|
|
ids: "",
|
|
title:""
|
|
})
|
|
const isEmpty=ref(false)
|
|
const isPage=ref(true)
|
|
const formControl = ref({
|
|
open: false,
|
|
ids: null
|
|
})
|
|
const readcount=ref(0)
|
|
const setReadCount=(num:number)=>{
|
|
readcount.value+=num
|
|
}
|
|
return { delControl,formControl,readcount,isEmpty,isPage,setReadCount }
|
|
})
|
|
export const useContentStore = defineStore('content', () => {
|
|
const content = ref({ text: "" });
|
|
const getTitle = ref("")
|
|
const showCatalogue = ref(false)
|
|
const titles = ref<{ title: string; lineIndex: string; indent: number }[]>([]);
|
|
function setContent(newContent: string) {
|
|
content.value.text = newContent;
|
|
}
|
|
|
|
function setTitles(newTitles: { title: string; lineIndex: string; indent: number }[]) {
|
|
titles.value = newTitles;
|
|
}
|
|
|
|
return { content, titles, setContent, setTitles, getTitle, showCatalogue };
|
|
});
|
|
export const diaryStore = defineStore("diary", () => {
|
|
const delControl = reactive({
|
|
open: false,
|
|
ids: null,
|
|
title:""
|
|
})
|
|
const isEmpty=ref(false)
|
|
const isPage=ref(true)
|
|
|
|
return { delControl,isEmpty,isPage }
|
|
})
|
|
export const classticStore = defineStore("classtic", () => {
|
|
const addControl = reactive({
|
|
open: false,
|
|
title: "",
|
|
mode: "",
|
|
ids: ""
|
|
})
|
|
|
|
const delControl = reactive({
|
|
open: false,
|
|
ids: "",
|
|
})
|
|
|
|
const editControl = reactive({
|
|
open: false,
|
|
ids: "",
|
|
title: ""
|
|
})
|
|
return { addControl, delControl, editControl }
|
|
})
|
|
export const comLinkStore = defineStore("comLink", () => {
|
|
const addControl = reactive({
|
|
open: false,
|
|
title: "",
|
|
mode: "",
|
|
ids: ""
|
|
})
|
|
|
|
const delControl = reactive({
|
|
open: false,
|
|
ids: ""
|
|
})
|
|
|
|
const editControl = reactive({
|
|
open: false,
|
|
ids: "",
|
|
title: ""
|
|
})
|
|
return { addControl, delControl, editControl }
|
|
})
|
|
export const typeStore = defineStore("type", () => {
|
|
const addControl = reactive({
|
|
open: false,
|
|
title: "",
|
|
ids: ""
|
|
})
|
|
|
|
const delControl = reactive({
|
|
open: false,
|
|
ids: ""
|
|
})
|
|
|
|
const editControl = reactive({
|
|
open: false,
|
|
ids: "",
|
|
title: ""
|
|
})
|
|
return { addControl, delControl, editControl }
|
|
})
|
|
export const labelStore = defineStore("label", () => {
|
|
const addControl = reactive({
|
|
open: false,
|
|
title: "",
|
|
ids: ""
|
|
})
|
|
|
|
const delControl = reactive({
|
|
open: false,
|
|
ids: ""
|
|
})
|
|
|
|
const editControl = reactive({
|
|
open: false,
|
|
ids: "",
|
|
title: ""
|
|
})
|
|
return { addControl, delControl, editControl }
|
|
})
|
|
export const useAuthStore = defineStore("auth", () => {
|
|
const tokenValue = ref("")
|
|
function setToken(token: string) {
|
|
tokenValue.value = token
|
|
}
|
|
function removeToken() {
|
|
localStorage.removeItem('token');
|
|
}
|
|
return { setToken, removeToken }
|
|
})
|
|
|
|
|
|
|