shared-ritm 1.2.96 → 1.2.98

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,270 +1,270 @@
1
- <template>
2
- <label class="field-label">
3
- {{ label }}
4
- <span v-if="rules?.length && isShowRequired" class="required">*</span>
5
- </label>
6
-
7
- <q-select
8
- ref="select"
9
- v-model="selected"
10
- :options="filteredOptions"
11
- :disable="isDisabled"
12
- :multiple="multiple"
13
- :popup-content-class="'custom-select-menu'"
14
- :hide-selected="!showChip && !simple"
15
- :placeholder="placeholder"
16
- :loading="loading"
17
- :option-value="optionValue || 'value'"
18
- :option-label="optionLabel || 'label'"
19
- emit-value
20
- filled
21
- map-options
22
- stack-label
23
- use-input
24
- :use-chips="!simple"
25
- :hide-bottom-space="hideBottomSpace"
26
- input-debounce="100"
27
- autocomplete=""
28
- :rules="rules"
29
- @virtual-scroll="onScroll"
30
- @filter="filterFn"
31
- >
32
- <template v-if="multiple || showChip" #selected-item="scope">
33
- <q-chip
34
- v-if="scope.opt"
35
- removable
36
- :tabindex="scope.tabindex"
37
- :style="{ backgroundColor: chipColor }"
38
- icon-remove="close"
39
- text-color="secondary"
40
- @remove="scope.removeAtIndex(scope.index)"
41
- >
42
- {{ scope.opt[optionLabel || 'label'] }}
43
- </q-chip>
44
- </template>
45
-
46
- <template #append>
47
- <q-icon
48
- v-if="!isDisabled && selected && (selected.length || selected > 0)"
49
- name="close"
50
- class="cursor-pointer clear-input"
51
- @click.stop="handleClear"
52
- />
53
- </template>
54
-
55
- <template #no-option>
56
- <div class="q-pa-sm">
57
- <q-item>
58
- <q-item-section class="wrapper-empty-text">
59
- {{ emptyText || 'Ничего не найдено' }}
60
- <button
61
- v-if="allowCreate && internalSearch && internalSearch.trim()"
62
- class="add-new-items"
63
- @click="handleCreateFromSearch"
64
- >
65
- Добавить
66
- </button>
67
- </q-item-section>
68
- </q-item>
69
- </div>
70
- </template>
71
-
72
- <template #option="scope">
73
- <q-item v-if="scope.opt.__loading" class="q-py-md q-ml-md">
74
- <q-spinner-dots size="24px" color="primary" />
75
- </q-item>
76
- <q-item v-else v-bind="scope.itemProps">
77
- <q-item-section>{{ scope.opt[optionLabel || 'label'] }}</q-item-section>
78
- </q-item>
79
- </template>
80
- </q-select>
81
- </template>
82
-
83
- <script setup lang="ts">
84
- import { computed, defineEmits, defineProps, ref, Ref } from 'vue'
85
- type Option = Record<string, any>
86
-
87
- interface AppQSelectProps {
88
- modelValue: any
89
- options: Option[]
90
- placeholder?: string | undefined
91
- emptyText?: string
92
- optionLabel?: string
93
- optionValue?: string
94
- label?: string
95
- multiple?: boolean
96
- loading?: boolean
97
- isShowRequired?: boolean
98
- isDisabled?: boolean
99
- allowCreate?: boolean
100
- isSearch?: boolean
101
- showChip?: boolean
102
- simple?: boolean
103
- hideBottomSpace?: boolean
104
- chipColor?: string
105
- height?: string
106
- borderColor?: string
107
- borderRadius?: string
108
- menuWidth?: string
109
- rules?: ((val: any) => boolean | string)[]
110
- }
111
-
112
- const props = defineProps<AppQSelectProps>()
113
- const emit = defineEmits(['update:modelValue', 'update:scroll', 'update:search', 'clear', 'create'])
114
-
115
- const select = ref({})
116
- const lcText: Ref<string> = ref('')
117
- const internalSearch = ref('')
118
-
119
- const selected = computed({
120
- get() {
121
- return props.modelValue
122
- },
123
- set(value) {
124
- emit('update:modelValue', value)
125
- },
126
- })
127
-
128
- function handleClear() {
129
- const emptyValue = props.multiple ? [] : null
130
- selected.value = emptyValue
131
- lcText.value = ''
132
- emit('update:modelValue', emptyValue)
133
- emit('clear')
134
- }
135
-
136
- const filteredOptions = computed(() => {
137
- const labelKey = props.optionLabel || 'label'
138
-
139
- const baseOptions = props.options.filter(x => {
140
- const label = x[labelKey]
141
- return typeof label === 'string' && label.toLowerCase().includes(lcText.value)
142
- })
143
-
144
- if (props.loading) {
145
- return [
146
- ...baseOptions,
147
- {
148
- __loading: true,
149
- label: '__loading__',
150
- value: '__loading__',
151
- },
152
- ]
153
- }
154
-
155
- return baseOptions
156
- })
157
-
158
- function handleCreateFromSearch() {
159
- const labelKey = props.optionLabel || 'label'
160
- const valueKey = props.optionValue || 'value'
161
-
162
- const trimmed = internalSearch.value?.trim()
163
- if (!trimmed) return
164
-
165
- const newOption = {
166
- [labelKey]: trimmed,
167
- [valueKey]: trimmed,
168
- }
169
- emit('create', newOption)
170
- handleClear()
171
- }
172
-
173
- function filterFn(val: string, update: (cb: () => void) => void) {
174
- debouncedFilter(val, update)
175
- }
176
-
177
- const debouncedFilter = debounce((val: string, update: (cb: () => void) => void) => {
178
- internalSearch.value = val
179
- emit('update:search', val)
180
- update(() => {
181
- lcText.value = val.toLowerCase()
182
- })
183
- }, 500)
184
-
185
- function onScroll({ to, ref: qSelectRef }) {
186
- const totalOptions = qSelectRef.options.length
187
- if (to >= totalOptions - 1 && !lcText.value) {
188
- emit('update:scroll')
189
- }
190
- }
191
-
192
- function debounce<T>(fn: T, ms) {
193
- let timeoutId
194
- return function (...args) {
195
- clearTimeout(timeoutId)
196
- return new Promise(resolve => {
197
- timeoutId = setTimeout(() => {
198
- resolve(fn(...args))
199
- }, ms)
200
- })
201
- }
202
- }
203
- </script>
204
-
205
- <style lang="scss" scoped>
206
- .wrapper-empty-text {
207
- display: flex;
208
- align-items: center;
209
- justify-content: space-between;
210
- flex-direction: row;
211
- .add-new-items {
212
- background: #3f8cff;
213
- color: #fff;
214
- outline: none;
215
- border: none;
216
- border-radius: 4px;
217
- padding: 5px 10px;
218
- cursor: pointer;
219
- }
220
- }
221
- .field-label {
222
- font-size: 14px;
223
- font-weight: 700;
224
- color: #7d8592;
225
- }
226
- .required {
227
- color: #f65160;
228
- font-weight: bold;
229
- }
230
-
231
- ::v-deep(.q-placeholder) {
232
- color: #7d8592;
233
- }
234
- ::v-deep(.q-field__control) {
235
- border-radius: 8px;
236
- border: 1px solid #d8e0f0;
237
- background: #fff;
238
- box-shadow: 0 1px 2px 0 rgba(184, 200, 224, 0.22);
239
- }
240
- :deep(.q-field__control:before) {
241
- display: none;
242
- }
243
- :global(.q-field--filled.q-field--highlighted .q-field__control:before) {
244
- background: #fff !important;
245
- border: none;
246
- }
247
- ::v-deep(.q-field--with-bottom) {
248
- padding-bottom: 0;
249
- }
250
- ::v-deep(.q-field__bottom) {
251
- padding: 0;
252
- }
253
- .clear-input {
254
- color: #d8e0f0;
255
- }
256
- ::v-deep(.q-chip) {
257
- border-radius: 4px;
258
- background: #e9eff9;
259
- color: #1d425d;
260
- font-family: NunitoSansFont, sans-serif;
261
- font-size: 14px;
262
- height: 30px;
263
- line-height: 30px;
264
- padding: 0 15px;
265
- .q-chip__icon {
266
- color: #3f8cff;
267
- margin-left: 5px;
268
- }
269
- }
270
- </style>
1
+ <template>
2
+ <label class="field-label">
3
+ {{ label }}
4
+ <span v-if="rules?.length && isShowRequired" class="required">*</span>
5
+ </label>
6
+
7
+ <q-select
8
+ ref="select"
9
+ v-model="selected"
10
+ :options="filteredOptions"
11
+ :disable="isDisabled"
12
+ :multiple="multiple"
13
+ :popup-content-class="'custom-select-menu'"
14
+ :hide-selected="!showChip && !simple"
15
+ :placeholder="placeholder"
16
+ :loading="loading"
17
+ :option-value="optionValue || 'value'"
18
+ :option-label="optionLabel || 'label'"
19
+ emit-value
20
+ filled
21
+ map-options
22
+ stack-label
23
+ use-input
24
+ :use-chips="!simple"
25
+ :hide-bottom-space="hideBottomSpace"
26
+ input-debounce="100"
27
+ autocomplete=""
28
+ :rules="rules"
29
+ @virtual-scroll="onScroll"
30
+ @filter="filterFn"
31
+ >
32
+ <template v-if="multiple || showChip" #selected-item="scope">
33
+ <q-chip
34
+ v-if="scope.opt"
35
+ removable
36
+ :tabindex="scope.tabindex"
37
+ :style="{ backgroundColor: chipColor }"
38
+ icon-remove="close"
39
+ text-color="secondary"
40
+ @remove="scope.removeAtIndex(scope.index)"
41
+ >
42
+ {{ scope.opt[optionLabel || 'label'] }}
43
+ </q-chip>
44
+ </template>
45
+
46
+ <template #append>
47
+ <q-icon
48
+ v-if="!isDisabled && selected && (selected.length || selected > 0)"
49
+ name="close"
50
+ class="cursor-pointer clear-input"
51
+ @click.stop="handleClear"
52
+ />
53
+ </template>
54
+
55
+ <template #no-option>
56
+ <div class="q-pa-sm">
57
+ <q-item>
58
+ <q-item-section class="wrapper-empty-text">
59
+ {{ emptyText || 'Ничего не найдено' }}
60
+ <button
61
+ v-if="allowCreate && internalSearch && internalSearch.trim()"
62
+ class="add-new-items"
63
+ @click="handleCreateFromSearch"
64
+ >
65
+ Добавить
66
+ </button>
67
+ </q-item-section>
68
+ </q-item>
69
+ </div>
70
+ </template>
71
+
72
+ <template #option="scope">
73
+ <q-item v-if="scope.opt.__loading" class="q-py-md q-ml-md">
74
+ <q-spinner-dots size="24px" color="primary" />
75
+ </q-item>
76
+ <q-item v-else v-bind="scope.itemProps">
77
+ <q-item-section>{{ scope.opt[optionLabel || 'label'] }}</q-item-section>
78
+ </q-item>
79
+ </template>
80
+ </q-select>
81
+ </template>
82
+
83
+ <script setup lang="ts">
84
+ import { computed, defineEmits, defineProps, ref, Ref } from 'vue'
85
+ type Option = Record<string, any>
86
+
87
+ interface AppQSelectProps {
88
+ modelValue: any
89
+ options: Option[]
90
+ placeholder?: string | undefined
91
+ emptyText?: string
92
+ optionLabel?: string
93
+ optionValue?: string
94
+ label?: string
95
+ multiple?: boolean
96
+ loading?: boolean
97
+ isShowRequired?: boolean
98
+ isDisabled?: boolean
99
+ allowCreate?: boolean
100
+ isSearch?: boolean
101
+ showChip?: boolean
102
+ simple?: boolean
103
+ hideBottomSpace?: boolean
104
+ chipColor?: string
105
+ height?: string
106
+ borderColor?: string
107
+ borderRadius?: string
108
+ menuWidth?: string
109
+ rules?: ((val: any) => boolean | string)[]
110
+ }
111
+
112
+ const props = defineProps<AppQSelectProps>()
113
+ const emit = defineEmits(['update:modelValue', 'update:scroll', 'update:search', 'clear', 'create'])
114
+
115
+ const select = ref({})
116
+ const lcText: Ref<string> = ref('')
117
+ const internalSearch = ref('')
118
+
119
+ const selected = computed({
120
+ get() {
121
+ return props.modelValue
122
+ },
123
+ set(value) {
124
+ emit('update:modelValue', value)
125
+ },
126
+ })
127
+
128
+ function handleClear() {
129
+ const emptyValue = props.multiple ? [] : null
130
+ selected.value = emptyValue
131
+ lcText.value = ''
132
+ emit('update:modelValue', emptyValue)
133
+ emit('clear')
134
+ }
135
+
136
+ const filteredOptions = computed(() => {
137
+ const labelKey = props.optionLabel || 'label'
138
+
139
+ const baseOptions = props.options.filter(x => {
140
+ const label = x[labelKey]
141
+ return typeof label === 'string' && label.toLowerCase().includes(lcText.value)
142
+ })
143
+
144
+ if (props.loading) {
145
+ return [
146
+ ...baseOptions,
147
+ {
148
+ __loading: true,
149
+ label: '__loading__',
150
+ value: '__loading__',
151
+ },
152
+ ]
153
+ }
154
+
155
+ return baseOptions
156
+ })
157
+
158
+ function handleCreateFromSearch() {
159
+ const labelKey = props.optionLabel || 'label'
160
+ const valueKey = props.optionValue || 'value'
161
+
162
+ const trimmed = internalSearch.value?.trim()
163
+ if (!trimmed) return
164
+
165
+ const newOption = {
166
+ [labelKey]: trimmed,
167
+ [valueKey]: trimmed,
168
+ }
169
+ emit('create', newOption)
170
+ handleClear()
171
+ }
172
+
173
+ function filterFn(val: string, update: (cb: () => void) => void) {
174
+ debouncedFilter(val, update)
175
+ }
176
+
177
+ const debouncedFilter = debounce((val: string, update: (cb: () => void) => void) => {
178
+ internalSearch.value = val
179
+ emit('update:search', val)
180
+ update(() => {
181
+ lcText.value = val.toLowerCase()
182
+ })
183
+ }, 500)
184
+
185
+ function onScroll({ to, ref: qSelectRef }) {
186
+ const totalOptions = qSelectRef.options.length
187
+ if (to >= totalOptions - 1 && !lcText.value) {
188
+ emit('update:scroll')
189
+ }
190
+ }
191
+
192
+ function debounce<T>(fn: T, ms) {
193
+ let timeoutId
194
+ return function (...args) {
195
+ clearTimeout(timeoutId)
196
+ return new Promise(resolve => {
197
+ timeoutId = setTimeout(() => {
198
+ resolve(fn(...args))
199
+ }, ms)
200
+ })
201
+ }
202
+ }
203
+ </script>
204
+
205
+ <style lang="scss" scoped>
206
+ .wrapper-empty-text {
207
+ display: flex;
208
+ align-items: center;
209
+ justify-content: space-between;
210
+ flex-direction: row;
211
+ .add-new-items {
212
+ background: #3f8cff;
213
+ color: #fff;
214
+ outline: none;
215
+ border: none;
216
+ border-radius: 4px;
217
+ padding: 5px 10px;
218
+ cursor: pointer;
219
+ }
220
+ }
221
+ .field-label {
222
+ font-size: 14px;
223
+ font-weight: 700;
224
+ color: #7d8592;
225
+ }
226
+ .required {
227
+ color: #f65160;
228
+ font-weight: bold;
229
+ }
230
+
231
+ ::v-deep(.q-placeholder) {
232
+ color: #7d8592;
233
+ }
234
+ ::v-deep(.q-field__control) {
235
+ border-radius: 8px;
236
+ border: 1px solid #d8e0f0;
237
+ background: #fff;
238
+ box-shadow: 0 1px 2px 0 rgba(184, 200, 224, 0.22);
239
+ }
240
+ :deep(.q-field__control:before) {
241
+ display: none;
242
+ }
243
+ :global(.q-field--filled.q-field--highlighted .q-field__control:before) {
244
+ background: #fff !important;
245
+ border: none;
246
+ }
247
+ ::v-deep(.q-field--with-bottom) {
248
+ padding-bottom: 0;
249
+ }
250
+ ::v-deep(.q-field__bottom) {
251
+ padding: 0;
252
+ }
253
+ .clear-input {
254
+ color: #d8e0f0;
255
+ }
256
+ ::v-deep(.q-chip) {
257
+ border-radius: 4px;
258
+ background: #e9eff9;
259
+ color: #1d425d;
260
+ font-family: NunitoSansFont, sans-serif;
261
+ font-size: 14px;
262
+ height: 30px;
263
+ line-height: 30px;
264
+ padding: 0 15px;
265
+ .q-chip__icon {
266
+ color: #3f8cff;
267
+ margin-left: 5px;
268
+ }
269
+ }
270
+ </style>