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.

216 lines
5.3 KiB

9 months ago
8 months ago
8 months ago
8 months ago
7 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
7 months ago
8 months ago
8 months ago
8 months ago
7 months ago
9 months ago
9 months ago
8 months ago
9 months ago
7 months ago
8 months ago
7 months ago
9 months ago
8 months ago
8 months ago
7 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
7 months ago
8 months ago
7 months ago
8 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
7 months ago
9 months ago
8 months ago
9 months ago
8 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
8 months ago
9 months ago
8 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
8 months ago
9 months ago
8 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
8 months ago
9 months ago
8 months ago
9 months ago
9 months ago
9 months ago
  1. import { reactive, ref } from 'vue'
  2. import { defineStore } from 'pinia'
  3. import type { homePageInterface } from '@/api'
  4. import dayjs from 'dayjs';
  5. import { get } from '@/tools/request'
  6. // 后台admin的store
  7. // 前台blog的store
  8. export const blogHeaderStore=defineStore('blogheader',()=>{
  9. const show_author=ref(true)
  10. const show_menu=ref(false)
  11. const searchValue=ref("")
  12. return {show_author,show_menu,searchValue}
  13. })
  14. export const blogContentStore=defineStore('blogcontent',()=>{
  15. const isEmpty=ref(false)
  16. const isDisabled=ref(false)
  17. const getTitle = ref("")
  18. const titles = ref<{ title: string; lineIndex: string; indent: number }[]>([]);
  19. const setTitles=(newTitles: { title: string; lineIndex: string; indent: number }[])=> {
  20. titles.value = newTitles;
  21. }
  22. return {getTitle,setTitles,isEmpty,isDisabled}
  23. })
  24. export const mainWrapperStore = defineStore("mainWrapper", () => {
  25. })
  26. export const homePageStore = defineStore("homePage", () => {
  27. const idShow = reactive({
  28. show_menu: false,
  29. show_carousel: true,
  30. show_author: true,
  31. show_anchornDown: true
  32. })
  33. const isEmpty=ref(false)
  34. const homepagelist = ref<homePageInterface[]>([]);
  35. const fetchHomePageList = async (query: string="") => {
  36. // const response = await get(`/statistics/searchtitle?title=${query}`);
  37. // homepagelist.value = response.data.data;
  38. get(`/statistics/searchtitle?title=${query}`).then(res => {
  39. homepagelist.value = res.data.data.map((items:any)=>({
  40. ...items,
  41. imglink: items.imglink || 'https://www.wuruilin.cn/personself/暂无图片.jpg',
  42. create_at:dayjs(items.create_at).format('YYYY-MM-DD HH:mm:ss'),
  43. update_at: dayjs(items.update_at).format('YYYY-MM-DD HH:mm:ss'),
  44. }));
  45. if (res.data.data.length === 0) {
  46. isEmpty.value=true
  47. }else{
  48. isEmpty.value=false
  49. }
  50. })
  51. };
  52. const fetchHomeLabelPageList= async (query:any) => {
  53. // const response = await get(`/statistics/searchtitle?title=${query}`);
  54. // homepagelist.value = response.data.data;
  55. get(
  56. "/blogs/search/label/",
  57. {labelname:query}
  58. ).then(res => {
  59. homepagelist.value = res.data.data.map((items:any)=>({
  60. ...items,
  61. create_at:dayjs(items.create_at).format('YYYY-MM-DD HH:mm:ss'),
  62. update_at: dayjs(items.update_at).format('YYYY-MM-DD HH:mm:ss'),
  63. }));
  64. if (res.data.data.length === 0) {
  65. isEmpty.value=true
  66. }else{
  67. isEmpty.value=false
  68. }
  69. })
  70. };
  71. return { idShow, homepagelist,isEmpty,fetchHomePageList,fetchHomeLabelPageList }
  72. })
  73. export const blogStore = defineStore("blog", () => {
  74. const delControl = reactive({
  75. open: false,
  76. ids: "",
  77. title:""
  78. })
  79. const isEmpty=ref(false)
  80. const isPage=ref(true)
  81. const formControl = ref({
  82. open: false,
  83. ids: null
  84. })
  85. const readcount=ref(0)
  86. const setReadCount=(num:number)=>{
  87. readcount.value+=num
  88. }
  89. return { delControl,formControl,readcount,isEmpty,isPage,setReadCount }
  90. })
  91. export const useContentStore = defineStore('content', () => {
  92. const content = ref({ text: "" });
  93. const getTitle = ref("")
  94. const showCatalogue = ref()
  95. const titles = ref<{ title: string; lineIndex: string; indent: number }[]>([]);
  96. function setContent(newContent: string) {
  97. content.value.text = newContent;
  98. }
  99. function setTitles(newTitles: { title: string; lineIndex: string; indent: number }[]) {
  100. titles.value = newTitles;
  101. }
  102. return { content, titles, setContent, setTitles, getTitle, showCatalogue };
  103. });
  104. export const diaryStore = defineStore("diary", () => {
  105. const delControl = reactive({
  106. open: false,
  107. ids: null,
  108. title:""
  109. })
  110. const isEmpty=ref(false)
  111. const isPage=ref(true)
  112. return { delControl,isEmpty,isPage }
  113. })
  114. export const classticStore = defineStore("classtic", () => {
  115. const addControl = reactive({
  116. open: false,
  117. title: "",
  118. mode: "",
  119. ids: ""
  120. })
  121. const delControl = reactive({
  122. open: false,
  123. ids: "",
  124. })
  125. const editControl = reactive({
  126. open: false,
  127. ids: "",
  128. title: ""
  129. })
  130. return { addControl, delControl, editControl }
  131. })
  132. export const comLinkStore = defineStore("comLink", () => {
  133. const addControl = reactive({
  134. open: false,
  135. title: "",
  136. mode: "",
  137. ids: ""
  138. })
  139. const delControl = reactive({
  140. open: false,
  141. ids: ""
  142. })
  143. const editControl = reactive({
  144. open: false,
  145. ids: "",
  146. title: ""
  147. })
  148. return { addControl, delControl, editControl }
  149. })
  150. export const typeStore = defineStore("type", () => {
  151. const addControl = reactive({
  152. open: false,
  153. title: "",
  154. ids: ""
  155. })
  156. const delControl = reactive({
  157. open: false,
  158. ids: ""
  159. })
  160. const editControl = reactive({
  161. open: false,
  162. ids: "",
  163. title: ""
  164. })
  165. return { addControl, delControl, editControl }
  166. })
  167. export const labelStore = defineStore("label", () => {
  168. const addControl = reactive({
  169. open: false,
  170. title: "",
  171. ids: ""
  172. })
  173. const delControl = reactive({
  174. open: false,
  175. ids: ""
  176. })
  177. const editControl = reactive({
  178. open: false,
  179. ids: "",
  180. title: ""
  181. })
  182. return { addControl, delControl, editControl }
  183. })
  184. export const useAuthStore = defineStore("auth", () => {
  185. const tokenValue = ref("")
  186. function setToken(token: string) {
  187. tokenValue.value = token
  188. }
  189. function removeToken() {
  190. localStorage.removeItem('token');
  191. }
  192. return { setToken, removeToken }
  193. })