@duxweb/dvha-core 0.0.6 → 0.0.8

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