SettingsPage.vue 18 KB

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