SettingsPage.vue 21 KB

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