SelectExtDialog.vue 4.6 KB

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