├── php-api/ # 改造后的PHP接口层 ├── java-ad-service/ # 若依框架微服务(广告+VIP+分账) ├── uniapp-reader/ # UniApp前端项目 │ ├── pages/ # 各端页面 │ └──
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

theme.js 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import { defineStore } from 'pinia'
  2. import { ref, computed } from 'vue'
  3. export const useThemeStore = defineStore('theme', () => {
  4. // 可用主题列表
  5. const themes = ref({
  6. default: {
  7. '--primary-color': '#1890ff',
  8. '--bg-color': '#f8f9fa',
  9. '--text-color': '#333',
  10. '--card-bg': '#ffffff'
  11. },
  12. aydzBlue: {
  13. '--primary-color': '#2a5caa',
  14. '--bg-color': '#e6f7ff',
  15. '--text-color': '#1a3353',
  16. '--card-bg': '#d0e8ff'
  17. },
  18. darkMode: {
  19. '--primary-color': '#52c41a',
  20. '--bg-color': '#1a1a1a',
  21. '--text-color': '#e6e6e6',
  22. '--card-bg': '#2a2a2a'
  23. }
  24. })
  25. // 当前主题
  26. const currentTheme = ref('aydzBlue')
  27. // 初始化主题
  28. const initTheme = () => {
  29. const savedTheme = uni.getStorageSync('selectedTheme') || 'aydzBlue'
  30. setTheme(savedTheme)
  31. }
  32. // 设置主题
  33. const setTheme = (themeName) => {
  34. if (!themes.value[themeName]) return
  35. currentTheme.value = themeName
  36. uni.setStorageSync('selectedTheme', themeName)
  37. // 应用CSS变量
  38. const root = document.documentElement
  39. const themeVars = themes.value[themeName]
  40. Object.keys(themeVars).forEach(key => {
  41. root.style.setProperty(key, themeVars[key])
  42. })
  43. // 动态设置导航栏颜色
  44. if (themeName === 'darkMode') {
  45. uni.setNavigationBarColor({
  46. frontColor: '#ffffff',
  47. backgroundColor: '#1a1a1a'
  48. })
  49. } else if (themeName === 'aydzBlue') {
  50. uni.setNavigationBarColor({
  51. frontColor: '#ffffff',
  52. backgroundColor: '#2a5caa'
  53. })
  54. } else {
  55. uni.setNavigationBarColor({
  56. frontColor: '#000000',
  57. backgroundColor: '#f8f9fa'
  58. })
  59. }
  60. }
  61. // 主题配置(用于UI显示)
  62. const themeOptions = computed(() => {
  63. return Object.keys(themes.value).map(key => ({
  64. name: key,
  65. label: getThemeLabel(key),
  66. colors: themes.value[key]
  67. }))
  68. })
  69. // 获取主题显示名称
  70. const getThemeLabel = (themeKey) => {
  71. const labels = {
  72. default: '默认主题',
  73. aydzBlue: '哎呀科技蓝',
  74. darkMode: '深色模式'
  75. }
  76. return labels[themeKey] || themeKey
  77. }
  78. return {
  79. themes,
  80. currentTheme,
  81. themeOptions,
  82. initTheme,
  83. setTheme,
  84. getThemeLabel
  85. }
  86. })