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.

107 lines
2.3 KiB

4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
  1. <template>
  2. <view class="main">
  3. <view :style="{height:iSMT+'px'}"></view>
  4. <view class="top">
  5. <view class="top-list">
  6. <text>标准</text>
  7. <radio value="0" class="radio-btn" activeBackgroundColor="red" :checked="selectedIndex === 0"
  8. @click="selectFont('small')" />
  9. </view>
  10. <view class="top-list">
  11. <text>中号</text>
  12. <radio value="1" class="radio-btn" activeBackgroundColor="red" :checked="selectedIndex === 1"
  13. @click="selectFont('medium')" />
  14. </view>
  15. <view class="top-list">
  16. <text>大号</text>
  17. <radio value="2" class="radio-btn" activeBackgroundColor="red" :checked="selectedIndex === 2"
  18. @click="selectFont('large')" />
  19. </view>
  20. </view>
  21. </view>
  22. </template>
  23. <script setup>
  24. import {
  25. ref,
  26. onMounted
  27. } from 'vue'
  28. import {
  29. getSetting,
  30. updateSetting
  31. } from "@/api/setting/general"
  32. const iSMT = ref(0)
  33. const selectedIndex = ref(0)
  34. const fontTypeMap = {
  35. 'small': 0,
  36. 'medium': 1,
  37. 'large': 2
  38. }
  39. const getFont = async () => {
  40. try {
  41. const res = await getSetting()
  42. if (res.code === 200) {
  43. const fontSize = res.data.fontSize
  44. selectedIndex.value = fontTypeMap[fontSize] ?? 0
  45. }
  46. } catch (err) {
  47. console.error("获取字体设置失败:", err)
  48. }
  49. }
  50. const selectFont = async (fontType) => {
  51. try {
  52. selectedIndex.value = fontTypeMap[fontType]
  53. console.log('字体类型:', fontType, ',looklook索引:', selectedIndex.value)
  54. const updateRes = await updateSetting({
  55. fontSize: fontType
  56. })
  57. if (updateRes.code === 200) {
  58. uni.showToast({
  59. title: '字体大小设置成功',
  60. icon: 'none'
  61. })
  62. }
  63. } catch (err) {
  64. console.error("更新字体设置失败:", err)
  65. uni.showToast({
  66. title: '设置失败,请重试',
  67. icon: 'none'
  68. })
  69. }
  70. }
  71. onMounted(() => {
  72. // 状态栏高度
  73. iSMT.value = uni.getSystemInfoSync().statusBarHeight;
  74. console.log('看看高度', iSMT.value)
  75. getFont()
  76. })
  77. </script>
  78. <style>
  79. .top {
  80. margin-top: 1.5vh;
  81. height: 21vh;
  82. background-color: white;
  83. }
  84. .top-list {
  85. width: 630rpx;
  86. height: 7vh;
  87. display: flex;
  88. align-items: center;
  89. margin: 0 40rpx;
  90. padding: 0 10rpx;
  91. border-bottom: 1rpx solid #eee;
  92. }
  93. .top-list:last-child {
  94. border-bottom: none;
  95. }
  96. .radio-btn {
  97. margin-left: auto;
  98. transform: scale(0.6);
  99. }
  100. </style>