SettingsPage.vue 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  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 configBucEnabled() {
  285. return this.$store.state.config.bucEnabled;
  286. }
  287. get currentProfileOptions() {
  288. const profNames = Object.keys(this.profiles)
  289. profNames.sort();
  290. let result = [{label: 'Нет', value: ''}];
  291. profNames.forEach(name => {
  292. result.push({label: name, value: name});
  293. });
  294. return result;
  295. }
  296. get wallpaperOptions() {
  297. let result = [{label: 'Нет', value: ''}];
  298. const userWallpapers = _.cloneDeep(this.userWallpapers);
  299. userWallpapers.sort((a, b) => a.label.localeCompare(b.label));
  300. for (const wp of userWallpapers) {
  301. if (wallpaperStorage.keyExists(wp.cssClass))
  302. result.push({label: wp.label, value: wp.cssClass});
  303. }
  304. for (let i = 1; i <= 17; i++) {
  305. result.push({label: i, value: `paper${i}`});
  306. }
  307. return result;
  308. }
  309. get fontsOptions() {
  310. let result = [];
  311. this.fonts.forEach(font => {
  312. result.push({label: (font.label ? font.label : font.name), value: font.name});
  313. });
  314. return result;
  315. }
  316. get webFontsOptions() {
  317. let result = [{label: 'Нет', value: ''}];
  318. this.webFonts.forEach(font => {
  319. result.push({label: font.name, value: font.name});
  320. });
  321. return result;
  322. }
  323. get pageChangeAnimationOptions() {
  324. let result = [
  325. {label: 'Нет', value: ''},
  326. {label: 'Вверх-вниз', value: 'downShift'},
  327. (!this.dualPageMode ? {label: 'Вправо-влево', value: 'rightShift'} : null),
  328. {label: 'Протаивание', value: 'thaw'},
  329. {label: 'Мерцание', value: 'blink'},
  330. {label: 'Вращение', value: 'rotate'},
  331. (this.wallpaper == '' && !this.dualPageMode ? {label: 'Листание', value: 'flip'} : null),
  332. ];
  333. result = result.filter(v => v);
  334. return result;
  335. }
  336. get currentProfile() {
  337. return this.$store.state.reader.currentProfile;
  338. }
  339. set currentProfile(newValue) {
  340. this.commit('reader/setCurrentProfile', newValue);
  341. }
  342. get partialStorageKey() {
  343. return this.serverStorageKey.substr(0, 7) + '***';
  344. }
  345. get serverStorageKey() {
  346. return this.$store.state.reader.serverStorageKey;
  347. }
  348. get setStorageKeyLink() {
  349. return `https://${window.location.host}/#/reader?setStorageAccessKey=${utils.toBase58(this.serverStorageKey)}`;
  350. }
  351. get predefineTextColors() {
  352. return defPalette.concat([
  353. '#ffffff',
  354. '#000000',
  355. '#202020',
  356. '#323232',
  357. '#aaaaaa',
  358. '#00c0c0',
  359. '#ebe2c9',
  360. '#cfdc99',
  361. '#478355',
  362. '#909080',
  363. ]);
  364. }
  365. get predefineBackgroundColors() {
  366. return defPalette.concat([
  367. '#ffffff',
  368. '#000000',
  369. '#202020',
  370. '#ebe2c9',
  371. '#cfdc99',
  372. '#478355',
  373. '#a6caf0',
  374. '#909080',
  375. '#808080',
  376. '#c8c8c8',
  377. ]);
  378. }
  379. colorPanStyle(type) {
  380. let result = 'width: 30px; height: 30px; border: 1px solid black; border-radius: 4px;';
  381. switch (type) {
  382. case 'text':
  383. result += `background-color: ${this.textColor};`
  384. break;
  385. case 'bg':
  386. result += `background-color: ${this.backgroundColor};`
  387. break;
  388. case 'div':
  389. result += `background-color: ${this.dualDivColor};`
  390. break;
  391. case 'statusbar':
  392. result += `background-color: ${this.statusBarColor};`
  393. break;
  394. }
  395. return result;
  396. }
  397. needReload() {
  398. this.$root.notify.warning('Необходимо обновить страницу (F5), чтобы изменения возымели эффект');
  399. }
  400. needTextReload() {
  401. this.$root.notify.warning('Необходимо обновить книгу в обход кэша, чтобы изменения возымели эффект');
  402. }
  403. close() {
  404. this.$emit('do-action', {action: 'settings'});
  405. }
  406. async setDefaults() {
  407. try {
  408. if (await this.$root.stdDialog.confirm('Подтвердите установку настроек по умолчанию:', ' ')) {
  409. this.form = Object.assign({}, rstore.settingDefaults);
  410. for (let prop in rstore.settingDefaults) {
  411. this[prop] = this.form[prop];
  412. }
  413. }
  414. } catch (e) {
  415. //
  416. }
  417. }
  418. async addProfile() {
  419. try {
  420. if (Object.keys(this.profiles).length >= 100) {
  421. this.$root.stdDialog.alert('Достигнут предел количества профилей', 'Ошибка');
  422. return;
  423. }
  424. const result = await this.$root.stdDialog.prompt('Введите произвольное название для профиля устройства:', ' ', {
  425. inputValidator: (str) => { if (!str) return 'Название не должно быть пустым'; else if (str.length > 50) return 'Слишком длинное название'; else return true; },
  426. });
  427. if (result && result.value) {
  428. if (this.profiles[result.value]) {
  429. this.$root.stdDialog.alert('Такой профиль уже существует', 'Ошибка');
  430. } else {
  431. const newProfiles = Object.assign({}, this.profiles, {[result.value]: 1});
  432. this.commit('reader/setAllowProfilesSave', true);
  433. await this.$nextTick();//ждем обработчики watch
  434. this.commit('reader/setProfiles', newProfiles);
  435. await this.$nextTick();//ждем обработчики watch
  436. this.commit('reader/setAllowProfilesSave', false);
  437. this.currentProfile = result.value;
  438. }
  439. }
  440. } catch (e) {
  441. //
  442. }
  443. }
  444. async delProfile() {
  445. if (!this.currentProfile)
  446. return;
  447. try {
  448. const result = await this.$root.stdDialog.prompt(`<b>Предупреждение!</b> Удаление профиля '${this.$root.sanitize(this.currentProfile)}' необратимо.` +
  449. `<br>Все настройки профиля будут потеряны, однако список читаемых книг сохранится.` +
  450. `<br><br>Введите 'да' для подтверждения удаления:`, ' ', {
  451. inputValidator: (str) => { if (str && str.toLowerCase() === 'да') return true; else return 'Удаление не подтверждено'; },
  452. });
  453. if (result && result.value && result.value.toLowerCase() == 'да') {
  454. if (this.profiles[this.currentProfile]) {
  455. const newProfiles = Object.assign({}, this.profiles);
  456. delete newProfiles[this.currentProfile];
  457. this.commit('reader/setAllowProfilesSave', true);
  458. await this.$nextTick();//ждем обработчики watch
  459. this.commit('reader/setProfiles', newProfiles);
  460. await this.$nextTick();//ждем обработчики watch
  461. this.commit('reader/setAllowProfilesSave', false);
  462. this.currentProfile = '';
  463. }
  464. }
  465. } catch (e) {
  466. //
  467. }
  468. }
  469. async delAllProfiles() {
  470. if (!Object.keys(this.profiles).length)
  471. return;
  472. try {
  473. const result = await this.$root.stdDialog.prompt(`<b>Предупреждение!</b> Удаление ВСЕХ профилей с настройками необратимо.` +
  474. `<br><br>Введите 'да' для подтверждения удаления:`, ' ', {
  475. inputValidator: (str) => { if (str && str.toLowerCase() === 'да') return true; else return 'Удаление не подтверждено'; },
  476. });
  477. if (result && result.value && result.value.toLowerCase() == 'да') {
  478. this.commit('reader/setAllowProfilesSave', true);
  479. await this.$nextTick();//ждем обработчики watch
  480. this.commit('reader/setProfiles', {});
  481. await this.$nextTick();//ждем обработчики watch
  482. this.commit('reader/setAllowProfilesSave', false);
  483. this.currentProfile = '';
  484. }
  485. } catch (e) {
  486. //
  487. }
  488. }
  489. async copyToClip(text, prefix) {
  490. const result = await utils.copyTextToClipboard(text);
  491. const suf = (prefix.substr(-1) == 'а' ? 'а' : '');
  492. const msg = (result ? `${prefix} успешно скопирован${suf} в буфер обмена` : 'Копирование не удалось');
  493. if (result)
  494. this.$root.notify.success(msg);
  495. else
  496. this.$root.notify.error(msg);
  497. }
  498. async showServerStorageKey() {
  499. this.serverStorageKeyVisible = !this.serverStorageKeyVisible;
  500. }
  501. async enterServerStorageKey(key) {
  502. try {
  503. const result = await this.$root.stdDialog.prompt(`<b>Предупреждение!</b> Изменение ключа доступа приведет к замене всех профилей и читаемых книг в читалке.` +
  504. `<br><br>Введите новый ключ доступа:`, ' ', {
  505. inputValidator: (str) => {
  506. try {
  507. if (str && utils.fromBase58(str).length == 32) {
  508. return true;
  509. }
  510. } catch (e) {
  511. //
  512. }
  513. return 'Неверный формат ключа';
  514. },
  515. inputValue: (key && _.isString(key) ? key : null),
  516. });
  517. if (result && result.value && utils.fromBase58(result.value).length == 32) {
  518. this.commit('reader/setServerStorageKey', result.value);
  519. }
  520. } catch (e) {
  521. //
  522. }
  523. }
  524. async generateServerStorageKey() {
  525. try {
  526. const result = await this.$root.stdDialog.prompt(`<b>Предупреждение!</b> Генерация нового ключа доступа приведет к удалению всех профилей и читаемых книг в читалке.` +
  527. `<br><br>Введите 'да' для подтверждения генерации нового ключа:`, ' ', {
  528. inputValidator: (str) => { if (str && str.toLowerCase() === 'да') return true; else return 'Генерация не подтверждена'; },
  529. });
  530. if (result && result.value && result.value.toLowerCase() == 'да') {
  531. if (this.$root.generateNewServerStorageKey)
  532. this.$root.generateNewServerStorageKey();
  533. }
  534. } catch (e) {
  535. //
  536. }
  537. }
  538. loadWallpaperFileClick() {
  539. this.$refs.file.click();
  540. }
  541. loadWallpaperFile() {
  542. const file = this.$refs.file.files[0];
  543. if (file.size > 10*1024*1024) {
  544. this.$root.stdDialog.alert('Файл обоев не должен превышать в размере 10Mb', 'Ошибка');
  545. return;
  546. }
  547. if (file.type != 'image/png' && file.type != 'image/jpeg') {
  548. this.$root.stdDialog.alert('Файл обоев должен иметь тип PNG или JPEG', 'Ошибка');
  549. return;
  550. }
  551. if (this.userWallpapers.length >= 100) {
  552. this.$root.stdDialog.alert('Превышено максимальное количество пользовательских обоев.', 'Ошибка');
  553. return;
  554. }
  555. this.$refs.file.value = '';
  556. if (file) {
  557. const reader = new FileReader();
  558. reader.onload = (e) => {
  559. (async() => {
  560. const data = e.target.result;
  561. const key = utils.toHex(cryptoUtils.sha256(data));
  562. const label = `#${key.substring(0, 4)}`;
  563. const cssClass = `user-paper${key}`;
  564. const newUserWallpapers = _.cloneDeep(this.userWallpapers);
  565. const index = _.findIndex(newUserWallpapers, (item) => (item.cssClass == cssClass));
  566. if (index < 0)
  567. newUserWallpapers.push({label, cssClass});
  568. if (!wallpaperStorage.keyExists(cssClass)) {
  569. await wallpaperStorage.setData(cssClass, data);
  570. //отправим data на сервер в файл `/upload/${key}`
  571. try {
  572. //const res =
  573. await readerApi.uploadFileBuf(data);
  574. //console.log(res);
  575. } catch (e) {
  576. console.error(e);
  577. }
  578. }
  579. this.userWallpapers = newUserWallpapers;
  580. this.wallpaper = cssClass;
  581. })();
  582. }
  583. reader.readAsDataURL(file);
  584. }
  585. }
  586. async delWallpaper() {
  587. if (this.wallpaper.indexOf('user-paper') == 0) {
  588. const newUserWallpapers = [];
  589. for (const wp of this.userWallpapers) {
  590. if (wp.cssClass != this.wallpaper) {
  591. newUserWallpapers.push(wp);
  592. }
  593. }
  594. await wallpaperStorage.removeData(this.wallpaper);
  595. this.userWallpapers = newUserWallpapers;
  596. this.wallpaper = '';
  597. }
  598. }
  599. async downloadWallpaper() {
  600. if (this.wallpaper.indexOf('user-paper') != 0)
  601. return;
  602. try {
  603. const d = this.$refs.download;
  604. const dataUrl = await wallpaperStorage.getData(this.wallpaper);
  605. if (!dataUrl)
  606. throw new Error('Файл обоев не найден');
  607. d.href = dataUrl;
  608. d.download = `wallpaper-#${this.wallpaper.replace('user-paper', '').substring(0, 4)}`;
  609. d.click();
  610. } catch (e) {
  611. this.$root.stdDialog.alert(e.message, 'Ошибка', {color: 'negative'});
  612. }
  613. }
  614. keyHook(event) {
  615. if (!this.$root.stdDialog.active && event.type == 'keydown' && event.key == 'Escape') {
  616. this.close();
  617. }
  618. return true;
  619. }
  620. }
  621. export default vueComponent(SettingsPage);
  622. //-----------------------------------------------------------------------------
  623. </script>
  624. <style scoped>
  625. .tab {
  626. justify-content: initial;
  627. }
  628. .tab-panel {
  629. overflow-x: hidden;
  630. overflow-y: auto;
  631. font-size: 90%;
  632. padding: 0 10px 15px 10px;
  633. }
  634. .part-header {
  635. border-top: 2px solid #bbbbbb;
  636. font-weight: bold;
  637. font-size: 110%;
  638. margin-top: 15px;
  639. margin-bottom: 5px;
  640. }
  641. .item {
  642. width: 100%;
  643. margin-top: 5px;
  644. margin-bottom: 5px;
  645. }
  646. .label-1, .label-3, .label-7 {
  647. width: 75px;
  648. }
  649. .label-2, .label-4, .label-5 {
  650. width: 110px;
  651. }
  652. .label-6 {
  653. width: 100px;
  654. }
  655. .label-1, .label-2, .label-3, .label-4, .label-5, .label-6, .label-7 {
  656. display: flex;
  657. flex-direction: column;
  658. justify-content: center;
  659. text-align: right;
  660. margin-right: 10px;
  661. overflow: hidden;
  662. }
  663. .text {
  664. font-size: 90%;
  665. line-height: 130%;
  666. }
  667. .button {
  668. margin: 3px 15px 3px 0;
  669. padding: 0 5px 0 5px;
  670. }
  671. .copy-icon {
  672. margin-left: 5px;
  673. cursor: pointer;
  674. font-size: 120%;
  675. color: blue;
  676. }
  677. .input {
  678. max-width: 150px;
  679. }
  680. .no-mp {
  681. margin: 0;
  682. padding: 0;
  683. }
  684. .col-left {
  685. width: 150px;
  686. }
  687. </style>