common.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /** @format */
  2. import { defineStore } from 'pinia'
  3. import { useUserStore } from './user'
  4. export const useCommonStore = defineStore(
  5. 'commonStore',
  6. () => {
  7. const navigateTextColor = ref('#ffffff')
  8. const navigateBgColor = ref('#0F0820')
  9. const isCompletedInfo = ref<boolean>(true) // 是否提交过的信息
  10. const loginType = ref<string>('choice')
  11. const downloadCatalog = ref<any>(null)
  12. const accountList = ref<any>([])
  13. // const userStore = useUserStore()
  14. const loginedAccountList = computed(() => {
  15. // 获取已经登陆的账号列表的前两位
  16. return accountList.value.filter((item: any) => item.email).slice(0, 2)
  17. })
  18. /**
  19. * 设置头部导航背景色
  20. */
  21. const setNavigateBgColor = (color: string) => {
  22. if (!color)
  23. return
  24. color = color.toUpperCase()
  25. if (color === '#0F0820') {
  26. navigateTextColor.value = '#ffffff'
  27. navigateBgColor.value = 'rgba(15,8,32, 0.7)'
  28. }
  29. else if (color === '#F3F4FB') {
  30. navigateTextColor.value = '#0F0820'
  31. navigateBgColor.value = 'rgba(243,244,251, 0.7)'
  32. }
  33. else if (color === '#FFFFFF') {
  34. navigateTextColor.value = '#0F0820'
  35. navigateBgColor.value = 'rgba(255, 255, 255, 0.7)'
  36. }
  37. }
  38. /**
  39. * 设置已经登陆的账号列表 (在登陆成功后调用)
  40. */
  41. const pushAccount = (user: any) => {
  42. if (!user || !user.email)
  43. return
  44. accountList.value.push(user)
  45. }
  46. /**
  47. * type 登录方式
  48. *
  49. */
  50. const setLoginType = (type: string) => {
  51. if (!type)
  52. return
  53. loginType.value = type
  54. }
  55. /**
  56. * 设置当前的下载的目录数据
  57. */
  58. const setDownloadCatalog = (catalog: any) => {
  59. if (!catalog)
  60. return
  61. downloadCatalog.value = catalog
  62. }
  63. /**
  64. * 记录用户是否提交过信息
  65. */
  66. const setFilledInfo = (filled: boolean) => {
  67. // isCompletedInfo.value = filled
  68. }
  69. return {
  70. navigateTextColor,
  71. navigateBgColor,
  72. downloadCatalog,
  73. isCompletedInfo,
  74. setNavigateBgColor,
  75. setLoginType,
  76. accountList,
  77. loginType,
  78. pushAccount,
  79. setFilledInfo,
  80. loginedAccountList,
  81. setDownloadCatalog,
  82. }
  83. },
  84. {
  85. persist: true,
  86. },
  87. )