@duxweb/dvha-core 0.0.5 → 0.0.7

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.
Files changed (120) hide show
  1. package/dist/cjs/components/common/logo.cjs +1 -0
  2. package/dist/cjs/components/overlay/overlay.cjs +1 -0
  3. package/dist/cjs/hooks/auth.cjs +1 -0
  4. package/dist/cjs/hooks/config.cjs +1 -0
  5. package/dist/cjs/hooks/data.cjs +1 -0
  6. package/dist/cjs/hooks/manage.cjs +1 -0
  7. package/dist/cjs/hooks/menu.cjs +1 -0
  8. package/dist/cjs/hooks/overlay.cjs +1 -0
  9. package/dist/cjs/hooks/theme.cjs +1 -0
  10. package/dist/cjs/index.cjs +1 -0
  11. package/dist/cjs/main.cjs +1 -0
  12. package/dist/cjs/provider/app.cjs +1 -0
  13. package/dist/cjs/provider/tab.cjs +1 -0
  14. package/dist/cjs/router/route.cjs +1 -0
  15. package/dist/cjs/simple/authProvider.cjs +1 -0
  16. package/dist/cjs/simple/dataProvider.cjs +1 -0
  17. package/dist/cjs/stores/auth.cjs +1 -0
  18. package/dist/cjs/stores/route.cjs +1 -0
  19. package/dist/cjs/stores/tab.cjs +1 -0
  20. package/dist/cjs/utils/tree.cjs +1 -0
  21. package/dist/esm/components/common/logo.js +50 -0
  22. package/dist/esm/components/overlay/overlay.js +72 -0
  23. package/dist/esm/hooks/auth.js +125 -0
  24. package/dist/esm/hooks/config.js +10 -0
  25. package/dist/esm/hooks/data.js +369 -0
  26. package/dist/esm/hooks/manage.js +24 -0
  27. package/dist/esm/hooks/menu.js +75 -0
  28. package/dist/esm/hooks/overlay.js +14 -0
  29. package/dist/esm/hooks/theme.js +31 -0
  30. package/dist/esm/index.js +67 -0
  31. package/dist/esm/main.js +22 -0
  32. package/dist/esm/provider/app.js +127 -0
  33. package/dist/esm/provider/tab.js +64 -0
  34. package/dist/esm/router/route.js +49 -0
  35. package/dist/esm/simple/authProvider.js +90 -0
  36. package/dist/esm/simple/dataProvider.js +99 -0
  37. package/dist/esm/stores/auth.js +50 -0
  38. package/dist/esm/stores/route.js +65 -0
  39. package/dist/esm/stores/tab.js +70 -0
  40. package/dist/esm/utils/tree.js +41 -0
  41. package/dist/types/components/common/index.d.ts +1 -0
  42. package/dist/types/components/common/logo.d.ts +22 -0
  43. package/dist/types/components/index.d.ts +3 -0
  44. package/dist/types/components/loader/iframe.d.ts +2 -0
  45. package/dist/types/components/loader/index.d.ts +1 -0
  46. package/dist/types/components/overlay/index.d.ts +1 -0
  47. package/dist/types/components/overlay/overlay.d.ts +44 -0
  48. package/dist/types/hooks/auth.d.ts +109 -0
  49. package/dist/types/hooks/config.d.ts +7 -0
  50. package/dist/types/hooks/data.d.ts +1487 -0
  51. package/dist/types/hooks/index.d.ts +7 -0
  52. package/dist/types/hooks/manage.d.ts +13 -0
  53. package/dist/types/hooks/menu.d.ts +16 -0
  54. package/dist/types/hooks/overlay.d.ts +7 -0
  55. package/dist/types/hooks/theme.d.ts +12 -0
  56. package/dist/types/index.d.ts +9 -0
  57. package/dist/types/main.d.ts +5 -0
  58. package/dist/types/provider/app.d.ts +1 -0
  59. package/dist/types/provider/index.d.ts +2 -0
  60. package/dist/types/provider/tab.d.ts +1 -0
  61. package/dist/types/router/index.d.ts +1 -0
  62. package/dist/types/router/route.d.ts +2 -0
  63. package/dist/types/simple/authProvider.d.ts +2 -0
  64. package/dist/types/simple/dataProvider.d.ts +2 -0
  65. package/dist/types/simple/index.d.ts +2 -0
  66. package/dist/types/stores/auth.d.ts +31 -0
  67. package/dist/types/stores/index.d.ts +3 -0
  68. package/dist/types/stores/route.d.ts +4040 -0
  69. package/dist/types/stores/tab.d.ts +1660 -0
  70. package/dist/types/types/auth.d.ts +36 -0
  71. package/dist/types/types/config.d.ts +32 -0
  72. package/dist/types/types/data.d.ts +84 -0
  73. package/dist/types/types/index.d.ts +6 -0
  74. package/dist/types/types/manage.d.ts +29 -0
  75. package/dist/types/types/menu.d.ts +13 -0
  76. package/dist/types/types/theme.d.ts +10 -0
  77. package/dist/types/utils/index.d.ts +1 -0
  78. package/dist/types/utils/tree.d.ts +13 -0
  79. package/package.json +38 -12
  80. package/CHANGELOG.md +0 -25
  81. package/src/components/common/index.ts +0 -1
  82. package/src/components/common/logo.tsx +0 -62
  83. package/src/components/index.ts +0 -3
  84. package/src/components/loader/iframe.tsx +0 -12
  85. package/src/components/loader/index.ts +0 -1
  86. package/src/components/overlay/index.ts +0 -1
  87. package/src/components/overlay/overlay.tsx +0 -84
  88. package/src/hooks/auth.ts +0 -261
  89. package/src/hooks/config.ts +0 -16
  90. package/src/hooks/data.ts +0 -648
  91. package/src/hooks/index.ts +0 -7
  92. package/src/hooks/manage.ts +0 -71
  93. package/src/hooks/menu.ts +0 -146
  94. package/src/hooks/overlay.ts +0 -21
  95. package/src/hooks/theme.ts +0 -49
  96. package/src/index.ts +0 -9
  97. package/src/main.ts +0 -28
  98. package/src/provider/app.tsx +0 -200
  99. package/src/provider/index.ts +0 -2
  100. package/src/provider/tab.tsx +0 -76
  101. package/src/router/index.ts +0 -1
  102. package/src/router/route.ts +0 -47
  103. package/src/simple/authProvider.ts +0 -99
  104. package/src/simple/dataProvider.ts +0 -153
  105. package/src/simple/index.ts +0 -2
  106. package/src/stores/auth.ts +0 -73
  107. package/src/stores/index.ts +0 -3
  108. package/src/stores/route.ts +0 -159
  109. package/src/stores/tab.ts +0 -120
  110. package/src/types/auth.ts +0 -44
  111. package/src/types/config.ts +0 -51
  112. package/src/types/data.ts +0 -108
  113. package/src/types/index.ts +0 -6
  114. package/src/types/manage.ts +0 -40
  115. package/src/types/menu.ts +0 -24
  116. package/src/types/theme.ts +0 -12
  117. package/src/utils/index.ts +0 -1
  118. package/src/utils/tree.ts +0 -63
  119. package/tsconfig.json +0 -41
  120. package/typings.d.ts +0 -10
package/src/hooks/data.ts DELETED
@@ -1,648 +0,0 @@
1
- import type { DefaultError, DefinedInitialDataInfiniteOptions, InfiniteData, QueryKey, UndefinedInitialDataOptions, UseMutationOptions } from '@tanstack/react-query'
2
- import type { IDataProviderCreateManyOptions, IDataProviderCreateOptions, IDataProviderCustomOptions, IDataProviderDeleteManyOptions, IDataProviderDeleteOptions, IDataProviderGetManyOptions, IDataProviderGetOneOptions, IDataProviderListOptions, IDataProviderResponse, IDataProviderUpdateManyOptions, IDataProviderUpdateOptions } from '../types'
3
- import { useInfiniteQuery, useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
4
- import { computed, watch } from 'vue'
5
- import { useError, useGetAuth } from './auth'
6
- import { useManage } from './manage'
7
- import { useAuthStore } from 'src/stores'
8
-
9
- type IDataQueryOptions = UndefinedInitialDataOptions<IDataProviderResponse | undefined, DefaultError, IDataProviderResponse | undefined, QueryKey>
10
- type IDataQueryOptionsInfinite = DefinedInitialDataInfiniteOptions<IDataProviderResponse | undefined, DefaultError, InfiniteData<IDataProviderResponse | undefined>, QueryKey, number>
11
-
12
- interface IListParams extends IDataProviderListOptions {
13
- options?: IDataQueryOptions
14
- onError?: (error: any) => void
15
- }
16
-
17
- /**
18
- * Get list data
19
- * @param params
20
- */
21
- export function useList(params: IListParams) {
22
- const manage = useManage()
23
- const auth = useGetAuth()
24
-
25
- const { mutate: onAuthError } = useError()
26
-
27
- const props = computed((): IDataProviderListOptions => {
28
- const { onError, options, ...rest } = params
29
- return rest
30
- })
31
-
32
- const req = useQuery({
33
- queryKey: [params.path, props],
34
- queryFn: () => manage.config.dataProvider?.getList({ ...props.value }, manage, auth),
35
- ...params.options,
36
- })
37
-
38
- const isLoading = computed(() => {
39
- if (req.isFetched) {
40
- return false
41
- }
42
- return req.isFetching
43
- })
44
-
45
- watch(() => req.isError, () => {
46
- onAuthError(req.error)
47
- params.onError?.(req.error)
48
- })
49
-
50
- return {
51
- ...req,
52
- isLoading,
53
- data: req.data,
54
- refetch: req.refetch,
55
- }
56
- }
57
-
58
- interface IInfiniteListParams extends IDataProviderListOptions {
59
- options?: IDataQueryOptionsInfinite
60
- onError?: (error: any) => void
61
- }
62
-
63
- /**
64
- * Get infinite list data
65
- * @param params
66
- */
67
- export function useInfiniteList(params: IInfiniteListParams) {
68
- const manage = useManage()
69
- const auth = useGetAuth()
70
- const { mutate: onAuthError } = useError()
71
-
72
- const props = computed((): IDataProviderListOptions => {
73
- const { onError, options, ...rest } = params
74
- return rest
75
- })
76
-
77
- const req = useInfiniteQuery({
78
- queryKey: [params.path, props],
79
- queryFn: () => manage.config.dataProvider?.getList({ ...props.value }, manage, auth),
80
- initialPageParam: 0,
81
- getNextPageParam: (lastPage, _allPages, lastPageParam) => {
82
- if (!lastPage?.data || lastPage?.data?.length === 0) {
83
- return undefined
84
- }
85
- return lastPageParam + 1
86
- },
87
- getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => {
88
- if (firstPageParam <= 1) {
89
- return undefined
90
- }
91
- return firstPageParam - 1
92
- },
93
- ...params.options,
94
- })
95
-
96
- const isLoading = computed(() => {
97
- if (req.isFetched) {
98
- return false
99
- }
100
- return req.isFetching
101
- })
102
-
103
- watch(() => req.isError, () => {
104
- onAuthError(req.error)
105
- params.onError?.(req.error)
106
- })
107
-
108
- return {
109
- ...req,
110
- isLoading,
111
- data: req.data,
112
- fetchNextPage: req.fetchNextPage,
113
- hasNextPage: req.hasNextPage,
114
- refetch: req.refetch,
115
- }
116
- }
117
-
118
- interface IOneParams extends IDataProviderGetOneOptions {
119
- options?: IDataQueryOptions
120
- onError?: (error: any) => void
121
- }
122
-
123
- /**
124
- * Get one data
125
- * @param params
126
- */
127
- export function useOne(params: IOneParams) {
128
- const manage = useManage()
129
- const auth = useGetAuth()
130
- const { mutate: onAuthError } = useError()
131
-
132
- const props = computed((): IDataProviderGetOneOptions => {
133
- const { onError, options, ...rest } = params
134
- return rest
135
- })
136
-
137
- const req = useQuery({
138
- queryKey: [params.path, props],
139
- queryFn: () => manage.config.dataProvider?.getOne({ ...props.value }, manage, auth),
140
- ...params.options,
141
- })
142
-
143
- const isLoading = computed(() => {
144
- if (req.isFetched) {
145
- return false
146
- }
147
- return req.isFetching
148
- })
149
-
150
- watch(() => req.isError, () => {
151
- onAuthError(req.error)
152
- params.onError?.(req.error)
153
- })
154
-
155
- return {
156
- ...req,
157
- isLoading,
158
- data: req.data,
159
- refetch: req.refetch,
160
- }
161
- }
162
-
163
- interface IManyParams extends IDataProviderGetManyOptions {
164
- options?: IDataQueryOptions
165
- onError?: (error: any) => void
166
- }
167
- /**
168
- * Get many data
169
- * @param params
170
- */
171
- export function useMany(params: IManyParams) {
172
- const manage = useManage()
173
- const auth = useGetAuth()
174
- const { mutate: onAuthError } = useError()
175
-
176
- const props = computed((): IDataProviderGetManyOptions => {
177
- const { onError, options, ...rest } = params
178
- return rest
179
- })
180
-
181
- const req = useQuery({
182
- queryKey: [params.path, props],
183
- queryFn: () => manage.config.dataProvider?.getMany({ ...props.value }, manage, auth),
184
- ...params.options,
185
- })
186
-
187
- const isLoading = computed(() => {
188
- if (req.isFetched) {
189
- return false
190
- }
191
- return req.isFetching
192
- })
193
-
194
- watch(() => req.isError, () => {
195
- onAuthError(req.error)
196
- params.onError?.(req.error)
197
- })
198
-
199
- return {
200
- ...req,
201
- isLoading,
202
- data: req.data,
203
- refetch: req.refetch,
204
- }
205
- }
206
-
207
- interface ICreateParams extends IDataProviderCreateOptions {
208
- options?: UseMutationOptions<IDataProviderResponse, DefaultError, IDataProviderCreateOptions>
209
- onSuccess?: (data: any) => void
210
- onError?: (error: any) => void
211
- }
212
-
213
- /**
214
- * Create data
215
- * @param params
216
- */
217
- export function useCreate(params: ICreateParams) {
218
- const manage = useManage()
219
- const auth = useGetAuth()
220
- const { mutate: onAuthError } = useError()
221
- const { invalidate } = useInvalidate()
222
-
223
- const props = computed((): IDataProviderCreateOptions => {
224
- const { onError, options, ...rest } = params
225
- return rest
226
- })
227
-
228
- const req = useMutation({
229
- mutationFn: (data) => {
230
- if (!manage.config.dataProvider) {
231
- throw new Error('Data provider is not initialized')
232
- }
233
- return manage.config.dataProvider.create({
234
- ...props.value,
235
- ...data,
236
- }, manage, auth)
237
- },
238
- onSuccess: (data) => {
239
- params.onSuccess?.(data)
240
- if (params.path) {
241
- invalidate(params.path)
242
- }
243
- },
244
- onError: (error) => {
245
- onAuthError(error)
246
- params.onError?.(error)
247
- },
248
- ...params.options,
249
- })
250
-
251
- const isLoading = computed(() => req.isPending)
252
-
253
- return {
254
- ...req,
255
- isLoading,
256
- mutate: req.mutate,
257
- }
258
- }
259
-
260
- interface ICreateManyParams extends IDataProviderCreateManyOptions {
261
- options?: UseMutationOptions<IDataProviderResponse, DefaultError, IDataProviderCreateManyOptions>
262
- onSuccess?: (data: any) => void
263
- onError?: (error: any) => void
264
- }
265
-
266
- /**
267
- * Create data
268
- * @param params
269
- */
270
- export function useCreateMany(params: ICreateManyParams) {
271
- const manage = useManage()
272
- const auth = useGetAuth()
273
- const { mutate: onAuthError } = useError()
274
- const { invalidate } = useInvalidate()
275
- const props = computed((): IDataProviderCreateManyOptions => {
276
- const { onError, options, ...rest } = params
277
- return rest
278
- })
279
-
280
- const req = useMutation({
281
- mutationFn: (data) => {
282
- if (!manage.config.dataProvider) {
283
- throw new Error('Data provider is not initialized')
284
- }
285
- return manage.config.dataProvider.createMany({
286
- ...props.value,
287
- ...data,
288
- }, manage, auth)
289
- },
290
- onSuccess: (data) => {
291
- params.onSuccess?.(data)
292
- if (params.path) {
293
- invalidate(params.path)
294
- }
295
- },
296
- onError: (error) => {
297
- onAuthError(error)
298
- params.onError?.(error)
299
- },
300
- ...params.options,
301
- })
302
-
303
- const isLoading = computed(() => req.isPending)
304
-
305
- return {
306
- ...req,
307
- isLoading,
308
- mutate: req.mutate,
309
- }
310
- }
311
-
312
- interface IUpdateParams extends IDataProviderUpdateOptions {
313
- options?: UseMutationOptions<IDataProviderResponse, DefaultError, IDataProviderUpdateOptions>
314
- onSuccess?: (data: any) => void
315
- onError?: (error: any) => void
316
- }
317
-
318
- /**
319
- * Update data
320
- * @param params
321
- */
322
- export function useUpdate(params: IUpdateParams) {
323
- const manage = useManage()
324
- const auth = useGetAuth()
325
- const { mutate: onAuthError } = useError()
326
- const { invalidate } = useInvalidate()
327
- const props = computed((): IDataProviderUpdateOptions => {
328
- const { onError, options, ...rest } = params
329
- return rest
330
- })
331
-
332
- const req = useMutation({
333
- mutationFn: (data) => {
334
- if (!manage.config.dataProvider) {
335
- throw new Error('Data provider is not initialized')
336
- }
337
- return manage.config.dataProvider.update({
338
- ...props.value,
339
- ...data,
340
- }, manage, auth)
341
- },
342
- onSuccess: (data) => {
343
- params.onSuccess?.(data)
344
- if (params.path) {
345
- invalidate(params.path)
346
- }
347
- },
348
- onError: (error) => {
349
- onAuthError(error)
350
- params.onError?.(error)
351
- },
352
- ...params.options,
353
- })
354
-
355
- const isLoading = computed(() => req.isPending)
356
-
357
- return {
358
- ...req,
359
- isLoading,
360
- mutate: req.mutate,
361
- }
362
- }
363
-
364
- interface IUpdateManyParams extends IDataProviderUpdateManyOptions {
365
- options?: UseMutationOptions<IDataProviderResponse, DefaultError, IDataProviderUpdateManyOptions>
366
- onSuccess?: (data: any) => void
367
- onError?: (error: any) => void
368
- }
369
-
370
- export function useUpdateMany(params: IUpdateManyParams) {
371
- const manage = useManage()
372
- const auth = useGetAuth()
373
- const { mutate: onAuthError } = useError()
374
- const { invalidate } = useInvalidate()
375
-
376
- const props = computed((): IDataProviderUpdateManyOptions => {
377
- const { onError, options, ...rest } = params
378
- return rest
379
- })
380
-
381
- const req = useMutation({
382
- mutationFn: (data) => {
383
- if (!manage.config.dataProvider) {
384
- throw new Error('Data provider is not initialized')
385
- }
386
- return manage.config.dataProvider.updateMany({
387
- ...props.value,
388
- ...data,
389
- }, manage, auth)
390
- },
391
- onSuccess: (data) => {
392
- params.onSuccess?.(data)
393
- if (params.path) {
394
- invalidate(params.path)
395
- }
396
- },
397
- onError: (error) => {
398
- onAuthError(error)
399
- params.onError?.(error)
400
- },
401
- ...params.options,
402
- })
403
-
404
- const isLoading = computed(() => req.isPending)
405
-
406
- return {
407
- ...req,
408
- isLoading,
409
- mutate: req.mutate,
410
- }
411
- }
412
-
413
- interface IDeleteParams extends IDataProviderDeleteOptions {
414
- options?: UseMutationOptions<IDataProviderResponse, DefaultError, IDataProviderDeleteOptions>
415
- onSuccess?: (data: any) => void
416
- onError?: (error: any) => void
417
- }
418
-
419
- /**
420
- * Update data
421
- * @param params
422
- */
423
- export function useDelete(params: IDeleteParams) {
424
- const manage = useManage()
425
- const auth = useGetAuth()
426
- const { mutate: onAuthError } = useError()
427
- const { invalidate } = useInvalidate()
428
- const props = computed((): IDataProviderDeleteOptions => {
429
- const { onError, options, ...rest } = params
430
- return rest
431
- })
432
-
433
- const req = useMutation({
434
- mutationFn: (data) => {
435
- if (!manage.config.dataProvider) {
436
- throw new Error('Data provider is not initialized')
437
- }
438
- return manage.config.dataProvider.deleteOne({
439
- ...props.value,
440
- ...data,
441
- }, manage, auth)
442
- },
443
- onSuccess: (data) => {
444
- params.onSuccess?.(data)
445
- if (params.path) {
446
- invalidate(params.path)
447
- }
448
- },
449
- onError: (error) => {
450
- onAuthError(error)
451
- params.onError?.(error)
452
- },
453
- ...params.options,
454
- })
455
-
456
- const isLoading = computed(() => req.isPending)
457
-
458
- return {
459
- ...req,
460
- isLoading,
461
- mutate: req.mutate,
462
- }
463
- }
464
-
465
- interface IDeleteManyParams extends IDataProviderDeleteManyOptions {
466
- options?: UseMutationOptions<IDataProviderResponse, DefaultError, IDataProviderDeleteManyOptions>
467
- onSuccess?: (data: any) => void
468
- onError?: (error: any) => void
469
- }
470
-
471
- /**
472
- * Update data
473
- * @param params
474
- */
475
- export function useDeleteMany(params: IDeleteManyParams) {
476
- const manage = useManage()
477
- const auth = useGetAuth()
478
- const { mutate: onAuthError } = useError()
479
- const { invalidate } = useInvalidate()
480
- const props = computed((): IDataProviderDeleteManyOptions => {
481
- const { onError, options, ...rest } = params
482
- return rest
483
- })
484
-
485
- const req = useMutation({
486
- mutationFn: (data) => {
487
- if (!manage.config.dataProvider) {
488
- throw new Error('Data provider is not initialized')
489
- }
490
- return manage.config.dataProvider.deleteMany({
491
- ...props.value,
492
- ...data,
493
- }, manage, auth)
494
- },
495
- onSuccess: (data) => {
496
- params.onSuccess?.(data)
497
- if (params.path) {
498
- invalidate(params.path)
499
- }
500
- },
501
- onError: (error) => {
502
- onAuthError(error)
503
- params.onError?.(error)
504
- },
505
- ...params.options,
506
- })
507
-
508
- const isLoading = computed(() => req.isPending)
509
-
510
- return {
511
- ...req,
512
- isLoading,
513
- mutate: req.mutate,
514
- }
515
- }
516
-
517
- interface ICustomParams extends IDataProviderCustomOptions {
518
- options?: IDataQueryOptions
519
- onError?: (error: any) => void
520
- }
521
-
522
- /**
523
- * Custom query request
524
- * @param params
525
- */
526
- export function useCustom(params: ICustomParams) {
527
- const manage = useManage()
528
- const auth = useGetAuth()
529
- const { mutate: onAuthError } = useError()
530
-
531
- const props = computed((): IDataProviderCustomOptions => {
532
- const { onError, options, ...rest } = params
533
- return rest
534
- })
535
-
536
- const req = useQuery({
537
- queryKey: [params.path, props],
538
- queryFn: () => manage.config.dataProvider?.custom({ ...props.value }, manage, auth),
539
- ...params.options,
540
- })
541
-
542
- const isLoading = computed(() => {
543
- if (req.isFetched) {
544
- return false
545
- }
546
- return req.isFetching
547
- })
548
-
549
- watch(() => req.isError, () => {
550
- onAuthError(req.error)
551
- params.onError?.(req.error)
552
- })
553
-
554
- return {
555
- ...req,
556
- isLoading,
557
- data: req.data,
558
- refetch: req.refetch,
559
- }
560
- }
561
-
562
- interface ICustomMutationParams extends IDataProviderCustomOptions {
563
- options?: UseMutationOptions<IDataProviderResponse, DefaultError, IDataProviderCustomOptions>
564
- onSuccess?: (data: any) => void
565
- onError?: (error: any) => void
566
- }
567
-
568
- /**
569
- * Custom mutation request
570
- * @param params
571
- */
572
- export function useCustomMutation(params: ICustomMutationParams) {
573
- const manage = useManage()
574
- const auth = useGetAuth()
575
- const { mutate: onAuthError } = useError()
576
-
577
- const props = computed((): IDataProviderCustomOptions => {
578
- const { onError, options, ...rest } = params
579
- return rest
580
- })
581
-
582
- const req = useMutation({
583
- mutationFn: (data) => {
584
- if (!manage.config.dataProvider) {
585
- throw new Error('Data provider is not initialized')
586
- }
587
- return manage.config.dataProvider.custom({
588
- ...props.value,
589
- ...data,
590
- }, manage, auth)
591
- },
592
- onSuccess: (data) => {
593
- params.onSuccess?.(data)
594
- },
595
- onError: (error) => {
596
- onAuthError(error)
597
- params.onError?.(error)
598
- },
599
- ...params.options,
600
- })
601
-
602
- const isLoading = computed(() => req.isPending)
603
-
604
- return {
605
- ...req,
606
- isLoading,
607
- mutate: req.mutate,
608
- }
609
- }
610
-
611
- /**
612
- * Custom request client
613
- */
614
- export function useClient() {
615
- const manage = useManage()
616
- const auth = useGetAuth()
617
- const request = (params: IDataProviderCustomOptions) => {
618
- if (!manage.config.dataProvider) {
619
- throw new Error('Data provider is not initialized')
620
- }
621
- return manage.config.dataProvider?.custom({
622
- ...params,
623
- }, manage, auth)
624
- }
625
-
626
- return {
627
- request,
628
- }
629
- }
630
-
631
- export function useInvalidate() {
632
- const queryClient = useQueryClient()
633
-
634
- const invalidate = (path: string) => {
635
- let marks: any = path
636
- if (!Array.isArray(path)) {
637
- marks = [path]
638
- }
639
-
640
- queryClient.invalidateQueries({
641
- queryKey: marks,
642
- })
643
- }
644
-
645
- return {
646
- invalidate,
647
- }
648
- }
@@ -1,7 +0,0 @@
1
- export * from './auth'
2
- export * from './config'
3
- export * from './data'
4
- export * from './manage'
5
- export * from './menu'
6
- export * from './theme'
7
- export * from "./overlay"
@@ -1,71 +0,0 @@
1
- import type { IManage } from '../types'
2
- import { cloneDeep, trim, trimStart } from 'lodash-es'
3
- import { useConfig } from './config'
4
- import { inject, Ref } from 'vue'
5
-
6
- export interface IManageHook {
7
- config: IManage
8
- getRoutePath: (path?: string) => string
9
- getApiUrl: (path?: string) => string
10
- }
11
-
12
- /**
13
- * Manage
14
- * get manage config
15
- * @param name Manage name
16
- * @returns Manage
17
- */
18
- export function useManage(name?: string): IManageHook {
19
- const config = useConfig()
20
- const manageRef = inject<Ref<string>>('dux.manage')
21
- if (!name) {
22
- name = manageRef?.value
23
- }
24
- if (!name) {
25
- throw new Error('manage name is not defined')
26
- }
27
-
28
- const manage = cloneDeep(config.manages?.find(manage => manage.name === name))
29
- if (!manage) {
30
- throw new Error(`manage ${name} is not defined`)
31
- }
32
-
33
- const title: string[] = []
34
- if (manage.title) {
35
- title.push(manage.title)
36
- }
37
- if (config.title) {
38
- title.push(config.title)
39
- }
40
- manage.title = title.join(' - ')
41
-
42
- manage.copyright = manage.copyright || config.copyright
43
- manage.description = manage.description || config.description
44
-
45
- manage.theme = { ...config?.theme, ...manage?.theme }
46
-
47
- manage.authProvider = manage?.authProvider || config.authProvider
48
- manage.dataProvider = manage?.dataProvider || config.dataProvider
49
-
50
- manage.layoutComponent = {
51
- ...config.layoutComponent,
52
- ...manage.layoutComponent,
53
- }
54
-
55
- manage.apiUrl = config?.apiUrl ? `${config.apiUrl}/${trim(manage.apiUrl, '/')}` : manage.apiUrl
56
- manage.apiUrl = trim(manage.apiUrl, '/')
57
-
58
- const getRoutePath = (path?: string) => {
59
- return `${manage.routePrefix}/${trimStart(path || '', '/')}`
60
- }
61
-
62
- const getApiUrl = (path?: string) => {
63
- return `${manage.apiUrl}/${trimStart(path || '', '/')}`
64
- }
65
-
66
- return {
67
- config: manage,
68
- getRoutePath,
69
- getApiUrl,
70
- }
71
- }