SettingsPage.vue 18 KB

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