SettingsPage.vue 21 KB

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