SettingsPage.vue 20 KB

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