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.

84 lines
1.8 KiB

  1. <template>
  2. <view class="main">
  3. <view :style="{height:iSMT+'px'}"></view>
  4. <view class="theme">
  5. <view class="left">
  6. <image class="img-theme" src="/static/my/whiteTheme.png" mode="widthFix" />
  7. <radio value="0" class="radio-btn" activeBackgroundColor="red" :checked="selectedIndex === 0"
  8. @click="selectFont(0)" />
  9. </view>
  10. <view class="left">
  11. <image class="img-theme" src="/static/my/blackTheme.png" mode="widthFix" />
  12. <radio value="1" class="radio-btn" activeBackgroundColor="red" :checked="selectedIndex === 1"
  13. @click="selectFont(1)" />
  14. </view>
  15. </view>
  16. </view>
  17. </template>
  18. <script setup>
  19. import {
  20. ref,
  21. onMounted
  22. } from 'vue'
  23. import {
  24. getSetting
  25. } from "@/api/setting/general"
  26. const iSMT = ref(0)
  27. const selectedIndex = ref(0)
  28. const getTheme = async () => {
  29. try {
  30. const res = await getSetting()
  31. if (res.code === 200) {
  32. const theme = res.data.theme
  33. const sizeMap = {
  34. 'light': 0,
  35. 'dark': 1
  36. }
  37. console.log('看看主题', res.data.theme)
  38. selectedIndex.value = sizeMap[theme] ?? 0;
  39. }
  40. } catch (err) {
  41. console.error("获取主题设置失败:", err);
  42. }
  43. }
  44. const selectFont = (index) => {
  45. selectedIndex.value = index
  46. console.log('看看选中状态', selectedIndex.value)
  47. }
  48. onMounted(() => {
  49. // 状态栏高度
  50. iSMT.value = uni.getSystemInfoSync().statusBarHeight;
  51. console.log('看看高度', iSMT.value)
  52. getTheme()
  53. })
  54. </script>
  55. <style>
  56. .theme {
  57. margin-top: 1.5vh;
  58. height: 34vh;
  59. background-color: white;
  60. display: flex;
  61. justify-content: space-around;
  62. }
  63. .img-theme {
  64. width: 316rpx;
  65. height: 362rpx;
  66. }
  67. .left {
  68. width: 350rpx;
  69. display: flex;
  70. flex-direction: column;
  71. justify-content: center;
  72. align-items: center;
  73. }
  74. .radio-btn {
  75. margin-top: 36rpx;
  76. transform: scale(0.8);
  77. }
  78. </style>