SettingsPage.vue 28 KB

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