settingMenu.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <view>
  3. <uni-popup @touchstart="maskStart" @touchmove="maskTouch" :animation="false" mask-background-color="rgba(0,0,0,0)" ref="menu" :background-color="db_color" @change="change">
  4. <view v-if="showSettingFontSizeMode==false" class="selects-box">
  5. <view @click="emit('clickPreChapter')" :style="{'color':font_color}">上一章</view>
  6. <view @click="emit('clickKeep')" style="align-items: center; display: flex;">
  7. <image src="../../static/logo.png" style="width: 40rpx;height: 40rpx; margin-right: 10px;"></image>
  8. <view :style="{'color':font_color}">加入书架</view>
  9. </view>
  10. <view @click="emit('clickNextChapter')" :style="{'color':font_color}">下一章</view>
  11. </view>
  12. <view v-if="showSettingFontSizeMode==false" class="popup-content">
  13. <view class="items-box">
  14. <view class="item-box" @click="emit('clickCatalog')" :style="{'color':font_color}">
  15. 目录
  16. </view>
  17. <view class="item-box" v-if="mode === config.read_config.readMode.Bright" @click="emit('clickMode',config.read_config.readMode.Dark)" :style="{'color':font_color}">
  18. 夜间
  19. </view>
  20. <view class="item-box" v-if="mode === config.read_config.readMode.Dark" @click="emit('clickMode',config.read_config.readMode.Bright)" :style="{'color':font_color}">
  21. 日间
  22. </view>
  23. <view class="item-box" @click="emit('clickOpenSetting')" :style="{'color':font_color}">
  24. 设置
  25. </view>
  26. </view>
  27. </view>
  28. <view v-if="showSettingFontSizeMode==true" class="fontSelect" >
  29. <view :style="{'color':font_color}">字号</view>
  30. <view @touchstart="emit('changeFontSize',-1)" :style="{'color':font_color}">小</view>
  31. <view :style="{'color':font_color}">{{showFontSize}}</view>
  32. <view @touchstart="emit('changeFontSize',+1)" :style="{'color':font_color}">大</view>
  33. </view>
  34. <view v-if="showSettingFontSizeMode==true" style="height: 10rpx;"></view>
  35. <view v-if="showSettingFontSizeMode==true" style="display: flex;justify-content: space-between;" >
  36. <view style="margin-left: 50rpx;" :style="{'color':font_color}">颜色</view>
  37. <image @touchstart="emit('changeBgColor',0)" src="../../static/logo.png" style="width: 50rpx;height: 50rpx;"></image>
  38. <image @touchstart="emit('changeBgColor',1)" src="../../static/logo.png" style="width: 50rpx;height: 50rpx;"></image>
  39. <image @touchstart="emit('changeBgColor',2)" src="../../static/logo.png" style="width: 50rpx;height: 50rpx;"></image>
  40. <image @touchstart="emit('changeBgColor',3)" src="../../static/logo.png" style="width: 50rpx;height: 50rpx;"></image>
  41. <image @touchstart="emit('changeBgColor',4)" src="../../static/logo.png" style="width: 50rpx;height: 50rpx; margin-right: 50rpx;"></image>
  42. </view>
  43. <view v-if="showSettingFontSizeMode==true" style="height: 30rpx;" ></view>
  44. <view v-if="showSettingFontSizeMode==true" style="display: flex;justify-content: center; align-items: center; ">
  45. <checkbox-group @change="emit('selectAutoBuy',!isAutoBuy)">
  46. <checkbox :checked="isAutoBuy" value="cb" :style="{'color':font_color}"> 自动购买下一章 </checkbox>
  47. </checkbox-group>
  48. </view>
  49. <view v-if="showSettingFontSizeMode==true" style="height: 50rpx;"></view>
  50. </uni-popup>
  51. </view>
  52. </template>
  53. <script setup lang="ts">
  54. import {ref, onMounted,defineProps,defineEmits, watch} from 'vue'
  55. import { config } from '../../config/config';
  56. import { ReadSetting } from '../../stores/readSetting';
  57. import { tools } from '../../framework/tools';
  58. const emit = defineEmits(['clickCatalog','clickPreChapter','clickNextChapter','clickMode','clickOpenSetting','Close','changeFontSize','changeBgColor','selectAutoBuy','clickKeep'])
  59. // const { windowWidth, windowHeight, statusBarHeight, platform, pixelRatio } = uni.getSystemInfoSync();
  60. let menu = ref(null)
  61. function change(e){
  62. if(e.show==false){
  63. emit('Close')
  64. }
  65. // console.log('当前模式:' + e.type + ',状态:' + e.show);
  66. }
  67. let type = 'bottom'
  68. onMounted(()=>{
  69. // open 方法传入参数 等同在 uni-popup 组件上绑定 type属性
  70. menu.value.open(type)
  71. })
  72. let mode = ref(ReadSetting().getReadSetting().readMode)
  73. let startPosY = ref(-1)
  74. function maskTouch(e){
  75. if(Math.abs(e.changedTouches[0].pageY-startPosY.value)>10){
  76. startPosY.value = -1
  77. emit('Close')
  78. }
  79. }
  80. function maskStart(e){
  81. startPosY.value = e.changedTouches[0].pageY
  82. }
  83. let showSettingFontSizeMode = ref(false)
  84. function showSettingFont(){
  85. showSettingFontSizeMode.value = true
  86. }
  87. let showFontSize = ref(config.read_config.fontSizeList[ReadSetting().getReadSetting().fontSizeIndex])
  88. let bgColorIndex = ref(ReadSetting().getReadSetting().colorBgIndex)
  89. let isAutoBuy = ref(ReadSetting().getReadSetting().autoBuyNextChpater)
  90. watch(
  91. () => ReadSetting().data.fontSizeIndex, // 监听的数据源
  92. (newVal, oldVal) => {
  93. // console.log(`Count changed from ${oldVal} to ${newVal}`);
  94. showFontSize.value = config.read_config.fontSizeList[ReadSetting().getReadSetting().fontSizeIndex]
  95. // 可以在这里执行一些操作,比如更新其他状态或触发其他函数
  96. }
  97. );
  98. watch(() => ReadSetting().data.autoBuyNextChpater, // 监听的数据源
  99. (newVal, oldVal) => {
  100. isAutoBuy.value = newVal
  101. }
  102. );
  103. watch(() => ReadSetting().data.readMode, // 监听的数据源
  104. (newVal, oldVal) => {
  105. mode.value = ReadSetting().data.readMode
  106. font_color.value = tools.getFontColorByMode(ReadSetting().data.readMode)
  107. db_color.value = tools.getDbColorByMode(ReadSetting().data.readMode)
  108. }
  109. );
  110. let font_color = ref(tools.getFontColorByMode(ReadSetting().data.readMode))
  111. let db_color = ref(tools.getDbColorByMode(ReadSetting().data.readMode))
  112. defineExpose({showSettingFont})
  113. </script>
  114. <style lang="scss" scoped>
  115. .selects-box{
  116. display: flex;
  117. justify-content: space-around;
  118. align-items: center;
  119. height: 80px;
  120. width: 100%;
  121. .item-box {
  122. display: flex;
  123. flex-flow: column;
  124. justify-content: center;
  125. align-items: center;
  126. height: 100%;
  127. }
  128. }
  129. .items-box {
  130. display: flex;
  131. justify-content: space-around;
  132. align-items: center;
  133. height: 80px;
  134. width: 100%;
  135. margin-bottom: 5%;
  136. .item-box {
  137. display: flex;
  138. flex-flow: column;
  139. justify-content: center;
  140. align-items: center;
  141. height: 100%;
  142. }
  143. }
  144. .fontSelect {
  145. display: flex;
  146. justify-content: space-around;
  147. align-items: center;
  148. height: 80px;
  149. width: 100%;
  150. }
  151. </style>