shared-ritm 1.2.54 → 1.2.56

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,241 +1,244 @@
1
- <script setup lang="ts">
2
- import { defineProps, defineEmits, ref, computed, watch } from 'vue'
3
- import type { Ref } from 'vue'
4
- import FilterIcon from '@/icons/components/table-filter-icon.vue'
5
-
6
- interface FilterOption {
7
- id: string
8
- name: string
9
- }
10
-
11
- interface TableEmits {
12
- 'toggle-filter-value': [colName: string, value: string]
13
- 'clear-filter': [colName: string]
14
- 'open-filter-menu': [colName: string, isOpen: boolean]
15
- 'row-click': [row: Record<string, any>]
16
- 'update:selectedRows': [rows: any[]]
17
- }
18
-
19
- const emit = defineEmits<TableEmits>()
20
-
21
- const props = defineProps<{
22
- rows: any[]
23
- columns: any[]
24
- columnFilters: Ref<Record<string, string | string[] | undefined>>
25
- filterMenus: Ref<Record<string, boolean>>
26
- filtersOptions: Record<string, FilterOption[]>
27
- meta: Ref<{ currentPage: number; perPage: number }>
28
- enableMultiSelect?: boolean
29
- selectedRows: any[]
30
- }>()
31
-
32
- const localSearches = ref<Record<string, string>>({})
33
-
34
- const filteredOptions = computed(() => {
35
- const result: Record<string, FilterOption[]> = {}
36
- for (const col of props.columns) {
37
- const search = localSearches.value[col.name]?.toLowerCase() || ''
38
- const options = props.filtersOptions[col.name] || []
39
- result[col.name] = options.filter(opt => opt.name.toLowerCase().includes(search))
40
- }
41
- return result
42
- })
43
- const selected = ref<any[]>([])
44
-
45
- watch(
46
- () => props.selectedRows,
47
- val => {
48
- selected.value = val
49
- },
50
- { immediate: true },
51
- )
52
-
53
- watch(
54
- selected,
55
- val => {
56
- emit('update:selectedRows', val)
57
- },
58
- { deep: true },
59
- )
60
- </script>
61
-
62
- <template>
63
- <q-page class="flex flex-col" style="min-height: 100%">
64
- <q-table
65
- v-model:selected="selected"
66
- :rows="rows"
67
- :columns="columns"
68
- row-key="id"
69
- flat
70
- bordered
71
- hide-bottom
72
- class="full-width"
73
- :rows-per-page-options="[0]"
74
- :selection="props.enableMultiSelect ? 'multiple' : 'none'"
75
- @row-click="(_, row) => emit('row-click', row)"
76
- >
77
- <template #header-selection="scope">
78
- <q-toggle v-model="scope.selected" />
79
- </template>
80
-
81
- <template #body-selection="scope">
82
- <q-toggle v-model="scope.selected" />
83
- </template>
84
-
85
- <template #body-cell-index="props">
86
- <q-td :props="props" class="text-center">
87
- {{ props.rowIndex + 1 + (meta.value.currentPage - 1) * meta.value.perPage }}
88
- </q-td>
89
- </template>
90
-
91
- <template v-for="col in columns" :key="col.name" #[`header-cell-${col.name}`]="propsSlot">
92
- <q-th :props="propsSlot" :class="{ 'cursor-pointer': col.filterType }">
93
- <div
94
- v-if="col.filterType"
95
- class="row items-center no-wrap"
96
- @click.stop="emit('open-filter-menu', col.name, !filterMenus.value[col.name])"
97
- >
98
- <filter-icon class="q-mr-xs" />
99
- <span>{{ col.label }}</span>
100
- <template v-if="col.filterType === 'multi' && columnFilters.value[col.name]?.length">
101
- <div class="label-length">- {{ columnFilters.value[col.name]?.length }}</div>
102
- </template>
103
- </div>
104
- <div v-else>{{ col.label }}</div>
105
-
106
- <q-menu
107
- v-if="col.filterType"
108
- :model-value="filterMenus.value[col.name]"
109
- fit
110
- max-height="300px"
111
- class="filter-menu"
112
- @update:model-value="isOpen => emit('open-filter-menu', col.name, isOpen)"
113
- >
114
- <div class="filter-content">
115
- <q-input v-model="localSearches[col.name]" dense outlined placeholder="Поиск" class="q-mb-sm" clearable />
116
- <q-scroll-area style="height: 200px">
117
- <q-list style="min-width: 200px">
118
- <q-item v-for="option in filteredOptions[col.name]" :key="`${col.name}-${option.id}`" tag="label">
119
- <q-item-section avatar>
120
- <q-checkbox
121
- v-if="col.filterType === 'multi'"
122
- dense
123
- :model-value="
124
- Array.isArray(columnFilters.value[col.name]) &&
125
- columnFilters.value[col.name]?.includes(option.name)
126
- "
127
- @update:model-value="() => emit('toggle-filter-value', col.name, option.name)"
128
- />
129
- <q-radio
130
- v-else
131
- dense
132
- :model-value="columnFilters.value[col.name]"
133
- :val="option.name"
134
- @update:model-value="emit('toggle-filter-value', col.name, $event)"
135
- />
136
- </q-item-section>
137
- <q-item-section>{{ option.name }}</q-item-section>
138
- </q-item>
139
- </q-list>
140
- </q-scroll-area>
141
-
142
- <div class="filter-footer">
143
- <q-btn color="negative" flat dense label="Сбросить фильтр" @click="emit('clear-filter', col.name)" />
144
- </div>
145
- </div>
146
- </q-menu>
147
- </q-th>
148
- </template>
149
-
150
- <template #body-cell="props">
151
- <q-td :props="props">
152
- <q-badge
153
- v-if="props.col.badge && typeof props.value === 'boolean'"
154
- :color="
155
- props.col.badge.colorTrue && props.value
156
- ? props.col.badge.colorTrue
157
- : props.col.badge.colorFalse && !props.value
158
- ? props.col.badge.colorFalse
159
- : props.value
160
- ? 'green'
161
- : 'red'
162
- "
163
- outline
164
- class="text-bold"
165
- >
166
- {{ props.value ? props.col.badge.true ?? 'Да' : props.col.badge.false ?? 'Нет' }}
167
- </q-badge>
168
- <span v-else-if="props.col.html" v-html="props.value"></span>
169
- <span v-else>{{ props.value }}</span>
170
- </q-td>
171
- </template>
172
- </q-table>
173
- </q-page>
174
- </template>
175
-
176
- <style scoped lang="scss">
177
- .cursor-pointer {
178
- cursor: pointer;
179
- }
180
-
181
- .filter-menu {
182
- padding: 10px;
183
- }
184
- .label-length {
185
- margin-left: 5px;
186
- }
187
- .filter-content {
188
- display: flex;
189
- flex-direction: column;
190
- color: #1d425d;
191
- .q-item {
192
- padding: 0 5px;
193
- min-height: 40px;
194
- }
195
- .q-item__section {
196
- min-width: 30px;
197
- padding: 0px;
198
- }
199
- ::v-deep(.q-radio__inner),
200
- ::v-deep(.q-checkbox__inner) {
201
- color: #a4b4cf;
202
- }
203
- }
204
-
205
- .filter-footer {
206
- border-top: 1px solid #eee;
207
- display: flex;
208
- justify-content: center;
209
- }
210
-
211
- ::v-deep(.q-table thead) {
212
- background: #f2f7fb;
213
- }
214
-
215
- ::v-deep(.q-table th) {
216
- font-family: NunitoSansFont, sans-serif;
217
- color: #a4b4cf;
218
- font-size: 15px;
219
- font-style: normal;
220
- font-weight: 700;
221
- line-height: 20px;
222
- height: 61px;
223
- }
224
-
225
- ::v-deep(.q-table tbody td) {
226
- height: 61px;
227
- font-size: 14px;
228
- }
229
-
230
- ::v-deep(.q-table tbody) {
231
- font-family: NunitoSansFont, sans-serif;
232
- border-color: #d7e0ef;
233
- color: #1d425d;
234
- line-height: 20px;
235
- font-size: 14px;
236
- }
237
-
238
- ::v-deep(.q-table tbody tr:last-child td) {
239
- border-bottom: 1px solid #d7e0ef;
240
- }
241
- </style>
1
+ <script setup lang="ts">
2
+ import { defineProps, defineEmits, ref, computed, watch } from 'vue'
3
+ import type { Ref } from 'vue'
4
+ import FilterIcon from '@/icons/components/table-filter-icon.vue'
5
+
6
+ interface FilterOption {
7
+ id: string
8
+ name: string
9
+ }
10
+
11
+ interface TableEmits {
12
+ 'toggle-filter-value': [colName: string, value: string]
13
+ 'clear-filter': [colName: string]
14
+ 'open-filter-menu': [colName: string, isOpen: boolean]
15
+ 'row-click': [row: Record<string, any>]
16
+ 'update:selectedRows': [rows: any[]]
17
+ }
18
+
19
+ const emit = defineEmits<TableEmits>()
20
+
21
+ const props = defineProps<{
22
+ rows: Ref<any[]>
23
+ columns: any[]
24
+ columnFilters: Ref<Record<string, string | string[] | undefined>>
25
+ filterMenus: Ref<Record<string, boolean>>
26
+ filtersOptions: Record<string, FilterOption[]>
27
+ meta: Ref<{ currentPage: number; perPage: number }>
28
+ enableMultiSelect?: boolean
29
+ selectedRows: any[]
30
+ }>()
31
+
32
+ const localSearches = ref<Record<string, string>>({})
33
+
34
+ const filteredOptions = computed(() => {
35
+ const result: Record<string, FilterOption[]> = {}
36
+ for (const col of props.columns) {
37
+ const search = localSearches.value[col.name]?.toLowerCase() || ''
38
+ const options = props.filtersOptions[col.name] || []
39
+ result[col.name] = options.filter(opt => opt.name.toLowerCase().includes(search))
40
+ }
41
+ return result
42
+ })
43
+ const selected = ref<any[]>([])
44
+
45
+ watch(
46
+ () => props.selectedRows,
47
+ val => {
48
+ selected.value = val
49
+ },
50
+ { immediate: true },
51
+ )
52
+
53
+ watch(
54
+ selected,
55
+ val => {
56
+ emit('update:selectedRows', val)
57
+ },
58
+ { deep: true },
59
+ )
60
+ </script>
61
+
62
+ <template>
63
+ <q-page class="flex flex-col" style="min-height: 100%">
64
+ <q-table
65
+ v-model:selected="selected"
66
+ :rows="rows.value"
67
+ :columns="columns"
68
+ row-key="id"
69
+ flat
70
+ bordered
71
+ hide-bottom
72
+ class="full-width"
73
+ :rows-per-page-options="[0]"
74
+ :selection="props.enableMultiSelect ? 'multiple' : 'none'"
75
+ @row-click="(_, row) => emit('row-click', row)"
76
+ >
77
+ <template #header-selection="scope">
78
+ <q-toggle v-model="scope.selected" />
79
+ </template>
80
+
81
+ <template #body-selection="scope">
82
+ <q-toggle v-model="scope.selected" />
83
+ </template>
84
+
85
+ <template #body-cell-index="props">
86
+ <q-td :props="props" class="text-center">
87
+ {{ props.rowIndex + 1 + (meta.value.currentPage - 1) * meta.value.perPage }}
88
+ </q-td>
89
+ </template>
90
+
91
+ <template v-for="col in columns" :key="col.name" #[`header-cell-${col.name}`]="propsSlot">
92
+ <q-th :props="propsSlot" :class="{ 'cursor-pointer': col.filterType }">
93
+ <div
94
+ v-if="col.filterType"
95
+ class="row items-center no-wrap"
96
+ @click.stop="emit('open-filter-menu', col.name, !filterMenus.value[col.name])"
97
+ >
98
+ <filter-icon class="q-mr-xs" />
99
+ <span>{{ col.label }}</span>
100
+ <div
101
+ v-if="['multi', 'single'].includes(col.filterType) && columnFilters.value[col.name]?.length"
102
+ class="label-length"
103
+ >
104
+ - {{ col.filterType === 'multi' ? columnFilters.value[col.name]?.length : 1 }}
105
+ </div>
106
+ </div>
107
+ <div v-else>{{ col.label }}</div>
108
+
109
+ <q-menu
110
+ v-if="col.filterType"
111
+ :model-value="filterMenus.value[col.name]"
112
+ fit
113
+ max-height="300px"
114
+ class="filter-menu"
115
+ @update:model-value="isOpen => emit('open-filter-menu', col.name, isOpen)"
116
+ >
117
+ <div class="filter-content">
118
+ <q-input v-model="localSearches[col.name]" dense outlined placeholder="Поиск" class="q-mb-sm" clearable />
119
+ <q-scroll-area style="height: 200px">
120
+ <q-list style="min-width: 200px">
121
+ <q-item v-for="option in filteredOptions[col.name]" :key="`${col.name}-${option.id}`" tag="label">
122
+ <q-item-section avatar>
123
+ <q-checkbox
124
+ v-if="col.filterType === 'multi'"
125
+ dense
126
+ :model-value="
127
+ Array.isArray(columnFilters.value[col.name]) &&
128
+ columnFilters.value[col.name]?.includes(option.name)
129
+ "
130
+ @update:model-value="() => emit('toggle-filter-value', col.name, option.name)"
131
+ />
132
+ <q-radio
133
+ v-else
134
+ dense
135
+ :model-value="columnFilters.value[col.name]"
136
+ :val="option.name"
137
+ @update:model-value="emit('toggle-filter-value', col.name, $event)"
138
+ />
139
+ </q-item-section>
140
+ <q-item-section>{{ option.name }}</q-item-section>
141
+ </q-item>
142
+ </q-list>
143
+ </q-scroll-area>
144
+
145
+ <div class="filter-footer">
146
+ <q-btn color="negative" flat dense label="Сбросить фильтр" @click="emit('clear-filter', col.name)" />
147
+ </div>
148
+ </div>
149
+ </q-menu>
150
+ </q-th>
151
+ </template>
152
+
153
+ <template #body-cell="props">
154
+ <q-td :props="props">
155
+ <q-badge
156
+ v-if="props.col.badge && typeof props.value === 'boolean'"
157
+ :color="
158
+ props.col.badge.colorTrue && props.value
159
+ ? props.col.badge.colorTrue
160
+ : props.col.badge.colorFalse && !props.value
161
+ ? props.col.badge.colorFalse
162
+ : props.value
163
+ ? 'green'
164
+ : 'red'
165
+ "
166
+ outline
167
+ class="text-bold"
168
+ >
169
+ {{ props.value ? props.col.badge.true ?? 'Да' : props.col.badge.false ?? 'Нет' }}
170
+ </q-badge>
171
+ <span v-else-if="props.col.html" v-html="props.value"></span>
172
+ <span v-else>{{ props.value }}</span>
173
+ </q-td>
174
+ </template>
175
+ </q-table>
176
+ </q-page>
177
+ </template>
178
+
179
+ <style scoped lang="scss">
180
+ .cursor-pointer {
181
+ cursor: pointer;
182
+ }
183
+
184
+ .filter-menu {
185
+ padding: 10px;
186
+ }
187
+ .label-length {
188
+ margin-left: 5px;
189
+ }
190
+ .filter-content {
191
+ display: flex;
192
+ flex-direction: column;
193
+ color: #1d425d;
194
+ .q-item {
195
+ padding: 0 5px;
196
+ min-height: 40px;
197
+ }
198
+ .q-item__section {
199
+ min-width: 30px;
200
+ padding: 0px;
201
+ }
202
+ ::v-deep(.q-radio__inner),
203
+ ::v-deep(.q-checkbox__inner) {
204
+ color: #a4b4cf;
205
+ }
206
+ }
207
+
208
+ .filter-footer {
209
+ border-top: 1px solid #eee;
210
+ display: flex;
211
+ justify-content: center;
212
+ }
213
+
214
+ ::v-deep(.q-table thead) {
215
+ background: #f2f7fb;
216
+ }
217
+
218
+ ::v-deep(.q-table th) {
219
+ font-family: NunitoSansFont, sans-serif;
220
+ color: #a4b4cf;
221
+ font-size: 15px;
222
+ font-style: normal;
223
+ font-weight: 700;
224
+ line-height: 20px;
225
+ height: 61px;
226
+ }
227
+
228
+ ::v-deep(.q-table tbody td) {
229
+ height: 61px;
230
+ font-size: 14px;
231
+ }
232
+
233
+ ::v-deep(.q-table tbody) {
234
+ font-family: NunitoSansFont, sans-serif;
235
+ border-color: #d7e0ef;
236
+ color: #1d425d;
237
+ line-height: 20px;
238
+ font-size: 14px;
239
+ }
240
+
241
+ ::v-deep(.q-table tbody tr:last-child td) {
242
+ border-bottom: 1px solid #d7e0ef;
243
+ }
244
+ </style>