cosey 0.10.9 → 0.10.10
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/components/editor/hooks/useHistoryColor.js +1 -2
- package/components/upload/upload.api.js +1 -1
- package/config/api.d.ts +5 -5
- package/config/index.d.ts +6 -24
- package/config/index.js +10 -14
- package/config/root-config-provider.js +2 -2
- package/config/upload.d.ts +1 -1
- package/hooks/index.d.ts +0 -1
- package/hooks/index.js +0 -1
- package/hooks/useColorScheme.js +1 -2
- package/index.d.ts +8 -12
- package/index.js +21 -34
- package/layout/index.d.ts +1 -3
- package/layout/index.js +2 -61
- package/locale/index.d.ts +3 -3
- package/locale/index.js +6 -7
- package/package.json +2 -2
- package/persist/index.d.ts +4 -0
- package/persist/index.js +11 -0
- package/request/Http.d.ts +3 -1
- package/request/Http.js +1 -0
- package/request/index.d.ts +5 -2
- package/request/index.js +97 -2
- package/router/guard/auth.js +3 -4
- package/router/guard/pageTitle.js +2 -2
- package/router/index.d.ts +4 -2
- package/router/index.js +9 -4
- package/store/index.d.ts +4 -5
- package/store/index.js +3 -13
- package/store/layout.d.ts +57 -25
- package/store/layout.js +19 -14
- package/store/pinia.d.ts +4 -0
- package/store/pinia.js +11 -0
- package/store/plugin.js +5 -6
- package/store/user.d.ts +33 -2
- package/store/user.js +22 -30
- package/hooks/usePersist.d.ts +0 -9
- package/hooks/usePersist.js +0 -17
- package/request/useRequest.d.ts +0 -13
- package/request/useRequest.js +0 -109
- package/store/appearance.d.ts +0 -7
- package/store/appearance.js +0 -9
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { ref } from 'vue';
|
|
2
|
-
import {
|
|
2
|
+
import { persist } from '../../../persist/index.js';
|
|
3
3
|
|
|
4
4
|
const historyColorKey = "Cosey:historyColor";
|
|
5
5
|
let historyColors = null;
|
|
6
6
|
function useHistoryColor() {
|
|
7
|
-
const persist = usePersist();
|
|
8
7
|
if (!historyColors) {
|
|
9
8
|
historyColors = ref(persist.get(historyColorKey) || []);
|
|
10
9
|
}
|
package/config/api.d.ts
CHANGED
|
@@ -7,23 +7,23 @@ export declare const defaultApiConfig: {
|
|
|
7
7
|
/**
|
|
8
8
|
* 文件上传
|
|
9
9
|
*/
|
|
10
|
-
upload: ((
|
|
10
|
+
upload: ((data: Blob, config?: AxiosRequestConfig, extra?: Record<PropertyKey, any>) => Promise<string>) | null;
|
|
11
11
|
/**
|
|
12
12
|
* 登录
|
|
13
13
|
*/
|
|
14
|
-
login: ((
|
|
14
|
+
login: ((data: any, config?: AxiosRequestConfig) => Promise<string>) | null;
|
|
15
15
|
/**
|
|
16
16
|
* 获取用户详情
|
|
17
17
|
*/
|
|
18
|
-
getUserInfo: ((
|
|
18
|
+
getUserInfo: ((config?: AxiosRequestConfig) => Promise<any>) | null;
|
|
19
19
|
/**
|
|
20
20
|
* 修改密码
|
|
21
21
|
*/
|
|
22
|
-
changePassword: ((
|
|
22
|
+
changePassword: ((data: any, config?: AxiosRequestConfig) => Promise<any>) | null;
|
|
23
23
|
/**
|
|
24
24
|
* 退出
|
|
25
25
|
*/
|
|
26
|
-
logout: ((
|
|
26
|
+
logout: ((config?: AxiosRequestConfig) => Promise<any>) | null;
|
|
27
27
|
};
|
|
28
28
|
export type ApiConfig = DeepPartial<typeof defaultApiConfig>;
|
|
29
29
|
export type RequiredApiConfig = typeof defaultApiConfig;
|
package/config/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { type SiteConfig, type RequiredSiteConfig } from './site';
|
|
|
5
5
|
import { type HttpConfig, type RequiredHttpConfig } from './http';
|
|
6
6
|
import { type ApiConfig, type RequiredApiConfig } from './api';
|
|
7
7
|
import { type PersistConfig } from './persist';
|
|
8
|
-
import { I18nConfig } from './i18n';
|
|
8
|
+
import { type I18nConfig } from './i18n';
|
|
9
9
|
import { type RouteRecordRaw } from 'vue-router';
|
|
10
10
|
import { type CoseyRouterOptions } from '../router';
|
|
11
11
|
export interface LayoutComponents {
|
|
@@ -51,19 +51,15 @@ type FilterRouteHandler = (route: RouteRecordRaw) => RouteRecordRaw | void | boo
|
|
|
51
51
|
type DefineAuthorityHandler = (userInfo: Record<any, any>) => void | Promise<void>;
|
|
52
52
|
export type CoseyOptions = {
|
|
53
53
|
router?: CoseyRouterOptions & RouterConfig;
|
|
54
|
-
persist?: PersistConfig;
|
|
55
54
|
http?: HttpConfig;
|
|
56
55
|
layout?: LayoutConfig;
|
|
57
56
|
site?: SiteConfig;
|
|
58
57
|
api?: ApiConfig;
|
|
59
|
-
filterRoute?:
|
|
60
|
-
|
|
61
|
-
} | FilterRouteHandler;
|
|
62
|
-
defineAuthority?: {
|
|
63
|
-
hook: () => DefineAuthorityHandler;
|
|
64
|
-
} | DefineAuthorityHandler;
|
|
58
|
+
filterRoute?: FilterRouteHandler;
|
|
59
|
+
defineAuthority?: DefineAuthorityHandler;
|
|
65
60
|
components?: LayoutComponents;
|
|
66
61
|
slots?: LayoutSlots;
|
|
62
|
+
persist?: PersistConfig;
|
|
67
63
|
i18n?: I18nConfig;
|
|
68
64
|
};
|
|
69
65
|
export interface GlobalConfig {
|
|
@@ -77,21 +73,7 @@ export interface GlobalConfig {
|
|
|
77
73
|
components: NonNullable<CoseyOptions['components']>;
|
|
78
74
|
slots: NonNullable<CoseyOptions['slots']>;
|
|
79
75
|
}
|
|
80
|
-
export declare
|
|
81
|
-
|
|
82
|
-
http: any;
|
|
83
|
-
layout: any;
|
|
84
|
-
site: any;
|
|
85
|
-
api: any;
|
|
86
|
-
filterRoute: FilterRouteHandler | {
|
|
87
|
-
hook: () => FilterRouteHandler;
|
|
88
|
-
};
|
|
89
|
-
defineAuthority: DefineAuthorityHandler | {
|
|
90
|
-
hook: () => DefineAuthorityHandler;
|
|
91
|
-
};
|
|
92
|
-
components: LayoutComponents;
|
|
93
|
-
slots: LayoutSlots;
|
|
94
|
-
persist: import("@gunny/persist").default;
|
|
95
|
-
};
|
|
76
|
+
export declare let globalConfig: GlobalConfig;
|
|
77
|
+
export declare function launchGlobalConfig(app: App, options: CoseyOptions): void;
|
|
96
78
|
export declare function useGlobalConfig(): GlobalConfig;
|
|
97
79
|
export {};
|
package/config/index.js
CHANGED
|
@@ -5,15 +5,14 @@ import { defaultLayoutConfig } from './layout.js';
|
|
|
5
5
|
import { defaultSiteConfig } from './site.js';
|
|
6
6
|
import { defaultHttpConfig } from './http.js';
|
|
7
7
|
import { defaultApiConfig } from './api.js';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import { createPersist, persistContextKey } from '../hooks/usePersist.js';
|
|
8
|
+
import { launchLocale } from '../locale/index.js';
|
|
9
|
+
import { launchPersist } from '../persist/index.js';
|
|
11
10
|
|
|
12
11
|
const globalConfigContextKey = Symbol("globalConfigContext");
|
|
13
|
-
|
|
12
|
+
let globalConfig;
|
|
13
|
+
function launchGlobalConfig(app, options) {
|
|
14
14
|
const {
|
|
15
15
|
router: { homePath, loginPath, changePasswordPath } = {},
|
|
16
|
-
persist = {},
|
|
17
16
|
http = {},
|
|
18
17
|
layout = {},
|
|
19
18
|
site = {},
|
|
@@ -22,13 +21,10 @@ function provideGlobalConfig(app, options) {
|
|
|
22
21
|
defineAuthority = () => void 0,
|
|
23
22
|
components = {},
|
|
24
23
|
slots = {},
|
|
24
|
+
persist = {},
|
|
25
25
|
i18n = {}
|
|
26
26
|
} = options;
|
|
27
|
-
|
|
28
|
-
const persistIns = createPersist(persistConfig.name, persistConfig.type);
|
|
29
|
-
setupLocale(app, i18n, persistIns);
|
|
30
|
-
app.provide(persistContextKey, persistIns);
|
|
31
|
-
const globalConfig = {
|
|
27
|
+
globalConfig = {
|
|
32
28
|
router: defaultsDeep({ homePath, loginPath, changePasswordPath }, defaultRouterConfig),
|
|
33
29
|
http: defaultsDeep(http, defaultHttpConfig),
|
|
34
30
|
layout: defaultsDeep(layout, defaultLayoutConfig),
|
|
@@ -37,14 +33,14 @@ function provideGlobalConfig(app, options) {
|
|
|
37
33
|
filterRoute,
|
|
38
34
|
defineAuthority,
|
|
39
35
|
components,
|
|
40
|
-
slots
|
|
41
|
-
persist: persistIns
|
|
36
|
+
slots
|
|
42
37
|
};
|
|
43
38
|
app.provide(globalConfigContextKey, globalConfig);
|
|
44
|
-
|
|
39
|
+
launchPersist(persist);
|
|
40
|
+
launchLocale(app, i18n);
|
|
45
41
|
}
|
|
46
42
|
function useGlobalConfig() {
|
|
47
43
|
return inject(globalConfigContextKey, {});
|
|
48
44
|
}
|
|
49
45
|
|
|
50
|
-
export {
|
|
46
|
+
export { globalConfig, launchGlobalConfig, useGlobalConfig };
|
|
@@ -32,7 +32,7 @@ var stdin_default = defineComponent({
|
|
|
32
32
|
const coseyLocale = useCoseyLocale();
|
|
33
33
|
const apiConfig = useGlobalConfig()?.api;
|
|
34
34
|
if (apiConfig) {
|
|
35
|
-
const uploadApi = apiConfig.upload
|
|
35
|
+
const uploadApi = apiConfig.upload;
|
|
36
36
|
provideUploadConfig({
|
|
37
37
|
request: uploadApi
|
|
38
38
|
});
|
|
@@ -52,7 +52,7 @@ var stdin_default = defineComponent({
|
|
|
52
52
|
return () => {
|
|
53
53
|
return createVNode(_ConfigProvider, mergedConfigProviderProps.value, {
|
|
54
54
|
default: () => [createVNode(ElConfigProvider, {
|
|
55
|
-
"locale":
|
|
55
|
+
"locale": coseyLocale.value
|
|
56
56
|
}, slots)]
|
|
57
57
|
});
|
|
58
58
|
};
|
package/config/upload.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AxiosRequestConfig } from 'axios';
|
|
2
2
|
export interface UploadContext {
|
|
3
|
-
request?: (data: Blob, config?: AxiosRequestConfig, extra?: Record<PropertyKey, any>) => Promise<string
|
|
3
|
+
request?: ((data: Blob, config?: AxiosRequestConfig, extra?: Record<PropertyKey, any>) => Promise<string>) | null;
|
|
4
4
|
}
|
|
5
5
|
export declare const provideUploadConfig: (context: UploadContext) => void;
|
|
6
6
|
export declare const injectUploadConfig: () => UploadContext | null;
|
package/hooks/index.d.ts
CHANGED
|
@@ -14,7 +14,6 @@ export * from './useTwoWayBinding';
|
|
|
14
14
|
export * from './useUpsert';
|
|
15
15
|
export * from './useVisible';
|
|
16
16
|
export * from './useWindowResize';
|
|
17
|
-
export * from './usePersist';
|
|
18
17
|
export * from './useRectObserver';
|
|
19
18
|
export * from './useTreeCheck';
|
|
20
19
|
export * from './useOptionalComponent';
|
package/hooks/index.js
CHANGED
|
@@ -14,7 +14,6 @@ export { useTwoWayBinding } from './useTwoWayBinding.js';
|
|
|
14
14
|
export { useOuterUpsert, useUpsert } from './useUpsert.js';
|
|
15
15
|
export { useVisible } from './useVisible.js';
|
|
16
16
|
export { useWindowResize } from './useWindowResize.js';
|
|
17
|
-
export { createPersist, persistContextKey, usePersist } from './usePersist.js';
|
|
18
17
|
export { useRectObserver } from './useRectObserver.js';
|
|
19
18
|
export { treeCheckContextKey, useTreeCheck, useTreeCheckInject } from './useTreeCheck.js';
|
|
20
19
|
export { useOptionalComponent } from './useOptionalComponent.js';
|
package/hooks/useColorScheme.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { inject, ref, computed, onMounted, onBeforeUnmount, watch, provide } from 'vue';
|
|
2
|
-
import {
|
|
2
|
+
import { persist } from '../persist/index.js';
|
|
3
3
|
import { isClient } from '../utils/env.js';
|
|
4
4
|
|
|
5
5
|
const colorSchemeContextSymbol = Symbol("colorScheme");
|
|
@@ -10,7 +10,6 @@ const colorSchemeOptions = [
|
|
|
10
10
|
{ label: "co.colorScheme.dark", icon: "co:moon", value: "dark" }
|
|
11
11
|
];
|
|
12
12
|
function useColorSchemeProvide() {
|
|
13
|
-
const persist = usePersist();
|
|
14
13
|
const defaultColorScheme = persist.get(colorSchemeKey) || "auto";
|
|
15
14
|
const colorScheme = ref(defaultColorScheme);
|
|
16
15
|
const appliedColorScheme = ref("light");
|
package/index.d.ts
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
import { type App } from 'vue';
|
|
2
2
|
import { type CoseyOptions } from './config';
|
|
3
|
-
export
|
|
4
|
-
export * from './layout';
|
|
5
|
-
export * from './
|
|
3
|
+
export { Http, createHttp, http } from './request';
|
|
4
|
+
export * from './layout/layout';
|
|
5
|
+
export * from './layout/merged';
|
|
6
|
+
export { defineRoute, defineRoutes, mergeRouteModules, router } from './router';
|
|
7
|
+
export { pinia, useUserStore, useOuterUserStore, useLayoutStore, useOuterLayoutStore, } from './store';
|
|
8
|
+
export { type CoseyOptions, type LayoutComponents, type LayoutSlots } from './config';
|
|
9
|
+
export { persist } from './persist';
|
|
6
10
|
export { i18n } from './locale';
|
|
7
|
-
export { useUserStore, useAppearanceStore, useLayoutStore } from './store';
|
|
8
|
-
export * from './config';
|
|
9
11
|
export * from './config/root-config-provider.api';
|
|
10
12
|
export { default as RootConfigProvider } from './config/root-config-provider';
|
|
11
|
-
export
|
|
12
|
-
}
|
|
13
|
-
export declare const createCosey: (options?: CoseyOptions) => {
|
|
14
|
-
install(app: App): void;
|
|
15
|
-
pinia: import("pinia").Pinia;
|
|
16
|
-
router: import("vue-router").Router;
|
|
17
|
-
};
|
|
13
|
+
export declare function launch(app: App, options?: CoseyOptions): void;
|
package/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { launchRouter } from './router/index.js';
|
|
2
|
+
export { router } from './router/index.js';
|
|
3
|
+
import { launchGlobalConfig } from './config/index.js';
|
|
4
|
+
import { launchGlobalComponents } from './layout/index.js';
|
|
5
|
+
import { launchStore } from './store/pinia.js';
|
|
6
|
+
export { pinia } from './store/pinia.js';
|
|
7
|
+
export { useLayoutStore, useOuterLayoutStore } from './store/layout.js';
|
|
8
|
+
export { useOuterUserStore, useUserStore } from './store/user.js';
|
|
9
|
+
export { createHttp, http } from './request/index.js';
|
|
10
|
+
export { persist } from './persist/index.js';
|
|
8
11
|
export { i18n } from './locale/index.js';
|
|
9
12
|
export { getAlgorithm, rootConfigProviderProps } from './config/root-config-provider.api.js';
|
|
10
13
|
export { default as RootConfigProvider } from './config/root-config-provider.js';
|
|
11
|
-
export { useAppearanceStore } from './store/appearance.js';
|
|
12
|
-
export { useLayoutStore } from './store/layout.js';
|
|
13
|
-
export { useUserStore } from './store/user.js';
|
|
14
|
-
import { isClient } from './utils/env.js';
|
|
15
14
|
export { Http } from './request/Http.js';
|
|
16
|
-
export {
|
|
15
|
+
export { defineRoute, defineRoutes, mergeRouteModules } from './router/utils.js';
|
|
16
|
+
import { isClient } from './utils/env.js';
|
|
17
17
|
export { default as LayoutAside } from './layout/layout-aside/layout-aside.vue.js';
|
|
18
18
|
export { default as LayoutAuth } from './layout/layout-auth/layout-auth.vue.js';
|
|
19
19
|
export { default as LayoutBase } from './layout/layout-base/layout-base.vue.js';
|
|
@@ -73,27 +73,14 @@ export { default as MergedLayoutToggle } from './layout/merged/layout-toggle.js'
|
|
|
73
73
|
export { default as MergedLayoutTopSnugMenu } from './layout/merged/layout-top-snug-menu.js';
|
|
74
74
|
export { default as MergedLayoutTopbar } from './layout/merged/layout-topbar.js';
|
|
75
75
|
export { default as MergedLayoutUserMenu } from './layout/merged/layout-user-menu.js';
|
|
76
|
-
export { defineRoute, defineRoutes, mergeRouteModules } from './router/utils.js';
|
|
77
|
-
export { getBreadcrumbRoutes, getMenuPathKeys, getMenus, getMenusMap } from './router/menus/index.js';
|
|
78
76
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
app.use(router);
|
|
88
|
-
if (router.listening) {
|
|
89
|
-
registerRouterGuard(router);
|
|
90
|
-
}
|
|
91
|
-
app.use(pinia);
|
|
92
|
-
registerGlobalComponents(app);
|
|
93
|
-
},
|
|
94
|
-
pinia,
|
|
95
|
-
router
|
|
96
|
-
};
|
|
97
|
-
};
|
|
77
|
+
function launch(app, options = {}) {
|
|
78
|
+
launchRouter(app, options.router);
|
|
79
|
+
launchStore(app);
|
|
80
|
+
launchGlobalComponents(app);
|
|
81
|
+
if (isClient()) {
|
|
82
|
+
launchGlobalConfig(app, options);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
98
85
|
|
|
99
|
-
export {
|
|
86
|
+
export { launch };
|
package/layout/index.d.ts
CHANGED
package/layout/index.js
CHANGED
|
@@ -1,68 +1,9 @@
|
|
|
1
1
|
import ElementPlus from 'element-plus';
|
|
2
2
|
import stdin_default from '../components/index.js';
|
|
3
|
-
export { default as LayoutAside } from './layout-aside/layout-aside.vue.js';
|
|
4
|
-
export { default as LayoutAuth } from './layout-auth/layout-auth.vue.js';
|
|
5
|
-
export { default as LayoutBase } from './layout-base/layout-base.vue.js';
|
|
6
|
-
export { default as LayoutBrand } from './layout-brand/layout-brand.vue.js';
|
|
7
|
-
export { default as LayoutBreadcrumb } from './layout-breadcrumb/layout-breadcrumb.vue.js';
|
|
8
|
-
export { default as LayoutChangePassword } from './layout-change-password/layout-change-password.vue.js';
|
|
9
|
-
export { default as LayoutColorScheme } from './layout-color-scheme/layout-color-scheme.vue.js';
|
|
10
|
-
export { default as LayoutContent } from './layout-content/layout-content.vue.js';
|
|
11
|
-
export { default as LayoutEmpty } from './layout-empty/layout-empty.vue.js';
|
|
12
|
-
export { default as LayoutException } from './layout-exception/layout-exception.vue.js';
|
|
13
|
-
export { default as LayoutForbidden } from './layout-forbidden/layout-forbidden.vue.js';
|
|
14
|
-
export { default as LayoutHeader } from './layout-header/layout-header.vue.js';
|
|
15
|
-
export { default as LayoutIframe } from './layout-iframe/layout-iframe.vue.js';
|
|
16
|
-
export { default as LayoutInternalServerError } from './layout-internal-server-error/layout-internal-server-error.vue.js';
|
|
17
|
-
export { default as LayoutLogin } from './layout-login/layout-login.vue.js';
|
|
18
|
-
export { default as LayoutMain } from './layout-main/layout-main.vue.js';
|
|
19
|
-
export { default as LayoutMask } from './layout-mask/layout-mask.vue.js';
|
|
20
|
-
export { default as LayoutMenu } from './layout-menu/layout-menu.vue.js';
|
|
21
|
-
export { default as LayoutNotFound } from './layout-not-found/layout-not-found.vue.js';
|
|
22
|
-
export { default as LayoutSearch } from './layout-search/layout-search.vue.js';
|
|
23
|
-
export { default as LayoutSidebar } from './layout-sidebar/layout-sidebar.vue.js';
|
|
24
|
-
export { default as LayoutSnugAside } from './layout-snug-aside/layout-snug-aside.vue.js';
|
|
25
|
-
export { default as LayoutSnugMenu } from './layout-snug-menu/layout-snug-menu.vue.js';
|
|
26
|
-
export { default as LayoutSwitchEffect } from './layout-switch-effect/layout-switch-effect.vue.js';
|
|
27
|
-
export { default as LayoutTabbar } from './layout-tabbar/layout-tabbar.vue.js';
|
|
28
|
-
export { default as LayoutToggle } from './layout-toggle/layout-toggle.vue.js';
|
|
29
|
-
export { default as LayoutTopSnugMenu } from './layout-top-snug-menu/layout-top-snug-menu.vue.js';
|
|
30
|
-
export { default as LayoutTopbar } from './layout-topbar/layout-topbar.vue.js';
|
|
31
|
-
export { default as LayoutUserMenu } from './layout-user-menu/layout-user-menu.vue.js';
|
|
32
|
-
export { default as MergedLayoutAside } from './merged/layout-aside.js';
|
|
33
|
-
export { default as MergedLayoutAuth } from './merged/layout-auth.js';
|
|
34
|
-
export { default as MergedLayoutBase } from './merged/layout-base.js';
|
|
35
|
-
export { default as MergedLayoutBrand } from './merged/layout-brand.js';
|
|
36
|
-
export { default as MergedLayoutBreadcrumb } from './merged/layout-breadcrumb.js';
|
|
37
|
-
export { default as MergedLayoutChangePassword } from './merged/layout-change-password.js';
|
|
38
|
-
export { default as MergedLayoutColorScheme } from './merged/layout-color-scheme.js';
|
|
39
|
-
export { default as MergedLayoutContent } from './merged/layout-content.js';
|
|
40
|
-
export { default as MergedLayoutEmpty } from './merged/layout-empty.js';
|
|
41
|
-
export { default as MergedLayoutException } from './merged/layout-exception.js';
|
|
42
|
-
export { default as MergedLayoutForbidden } from './merged/layout-forbidden.js';
|
|
43
|
-
export { default as MergedLayoutHeader } from './merged/layout-header.js';
|
|
44
|
-
export { default as MergedLayoutIframe } from './merged/layout-iframe.js';
|
|
45
|
-
export { default as MergedLayoutInternalServerError } from './merged/layout-internal-server-error.js';
|
|
46
|
-
export { default as MergedLayoutLocale } from './merged/layout-locale.js';
|
|
47
|
-
export { default as MergedLayoutLogin } from './merged/layout-login.js';
|
|
48
|
-
export { default as MergedLayoutMain } from './merged/layout-main.js';
|
|
49
|
-
export { default as MergedLayoutMask } from './merged/layout-mask.js';
|
|
50
|
-
export { default as MergedLayoutMenu } from './merged/layout-menu.js';
|
|
51
|
-
export { default as MergedLayoutNotFound } from './merged/layout-not-found.js';
|
|
52
|
-
export { default as MergedLayoutSearch } from './merged/layout-search.js';
|
|
53
|
-
export { default as MergedLayoutSidebar } from './merged/layout-sidebar.js';
|
|
54
|
-
export { default as MergedLayoutSnugAside } from './merged/layout-snug-aside.js';
|
|
55
|
-
export { default as MergedLayoutSnugMenu } from './merged/layout-snug-menu.js';
|
|
56
|
-
export { default as MergedLayoutSwitchEffect } from './merged/layout-switch-effect.js';
|
|
57
|
-
export { default as MergedLayoutTabbar } from './merged/layout-tabbar.js';
|
|
58
|
-
export { default as MergedLayoutToggle } from './merged/layout-toggle.js';
|
|
59
|
-
export { default as MergedLayoutTopSnugMenu } from './merged/layout-top-snug-menu.js';
|
|
60
|
-
export { default as MergedLayoutTopbar } from './merged/layout-topbar.js';
|
|
61
|
-
export { default as MergedLayoutUserMenu } from './merged/layout-user-menu.js';
|
|
62
3
|
|
|
63
|
-
function
|
|
4
|
+
function launchGlobalComponents(app) {
|
|
64
5
|
app.use(ElementPlus);
|
|
65
6
|
app.use(stdin_default);
|
|
66
7
|
}
|
|
67
8
|
|
|
68
|
-
export {
|
|
9
|
+
export { launchGlobalComponents };
|
package/locale/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type App } from 'vue';
|
|
2
|
+
import { type I18n } from 'vue-i18n';
|
|
2
3
|
import { type I18nConfig } from '../config/i18n';
|
|
3
|
-
import Persist from '@gunny/persist';
|
|
4
4
|
export type TranslatePair = {
|
|
5
5
|
[key: string]: string | string[] | TranslatePair;
|
|
6
6
|
};
|
|
@@ -9,8 +9,8 @@ export type Language = {
|
|
|
9
9
|
el: TranslatePair;
|
|
10
10
|
co: TranslatePair;
|
|
11
11
|
};
|
|
12
|
-
export declare let i18n:
|
|
13
|
-
export declare function
|
|
12
|
+
export declare let i18n: I18n;
|
|
13
|
+
export declare function launchLocale(app: App, config?: I18nConfig): void;
|
|
14
14
|
export declare function useCoseyLocale(): Record<string, any>;
|
|
15
15
|
export declare function useLocaleMessages(): {
|
|
16
16
|
value: string;
|
package/locale/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { inject, shallowRef, watch } from 'vue';
|
|
1
|
+
import { inject, shallowRef, watch, toValue } from 'vue';
|
|
2
2
|
import { createI18n } from 'vue-i18n';
|
|
3
3
|
import { defaultsDeep } from 'lodash-es';
|
|
4
4
|
import dayjs from 'dayjs';
|
|
5
5
|
import { defaultI18nConfig } from '../config/i18n.js';
|
|
6
|
+
import { persist } from '../persist/index.js';
|
|
6
7
|
|
|
7
8
|
const langKey = "Cosey:lang";
|
|
8
9
|
const rtlLangs = ["ar"];
|
|
@@ -15,10 +16,8 @@ function getMessages(config, type) {
|
|
|
15
16
|
}
|
|
16
17
|
const coseyLocaleKey = Symbol("coseyLocale");
|
|
17
18
|
const localeMessagesKey = Symbol("localeMessages");
|
|
18
|
-
let i18n
|
|
19
|
-
|
|
20
|
-
});
|
|
21
|
-
function setupLocale(app, config = {}, persist) {
|
|
19
|
+
let i18n;
|
|
20
|
+
function launchLocale(app, config = {}) {
|
|
22
21
|
const mergedConfig = defaultsDeep(config, defaultI18nConfig);
|
|
23
22
|
const appMessages = getMessages(mergedConfig, "app");
|
|
24
23
|
const coesyMessages = getMessages(mergedConfig, "cosey");
|
|
@@ -36,7 +35,7 @@ function setupLocale(app, config = {}, persist) {
|
|
|
36
35
|
fallbackWarn: false
|
|
37
36
|
});
|
|
38
37
|
watch(
|
|
39
|
-
i18n.global.locale,
|
|
38
|
+
() => toValue(i18n.global.locale),
|
|
40
39
|
(locale2) => {
|
|
41
40
|
coseyLocale.value = coesyMessages[locale2];
|
|
42
41
|
dayjs.locale(dayjsMessages[locale2]);
|
|
@@ -58,4 +57,4 @@ function useLocaleMessages() {
|
|
|
58
57
|
return inject(localeMessagesKey, []);
|
|
59
58
|
}
|
|
60
59
|
|
|
61
|
-
export { i18n,
|
|
60
|
+
export { i18n, launchLocale, useCoseyLocale, useLocaleMessages };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cosey",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.10",
|
|
4
4
|
"description": "基于 Vue3 + vite 的后台管理系统框架",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"@emotion/hash": "^0.9.2",
|
|
16
16
|
"@emotion/unitless": "^0.10.0",
|
|
17
17
|
"@floating-ui/dom": "^1.6.13",
|
|
18
|
-
"@gunny/persist": "^1.0.
|
|
18
|
+
"@gunny/persist": "^1.0.3",
|
|
19
19
|
"@iconify/types": "^2.0.0",
|
|
20
20
|
"@types/is-hotkey": "^0.1.10",
|
|
21
21
|
"@types/nprogress": "^0.2.3",
|
package/persist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import Persist from '@gunny/persist';
|
|
2
|
+
import { defaultPersistConfig } from '../config/persist.js';
|
|
3
|
+
import { defaultsDeep } from 'lodash-es';
|
|
4
|
+
|
|
5
|
+
let persist;
|
|
6
|
+
function launchPersist(config) {
|
|
7
|
+
const { name, type } = defaultsDeep(config, defaultPersistConfig);
|
|
8
|
+
persist = new Persist(name, { type });
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { launchPersist, persist };
|
package/request/Http.d.ts
CHANGED
|
@@ -7,7 +7,9 @@ export declare class Http {
|
|
|
7
7
|
config: AxiosRequestConfig | null;
|
|
8
8
|
constructor(axiosFactory: (httpConfig?: HttpConfig) => AxiosInstance);
|
|
9
9
|
abort(): void;
|
|
10
|
-
_request<T = any, D = any>(config: AxiosRequestConfig<D
|
|
10
|
+
_request<T = any, D = any>(config: AxiosRequestConfig<D> & {
|
|
11
|
+
coseyHttpConfig?: HttpConfig;
|
|
12
|
+
}, httpConfig?: HttpConfig): Promise<T>;
|
|
11
13
|
request<T = any, D = any>(config: AxiosRequestConfig<D>, httpConfig?: HttpConfig): Promise<T>;
|
|
12
14
|
get<T = any, D = any>(url: string, config?: AxiosRequestConfig<D>, httpConfig?: HttpConfig): Promise<T>;
|
|
13
15
|
delete<T = any, D = any>(url: string, config?: AxiosRequestConfig<D>, httpConfig?: HttpConfig): Promise<T>;
|
package/request/Http.js
CHANGED
package/request/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { type CreateAxiosDefaults } from 'axios';
|
|
1
2
|
import { Http } from './Http';
|
|
2
|
-
import {
|
|
3
|
-
export {
|
|
3
|
+
import { type HttpConfig } from '../config/http';
|
|
4
|
+
export { Http } from './Http';
|
|
5
|
+
export declare function createHttp(axiosConfig?: CreateAxiosDefaults, createCfg?: HttpConfig): Http;
|
|
6
|
+
export declare const http: Http;
|
package/request/index.js
CHANGED
|
@@ -1,2 +1,97 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import axios, { AxiosError } from 'axios';
|
|
2
|
+
import { ElMessage } from 'element-plus';
|
|
3
|
+
import { merge, pick, get } from 'lodash-es';
|
|
4
|
+
import { useOuterUserStore } from '../store/user.js';
|
|
5
|
+
import { TOKEN_NAME, ROUTER_TO } from '../constant.js';
|
|
6
|
+
import { Http } from './Http.js';
|
|
7
|
+
import { persist } from '../persist/index.js';
|
|
8
|
+
import { globalConfig } from '../config/index.js';
|
|
9
|
+
import { router } from '../router/index.js';
|
|
10
|
+
import { isObject } from '../utils/is.js';
|
|
11
|
+
|
|
12
|
+
function createHttp(axiosConfig = {}, createCfg = {}) {
|
|
13
|
+
function createAxios() {
|
|
14
|
+
const { http: globalCfg, router: routerConfig } = globalConfig;
|
|
15
|
+
const createdMergedCfg = merge({}, globalCfg, createCfg);
|
|
16
|
+
const userStore = useOuterUserStore();
|
|
17
|
+
const handleError = (resData, mergedCfg) => {
|
|
18
|
+
const httpPath = mergedCfg.path;
|
|
19
|
+
const code = get(resData, httpPath.code);
|
|
20
|
+
const message = get(resData, httpPath.message) || "Error";
|
|
21
|
+
const data = httpPath.data ? get(resData, httpPath.data) : resData;
|
|
22
|
+
if (code !== mergedCfg.code.success) {
|
|
23
|
+
ElMessage.error({
|
|
24
|
+
message,
|
|
25
|
+
duration: mergedCfg.errorDuration
|
|
26
|
+
});
|
|
27
|
+
if (code === mergedCfg.code.forbidden) {
|
|
28
|
+
router.push(routerConfig.homePath);
|
|
29
|
+
} else if (code === mergedCfg.code.unauthorized) {
|
|
30
|
+
if (persist.get(TOKEN_NAME)) {
|
|
31
|
+
userStore.logout(persist.get(ROUTER_TO) || router.currentRoute.value.fullPath);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return Promise.reject(new Error(message));
|
|
35
|
+
}
|
|
36
|
+
if (mergedCfg.originalData) {
|
|
37
|
+
return resData;
|
|
38
|
+
}
|
|
39
|
+
return data;
|
|
40
|
+
};
|
|
41
|
+
const axiosIns = axios.create(
|
|
42
|
+
merge({}, pick(createdMergedCfg, ["baseURL", "timeout", "headers"]), axiosConfig)
|
|
43
|
+
);
|
|
44
|
+
function getMergedCfg(target) {
|
|
45
|
+
return target?.config?.coseyMergedCfg || createdMergedCfg;
|
|
46
|
+
}
|
|
47
|
+
axiosIns.interceptors.request.use(
|
|
48
|
+
(config) => {
|
|
49
|
+
const mergedCfg = config.coseyMergedCfg = merge(
|
|
50
|
+
{},
|
|
51
|
+
createdMergedCfg,
|
|
52
|
+
config.coseyHttpConfig
|
|
53
|
+
);
|
|
54
|
+
const token = persist.get(TOKEN_NAME);
|
|
55
|
+
if (token) {
|
|
56
|
+
config.headers[mergedCfg.authHeaderKey] = mergedCfg.authScheme ? `${mergedCfg.authScheme} ${token}` : token;
|
|
57
|
+
}
|
|
58
|
+
return config;
|
|
59
|
+
},
|
|
60
|
+
(error) => {
|
|
61
|
+
const mergedCfg = getMergedCfg(error);
|
|
62
|
+
ElMessage.error({
|
|
63
|
+
message: error.message,
|
|
64
|
+
duration: mergedCfg.errorDuration
|
|
65
|
+
});
|
|
66
|
+
return Promise.reject(error);
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
axiosIns.interceptors.response.use(
|
|
70
|
+
(response) => {
|
|
71
|
+
const mergedCfg = getMergedCfg(response);
|
|
72
|
+
if (mergedCfg.originalResponse) {
|
|
73
|
+
return response;
|
|
74
|
+
}
|
|
75
|
+
const { data: resData } = response;
|
|
76
|
+
return handleError(resData, mergedCfg);
|
|
77
|
+
},
|
|
78
|
+
(error) => {
|
|
79
|
+
const mergedCfg = getMergedCfg(error);
|
|
80
|
+
if (error instanceof AxiosError && error.response && isObject(error.response.data) && get(error.response.data, mergedCfg.path.code)) {
|
|
81
|
+
return handleError(error.response.data, mergedCfg);
|
|
82
|
+
} else {
|
|
83
|
+
ElMessage.error({
|
|
84
|
+
message: error.message,
|
|
85
|
+
duration: mergedCfg.errorDuration
|
|
86
|
+
});
|
|
87
|
+
return Promise.reject(error);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
);
|
|
91
|
+
return axiosIns;
|
|
92
|
+
}
|
|
93
|
+
return new Http(createAxios);
|
|
94
|
+
}
|
|
95
|
+
const http = createHttp();
|
|
96
|
+
|
|
97
|
+
export { Http, createHttp, http };
|
package/router/guard/auth.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { globalConfig } from '../../config/index.js';
|
|
2
2
|
import { useUserStore } from '../../store/user.js';
|
|
3
3
|
import { TOKEN_NAME, ROUTER_TO } from '../../constant.js';
|
|
4
|
-
import {
|
|
4
|
+
import { persist } from '../../persist/index.js';
|
|
5
5
|
|
|
6
6
|
function registerAuthGuard(router) {
|
|
7
7
|
let firstTimeAddRoutes = false;
|
|
8
8
|
router.beforeEach(async (to) => {
|
|
9
|
-
const
|
|
10
|
-
const routerConfig = useGlobalConfig().router;
|
|
9
|
+
const { router: routerConfig } = globalConfig;
|
|
11
10
|
const token = persist.get(TOKEN_NAME);
|
|
12
11
|
const userStore = useUserStore();
|
|
13
12
|
if (to.path === "/" && routerConfig.homePath !== "/") {
|