SettingsPage.vue 20 KB

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