SettingsPage.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <template>
  2. <Window ref="window" width="600px" @close="close">
  3. <template #header>
  4. Настройки
  5. </template>
  6. <div class="col row">
  7. <div class="full-height">
  8. <q-tabs
  9. ref="tabs"
  10. v-model="selectedTab"
  11. class="bg-grey-3 text-grey-9"
  12. style="max-width: 130px"
  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. <q-tab v-for="item in tabs" :key="item.name" class="tab row items-center" :name="item.name">
  24. <q-icon :name="item.icon" :color="selectedTab == item.name ? 'yellow' : 'teal-7'" size="24px" />
  25. <div class="q-ml-xs" style="font-size: 90%">
  26. {{ item.label }}
  27. </div>
  28. </q-tab>
  29. </q-tabs>
  30. </div>
  31. <div class="col fit">
  32. <!-- Профили --------------------------------------------------------------------->
  33. <ProfilesTab v-if="selectedTab == 'profiles'" :form="form" />
  34. <!-- Вид ------------------------------------------------------------------------->
  35. <ViewTab v-if="selectedTab == 'view'" :form="form" />
  36. <!-- Кнопки ---------------------------------------------------------------------->
  37. <ToolBarTab v-if="selectedTab == 'toolbar'" :form="form" />
  38. <!-- Управление ------------------------------------------------------------------>
  39. <KeysTab v-if="selectedTab == 'keys'" :form="form" />
  40. <!-- Листание -------------------------------------------------------------------->
  41. <PageMoveTab v-if="selectedTab == 'pagemove'" :form="form" />
  42. <!-- Конвертирование ------------------------------------------------------------->
  43. <ConvertTab v-if="selectedTab == 'convert'" :form="form" />
  44. <!-- Обновление ------------------------------------------------------------------>
  45. <UpdateTab v-if="selectedTab == 'update'" :form="form" />
  46. <!-- Прочее ---------------------------------------------------------------------->
  47. <OthersTab v-if="selectedTab == 'others'" :form="form" />
  48. <!-- Сброс ----------------------------------------------------------------------->
  49. <ResetTab v-if="selectedTab == 'reset'" :form="form" @tab-event="tabEvent" />
  50. </div>
  51. </div>
  52. </Window>
  53. </template>
  54. <script>
  55. //-----------------------------------------------------------------------------
  56. import vueComponent from '../../vueComponent.js';
  57. import { reactive } from 'vue';
  58. import _ from 'lodash';
  59. //stuff
  60. import Window from '../../share/Window.vue';
  61. import rstore from '../../../store/modules/reader';
  62. //pages
  63. import ProfilesTab from './ProfilesTab/ProfilesTab.vue';
  64. import ViewTab from './ViewTab/ViewTab.vue';
  65. import ToolBarTab from './ToolBarTab/ToolBarTab.vue';
  66. import KeysTab from './KeysTab/KeysTab.vue';
  67. import PageMoveTab from './PageMoveTab/PageMoveTab.vue';
  68. import ConvertTab from './ConvertTab/ConvertTab.vue';
  69. import UpdateTab from './UpdateTab/UpdateTab.vue';
  70. import OthersTab from './OthersTab/OthersTab.vue';
  71. import ResetTab from './ResetTab/ResetTab.vue';
  72. const hex = /^#[0-9a-fA-F]{3}([0-9a-fA-F]{3})?$/;
  73. const componentOptions = {
  74. components: {
  75. Window,
  76. //pages
  77. ProfilesTab,
  78. ViewTab,
  79. ToolBarTab,
  80. KeysTab,
  81. PageMoveTab,
  82. ConvertTab,
  83. UpdateTab,
  84. OthersTab,
  85. ResetTab,
  86. },
  87. watch: {
  88. settings: function() {
  89. this.settingsChanged();//no await
  90. },
  91. form: {
  92. handler() {
  93. if (this.inited && !this.isSetsChanged) {
  94. this.debouncedCommitSettings();
  95. }
  96. },
  97. deep: true,
  98. },
  99. },
  100. };
  101. class SettingsPage {
  102. _options = componentOptions;
  103. form = {};
  104. tabs = [
  105. { name: 'profiles', icon: 'la la-users', label: 'Профили' },
  106. { name: 'view', icon: 'la la-eye', label: 'Вид'},
  107. { name: 'toolbar', icon: 'la la-grip-horizontal', label: 'Панель'},
  108. { name: 'keys', icon: 'la la-gamepad', label: 'Управление'},
  109. { name: 'pagemove', icon: 'la la-school', label: 'Листание'},
  110. { name: 'convert', icon: 'la la-magic', label: 'Конвертир.'},
  111. { name: 'update', icon: 'la la-retweet', label: 'Обновление'},
  112. { name: 'others', icon: 'la la-list-ul', label: 'Прочее'},
  113. { name: 'reset', icon: 'la la-broom', label: 'Сброс'},
  114. ];
  115. selectedTab = 'profiles';
  116. isSetsChanged = false;
  117. created() {
  118. this.commit = this.$store.commit;
  119. this.debouncedCommitSettings = _.debounce(() => {
  120. this.commit('reader/setSettings', _.cloneDeep(this.form));
  121. }, 50);
  122. this.settingsChanged();//no await
  123. }
  124. mounted() {
  125. }
  126. init() {
  127. this.$refs.window.init();
  128. this.inited = true;
  129. }
  130. async settingsChanged() {
  131. this.isSetsChanged = true;
  132. try {
  133. this.form = reactive(_.cloneDeep(this.settings));
  134. } finally {
  135. await this.$nextTick();
  136. this.isSetsChanged = false;
  137. }
  138. }
  139. get settings() {
  140. return this.$store.state.reader.settings;
  141. }
  142. close() {
  143. this.$emit('do-action', {action: 'settings'});
  144. }
  145. async setDefaults() {
  146. try {
  147. if (await this.$root.stdDialog.confirm('Подтвердите установку настроек по умолчанию:', ' ')) {
  148. this.form = _.cloneDeep(rstore.settingDefaults);
  149. }
  150. } catch (e) {
  151. //
  152. }
  153. }
  154. tabEvent(event) {
  155. if (!event || !event.action)
  156. return;
  157. switch (event.action) {
  158. case 'set-defaults': this.setDefaults(); break;
  159. }
  160. }
  161. keyHook(event) {
  162. if (!this.$root.stdDialog.active && event.type == 'keydown' && event.key == 'Escape') {
  163. this.close();
  164. }
  165. return true;
  166. }
  167. }
  168. export default vueComponent(SettingsPage);
  169. //-----------------------------------------------------------------------------
  170. </script>
  171. <style scoped>
  172. .tab {
  173. justify-content: initial;
  174. }
  175. </style>
  176. <style>
  177. .sets-tab-panel {
  178. overflow-x: hidden;
  179. overflow-y: auto;
  180. font-size: 90%;
  181. padding: 0 10px 15px 10px;
  182. }
  183. .sets-part-header {
  184. border-top: 2px solid #bbbbbb;
  185. font-weight: bold;
  186. font-size: 110%;
  187. margin-top: 15px;
  188. margin-bottom: 5px;
  189. }
  190. .sets-label {
  191. display: flex;
  192. flex-direction: column;
  193. justify-content: center;
  194. text-align: right;
  195. margin-right: 10px;
  196. overflow: hidden;
  197. }
  198. .sets-item {
  199. width: 100%;
  200. margin-top: 5px;
  201. margin-bottom: 5px;
  202. }
  203. .sets-button {
  204. margin: 3px 15px 3px 0;
  205. padding: 0 5px 0 5px;
  206. }
  207. </style>