SettingsPage.vue 21 KB

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