ReadSettings.vue 15 KB

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