SettingsPage.vue 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  1. <template>
  2. <Window ref="window" width="600px" @close="close">
  3. <template #header>
  4. Настройки
  5. </template>
  6. <div class="col row">
  7. <a ref="download" style="display: none;" target="_blank"></a>
  8. <div class="full-height">
  9. <q-tabs
  10. ref="tabs"
  11. v-model="selectedTab"
  12. class="bg-grey-3 text-black"
  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="toolbar" 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="convert" icon="la la-magic" label="Конвертир." />
  30. <q-tab class="tab" name="others" icon="la la-list-ul" label="Прочее" />
  31. <q-tab class="tab" name="reset" icon="la la-broom" label="Сброс" />
  32. <div v-show="tabsScrollable" class="q-pt-lg" />
  33. </q-tabs>
  34. </div>
  35. <div class="col fit">
  36. <!-- Профили --------------------------------------------------------------------->
  37. <div v-if="selectedTab == 'profiles'" class="fit tab-panel">
  38. @@include('./ProfilesTab.inc');
  39. </div>
  40. <!-- Вид ------------------------------------------------------------------------->
  41. <div v-if="selectedTab == 'view'" class="fit column">
  42. <q-tabs
  43. v-model="selectedViewTab"
  44. active-color="black"
  45. active-bg-color="white"
  46. indicator-color="white"
  47. dense
  48. no-caps
  49. class="no-mp bg-grey-4 text-grey-7"
  50. >
  51. <q-tab name="mode" label="Режим" />
  52. <q-tab name="color" label="Цвет" />
  53. <q-tab name="font" label="Шрифт" />
  54. <q-tab name="text" label="Текст" />
  55. <q-tab name="status" label="Строка статуса" />
  56. </q-tabs>
  57. <div class="q-mb-sm" />
  58. <div class="col tab-panel">
  59. <div v-if="selectedViewTab == 'mode'">
  60. @@include('./ViewTab/Mode.inc');
  61. </div>
  62. <div v-if="selectedViewTab == 'color'">
  63. @@include('./ViewTab/Color.inc');
  64. </div>
  65. <div v-if="selectedViewTab == 'font'">
  66. @@include('./ViewTab/Font.inc');
  67. </div>
  68. <div v-if="selectedViewTab == 'text'">
  69. @@include('./ViewTab/Text.inc');
  70. </div>
  71. <div v-if="selectedViewTab == 'status'">
  72. @@include('./ViewTab/Status.inc');
  73. </div>
  74. </div>
  75. </div>
  76. <!-- Кнопки ---------------------------------------------------------------------->
  77. <div v-if="selectedTab == 'toolbar'" class="fit tab-panel">
  78. @@include('./ToolBarTab.inc');
  79. </div>
  80. <!-- Управление ------------------------------------------------------------------>
  81. <div v-if="selectedTab == 'keys'" class="fit column">
  82. @@include('./KeysTab.inc');
  83. </div>
  84. <!-- Листание -------------------------------------------------------------------->
  85. <div v-if="selectedTab == 'pagemove'" class="fit tab-panel">
  86. @@include('./PageMoveTab.inc');
  87. </div>
  88. <!-- Конвертирование ------------------------------------------------------------->
  89. <div v-if="selectedTab == 'convert'" class="fit tab-panel">
  90. @@include('./ConvertTab.inc');
  91. </div>
  92. <!-- Прочее ---------------------------------------------------------------------->
  93. <div v-if="selectedTab == 'others'" class="fit tab-panel">
  94. @@include('./OthersTab.inc');
  95. </div>
  96. <!-- Сброс ----------------------------------------------------------------------->
  97. <div v-if="selectedTab == 'reset'" class="fit tab-panel">
  98. @@include('./ResetTab.inc');
  99. </div>
  100. </div>
  101. </div>
  102. </Window>
  103. </template>
  104. <script>
  105. //-----------------------------------------------------------------------------
  106. import { ref, watch } from 'vue';
  107. import vueComponent from '../../vueComponent.js';
  108. import _ from 'lodash';
  109. import * as utils from '../../../share/utils';
  110. import * as cryptoUtils from '../../../share/cryptoUtils';
  111. import Window from '../../share/Window.vue';
  112. import NumInput from '../../share/NumInput.vue';
  113. import UserHotKeys from './UserHotKeys/UserHotKeys.vue';
  114. import wallpaperStorage from '../share/wallpaperStorage';
  115. import readerApi from '../../../api/reader';
  116. import rstore from '../../../store/modules/reader';
  117. import defPalette from './defPalette';
  118. const hex = /^#[0-9a-fA-F]{3}([0-9a-fA-F]{3})?$/;
  119. const componentOptions = {
  120. components: {
  121. Window,
  122. NumInput,
  123. UserHotKeys,
  124. },
  125. data: function() {
  126. return Object.assign({}, rstore.settingDefaults);
  127. },
  128. watch: {
  129. settings: function() {
  130. this.settingsChanged();
  131. },
  132. form: function(newValue) {
  133. if (this.inited) {
  134. this.commit('reader/setSettings', _.cloneDeep(newValue));
  135. }
  136. },
  137. fontBold: function(newValue) {
  138. this.fontWeight = (newValue ? 'bold' : '');
  139. },
  140. fontItalic: function(newValue) {
  141. this.fontStyle = (newValue ? 'italic' : '');
  142. },
  143. vertShift: function(newValue) {
  144. const font = (this.webFontName ? this.webFontName : this.fontName);
  145. if (this.fontShifts[font] != newValue || this.fontVertShift != newValue) {
  146. this.fontShifts = Object.assign({}, this.fontShifts, {[font]: newValue});
  147. this.fontVertShift = newValue;
  148. }
  149. },
  150. fontName: function(newValue) {
  151. const font = (this.webFontName ? this.webFontName : newValue);
  152. this.vertShift = this.fontShifts[font] || 0;
  153. },
  154. webFontName: function(newValue) {
  155. const font = (newValue ? newValue : this.fontName);
  156. this.vertShift = this.fontShifts[font] || 0;
  157. },
  158. wallpaper: function(newValue) {
  159. if (newValue != '' && this.pageChangeAnimation == 'flip')
  160. this.pageChangeAnimation = '';
  161. },
  162. dualPageMode(newValue) {
  163. if (newValue && this.pageChangeAnimation == 'flip' || this.pageChangeAnimation == 'rightShift')
  164. this.pageChangeAnimation = '';
  165. },
  166. textColor: function(newValue) {
  167. this.textColorFiltered = newValue;
  168. },
  169. textColorFiltered: function(newValue) {
  170. if (hex.test(newValue))
  171. this.textColor = newValue;
  172. },
  173. backgroundColor: function(newValue) {
  174. this.bgColorFiltered = newValue;
  175. },
  176. bgColorFiltered: function(newValue) {
  177. if (hex.test(newValue))
  178. this.backgroundColor = newValue;
  179. },
  180. dualDivColor(newValue) {
  181. this.dualDivColorFiltered = newValue;
  182. },
  183. dualDivColorFiltered(newValue) {
  184. if (hex.test(newValue))
  185. this.dualDivColor = newValue;
  186. },
  187. statusBarColor(newValue) {
  188. this.statusBarColorFiltered = newValue;
  189. },
  190. statusBarColorFiltered(newValue) {
  191. if (hex.test(newValue))
  192. this.statusBarColor = newValue;
  193. },
  194. },
  195. };
  196. class SettingsPage {
  197. _options = componentOptions;
  198. selectedTab = 'profiles';
  199. selectedViewTab = 'mode';
  200. selectedKeysTab = 'mouse';
  201. fontBold = false;
  202. fontItalic = false;
  203. vertShift = 0;
  204. tabsScrollable = false;
  205. textColorFiltered = '';
  206. bgColorFiltered = '';
  207. dualDivColorFiltered = '';
  208. webFonts = [];
  209. fonts = [];
  210. serverStorageKeyVisible = false;
  211. toolButtons = [];
  212. rstore = {};
  213. setup() {
  214. const settingsProps = { form: ref({}) };
  215. for (let prop in rstore.settingDefaults) {
  216. settingsProps[prop] = ref(_.cloneDeep(rstore.settingDefaults[prop]));
  217. watch(settingsProps[prop], (newValue) => {
  218. settingsProps.form.value = Object.assign({}, settingsProps.form.value, {[prop]: newValue});
  219. }, {deep: true});
  220. }
  221. return settingsProps;
  222. }
  223. created() {
  224. this.commit = this.$store.commit;
  225. this.reader = this.$store.state.reader;
  226. this.form = {};
  227. this.rstore = rstore;
  228. this.toolButtons = rstore.toolButtons;
  229. this.settingsChanged();
  230. }
  231. mounted() {
  232. this.$watch(
  233. '$refs.tabs.scrollable',
  234. (newValue) => {
  235. this.tabsScrollable = newValue && !this.$root.isMobileDevice;
  236. }
  237. );
  238. }
  239. init() {
  240. this.$refs.window.init();
  241. this.inited = true;
  242. }
  243. settingsChanged() {
  244. if (_.isEqual(this.form, this.settings))
  245. return;
  246. this.form = Object.assign({}, this.settings);
  247. for (const prop in rstore.settingDefaults) {
  248. this[prop] = _.cloneDeep(this.form[prop]);
  249. }
  250. this.fontBold = (this.fontWeight == 'bold');
  251. this.fontItalic = (this.fontStyle == 'italic');
  252. this.fonts = rstore.fonts;
  253. this.webFonts = rstore.webFonts;
  254. const font = (this.webFontName ? this.webFontName : this.fontName);
  255. this.vertShift = this.fontShifts[font] || 0;
  256. this.textColorFiltered = this.textColor;
  257. this.bgColorFiltered = this.backgroundColor;
  258. this.dualDivColorFiltered = this.dualDivColor;
  259. this.statusBarColorFiltered = this.statusBarColor;
  260. }
  261. get mode() {
  262. return this.$store.state.config.mode;
  263. }
  264. get isExternalConverter() {
  265. return this.$store.state.config.useExternalBookConverter;
  266. }
  267. get settings() {
  268. return this.$store.state.reader.settings;
  269. }
  270. get serverSyncEnabled() {
  271. return this.$store.state.reader.serverSyncEnabled;
  272. }
  273. set serverSyncEnabled(newValue) {
  274. this.commit('reader/setServerSyncEnabled', newValue);
  275. }
  276. get profiles() {
  277. return this.$store.state.reader.profiles;
  278. }
  279. get currentProfileOptions() {
  280. const profNames = Object.keys(this.profiles)
  281. profNames.sort();
  282. let result = [{label: 'Нет', value: ''}];
  283. profNames.forEach(name => {
  284. result.push({label: name, value: name});
  285. });
  286. return result;
  287. }
  288. get wallpaperOptions() {
  289. let result = [{label: 'Нет', value: ''}];
  290. const userWallpapers = _.cloneDeep(this.userWallpapers);
  291. userWallpapers.sort((a, b) => a.label.localeCompare(b.label));
  292. for (const wp of userWallpapers) {
  293. if (wallpaperStorage.keyExists(wp.cssClass))
  294. result.push({label: wp.label, value: wp.cssClass});
  295. }
  296. for (let i = 1; i <= 17; i++) {
  297. result.push({label: i, value: `paper${i}`});
  298. }
  299. return result;
  300. }
  301. get fontsOptions() {
  302. let result = [];
  303. this.fonts.forEach(font => {
  304. result.push({label: (font.label ? font.label : font.name), value: font.name});
  305. });
  306. return result;
  307. }
  308. get webFontsOptions() {
  309. let result = [{label: 'Нет', value: ''}];
  310. this.webFonts.forEach(font => {
  311. result.push({label: font.name, value: font.name});
  312. });
  313. return result;
  314. }
  315. get pageChangeAnimationOptions() {
  316. let result = [
  317. {label: 'Нет', value: ''},
  318. {label: 'Вверх-вниз', value: 'downShift'},
  319. (!this.dualPageMode ? {label: 'Вправо-влево', value: 'rightShift'} : null),
  320. {label: 'Протаивание', value: 'thaw'},
  321. {label: 'Мерцание', value: 'blink'},
  322. {label: 'Вращение', value: 'rotate'},
  323. (this.wallpaper == '' && !this.dualPageMode ? {label: 'Листание', value: 'flip'} : null),
  324. ];
  325. result = result.filter(v => v);
  326. return result;
  327. }
  328. get currentProfile() {
  329. return this.$store.state.reader.currentProfile;
  330. }
  331. set currentProfile(newValue) {
  332. this.commit('reader/setCurrentProfile', newValue);
  333. }
  334. get partialStorageKey() {
  335. return this.serverStorageKey.substr(0, 7) + '***';
  336. }
  337. get serverStorageKey() {
  338. return this.$store.state.reader.serverStorageKey;
  339. }
  340. get setStorageKeyLink() {
  341. return `https://${window.location.host}/#/reader?setStorageAccessKey=${utils.toBase58(this.serverStorageKey)}`;
  342. }
  343. get predefineTextColors() {
  344. return defPalette.concat([
  345. '#ffffff',
  346. '#000000',
  347. '#202020',
  348. '#323232',
  349. '#aaaaaa',
  350. '#00c0c0',
  351. '#ebe2c9',
  352. '#cfdc99',
  353. '#478355',
  354. '#909080',
  355. ]);
  356. }
  357. get predefineBackgroundColors() {
  358. return defPalette.concat([
  359. '#ffffff',
  360. '#000000',
  361. '#202020',
  362. '#ebe2c9',
  363. '#cfdc99',
  364. '#478355',
  365. '#a6caf0',
  366. '#909080',
  367. '#808080',
  368. '#c8c8c8',
  369. ]);
  370. }
  371. colorPanStyle(type) {
  372. let result = 'width: 30px; height: 30px; border: 1px solid black; border-radius: 4px;';
  373. switch (type) {
  374. case 'text':
  375. result += `background-color: ${this.textColor};`
  376. break;
  377. case 'bg':
  378. result += `background-color: ${this.backgroundColor};`
  379. break;
  380. case 'div':
  381. result += `background-color: ${this.dualDivColor};`
  382. break;
  383. case 'statusbar':
  384. result += `background-color: ${this.statusBarColor};`
  385. break;
  386. }
  387. return result;
  388. }
  389. needReload() {
  390. this.$root.notify.warning('Необходимо обновить страницу (F5), чтобы изменения возымели эффект');
  391. }
  392. needTextReload() {
  393. this.$root.notify.warning('Необходимо обновить книгу в обход кэша, чтобы изменения возымели эффект');
  394. }
  395. close() {
  396. this.$emit('do-action', {action: 'settings'});
  397. }
  398. async setDefaults() {
  399. try {
  400. if (await this.$root.stdDialog.confirm('Подтвердите установку настроек по умолчанию:', ' ')) {
  401. this.form = Object.assign({}, rstore.settingDefaults);
  402. for (let prop in rstore.settingDefaults) {
  403. this[prop] = this.form[prop];
  404. }
  405. }
  406. } catch (e) {
  407. //
  408. }
  409. }
  410. async addProfile() {
  411. try {
  412. if (Object.keys(this.profiles).length >= 100) {
  413. this.$root.stdDialog.alert('Достигнут предел количества профилей', 'Ошибка');
  414. return;
  415. }
  416. const result = await this.$root.stdDialog.prompt('Введите произвольное название для профиля устройства:', ' ', {
  417. inputValidator: (str) => { if (!str) return 'Название не должно быть пустым'; else if (str.length > 50) return 'Слишком длинное название'; else return true; },
  418. });
  419. if (result && result.value) {
  420. if (this.profiles[result.value]) {
  421. this.$root.stdDialog.alert('Такой профиль уже существует', 'Ошибка');
  422. } else {
  423. const newProfiles = Object.assign({}, this.profiles, {[result.value]: 1});
  424. this.commit('reader/setAllowProfilesSave', true);
  425. await this.$nextTick();//ждем обработчики watch
  426. this.commit('reader/setProfiles', newProfiles);
  427. await this.$nextTick();//ждем обработчики watch
  428. this.commit('reader/setAllowProfilesSave', false);
  429. this.currentProfile = result.value;
  430. }
  431. }
  432. } catch (e) {
  433. //
  434. }
  435. }
  436. async delProfile() {
  437. if (!this.currentProfile)
  438. return;
  439. try {
  440. const result = await this.$root.stdDialog.prompt(`<b>Предупреждение!</b> Удаление профиля '${this.$root.sanitize(this.currentProfile)}' необратимо.` +
  441. `<br>Все настройки профиля будут потеряны, однако список читаемых книг сохранится.` +
  442. `<br><br>Введите 'да' для подтверждения удаления:`, ' ', {
  443. inputValidator: (str) => { if (str && str.toLowerCase() === 'да') return true; else return 'Удаление не подтверждено'; },
  444. });
  445. if (result && result.value && result.value.toLowerCase() == 'да') {
  446. if (this.profiles[this.currentProfile]) {
  447. const newProfiles = Object.assign({}, this.profiles);
  448. delete newProfiles[this.currentProfile];
  449. this.commit('reader/setAllowProfilesSave', true);
  450. await this.$nextTick();//ждем обработчики watch
  451. this.commit('reader/setProfiles', newProfiles);
  452. await this.$nextTick();//ждем обработчики watch
  453. this.commit('reader/setAllowProfilesSave', false);
  454. this.currentProfile = '';
  455. }
  456. }
  457. } catch (e) {
  458. //
  459. }
  460. }
  461. async delAllProfiles() {
  462. if (!Object.keys(this.profiles).length)
  463. return;
  464. try {
  465. const result = await this.$root.stdDialog.prompt(`<b>Предупреждение!</b> Удаление ВСЕХ профилей с настройками необратимо.` +
  466. `<br><br>Введите 'да' для подтверждения удаления:`, ' ', {
  467. inputValidator: (str) => { if (str && str.toLowerCase() === 'да') return true; else return 'Удаление не подтверждено'; },
  468. });
  469. if (result && result.value && result.value.toLowerCase() == 'да') {
  470. this.commit('reader/setAllowProfilesSave', true);
  471. await this.$nextTick();//ждем обработчики watch
  472. this.commit('reader/setProfiles', {});
  473. await this.$nextTick();//ждем обработчики watch
  474. this.commit('reader/setAllowProfilesSave', false);
  475. this.currentProfile = '';
  476. }
  477. } catch (e) {
  478. //
  479. }
  480. }
  481. async copyToClip(text, prefix) {
  482. const result = await utils.copyTextToClipboard(text);
  483. const suf = (prefix.substr(-1) == 'а' ? 'а' : '');
  484. const msg = (result ? `${prefix} успешно скопирован${suf} в буфер обмена` : 'Копирование не удалось');
  485. if (result)
  486. this.$root.notify.success(msg);
  487. else
  488. this.$root.notify.error(msg);
  489. }
  490. async showServerStorageKey() {
  491. this.serverStorageKeyVisible = !this.serverStorageKeyVisible;
  492. }
  493. async enterServerStorageKey(key) {
  494. try {
  495. const result = await this.$root.stdDialog.prompt(`<b>Предупреждение!</b> Изменение ключа доступа приведет к замене всех профилей и читаемых книг в читалке.` +
  496. `<br><br>Введите новый ключ доступа:`, ' ', {
  497. inputValidator: (str) => {
  498. try {
  499. if (str && utils.fromBase58(str).length == 32) {
  500. return true;
  501. }
  502. } catch (e) {
  503. //
  504. }
  505. return 'Неверный формат ключа';
  506. },
  507. inputValue: (key && _.isString(key) ? key : null),
  508. });
  509. if (result && result.value && utils.fromBase58(result.value).length == 32) {
  510. this.commit('reader/setServerStorageKey', result.value);
  511. }
  512. } catch (e) {
  513. //
  514. }
  515. }
  516. async generateServerStorageKey() {
  517. try {
  518. const result = await this.$root.stdDialog.prompt(`<b>Предупреждение!</b> Генерация нового ключа доступа приведет к удалению всех профилей и читаемых книг в читалке.` +
  519. `<br><br>Введите 'да' для подтверждения генерации нового ключа:`, ' ', {
  520. inputValidator: (str) => { if (str && str.toLowerCase() === 'да') return true; else return 'Генерация не подтверждена'; },
  521. });
  522. if (result && result.value && result.value.toLowerCase() == 'да') {
  523. if (this.$root.generateNewServerStorageKey)
  524. this.$root.generateNewServerStorageKey();
  525. }
  526. } catch (e) {
  527. //
  528. }
  529. }
  530. loadWallpaperFileClick() {
  531. this.$refs.file.click();
  532. }
  533. loadWallpaperFile() {
  534. const file = this.$refs.file.files[0];
  535. if (file.size > 10*1024*1024) {
  536. this.$root.stdDialog.alert('Файл обоев не должен превышать в размере 10Mb', 'Ошибка');
  537. return;
  538. }
  539. if (file.type != 'image/png' && file.type != 'image/jpeg') {
  540. this.$root.stdDialog.alert('Файл обоев должен иметь тип PNG или JPEG', 'Ошибка');
  541. return;
  542. }
  543. if (this.userWallpapers.length >= 100) {
  544. this.$root.stdDialog.alert('Превышено максимальное количество пользовательских обоев.', 'Ошибка');
  545. return;
  546. }
  547. this.$refs.file.value = '';
  548. if (file) {
  549. const reader = new FileReader();
  550. reader.onload = (e) => {
  551. (async() => {
  552. const data = e.target.result;
  553. const key = utils.toHex(cryptoUtils.sha256(data));
  554. const label = `#${key.substring(0, 4)}`;
  555. const cssClass = `user-paper${key}`;
  556. const newUserWallpapers = _.cloneDeep(this.userWallpapers);
  557. const index = _.findIndex(newUserWallpapers, (item) => (item.cssClass == cssClass));
  558. if (index < 0)
  559. newUserWallpapers.push({label, cssClass});
  560. if (!wallpaperStorage.keyExists(cssClass)) {
  561. await wallpaperStorage.setData(cssClass, data);
  562. //отправим data на сервер в файл `/upload/${key}`
  563. try {
  564. //const res =
  565. await readerApi.uploadFileBuf(data);
  566. //console.log(res);
  567. } catch (e) {
  568. console.error(e);
  569. }
  570. }
  571. this.userWallpapers = newUserWallpapers;
  572. this.wallpaper = cssClass;
  573. })();
  574. }
  575. reader.readAsDataURL(file);
  576. }
  577. }
  578. async delWallpaper() {
  579. if (this.wallpaper.indexOf('user-paper') == 0) {
  580. const newUserWallpapers = [];
  581. for (const wp of this.userWallpapers) {
  582. if (wp.cssClass != this.wallpaper) {
  583. newUserWallpapers.push(wp);
  584. }
  585. }
  586. await wallpaperStorage.removeData(this.wallpaper);
  587. this.userWallpapers = newUserWallpapers;
  588. this.wallpaper = '';
  589. }
  590. }
  591. async downloadWallpaper() {
  592. if (this.wallpaper.indexOf('user-paper') != 0)
  593. return;
  594. try {
  595. const d = this.$refs.download;
  596. const dataUrl = await wallpaperStorage.getData(this.wallpaper);
  597. if (!dataUrl)
  598. throw new Error('Файл обоев не найден');
  599. d.href = dataUrl;
  600. d.download = `wallpaper-#${this.wallpaper.replace('user-paper', '').substring(0, 4)}`;
  601. d.click();
  602. } catch (e) {
  603. this.$root.stdDialog.alert(e.message, 'Ошибка', {color: 'negative'});
  604. }
  605. }
  606. keyHook(event) {
  607. if (!this.$root.stdDialog.active && event.type == 'keydown' && event.key == 'Escape') {
  608. this.close();
  609. }
  610. return true;
  611. }
  612. }
  613. export default vueComponent(SettingsPage);
  614. //-----------------------------------------------------------------------------
  615. </script>
  616. <style scoped>
  617. .tab {
  618. justify-content: initial;
  619. }
  620. .tab-panel {
  621. overflow-x: hidden;
  622. overflow-y: auto;
  623. font-size: 90%;
  624. padding: 0 10px 15px 10px;
  625. }
  626. .part-header {
  627. border-top: 2px solid #bbbbbb;
  628. font-weight: bold;
  629. font-size: 110%;
  630. margin-top: 15px;
  631. margin-bottom: 5px;
  632. }
  633. .item {
  634. width: 100%;
  635. margin-top: 5px;
  636. margin-bottom: 5px;
  637. }
  638. .label-1, .label-3, .label-7 {
  639. width: 75px;
  640. }
  641. .label-2, .label-4, .label-5 {
  642. width: 110px;
  643. }
  644. .label-6 {
  645. width: 100px;
  646. }
  647. .label-1, .label-2, .label-3, .label-4, .label-5, .label-6, .label-7 {
  648. display: flex;
  649. flex-direction: column;
  650. justify-content: center;
  651. text-align: right;
  652. margin-right: 10px;
  653. overflow: hidden;
  654. }
  655. .text {
  656. font-size: 90%;
  657. line-height: 130%;
  658. }
  659. .button {
  660. margin: 3px 15px 3px 0;
  661. padding: 0 5px 0 5px;
  662. }
  663. .copy-icon {
  664. margin-left: 5px;
  665. cursor: pointer;
  666. font-size: 120%;
  667. color: blue;
  668. }
  669. .input {
  670. max-width: 150px;
  671. }
  672. .no-mp {
  673. margin: 0;
  674. padding: 0;
  675. }
  676. .col-left {
  677. width: 150px;
  678. }
  679. </style>