SettingsPage.vue 21 KB

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