SelectExtDialog.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <template>
  2. <Dialog ref="dialog" v-model="dialogVisible">
  3. <template #header>
  4. <div class="row items-center">
  5. <div style="font-size: 110%">
  6. Выбрать типы файлов
  7. </div>
  8. </div>
  9. </template>
  10. <div ref="box" class="column q-mt-xs overflow-auto no-wrap" style="width: 370px; padding: 0px 10px 10px 10px;">
  11. <div v-show="extList.length" class="checkbox-tick-all">
  12. <div class="row items-center">
  13. <q-option-group
  14. v-model="ticked"
  15. :options="optionsPre"
  16. type="checkbox"
  17. inline
  18. />
  19. </div>
  20. <q-checkbox v-model="tickAll" label="Выбрать/снять все" toggle-order="ft" @update:model-value="makeTickAll" />
  21. </div>
  22. <q-option-group
  23. v-model="ticked"
  24. :options="options"
  25. type="checkbox"
  26. >
  27. </q-option-group>
  28. </div>
  29. <template #footer>
  30. <q-btn class="q-px-md q-ml-sm" color="primary" dense no-caps @click="okClick">
  31. OK
  32. </q-btn>
  33. </template>
  34. </Dialog>
  35. </template>
  36. <script>
  37. //-----------------------------------------------------------------------------
  38. import vueComponent from '../../vueComponent.js';
  39. import Dialog from '../../share/Dialog.vue';
  40. const componentOptions = {
  41. components: {
  42. Dialog
  43. },
  44. watch: {
  45. modelValue(newValue) {
  46. this.dialogVisible = newValue;
  47. if (newValue)
  48. this.init();//no await
  49. },
  50. dialogVisible(newValue) {
  51. this.$emit('update:modelValue', newValue);
  52. },
  53. lang() {
  54. this.updateTicked();
  55. },
  56. ticked() {
  57. this.checkAllTicked();
  58. this.updateLang();
  59. },
  60. }
  61. };
  62. class SelectExtDialog {
  63. _options = componentOptions;
  64. _props = {
  65. modelValue: Boolean,
  66. ext: {type: String, value: ''},
  67. extList: Array,
  68. };
  69. dialogVisible = false;
  70. ticked = [];
  71. tickAll = false;
  72. created() {
  73. this.commit = this.$store.commit;
  74. }
  75. mounted() {
  76. this.updateTicked();
  77. }
  78. async init() {
  79. //await this.$refs.dialog.waitShown();
  80. }
  81. get options() {
  82. const result = [];
  83. for (const ext of this.extList) {
  84. result.push({label: ext, value: ext});
  85. }
  86. return result;
  87. }
  88. get optionsPre() {
  89. const result = [];
  90. for (const ext of ['fb2', 'pdf']) {
  91. if (this.extList.includes(ext)) {
  92. result.push({label: ext, value: ext});
  93. }
  94. }
  95. return result;
  96. }
  97. makeTickAll() {
  98. if (this.tickAll) {
  99. const newTicked = [];
  100. for (const ext of this.extList) {
  101. newTicked.push(ext);
  102. }
  103. this.ticked = newTicked;
  104. } else {
  105. this.ticked = [];
  106. this.tickAll = false;
  107. }
  108. }
  109. checkAllTicked() {
  110. const ticked = new Set(this.ticked);
  111. let newTickAll = !!(this.extList.length);
  112. for (const ext of this.extList) {
  113. if (!ticked.has(ext)) {
  114. newTickAll = false;
  115. break;
  116. }
  117. }
  118. if (this.ticked.length && !newTickAll) {
  119. this.tickAll = undefined;
  120. } else {
  121. this.tickAll = newTickAll;
  122. }
  123. }
  124. updateTicked() {
  125. this.ticked = this.ext.split(',').filter(s => s);
  126. }
  127. updateLang() {
  128. this.$emit('update:ext', this.ticked.join(','));
  129. }
  130. okClick() {
  131. this.dialogVisible = false;
  132. }
  133. }
  134. export default vueComponent(SelectExtDialog);
  135. //-----------------------------------------------------------------------------
  136. </script>
  137. <style scoped>
  138. .checkbox-tick-all {
  139. border-bottom: 1px solid #bbbbbb;
  140. margin-bottom: 7px;
  141. padding: 5px 5px 2px 0px;
  142. }
  143. .clickable {
  144. color: blue;
  145. cursor: pointer;
  146. }
  147. </style>