ReadSettings.vue 14 KB

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