ReadSettings.vue 15 KB

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