shared-ritm 1.3.27 → 1.3.29

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,356 +1,375 @@
1
- <template>
2
- <q-dialog :model-value="modelValue" @update:model-value="toggleModal">
3
- <q-card style="min-width: 700px">
4
- <q-card-section>
5
- <div class="modal-title">{{ title }}</div>
6
- </q-card-section>
7
-
8
- <q-card-section>
9
- <q-form ref="formRef" @submit.prevent="submit">
10
- <div v-for="field in fields" :key="field.key" class="field-wrapper">
11
- <label v-if="field.type === 'text'" class="field-label">
12
- {{ field.label }}
13
- <span v-if="field.rules?.length && mode !== 'view'" class="required">*</span>
14
- </label>
15
-
16
- <q-input
17
- v-if="field.type === 'text'"
18
- v-model="formData[field.key]"
19
- :rules="field.rules"
20
- :readonly="mode === 'view' || (field.key === 'uuid' && mode === 'edit')"
21
- filled
22
- :placeholder="field.placeholder"
23
- >
24
- <template #append>
25
- <q-icon
26
- v-if="mode !== 'view' && formData[field.key] && !(field.key === 'uuid' && mode === 'edit')"
27
- name="close"
28
- class="cursor-pointer clear-input"
29
- @click="() => handleClear(field.key)"
30
- />
31
- <q-btn
32
- v-if="field.key === 'uuid' && mode === 'create'"
33
- flat
34
- no-caps
35
- label="UUID"
36
- size="sm"
37
- class="q-ml-sm uuid-btn"
38
- @click="generateUuid"
39
- />
40
- <q-icon
41
- v-else-if="field.key === 'uuid' && mode !== 'create'"
42
- name="content_copy"
43
- class="cursor-pointer q-ml-sm copy-icon"
44
- color="primary"
45
- @click="copyToClipboard(formData[field.key])"
46
- />
47
- </template>
48
- </q-input>
49
-
50
- <app-modal-select
51
- v-else-if="field.type === 'select'"
52
- v-model="formData[field.key]"
53
- :options="filteredOptions[field.key] || field.options"
54
- :rules="field.rules"
55
- :placeholder="mode === 'view' ? '' : field.placeholder"
56
- :multiple="true"
57
- :show-chip="true"
58
- :is-disabled="mode === 'view'"
59
- :loading="field.loading"
60
- :label="field.label"
61
- :is-show-required="mode !== 'view'"
62
- empty-text="Ничего не найдено"
63
- option-label="label"
64
- option-value="value"
65
- chip-color="#e9eff9"
66
- @update:search="val => field.onSearch?.(val)"
67
- @update:scroll="() => field.onScroll?.()"
68
- @clear="
69
- () => {
70
- handleClear(field.key)
71
- nextTick(() => formRef.value?.validate())
72
- }
73
- "
74
- />
75
- </div>
76
- </q-form>
77
- </q-card-section>
78
-
79
- <q-card-actions align="center">
80
- <q-btn v-if="mode === 'view'" class="remove" flat label="Удалить" :loading="loading" @click="emit('delete')" />
81
- <q-btn
82
- v-if="mode !== 'view'"
83
- class="confirm"
84
- flat
85
- :label="mode === 'edit' ? 'Сохранить' : 'Создать'"
86
- :disable="isSubmitDisabled"
87
- :loading="loading"
88
- @click="submit"
89
- />
90
- <q-btn v-else class="confirm" flat label="Редактировать" :disable="loading" @click="$emit('edit')" />
91
- <q-btn class="cancel" flat label="Закрыть" :disable="loading" @click="close" />
92
- </q-card-actions>
93
- </q-card>
94
- </q-dialog>
95
- </template>
96
-
97
- <script setup lang="ts">
98
- import { ref, watch, defineProps, defineEmits, nextTick, computed } from 'vue'
99
- import { useQuasar } from 'quasar'
100
- import AppModalSelect from '../components/ModalSelect.vue'
101
- import { notificationSettings } from '@/utils/notification'
102
- import { isEqual, normalizeValue, uuidv4 } from '@/utils/helpers'
103
-
104
- type ModalMode = 'view' | 'edit' | 'create'
105
- type FieldType = 'text' | 'select'
106
-
107
- interface FieldOption {
108
- label: string
109
- value: string
110
- }
111
- interface FieldSchema {
112
- key: string
113
- label: string
114
- type: FieldType
115
- rules?: ((val: any) => boolean | string)[]
116
- options?: FieldOption[]
117
- placeholder?: string
118
- onSearch?: (val: string) => void
119
- onScroll?: () => void
120
- loading?: boolean
121
- }
122
-
123
- const props = defineProps<{
124
- modelValue: boolean
125
- title: string
126
- mode: ModalMode
127
- fields: FieldSchema[]
128
- initialData?: Record<string, any>
129
- loading?: boolean
130
- }>()
131
- const emit = defineEmits<{
132
- (e: 'update:modelValue', val: boolean, hasChanges?: boolean): void
133
- (e: 'submit', data: Record<string, any>): void
134
- (e: 'edit'): void
135
- (e: 'delete'): void
136
- }>()
137
-
138
- const $q = useQuasar()
139
- const formRef = ref()
140
- const formData = ref<Record<string, any>>({})
141
- const filteredOptions = ref<Record<string, FieldOption[]>>({})
142
- const isSubmitDisabled = computed(() => {
143
- if (props.mode === 'view') return false
144
-
145
- const hasEmptyRequired = props.fields.some(field => {
146
- const isRequired = field.rules?.some(rule => rule('') !== true)
147
- const val = formData.value[field.key]
148
- const normalized = normalizeValue(val)
149
-
150
- const empty =
151
- normalized === null ||
152
- normalized === undefined ||
153
- (typeof normalized === 'string' && normalized.trim() === '') ||
154
- (Array.isArray(normalized) && normalized.length === 0)
155
-
156
- return isRequired && empty
157
- })
158
-
159
- if (hasEmptyRequired) return true
160
-
161
- const hasChanges = props.fields.some(field => {
162
- const key = field.key
163
- const current = normalizeValue(formData.value[key])
164
- const initial = normalizeValue(props.initialData?.[key])
165
- return !isEqual(current, initial)
166
- })
167
-
168
- return !hasChanges
169
- })
170
- function toggleModal(val: boolean) {
171
- if (val) {
172
- emit('update:modelValue', val)
173
- } else {
174
- close()
175
- }
176
- }
177
- function checkChanges() {
178
- if (props.mode === 'view') {
179
- return false
180
- }
181
-
182
- if (!props.initialData || !Object.keys(props.initialData).length) {
183
- return props.fields?.some(
184
- field =>
185
- formData.value?.[field.key] &&
186
- !(Array.isArray(formData.value?.[field.key]) && !formData.value?.[field.key].length),
187
- )
188
- }
189
-
190
- return props.fields?.some(field => !isEqual(formData.value?.[field.key], props.initialData?.[field.key]))
191
- }
192
- function close() {
193
- emit('update:modelValue', false, checkChanges())
194
- }
195
- function submit() {
196
- formRef.value?.validate().then(ok => {
197
- if (!ok) return
198
-
199
- const changed: Record<string, any> = {}
200
-
201
- for (const field of props.fields) {
202
- const key = field.key
203
- const current = formData.value[key]
204
- const initial = props.initialData?.[key]
205
-
206
- const normalizedCurrent = field.type === 'select' ? normalizeValue(current) : current
207
- const normalizedInitial = field.type === 'select' ? normalizeValue(initial) : initial
208
-
209
- if (!isEqual(normalizedCurrent, normalizedInitial)) {
210
- changed[key] = normalizedCurrent
211
- }
212
- }
213
-
214
- emit('submit', changed)
215
- })
216
- }
217
- function handleClear(key: string) {
218
- const field = props.fields.find(f => f.key === key)
219
- formData.value[key] = field?.type === 'select' ? [] : ''
220
-
221
- nextTick(() => {
222
- formRef.value?.validate()
223
- })
224
- }
225
- function generateUuid() {
226
- formData.value.uuid = uuidv4()
227
- }
228
- function copyToClipboard(text: string) {
229
- navigator.clipboard.writeText(text).then(() => {
230
- $q.notify(notificationSettings('success', 'UUID скопирован'))
231
- })
232
- }
233
-
234
- watch(
235
- () => props.modelValue,
236
- val => {
237
- if (val) {
238
- formData.value = { ...(props.initialData ?? {}) }
239
- }
240
- },
241
- { immediate: true },
242
- )
243
- </script>
244
-
245
- <style lang="scss">
246
- .custom-select-menu {
247
- max-height: 250px !important;
248
- overflow-y: auto !important;
249
- }
250
- </style>
251
- <style scoped lang="scss">
252
- .uuid-btn {
253
- height: 32px;
254
- padding: 0 10px;
255
- border: 1px solid #3f8cff;
256
- color: #3f8cff;
257
- font-weight: 700;
258
- font-size: 14px;
259
- background: white;
260
- border-radius: 6px;
261
- }
262
-
263
- .q-card {
264
- border-radius: 12px;
265
- background: #fff;
266
- box-shadow: 0 4px 4px 0 rgba(0, 0, 0, 0.25);
267
- font-family: NunitoSansFont, sans-serif;
268
-
269
- .modal-title {
270
- color: #1d425d;
271
- text-align: center;
272
- font-size: 32px;
273
- font-weight: 700;
274
- padding: 18px 29px;
275
- }
276
-
277
- .q-card__section {
278
- padding: 0;
279
- }
280
-
281
- .q-form {
282
- padding: 0 29px;
283
- }
284
-
285
- .field-wrapper {
286
- display: flex;
287
- flex-direction: column;
288
- margin-bottom: 15px;
289
- }
290
-
291
- .field-label {
292
- font-size: 14px;
293
- font-weight: 700;
294
- color: #7d8592;
295
- }
296
- ::v-deep(.q-placeholder) {
297
- color: #7d8592;
298
- }
299
- ::v-deep(.q-field__control) {
300
- border-radius: 8px;
301
- border: 1px solid #d8e0f0;
302
- background: #fff;
303
- box-shadow: 0px 1px 2px 0px rgba(184, 200, 224, 0.22);
304
- }
305
-
306
- ::v-deep(.q-field--filled .q-field__control:before) {
307
- background: #fff !important;
308
- border: none;
309
- }
310
-
311
- ::v-deep(.q-field--with-bottom) {
312
- padding-bottom: 0;
313
- }
314
-
315
- ::v-deep(.q-field__bottom) {
316
- padding: 0;
317
- }
318
-
319
- .clear-input {
320
- color: #d8e0f0;
321
- }
322
-
323
- .required {
324
- color: #f65160;
325
- font-weight: bold;
326
- }
327
-
328
- &__actions {
329
- padding: 18px 0;
330
- border-radius: 0px 0px 16px 16px;
331
- background: #f4f9fd;
332
-
333
- button {
334
- padding: 13px 37px;
335
- border-radius: 4px;
336
- font-size: 16px;
337
- font-weight: 700;
338
- text-transform: none;
339
-
340
- &.remove {
341
- border: 1px solid #f65160;
342
- color: #f65160;
343
- }
344
- &.confirm {
345
- background: #3f8cff;
346
- color: #fff;
347
- }
348
-
349
- &.cancel {
350
- color: #3f8cff;
351
- border: 1px solid #3f8cff;
352
- }
353
- }
354
- }
355
- }
356
- </style>
1
+ <template>
2
+ <q-dialog :model-value="modelValue" @update:model-value="toggleModal">
3
+ <q-card style="min-width: 700px">
4
+ <q-card-section>
5
+ <div class="modal-title">{{ title }}</div>
6
+ </q-card-section>
7
+
8
+ <q-card-section>
9
+ <q-form ref="formRef" @submit.prevent="submit">
10
+ <div v-for="field in fields" :key="field.key" class="field-wrapper">
11
+ <label v-if="field.type === 'text'" :data-test="`${field.key}-label`" class="field-label">
12
+ {{ field.label }}
13
+ <span v-if="field.rules?.length && mode !== 'view'" class="required">*</span>
14
+ </label>
15
+
16
+ <q-input
17
+ v-if="field.type === 'text'"
18
+ v-model="formData[field.key]"
19
+ :data-test="`${field.key}-input`"
20
+ :rules="field.rules"
21
+ :readonly="mode === 'view' || (field.key === 'uuid' && mode === 'edit')"
22
+ filled
23
+ :placeholder="field.placeholder"
24
+ >
25
+ <template #append>
26
+ <q-icon
27
+ v-if="mode !== 'view' && formData[field.key] && !(field.key === 'uuid' && mode === 'edit')"
28
+ name="close"
29
+ class="cursor-pointer clear-input"
30
+ @click="() => handleClear(field.key)"
31
+ />
32
+ <q-btn
33
+ v-if="field.key === 'uuid' && mode === 'create'"
34
+ flat
35
+ no-caps
36
+ label="UUID"
37
+ size="sm"
38
+ class="q-ml-sm uuid-btn"
39
+ @click="generateUuid"
40
+ />
41
+ <q-icon
42
+ v-else-if="field.key === 'uuid' && mode !== 'create'"
43
+ name="content_copy"
44
+ class="cursor-pointer q-ml-sm copy-icon"
45
+ color="primary"
46
+ @click="copyToClipboard(formData[field.key])"
47
+ />
48
+ </template>
49
+ </q-input>
50
+
51
+ <app-modal-select
52
+ v-else-if="field.type === 'select'"
53
+ v-model="formData[field.key]"
54
+ :data-test="`${field.key}-select`"
55
+ :options="filteredOptions[field.key] || field.options"
56
+ :rules="field.rules"
57
+ :placeholder="mode === 'view' ? '' : field.placeholder"
58
+ :multiple="true"
59
+ :show-chip="true"
60
+ :is-disabled="mode === 'view'"
61
+ :loading="field.loading"
62
+ :label="field.label"
63
+ :is-show-required="mode !== 'view'"
64
+ empty-text="Нет данных"
65
+ option-label="label"
66
+ option-value="value"
67
+ chip-color="#e9eff9"
68
+ @update:search="val => field.onSearch?.(val)"
69
+ @update:scroll="() => field.onScroll?.()"
70
+ @clear="
71
+ () => {
72
+ handleClear(field.key)
73
+ nextTick(() => formRef.value?.validate())
74
+ }
75
+ "
76
+ />
77
+ </div>
78
+ </q-form>
79
+ </q-card-section>
80
+
81
+ <q-card-actions align="center">
82
+ <q-btn
83
+ v-if="mode === 'view'"
84
+ class="remove"
85
+ data-test="remove-button"
86
+ flat
87
+ label="Удалить"
88
+ :loading="loading"
89
+ @click="emit('delete')"
90
+ />
91
+ <q-btn
92
+ v-if="mode !== 'view'"
93
+ class="confirm"
94
+ data-test="save-create-button"
95
+ flat
96
+ :label="mode === 'edit' ? 'Сохранить' : 'Создать'"
97
+ :disable="isSubmitDisabled"
98
+ :loading="loading"
99
+ @click="submit"
100
+ />
101
+ <q-btn
102
+ v-else
103
+ class="confirm"
104
+ data-test="edit-button"
105
+ flat
106
+ label="Редактировать"
107
+ :disable="loading"
108
+ @click="$emit('edit')"
109
+ />
110
+ <q-btn class="cancel" data-test="cancel-button" flat label="Закрыть" :disable="loading" @click="close" />
111
+ </q-card-actions>
112
+ </q-card>
113
+ </q-dialog>
114
+ </template>
115
+
116
+ <script setup lang="ts">
117
+ import { ref, watch, defineProps, defineEmits, nextTick, computed } from 'vue'
118
+ import { useQuasar } from 'quasar'
119
+ import AppModalSelect from '../components/ModalSelect.vue'
120
+ import { notificationSettings } from '@/utils/notification'
121
+ import { isEqual, normalizeValue, uuidv4 } from '@/utils/helpers'
122
+
123
+ type ModalMode = 'view' | 'edit' | 'create'
124
+ type FieldType = 'text' | 'select'
125
+
126
+ interface FieldOption {
127
+ label: string
128
+ value: string
129
+ }
130
+ interface FieldSchema {
131
+ key: string
132
+ label: string
133
+ type: FieldType
134
+ rules?: ((val: any) => boolean | string)[]
135
+ options?: FieldOption[]
136
+ placeholder?: string
137
+ onSearch?: (val: string) => void
138
+ onScroll?: () => void
139
+ loading?: boolean
140
+ }
141
+
142
+ const props = defineProps<{
143
+ modelValue: boolean
144
+ title: string
145
+ mode: ModalMode
146
+ fields: FieldSchema[]
147
+ initialData?: Record<string, any>
148
+ loading?: boolean
149
+ }>()
150
+ const emit = defineEmits<{
151
+ (e: 'update:modelValue', val: boolean, hasChanges?: boolean): void
152
+ (e: 'submit', data: Record<string, any>): void
153
+ (e: 'edit'): void
154
+ (e: 'delete'): void
155
+ }>()
156
+
157
+ const $q = useQuasar()
158
+ const formRef = ref()
159
+ const formData = ref<Record<string, any>>({})
160
+ const filteredOptions = ref<Record<string, FieldOption[]>>({})
161
+ const isSubmitDisabled = computed(() => {
162
+ if (props.mode === 'view') return false
163
+
164
+ const hasEmptyRequired = props.fields.some(field => {
165
+ const isRequired = field.rules?.some(rule => rule('') !== true)
166
+ const val = formData.value[field.key]
167
+ const normalized = normalizeValue(val)
168
+
169
+ const empty =
170
+ normalized === null ||
171
+ normalized === undefined ||
172
+ (typeof normalized === 'string' && normalized.trim() === '') ||
173
+ (Array.isArray(normalized) && normalized.length === 0)
174
+
175
+ return isRequired && empty
176
+ })
177
+
178
+ if (hasEmptyRequired) return true
179
+
180
+ const hasChanges = props.fields.some(field => {
181
+ const key = field.key
182
+ const current = normalizeValue(formData.value[key])
183
+ const initial = normalizeValue(props.initialData?.[key])
184
+ return !isEqual(current, initial)
185
+ })
186
+
187
+ return !hasChanges
188
+ })
189
+ function toggleModal(val: boolean) {
190
+ if (val) {
191
+ emit('update:modelValue', val)
192
+ } else {
193
+ close()
194
+ }
195
+ }
196
+ function checkChanges() {
197
+ if (props.mode === 'view') {
198
+ return false
199
+ }
200
+
201
+ if (!props.initialData || !Object.keys(props.initialData).length) {
202
+ return props.fields?.some(
203
+ field =>
204
+ formData.value?.[field.key] &&
205
+ !(Array.isArray(formData.value?.[field.key]) && !formData.value?.[field.key].length),
206
+ )
207
+ }
208
+
209
+ return props.fields?.some(field => !isEqual(formData.value?.[field.key], props.initialData?.[field.key]))
210
+ }
211
+ function close() {
212
+ emit('update:modelValue', false, checkChanges())
213
+ }
214
+ function submit() {
215
+ formRef.value?.validate().then(ok => {
216
+ if (!ok) return
217
+
218
+ const changed: Record<string, any> = {}
219
+
220
+ for (const field of props.fields) {
221
+ const key = field.key
222
+ const current = formData.value[key]
223
+ const initial = props.initialData?.[key]
224
+
225
+ const normalizedCurrent = field.type === 'select' ? normalizeValue(current) : current
226
+ const normalizedInitial = field.type === 'select' ? normalizeValue(initial) : initial
227
+
228
+ if (!isEqual(normalizedCurrent, normalizedInitial)) {
229
+ changed[key] = normalizedCurrent
230
+ }
231
+ }
232
+
233
+ emit('submit', changed)
234
+ })
235
+ }
236
+ function handleClear(key: string) {
237
+ const field = props.fields.find(f => f.key === key)
238
+ formData.value[key] = field?.type === 'select' ? [] : ''
239
+
240
+ nextTick(() => {
241
+ formRef.value?.validate()
242
+ })
243
+ }
244
+ function generateUuid() {
245
+ formData.value.uuid = uuidv4()
246
+ }
247
+ function copyToClipboard(text: string) {
248
+ navigator.clipboard.writeText(text).then(() => {
249
+ $q.notify(notificationSettings('success', 'UUID скопирован'))
250
+ })
251
+ }
252
+
253
+ watch(
254
+ () => props.modelValue,
255
+ val => {
256
+ if (val) {
257
+ formData.value = { ...(props.initialData ?? {}) }
258
+ }
259
+ },
260
+ { immediate: true },
261
+ )
262
+ </script>
263
+
264
+ <style lang="scss">
265
+ .custom-select-menu {
266
+ max-height: 250px !important;
267
+ overflow-y: auto !important;
268
+ }
269
+ </style>
270
+ <style scoped lang="scss">
271
+ .uuid-btn {
272
+ height: 32px;
273
+ padding: 0 10px;
274
+ border: 1px solid #3f8cff;
275
+ color: #3f8cff;
276
+ font-weight: 700;
277
+ font-size: 14px;
278
+ background: white;
279
+ border-radius: 6px;
280
+ }
281
+
282
+ .q-card {
283
+ border-radius: 12px;
284
+ background: #fff;
285
+ box-shadow: 0 4px 4px 0 rgba(0, 0, 0, 0.25);
286
+ font-family: NunitoSansFont, sans-serif;
287
+
288
+ .modal-title {
289
+ color: #1d425d;
290
+ text-align: center;
291
+ font-size: 32px;
292
+ font-weight: 700;
293
+ padding: 18px 29px;
294
+ }
295
+
296
+ .q-card__section {
297
+ padding: 0;
298
+ }
299
+
300
+ .q-form {
301
+ padding: 0 29px;
302
+ }
303
+
304
+ .field-wrapper {
305
+ display: flex;
306
+ flex-direction: column;
307
+ margin-bottom: 15px;
308
+ }
309
+
310
+ .field-label {
311
+ font-size: 14px;
312
+ font-weight: 700;
313
+ color: #7d8592;
314
+ }
315
+ ::v-deep(.q-placeholder) {
316
+ color: #7d8592;
317
+ }
318
+ ::v-deep(.q-field__control) {
319
+ border-radius: 8px;
320
+ border: 1px solid #d8e0f0;
321
+ background: #fff;
322
+ box-shadow: 0px 1px 2px 0px rgba(184, 200, 224, 0.22);
323
+ }
324
+
325
+ ::v-deep(.q-field--filled .q-field__control:before) {
326
+ background: #fff !important;
327
+ border: none;
328
+ }
329
+
330
+ ::v-deep(.q-field--with-bottom) {
331
+ padding-bottom: 0;
332
+ }
333
+
334
+ ::v-deep(.q-field__bottom) {
335
+ padding: 0;
336
+ }
337
+
338
+ .clear-input {
339
+ color: #d8e0f0;
340
+ }
341
+
342
+ .required {
343
+ color: #f65160;
344
+ font-weight: bold;
345
+ }
346
+
347
+ &__actions {
348
+ padding: 18px 0;
349
+ border-radius: 0px 0px 16px 16px;
350
+ background: #f4f9fd;
351
+
352
+ button {
353
+ padding: 13px 37px;
354
+ border-radius: 4px;
355
+ font-size: 16px;
356
+ font-weight: 700;
357
+ text-transform: none;
358
+
359
+ &.remove {
360
+ border: 1px solid #f65160;
361
+ color: #f65160;
362
+ }
363
+ &.confirm {
364
+ background: #3f8cff;
365
+ color: #fff;
366
+ }
367
+
368
+ &.cancel {
369
+ color: #3f8cff;
370
+ border: 1px solid #3f8cff;
371
+ }
372
+ }
373
+ }
374
+ }
375
+ </style>