SettingsPage.vue 20 KB

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