SettingsPage.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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 componentOptions = {
  73. components: {
  74. Window,
  75. //pages
  76. ProfilesTab,
  77. ViewTab,
  78. ToolBarTab,
  79. KeysTab,
  80. PageMoveTab,
  81. ConvertTab,
  82. UpdateTab,
  83. OthersTab,
  84. ResetTab,
  85. },
  86. watch: {
  87. settings: function() {
  88. this.settingsChanged();//no await
  89. },
  90. form: {
  91. handler() {
  92. if (this.inited && !this.isSetsChanged) {
  93. this.debouncedCommitSettings();
  94. }
  95. },
  96. deep: true,
  97. },
  98. },
  99. };
  100. class SettingsPage {
  101. _options = componentOptions;
  102. form = {};
  103. tabs = [
  104. { name: 'profiles', icon: 'la la-users', label: 'Профили' },
  105. { name: 'view', icon: 'la la-eye', label: 'Вид'},
  106. { name: 'toolbar', icon: 'la la-grip-horizontal', label: 'Панель'},
  107. { name: 'keys', icon: 'la la-gamepad', label: 'Управление'},
  108. { name: 'pagemove', icon: 'la la-school', label: 'Листание'},
  109. { name: 'convert', icon: 'la la-magic', label: 'Конвертир.'},
  110. { name: 'update', icon: 'la la-retweet', label: 'Обновление'},
  111. { name: 'others', icon: 'la la-list-ul', label: 'Прочее'},
  112. { name: 'reset', icon: 'la la-broom', label: 'Сброс'},
  113. ];
  114. selectedTab = 'profiles';
  115. isSetsChanged = false;
  116. created() {
  117. this.commit = this.$store.commit;
  118. this.debouncedCommitSettings = _.debounce(() => {
  119. this.commit('reader/setSettings', _.cloneDeep(this.form));
  120. }, 50);
  121. this.settingsChanged();//no await
  122. }
  123. mounted() {
  124. }
  125. init() {
  126. this.$refs.window.init();
  127. this.inited = true;
  128. }
  129. async settingsChanged() {
  130. this.isSetsChanged = true;
  131. try {
  132. this.form = reactive(_.cloneDeep(this.settings));
  133. } finally {
  134. await this.$nextTick();
  135. this.isSetsChanged = false;
  136. }
  137. }
  138. get settings() {
  139. return this.$store.state.reader.settings;
  140. }
  141. close() {
  142. this.$emit('do-action', {action: 'settings'});
  143. }
  144. async setDefaults() {
  145. try {
  146. if (await this.$root.stdDialog.confirm('Подтвердите установку настроек по умолчанию:', ' ')) {
  147. this.form = _.cloneDeep(rstore.settingDefaults);
  148. }
  149. } catch (e) {
  150. //
  151. }
  152. }
  153. tabEvent(event) {
  154. if (!event || !event.action)
  155. return;
  156. switch (event.action) {
  157. case 'set-defaults': this.setDefaults(); break;
  158. }
  159. }
  160. keyHook(event) {
  161. if (!this.$root.stdDialog.active && event.type == 'keydown' && event.key == 'Escape') {
  162. this.close();
  163. }
  164. return true;
  165. }
  166. }
  167. export default vueComponent(SettingsPage);
  168. //-----------------------------------------------------------------------------
  169. </script>
  170. <style scoped>
  171. .tab {
  172. justify-content: initial;
  173. }
  174. </style>
  175. <style>
  176. .sets-tab-panel {
  177. overflow-x: hidden;
  178. overflow-y: auto;
  179. font-size: 90%;
  180. padding: 0 10px 15px 10px;
  181. }
  182. .sets-part-header {
  183. border-top: 2px solid #bbbbbb;
  184. font-weight: bold;
  185. font-size: 110%;
  186. margin-top: 15px;
  187. margin-bottom: 5px;
  188. }
  189. .sets-label {
  190. display: flex;
  191. flex-direction: column;
  192. justify-content: center;
  193. text-align: right;
  194. margin-right: 10px;
  195. overflow: hidden;
  196. }
  197. .sets-item {
  198. width: 100%;
  199. margin-top: 5px;
  200. margin-bottom: 5px;
  201. }
  202. .sets-button {
  203. margin: 3px 15px 3px 0;
  204. padding: 0 5px 0 5px;
  205. }
  206. </style>