SettingsPage.vue 18 KB

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