123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- <template>
- <Dialog ref="dialog" v-model="dialogVisible">
- <template #header>
- <div class="row items-center">
- <div style="font-size: 110%">
- Выбрать типы файлов
- </div>
- </div>
- </template>
- <div ref="box" class="column q-mt-xs overflow-auto no-wrap" style="width: 370px; padding: 0px 10px 10px 10px;">
- <div v-show="extList.length" class="checkbox-tick-all">
- <div class="row items-center">
- <q-option-group
- v-model="ticked"
- :options="optionsPre"
- type="checkbox"
- inline
- >
- <template #label="opt">
- <div class="row items-center" style="width: 35px">
- <span>{{ opt.label }}</span>
- </div>
- </template>
- </q-option-group>
- </div>
- <q-checkbox v-model="tickAll" label="Выбрать/снять все" toggle-order="ft" @update:model-value="makeTickAll" />
- </div>
- <q-option-group
- v-model="ticked"
- :options="options"
- type="checkbox"
- >
- </q-option-group>
- </div>
- <template #footer>
- <q-btn class="q-px-md q-ml-sm" color="primary" dense no-caps @click="okClick">
- OK
- </q-btn>
- </template>
- </Dialog>
- </template>
- <script>
- //-----------------------------------------------------------------------------
- import vueComponent from '../../vueComponent.js';
- import Dialog from '../../share/Dialog.vue';
- const componentOptions = {
- components: {
- Dialog
- },
- watch: {
- modelValue(newValue) {
- this.dialogVisible = newValue;
- if (newValue)
- this.init();//no await
- },
- dialogVisible(newValue) {
- this.$emit('update:modelValue', newValue);
- },
- ext() {
- this.updateTicked();
- },
- ticked() {
- this.checkAllTicked();
- this.updateExt();
- },
- }
- };
- class SelectExtDialog {
- _options = componentOptions;
- _props = {
- modelValue: Boolean,
- ext: {type: String, value: ''},
- extList: Array,
- };
- dialogVisible = false;
- ticked = [];
- tickAll = false;
- created() {
- this.commit = this.$store.commit;
- }
- mounted() {
- this.updateTicked();
- }
- async init() {
- //await this.$refs.dialog.waitShown();
- }
- get options() {
- const result = [];
- for (const ext of this.extList) {
- if (ext.length <= 4)
- result.push({label: ext, value: ext});
- }
- for (const ext of this.extList) {
- if (ext.length > 4)
- result.push({label: ext, value: ext});
- }
- return result;
- }
- get optionsPre() {
- const result = [];
- for (const ext of ['fb2', 'epub', 'mobi', 'pdf', 'djvu', 'doc', 'docx', 'rtf', 'xml', 'html', 'txt', 'zip']) {
- if (this.extList.includes(ext)) {
- result.push({label: ext, value: ext});
- }
- }
- return result;
- }
- makeTickAll() {
- if (this.tickAll) {
- const newTicked = [];
- for (const ext of this.extList) {
- newTicked.push(ext);
- }
- this.ticked = newTicked;
- } else {
- this.ticked = [];
- this.tickAll = false;
- }
- }
- checkAllTicked() {
- const ticked = new Set(this.ticked);
- let newTickAll = !!(this.extList.length);
- for (const ext of this.extList) {
- if (!ticked.has(ext)) {
- newTickAll = false;
- break;
- }
- }
- if (this.ticked.length && !newTickAll) {
- this.tickAll = undefined;
- } else {
- this.tickAll = newTickAll;
- }
- }
- updateTicked() {
- this.ticked = this.ext.split('|').filter(s => s);
- }
- updateExt() {
- this.$emit('update:ext', this.ticked.join('|'));
- }
- okClick() {
- this.dialogVisible = false;
- }
- }
- export default vueComponent(SelectExtDialog);
- //-----------------------------------------------------------------------------
- </script>
- <style scoped>
- .checkbox-tick-all {
- border-bottom: 1px solid #bbbbbb;
- margin-bottom: 7px;
- padding: 5px 5px 2px 0px;
- }
- .clickable {
- color: blue;
- cursor: pointer;
- }
- </style>
|