SettingsPage.vue 21 KB

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