SettingsPage.vue 20 KB

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