reader-settings.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <template>
  2. <view class="settings-panel" v-if="show">
  3. <view class="settings-header">
  4. <text>设置</text>
  5. <text class="close-btn" @tap="onClose">×</text>
  6. </view>
  7. <view class="settings-section">
  8. <text class="section-title">页面颜色</text>
  9. <view class="color-options">
  10. <view v-for="(color, index) in bgColors" :key="index" class="color-option"
  11. :class="{ active: themeIndex === index }" :style="{ backgroundColor: color.bg }"
  12. @tap="onThemeChange(index)"></view>
  13. </view>
  14. </view>
  15. <view class="settings-section">
  16. <text class="section-title">文字</text>
  17. <view class="slider-container">
  18. <slider class="custom-slider" :value="fontSize" activeColor="#cbbfa7" block-color="#988153"
  19. background-color="#f8f8f8" :min="12" :max="30" :step="1" show-value @change="onFontSizeChange"
  20. @changing="onFontSizeChanging" />
  21. </view>
  22. </view>
  23. <view class="settings-section">
  24. <text class="section-title">边距</text>
  25. <view class="slider-container">
  26. <slider class="custom-slider" :value="margin" activeColor="#cbbfa7" block-color="#988153"
  27. background-color="#f8f8f8" :min="10" :max="50" :step="5" show-value @change="onMarginChange"
  28. @changing="onMarginChanging" />
  29. </view>
  30. </view>
  31. <view class="settings-section">
  32. <text class="section-title">行距</text>
  33. <view class="slider-container">
  34. <slider class="custom-slider" :value="lineHeight" activeColor="#cbbfa7" block-color="#988153"
  35. background-color="#f8f8f8" :min="1" :max="3" :step="0.1" show-value @change="onLineHeightChange"
  36. @changing="onLineHeightChanging" />
  37. </view>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. export default {
  43. name: 'ReaderSettings',
  44. props: {
  45. show: {
  46. type: Boolean,
  47. default: false
  48. },
  49. themeIndex: {
  50. type: Number,
  51. default: 0
  52. },
  53. fontSize: {
  54. type: Number,
  55. default: 18
  56. },
  57. margin: {
  58. type: Number,
  59. default: 20
  60. },
  61. lineHeight: {
  62. type: Number,
  63. default: 1.8
  64. },
  65. bgColors: {
  66. type: Array,
  67. default: () => [{
  68. bg: '#f8f4e9',
  69. text: '#3e3d3b'
  70. }, // 米黄色
  71. {
  72. bg: '#ffffff',
  73. text: '#333333'
  74. }, // 白色
  75. {
  76. bg: '#e9e9e9',
  77. text: '#333333'
  78. }, // 浅灰色
  79. {
  80. bg: '#cce8cf',
  81. text: '#333333'
  82. }, // 浅绿色
  83. {
  84. bg: '#333333',
  85. text: '#c4c4c4'
  86. }, // 夜间模式
  87. ]
  88. }
  89. },
  90. methods: {
  91. onClose() {
  92. this.$emit('close')
  93. },
  94. onThemeChange(index) {
  95. // 添加触感反馈
  96. uni.vibrateShort({
  97. success: () => {
  98. this.$emit('theme-change', index)
  99. }
  100. });
  101. },
  102. onFontSizeChange(e) {
  103. this.$emit('font-size-change', e.detail.value)
  104. },
  105. onMarginChange(e) {
  106. this.$emit('margin-change', e.detail.value)
  107. },
  108. onLineHeightChange(e) {
  109. this.$emit('line-height-change', e.detail.value)
  110. },
  111. onFontSizeChanging(e) {
  112. this.$emit('font-size-change', Number(e.detail.value))
  113. },
  114. onMarginChanging(e) {
  115. this.$emit('margin-change', Number(e.detail.value))
  116. },
  117. onLineHeightChanging(e) {
  118. this.$emit('line-height-change', Number(e.detail.value))
  119. }
  120. }
  121. }
  122. </script>
  123. <style scoped>
  124. .settings-panel {
  125. position: fixed;
  126. bottom: 0;
  127. left: 0;
  128. right: 0;
  129. background-color: #fff;
  130. border-top-left-radius: 30rpx;
  131. border-top-right-radius: 30rpx;
  132. padding: 30rpx;
  133. z-index: 200;
  134. /* box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1); */
  135. }
  136. .settings-header {
  137. display: flex;
  138. justify-content: space-between;
  139. align-items: center;
  140. margin-bottom: 30rpx;
  141. font-size: 32rpx;
  142. font-weight: bold;
  143. }
  144. .close-btn {
  145. font-size: 40rpx;
  146. padding: 0 20rpx;
  147. }
  148. .settings-section {
  149. display: flex;
  150. align-items: center;
  151. margin-bottom: 30rpx;
  152. }
  153. .section-title {
  154. width: 120rpx;
  155. flex: none;
  156. font-size: 28rpx;
  157. margin-right: 20rpx;
  158. margin-bottom: 20rpx;
  159. color: #666;
  160. }
  161. .color-options {
  162. width: 100%;
  163. display: flex;
  164. justify-content: space-between;
  165. margin-bottom: 20rpx;
  166. }
  167. .color-option {
  168. width: 70rpx;
  169. height: 70rpx;
  170. border-radius: 50%;
  171. border: 2rpx solid #ddd;
  172. transition: all 0.3s ease;
  173. cursor: pointer;
  174. }
  175. .color-option.active {
  176. border: 4rpx solid #988153;
  177. transform: scale(1.1);
  178. }
  179. .slider-container {
  180. width: 100%;
  181. display: flex;
  182. align-items: center;
  183. }
  184. .slider-label {
  185. width: 60rpx;
  186. text-align: center;
  187. font-size: 28rpx;
  188. color: #666;
  189. }
  190. ::v-deep uni-slider {
  191. margin: 0px;
  192. }
  193. .custom-slider {
  194. width: 100%;
  195. }
  196. ::v-deep uni-slider .uni-slider-handle-wrapper {
  197. height: 30rpx;
  198. border-radius: 40rpx;
  199. }
  200. ::v-deep uni-slider .uni-slider-track {
  201. border-radius: 40rpx;
  202. }
  203. </style>