SettingsPage.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  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 profilesArray() {
  162. const result = Object.keys(this.profiles)
  163. result.sort();
  164. return result;
  165. }
  166. get currentProfile() {
  167. return this.$store.state.reader.currentProfile;
  168. }
  169. set currentProfile(newValue) {
  170. this.commit('reader/setCurrentProfile', newValue);
  171. }
  172. get partialStorageKey() {
  173. return this.serverStorageKey.substr(0, 7) + '***';
  174. }
  175. get serverStorageKey() {
  176. return this.$store.state.reader.serverStorageKey;
  177. }
  178. get setStorageKeyLink() {
  179. return `https://${window.location.host}/#/reader?setStorageAccessKey=${utils.toBase58(this.serverStorageKey)}`;
  180. }
  181. get predefineTextColors() {
  182. return [
  183. '#ffffff',
  184. '#000000',
  185. '#202020',
  186. '#323232',
  187. '#aaaaaa',
  188. '#00c0c0',
  189. ];
  190. }
  191. get predefineBackgroundColors() {
  192. return [
  193. '#ffffff',
  194. '#000000',
  195. '#202020',
  196. '#ebe2c9',
  197. '#cfdc99',
  198. '#478355',
  199. '#a6caf0',
  200. '#909080',
  201. '#808080',
  202. '#c8c8c8',
  203. ];
  204. }
  205. needReload() {
  206. this.$notify.warning({message: 'Необходимо обновить страницу (F5), чтобы изменения возымели эффект'});
  207. }
  208. needTextReload() {
  209. this.$notify.warning({message: 'Необходимо обновить книгу в обход кэша, чтобы изменения возымели эффект'});
  210. }
  211. close() {
  212. this.$emit('settings-toggle');
  213. }
  214. async setDefaults() {
  215. try {
  216. if (await this.$confirm('Подтвердите установку настроек по умолчанию:', '', {
  217. confirmButtonText: 'OK',
  218. cancelButtonText: 'Отмена',
  219. customClass: 'prompt-dialog',
  220. type: 'warning'
  221. })) {
  222. this.form = Object.assign({}, rstore.settingDefaults);
  223. for (let prop in rstore.settingDefaults) {
  224. this[prop] = this.form[prop];
  225. }
  226. }
  227. } catch (e) {
  228. //
  229. }
  230. }
  231. changeShowToolButton(buttonName) {
  232. this.showToolButton = Object.assign({}, this.showToolButton, {[buttonName]: !this.showToolButton[buttonName]});
  233. }
  234. async addProfile() {
  235. try {
  236. if (Object.keys(this.profiles).length >= 100) {
  237. this.$alert('Достигнут предел количества профилей', 'Ошибка');
  238. return;
  239. }
  240. const result = await this.$prompt('Введите произвольное название для профиля устройства:', '', {
  241. confirmButtonText: 'OK',
  242. cancelButtonText: 'Отмена',
  243. inputValidator: (str) => { if (!str) return 'Название не должно быть пустым'; else if (str.length > 50) return 'Слишком длинное название'; else return true; },
  244. customClass: 'prompt-dialog',
  245. });
  246. if (result.value) {
  247. if (this.profiles[result.value]) {
  248. this.$alert('Такой профиль уже существует', 'Ошибка');
  249. } else {
  250. const newProfiles = Object.assign({}, this.profiles, {[result.value]: 1});
  251. this.commit('reader/setAllowProfilesSave', true);
  252. await this.$nextTick();//ждем обработчики watch
  253. this.commit('reader/setProfiles', newProfiles);
  254. await this.$nextTick();//ждем обработчики watch
  255. this.commit('reader/setAllowProfilesSave', false);
  256. this.currentProfile = result.value;
  257. }
  258. }
  259. } catch (e) {
  260. //
  261. }
  262. }
  263. async delProfile() {
  264. if (!this.currentProfile)
  265. return;
  266. try {
  267. const result = await this.$prompt(`<b>Предупреждение!</b> Удаление профиля '${this.currentProfile}' необратимо.` +
  268. `<br>Все настройки профиля будут потеряны,<br>однако список читаемых книг сохранится.` +
  269. `<br><br>Введите 'да' для подтверждения удаления:`, '', {
  270. dangerouslyUseHTMLString: true,
  271. confirmButtonText: 'OK',
  272. cancelButtonText: 'Отмена',
  273. inputValidator: (str) => { if (str && str.toLowerCase() === 'да') return true; else return 'Удаление не подтверждено'; },
  274. customClass: 'prompt-dialog',
  275. type: 'warning',
  276. });
  277. if (result.value && result.value.toLowerCase() == 'да') {
  278. if (this.profiles[this.currentProfile]) {
  279. const newProfiles = Object.assign({}, this.profiles);
  280. delete newProfiles[this.currentProfile];
  281. this.commit('reader/setAllowProfilesSave', true);
  282. await this.$nextTick();//ждем обработчики watch
  283. this.commit('reader/setProfiles', newProfiles);
  284. await this.$nextTick();//ждем обработчики watch
  285. this.commit('reader/setAllowProfilesSave', false);
  286. this.currentProfile = '';
  287. }
  288. }
  289. } catch (e) {
  290. //
  291. }
  292. }
  293. async delAllProfiles() {
  294. if (!Object.keys(this.profiles).length)
  295. return;
  296. try {
  297. const result = await this.$prompt(`<b>Предупреждение!</b> Удаление ВСЕХ профилей с настройками необратимо.` +
  298. `<br><br>Введите 'да' для подтверждения удаления:`, '', {
  299. dangerouslyUseHTMLString: true,
  300. confirmButtonText: 'OK',
  301. cancelButtonText: 'Отмена',
  302. inputValidator: (str) => { if (str && str.toLowerCase() === 'да') return true; else return 'Удаление не подтверждено'; },
  303. customClass: 'prompt-dialog',
  304. type: 'warning',
  305. });
  306. if (result.value && result.value.toLowerCase() == 'да') {
  307. this.commit('reader/setAllowProfilesSave', true);
  308. await this.$nextTick();//ждем обработчики watch
  309. this.commit('reader/setProfiles', {});
  310. await this.$nextTick();//ждем обработчики watch
  311. this.commit('reader/setAllowProfilesSave', false);
  312. this.currentProfile = '';
  313. }
  314. } catch (e) {
  315. //
  316. }
  317. }
  318. async copyToClip(text, prefix) {
  319. const result = await utils.copyTextToClipboard(text);
  320. const suf = (prefix.substr(-1) == 'а' ? 'а' : '');
  321. const msg = (result ? `${prefix} успешно скопирован${suf} в буфер обмена` : 'Копирование не удалось');
  322. if (result)
  323. this.$notify.success({message: msg});
  324. else
  325. this.$notify.error({message: msg});
  326. }
  327. async showServerStorageKey() {
  328. this.serverStorageKeyVisible = !this.serverStorageKeyVisible;
  329. }
  330. async enterServerStorageKey(key) {
  331. try {
  332. const result = await this.$prompt(`<b>Предупреждение!</b> Изменение ключа доступа приведет к замене всех профилей и читаемых книг в читалке.` +
  333. `<br><br>Введите новый ключ доступа:`, '', {
  334. dangerouslyUseHTMLString: true,
  335. confirmButtonText: 'OK',
  336. cancelButtonText: 'Отмена',
  337. inputValidator: (str) => { if (str && utils.fromBase58(str).length == 32) return true; else return 'Неверный формат ключа'; },
  338. inputValue: (key && _.isString(key) ? key : null),
  339. customClass: 'prompt-dialog',
  340. type: 'warning',
  341. });
  342. if (result.value && utils.fromBase58(result.value).length == 32) {
  343. this.commit('reader/setServerStorageKey', result.value);
  344. }
  345. } catch (e) {
  346. //
  347. }
  348. }
  349. async generateServerStorageKey() {
  350. try {
  351. const result = await this.$prompt(`<b>Предупреждение!</b> Генерация нового ключа доступа приведет к удалению всех профилей и читаемых книг в читалке.` +
  352. `<br><br>Введите 'да' для подтверждения генерации нового ключа:`, '', {
  353. dangerouslyUseHTMLString: true,
  354. confirmButtonText: 'OK',
  355. cancelButtonText: 'Отмена',
  356. inputValidator: (str) => { if (str && str.toLowerCase() === 'да') return true; else return 'Генерация не подтверждена'; },
  357. customClass: 'prompt-dialog',
  358. type: 'warning',
  359. });
  360. if (result.value && result.value.toLowerCase() == 'да') {
  361. this.$root.$emit('generateNewServerStorageKey');
  362. }
  363. } catch (e) {
  364. //
  365. }
  366. }
  367. keyHook(event) {
  368. if (event.type == 'keydown' && event.code == 'Escape') {
  369. this.close();
  370. }
  371. return true;
  372. }
  373. }
  374. //-----------------------------------------------------------------------------
  375. </script>
  376. <style scoped>
  377. .tab {
  378. justify-content: initial;
  379. }
  380. .tab-panel {
  381. overflow-x: hidden;
  382. overflow-y: auto;
  383. font-size: 90%;
  384. padding: 15px 10px 15px 10px;
  385. }
  386. .part-header {
  387. border-top: 2px solid #bbbbbb;
  388. font-weight: bold;
  389. font-size: 110%;
  390. margin-bottom: 5px;
  391. }
  392. .item {
  393. width: 100%;
  394. margin-top: 5px;
  395. margin-bottom: 5px;
  396. }
  397. .label {
  398. display: flex;
  399. flex-direction: column;
  400. justify-content: center;
  401. text-align: right;
  402. margin-right: 10px;
  403. }
  404. .text {
  405. font-size: 90%;
  406. line-height: 130%;
  407. }
  408. </style>
  409. <style scoped>
  410. /* TODO: REMOVE */
  411. .text {
  412. font-size: 90%;
  413. line-height: 130%;
  414. }
  415. .el-form {
  416. border-top: 2px solid #bbbbbb;
  417. margin-bottom: 5px;
  418. }
  419. .el-form-item {
  420. padding: 0 !important;
  421. margin: 0 !important;
  422. margin-bottom: 5px !important;
  423. }
  424. .color-picked {
  425. margin-left: 10px;
  426. position: relative;
  427. top: -11px;
  428. }
  429. .el-tabs {
  430. flex: 1;
  431. display: flex;
  432. }
  433. .el-tab-pane {
  434. flex: 1;
  435. display: flex;
  436. flex-direction: column;
  437. width: 420px;
  438. overflow-y: auto;
  439. padding: 15px;
  440. }
  441. .center {
  442. text-align: center;
  443. }
  444. </style>
  445. <style>
  446. .prompt-dialog {
  447. width: 100% !important;
  448. max-width: 450px;
  449. }
  450. </style>