common.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /** @format */
  2. import { defineStore } from 'pinia'
  3. import { id } from 'element-plus/es/locales.mjs'
  4. import { useUserStore } from './user'
  5. export const useCommonStore = defineStore(
  6. 'commonStore',
  7. () => {
  8. const navigateTextColor = ref('#ffffff')
  9. const navigateBgColor = ref('#0F0820')
  10. const loginType = ref<string>('choice')
  11. const accountList = ref([
  12. {
  13. name: 'EJET Spark 12',
  14. email: '185@163.com',
  15. id: '1',
  16. },
  17. {
  18. name: 'EJET Spark 34',
  19. email: '18525917172@gmail.com',
  20. id: '2',
  21. },
  22. ])
  23. // const userStore = useUserStore()
  24. /**
  25. * 设置头部导航背景色
  26. * @returns
  27. */
  28. const setNavigateBgColor = (color: string) => {
  29. if (!color)
  30. return
  31. color = color.toUpperCase()
  32. if (color === '#0F0820') {
  33. navigateTextColor.value = '#ffffff'
  34. navigateBgColor.value = 'rgba(15,8,32, 0.7)'
  35. }
  36. else if (color === '#F3F4FB') {
  37. navigateTextColor.value = '#0F0820'
  38. navigateBgColor.value = 'rgba(243,244,251, 0.7)'
  39. }
  40. else if (color === '#FFFFFF') {
  41. navigateTextColor.value = '#0F0820'
  42. navigateBgColor.value = 'rgba(255, 255, 255, 0.7)'
  43. }
  44. }
  45. /**
  46. * 设置已经登陆的账号列表 (在登陆成功后调用)
  47. */
  48. const setAccountList = (list: any[]) => {
  49. if (!list || !Array.isArray(list))
  50. return
  51. accountList.value = list
  52. }
  53. const setLoginType = (type: string) => {
  54. if (!type)
  55. return
  56. loginType.value = type
  57. }
  58. return {
  59. navigateTextColor,
  60. navigateBgColor,
  61. setNavigateBgColor,
  62. setLoginType,
  63. accountList,
  64. loginType,
  65. setAccountList,
  66. }
  67. },
  68. {
  69. persist: true,
  70. },
  71. )