BookmarkSettings.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <template>
  2. <Window ref="window" width="600px" height="95%" @close="close">
  3. <template slot="header">
  4. Настроить закладки
  5. </template>
  6. <div class="column fit">
  7. <div class="row items-center top-panel bg-grey-3">
  8. <q-btn class="q-mr-md" round dense color="blue" icon="la la-check" @click.stop="openSelected" size="16px" :disabled="!selected">
  9. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">Открыть выбранную закладку</q-tooltip>
  10. </q-btn>
  11. <q-input class="col q-mr-sm" ref="search" rounded outlined dense bg-color="white" placeholder="Найти" v-model="search">
  12. <template v-slot:append>
  13. <q-icon v-if="search !== ''" name="la la-times" class="cursor-pointer" @click="resetSearch"/>
  14. </template>
  15. </q-input>
  16. </div>
  17. <div class="col row">
  18. <div class="left-panel column items-center bg-grey-3">
  19. <q-btn class="q-mb-sm" round dense color="blue" icon="la la-plus" @click.stop="addBookmark" size="14px">
  20. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">Добавить закладку</q-tooltip>
  21. </q-btn>
  22. <q-btn class="q-mb-sm" round dense color="blue" icon="la la-minus" @click.stop="delBookmark" size="14px" :disabled="!ticked.length">
  23. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">Удалить отмеченные закладки</q-tooltip>
  24. </q-btn>
  25. <q-btn class="q-mb-sm" round dense color="blue" icon="la la-edit" @click.stop="editBookmark" size="14px" :disabled="!selected || selected.indexOf('-') < 0">
  26. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">Редактировать закладку</q-tooltip>
  27. </q-btn>
  28. <q-btn class="q-mb-sm" round dense color="blue" icon="la la-arrow-up" @click.stop="moveBookmark(false)" size="14px" :disabled="!ticked.length">
  29. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">Переместить отмеченные вверх</q-tooltip>
  30. </q-btn>
  31. <q-btn class="q-mb-sm" round dense color="blue" icon="la la-arrow-down" @click.stop="moveBookmark(true)" size="14px" :disabled="!ticked.length">
  32. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">Переместить отмеченные вниз</q-tooltip>
  33. </q-btn>
  34. <q-btn class="q-mb-sm" round dense color="blue" icon="la la-broom" @click.stop="setDefaultBookmarks" size="14px">
  35. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">Установить по умолчанию</q-tooltip>
  36. </q-btn>
  37. </div>
  38. <div class="col tree">
  39. <q-tree
  40. :nodes="nodes"
  41. node-key="key"
  42. tick-strategy="leaf"
  43. :selected.sync="selected"
  44. :ticked.sync="ticked"
  45. :expanded.sync="expanded"
  46. selected-color="black"
  47. :filter="search"
  48. no-nodes-label="Закладок пока нет"
  49. no-results-label="Ничего не найдено"
  50. >
  51. <template v-slot:default-header="p">
  52. <div class="q-px-xs" :class="{selected: selected == p.key}">{{ p.node.label }}</div>
  53. </template>
  54. </q-tree>
  55. </div>
  56. </div>
  57. </div>
  58. </Window>
  59. </template>
  60. <script>
  61. //-----------------------------------------------------------------------------
  62. import Vue from 'vue';
  63. import Component from 'vue-class-component';
  64. import _ from 'lodash';
  65. import Window from '../../share/Window.vue';
  66. import * as lu from '../linkUtils';
  67. import rstore from '../../../store/modules/reader';
  68. const BookmarkSettingsProps = Vue.extend({
  69. props: {
  70. libs: Object,
  71. addBookmarkVisible: Boolean,
  72. }
  73. });
  74. export default @Component({
  75. components: {
  76. Window,
  77. },
  78. watch: {
  79. libs: function() {
  80. },
  81. }
  82. })
  83. class BookmarkSettings extends BookmarkSettingsProps {
  84. search = '';
  85. selected = '';
  86. ticked = [];
  87. expanded = [];
  88. created() {
  89. this.afterInit = true;
  90. }
  91. mounted() {
  92. }
  93. init() {
  94. this.$refs.window.init();
  95. }
  96. get nodes() {
  97. const result = [];
  98. const expanded = [];
  99. this.links = {};
  100. this.libs.groups.forEach(group => {
  101. const rkey = `r-${group.r}`;
  102. const g = {label: group.r, key: rkey, children: []};
  103. this.links[rkey] = {l: group.r, c: ''};
  104. group.list.forEach(link => {
  105. const key = link.l;
  106. g.children.push({
  107. label: (link.c ? link.c + ' ': '') + lu.removeOrigin(link.l),
  108. key
  109. });
  110. this.links[key] = link;
  111. if (link.l == this.libs.startLink && expanded.indexOf(rkey) < 0) {
  112. expanded.push(rkey);
  113. }
  114. });
  115. result.push(g);
  116. });
  117. if (this.afterInit) {
  118. this.$nextTick(() => {
  119. this.expanded = expanded;
  120. });
  121. this.afterInit = false;
  122. }
  123. return result;
  124. }
  125. resetSearch() {
  126. this.search = '';
  127. this.$refs.search.focus();
  128. }
  129. openSelected() {
  130. if (!this.selected)
  131. return;
  132. if (this.selected.indexOf('r-') === 0) {//rootLink
  133. this.$emit('do-action', {action: 'setRootLink', data: this.links[this.selected].l});
  134. } else {//selectedLink
  135. this.$emit('do-action', {action: 'setSelectedLink', data: this.links[this.selected].l});
  136. }
  137. this.close();
  138. }
  139. editBookmark() {
  140. this.$emit('do-action', {action: 'editBookmark', data: {link: this.links[this.selected].l, desc: this.links[this.selected].c}});
  141. }
  142. addBookmark() {
  143. this.$emit('do-action', {action: 'addBookmark'});
  144. }
  145. async delBookmark() {
  146. const newLibs = _.cloneDeep(this.libs);
  147. if (await this.$root.stdDialog.confirm(`Подтвердите удаление ${this.ticked.length} закладок:`, ' ')) {
  148. const ticked = new Set(this.ticked);
  149. for (let i = newLibs.groups.length - 1; i >= 0; i--) {
  150. const g = newLibs.groups[i];
  151. for (let j = g.list.length - 1; j >= 0; j--) {
  152. if (ticked.has(g.list[j].l)) {
  153. delete g.list[j];
  154. }
  155. }
  156. g.list = g.list.filter(v => v);
  157. if (!g.list.length)
  158. delete newLibs.groups[i];
  159. else {
  160. const item = lu.getListItemByLink(g.list, g.s);
  161. if (!item)
  162. g.s = g.list[0].l;
  163. }
  164. }
  165. newLibs.groups = newLibs.groups.filter(v => v);
  166. this.ticked = [];
  167. this.selected = '';
  168. this.$emit('do-action', {action: 'setLibs', data: newLibs});
  169. }
  170. }
  171. moveBookmark() {
  172. }
  173. async setDefaultBookmarks() {
  174. const result = await this.$root.stdDialog.prompt(`Введите 'да' для сброса всех закладок в предустановленные значения:`, ' ', {
  175. inputValidator: (str) => { if (str && str.toLowerCase() === 'да') return true; else return 'Удаление не подтверждено'; },
  176. });
  177. if (result && result.value && result.value.toLowerCase() == 'да') {
  178. this.$emit('do-action', {action: 'setLibs', data: _.cloneDeep(rstore.libsDefaults)});
  179. }
  180. }
  181. close() {
  182. this.afterInit = false;
  183. this.$emit('close');
  184. }
  185. keyHook(event) {
  186. if (this.addBookmarkVisible)
  187. return false;
  188. if (event.type == 'keydown' && event.key == 'Escape') {
  189. this.close();
  190. return true;
  191. }
  192. return false;
  193. }
  194. }
  195. //-----------------------------------------------------------------------------
  196. </script>
  197. <style scoped>
  198. .top-panel {
  199. height: 50px;
  200. border-bottom: 1px solid gray;
  201. padding: 0 10px 0 12px;
  202. }
  203. .left-panel {
  204. width: 60px;
  205. border-right: 1px solid gray;
  206. padding: 10px 0 10px 0;
  207. }
  208. .tree {
  209. padding: 10px;
  210. }
  211. .selected {
  212. text-shadow: 0 0 20px yellow, 0 0 15px yellow, 0 0 10px yellow, 0 0 10px yellow, 0 0 5px yellow;
  213. }
  214. </style>