SettingsPage.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. <template lang="includer">
  2. <Window ref="window" height="95%" width="600px" @close="close">
  3. <template slot="header">
  4. Настройки
  5. </template>
  6. <div class="col row">
  7. <div class="full-height">
  8. <q-tabs
  9. ref="tabs"
  10. class="bg-grey-3 text-black"
  11. v-model="selectedTab"
  12. left-icon="la la-caret-up"
  13. right-icon="la la-caret-down"
  14. active-color="white"
  15. active-bg-color="primary"
  16. indicator-color="black"
  17. vertical
  18. no-caps
  19. stretch
  20. inline-label
  21. >
  22. <div v-show="tabsScrollable" class="q-pt-lg"/>
  23. <q-tab class="tab" name="profiles" icon="la la-users" label="Профили" />
  24. <q-tab class="tab" name="view" icon="la la-eye" label="Вид" />
  25. <q-tab class="tab" name="buttons" icon="la la-grip-horizontal" label="Кнопки" />
  26. <q-tab class="tab" name="keys" icon="la la-gamepad" label="Управление" />
  27. <q-tab class="tab" name="pagemove" icon="la la-school" label="Листание" />
  28. <q-tab class="tab" name="convert" icon="la la-magic" label="Конвертир." />
  29. <q-tab class="tab" name="others" icon="la la-list-ul" label="Прочее" />
  30. <q-tab class="tab" name="reset" icon="la la-broom" label="Сброс" />
  31. <div v-show="tabsScrollable" class="q-pt-lg"/>
  32. </q-tabs>
  33. </div>
  34. <div class="col fit">
  35. <!-- Профили --------------------------------------------------------------------->
  36. <div v-if="selectedTab == 'profiles'" class="fit tab-panel">
  37. @@include('./include/ProfilesTab.inc');
  38. </div>
  39. <!-- Вид ------------------------------------------------------------------------->
  40. <div v-if="selectedTab == 'view'" class="fit column">
  41. @@include('./include/ViewTab.inc');
  42. </div>
  43. <!-- Кнопки ---------------------------------------------------------------------->
  44. <div v-if="selectedTab == 'buttons'" class="fit tab-panel">
  45. @@include('./include/ButtonsTab.inc');
  46. </div>
  47. <!-- Управление ------------------------------------------------------------------>
  48. <div v-if="selectedTab == 'keys'" class="fit column">
  49. @@include('./include/KeysTab.inc');
  50. </div>
  51. <!-- Листание -------------------------------------------------------------------->
  52. <div v-if="selectedTab == 'pagemove'" class="fit tab-panel">
  53. @@include('./include/PageMoveTab.inc');
  54. </div>
  55. <!-- Конвертирование ------------------------------------------------------------->
  56. <div v-if="selectedTab == 'convert'" class="fit tab-panel">
  57. @@include('./include/ConvertTab.inc');
  58. </div>
  59. <!-- Прочее ---------------------------------------------------------------------->
  60. <div v-if="selectedTab == 'others'" class="fit tab-panel">
  61. @@include('./include/OthersTab.inc');
  62. </div>
  63. <!-- Сброс ----------------------------------------------------------------------->
  64. <div v-if="selectedTab == 'reset'" class="fit tab-panel">
  65. @@include('./include/ResetTab.inc');
  66. </div>
  67. </div>
  68. </div>
  69. </Window>
  70. </template>
  71. <script>
  72. //-----------------------------------------------------------------------------
  73. import Vue from 'vue';
  74. import Component from 'vue-class-component';
  75. import _ from 'lodash';
  76. import * as utils from '../../../share/utils';
  77. import Window from '../../share/Window.vue';
  78. import NumInput from '../../share/NumInput.vue';
  79. import UserHotKeys from './UserHotKeys/UserHotKeys.vue';
  80. import rstore from '../../../store/modules/reader';
  81. import defPalette from './defPalette';
  82. const hex = /^#[0-9a-fA-F]{3}([0-9a-fA-F]{3})?$/;
  83. export default @Component({
  84. components: {
  85. Window,
  86. NumInput,
  87. UserHotKeys,
  88. },
  89. data: function() {
  90. return Object.assign({}, rstore.settingDefaults);
  91. },
  92. watch: {
  93. settings: function() {
  94. this.settingsChanged();
  95. },
  96. form: function(newValue) {
  97. if (this.inited)
  98. this.commit('reader/setSettings', newValue);
  99. },
  100. fontBold: function(newValue) {
  101. this.fontWeight = (newValue ? 'bold' : '');
  102. },
  103. fontItalic: function(newValue) {
  104. this.fontStyle = (newValue ? 'italic' : '');
  105. },
  106. vertShift: function(newValue) {
  107. const font = (this.webFontName ? this.webFontName : this.fontName);
  108. if (this.fontShifts[font] != newValue || this.fontVertShift != newValue) {
  109. this.fontShifts = Object.assign({}, this.fontShifts, {[font]: newValue});
  110. this.fontVertShift = newValue;
  111. }
  112. },
  113. fontName: function(newValue) {
  114. const font = (this.webFontName ? this.webFontName : newValue);
  115. this.vertShift = this.fontShifts[font] || 0;
  116. },
  117. webFontName: function(newValue) {
  118. const font = (newValue ? newValue : this.fontName);
  119. this.vertShift = this.fontShifts[font] || 0;
  120. },
  121. wallpaper: function(newValue) {
  122. if (newValue != '' && this.pageChangeAnimation == 'flip')
  123. this.pageChangeAnimation = '';
  124. },
  125. dualPageMode(newValue) {
  126. if (newValue && this.pageChangeAnimation == 'flip' || this.pageChangeAnimation == 'rightShift')
  127. this.pageChangeAnimation = '';
  128. },
  129. textColor: function(newValue) {
  130. this.textColorFiltered = newValue;
  131. },
  132. textColorFiltered: function(newValue) {
  133. if (hex.test(newValue))
  134. this.textColor = newValue;
  135. },
  136. backgroundColor: function(newValue) {
  137. this.bgColorFiltered = newValue;
  138. },
  139. bgColorFiltered: function(newValue) {
  140. if (hex.test(newValue))
  141. this.backgroundColor = newValue;
  142. },
  143. dualDivColor(newValue) {
  144. this.dualDivColorFiltered = newValue;
  145. },
  146. dualDivColorFiltered(newValue) {
  147. if (hex.test(newValue))
  148. this.dualDivColor = newValue;
  149. },
  150. statusBarColor(newValue) {
  151. this.statusBarColorFiltered = newValue;
  152. },
  153. statusBarColorFiltered(newValue) {
  154. if (hex.test(newValue))
  155. this.statusBarColor = newValue;
  156. },
  157. },
  158. })
  159. class SettingsPage extends Vue {
  160. selectedTab = 'profiles';
  161. selectedViewTab = 'mode';
  162. selectedKeysTab = 'mouse';
  163. form = {};
  164. fontBold = false;
  165. fontItalic = false;
  166. vertShift = 0;
  167. tabsScrollable = false;
  168. textColorFiltered = '';
  169. bgColorFiltered = '';
  170. dualDivColorFiltered = '';
  171. webFonts = [];
  172. fonts = [];
  173. serverStorageKeyVisible = false;
  174. toolButtons = [];
  175. rstore = {};
  176. created() {
  177. this.commit = this.$store.commit;
  178. this.reader = this.$store.state.reader;
  179. this.form = {};
  180. this.rstore = rstore;
  181. this.toolButtons = rstore.toolButtons;
  182. this.settingsChanged();
  183. }
  184. mounted() {
  185. this.$watch(
  186. '$refs.tabs.scrollable',
  187. (newValue) => {
  188. this.tabsScrollable = newValue && !this.$isMobileDevice;
  189. }
  190. );
  191. }
  192. init() {
  193. this.$refs.window.init();
  194. this.inited = true;
  195. }
  196. settingsChanged() {
  197. if (_.isEqual(this.form, this.settings))
  198. return;
  199. this.form = Object.assign({}, this.settings);
  200. if (!this.unwatch)
  201. this.unwatch = {};
  202. for (let prop in rstore.settingDefaults) {
  203. if (this.unwatch && this.unwatch[prop])
  204. this.unwatch[prop]();
  205. this[prop] = this.form[prop];
  206. this.unwatch[prop] = this.$watch(prop, (newValue) => {
  207. this.form = Object.assign({}, this.form, {[prop]: newValue});
  208. });
  209. }
  210. this.fontBold = (this.fontWeight == 'bold');
  211. this.fontItalic = (this.fontStyle == 'italic');
  212. this.fonts = rstore.fonts;
  213. this.webFonts = rstore.webFonts;
  214. const font = (this.webFontName ? this.webFontName : this.fontName);
  215. this.vertShift = this.fontShifts[font] || 0;
  216. this.textColorFiltered = this.textColor;
  217. this.bgColorFiltered = this.backgroundColor;
  218. this.dualDivColorFiltered = this.dualDivColor;
  219. this.statusBarColorFiltered = this.statusBarColor;
  220. }
  221. get mode() {
  222. return this.$store.state.config.mode;
  223. }
  224. get isExternalConverter() {
  225. return this.$store.state.config.useExternalBookConverter;
  226. }
  227. get settings() {
  228. return this.$store.state.reader.settings;
  229. }
  230. get serverSyncEnabled() {
  231. return this.$store.state.reader.serverSyncEnabled;
  232. }
  233. set serverSyncEnabled(newValue) {
  234. this.commit('reader/setServerSyncEnabled', newValue);
  235. }
  236. get profiles() {
  237. return this.$store.state.reader.profiles;
  238. }
  239. get currentProfileOptions() {
  240. const profNames = Object.keys(this.profiles)
  241. profNames.sort();
  242. let result = [{label: 'Нет', value: ''}];
  243. profNames.forEach(name => {
  244. result.push({label: name, value: name});
  245. });
  246. return result;
  247. }
  248. get wallpaperOptions() {
  249. let result = [{label: 'Нет', value: ''}];
  250. for (let i = 1; i < 10; i++) {
  251. result.push({label: i, value: `paper${i}`});
  252. }
  253. return result;
  254. }
  255. get fontsOptions() {
  256. let result = [];
  257. this.fonts.forEach(font => {
  258. result.push({label: (font.label ? font.label : font.name), value: font.name});
  259. });
  260. return result;
  261. }
  262. get webFontsOptions() {
  263. let result = [{label: 'Нет', value: ''}];
  264. this.webFonts.forEach(font => {
  265. result.push({label: font.name, value: font.name});
  266. });
  267. return result;
  268. }
  269. get pageChangeAnimationOptions() {
  270. let result = [
  271. {label: 'Нет', value: ''},
  272. {label: 'Вверх-вниз', value: 'downShift'},
  273. (!this.dualPageMode ? {label: 'Вправо-влево', value: 'rightShift'} : null),
  274. {label: 'Протаивание', value: 'thaw'},
  275. {label: 'Мерцание', value: 'blink'},
  276. {label: 'Вращение', value: 'rotate'},
  277. (this.wallpaper == '' && !this.dualPageMode ? {label: 'Листание', value: 'flip'} : null),
  278. ];
  279. result = result.filter(v => v);
  280. return result;
  281. }
  282. get currentProfile() {
  283. return this.$store.state.reader.currentProfile;
  284. }
  285. set currentProfile(newValue) {
  286. this.commit('reader/setCurrentProfile', newValue);
  287. }
  288. get partialStorageKey() {
  289. return this.serverStorageKey.substr(0, 7) + '***';
  290. }
  291. get serverStorageKey() {
  292. return this.$store.state.reader.serverStorageKey;
  293. }
  294. get setStorageKeyLink() {
  295. return `https://${window.location.host}/#/reader?setStorageAccessKey=${utils.toBase58(this.serverStorageKey)}`;
  296. }
  297. get predefineTextColors() {
  298. return defPalette.concat([
  299. '#ffffff',
  300. '#000000',
  301. '#202020',
  302. '#323232',
  303. '#aaaaaa',
  304. '#00c0c0',
  305. '#ebe2c9',
  306. '#cfdc99',
  307. '#478355',
  308. '#909080',
  309. ]);
  310. }
  311. get predefineBackgroundColors() {
  312. return defPalette.concat([
  313. '#ffffff',
  314. '#000000',
  315. '#202020',
  316. '#ebe2c9',
  317. '#cfdc99',
  318. '#478355',
  319. '#a6caf0',
  320. '#909080',
  321. '#808080',
  322. '#c8c8c8',
  323. ]);
  324. }
  325. colorPanStyle(type) {
  326. let result = 'width: 30px; height: 30px; border: 1px solid black; border-radius: 4px;';
  327. switch (type) {
  328. case 'text':
  329. result += `background-color: ${this.textColor};`
  330. break;
  331. case 'bg':
  332. result += `background-color: ${this.backgroundColor};`
  333. break;
  334. case 'div':
  335. result += `background-color: ${this.dualDivColor};`
  336. break;
  337. case 'statusbar':
  338. result += `background-color: ${this.statusBarColor};`
  339. break;
  340. }
  341. return result;
  342. }
  343. needReload() {
  344. this.$root.notify.warning('Необходимо обновить страницу (F5), чтобы изменения возымели эффект');
  345. }
  346. needTextReload() {
  347. this.$root.notify.warning('Необходимо обновить книгу в обход кэша, чтобы изменения возымели эффект');
  348. }
  349. close() {
  350. this.$emit('do-action', {action: 'settings'});
  351. }
  352. async setDefaults() {
  353. try {
  354. if (await this.$root.stdDialog.confirm('Подтвердите установку настроек по умолчанию:', ' ')) {
  355. this.form = Object.assign({}, rstore.settingDefaults);
  356. for (let prop in rstore.settingDefaults) {
  357. this[prop] = this.form[prop];
  358. }
  359. }
  360. } catch (e) {
  361. //
  362. }
  363. }
  364. changeShowToolButton(buttonName) {
  365. this.showToolButton = Object.assign({}, this.showToolButton, {[buttonName]: !this.showToolButton[buttonName]});
  366. }
  367. async addProfile() {
  368. try {
  369. if (Object.keys(this.profiles).length >= 100) {
  370. this.$root.stdDialog.alert('Достигнут предел количества профилей', 'Ошибка');
  371. return;
  372. }
  373. const result = await this.$root.stdDialog.prompt('Введите произвольное название для профиля устройства:', ' ', {
  374. inputValidator: (str) => { if (!str) return 'Название не должно быть пустым'; else if (str.length > 50) return 'Слишком длинное название'; else return true; },
  375. });
  376. if (result && result.value) {
  377. if (this.profiles[result.value]) {
  378. this.$root.stdDialog.alert('Такой профиль уже существует', 'Ошибка');
  379. } else {
  380. const newProfiles = Object.assign({}, this.profiles, {[result.value]: 1});
  381. this.commit('reader/setAllowProfilesSave', true);
  382. await this.$nextTick();//ждем обработчики watch
  383. this.commit('reader/setProfiles', newProfiles);
  384. await this.$nextTick();//ждем обработчики watch
  385. this.commit('reader/setAllowProfilesSave', false);
  386. this.currentProfile = result.value;
  387. }
  388. }
  389. } catch (e) {
  390. //
  391. }
  392. }
  393. async delProfile() {
  394. if (!this.currentProfile)
  395. return;
  396. try {
  397. const result = await this.$root.stdDialog.prompt(`<b>Предупреждение!</b> Удаление профиля '${this.$sanitize(this.currentProfile)}' необратимо.` +
  398. `<br>Все настройки профиля будут потеряны, однако список читаемых книг сохранится.` +
  399. `<br><br>Введите 'да' для подтверждения удаления:`, ' ', {
  400. inputValidator: (str) => { if (str && str.toLowerCase() === 'да') return true; else return 'Удаление не подтверждено'; },
  401. });
  402. if (result && result.value && result.value.toLowerCase() == 'да') {
  403. if (this.profiles[this.currentProfile]) {
  404. const newProfiles = Object.assign({}, this.profiles);
  405. delete newProfiles[this.currentProfile];
  406. this.commit('reader/setAllowProfilesSave', true);
  407. await this.$nextTick();//ждем обработчики watch
  408. this.commit('reader/setProfiles', newProfiles);
  409. await this.$nextTick();//ждем обработчики watch
  410. this.commit('reader/setAllowProfilesSave', false);
  411. this.currentProfile = '';
  412. }
  413. }
  414. } catch (e) {
  415. //
  416. }
  417. }
  418. async delAllProfiles() {
  419. if (!Object.keys(this.profiles).length)
  420. return;
  421. try {
  422. const result = await this.$root.stdDialog.prompt(`<b>Предупреждение!</b> Удаление ВСЕХ профилей с настройками необратимо.` +
  423. `<br><br>Введите 'да' для подтверждения удаления:`, ' ', {
  424. inputValidator: (str) => { if (str && str.toLowerCase() === 'да') return true; else return 'Удаление не подтверждено'; },
  425. });
  426. if (result && result.value && result.value.toLowerCase() == 'да') {
  427. this.commit('reader/setAllowProfilesSave', true);
  428. await this.$nextTick();//ждем обработчики watch
  429. this.commit('reader/setProfiles', {});
  430. await this.$nextTick();//ждем обработчики watch
  431. this.commit('reader/setAllowProfilesSave', false);
  432. this.currentProfile = '';
  433. }
  434. } catch (e) {
  435. //
  436. }
  437. }
  438. async copyToClip(text, prefix) {
  439. const result = await utils.copyTextToClipboard(text);
  440. const suf = (prefix.substr(-1) == 'а' ? 'а' : '');
  441. const msg = (result ? `${prefix} успешно скопирован${suf} в буфер обмена` : 'Копирование не удалось');
  442. if (result)
  443. this.$root.notify.success(msg);
  444. else
  445. this.$root.notify.error(msg);
  446. }
  447. async showServerStorageKey() {
  448. this.serverStorageKeyVisible = !this.serverStorageKeyVisible;
  449. }
  450. async enterServerStorageKey(key) {
  451. try {
  452. const result = await this.$root.stdDialog.prompt(`<b>Предупреждение!</b> Изменение ключа доступа приведет к замене всех профилей и читаемых книг в читалке.` +
  453. `<br><br>Введите новый ключ доступа:`, ' ', {
  454. inputValidator: (str) => {
  455. try {
  456. if (str && utils.fromBase58(str).length == 32) {
  457. return true;
  458. }
  459. } catch (e) {
  460. //
  461. }
  462. return 'Неверный формат ключа';
  463. },
  464. inputValue: (key && _.isString(key) ? key : null),
  465. });
  466. if (result && result.value && utils.fromBase58(result.value).length == 32) {
  467. this.commit('reader/setServerStorageKey', result.value);
  468. }
  469. } catch (e) {
  470. //
  471. }
  472. }
  473. async generateServerStorageKey() {
  474. try {
  475. const result = await this.$root.stdDialog.prompt(`<b>Предупреждение!</b> Генерация нового ключа доступа приведет к удалению всех профилей и читаемых книг в читалке.` +
  476. `<br><br>Введите 'да' для подтверждения генерации нового ключа:`, ' ', {
  477. inputValidator: (str) => { if (str && str.toLowerCase() === 'да') return true; else return 'Генерация не подтверждена'; },
  478. });
  479. if (result && result.value && result.value.toLowerCase() == 'да') {
  480. this.$root.$emit('generateNewServerStorageKey');
  481. }
  482. } catch (e) {
  483. //
  484. }
  485. }
  486. keyHook(event) {
  487. if (!this.$root.stdDialog.active && event.type == 'keydown' && event.key == 'Escape') {
  488. this.close();
  489. }
  490. return true;
  491. }
  492. }
  493. //-----------------------------------------------------------------------------
  494. </script>
  495. <style scoped>
  496. .tab {
  497. justify-content: initial;
  498. }
  499. .tab-panel {
  500. overflow-x: hidden;
  501. overflow-y: auto;
  502. font-size: 90%;
  503. padding: 0 10px 15px 10px;
  504. }
  505. .part-header {
  506. border-top: 2px solid #bbbbbb;
  507. font-weight: bold;
  508. font-size: 110%;
  509. margin-top: 15px;
  510. margin-bottom: 5px;
  511. }
  512. .item {
  513. width: 100%;
  514. margin-top: 5px;
  515. margin-bottom: 5px;
  516. }
  517. .label-1, .label-7 {
  518. width: 75px;
  519. }
  520. .label-2, .label-3, .label-4, .label-5 {
  521. width: 110px;
  522. }
  523. .label-6 {
  524. width: 100px;
  525. }
  526. .label-1, .label-2, .label-3, .label-4, .label-5, .label-6, .label-7 {
  527. display: flex;
  528. flex-direction: column;
  529. justify-content: center;
  530. text-align: right;
  531. margin-right: 10px;
  532. overflow: hidden;
  533. }
  534. .text {
  535. font-size: 90%;
  536. line-height: 130%;
  537. }
  538. .button {
  539. margin: 3px 15px 3px 0;
  540. padding: 0 5px 0 5px;
  541. }
  542. .copy-icon {
  543. margin-left: 5px;
  544. cursor: pointer;
  545. font-size: 120%;
  546. color: blue;
  547. }
  548. .input {
  549. max-width: 150px;
  550. }
  551. .no-mp {
  552. margin: 0;
  553. padding: 0;
  554. }
  555. .col-left {
  556. width: 150px;
  557. }
  558. </style>