SettingsPage.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  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. }
  177. get mode() {
  178. return this.$store.state.config.mode;
  179. }
  180. get settings() {
  181. return this.$store.state.reader.settings;
  182. }
  183. get serverSyncEnabled() {
  184. return this.$store.state.reader.serverSyncEnabled;
  185. }
  186. set serverSyncEnabled(newValue) {
  187. this.commit('reader/setServerSyncEnabled', newValue);
  188. }
  189. get profiles() {
  190. return this.$store.state.reader.profiles;
  191. }
  192. get currentProfileOptions() {
  193. const profNames = Object.keys(this.profiles)
  194. profNames.sort();
  195. let result = [{label: 'Нет', value: ''}];
  196. profNames.forEach(name => {
  197. result.push({label: name, value: name});
  198. });
  199. return result;
  200. }
  201. get wallpaperOptions() {
  202. let result = [{label: 'Нет', value: ''}];
  203. for (let i = 1; i < 10; i++) {
  204. result.push({label: i, value: `paper${i}`});
  205. }
  206. return result;
  207. }
  208. get currentProfile() {
  209. return this.$store.state.reader.currentProfile;
  210. }
  211. set currentProfile(newValue) {
  212. this.commit('reader/setCurrentProfile', newValue);
  213. }
  214. get partialStorageKey() {
  215. return this.serverStorageKey.substr(0, 7) + '***';
  216. }
  217. get serverStorageKey() {
  218. return this.$store.state.reader.serverStorageKey;
  219. }
  220. get setStorageKeyLink() {
  221. return `https://${window.location.host}/#/reader?setStorageAccessKey=${utils.toBase58(this.serverStorageKey)}`;
  222. }
  223. get predefineTextColors() {
  224. return defPalette.concat([
  225. '#ffffff',
  226. '#000000',
  227. '#202020',
  228. '#323232',
  229. '#aaaaaa',
  230. '#00c0c0',
  231. '#ebe2c9',
  232. '#cfdc99',
  233. '#478355',
  234. '#909080',
  235. ]);
  236. }
  237. get predefineBackgroundColors() {
  238. return defPalette.concat([
  239. '#ffffff',
  240. '#000000',
  241. '#202020',
  242. '#ebe2c9',
  243. '#cfdc99',
  244. '#478355',
  245. '#a6caf0',
  246. '#909080',
  247. '#808080',
  248. '#c8c8c8',
  249. ]);
  250. }
  251. colorPanStyle(type) {
  252. let result = 'width: 30px; height: 30px; border: 1px solid black; border-radius: 4px;';
  253. switch (type) {
  254. case 'text':
  255. result += `background-color: ${this.textColor};`
  256. break;
  257. case 'bg':
  258. result += `background-color: ${this.backgroundColor};`
  259. break;
  260. }
  261. return result;
  262. }
  263. needReload() {
  264. this.$notify.warning({message: 'Необходимо обновить страницу (F5), чтобы изменения возымели эффект'});
  265. }
  266. needTextReload() {
  267. this.$notify.warning({message: 'Необходимо обновить книгу в обход кэша, чтобы изменения возымели эффект'});
  268. }
  269. close() {
  270. this.$emit('settings-toggle');
  271. }
  272. async setDefaults() {
  273. try {
  274. if (await this.$confirm('Подтвердите установку настроек по умолчанию:', '', {
  275. confirmButtonText: 'OK',
  276. cancelButtonText: 'Отмена',
  277. customClass: 'prompt-dialog',
  278. type: 'warning'
  279. })) {
  280. this.form = Object.assign({}, rstore.settingDefaults);
  281. for (let prop in rstore.settingDefaults) {
  282. this[prop] = this.form[prop];
  283. }
  284. }
  285. } catch (e) {
  286. //
  287. }
  288. }
  289. changeShowToolButton(buttonName) {
  290. this.showToolButton = Object.assign({}, this.showToolButton, {[buttonName]: !this.showToolButton[buttonName]});
  291. }
  292. async addProfile() {
  293. try {
  294. if (Object.keys(this.profiles).length >= 100) {
  295. this.$alert('Достигнут предел количества профилей', 'Ошибка');
  296. return;
  297. }
  298. const result = await this.$prompt('Введите произвольное название для профиля устройства:', '', {
  299. confirmButtonText: 'OK',
  300. cancelButtonText: 'Отмена',
  301. inputValidator: (str) => { if (!str) return 'Название не должно быть пустым'; else if (str.length > 50) return 'Слишком длинное название'; else return true; },
  302. customClass: 'prompt-dialog',
  303. });
  304. if (result.value) {
  305. if (this.profiles[result.value]) {
  306. this.$alert('Такой профиль уже существует', 'Ошибка');
  307. } else {
  308. const newProfiles = Object.assign({}, this.profiles, {[result.value]: 1});
  309. this.commit('reader/setAllowProfilesSave', true);
  310. await this.$nextTick();//ждем обработчики watch
  311. this.commit('reader/setProfiles', newProfiles);
  312. await this.$nextTick();//ждем обработчики watch
  313. this.commit('reader/setAllowProfilesSave', false);
  314. this.currentProfile = result.value;
  315. }
  316. }
  317. } catch (e) {
  318. //
  319. }
  320. }
  321. async delProfile() {
  322. if (!this.currentProfile)
  323. return;
  324. try {
  325. const result = await this.$prompt(`<b>Предупреждение!</b> Удаление профиля '${this.currentProfile}' необратимо.` +
  326. `<br>Все настройки профиля будут потеряны,<br>однако список читаемых книг сохранится.` +
  327. `<br><br>Введите 'да' для подтверждения удаления:`, '', {
  328. dangerouslyUseHTMLString: true,
  329. confirmButtonText: 'OK',
  330. cancelButtonText: 'Отмена',
  331. inputValidator: (str) => { if (str && str.toLowerCase() === 'да') return true; else return 'Удаление не подтверждено'; },
  332. customClass: 'prompt-dialog',
  333. type: 'warning',
  334. });
  335. if (result.value && result.value.toLowerCase() == 'да') {
  336. if (this.profiles[this.currentProfile]) {
  337. const newProfiles = Object.assign({}, this.profiles);
  338. delete newProfiles[this.currentProfile];
  339. this.commit('reader/setAllowProfilesSave', true);
  340. await this.$nextTick();//ждем обработчики watch
  341. this.commit('reader/setProfiles', newProfiles);
  342. await this.$nextTick();//ждем обработчики watch
  343. this.commit('reader/setAllowProfilesSave', false);
  344. this.currentProfile = '';
  345. }
  346. }
  347. } catch (e) {
  348. //
  349. }
  350. }
  351. async delAllProfiles() {
  352. if (!Object.keys(this.profiles).length)
  353. return;
  354. try {
  355. const result = await this.$prompt(`<b>Предупреждение!</b> Удаление ВСЕХ профилей с настройками необратимо.` +
  356. `<br><br>Введите 'да' для подтверждения удаления:`, '', {
  357. dangerouslyUseHTMLString: true,
  358. confirmButtonText: 'OK',
  359. cancelButtonText: 'Отмена',
  360. inputValidator: (str) => { if (str && str.toLowerCase() === 'да') return true; else return 'Удаление не подтверждено'; },
  361. customClass: 'prompt-dialog',
  362. type: 'warning',
  363. });
  364. if (result.value && result.value.toLowerCase() == 'да') {
  365. this.commit('reader/setAllowProfilesSave', true);
  366. await this.$nextTick();//ждем обработчики watch
  367. this.commit('reader/setProfiles', {});
  368. await this.$nextTick();//ждем обработчики watch
  369. this.commit('reader/setAllowProfilesSave', false);
  370. this.currentProfile = '';
  371. }
  372. } catch (e) {
  373. //
  374. }
  375. }
  376. async copyToClip(text, prefix) {
  377. const result = await utils.copyTextToClipboard(text);
  378. const suf = (prefix.substr(-1) == 'а' ? 'а' : '');
  379. const msg = (result ? `${prefix} успешно скопирован${suf} в буфер обмена` : 'Копирование не удалось');
  380. if (result)
  381. this.$notify.success({message: msg});
  382. else
  383. this.$notify.error({message: msg});
  384. }
  385. async showServerStorageKey() {
  386. this.serverStorageKeyVisible = !this.serverStorageKeyVisible;
  387. }
  388. async enterServerStorageKey(key) {
  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 && utils.fromBase58(str).length == 32) return true; else return 'Неверный формат ключа'; },
  396. inputValue: (key && _.isString(key) ? key : null),
  397. customClass: 'prompt-dialog',
  398. type: 'warning',
  399. });
  400. if (result.value && utils.fromBase58(result.value).length == 32) {
  401. this.commit('reader/setServerStorageKey', result.value);
  402. }
  403. } catch (e) {
  404. //
  405. }
  406. }
  407. async generateServerStorageKey() {
  408. try {
  409. const result = await this.$prompt(`<b>Предупреждение!</b> Генерация нового ключа доступа приведет к удалению всех профилей и читаемых книг в читалке.` +
  410. `<br><br>Введите 'да' для подтверждения генерации нового ключа:`, '', {
  411. dangerouslyUseHTMLString: true,
  412. confirmButtonText: 'OK',
  413. cancelButtonText: 'Отмена',
  414. inputValidator: (str) => { if (str && str.toLowerCase() === 'да') return true; else return 'Генерация не подтверждена'; },
  415. customClass: 'prompt-dialog',
  416. type: 'warning',
  417. });
  418. if (result.value && result.value.toLowerCase() == 'да') {
  419. this.$root.$emit('generateNewServerStorageKey');
  420. }
  421. } catch (e) {
  422. //
  423. }
  424. }
  425. keyHook(event) {
  426. if (event.type == 'keydown' && event.code == 'Escape') {
  427. this.close();
  428. }
  429. return true;
  430. }
  431. }
  432. //-----------------------------------------------------------------------------
  433. </script>
  434. <style scoped>
  435. .tab {
  436. justify-content: initial;
  437. }
  438. .tab-panel {
  439. overflow-x: hidden;
  440. overflow-y: auto;
  441. font-size: 90%;
  442. padding: 0 10px 15px 10px;
  443. }
  444. .part-header {
  445. border-top: 2px solid #bbbbbb;
  446. font-weight: bold;
  447. font-size: 110%;
  448. margin-top: 15px;
  449. margin-bottom: 5px;
  450. }
  451. .item {
  452. width: 100%;
  453. margin-top: 5px;
  454. margin-bottom: 5px;
  455. }
  456. .label-1 {
  457. width: 75px;
  458. }
  459. .label-2 {
  460. width: 100px;
  461. }
  462. .label-1, .label-2 {
  463. display: flex;
  464. flex-direction: column;
  465. justify-content: center;
  466. text-align: right;
  467. margin-right: 10px;
  468. overflow: hidden;
  469. }
  470. .text {
  471. font-size: 90%;
  472. line-height: 130%;
  473. }
  474. .button {
  475. margin: 3px 15px 3px 0;
  476. padding: 0 5px 0 5px;
  477. }
  478. .copy-icon {
  479. margin-left: 5px;
  480. cursor: pointer;
  481. font-size: 120%;
  482. color: blue;
  483. }
  484. .input {
  485. max-width: 150px;
  486. }
  487. .no-mp {
  488. margin: 0;
  489. padding: 0;
  490. }
  491. .col-left-2 {
  492. width: 150px;
  493. }
  494. </style>
  495. <style scoped>
  496. /* TODO: REMOVE */
  497. .el-form {
  498. border-top: 2px solid #bbbbbb;
  499. margin-bottom: 5px;
  500. }
  501. .el-form-item {
  502. padding: 0 !important;
  503. margin: 0 !important;
  504. margin-bottom: 5px !important;
  505. }
  506. .color-picked {
  507. margin-left: 10px;
  508. position: relative;
  509. top: -11px;
  510. }
  511. .el-tabs {
  512. flex: 1;
  513. display: flex;
  514. }
  515. .el-tab-pane {
  516. flex: 1;
  517. display: flex;
  518. flex-direction: column;
  519. width: 420px;
  520. overflow-y: auto;
  521. padding: 15px;
  522. }
  523. </style>
  524. <style>
  525. .prompt-dialog {
  526. width: 100% !important;
  527. max-width: 450px;
  528. }
  529. </style>