SettingsPage.vue 20 KB

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