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. <StdDialog ref="stdDialog"/>
  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 StdDialog from '../../share/StdDialog.vue';
  76. import rstore from '../../../store/modules/reader';
  77. import defPalette from './defPalette';
  78. import * as notify from '../../share/notify';
  79. const hex = /^#[0-9a-fA-F]{3}([0-9a-fA-F]{3})?$/;
  80. export default @Component({
  81. components: {
  82. Window,
  83. NumInput,
  84. StdDialog,
  85. },
  86. data: function() {
  87. return Object.assign({}, rstore.settingDefaults);
  88. },
  89. watch: {
  90. settings: function() {
  91. this.settingsChanged();
  92. },
  93. form: function(newValue) {
  94. if (this.inited)
  95. this.commit('reader/setSettings', newValue);
  96. },
  97. fontBold: function(newValue) {
  98. this.fontWeight = (newValue ? 'bold' : '');
  99. },
  100. fontItalic: function(newValue) {
  101. this.fontStyle = (newValue ? 'italic' : '');
  102. },
  103. vertShift: function(newValue) {
  104. const font = (this.webFontName ? this.webFontName : this.fontName);
  105. this.fontShifts = Object.assign({}, this.fontShifts, {[font]: newValue});
  106. this.fontVertShift = newValue;
  107. },
  108. fontName: function(newValue) {
  109. const font = (this.webFontName ? this.webFontName : newValue);
  110. this.vertShift = this.fontShifts[font] || 0;
  111. },
  112. webFontName: function(newValue) {
  113. const font = (newValue ? newValue : this.fontName);
  114. this.vertShift = this.fontShifts[font] || 0;
  115. },
  116. wallpaper: function(newValue) {
  117. if (newValue != '' && this.pageChangeAnimation == 'flip')
  118. this.pageChangeAnimation = '';
  119. },
  120. textColor: function(newValue) {
  121. this.textColorFiltered = newValue;
  122. },
  123. textColorFiltered: function(newValue) {
  124. if (hex.test(newValue))
  125. this.textColor = newValue;
  126. },
  127. backgroundColor: function(newValue) {
  128. this.bgColorFiltered = newValue;
  129. },
  130. bgColorFiltered: function(newValue) {
  131. if (hex.test(newValue))
  132. this.backgroundColor = newValue;
  133. },
  134. },
  135. })
  136. class SettingsPage extends Vue {
  137. selectedTab = 'profiles';
  138. selectedViewTab = 'color';
  139. form = {};
  140. fontBold = false;
  141. fontItalic = false;
  142. vertShift = 0;
  143. tabsScrollable = false;
  144. textColorFiltered = '';
  145. bgColorFiltered = '';
  146. webFonts = [];
  147. fonts = [];
  148. serverStorageKeyVisible = false;
  149. toolButtons = [];
  150. created() {
  151. this.commit = this.$store.commit;
  152. this.reader = this.$store.state.reader;
  153. this.form = {};
  154. this.toolButtons = rstore.toolButtons;
  155. this.settingsChanged();
  156. }
  157. mounted() {
  158. this.stdDialog = this.$refs.stdDialog;
  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. notify.warning(this, 'Необходимо обновить страницу (F5), чтобы изменения возымели эффект');
  304. }
  305. needTextReload() {
  306. notify.warning(this, 'Необходимо обновить книгу в обход кэша, чтобы изменения возымели эффект');
  307. }
  308. close() {
  309. this.$emit('settings-toggle');
  310. }
  311. async setDefaults() {
  312. try {
  313. if (await this.$confirm('Подтвердите установку настроек по умолчанию:', '', {
  314. confirmButtonText: 'OK',
  315. cancelButtonText: 'Отмена',
  316. customClass: 'prompt-dialog',
  317. type: 'warning'
  318. })) {
  319. this.form = Object.assign({}, rstore.settingDefaults);
  320. for (let prop in rstore.settingDefaults) {
  321. this[prop] = this.form[prop];
  322. }
  323. }
  324. } catch (e) {
  325. //
  326. }
  327. }
  328. changeShowToolButton(buttonName) {
  329. this.showToolButton = Object.assign({}, this.showToolButton, {[buttonName]: !this.showToolButton[buttonName]});
  330. }
  331. async addProfile() {
  332. try {
  333. if (Object.keys(this.profiles).length >= 100) {
  334. this.$alert('Достигнут предел количества профилей', 'Ошибка');
  335. return;
  336. }
  337. const result = await this.$prompt('Введите произвольное название для профиля устройства:', '', {
  338. confirmButtonText: 'OK',
  339. cancelButtonText: 'Отмена',
  340. inputValidator: (str) => { if (!str) return 'Название не должно быть пустым'; else if (str.length > 50) return 'Слишком длинное название'; else return true; },
  341. customClass: 'prompt-dialog',
  342. });
  343. if (result.value) {
  344. if (this.profiles[result.value]) {
  345. this.$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.$prompt(`<b>Предупреждение!</b> Удаление профиля '${this.currentProfile}' необратимо.` +
  365. `<br>Все настройки профиля будут потеряны,<br>однако список читаемых книг сохранится.` +
  366. `<br><br>Введите 'да' для подтверждения удаления:`, '', {
  367. dangerouslyUseHTMLString: true,
  368. confirmButtonText: 'OK',
  369. cancelButtonText: 'Отмена',
  370. inputValidator: (str) => { if (str && str.toLowerCase() === 'да') return true; else return 'Удаление не подтверждено'; },
  371. customClass: 'prompt-dialog',
  372. type: 'warning',
  373. });
  374. if (result.value && result.value.toLowerCase() == 'да') {
  375. if (this.profiles[this.currentProfile]) {
  376. const newProfiles = Object.assign({}, this.profiles);
  377. delete newProfiles[this.currentProfile];
  378. this.commit('reader/setAllowProfilesSave', true);
  379. await this.$nextTick();//ждем обработчики watch
  380. this.commit('reader/setProfiles', newProfiles);
  381. await this.$nextTick();//ждем обработчики watch
  382. this.commit('reader/setAllowProfilesSave', false);
  383. this.currentProfile = '';
  384. }
  385. }
  386. } catch (e) {
  387. //
  388. }
  389. }
  390. async delAllProfiles() {
  391. if (!Object.keys(this.profiles).length)
  392. return;
  393. try {
  394. const result = await this.$prompt(`<b>Предупреждение!</b> Удаление ВСЕХ профилей с настройками необратимо.` +
  395. `<br><br>Введите 'да' для подтверждения удаления:`, '', {
  396. dangerouslyUseHTMLString: true,
  397. confirmButtonText: 'OK',
  398. cancelButtonText: 'Отмена',
  399. inputValidator: (str) => { if (str && str.toLowerCase() === 'да') return true; else return 'Удаление не подтверждено'; },
  400. customClass: 'prompt-dialog',
  401. type: 'warning',
  402. });
  403. if (result.value && result.value.toLowerCase() == 'да') {
  404. this.commit('reader/setAllowProfilesSave', true);
  405. await this.$nextTick();//ждем обработчики watch
  406. this.commit('reader/setProfiles', {});
  407. await this.$nextTick();//ждем обработчики watch
  408. this.commit('reader/setAllowProfilesSave', false);
  409. this.currentProfile = '';
  410. }
  411. } catch (e) {
  412. //
  413. }
  414. }
  415. async copyToClip(text, prefix) {
  416. const result = await utils.copyTextToClipboard(text);
  417. const suf = (prefix.substr(-1) == 'а' ? 'а' : '');
  418. const msg = (result ? `${prefix} успешно скопирован${suf} в буфер обмена` : 'Копирование не удалось');
  419. if (result)
  420. notify.success(this, msg);
  421. else
  422. notify.error(this, msg);
  423. }
  424. async showServerStorageKey() {
  425. this.serverStorageKeyVisible = !this.serverStorageKeyVisible;
  426. }
  427. async enterServerStorageKey(key) {
  428. try {
  429. const result = await this.$prompt(`<b>Предупреждение!</b> Изменение ключа доступа приведет к замене всех профилей и читаемых книг в читалке.` +
  430. `<br><br>Введите новый ключ доступа:`, '', {
  431. dangerouslyUseHTMLString: true,
  432. confirmButtonText: 'OK',
  433. cancelButtonText: 'Отмена',
  434. inputValidator: (str) => { if (str && utils.fromBase58(str).length == 32) return true; else return 'Неверный формат ключа'; },
  435. inputValue: (key && _.isString(key) ? key : null),
  436. customClass: 'prompt-dialog',
  437. type: 'warning',
  438. });
  439. if (result.value && utils.fromBase58(result.value).length == 32) {
  440. this.commit('reader/setServerStorageKey', result.value);
  441. }
  442. } catch (e) {
  443. //
  444. }
  445. }
  446. async generateServerStorageKey() {
  447. try {
  448. const result = await this.$prompt(`<b>Предупреждение!</b> Генерация нового ключа доступа приведет к удалению всех профилей и читаемых книг в читалке.` +
  449. `<br><br>Введите 'да' для подтверждения генерации нового ключа:`, '', {
  450. dangerouslyUseHTMLString: true,
  451. confirmButtonText: 'OK',
  452. cancelButtonText: 'Отмена',
  453. inputValidator: (str) => { if (str && str.toLowerCase() === 'да') return true; else return 'Генерация не подтверждена'; },
  454. customClass: 'prompt-dialog',
  455. type: 'warning',
  456. });
  457. if (result.value && result.value.toLowerCase() == 'да') {
  458. this.$root.$emit('generateNewServerStorageKey');
  459. }
  460. } catch (e) {
  461. //
  462. }
  463. }
  464. keyHook(event) {
  465. if (event.type == 'keydown' && event.code == 'Escape') {
  466. this.close();
  467. }
  468. return true;
  469. }
  470. }
  471. //-----------------------------------------------------------------------------
  472. </script>
  473. <style scoped>
  474. .tab {
  475. justify-content: initial;
  476. }
  477. .tab-panel {
  478. overflow-x: hidden;
  479. overflow-y: auto;
  480. font-size: 90%;
  481. padding: 0 10px 15px 10px;
  482. }
  483. .part-header {
  484. border-top: 2px solid #bbbbbb;
  485. font-weight: bold;
  486. font-size: 110%;
  487. margin-top: 15px;
  488. margin-bottom: 5px;
  489. }
  490. .item {
  491. width: 100%;
  492. margin-top: 5px;
  493. margin-bottom: 5px;
  494. }
  495. .label-1 {
  496. width: 75px;
  497. }
  498. .label-2, .label-3, .label-4, .label-5, .label-6 {
  499. width: 110px;
  500. }
  501. .label-1, .label-2, .label-3, .label-4, .label-5, .label-6 {
  502. display: flex;
  503. flex-direction: column;
  504. justify-content: center;
  505. text-align: right;
  506. margin-right: 10px;
  507. overflow: hidden;
  508. }
  509. .text {
  510. font-size: 90%;
  511. line-height: 130%;
  512. }
  513. .button {
  514. margin: 3px 15px 3px 0;
  515. padding: 0 5px 0 5px;
  516. }
  517. .copy-icon {
  518. margin-left: 5px;
  519. cursor: pointer;
  520. font-size: 120%;
  521. color: blue;
  522. }
  523. .input {
  524. max-width: 150px;
  525. }
  526. .no-mp {
  527. margin: 0;
  528. padding: 0;
  529. }
  530. .col-left {
  531. width: 150px;
  532. }
  533. </style>