SettingsPage.vue 21 KB

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