@duxweb/dvha-core 0.0.2

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 (44) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/LICENSE +165 -0
  3. package/README.md +0 -0
  4. package/package.json +27 -0
  5. package/src/components/common/index.ts +1 -0
  6. package/src/components/common/logo.tsx +62 -0
  7. package/src/components/index.ts +3 -0
  8. package/src/components/loader/iframe.tsx +12 -0
  9. package/src/components/loader/index.ts +1 -0
  10. package/src/components/overlay/index.ts +1 -0
  11. package/src/components/overlay/overlay.tsx +84 -0
  12. package/src/hooks/auth.ts +261 -0
  13. package/src/hooks/config.ts +16 -0
  14. package/src/hooks/data.ts +648 -0
  15. package/src/hooks/index.ts +7 -0
  16. package/src/hooks/manage.ts +71 -0
  17. package/src/hooks/menu.ts +146 -0
  18. package/src/hooks/overlay.ts +21 -0
  19. package/src/hooks/theme.ts +49 -0
  20. package/src/index.ts +9 -0
  21. package/src/main.ts +28 -0
  22. package/src/provider/app.tsx +179 -0
  23. package/src/provider/index.ts +2 -0
  24. package/src/provider/tab.tsx +76 -0
  25. package/src/router/index.ts +1 -0
  26. package/src/router/route.ts +47 -0
  27. package/src/simple/authProvider.ts +99 -0
  28. package/src/simple/dataProvider.ts +153 -0
  29. package/src/simple/index.ts +2 -0
  30. package/src/stores/auth.ts +73 -0
  31. package/src/stores/index.ts +3 -0
  32. package/src/stores/route.ts +159 -0
  33. package/src/stores/tab.ts +120 -0
  34. package/src/types/auth.ts +44 -0
  35. package/src/types/config.ts +49 -0
  36. package/src/types/data.ts +108 -0
  37. package/src/types/index.ts +6 -0
  38. package/src/types/manage.ts +40 -0
  39. package/src/types/menu.ts +24 -0
  40. package/src/types/theme.ts +12 -0
  41. package/src/utils/index.ts +1 -0
  42. package/src/utils/tree.ts +63 -0
  43. package/tsconfig.json +41 -0
  44. package/typings.d.ts +10 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # @duxweb/dvha-core
2
+
3
+ ## 0.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - init
package/LICENSE ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
package/README.md ADDED
File without changes
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@duxweb/dvha-core",
3
+ "type": "module",
4
+ "version": "0.0.2",
5
+ "author": "DuxWeb",
6
+ "license": "LGPL-3.0",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/duxweb/dux-vue.git"
10
+ },
11
+ "main": "src/index.ts",
12
+ "dependencies": {
13
+ "@overlastic/vue": "^0.8.1",
14
+ "@tanstack/react-query": "^5.76.1",
15
+ "@vueuse/core": "^13.2.0",
16
+ "@vueuse/integrations": "^13.2.0",
17
+ "axios": "^1.9.0",
18
+ "lodash-es": "^4.17.21",
19
+ "pinia": "^3.0.2",
20
+ "pinia-plugin-persistedstate": "^4.3.0",
21
+ "vue": "^3.5.14",
22
+ "vue-router": "4"
23
+ },
24
+ "devDependencies": {
25
+ "clsx": "^2.1.1"
26
+ }
27
+ }
@@ -0,0 +1 @@
1
+ export * from './logo'
@@ -0,0 +1,62 @@
1
+ import clsx from 'clsx'
2
+ import { defineComponent } from 'vue'
3
+
4
+ export const DuxLogo = defineComponent({
5
+ name: 'DuxLogo',
6
+ props: {
7
+ dark: { type: Boolean, default: false },
8
+ highlight: { type: String, default: 'fill-primary' },
9
+ },
10
+ setup(props) {
11
+ return () => (
12
+ <svg
13
+ class="w-auto h-full"
14
+ viewBox="0 0 400.893 121.787"
15
+ version="1.1"
16
+ xmlns="http://www.w3.org/2000/svg"
17
+ >
18
+ <g
19
+ transform="translate(-6545.000000, -3038.106602) translate(6345.000000, 2899.000000) translate(200.000000, 132.393398)"
20
+ fill-rule="nonzero"
21
+ stroke="none"
22
+ stroke-width="1"
23
+ fill="none"
24
+ >
25
+ <path
26
+ d="M0 62.607v50c0 8.284 6.716 15 15 15s15-6.716 15-15v-50c0-8.285-6.716-15-15-15s-15 6.715-15 15z"
27
+ class={clsx([
28
+ props.dark ? 'fill-white/90' : 'fill-black dark:fill-white/90',
29
+ ])}
30
+ />
31
+ <path
32
+ d="M60 7.607c33.137 0 60 26.863 60 60s-26.863 60-60 60h-5c-8.284 0-15-6.716-15-15 0-8.285 6.716-15 15-15h5c16.57 0 30-13.432 30-30 0-16.57-13.43-30-30-30H15c-8.284 0-15-6.716-15-15 0-8.285 6.716-15 15-15h45z"
33
+ class={clsx([
34
+ props.dark ? 'fill-white/90' : 'fill-black dark:fill-white/90',
35
+ ])}
36
+ />
37
+ <path
38
+ d="M201 7.607c33.137 0 60 26.863 60 60s-26.863 60-60 60h-46c-8.284 0-15-6.716-15-15 0-8.285 6.716-15 15-15h46c16.57 0 30-13.432 30-30 0-16.57-13.43-30-30-30h-45.5c-8.284 0-15-6.716-15-15 0-8.285 6.716-15 15-15H201z"
39
+ class={clsx([
40
+ props.dark ? 'fill-white/90' : 'fill-black dark:fill-white/90',
41
+ ])}
42
+ transform="translate(200.500000, 67.606602) rotate(90.000000) translate(-200.500000, -67.606602) "
43
+ />
44
+ <g transform="translate(279.106602, 6.713203)">
45
+ <path
46
+ d="M25.607 4.393 52.893 31.68c5.858 5.858 5.858 15.356 0 21.213-5.857 5.858-15.355 5.858-21.213 0L4.393 25.607c-5.857-5.858-5.857-15.356 0-21.214 5.858-5.857 15.356-5.857 21.214 0zm91.786 0c5.858 5.858 5.858 15.356 0 21.214L90.107 52.893c-5.858 5.858-15.356 5.858-21.214 0-5.857-5.857-5.857-15.355 0-21.213L96.18 4.393c5.858-5.857 15.356-5.857 21.213 0zm-64.5 64.5c5.858 5.858 5.858 15.356 0 21.214l-27.286 27.286c-5.858 5.858-15.356 5.858-21.214 0-5.857-5.857-5.857-15.355 0-21.213L31.68 68.893c5.858-5.857 15.356-5.857 21.213 0z"
47
+ class={clsx([
48
+ props.dark ? 'fill-white/90' : 'fill-black dark:fill-white/90',
49
+ ])}
50
+ />
51
+ <path
52
+ d="m90.107 68.893 27.286 27.287c5.858 5.858 5.858 15.356 0 21.213-5.857 5.858-15.355 5.858-21.213 0L68.893 90.107c-5.857-5.858-5.857-15.356 0-21.214 5.858-5.857 15.356-5.857 21.214 0z"
53
+ class={clsx([
54
+ props.highlight,
55
+ ])}
56
+ />
57
+ </g>
58
+ </g>
59
+ </svg>
60
+ )
61
+ },
62
+ })
@@ -0,0 +1,3 @@
1
+ export * from './common'
2
+ export * from './loader'
3
+ export * from './overlay'
@@ -0,0 +1,12 @@
1
+ import { defineComponent } from 'vue'
2
+ import { useRoute } from 'vue-router'
3
+
4
+ export default defineComponent({
5
+ name: 'DuxIframe',
6
+ setup(_props) {
7
+ const route = useRoute()
8
+ return () => (
9
+ <iframe src={route.meta?.src as string} class="h-full w-full"></iframe>
10
+ )
11
+ },
12
+ })
@@ -0,0 +1 @@
1
+ export * from './iframe'
@@ -0,0 +1 @@
1
+ export * from './overlay'
@@ -0,0 +1,84 @@
1
+ import { useExtendOverlay } from '@overlastic/vue'
2
+ import { defineAsyncComponent, defineComponent, Transition } from 'vue'
3
+
4
+ export const DuxOverlay = defineComponent({
5
+ name: 'DuxOverlay',
6
+ props: {
7
+ component: Function,
8
+ componentProps: Object,
9
+ mask: {
10
+ type: Boolean,
11
+ default: true,
12
+ },
13
+ maskClosable: {
14
+ type: Boolean,
15
+ default: true,
16
+ },
17
+ duration: {
18
+ type: Number,
19
+ default: 300,
20
+ },
21
+ zIndex: {
22
+ type: Number,
23
+ default: 1000,
24
+ },
25
+ },
26
+ setup(props) {
27
+ const { visible, resolve, reject } = useExtendOverlay({
28
+ duration: props.duration,
29
+ })
30
+
31
+ const params = props?.componentProps || {}
32
+ params.onConfirm = resolve
33
+ params.onClose = reject
34
+
35
+ const Modal = defineAsyncComponent(props.component as () => Promise<any>)
36
+
37
+ const handleMaskClick = () => {
38
+ if (props.maskClosable) {
39
+ reject()
40
+ }
41
+ }
42
+ return () => (
43
+ <div
44
+ class='fixed inset-0 flex items-center justify-center overflow-auto'
45
+ style={{
46
+ zIndex: props.zIndex,
47
+ }}
48
+ >
49
+ <Transition
50
+ enterActiveClass="transition-opacity"
51
+ enterFromClass="opacity-0"
52
+ enterToClass="opacity-100"
53
+ leaveActiveClass="transition-opacity"
54
+ leaveFromClass="opacity-100"
55
+ leaveToClass="opacity-0"
56
+ >
57
+ {visible.value && props.mask && (
58
+ <div
59
+ class="fixed inset-0 bg-black bg-opacity-30"
60
+ style={{
61
+ transitionDuration: `${props.duration}ms`,
62
+ }}
63
+ onClick={handleMaskClick}
64
+ aria-hidden="true"
65
+ ></div>
66
+ )}
67
+ </Transition>
68
+
69
+ <Transition
70
+ enterActiveClass="transition-all"
71
+ enterFromClass="opacity-0 scale-95"
72
+ enterToClass="opacity-100 scale-100"
73
+ leaveActiveClass="transition-all"
74
+ leaveFromClass="opacity-100 scale-100"
75
+ leaveToClass="opacity-0 scale-95"
76
+ >
77
+ {visible.value && (
78
+ <Modal {...params} />
79
+ )}
80
+ </Transition>
81
+ </div>
82
+ )
83
+ },
84
+ })
@@ -0,0 +1,261 @@
1
+ import type { IAuthActionResponse, IAuthCheckResponse, IAuthErrorResponse, IAuthLoginResponse, IAuthLogoutResponse } from '../types'
2
+ import { ref } from 'vue'
3
+ import { useRouter } from 'vue-router'
4
+ import { useAuthStore } from '../stores/auth'
5
+ import { useManage } from './manage'
6
+
7
+ /**
8
+ * Auth login params
9
+ */
10
+ export interface IAuthLoginParams {
11
+ onSuccess?: (data?: IAuthLoginResponse) => void
12
+ onError?: (error?: IAuthLoginResponse) => void
13
+ }
14
+
15
+ /**
16
+ * Auth logout params
17
+ */
18
+ export interface IAuthLogoutParams {
19
+ onSuccess?: (data?: IAuthLogoutResponse) => void
20
+ onError?: (error?: IAuthLogoutResponse) => void
21
+ }
22
+
23
+ /**
24
+ * Auth check params
25
+ */
26
+ export interface IAuthCheckParams {
27
+ onSuccess?: (data?: IAuthCheckResponse) => void
28
+ onError?: (error?: IAuthCheckResponse) => void
29
+ }
30
+
31
+ /**
32
+ * Auth action params
33
+ */
34
+ export interface IAuthActionParams {
35
+ onSuccess?: (data?: IAuthActionResponse) => void
36
+ onError?: (error?: IAuthActionResponse) => void
37
+ }
38
+
39
+ /**
40
+ * Login
41
+ * login to manage
42
+ * @param onSuccess Login success callback
43
+ * @param onError Login error callback
44
+ * @returns Login method
45
+ */
46
+ export function useLogin({ onSuccess, onError }: IAuthLoginParams) {
47
+ const manage = useManage()
48
+ const authStore = useAuthStore()
49
+ const router = useRouter()
50
+ const loading = ref(false)
51
+
52
+ const mutate = async (data: Record<string, any>) => {
53
+ loading.value = true
54
+ const result = await manage.config.authProvider?.login(data, manage)
55
+ loading.value = false
56
+ if (result?.success) {
57
+ if (!result?.data) {
58
+ throw new Error('Login response data is undefined')
59
+ }
60
+ onSuccess?.(result)
61
+ authStore.login(manage.config.name, result.data)
62
+ router.push(manage.getRoutePath(result.redirectTo || '/'))
63
+ return
64
+ }
65
+ onError?.(result)
66
+ }
67
+
68
+ return {
69
+ mutate,
70
+ isLoading: loading,
71
+ }
72
+ }
73
+
74
+ /**
75
+ * Logout
76
+ * logout from manage
77
+ * @param onSuccess Logout success callback
78
+ * @param onError Logout error callback
79
+ * @returns Logout method
80
+ */
81
+ export function useLogout({ onSuccess, onError }: IAuthLogoutParams) {
82
+ const { config: manage, getRoutePath } = useManage()
83
+ const authStore = useAuthStore()
84
+ const router = useRouter()
85
+
86
+ const mutate = async (params?: any) => {
87
+ const result = await manage.authProvider?.logout(params)
88
+ if (result?.success) {
89
+ onSuccess?.(result)
90
+ authStore.logout(manage.name)
91
+ router.push(getRoutePath(result.redirectTo || '/login'))
92
+ return
93
+ }
94
+ onError?.(result)
95
+ }
96
+
97
+ return {
98
+ mutate,
99
+ }
100
+ }
101
+
102
+ /**
103
+ * Check
104
+ * check auth
105
+ * @param onSuccess Check success callback
106
+ * @param onError Check error callback
107
+ * @returns Check method
108
+ */
109
+ export function useCheck({ onSuccess, onError }: IAuthCheckParams) {
110
+ const { config: manage, getRoutePath } = useManage()
111
+ const authStore = useAuthStore()
112
+ const router = useRouter()
113
+
114
+ const mutate = async (params?: any) => {
115
+ const result = await manage.authProvider?.check(params)
116
+ if (result?.success) {
117
+ onSuccess?.(result)
118
+ if (!result?.data) {
119
+ throw new Error('Check response data is undefined')
120
+ }
121
+ authStore.update(manage.name, result.data)
122
+ return
123
+ }
124
+ onError?.(result)
125
+ if (result?.logout) {
126
+ router.push(getRoutePath(result.redirectTo || '/login'))
127
+ }
128
+ }
129
+
130
+ return {
131
+ mutate,
132
+ }
133
+ }
134
+
135
+ /**
136
+ * Register
137
+ * register to manage
138
+ * @param onSuccess Register success callback
139
+ * @param onError Register error callback
140
+ * @returns Register method
141
+ */
142
+ export function useRegister({ onSuccess, onError }: IAuthLoginParams) {
143
+ const { config: manage, getRoutePath } = useManage()
144
+ const authStore = useAuthStore()
145
+ const router = useRouter()
146
+ const mutate = async (data: Record<string, any>) => {
147
+ const result = await manage.authProvider?.register(data)
148
+ if (result?.success) {
149
+ onSuccess?.(result)
150
+ if (!result?.data) {
151
+ throw new Error('Register response data is undefined')
152
+ }
153
+ authStore.login(manage.name, result.data)
154
+ router.push(getRoutePath(result.redirectTo || ''))
155
+ return
156
+ }
157
+ onError?.(result)
158
+ }
159
+ return {
160
+ mutate,
161
+ }
162
+ }
163
+
164
+ /**
165
+ * Forgot password
166
+ * @param onSuccess Forgot password success callback
167
+ * @param onError Forgot password error callback
168
+ * @returns Forgot password method
169
+ */
170
+ export function useForgotPassword({ onSuccess, onError }: IAuthActionParams) {
171
+ const { config: manage, getRoutePath } = useManage()
172
+ const router = useRouter()
173
+
174
+ const mutate = async (params?: any) => {
175
+ const result = await manage.authProvider?.forgotPassword(params)
176
+ if (result?.success) {
177
+ onSuccess?.(result)
178
+ if (result.redirectTo) {
179
+ router.push(getRoutePath(result.redirectTo))
180
+ }
181
+ return
182
+ }
183
+ onError?.(result)
184
+ }
185
+
186
+ return {
187
+ mutate,
188
+ }
189
+ }
190
+
191
+ /**
192
+ * Update password
193
+ * @param onSuccess Update password success callback
194
+ * @param onError Update password error callback
195
+ * @returns Update password method
196
+ */
197
+ export function useUpdatePassword({ onSuccess, onError }: IAuthActionParams) {
198
+ const { config: manage, getRoutePath } = useManage()
199
+ const router = useRouter()
200
+
201
+ const mutate = async (params?: any) => {
202
+ const result = await manage.authProvider?.updatePassword(params)
203
+ if (result?.success) {
204
+ onSuccess?.(result)
205
+ if (result.redirectTo) {
206
+ router.push(getRoutePath(result.redirectTo))
207
+ }
208
+ return
209
+ }
210
+ onError?.(result)
211
+ }
212
+
213
+ return {
214
+ mutate,
215
+ }
216
+ }
217
+
218
+ /**
219
+ * Error
220
+ * handle auth error
221
+ * @param onCallback Error callback
222
+ * @returns Error method
223
+ */
224
+ export function useError(onCallback?: (data?: IAuthErrorResponse) => void) {
225
+ const { config: manage, getRoutePath } = useManage()
226
+ const router = useRouter()
227
+
228
+ const mutate = async (error: any) => {
229
+ const result = await manage.authProvider?.onError(error)
230
+ onCallback?.(result)
231
+ if (result?.logout) {
232
+ router.push(getRoutePath(result.redirectTo || '/login'))
233
+ }
234
+ }
235
+ return {
236
+ mutate,
237
+ }
238
+ }
239
+
240
+ /**
241
+ * Get auth
242
+ * get auth info
243
+ * @returns Auth info
244
+ */
245
+ export function useGetAuth(manageName?: string) {
246
+ const { config: manage } = useManage(manageName)
247
+ const authStore = useAuthStore()
248
+ const user = authStore.getUser(manage.name)
249
+ return user
250
+ }
251
+
252
+ /**
253
+ * Is login
254
+ * check if user is login
255
+ * @returns Is login
256
+ */
257
+ export function useIsLogin(manageName?: string) {
258
+ const { config: manage } = useManage(manageName)
259
+ const authStore = useAuthStore()
260
+ return authStore.isLogin(manage.name)
261
+ }
@@ -0,0 +1,16 @@
1
+ import type { IConfig } from '../types'
2
+ import { inject } from 'vue'
3
+
4
+ /**
5
+ * Config
6
+ * get global config
7
+ * @returns Config
8
+ */
9
+ export function useConfig(): IConfig {
10
+ const config = inject<IConfig>('dux.config')
11
+ if (!config) {
12
+ throw new Error('config is not defined')
13
+ }
14
+
15
+ return config
16
+ }