ReadSettings.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. <template>
  2. <div
  3. class="settings-wrapper"
  4. :style="popupTheme"
  5. :class="{ night: isNight, day: !isNight }"
  6. >
  7. <div class="settings-title">设置</div>
  8. <div class="setting-list">
  9. <ul>
  10. <li class="theme-list">
  11. <i>阅读主题</i>
  12. <span
  13. class="theme-item"
  14. v-for="(themeColor, index) in themeColors"
  15. :key="index"
  16. :style="themeColor"
  17. ref="themes"
  18. @click="setTheme(index)"
  19. :class="{ selected: theme == index }"
  20. ><em v-if="index < 6" class="iconfont">&#58980;</em
  21. ><em v-else class="moon-icon">{{ moonIcon }}</em></span
  22. >
  23. </li>
  24. <li class="font-list">
  25. <i>正文字体</i>
  26. <span
  27. class="font-item"
  28. v-for="(font, index) in fonts"
  29. :key="index"
  30. :class="{ selected: selectedFont == index }"
  31. @click="setFont(index)"
  32. >{{ font }}</span
  33. >
  34. </li>
  35. <li class="font-list">
  36. <i>自定字体</i>
  37. <el-tooltip effect="dark" content="自定义的字体名称" placement="top">
  38. <input
  39. type="text"
  40. class="font-item font-item-input"
  41. v-model="customFontName"
  42. placeholder="请输入自定义的字体名称"
  43. />
  44. </el-tooltip>
  45. <el-popover
  46. placement="top"
  47. width="270"
  48. trigger="click"
  49. v-model:visible="customFontSavePopVisible"
  50. >
  51. <p>
  52. 已经安装在您的设备上的字体请确认输入的字体名称完整无误,或者从网络下载字体。
  53. </p>
  54. <div style="text-align: right; margin: 0">
  55. <el-button
  56. size="small"
  57. plain
  58. @click="customFontSavePopVisible = false"
  59. >取消</el-button
  60. >
  61. <el-button
  62. type="primary"
  63. size="small"
  64. @click="setCustomFont(), (customFontSavePopVisible = false)"
  65. >确定</el-button
  66. >
  67. <el-button type="primary" size="small" @click="loadFontFromURL()"
  68. >网络下载</el-button
  69. >
  70. </div>
  71. <template #reference>
  72. <span type="text" class="font-item">保存</span>
  73. </template>
  74. </el-popover>
  75. </li>
  76. <li class="font-size">
  77. <i>字体大小</i>
  78. <div class="resize">
  79. <span class="less" @click="lessFontSize"
  80. ><em class="iconfont">&#58966;</em></span
  81. ><b></b> <span class="lang">{{ fontSize }}</span
  82. ><b></b>
  83. <span class="more" @click="moreFontSize"
  84. ><em class="iconfont">&#58976;</em></span
  85. >
  86. </div>
  87. </li>
  88. <li class="letter-spacing">
  89. <i>字距</i>
  90. <div class="resize">
  91. <span class="less" @click="lessLetterSpacing"
  92. ><em class="iconfont">&#58966;</em></span
  93. ><b></b> <span class="lang">{{ spacing.letter.toFixed(2) }}</span
  94. ><b></b>
  95. <span class="more" @click="moreLetterSpacing"
  96. ><em class="iconfont">&#58976;</em></span
  97. >
  98. </div>
  99. </li>
  100. <li class="line-spacing">
  101. <i>行距</i>
  102. <div class="resize">
  103. <span class="less" @click="lessLineSpacing"
  104. ><em class="iconfont">&#58966;</em></span
  105. ><b></b> <span class="lang">{{ spacing.line.toFixed(1) }}</span
  106. ><b></b>
  107. <span class="more" @click="moreLineSpacing"
  108. ><em class="iconfont">&#58976;</em></span
  109. >
  110. </div>
  111. </li>
  112. <li class="paragraph-spacing">
  113. <i>段距</i>
  114. <div class="resize">
  115. <div class="resize">
  116. <span class="less" @click="lessParagraphSpacing"
  117. ><em class="iconfont">&#58966;</em></span
  118. ><b></b>
  119. <span class="lang">{{ spacing.paragraph.toFixed(1) }}</span
  120. ><b></b>
  121. <span class="more" @click="moreParagraphSpacing"
  122. ><em class="iconfont">&#58976;</em></span
  123. >
  124. </div>
  125. </div>
  126. </li>
  127. <li class="read-width" v-if="!store.miniInterface">
  128. <i>页面宽度</i>
  129. <div class="resize">
  130. <span class="less" @click="lessReadWidth"
  131. ><em class="iconfont">&#58965;</em></span
  132. ><b></b> <span class="lang">{{ readWidth }}</span
  133. ><b></b>
  134. <span class="more" @click="moreReadWidth"
  135. ><em class="iconfont">&#58975;</em></span
  136. >
  137. </div>
  138. </li>
  139. <li class="paragraph-spacing">
  140. <i>翻页速度</i>
  141. <div class="resize">
  142. <div class="resize">
  143. <span class="less" @click="lessJumpDuration">
  144. <em class="iconfont">&#xe625;</em>
  145. </span>
  146. <b></b> <span class="lang">{{ jumpDuration }}</span
  147. ><b></b>
  148. <span class="more" @click="moreJumpDuration"
  149. ><em class="iconfont">&#xe626;</em></span
  150. >
  151. </div>
  152. </div>
  153. </li>
  154. <li class="infinite-loading">
  155. <i>无限加载</i>
  156. <span
  157. class="infinite-loading-item"
  158. :key="0"
  159. :class="{ selected: infiniteLoading == false }"
  160. @click="setInfiniteLoading(false)"
  161. >关闭</span
  162. >
  163. <span
  164. class="infinite-loading-item"
  165. :key="1"
  166. :class="{ selected: infiniteLoading == true }"
  167. @click="setInfiniteLoading(true)"
  168. >开启</span
  169. >
  170. </li>
  171. </ul>
  172. </div>
  173. </div>
  174. </template>
  175. <script setup lang="ts">
  176. import '../assets/fonts/popfont.css'
  177. import '../assets/fonts/iconfont.css'
  178. import settings from '../config/themeConfig'
  179. import API from '@api'
  180. import { useDebounceFn } from '@vueuse/shared'
  181. const store = useBookStore()
  182. const saveConfigDebounce = useDebounceFn(
  183. () => API.saveReadConfig(store.config),
  184. 500,
  185. )
  186. //阅读界面设置改变时保存同步配置
  187. watch(
  188. () => store.config,
  189. () => {
  190. saveConfigDebounce()
  191. },
  192. {
  193. deep: 2, //深度为2
  194. },
  195. )
  196. //主题颜色
  197. const theme = computed(() => store.theme)
  198. const isNight = computed(() => store.isNight)
  199. const moonIcon = computed(() => (theme.value == 6 ? '' : ''))
  200. const themeColors = [
  201. {
  202. background: 'rgba(250, 245, 235, 0.8)',
  203. },
  204. {
  205. background: 'rgba(245, 234, 204, 0.8)',
  206. },
  207. {
  208. background: 'rgba(230, 242, 230, 0.8)',
  209. },
  210. {
  211. background: 'rgba(228, 241, 245, 0.8)',
  212. },
  213. {
  214. background: 'rgba(245, 228, 228, 0.8)',
  215. },
  216. {
  217. background: 'rgba(224, 224, 224, 0.8)',
  218. },
  219. {
  220. background: 'rgba(0, 0, 0, 0.5)',
  221. },
  222. ]
  223. const popupTheme = computed(() => {
  224. return {
  225. background: settings.themes[theme.value].popup,
  226. }
  227. })
  228. const setTheme = (theme: number) => {
  229. store.config.theme = theme
  230. }
  231. //预置字体
  232. const fonts = ref(['雅黑', '宋体', '楷书'])
  233. const setFont = (font: number) => {
  234. store.config.font = font
  235. }
  236. const selectedFont = computed(() => {
  237. return store.config.font
  238. })
  239. //自定义字体
  240. const customFontName = ref(store.config.customFontName)
  241. const customFontSavePopVisible = ref(false)
  242. const setCustomFont = () => {
  243. customFontSavePopVisible.value = false
  244. store.config.font = -1
  245. store.config.customFontName = customFontName.value
  246. }
  247. // 加载网络字体
  248. const loadFontFromURL = () => {
  249. customFontSavePopVisible.value = false
  250. ElMessageBox.prompt('请输入 字体网络链接', '提示', {
  251. confirmButtonText: '确定',
  252. cancelButtonText: '取消',
  253. inputPattern: /^https?:.+$/,
  254. inputErrorMessage: 'url 形式不正确',
  255. beforeClose: (action, instance, done) => {
  256. if (action === 'confirm') {
  257. instance.confirmButtonLoading = true
  258. instance.confirmButtonText = '下载中……'
  259. // instance.inputValue
  260. const url = instance.inputValue
  261. if (typeof FontFace !== 'function') {
  262. ElMessage.error('浏览器不支持FontFace')
  263. return done()
  264. }
  265. const fontface = new FontFace(customFontName.value, `url("${url}")`)
  266. document.fonts.add(fontface)
  267. fontface
  268. .load()
  269. //API.getBookShelf()
  270. .then(function () {
  271. instance.confirmButtonLoading = false
  272. ElMessage.info('字体加载成功!')
  273. setCustomFont()
  274. done()
  275. })
  276. .catch(function (error) {
  277. instance.confirmButtonLoading = false
  278. instance.confirmButtonText = '确定'
  279. ElMessage.error('下载失败,请检查您输入的 url')
  280. throw error
  281. })
  282. } else {
  283. done()
  284. }
  285. },
  286. })
  287. }
  288. //字体大小
  289. const fontSize = computed(() => {
  290. return store.config.fontSize
  291. })
  292. const moreFontSize = () => {
  293. if (store.config.fontSize < 48) store.config.fontSize += 2
  294. }
  295. const lessFontSize = () => {
  296. if (store.config.fontSize > 12) store.config.fontSize -= 2
  297. }
  298. //字 行 段落间距
  299. const spacing = computed(() => {
  300. return store.config.spacing
  301. })
  302. const lessLetterSpacing = () => {
  303. store.config.spacing.letter -= 0.01
  304. }
  305. const moreLetterSpacing = () => {
  306. store.config.spacing.letter += 0.01
  307. }
  308. const lessLineSpacing = () => {
  309. store.config.spacing.line -= 0.1
  310. }
  311. const moreLineSpacing = () => {
  312. store.config.spacing.line += 0.1
  313. }
  314. const lessParagraphSpacing = () => {
  315. store.config.spacing.paragraph -= 0.1
  316. }
  317. const moreParagraphSpacing = () => {
  318. store.config.spacing.paragraph += 0.1
  319. }
  320. //页面宽度
  321. const readWidth = computed(() => {
  322. return store.config.readWidth
  323. })
  324. const moreReadWidth = () => {
  325. // 此时会截断页面
  326. if (store.config.readWidth + 160 + 2 * 68 > window.innerWidth) return
  327. store.config.readWidth += 160
  328. }
  329. const lessReadWidth = () => {
  330. if (store.config.readWidth > 640) store.config.readWidth -= 160
  331. }
  332. //翻页速度
  333. const jumpDuration = computed(() => {
  334. return store.config.jumpDuration
  335. })
  336. const moreJumpDuration = () => {
  337. store.config.jumpDuration += 100
  338. }
  339. const lessJumpDuration = () => {
  340. if (store.config.jumpDuration === 0) return
  341. store.config.jumpDuration -= 100
  342. }
  343. //无限加载
  344. const infiniteLoading = computed(() => {
  345. return store.config.infiniteLoading
  346. })
  347. const setInfiniteLoading = (loading: boolean) => {
  348. store.config.infiniteLoading = loading
  349. }
  350. </script>
  351. <style scoped>
  352. :deep(.iconfont) {
  353. font-family: iconfont;
  354. font-style: normal;
  355. }
  356. :deep(.moon-icon) {
  357. font-family: iconfont;
  358. font-style: normal;
  359. }
  360. .settings-wrapper {
  361. user-select: none;
  362. margin: -13px;
  363. /* width: 478px;
  364. height: 350px; */
  365. text-align: left;
  366. padding: 40px 0 40px 24px;
  367. background: #ede7da url('../assets/imgs/themes/popup_1.png') repeat;
  368. .settings-title {
  369. font-size: 18px;
  370. line-height: 22px;
  371. margin-bottom: 28px;
  372. font-family: FZZCYSK;
  373. font-weight: 400;
  374. }
  375. .setting-list {
  376. max-height: calc(70vh - 50px);
  377. overflow: auto;
  378. ul {
  379. list-style: none outside none;
  380. margin: 0;
  381. padding: 0;
  382. li {
  383. list-style: none outside none;
  384. i {
  385. font:
  386. 12px / 16px PingFangSC-Regular,
  387. '-apple-system',
  388. Simsun;
  389. display: inline-block;
  390. min-width: 48px;
  391. margin-right: 16px;
  392. vertical-align: middle;
  393. color: #666;
  394. }
  395. .theme-item {
  396. line-height: 32px;
  397. width: 34px;
  398. height: 34px;
  399. margin-right: 16px;
  400. margin-top: 5px;
  401. border-radius: 100%;
  402. display: inline-block;
  403. cursor: pointer;
  404. text-align: center;
  405. vertical-align: middle;
  406. .iconfont {
  407. display: none;
  408. }
  409. }
  410. .selected {
  411. color: #ed4259;
  412. .iconfont {
  413. display: inline;
  414. }
  415. }
  416. }
  417. .font-list,
  418. .infinite-loading {
  419. margin-top: 28px;
  420. .font-item,
  421. .infinite-loading-item {
  422. width: 78px;
  423. height: 34px;
  424. cursor: pointer;
  425. margin-right: 16px;
  426. border-radius: 2px;
  427. text-align: center;
  428. vertical-align: middle;
  429. display: inline-block;
  430. font:
  431. 14px / 34px PingFangSC-Regular,
  432. HelveticaNeue-Light,
  433. 'Helvetica Neue Light',
  434. 'Microsoft YaHei',
  435. sans-serif;
  436. }
  437. .font-item-input {
  438. width: 168px;
  439. color: #000000;
  440. }
  441. .selected {
  442. color: #ed4259;
  443. border: 1px solid #ed4259;
  444. }
  445. .font-item:hover,
  446. .infinite-loading-item:hover {
  447. border: 1px solid #ed4259;
  448. color: #ed4259;
  449. }
  450. }
  451. .font-size,
  452. .read-width,
  453. .letter-spacing,
  454. .line-spacing,
  455. .paragraph-spacing {
  456. margin-top: 28px;
  457. .resize {
  458. display: inline-block;
  459. width: 274px;
  460. height: 34px;
  461. vertical-align: middle;
  462. border-radius: 2px;
  463. span {
  464. width: 89px;
  465. height: 34px;
  466. line-height: 34px;
  467. display: inline-block;
  468. cursor: pointer;
  469. text-align: center;
  470. vertical-align: middle;
  471. em {
  472. font-style: normal;
  473. }
  474. }
  475. .less:hover,
  476. .more:hover {
  477. color: #ed4259;
  478. }
  479. .lang {
  480. color: #a6a6a6;
  481. font-weight: 400;
  482. font-family: FZZCYSK;
  483. }
  484. b {
  485. display: inline-block;
  486. height: 20px;
  487. vertical-align: middle;
  488. }
  489. }
  490. }
  491. }
  492. }
  493. }
  494. .night {
  495. :deep(.theme-item) {
  496. border: 1px solid #666;
  497. }
  498. :deep(.selected) {
  499. border: 1px solid #666;
  500. }
  501. :deep(.moon-icon) {
  502. color: #ed4259;
  503. }
  504. :deep(.font-list),
  505. .infinite-loading {
  506. .font-item,
  507. .infinite-loading-item {
  508. border: 1px solid #666;
  509. background: rgba(45, 45, 45, 0.5);
  510. }
  511. }
  512. :deep(.resize) {
  513. border: 1px solid #666;
  514. background: rgba(45, 45, 45, 0.5);
  515. b {
  516. border-right: 1px solid #666;
  517. }
  518. }
  519. }
  520. .day {
  521. :deep(.theme-item) {
  522. border: 1px solid #e5e5e5;
  523. }
  524. :deep(.selected) {
  525. border: 1px solid #ed4259;
  526. }
  527. :deep(.moon-icon) {
  528. display: inline;
  529. color: rgba(255, 255, 255, 0.2);
  530. }
  531. :deep(.font-list),
  532. .infinite-loading {
  533. .font-item,
  534. .infinite-loading-item {
  535. background: rgba(255, 255, 255, 0.5);
  536. border: 1px solid rgba(0, 0, 0, 0.1);
  537. }
  538. }
  539. :deep(.resize) {
  540. border: 1px solid #e5e5e5;
  541. background: rgba(255, 255, 255, 0.5);
  542. b {
  543. border-right: 1px solid #e5e5e5;
  544. }
  545. }
  546. }
  547. @media screen and (max-width: 500px) {
  548. .settings-wrapper i {
  549. display: flex !important;
  550. flex-wrap: wrap;
  551. padding-bottom: 5px !important;
  552. }
  553. }
  554. </style>