settingMenu.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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="rgba(0,0,0,0)" @change="change">
  4. <view class="mypopup" :style="{'backgroundColor':db_color}">
  5. <view v-if="showSettingFontSizeMode==false" class="selects-box">
  6. <view @click="emit('clickPreChapter')" :style="{'color':font_color}">上一章</view>
  7. <view @click="emit('clickKeep',book_id)" style="align-items: center; display: flex;">
  8. <image :src="BookshelfStatusImg" style="height: 48rpx; margin-right: 10px; width: 213rpx;"></image>
  9. <!-- <view :style="{'color':font_color}">{{BookshelfStatusTitle}}</view> -->
  10. </view>
  11. <view @click="emit('clickNextChapter')" :style="{'color':font_color}">下一章</view>
  12. </view>
  13. <view v-if="showSettingFontSizeMode==true" style="display: flex;justify-content:space-between; align-items: center;padding-left: 5%;padding-right: 5%;margin-top: 5%;">
  14. <view :style="{'color':font_color}">自动购买下一章</view>
  15. <!-- <checkbox-group @change="emit('selectAutoBuy',!isAutoBuy)">
  16. <checkbox :checked="isAutoBuy" value="cb" > </checkbox>
  17. </checkbox-group> -->
  18. <view>
  19. <image @click="onAutoClick()" :src="getAutoImgStyle()" style="height: 50rpx;width: 107rpx;"></image>
  20. </view>
  21. </view>
  22. <view v-if="showSettingFontSizeMode==true" class="fontSelect" >
  23. <!-- <view :style="{'color':font_color}">字号</view> -->
  24. <view @touchstart="emit('changeFontSize',-1)" :style="{'color':font_color}">
  25. <image src="../../static/imgs/read/setting/img_a_jian.png" style="width: 90rpx;height: 90rpx;"></image>
  26. </view>
  27. <view :style="{'color':font_color}">{{showFontSize}}</view>
  28. <view @touchstart="emit('changeFontSize',+1)" :style="{'color':font_color}">
  29. <image src="../../static/imgs/read/setting/img_a_jia.png" style="width: 90rpx;height: 90rpx;"></image>
  30. </view>
  31. </view>
  32. <view v-if="showSettingFontSizeMode==true" style="height: 10rpx;"></view>
  33. <view v-if="showSettingFontSizeMode==true" style="display: flex;justify-content: space-between;padding-left: 5%;padding-right: 5%;" >
  34. <image @touchstart="emit('changeBgColor',0)" :src="tools.getBgResByIndex(0,bgColorIndex)" style="width: 100rpx;height: 100rpx;"></image>
  35. <image @touchstart="emit('changeBgColor',1)" :src="tools.getBgResByIndex(1,bgColorIndex)" style="width: 100rpx;height: 100rpx;"></image>
  36. <image @touchstart="emit('changeBgColor',2)" :src="tools.getBgResByIndex(2,bgColorIndex)" style="width: 100rpx;height: 100rpx;"></image>
  37. <image @touchstart="emit('changeBgColor',3)" :src="tools.getBgResByIndex(3,bgColorIndex)" style="width: 100rpx;height: 100rpx;"></image>
  38. <image @touchstart="emit('changeBgColor',4)" :src="tools.getBgResByIndex(4,bgColorIndex)" style="width: 100rpx;height: 100rpx;"></image>
  39. </view>
  40. <view v-if="showSettingFontSizeMode==true" style="height: 30rpx;" ></view>
  41. <!-- <view v-if="showSettingFontSizeMode==true" style="height: 50rpx;"></view> -->
  42. <view class="popup-content">
  43. <view class="items-box">
  44. <view class="item-box" @click="emit('clickCatalog')" :style="{'color':font_color}">
  45. <image :src="getMLRes()" style="width: 95rpx;height: 95rpx;"></image>
  46. </view>
  47. <!-- <view class="item-box" v-if="mode === config.read_config.readMode.Dark" @click="emit('clickCatalog')" :style="{'color':font_color}">
  48. <image src="../../static/imgs/read/setting/img_setting_ml1.png" style="width: 95rpx;height: 95rpx;"></image>
  49. </view> -->
  50. <view class="item-box" v-if="mode === config.read_config.readMode.Bright" @click="emit('clickMode',config.read_config.readMode.Dark)" :style="{'color':font_color}">
  51. <image src="../../static/imgs/read/setting/img_setting_mode0.png" style="width: 95rpx;height: 95rpx;"></image>
  52. </view>
  53. <view class="item-box" v-if="mode === config.read_config.readMode.Dark" @click="emit('clickMode',config.read_config.readMode.Bright)" :style="{'color':font_color}">
  54. <image src="../../static/imgs/read/setting/img_setting_mode1.png" style="width: 95rpx;height: 95rpx;"></image>
  55. </view>
  56. <view class="item-box" @click="emit('clickOpenSetting')" :style="{'color':font_color}">
  57. <image :src="getSettingRes()" style="width: 95rpx;height: 95rpx;"></image>
  58. </view>
  59. <!-- <view class="item-box" v-if="mode === config.read_config.readMode.Dark" @click="emit('clickOpenSetting')" :style="{'color':font_color}">
  60. <image src="../../static/imgs/read/setting/img_setting_btn1.png" style="width: 95rpx;height: 95rpx;"></image>
  61. </view> -->
  62. </view>
  63. </view>
  64. </view>
  65. </uni-popup>
  66. </view>
  67. </template>
  68. <script setup lang="ts">
  69. import {ref, onMounted,defineProps,defineEmits, watch} from 'vue'
  70. import { config } from '../../config/config';
  71. import { ReadSetting } from '../../stores/readSetting';
  72. import { tools } from '../../framework/tools';
  73. const emit = defineEmits(['clickCatalog','clickPreChapter','clickNextChapter','clickMode','clickOpenSetting','Close','changeFontSize','changeBgColor','selectAutoBuy','clickKeep'])
  74. // const { windowWidth, windowHeight, statusBarHeight, platform, pixelRatio } = uni.getSystemInfoSync();
  75. const {book_id} = defineProps(['book_id'])
  76. let menu = ref(null)
  77. function change(e){
  78. if(e.show==false){
  79. emit('Close')
  80. }
  81. // console.log('当前模式:' + e.type + ',状态:' + e.show);
  82. }
  83. let type = 'bottom'
  84. onMounted(()=>{
  85. tools.checkBookOnBookshelf(book_id,(is_on)=>{
  86. if(is_on){
  87. BookshelfStatusTitle.value = '已添加书架'
  88. BookshelfStatusImg.value = getRemoveBookShelfRes()
  89. }else{
  90. BookshelfStatusTitle.value = '加入书架'
  91. BookshelfStatusImg.value = getAddBookShelfRes()
  92. }
  93. })
  94. // open 方法传入参数 等同在 uni-popup 组件上绑定 type属性
  95. menu.value.open(type)
  96. })
  97. let mode = ref(ReadSetting().data.readMode)
  98. let startPosY = ref(-1)
  99. function maskTouch(e){
  100. if(Math.abs(e.changedTouches[0].pageY-startPosY.value)>10){
  101. startPosY.value = -1
  102. emit('Close')
  103. }
  104. }
  105. function maskStart(e){
  106. startPosY.value = e.changedTouches[0].pageY
  107. }
  108. let showSettingFontSizeMode = ref(false)
  109. function showSettingFont(){
  110. showSettingFontSizeMode.value = true
  111. }
  112. function showSettingOther(){
  113. showSettingFontSizeMode.value = false
  114. }
  115. function getSetttingStatus():boolean{
  116. return showSettingFontSizeMode.value
  117. }
  118. let showFontSize = ref(config.read_config.fontSizeList[ReadSetting().getReadSetting().fontSizeIndex])
  119. let bgColorIndex = ref(ReadSetting().data.colorBgIndex)
  120. let isAutoBuy = ref(ReadSetting().data.autoBuyNextChpater)
  121. watch(
  122. () => ReadSetting().data.fontSizeIndex, // 监听的数据源
  123. (newVal, oldVal) => {
  124. // console.log(`Count changed from ${oldVal} to ${newVal}`);
  125. showFontSize.value = config.read_config.fontSizeList[ReadSetting().data.fontSizeIndex]
  126. // 可以在这里执行一些操作,比如更新其他状态或触发其他函数
  127. }
  128. );
  129. watch(() => ReadSetting().data.colorBgIndex,()=>{
  130. bgColorIndex.value = ReadSetting().data.colorBgIndex
  131. })
  132. watch(() => ReadSetting().data.autoBuyNextChpater, // 监听的数据源
  133. (newVal, oldVal) => {
  134. isAutoBuy.value = newVal
  135. }
  136. );
  137. watch(() => ReadSetting().data.readMode, // 监听的数据源
  138. (newVal, oldVal) => {
  139. mode.value = ReadSetting().data.readMode
  140. font_color.value = tools.getFontColorByMode(ReadSetting().data.readMode)
  141. db_color.value = tools.getDbColorByMode(ReadSetting().data.readMode)
  142. }
  143. );
  144. let font_color = ref(tools.getFontColorByMode(ReadSetting().data.readMode))
  145. let db_color = ref(tools.getDbColorByMode(ReadSetting().data.readMode))
  146. let BookshelfStatusTitle = ref('加入书架')
  147. function updateBookshelfStatus(){
  148. tools.checkBookOnBookshelf(book_id,(is_on)=>{
  149. if(is_on){
  150. BookshelfStatusTitle.value = '已添加书架'
  151. BookshelfStatusImg.value = getRemoveBookShelfRes()
  152. }else{
  153. BookshelfStatusTitle.value = '加入书架'
  154. BookshelfStatusImg.value = getAddBookShelfRes()
  155. }
  156. })
  157. }
  158. function getMLRes(){
  159. if(mode.value == config.read_config.readMode.Dark){
  160. return '../../static/imgs/read/setting/img_setting_ml_dark.png'
  161. }
  162. return '../../static/imgs/read/setting/img_setting_ml0.png'
  163. }
  164. function getDarkModeRes(){
  165. }
  166. function getBrightModeRes(){
  167. }
  168. function getSettingRes(){
  169. if(mode.value == config.read_config.readMode.Dark){
  170. if(showSettingFontSizeMode.value==true){
  171. return '../../static/imgs/read/setting/img_dark_setting_icon.png'
  172. }
  173. return '../../static/imgs/read/setting/img_bright_setting_icon.png'
  174. }
  175. if(showSettingFontSizeMode.value==true){
  176. return '../../static/imgs/read/setting/img_setting_btn1.png'
  177. }
  178. return '../../static/imgs/read/setting/img_setting_btn0.png'
  179. }
  180. function getAutoImgStyle(){
  181. return ReadSetting().getReadSetting().autoBuyNextChpater?'../../static/imgs/read/setting/img_auto_on.png':'../../static/imgs/read/setting/img_auto_off.png'
  182. }
  183. function onAutoClick(){
  184. ReadSetting().changeAutoBuyNextChapter(!ReadSetting().getReadSetting().autoBuyNextChpater)
  185. }
  186. function getAddBookShelfRes(){
  187. if(mode.value == config.read_config.readMode.Dark){
  188. return '../../static/imgs/read/setting/img_dark_add_bookshelf.png'
  189. }
  190. return '../../static/imgs/read/setting/img_add_bookshelf.png'
  191. }
  192. function getRemoveBookShelfRes(){
  193. if(mode.value == config.read_config.readMode.Dark){
  194. return '../../static/imgs/read/setting/img_dark_remove_bookshelf.png'
  195. }
  196. return '../../static/imgs/read/setting/img_remove_bookshelf.png'
  197. }
  198. let BookshelfStatusImg = ref('../../static/imgs/read/setting/img_add_bookshelf.png')
  199. defineExpose({showSettingFont,updateBookshelfStatus,getSetttingStatus,showSettingOther})
  200. </script>
  201. <style lang="scss" scoped>
  202. .selects-box{
  203. display: flex;
  204. justify-content: space-around;
  205. align-items: center;
  206. height: 80px;
  207. width: 100%;
  208. border-bottom: #eee solid 1px;
  209. .item-box {
  210. display: flex;
  211. flex-flow: column;
  212. justify-content: center;
  213. align-items: center;
  214. height: 100%;
  215. }
  216. }
  217. .items-box {
  218. display: flex;
  219. justify-content: space-around;
  220. align-items: center;
  221. height: 80px;
  222. width: 100%;
  223. margin-bottom: 5%;
  224. .item-box {
  225. display: flex;
  226. flex-flow: column;
  227. justify-content: center;
  228. align-items: center;
  229. height: 100%;
  230. }
  231. }
  232. .fontSelect {
  233. display: flex;
  234. justify-content: space-around;
  235. align-items: center;
  236. height: 80px;
  237. width: 100%;
  238. }
  239. .mypopup {
  240. border-top-left-radius: 45rpx;
  241. border-top-right-radius: 45rpx;
  242. position: absolute;
  243. bottom: 0;
  244. width: 100vw;
  245. }
  246. </style>