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.

127 lines
2.6 KiB

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"
  8. :checked="selectedIndex === 0" @click="selectFont('auto')" />
  9. </view>
  10. <view class="top-list">
  11. <text>新加坡服务器</text>
  12. <radio value="1" class="radio-btn" activeBackgroundColor="red"
  13. :checked="selectedIndex === 1" @click="selectFont('singapore')" />
  14. </view>
  15. <view class="top-list">
  16. <text>香港服务器</text>
  17. <radio value="2" class="radio-btn" activeBackgroundColor="red"
  18. :checked="selectedIndex === 2" @click="selectFont('hongkong')" />
  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 servertypeMap = {
  35. 'auto': 0,
  36. 'singapore': 1,
  37. 'hongkong': 2
  38. }
  39. const getServer = async () => {
  40. try {
  41. const res = await getSetting()
  42. if (res.code === 200) {
  43. const serverSelection = res.data.serverSelection
  44. selectedIndex.value = servertypeMap[serverSelection] ?? 0;
  45. }
  46. } catch (err) {
  47. console.error("获取服务器设置失败:", err);
  48. }
  49. }
  50. const selectFont = async (servertype) => {
  51. try {
  52. selectedIndex.value = servertypeMap[servertype]
  53. console.log('服务器类型:', servertype, ',looklook索引:', selectedIndex.value)
  54. const updateRes = await updateSetting({
  55. serverSelection: servertype
  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. getServer()
  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. justify-content: center;
  90. margin: 0 40rpx;
  91. padding: 0 10rpx;
  92. border-bottom: 1rpx solid #eee;
  93. }
  94. .top-list:last-child {
  95. border-bottom: none;
  96. }
  97. .switch-btn {
  98. width: 100rpx;
  99. transform: scale(0.6);
  100. transform-origin: center right;
  101. }
  102. .public {
  103. width: 450rpx;
  104. margin-left: auto;
  105. font-size: 10px;
  106. color: rgb(203, 203, 203);
  107. }
  108. .arrow {
  109. margin-left: auto;
  110. }
  111. .radio-btn {
  112. margin-left: auto;
  113. transform: scale(0.6);
  114. }
  115. </style>