SettingsPage.vue 20 KB

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