SettingsPage.vue 20 KB

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