settingMenu.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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',book_id)" 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}">{{BookshelfStatusTitle}}</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. const {book_id} = defineProps(['book_id'])
  61. let menu = ref(null)
  62. function change(e){
  63. if(e.show==false){
  64. emit('Close')
  65. }
  66. // console.log('当前模式:' + e.type + ',状态:' + e.show);
  67. }
  68. let type = 'bottom'
  69. onMounted(()=>{
  70. tools.checkBookOnBookshelf(book_id,(is_on)=>{
  71. if(is_on){
  72. BookshelfStatusTitle.value = '已添加书架'
  73. }else{
  74. BookshelfStatusTitle.value = '加入书架'
  75. }
  76. })
  77. // open 方法传入参数 等同在 uni-popup 组件上绑定 type属性
  78. menu.value.open(type)
  79. })
  80. let mode = ref(ReadSetting().data.readMode)
  81. let startPosY = ref(-1)
  82. function maskTouch(e){
  83. if(Math.abs(e.changedTouches[0].pageY-startPosY.value)>10){
  84. startPosY.value = -1
  85. emit('Close')
  86. }
  87. }
  88. function maskStart(e){
  89. startPosY.value = e.changedTouches[0].pageY
  90. }
  91. let showSettingFontSizeMode = ref(false)
  92. function showSettingFont(){
  93. showSettingFontSizeMode.value = true
  94. }
  95. let showFontSize = ref(config.read_config.fontSizeList[ReadSetting().getReadSetting().fontSizeIndex])
  96. let bgColorIndex = ref(ReadSetting().data.colorBgIndex)
  97. let isAutoBuy = ref(ReadSetting().data.autoBuyNextChpater)
  98. watch(
  99. () => ReadSetting().data.fontSizeIndex, // 监听的数据源
  100. (newVal, oldVal) => {
  101. // console.log(`Count changed from ${oldVal} to ${newVal}`);
  102. showFontSize.value = config.read_config.fontSizeList[ReadSetting().data.fontSizeIndex]
  103. // 可以在这里执行一些操作,比如更新其他状态或触发其他函数
  104. }
  105. );
  106. watch(() => ReadSetting().data.autoBuyNextChpater, // 监听的数据源
  107. (newVal, oldVal) => {
  108. isAutoBuy.value = newVal
  109. }
  110. );
  111. watch(() => ReadSetting().data.readMode, // 监听的数据源
  112. (newVal, oldVal) => {
  113. mode.value = ReadSetting().data.readMode
  114. font_color.value = tools.getFontColorByMode(ReadSetting().data.readMode)
  115. db_color.value = tools.getDbColorByMode(ReadSetting().data.readMode)
  116. }
  117. );
  118. let font_color = ref(tools.getFontColorByMode(ReadSetting().data.readMode))
  119. let db_color = ref(tools.getDbColorByMode(ReadSetting().data.readMode))
  120. let BookshelfStatusTitle = ref('加入书架')
  121. function updateBookshelfStatus(){
  122. tools.checkBookOnBookshelf(book_id,(is_on)=>{
  123. if(is_on){
  124. BookshelfStatusTitle.value = '已添加书架'
  125. }else{
  126. BookshelfStatusTitle.value = '加入书架'
  127. }
  128. })
  129. }
  130. defineExpose({showSettingFont,updateBookshelfStatus})
  131. </script>
  132. <style lang="scss" scoped>
  133. .selects-box{
  134. display: flex;
  135. justify-content: space-around;
  136. align-items: center;
  137. height: 80px;
  138. width: 100%;
  139. .item-box {
  140. display: flex;
  141. flex-flow: column;
  142. justify-content: center;
  143. align-items: center;
  144. height: 100%;
  145. }
  146. }
  147. .items-box {
  148. display: flex;
  149. justify-content: space-around;
  150. align-items: center;
  151. height: 80px;
  152. width: 100%;
  153. margin-bottom: 5%;
  154. .item-box {
  155. display: flex;
  156. flex-flow: column;
  157. justify-content: center;
  158. align-items: center;
  159. height: 100%;
  160. }
  161. }
  162. .fontSelect {
  163. display: flex;
  164. justify-content: space-around;
  165. align-items: center;
  166. height: 80px;
  167. width: 100%;
  168. }
  169. </style>