shared-ritm 1.3.83 → 1.3.84
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.
- package/dist/index.css +1 -1
- package/dist/shared-ritm.es.js +12 -12
- package/dist/shared-ritm.umd.js +3 -3
- package/package.json +70 -70
- package/src/App.vue +2461 -2461
- package/src/api/services/AuthService.ts +67 -67
- package/src/api/services/ControlsService.ts +96 -96
- package/src/api/services/EquipmentService.ts +52 -52
- package/src/api/services/MetricsService.ts +143 -143
- package/src/api/services/RepairsService.ts +111 -111
- package/src/api/services/UserIssueService.ts +32 -32
- package/src/api/services/UserService.ts +129 -129
- package/src/api/services/VideoService.ts +118 -118
- package/src/api/settings/ApiService.ts +3 -1
- package/src/api/types/Api_Auth.ts +121 -121
- package/src/api/types/Api_Equipment.ts +13 -13
- package/src/api/types/Api_Metrics.ts +51 -51
- package/src/api/types/Api_Repairs.ts +187 -187
- package/src/api/types/Api_Search.ts +81 -81
- package/src/api/types/Api_Tasks.ts +376 -376
- package/src/api/types/Api_User.ts +157 -157
- package/src/api/types/Api_User_Issue.ts +36 -36
- package/src/api/types/Api_Video.ts +244 -244
- package/src/common/app-button/Button.stories.ts +369 -369
- package/src/common/app-checkbox/AppCheckbox.vue +31 -31
- package/src/common/app-checkbox/Checkbox.stories.ts +252 -252
- package/src/common/app-date-picker/DatePicker.stories.ts +66 -66
- package/src/common/app-datepicker/Datepicker.stories.ts +145 -145
- package/src/common/app-dialogs/AppConfirmDialog.vue +109 -109
- package/src/common/app-dialogs/Confirm.stories.ts +93 -93
- package/src/common/app-dropdown/Dropdown.stories.ts +94 -94
- package/src/common/app-file/File.stories.ts +104 -104
- package/src/common/app-icon/AppIcon.vue +110 -110
- package/src/common/app-icon/Icon.stories.ts +91 -91
- package/src/common/app-input/Input.stories.ts +160 -160
- package/src/common/app-input-new/AppInputNew.vue +181 -181
- package/src/common/app-input-new/InputNew.stories.ts +240 -240
- package/src/common/app-input-search/InputSearch.stories.ts +149 -149
- package/src/common/app-layout/components/AppLayoutHeader.vue +289 -289
- package/src/common/app-loader/Loader.stories.ts +114 -114
- package/src/common/app-select/AppSelect.vue +159 -159
- package/src/common/app-select/Select.stories.ts +155 -155
- package/src/common/app-sidebar/AppSidebar.vue +174 -174
- package/src/common/app-table/AppTable.vue +313 -313
- package/src/common/app-table/components/ModalSelect.stories.ts +323 -323
- package/src/common/app-table/components/ModalSelect.vue +302 -302
- package/src/common/app-table/components/TableModal.vue +367 -367
- package/src/common/app-table/controllers/useColumnSelector.ts +45 -45
- package/src/common/app-table/controllers/useTableModel.ts +97 -97
- package/src/common/app-toggle/AppToggle.vue +12 -12
- package/src/common/app-toggle/Toggle.stories.ts +245 -245
- package/src/common/app-wrapper/AppWrapper.vue +31 -31
- package/src/configs/storybook.ts +14 -14
- package/src/icons/sidebar/user-requests-icon.vue +23 -23
- package/src/index.ts +134 -134
- package/src/shared/styles/general.css +140 -140
- package/src/styles/variables.sass +12 -12
- package/src/utils/files.ts +38 -38
- package/src/utils/helpers.ts +59 -59
- package/dist/types/api/services/PhotoService.d.ts +0 -40
- package/dist/types/stories/Button.stories.d.ts +0 -13
- package/dist/types/stories/Checkbox.stories.d.ts +0 -7
- package/dist/types/stories/Confirm.stories.d.ts +0 -8
- package/dist/types/stories/DatePicker.stories.d.ts +0 -8
- package/dist/types/stories/Dropdown.stories.d.ts +0 -8
- package/dist/types/stories/File.stories.d.ts +0 -8
- package/dist/types/stories/Icon.stories.d.ts +0 -7
- package/dist/types/stories/Input.stories.d.ts +0 -11
- package/dist/types/stories/InputNew.stories.d.ts +0 -12
- package/dist/types/stories/InputSearch.stories.d.ts +0 -10
- package/dist/types/stories/Loader.stories.d.ts +0 -8
- package/dist/types/stories/Select.stories.d.ts +0 -7
- package/dist/types/stories/Toggle.stories.d.ts +0 -8
|
@@ -1,367 +1,367 @@
|
|
|
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 v-if="mode === 'view'" class="remove" flat label="Удалить" :loading="loading" @click="emit('delete')" />
|
|
83
|
-
<q-btn
|
|
84
|
-
v-if="mode !== 'view'"
|
|
85
|
-
class="confirm"
|
|
86
|
-
data-test="save-create-button"
|
|
87
|
-
flat
|
|
88
|
-
:label="mode === 'edit' ? 'Сохранить' : 'Создать'"
|
|
89
|
-
:disable="isSubmitDisabled"
|
|
90
|
-
:loading="loading"
|
|
91
|
-
@click="submit"
|
|
92
|
-
/>
|
|
93
|
-
<q-btn
|
|
94
|
-
v-else
|
|
95
|
-
class="confirm"
|
|
96
|
-
data-test="edit-button"
|
|
97
|
-
flat
|
|
98
|
-
label="Редактировать"
|
|
99
|
-
:disable="loading"
|
|
100
|
-
@click="$emit('edit')"
|
|
101
|
-
/>
|
|
102
|
-
<q-btn class="cancel" data-test="close-button" flat label="Закрыть" :disable="loading" @click="close" />
|
|
103
|
-
</q-card-actions>
|
|
104
|
-
</q-card>
|
|
105
|
-
</q-dialog>
|
|
106
|
-
</template>
|
|
107
|
-
|
|
108
|
-
<script setup lang="ts">
|
|
109
|
-
import { ref, watch, defineProps, defineEmits, nextTick, computed } from 'vue'
|
|
110
|
-
import { useQuasar } from 'quasar'
|
|
111
|
-
import AppModalSelect from '../components/ModalSelect.vue'
|
|
112
|
-
import { notificationSettings } from '@/utils/notification'
|
|
113
|
-
import { isEqual, normalizeValue, uuidv4 } from '@/utils/helpers'
|
|
114
|
-
|
|
115
|
-
type ModalMode = 'view' | 'edit' | 'create'
|
|
116
|
-
type FieldType = 'text' | 'select'
|
|
117
|
-
|
|
118
|
-
interface FieldOption {
|
|
119
|
-
label: string
|
|
120
|
-
value: string
|
|
121
|
-
}
|
|
122
|
-
interface FieldSchema {
|
|
123
|
-
key: string
|
|
124
|
-
label: string
|
|
125
|
-
type: FieldType
|
|
126
|
-
rules?: ((val: any) => boolean | string)[]
|
|
127
|
-
options?: FieldOption[]
|
|
128
|
-
placeholder?: string
|
|
129
|
-
onSearch?: (val: string) => void
|
|
130
|
-
onScroll?: () => void
|
|
131
|
-
loading?: boolean
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const props = defineProps<{
|
|
135
|
-
modelValue: boolean
|
|
136
|
-
title: string
|
|
137
|
-
mode: ModalMode
|
|
138
|
-
fields: FieldSchema[]
|
|
139
|
-
initialData?: Record<string, any>
|
|
140
|
-
loading?: boolean
|
|
141
|
-
}>()
|
|
142
|
-
const emit = defineEmits<{
|
|
143
|
-
(e: 'update:modelValue', val: boolean, hasChanges?: boolean): void
|
|
144
|
-
(e: 'submit', data: Record<string, any>): void
|
|
145
|
-
(e: 'edit'): void
|
|
146
|
-
(e: 'delete'): void
|
|
147
|
-
}>()
|
|
148
|
-
|
|
149
|
-
const $q = useQuasar()
|
|
150
|
-
const formRef = ref()
|
|
151
|
-
const formData = ref<Record<string, any>>({})
|
|
152
|
-
const filteredOptions = ref<Record<string, FieldOption[]>>({})
|
|
153
|
-
const isSubmitDisabled = computed(() => {
|
|
154
|
-
if (props.mode === 'view') return false
|
|
155
|
-
|
|
156
|
-
const hasEmptyRequired = props.fields.some(field => {
|
|
157
|
-
const isRequired = field.rules?.some(rule => rule('') !== true)
|
|
158
|
-
const val = formData.value[field.key]
|
|
159
|
-
const normalized = normalizeValue(val)
|
|
160
|
-
|
|
161
|
-
const empty =
|
|
162
|
-
normalized === null ||
|
|
163
|
-
normalized === undefined ||
|
|
164
|
-
(typeof normalized === 'string' && normalized.trim() === '') ||
|
|
165
|
-
(Array.isArray(normalized) && normalized.length === 0)
|
|
166
|
-
|
|
167
|
-
return isRequired && empty
|
|
168
|
-
})
|
|
169
|
-
|
|
170
|
-
if (hasEmptyRequired) return true
|
|
171
|
-
|
|
172
|
-
const hasChanges = props.fields.some(field => {
|
|
173
|
-
const key = field.key
|
|
174
|
-
const current = normalizeValue(formData.value[key])
|
|
175
|
-
const initial = normalizeValue(props.initialData?.[key])
|
|
176
|
-
return !isEqual(current, initial)
|
|
177
|
-
})
|
|
178
|
-
|
|
179
|
-
return !hasChanges
|
|
180
|
-
})
|
|
181
|
-
function toggleModal(val: boolean) {
|
|
182
|
-
if (val) {
|
|
183
|
-
emit('update:modelValue', val)
|
|
184
|
-
} else {
|
|
185
|
-
close()
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
function checkChanges() {
|
|
189
|
-
if (props.mode === 'view') {
|
|
190
|
-
return false
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
if (!props.initialData || !Object.keys(props.initialData).length) {
|
|
194
|
-
return props.fields?.some(
|
|
195
|
-
field =>
|
|
196
|
-
formData.value?.[field.key] &&
|
|
197
|
-
!(Array.isArray(formData.value?.[field.key]) && !formData.value?.[field.key].length),
|
|
198
|
-
)
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
return props.fields?.some(field => !isEqual(formData.value?.[field.key], props.initialData?.[field.key]))
|
|
202
|
-
}
|
|
203
|
-
function close() {
|
|
204
|
-
emit('update:modelValue', false, checkChanges())
|
|
205
|
-
}
|
|
206
|
-
function submit() {
|
|
207
|
-
formRef.value?.validate().then(ok => {
|
|
208
|
-
if (!ok) return
|
|
209
|
-
|
|
210
|
-
const changed: Record<string, any> = {}
|
|
211
|
-
|
|
212
|
-
for (const field of props.fields) {
|
|
213
|
-
const key = field.key
|
|
214
|
-
const current = formData.value[key]
|
|
215
|
-
const initial = props.initialData?.[key]
|
|
216
|
-
|
|
217
|
-
const normalizedCurrent = field.type === 'select' ? normalizeValue(current) : current
|
|
218
|
-
const normalizedInitial = field.type === 'select' ? normalizeValue(initial) : initial
|
|
219
|
-
|
|
220
|
-
if (!isEqual(normalizedCurrent, normalizedInitial)) {
|
|
221
|
-
changed[key] = normalizedCurrent
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
emit('submit', changed)
|
|
226
|
-
})
|
|
227
|
-
}
|
|
228
|
-
function handleClear(key: string) {
|
|
229
|
-
const field = props.fields.find(f => f.key === key)
|
|
230
|
-
formData.value[key] = field?.type === 'select' ? [] : ''
|
|
231
|
-
|
|
232
|
-
nextTick(() => {
|
|
233
|
-
formRef.value?.validate()
|
|
234
|
-
})
|
|
235
|
-
}
|
|
236
|
-
function generateUuid() {
|
|
237
|
-
formData.value.uuid = uuidv4()
|
|
238
|
-
}
|
|
239
|
-
function copyToClipboard(text: string) {
|
|
240
|
-
navigator.clipboard.writeText(text).then(() => {
|
|
241
|
-
$q.notify(notificationSettings('success', 'UUID скопирован'))
|
|
242
|
-
})
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
watch(
|
|
246
|
-
() => props.modelValue,
|
|
247
|
-
val => {
|
|
248
|
-
if (val) {
|
|
249
|
-
formData.value = { ...(props.initialData ?? {}) }
|
|
250
|
-
}
|
|
251
|
-
},
|
|
252
|
-
{ immediate: true },
|
|
253
|
-
)
|
|
254
|
-
</script>
|
|
255
|
-
|
|
256
|
-
<style lang="scss">
|
|
257
|
-
.custom-select-menu {
|
|
258
|
-
max-height: 250px !important;
|
|
259
|
-
overflow-y: auto !important;
|
|
260
|
-
}
|
|
261
|
-
</style>
|
|
262
|
-
<style scoped lang="scss">
|
|
263
|
-
.uuid-btn {
|
|
264
|
-
height: 32px;
|
|
265
|
-
padding: 0 10px;
|
|
266
|
-
border: 1px solid #3f8cff;
|
|
267
|
-
color: #3f8cff;
|
|
268
|
-
font-weight: 700;
|
|
269
|
-
font-size: 14px;
|
|
270
|
-
background: white;
|
|
271
|
-
border-radius: 6px;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
.q-card {
|
|
275
|
-
border-radius: 12px;
|
|
276
|
-
background: #fff;
|
|
277
|
-
box-shadow: 0 4px 4px 0 rgba(0, 0, 0, 0.25);
|
|
278
|
-
font-family: NunitoSansFont, sans-serif;
|
|
279
|
-
|
|
280
|
-
.modal-title {
|
|
281
|
-
color: #1d425d;
|
|
282
|
-
text-align: center;
|
|
283
|
-
font-size: 32px;
|
|
284
|
-
font-weight: 700;
|
|
285
|
-
padding: 18px 29px;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
.q-card__section {
|
|
289
|
-
padding: 0;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
.q-form {
|
|
293
|
-
padding: 0 29px;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
.field-wrapper {
|
|
297
|
-
display: flex;
|
|
298
|
-
flex-direction: column;
|
|
299
|
-
margin-bottom: 15px;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
.field-label {
|
|
303
|
-
font-size: 14px;
|
|
304
|
-
font-weight: 700;
|
|
305
|
-
color: #7d8592;
|
|
306
|
-
}
|
|
307
|
-
::v-deep(.q-placeholder) {
|
|
308
|
-
color: #7d8592;
|
|
309
|
-
}
|
|
310
|
-
::v-deep(.q-field__control) {
|
|
311
|
-
border-radius: 8px;
|
|
312
|
-
border: 1px solid #d8e0f0;
|
|
313
|
-
background: #fff;
|
|
314
|
-
box-shadow: 0px 1px 2px 0px rgba(184, 200, 224, 0.22);
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
::v-deep(.q-field--filled .q-field__control:before) {
|
|
318
|
-
background: #fff !important;
|
|
319
|
-
border: none;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
::v-deep(.q-field--with-bottom) {
|
|
323
|
-
padding-bottom: 0;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
::v-deep(.q-field__bottom) {
|
|
327
|
-
padding: 0;
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
.clear-input {
|
|
331
|
-
color: #d8e0f0;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
.required {
|
|
335
|
-
color: #f65160;
|
|
336
|
-
font-weight: bold;
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
&__actions {
|
|
340
|
-
padding: 18px 0;
|
|
341
|
-
border-radius: 0px 0px 16px 16px;
|
|
342
|
-
background: #f4f9fd;
|
|
343
|
-
|
|
344
|
-
button {
|
|
345
|
-
padding: 13px 37px;
|
|
346
|
-
border-radius: 4px;
|
|
347
|
-
font-size: 16px;
|
|
348
|
-
font-weight: 700;
|
|
349
|
-
text-transform: none;
|
|
350
|
-
|
|
351
|
-
&.remove {
|
|
352
|
-
border: 1px solid #f65160;
|
|
353
|
-
color: #f65160;
|
|
354
|
-
}
|
|
355
|
-
&.confirm {
|
|
356
|
-
background: #3f8cff;
|
|
357
|
-
color: #fff;
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
&.cancel {
|
|
361
|
-
color: #3f8cff;
|
|
362
|
-
border: 1px solid #3f8cff;
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
</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 v-if="mode === 'view'" class="remove" flat label="Удалить" :loading="loading" @click="emit('delete')" />
|
|
83
|
+
<q-btn
|
|
84
|
+
v-if="mode !== 'view'"
|
|
85
|
+
class="confirm"
|
|
86
|
+
data-test="save-create-button"
|
|
87
|
+
flat
|
|
88
|
+
:label="mode === 'edit' ? 'Сохранить' : 'Создать'"
|
|
89
|
+
:disable="isSubmitDisabled"
|
|
90
|
+
:loading="loading"
|
|
91
|
+
@click="submit"
|
|
92
|
+
/>
|
|
93
|
+
<q-btn
|
|
94
|
+
v-else
|
|
95
|
+
class="confirm"
|
|
96
|
+
data-test="edit-button"
|
|
97
|
+
flat
|
|
98
|
+
label="Редактировать"
|
|
99
|
+
:disable="loading"
|
|
100
|
+
@click="$emit('edit')"
|
|
101
|
+
/>
|
|
102
|
+
<q-btn class="cancel" data-test="close-button" flat label="Закрыть" :disable="loading" @click="close" />
|
|
103
|
+
</q-card-actions>
|
|
104
|
+
</q-card>
|
|
105
|
+
</q-dialog>
|
|
106
|
+
</template>
|
|
107
|
+
|
|
108
|
+
<script setup lang="ts">
|
|
109
|
+
import { ref, watch, defineProps, defineEmits, nextTick, computed } from 'vue'
|
|
110
|
+
import { useQuasar } from 'quasar'
|
|
111
|
+
import AppModalSelect from '../components/ModalSelect.vue'
|
|
112
|
+
import { notificationSettings } from '@/utils/notification'
|
|
113
|
+
import { isEqual, normalizeValue, uuidv4 } from '@/utils/helpers'
|
|
114
|
+
|
|
115
|
+
type ModalMode = 'view' | 'edit' | 'create'
|
|
116
|
+
type FieldType = 'text' | 'select'
|
|
117
|
+
|
|
118
|
+
interface FieldOption {
|
|
119
|
+
label: string
|
|
120
|
+
value: string
|
|
121
|
+
}
|
|
122
|
+
interface FieldSchema {
|
|
123
|
+
key: string
|
|
124
|
+
label: string
|
|
125
|
+
type: FieldType
|
|
126
|
+
rules?: ((val: any) => boolean | string)[]
|
|
127
|
+
options?: FieldOption[]
|
|
128
|
+
placeholder?: string
|
|
129
|
+
onSearch?: (val: string) => void
|
|
130
|
+
onScroll?: () => void
|
|
131
|
+
loading?: boolean
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const props = defineProps<{
|
|
135
|
+
modelValue: boolean
|
|
136
|
+
title: string
|
|
137
|
+
mode: ModalMode
|
|
138
|
+
fields: FieldSchema[]
|
|
139
|
+
initialData?: Record<string, any>
|
|
140
|
+
loading?: boolean
|
|
141
|
+
}>()
|
|
142
|
+
const emit = defineEmits<{
|
|
143
|
+
(e: 'update:modelValue', val: boolean, hasChanges?: boolean): void
|
|
144
|
+
(e: 'submit', data: Record<string, any>): void
|
|
145
|
+
(e: 'edit'): void
|
|
146
|
+
(e: 'delete'): void
|
|
147
|
+
}>()
|
|
148
|
+
|
|
149
|
+
const $q = useQuasar()
|
|
150
|
+
const formRef = ref()
|
|
151
|
+
const formData = ref<Record<string, any>>({})
|
|
152
|
+
const filteredOptions = ref<Record<string, FieldOption[]>>({})
|
|
153
|
+
const isSubmitDisabled = computed(() => {
|
|
154
|
+
if (props.mode === 'view') return false
|
|
155
|
+
|
|
156
|
+
const hasEmptyRequired = props.fields.some(field => {
|
|
157
|
+
const isRequired = field.rules?.some(rule => rule('') !== true)
|
|
158
|
+
const val = formData.value[field.key]
|
|
159
|
+
const normalized = normalizeValue(val)
|
|
160
|
+
|
|
161
|
+
const empty =
|
|
162
|
+
normalized === null ||
|
|
163
|
+
normalized === undefined ||
|
|
164
|
+
(typeof normalized === 'string' && normalized.trim() === '') ||
|
|
165
|
+
(Array.isArray(normalized) && normalized.length === 0)
|
|
166
|
+
|
|
167
|
+
return isRequired && empty
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
if (hasEmptyRequired) return true
|
|
171
|
+
|
|
172
|
+
const hasChanges = props.fields.some(field => {
|
|
173
|
+
const key = field.key
|
|
174
|
+
const current = normalizeValue(formData.value[key])
|
|
175
|
+
const initial = normalizeValue(props.initialData?.[key])
|
|
176
|
+
return !isEqual(current, initial)
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
return !hasChanges
|
|
180
|
+
})
|
|
181
|
+
function toggleModal(val: boolean) {
|
|
182
|
+
if (val) {
|
|
183
|
+
emit('update:modelValue', val)
|
|
184
|
+
} else {
|
|
185
|
+
close()
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
function checkChanges() {
|
|
189
|
+
if (props.mode === 'view') {
|
|
190
|
+
return false
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (!props.initialData || !Object.keys(props.initialData).length) {
|
|
194
|
+
return props.fields?.some(
|
|
195
|
+
field =>
|
|
196
|
+
formData.value?.[field.key] &&
|
|
197
|
+
!(Array.isArray(formData.value?.[field.key]) && !formData.value?.[field.key].length),
|
|
198
|
+
)
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return props.fields?.some(field => !isEqual(formData.value?.[field.key], props.initialData?.[field.key]))
|
|
202
|
+
}
|
|
203
|
+
function close() {
|
|
204
|
+
emit('update:modelValue', false, checkChanges())
|
|
205
|
+
}
|
|
206
|
+
function submit() {
|
|
207
|
+
formRef.value?.validate().then(ok => {
|
|
208
|
+
if (!ok) return
|
|
209
|
+
|
|
210
|
+
const changed: Record<string, any> = {}
|
|
211
|
+
|
|
212
|
+
for (const field of props.fields) {
|
|
213
|
+
const key = field.key
|
|
214
|
+
const current = formData.value[key]
|
|
215
|
+
const initial = props.initialData?.[key]
|
|
216
|
+
|
|
217
|
+
const normalizedCurrent = field.type === 'select' ? normalizeValue(current) : current
|
|
218
|
+
const normalizedInitial = field.type === 'select' ? normalizeValue(initial) : initial
|
|
219
|
+
|
|
220
|
+
if (!isEqual(normalizedCurrent, normalizedInitial)) {
|
|
221
|
+
changed[key] = normalizedCurrent
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
emit('submit', changed)
|
|
226
|
+
})
|
|
227
|
+
}
|
|
228
|
+
function handleClear(key: string) {
|
|
229
|
+
const field = props.fields.find(f => f.key === key)
|
|
230
|
+
formData.value[key] = field?.type === 'select' ? [] : ''
|
|
231
|
+
|
|
232
|
+
nextTick(() => {
|
|
233
|
+
formRef.value?.validate()
|
|
234
|
+
})
|
|
235
|
+
}
|
|
236
|
+
function generateUuid() {
|
|
237
|
+
formData.value.uuid = uuidv4()
|
|
238
|
+
}
|
|
239
|
+
function copyToClipboard(text: string) {
|
|
240
|
+
navigator.clipboard.writeText(text).then(() => {
|
|
241
|
+
$q.notify(notificationSettings('success', 'UUID скопирован'))
|
|
242
|
+
})
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
watch(
|
|
246
|
+
() => props.modelValue,
|
|
247
|
+
val => {
|
|
248
|
+
if (val) {
|
|
249
|
+
formData.value = { ...(props.initialData ?? {}) }
|
|
250
|
+
}
|
|
251
|
+
},
|
|
252
|
+
{ immediate: true },
|
|
253
|
+
)
|
|
254
|
+
</script>
|
|
255
|
+
|
|
256
|
+
<style lang="scss">
|
|
257
|
+
.custom-select-menu {
|
|
258
|
+
max-height: 250px !important;
|
|
259
|
+
overflow-y: auto !important;
|
|
260
|
+
}
|
|
261
|
+
</style>
|
|
262
|
+
<style scoped lang="scss">
|
|
263
|
+
.uuid-btn {
|
|
264
|
+
height: 32px;
|
|
265
|
+
padding: 0 10px;
|
|
266
|
+
border: 1px solid #3f8cff;
|
|
267
|
+
color: #3f8cff;
|
|
268
|
+
font-weight: 700;
|
|
269
|
+
font-size: 14px;
|
|
270
|
+
background: white;
|
|
271
|
+
border-radius: 6px;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
.q-card {
|
|
275
|
+
border-radius: 12px;
|
|
276
|
+
background: #fff;
|
|
277
|
+
box-shadow: 0 4px 4px 0 rgba(0, 0, 0, 0.25);
|
|
278
|
+
font-family: NunitoSansFont, sans-serif;
|
|
279
|
+
|
|
280
|
+
.modal-title {
|
|
281
|
+
color: #1d425d;
|
|
282
|
+
text-align: center;
|
|
283
|
+
font-size: 32px;
|
|
284
|
+
font-weight: 700;
|
|
285
|
+
padding: 18px 29px;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
.q-card__section {
|
|
289
|
+
padding: 0;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
.q-form {
|
|
293
|
+
padding: 0 29px;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
.field-wrapper {
|
|
297
|
+
display: flex;
|
|
298
|
+
flex-direction: column;
|
|
299
|
+
margin-bottom: 15px;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
.field-label {
|
|
303
|
+
font-size: 14px;
|
|
304
|
+
font-weight: 700;
|
|
305
|
+
color: #7d8592;
|
|
306
|
+
}
|
|
307
|
+
::v-deep(.q-placeholder) {
|
|
308
|
+
color: #7d8592;
|
|
309
|
+
}
|
|
310
|
+
::v-deep(.q-field__control) {
|
|
311
|
+
border-radius: 8px;
|
|
312
|
+
border: 1px solid #d8e0f0;
|
|
313
|
+
background: #fff;
|
|
314
|
+
box-shadow: 0px 1px 2px 0px rgba(184, 200, 224, 0.22);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
::v-deep(.q-field--filled .q-field__control:before) {
|
|
318
|
+
background: #fff !important;
|
|
319
|
+
border: none;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
::v-deep(.q-field--with-bottom) {
|
|
323
|
+
padding-bottom: 0;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
::v-deep(.q-field__bottom) {
|
|
327
|
+
padding: 0;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
.clear-input {
|
|
331
|
+
color: #d8e0f0;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
.required {
|
|
335
|
+
color: #f65160;
|
|
336
|
+
font-weight: bold;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
&__actions {
|
|
340
|
+
padding: 18px 0;
|
|
341
|
+
border-radius: 0px 0px 16px 16px;
|
|
342
|
+
background: #f4f9fd;
|
|
343
|
+
|
|
344
|
+
button {
|
|
345
|
+
padding: 13px 37px;
|
|
346
|
+
border-radius: 4px;
|
|
347
|
+
font-size: 16px;
|
|
348
|
+
font-weight: 700;
|
|
349
|
+
text-transform: none;
|
|
350
|
+
|
|
351
|
+
&.remove {
|
|
352
|
+
border: 1px solid #f65160;
|
|
353
|
+
color: #f65160;
|
|
354
|
+
}
|
|
355
|
+
&.confirm {
|
|
356
|
+
background: #3f8cff;
|
|
357
|
+
color: #fff;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
&.cancel {
|
|
361
|
+
color: #3f8cff;
|
|
362
|
+
border: 1px solid #3f8cff;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
</style>
|