SettingsPage.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  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) {
  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. },
  144. })
  145. class SettingsPage extends Vue {
  146. selectedTab = 'profiles';
  147. selectedViewTab = 'mode';
  148. selectedKeysTab = 'mouse';
  149. form = {};
  150. fontBold = false;
  151. fontItalic = false;
  152. vertShift = 0;
  153. tabsScrollable = false;
  154. textColorFiltered = '';
  155. bgColorFiltered = '';
  156. webFonts = [];
  157. fonts = [];
  158. serverStorageKeyVisible = false;
  159. toolButtons = [];
  160. rstore = {};
  161. created() {
  162. this.commit = this.$store.commit;
  163. this.reader = this.$store.state.reader;
  164. this.form = {};
  165. this.rstore = rstore;
  166. this.toolButtons = rstore.toolButtons;
  167. this.settingsChanged();
  168. }
  169. mounted() {
  170. this.$watch(
  171. '$refs.tabs.scrollable',
  172. (newValue) => {
  173. this.tabsScrollable = newValue && !this.$isMobileDevice;
  174. }
  175. );
  176. }
  177. init() {
  178. this.$refs.window.init();
  179. this.inited = true;
  180. }
  181. settingsChanged() {
  182. if (_.isEqual(this.form, this.settings))
  183. return;
  184. this.form = Object.assign({}, this.settings);
  185. if (!this.unwatch)
  186. this.unwatch = {};
  187. for (let prop in rstore.settingDefaults) {
  188. if (this.unwatch && this.unwatch[prop])
  189. this.unwatch[prop]();
  190. this[prop] = this.form[prop];
  191. this.unwatch[prop] = this.$watch(prop, (newValue) => {
  192. this.form = Object.assign({}, this.form, {[prop]: newValue});
  193. });
  194. }
  195. this.fontBold = (this.fontWeight == 'bold');
  196. this.fontItalic = (this.fontStyle == 'italic');
  197. this.fonts = rstore.fonts;
  198. this.webFonts = rstore.webFonts;
  199. const font = (this.webFontName ? this.webFontName : this.fontName);
  200. this.vertShift = this.fontShifts[font] || 0;
  201. this.textColorFiltered = this.textColor;
  202. this.bgColorFiltered = this.backgroundColor;
  203. }
  204. get mode() {
  205. return this.$store.state.config.mode;
  206. }
  207. get isExternalConverter() {
  208. return this.$store.state.config.useExternalBookConverter;
  209. }
  210. get settings() {
  211. return this.$store.state.reader.settings;
  212. }
  213. get serverSyncEnabled() {
  214. return this.$store.state.reader.serverSyncEnabled;
  215. }
  216. set serverSyncEnabled(newValue) {
  217. this.commit('reader/setServerSyncEnabled', newValue);
  218. }
  219. get profiles() {
  220. return this.$store.state.reader.profiles;
  221. }
  222. get currentProfileOptions() {
  223. const profNames = Object.keys(this.profiles)
  224. profNames.sort();
  225. let result = [{label: 'Нет', value: ''}];
  226. profNames.forEach(name => {
  227. result.push({label: name, value: name});
  228. });
  229. return result;
  230. }
  231. get wallpaperOptions() {
  232. let result = [{label: 'Нет', value: ''}];
  233. for (let i = 1; i < 10; i++) {
  234. result.push({label: i, value: `paper${i}`});
  235. }
  236. return result;
  237. }
  238. get fontsOptions() {
  239. let result = [];
  240. this.fonts.forEach(font => {
  241. result.push({label: (font.label ? font.label : font.name), value: font.name});
  242. });
  243. return result;
  244. }
  245. get webFontsOptions() {
  246. let result = [{label: 'Нет', value: ''}];
  247. this.webFonts.forEach(font => {
  248. result.push({label: font.name, value: font.name});
  249. });
  250. return result;
  251. }
  252. get pageChangeAnimationOptions() {
  253. let result = [
  254. {label: 'Нет', value: ''},
  255. {label: 'Вверх-вниз', value: 'downShift'},
  256. (!this.dualPageMode ? {label: 'Вправо-влево', value: 'rightShift'} : null),
  257. {label: 'Протаивание', value: 'thaw'},
  258. {label: 'Мерцание', value: 'blink'},
  259. {label: 'Вращение', value: 'rotate'},
  260. (this.wallpaper == '' && !this.dualPageMode ? {label: 'Листание', value: 'flip'} : null),
  261. ];
  262. result = result.filter(v => v);
  263. return result;
  264. }
  265. get currentProfile() {
  266. return this.$store.state.reader.currentProfile;
  267. }
  268. set currentProfile(newValue) {
  269. this.commit('reader/setCurrentProfile', newValue);
  270. }
  271. get partialStorageKey() {
  272. return this.serverStorageKey.substr(0, 7) + '***';
  273. }
  274. get serverStorageKey() {
  275. return this.$store.state.reader.serverStorageKey;
  276. }
  277. get setStorageKeyLink() {
  278. return `https://${window.location.host}/#/reader?setStorageAccessKey=${utils.toBase58(this.serverStorageKey)}`;
  279. }
  280. get predefineTextColors() {
  281. return defPalette.concat([
  282. '#ffffff',
  283. '#000000',
  284. '#202020',
  285. '#323232',
  286. '#aaaaaa',
  287. '#00c0c0',
  288. '#ebe2c9',
  289. '#cfdc99',
  290. '#478355',
  291. '#909080',
  292. ]);
  293. }
  294. get predefineBackgroundColors() {
  295. return defPalette.concat([
  296. '#ffffff',
  297. '#000000',
  298. '#202020',
  299. '#ebe2c9',
  300. '#cfdc99',
  301. '#478355',
  302. '#a6caf0',
  303. '#909080',
  304. '#808080',
  305. '#c8c8c8',
  306. ]);
  307. }
  308. colorPanStyle(type) {
  309. let result = 'width: 30px; height: 30px; border: 1px solid black; border-radius: 4px;';
  310. switch (type) {
  311. case 'text':
  312. result += `background-color: ${this.textColor};`
  313. break;
  314. case 'bg':
  315. result += `background-color: ${this.backgroundColor};`
  316. break;
  317. }
  318. return result;
  319. }
  320. needReload() {
  321. this.$root.notify.warning('Необходимо обновить страницу (F5), чтобы изменения возымели эффект');
  322. }
  323. needTextReload() {
  324. this.$root.notify.warning('Необходимо обновить книгу в обход кэша, чтобы изменения возымели эффект');
  325. }
  326. close() {
  327. this.$emit('do-action', {action: 'settings'});
  328. }
  329. async setDefaults() {
  330. try {
  331. if (await this.$root.stdDialog.confirm('Подтвердите установку настроек по умолчанию:', ' ')) {
  332. this.form = Object.assign({}, rstore.settingDefaults);
  333. for (let prop in rstore.settingDefaults) {
  334. this[prop] = this.form[prop];
  335. }
  336. }
  337. } catch (e) {
  338. //
  339. }
  340. }
  341. changeShowToolButton(buttonName) {
  342. this.showToolButton = Object.assign({}, this.showToolButton, {[buttonName]: !this.showToolButton[buttonName]});
  343. }
  344. async addProfile() {
  345. try {
  346. if (Object.keys(this.profiles).length >= 100) {
  347. this.$root.stdDialog.alert('Достигнут предел количества профилей', 'Ошибка');
  348. return;
  349. }
  350. const result = await this.$root.stdDialog.prompt('Введите произвольное название для профиля устройства:', ' ', {
  351. inputValidator: (str) => { if (!str) return 'Название не должно быть пустым'; else if (str.length > 50) return 'Слишком длинное название'; else return true; },
  352. });
  353. if (result && result.value) {
  354. if (this.profiles[result.value]) {
  355. this.$root.stdDialog.alert('Такой профиль уже существует', 'Ошибка');
  356. } else {
  357. const newProfiles = Object.assign({}, this.profiles, {[result.value]: 1});
  358. this.commit('reader/setAllowProfilesSave', true);
  359. await this.$nextTick();//ждем обработчики watch
  360. this.commit('reader/setProfiles', newProfiles);
  361. await this.$nextTick();//ждем обработчики watch
  362. this.commit('reader/setAllowProfilesSave', false);
  363. this.currentProfile = result.value;
  364. }
  365. }
  366. } catch (e) {
  367. //
  368. }
  369. }
  370. async delProfile() {
  371. if (!this.currentProfile)
  372. return;
  373. try {
  374. const result = await this.$root.stdDialog.prompt(`<b>Предупреждение!</b> Удаление профиля '${this.$sanitize(this.currentProfile)}' необратимо.` +
  375. `<br>Все настройки профиля будут потеряны, однако список читаемых книг сохранится.` +
  376. `<br><br>Введите 'да' для подтверждения удаления:`, ' ', {
  377. inputValidator: (str) => { if (str && str.toLowerCase() === 'да') return true; else return 'Удаление не подтверждено'; },
  378. });
  379. if (result && result.value && result.value.toLowerCase() == 'да') {
  380. if (this.profiles[this.currentProfile]) {
  381. const newProfiles = Object.assign({}, this.profiles);
  382. delete newProfiles[this.currentProfile];
  383. this.commit('reader/setAllowProfilesSave', true);
  384. await this.$nextTick();//ждем обработчики watch
  385. this.commit('reader/setProfiles', newProfiles);
  386. await this.$nextTick();//ждем обработчики watch
  387. this.commit('reader/setAllowProfilesSave', false);
  388. this.currentProfile = '';
  389. }
  390. }
  391. } catch (e) {
  392. //
  393. }
  394. }
  395. async delAllProfiles() {
  396. if (!Object.keys(this.profiles).length)
  397. return;
  398. try {
  399. const result = await this.$root.stdDialog.prompt(`<b>Предупреждение!</b> Удаление ВСЕХ профилей с настройками необратимо.` +
  400. `<br><br>Введите 'да' для подтверждения удаления:`, ' ', {
  401. inputValidator: (str) => { if (str && str.toLowerCase() === 'да') return true; else return 'Удаление не подтверждено'; },
  402. });
  403. if (result && result.value && result.value.toLowerCase() == 'да') {
  404. this.commit('reader/setAllowProfilesSave', true);
  405. await this.$nextTick();//ждем обработчики watch
  406. this.commit('reader/setProfiles', {});
  407. await this.$nextTick();//ждем обработчики watch
  408. this.commit('reader/setAllowProfilesSave', false);
  409. this.currentProfile = '';
  410. }
  411. } catch (e) {
  412. //
  413. }
  414. }
  415. async copyToClip(text, prefix) {
  416. const result = await utils.copyTextToClipboard(text);
  417. const suf = (prefix.substr(-1) == 'а' ? 'а' : '');
  418. const msg = (result ? `${prefix} успешно скопирован${suf} в буфер обмена` : 'Копирование не удалось');
  419. if (result)
  420. this.$root.notify.success(msg);
  421. else
  422. this.$root.notify.error(msg);
  423. }
  424. async showServerStorageKey() {
  425. this.serverStorageKeyVisible = !this.serverStorageKeyVisible;
  426. }
  427. async enterServerStorageKey(key) {
  428. try {
  429. const result = await this.$root.stdDialog.prompt(`<b>Предупреждение!</b> Изменение ключа доступа приведет к замене всех профилей и читаемых книг в читалке.` +
  430. `<br><br>Введите новый ключ доступа:`, ' ', {
  431. inputValidator: (str) => {
  432. try {
  433. if (str && utils.fromBase58(str).length == 32) {
  434. return true;
  435. }
  436. } catch (e) {
  437. //
  438. }
  439. return 'Неверный формат ключа';
  440. },
  441. inputValue: (key && _.isString(key) ? key : null),
  442. });
  443. if (result && result.value && utils.fromBase58(result.value).length == 32) {
  444. this.commit('reader/setServerStorageKey', result.value);
  445. }
  446. } catch (e) {
  447. //
  448. }
  449. }
  450. async generateServerStorageKey() {
  451. try {
  452. const result = await this.$root.stdDialog.prompt(`<b>Предупреждение!</b> Генерация нового ключа доступа приведет к удалению всех профилей и читаемых книг в читалке.` +
  453. `<br><br>Введите 'да' для подтверждения генерации нового ключа:`, ' ', {
  454. inputValidator: (str) => { if (str && str.toLowerCase() === 'да') return true; else return 'Генерация не подтверждена'; },
  455. });
  456. if (result && result.value && result.value.toLowerCase() == 'да') {
  457. this.$root.$emit('generateNewServerStorageKey');
  458. }
  459. } catch (e) {
  460. //
  461. }
  462. }
  463. keyHook(event) {
  464. if (!this.$root.stdDialog.active && event.type == 'keydown' && event.key == 'Escape') {
  465. this.close();
  466. }
  467. return true;
  468. }
  469. }
  470. //-----------------------------------------------------------------------------
  471. </script>
  472. <style scoped>
  473. .tab {
  474. justify-content: initial;
  475. }
  476. .tab-panel {
  477. overflow-x: hidden;
  478. overflow-y: auto;
  479. font-size: 90%;
  480. padding: 0 10px 15px 10px;
  481. }
  482. .part-header {
  483. border-top: 2px solid #bbbbbb;
  484. font-weight: bold;
  485. font-size: 110%;
  486. margin-top: 15px;
  487. margin-bottom: 5px;
  488. }
  489. .item {
  490. width: 100%;
  491. margin-top: 5px;
  492. margin-bottom: 5px;
  493. }
  494. .label-1, .label-7 {
  495. width: 75px;
  496. }
  497. .label-2, .label-3, .label-4, .label-5 {
  498. width: 110px;
  499. }
  500. .label-6 {
  501. width: 100px;
  502. }
  503. .label-1, .label-2, .label-3, .label-4, .label-5, .label-6, .label-7 {
  504. display: flex;
  505. flex-direction: column;
  506. justify-content: center;
  507. text-align: right;
  508. margin-right: 10px;
  509. overflow: hidden;
  510. }
  511. .text {
  512. font-size: 90%;
  513. line-height: 130%;
  514. }
  515. .button {
  516. margin: 3px 15px 3px 0;
  517. padding: 0 5px 0 5px;
  518. }
  519. .copy-icon {
  520. margin-left: 5px;
  521. cursor: pointer;
  522. font-size: 120%;
  523. color: blue;
  524. }
  525. .input {
  526. max-width: 150px;
  527. }
  528. .no-mp {
  529. margin: 0;
  530. padding: 0;
  531. }
  532. .col-left {
  533. width: 150px;
  534. }
  535. </style>