useReqConfig.js 977 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import {
  2. getAllConfig,
  3. } from "@/api/user";
  4. import {
  5. getArticle
  6. } from "@/api/article.js";
  7. import {
  8. formatRich
  9. } from "@/core/app.js";
  10. import {
  11. ref
  12. } from "vue";
  13. export const useReqConfig = () => {
  14. const configData = ref(null)
  15. const articleData = ref(null)
  16. const getAllConfigData = async (parmas) => {
  17. let res = await getAllConfig(parmas)
  18. if (res) {
  19. configData.value = res.data
  20. return configData.value
  21. }
  22. }
  23. const getConfig = (list = configData.value, name, key) => {
  24. let res = ''
  25. if (list && list.length > 0) res = list.find(item => item.name == name)
  26. if (res[key]) res = res[key]
  27. else res = ''
  28. return res
  29. }
  30. // 单个文章
  31. const getArticleDetails = async (parmas) => {
  32. let res = await getArticle(parmas)
  33. if (res) {
  34. articleData.value = res.data
  35. articleData.value.content = formatRich(res.data.content)
  36. return articleData.value
  37. }
  38. }
  39. return {
  40. configData,
  41. articleData,
  42. getAllConfigData,
  43. getArticleDetails,
  44. getConfig
  45. }
  46. }