SettingsPage.vue 20 KB

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