cosey 0.10.21 → 0.10.23
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/form-list/form-list.vue.js +2 -2
- package/components/remote-select/remote-select.js +2 -2
- package/components/table/table-column-editor/list.vue.js +2 -2
- package/components/table/table.vue.js +3 -3
- package/components/upload/upload.js +3 -3
- package/config/api.d.ts +0 -4
- package/config/api.js +0 -4
- package/config/index.d.ts +7 -3
- package/config/index.js +2 -2
- package/hooks/useUpsert.js +2 -2
- package/layout/layout-user-menu/layout-user-menu.vue.js +1 -1
- package/package.json +1 -1
- package/router/guard/auth.js +11 -20
- package/router/utils.js +3 -3
- package/store/layout.d.ts +10 -16
- package/store/user.d.ts +18 -32
- package/store/user.js +41 -38
- package/utils/index.js +1 -1
- package/utils/string.d.ts +1 -8
- package/utils/string.js +4 -6
|
@@ -14,7 +14,7 @@ import { arrayMove } from '../../utils/array.js';
|
|
|
14
14
|
import { getFormItemWidth } from '../form/useFormItemWidth.js';
|
|
15
15
|
import { useLocale } from '../../hooks/useLocale.js';
|
|
16
16
|
import { useComponentConfig } from '../config-provider/config-provider.api.js';
|
|
17
|
-
import {
|
|
17
|
+
import { auid } from '../../utils/string.js';
|
|
18
18
|
import { createMergedExpose, defineTemplate } from '../../utils/vue.js';
|
|
19
19
|
import { isString, isNumber } from '../../utils/is.js';
|
|
20
20
|
|
|
@@ -187,7 +187,7 @@ var stdin_default = /* @__PURE__ */defineComponent({
|
|
|
187
187
|
props.modelValue.forEach(row => {
|
|
188
188
|
let key = mapRowKey.get(row);
|
|
189
189
|
if (!key) {
|
|
190
|
-
key =
|
|
190
|
+
key = auid();
|
|
191
191
|
}
|
|
192
192
|
newMapRowKey.set(row, key);
|
|
193
193
|
});
|
|
@@ -9,10 +9,10 @@ import stdin_default$2 from '../table/table-query/table-query.js';
|
|
|
9
9
|
import { useComponentConfig, useConfig } from '../config-provider/config-provider.api.js';
|
|
10
10
|
import { useFetch } from '../../hooks/useFetch.js';
|
|
11
11
|
import { createLoading, filterEmptyFormValue } from '../../utils/components.js';
|
|
12
|
-
import { uniqid } from '../../utils/string.js';
|
|
13
12
|
import { bulkBindEvents } from '../../utils/vue.js';
|
|
14
13
|
import { isObject, isFunction } from '../../utils/is.js';
|
|
15
14
|
import { useProps } from '../../hooks/useProps.js';
|
|
15
|
+
import { auid } from '../../utils/string.js';
|
|
16
16
|
|
|
17
17
|
var stdin_default = defineComponent({
|
|
18
18
|
name: "CoRemoteSelect",
|
|
@@ -128,7 +128,7 @@ var stdin_default = defineComponent({
|
|
|
128
128
|
getValue,
|
|
129
129
|
getKey
|
|
130
130
|
} = useProps(props);
|
|
131
|
-
const popperId =
|
|
131
|
+
const popperId = auid();
|
|
132
132
|
const events = bulkBindEvents(remoteSelectEmits, emit);
|
|
133
133
|
const selectProps = computed(() => {
|
|
134
134
|
return omit(props, ["optionProps", "api", "pagination", "formProps", "transformParams", "keys", "immediate"]);
|
|
@@ -4,7 +4,7 @@ import { TransitionGroup as _TransitionGroup } from '../../transition-group/inde
|
|
|
4
4
|
import stdin_default$1 from './item.vue.js';
|
|
5
5
|
import { useDndSort } from '../../dnd-sort/useDndSort.js';
|
|
6
6
|
import { useComponentConfig } from '../../config-provider/config-provider.api.js';
|
|
7
|
-
import {
|
|
7
|
+
import { auid } from '../../../utils/string.js';
|
|
8
8
|
import { arrayMove } from '../../../utils/array.js';
|
|
9
9
|
|
|
10
10
|
var stdin_default = /* @__PURE__ */defineComponent({
|
|
@@ -33,7 +33,7 @@ var stdin_default = /* @__PURE__ */defineComponent({
|
|
|
33
33
|
props.nodeList.forEach(node => {
|
|
34
34
|
let key = mapTargetKey.get(node);
|
|
35
35
|
if (!key) {
|
|
36
|
-
key =
|
|
36
|
+
key = auid();
|
|
37
37
|
}
|
|
38
38
|
newMapTargetKey.set(node, key);
|
|
39
39
|
});
|
|
@@ -16,7 +16,7 @@ import stdin_default$3 from './table-stats/table-stats.js';
|
|
|
16
16
|
import { flatColumns } from '../../utils/excel/index.js';
|
|
17
17
|
import { useFullPage } from '../../hooks/useFullPage.js';
|
|
18
18
|
import { useLocale } from '../../hooks/useLocale.js';
|
|
19
|
-
import {
|
|
19
|
+
import { auid } from '../../utils/string.js';
|
|
20
20
|
import { useComponentConfig, useConfig } from '../config-provider/config-provider.api.js';
|
|
21
21
|
import { addPxUnit } from '../../utils/css.js';
|
|
22
22
|
import { isNullish, isObject, isFunction } from '../../utils/is.js';
|
|
@@ -61,7 +61,7 @@ var stdin_default = /* @__PURE__ */defineComponent({
|
|
|
61
61
|
const {
|
|
62
62
|
t
|
|
63
63
|
} = useLocale();
|
|
64
|
-
const tableId =
|
|
64
|
+
const tableId = auid();
|
|
65
65
|
const {
|
|
66
66
|
prefixCls
|
|
67
67
|
} = useComponentConfig("table");
|
|
@@ -550,7 +550,7 @@ var stdin_default = /* @__PURE__ */defineComponent({
|
|
|
550
550
|
"show-summary": false,
|
|
551
551
|
"summary-method": void 0,
|
|
552
552
|
style: {
|
|
553
|
-
|
|
553
|
+
width: "100%"
|
|
554
554
|
},
|
|
555
555
|
height: "100%",
|
|
556
556
|
"max-height": "none"
|
|
@@ -10,7 +10,7 @@ import { getFileType, chooseFiles } from '../../utils/file.js';
|
|
|
10
10
|
import { useLocale } from '../../hooks/useLocale.js';
|
|
11
11
|
import { useComponentConfig } from '../config-provider/config-provider.api.js';
|
|
12
12
|
import { debugWarn } from 'element-plus/es/utils/error.mjs';
|
|
13
|
-
import {
|
|
13
|
+
import { auid } from '../../utils/string.js';
|
|
14
14
|
import { getBasename } from '../../utils/path.js';
|
|
15
15
|
import { isString } from '../../utils/is.js';
|
|
16
16
|
import { isShallowEqual } from '../../utils/array.js';
|
|
@@ -65,7 +65,7 @@ var stdin_default = defineComponent({
|
|
|
65
65
|
size: 0,
|
|
66
66
|
url: item,
|
|
67
67
|
previewUrl: item instanceof File ? URL.createObjectURL(item) : item,
|
|
68
|
-
key:
|
|
68
|
+
key: auid(),
|
|
69
69
|
percent: 0,
|
|
70
70
|
status: "unready",
|
|
71
71
|
controller: null
|
|
@@ -101,7 +101,7 @@ var stdin_default = defineComponent({
|
|
|
101
101
|
size: rawFile.size,
|
|
102
102
|
url: "",
|
|
103
103
|
previewUrl: URL.createObjectURL(rawFile),
|
|
104
|
-
key:
|
|
104
|
+
key: auid(),
|
|
105
105
|
status: "ready",
|
|
106
106
|
percent: 0,
|
|
107
107
|
controller: null
|
package/config/api.d.ts
CHANGED
package/config/api.js
CHANGED
package/config/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { type PersistConfig } from './persist';
|
|
|
8
8
|
import { type I18nConfig } from './i18n';
|
|
9
9
|
import { type RouteRecordRaw } from 'vue-router';
|
|
10
10
|
import { type CoseyRouterOptions } from '../router';
|
|
11
|
+
import { type UserInfo } from '../store';
|
|
11
12
|
export interface LayoutComponents {
|
|
12
13
|
base?: string | Component;
|
|
13
14
|
sidebar?: string | Component;
|
|
@@ -48,15 +49,18 @@ export interface LayoutSlots {
|
|
|
48
49
|
afterToggle?: () => VNodeChild;
|
|
49
50
|
}
|
|
50
51
|
type FilterRouteHandler = (route: RouteRecordRaw) => RouteRecordRaw | void | boolean | undefined | null;
|
|
51
|
-
type
|
|
52
|
+
type InitializeDataHandler = (handlers: {
|
|
53
|
+
setUserInfo: (userInfo: UserInfo) => void;
|
|
54
|
+
setRoutes: (route: RouteRecordRaw | RouteRecordRaw[]) => void;
|
|
55
|
+
}) => void | Promise<void>;
|
|
52
56
|
export type CoseyOptions = {
|
|
53
57
|
router?: CoseyRouterOptions & RouterConfig;
|
|
54
58
|
http?: HttpConfig;
|
|
55
59
|
layout?: LayoutConfig;
|
|
56
60
|
site?: SiteConfig;
|
|
57
61
|
api?: ApiConfig;
|
|
62
|
+
initializeData?: InitializeDataHandler;
|
|
58
63
|
filterRoute?: FilterRouteHandler;
|
|
59
|
-
defineAuthority?: DefineAuthorityHandler;
|
|
60
64
|
components?: LayoutComponents;
|
|
61
65
|
slots?: LayoutSlots;
|
|
62
66
|
persist?: PersistConfig;
|
|
@@ -68,8 +72,8 @@ export interface GlobalConfig {
|
|
|
68
72
|
layout: RequiredLayoutConfig;
|
|
69
73
|
site: RequiredSiteConfig;
|
|
70
74
|
api: RequiredApiConfig;
|
|
75
|
+
initializeData: NonNullable<CoseyOptions['initializeData']>;
|
|
71
76
|
filterRoute: NonNullable<CoseyOptions['filterRoute']>;
|
|
72
|
-
defineAuthority: NonNullable<CoseyOptions['defineAuthority']>;
|
|
73
77
|
components: NonNullable<CoseyOptions['components']>;
|
|
74
78
|
slots: NonNullable<CoseyOptions['slots']>;
|
|
75
79
|
}
|
package/config/index.js
CHANGED
|
@@ -17,8 +17,8 @@ function launchGlobalConfig(app, options) {
|
|
|
17
17
|
layout = {},
|
|
18
18
|
site = {},
|
|
19
19
|
api = {},
|
|
20
|
+
initializeData = () => void 0,
|
|
20
21
|
filterRoute = () => true,
|
|
21
|
-
defineAuthority = () => void 0,
|
|
22
22
|
components = {},
|
|
23
23
|
slots = {},
|
|
24
24
|
persist = {},
|
|
@@ -30,8 +30,8 @@ function launchGlobalConfig(app, options) {
|
|
|
30
30
|
layout: defaultsDeep(layout, defaultLayoutConfig),
|
|
31
31
|
site: defaultsDeep(site, defaultSiteConfig),
|
|
32
32
|
api: defaultsDeep(api, defaultApiConfig),
|
|
33
|
+
initializeData,
|
|
33
34
|
filterRoute,
|
|
34
|
-
defineAuthority,
|
|
35
35
|
components,
|
|
36
36
|
slots
|
|
37
37
|
};
|
package/hooks/useUpsert.js
CHANGED
|
@@ -3,7 +3,7 @@ import { cloneDeep, pick } from 'lodash-es';
|
|
|
3
3
|
import { ref, computed, unref, reactive, shallowRef, useTemplateRef, readonly, nextTick } from 'vue';
|
|
4
4
|
import { toRefs } from '@vueuse/core';
|
|
5
5
|
import { useLocale } from './useLocale.js';
|
|
6
|
-
import {
|
|
6
|
+
import { auid } from '../utils/string.js';
|
|
7
7
|
import { deepAssign } from '../utils/object.js';
|
|
8
8
|
|
|
9
9
|
const mapTypeTitle = {
|
|
@@ -50,7 +50,7 @@ function useUpsert(options) {
|
|
|
50
50
|
const row = shallowRef();
|
|
51
51
|
let addParams = [];
|
|
52
52
|
let editParams = [];
|
|
53
|
-
const formRefKey =
|
|
53
|
+
const formRefKey = auid();
|
|
54
54
|
const formRef = useTemplateRef(formRefKey);
|
|
55
55
|
const onSubmit = async () => {
|
|
56
56
|
let res;
|
|
@@ -46,7 +46,7 @@ var stdin_default = /* @__PURE__ */defineComponent({
|
|
|
46
46
|
lock: true,
|
|
47
47
|
text: t("co.auth.loggingOut")
|
|
48
48
|
});
|
|
49
|
-
userStore.logout().finally(() => {
|
|
49
|
+
userStore.logout(router.currentRoute.value.fullPath).finally(() => {
|
|
50
50
|
fullscreenLoading.value = false;
|
|
51
51
|
loading.close();
|
|
52
52
|
});
|
package/package.json
CHANGED
package/router/guard/auth.js
CHANGED
|
@@ -4,7 +4,6 @@ import { TOKEN_NAME, ROUTER_TO } from '../../constant.js';
|
|
|
4
4
|
import { persist } from '../../persist/index.js';
|
|
5
5
|
|
|
6
6
|
function registerAuthGuard(router) {
|
|
7
|
-
let firstTimeAddRoutes = false;
|
|
8
7
|
router.beforeEach(async (to) => {
|
|
9
8
|
const { router: routerConfig } = globalConfig;
|
|
10
9
|
const token = persist.get(TOKEN_NAME);
|
|
@@ -13,14 +12,11 @@ function registerAuthGuard(router) {
|
|
|
13
12
|
return routerConfig.homePath;
|
|
14
13
|
}
|
|
15
14
|
if (token) {
|
|
16
|
-
if (!userStore.
|
|
15
|
+
if (!userStore.initialized) {
|
|
17
16
|
try {
|
|
18
17
|
persist.set(ROUTER_TO, to.fullPath);
|
|
19
|
-
await userStore.
|
|
20
|
-
|
|
21
|
-
await userStore.addDynamicRoutes();
|
|
22
|
-
firstTimeAddRoutes = true;
|
|
23
|
-
userStore.requestedUserInfo = true;
|
|
18
|
+
await userStore.initializeData();
|
|
19
|
+
return to.fullPath;
|
|
24
20
|
} catch {
|
|
25
21
|
return false;
|
|
26
22
|
} finally {
|
|
@@ -30,21 +26,16 @@ function registerAuthGuard(router) {
|
|
|
30
26
|
if (to.path === routerConfig.loginPath) {
|
|
31
27
|
return routerConfig.homePath;
|
|
32
28
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return
|
|
29
|
+
} else {
|
|
30
|
+
if (to.meta.authentication) {
|
|
31
|
+
return {
|
|
32
|
+
path: routerConfig.loginPath,
|
|
33
|
+
query: {
|
|
34
|
+
redirect: to.path
|
|
35
|
+
}
|
|
36
|
+
};
|
|
36
37
|
}
|
|
37
|
-
return true;
|
|
38
38
|
}
|
|
39
|
-
if (!to.meta.authentication) {
|
|
40
|
-
return true;
|
|
41
|
-
}
|
|
42
|
-
return {
|
|
43
|
-
path: routerConfig.loginPath,
|
|
44
|
-
query: {
|
|
45
|
-
redirect: to.path
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
39
|
});
|
|
49
40
|
}
|
|
50
41
|
|
package/router/utils.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { auid } from '../utils/string.js';
|
|
2
2
|
|
|
3
3
|
function defineRoute(route) {
|
|
4
4
|
function recur(route2, index = 0, parent) {
|
|
5
5
|
const meta = route2.meta || {};
|
|
6
6
|
const newRoute = {
|
|
7
7
|
...route2,
|
|
8
|
-
name: route2.name ||
|
|
8
|
+
name: route2.name || auid(),
|
|
9
9
|
meta: {
|
|
10
10
|
...meta,
|
|
11
11
|
closable: meta.closable ?? true,
|
|
@@ -30,7 +30,7 @@ function defineRoutes(route) {
|
|
|
30
30
|
}
|
|
31
31
|
const mergeRouteModules = (modules) => {
|
|
32
32
|
return Object.keys(modules).reduce((result, key) => {
|
|
33
|
-
const module = modules[key].default;
|
|
33
|
+
const module = modules[key].default || [];
|
|
34
34
|
return result.concat(module);
|
|
35
35
|
}, []);
|
|
36
36
|
};
|
package/store/layout.d.ts
CHANGED
|
@@ -165,7 +165,7 @@ export declare const useLayoutStore: import("pinia").StoreDefinition<"cosey-layo
|
|
|
165
165
|
topbarHeight: import("vue").Ref<number, number>;
|
|
166
166
|
tabbarHeight: import("vue").Ref<number, number>;
|
|
167
167
|
headerHeight: import("vue").ComputedRef<number>;
|
|
168
|
-
}, "menus" | "keepAlive" | "
|
|
168
|
+
}, "menus" | "keepAlive" | "includeHorizontal" | "isVertical" | "isBiserial" | "isHorizontal" | "isHorizontalVertical" | "isHorizontalBiserial" | "menusMap" | "firstLevelMenus" | "secondLevelMenus" | "thirdLevelMenus" | "topMenus" | "snugMenus" | "snugActive" | "defaultMenus" | "iframeTabList" | "keepAliveExclude" | "sidebarWidth" | "headerHeight">, Pick<{
|
|
169
169
|
sidebarVisible: import("vue").Ref<boolean, boolean>;
|
|
170
170
|
collapse: import("vue").Ref<boolean, boolean>;
|
|
171
171
|
isMobile: import("vue").Ref<boolean, boolean>;
|
|
@@ -249,31 +249,25 @@ export declare const useLayoutStore: import("pinia").StoreDefinition<"cosey-layo
|
|
|
249
249
|
export declare const useOuterLayoutStore: (hot?: StoreGeneric) => import("pinia").Store<"cosey-user", Pick<{
|
|
250
250
|
dynamicRoutes: import("vue").ShallowRef<any[], any[]>;
|
|
251
251
|
userInfo: import("vue").Ref<import("./user").UserInfo | undefined, import("./user").UserInfo | undefined>;
|
|
252
|
-
|
|
252
|
+
initialized: import("vue").ComputedRef<boolean>;
|
|
253
253
|
login: (data: any) => Promise<void>;
|
|
254
|
-
|
|
254
|
+
initializeData: () => Promise<void>;
|
|
255
255
|
changePassword: (data: any) => Promise<void>;
|
|
256
|
-
setAuthorization: () => Promise<void>;
|
|
257
|
-
addDynamicRoutes: () => Promise<void>;
|
|
258
256
|
logout: (lastPath?: string) => Promise<void>;
|
|
259
|
-
}, "dynamicRoutes" | "userInfo"
|
|
257
|
+
}, "dynamicRoutes" | "userInfo">, Pick<{
|
|
260
258
|
dynamicRoutes: import("vue").ShallowRef<any[], any[]>;
|
|
261
259
|
userInfo: import("vue").Ref<import("./user").UserInfo | undefined, import("./user").UserInfo | undefined>;
|
|
262
|
-
|
|
260
|
+
initialized: import("vue").ComputedRef<boolean>;
|
|
263
261
|
login: (data: any) => Promise<void>;
|
|
264
|
-
|
|
262
|
+
initializeData: () => Promise<void>;
|
|
265
263
|
changePassword: (data: any) => Promise<void>;
|
|
266
|
-
setAuthorization: () => Promise<void>;
|
|
267
|
-
addDynamicRoutes: () => Promise<void>;
|
|
268
264
|
logout: (lastPath?: string) => Promise<void>;
|
|
269
|
-
},
|
|
265
|
+
}, "initialized">, Pick<{
|
|
270
266
|
dynamicRoutes: import("vue").ShallowRef<any[], any[]>;
|
|
271
267
|
userInfo: import("vue").Ref<import("./user").UserInfo | undefined, import("./user").UserInfo | undefined>;
|
|
272
|
-
|
|
268
|
+
initialized: import("vue").ComputedRef<boolean>;
|
|
273
269
|
login: (data: any) => Promise<void>;
|
|
274
|
-
|
|
270
|
+
initializeData: () => Promise<void>;
|
|
275
271
|
changePassword: (data: any) => Promise<void>;
|
|
276
|
-
setAuthorization: () => Promise<void>;
|
|
277
|
-
addDynamicRoutes: () => Promise<void>;
|
|
278
272
|
logout: (lastPath?: string) => Promise<void>;
|
|
279
|
-
}, "changePassword" | "login" | "logout" | "
|
|
273
|
+
}, "changePassword" | "login" | "logout" | "initializeData">>;
|
package/store/user.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { type StoreGeneric } from 'pinia';
|
|
2
2
|
export interface UserInfo {
|
|
3
|
-
id?: number;
|
|
4
|
-
username?: string;
|
|
5
3
|
nickname: string;
|
|
6
4
|
avatar: string;
|
|
7
5
|
[key: PropertyKey]: any;
|
|
@@ -9,62 +7,50 @@ export interface UserInfo {
|
|
|
9
7
|
export declare const useUserStore: import("pinia").StoreDefinition<"cosey-user", Pick<{
|
|
10
8
|
dynamicRoutes: import("vue").ShallowRef<any[], any[]>;
|
|
11
9
|
userInfo: import("vue").Ref<UserInfo | undefined, UserInfo | undefined>;
|
|
12
|
-
|
|
10
|
+
initialized: import("vue").ComputedRef<boolean>;
|
|
13
11
|
login: (data: any) => Promise<void>;
|
|
14
|
-
|
|
12
|
+
initializeData: () => Promise<void>;
|
|
15
13
|
changePassword: (data: any) => Promise<void>;
|
|
16
|
-
setAuthorization: () => Promise<void>;
|
|
17
|
-
addDynamicRoutes: () => Promise<void>;
|
|
18
14
|
logout: (lastPath?: string) => Promise<void>;
|
|
19
|
-
}, "dynamicRoutes" | "userInfo"
|
|
15
|
+
}, "dynamicRoutes" | "userInfo">, Pick<{
|
|
20
16
|
dynamicRoutes: import("vue").ShallowRef<any[], any[]>;
|
|
21
17
|
userInfo: import("vue").Ref<UserInfo | undefined, UserInfo | undefined>;
|
|
22
|
-
|
|
18
|
+
initialized: import("vue").ComputedRef<boolean>;
|
|
23
19
|
login: (data: any) => Promise<void>;
|
|
24
|
-
|
|
20
|
+
initializeData: () => Promise<void>;
|
|
25
21
|
changePassword: (data: any) => Promise<void>;
|
|
26
|
-
setAuthorization: () => Promise<void>;
|
|
27
|
-
addDynamicRoutes: () => Promise<void>;
|
|
28
22
|
logout: (lastPath?: string) => Promise<void>;
|
|
29
|
-
},
|
|
23
|
+
}, "initialized">, Pick<{
|
|
30
24
|
dynamicRoutes: import("vue").ShallowRef<any[], any[]>;
|
|
31
25
|
userInfo: import("vue").Ref<UserInfo | undefined, UserInfo | undefined>;
|
|
32
|
-
|
|
26
|
+
initialized: import("vue").ComputedRef<boolean>;
|
|
33
27
|
login: (data: any) => Promise<void>;
|
|
34
|
-
|
|
28
|
+
initializeData: () => Promise<void>;
|
|
35
29
|
changePassword: (data: any) => Promise<void>;
|
|
36
|
-
setAuthorization: () => Promise<void>;
|
|
37
|
-
addDynamicRoutes: () => Promise<void>;
|
|
38
30
|
logout: (lastPath?: string) => Promise<void>;
|
|
39
|
-
}, "changePassword" | "login" | "logout" | "
|
|
31
|
+
}, "changePassword" | "login" | "logout" | "initializeData">>;
|
|
40
32
|
export declare const useOuterUserStore: (hot?: StoreGeneric) => import("pinia").Store<"cosey-user", Pick<{
|
|
41
33
|
dynamicRoutes: import("vue").ShallowRef<any[], any[]>;
|
|
42
34
|
userInfo: import("vue").Ref<UserInfo | undefined, UserInfo | undefined>;
|
|
43
|
-
|
|
35
|
+
initialized: import("vue").ComputedRef<boolean>;
|
|
44
36
|
login: (data: any) => Promise<void>;
|
|
45
|
-
|
|
37
|
+
initializeData: () => Promise<void>;
|
|
46
38
|
changePassword: (data: any) => Promise<void>;
|
|
47
|
-
setAuthorization: () => Promise<void>;
|
|
48
|
-
addDynamicRoutes: () => Promise<void>;
|
|
49
39
|
logout: (lastPath?: string) => Promise<void>;
|
|
50
|
-
}, "dynamicRoutes" | "userInfo"
|
|
40
|
+
}, "dynamicRoutes" | "userInfo">, Pick<{
|
|
51
41
|
dynamicRoutes: import("vue").ShallowRef<any[], any[]>;
|
|
52
42
|
userInfo: import("vue").Ref<UserInfo | undefined, UserInfo | undefined>;
|
|
53
|
-
|
|
43
|
+
initialized: import("vue").ComputedRef<boolean>;
|
|
54
44
|
login: (data: any) => Promise<void>;
|
|
55
|
-
|
|
45
|
+
initializeData: () => Promise<void>;
|
|
56
46
|
changePassword: (data: any) => Promise<void>;
|
|
57
|
-
setAuthorization: () => Promise<void>;
|
|
58
|
-
addDynamicRoutes: () => Promise<void>;
|
|
59
47
|
logout: (lastPath?: string) => Promise<void>;
|
|
60
|
-
},
|
|
48
|
+
}, "initialized">, Pick<{
|
|
61
49
|
dynamicRoutes: import("vue").ShallowRef<any[], any[]>;
|
|
62
50
|
userInfo: import("vue").Ref<UserInfo | undefined, UserInfo | undefined>;
|
|
63
|
-
|
|
51
|
+
initialized: import("vue").ComputedRef<boolean>;
|
|
64
52
|
login: (data: any) => Promise<void>;
|
|
65
|
-
|
|
53
|
+
initializeData: () => Promise<void>;
|
|
66
54
|
changePassword: (data: any) => Promise<void>;
|
|
67
|
-
setAuthorization: () => Promise<void>;
|
|
68
|
-
addDynamicRoutes: () => Promise<void>;
|
|
69
55
|
logout: (lastPath?: string) => Promise<void>;
|
|
70
|
-
}, "changePassword" | "login" | "logout" | "
|
|
56
|
+
}, "changePassword" | "login" | "logout" | "initializeData">>;
|
package/store/user.js
CHANGED
|
@@ -1,54 +1,37 @@
|
|
|
1
|
-
import { shallowRef, ref } from 'vue';
|
|
1
|
+
import { shallowRef, ref, computed } from 'vue';
|
|
2
2
|
import { defineStore } from 'pinia';
|
|
3
|
-
import {
|
|
3
|
+
import { router, getAllDynamicRoutes } from '../router/index.js';
|
|
4
4
|
import { TOKEN_NAME } from '../constant.js';
|
|
5
5
|
import { NOT_FOUND_ROUTE_NAME, NotFoundRoute } from '../router/not-found.js';
|
|
6
6
|
import { persist } from '../persist/index.js';
|
|
7
7
|
import { pinia } from './pinia.js';
|
|
8
8
|
import { globalConfig } from '../config/index.js';
|
|
9
|
+
import { defineRoutes } from '../router/utils.js';
|
|
9
10
|
import { warningOnce } from '../utils/warning.js';
|
|
10
11
|
|
|
11
12
|
const useUserStore = defineStore("cosey-user", () => {
|
|
12
|
-
const {
|
|
13
|
+
const {
|
|
14
|
+
router: routerConfig,
|
|
15
|
+
api: apiConfig,
|
|
16
|
+
filterRoute,
|
|
17
|
+
initializeData: _initializeData
|
|
18
|
+
} = globalConfig;
|
|
13
19
|
if (!apiConfig?.login) {
|
|
14
20
|
warningOnce(!!apiConfig?.login, 'The "login" api is required.');
|
|
15
21
|
}
|
|
16
|
-
if (!apiConfig?.getUserInfo) {
|
|
17
|
-
warningOnce(!!apiConfig?.getUserInfo, 'The "getUserInfo" api is required.');
|
|
18
|
-
}
|
|
19
22
|
const loginApi = apiConfig?.login;
|
|
20
|
-
const getUserInfoApi = apiConfig?.getUserInfo;
|
|
21
23
|
const changePasswordApi = apiConfig?.changePassword;
|
|
22
24
|
const logoutApi = apiConfig?.logout;
|
|
23
25
|
const dynamicRoutes = shallowRef([]);
|
|
26
|
+
const remoteDynamicRoutes = shallowRef([]);
|
|
24
27
|
const userInfo = ref();
|
|
25
|
-
const
|
|
28
|
+
const initialized = ref(false);
|
|
26
29
|
const login = async (data) => {
|
|
27
30
|
await loginApi?.(data).then((token) => {
|
|
28
31
|
persist.set(TOKEN_NAME, token);
|
|
29
32
|
router.push(router.currentRoute.value.query.redirect || routerConfig.homePath);
|
|
30
33
|
});
|
|
31
34
|
};
|
|
32
|
-
const getUserInfo = async () => {
|
|
33
|
-
return getUserInfoApi?.().then((res) => {
|
|
34
|
-
const nickname = res.nickname;
|
|
35
|
-
const avatar = res.avatar;
|
|
36
|
-
userInfo.value = {
|
|
37
|
-
...res,
|
|
38
|
-
nickname,
|
|
39
|
-
avatar
|
|
40
|
-
};
|
|
41
|
-
return userInfo.value;
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
const changePassword = async (data) => {
|
|
45
|
-
await changePasswordApi?.(data).then(() => {
|
|
46
|
-
router.back();
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
const setAuthorization = async () => {
|
|
50
|
-
return defineAuthority(userInfo.value);
|
|
51
|
-
};
|
|
52
35
|
const mapRoute = (routes) => {
|
|
53
36
|
return routes.map((route) => {
|
|
54
37
|
const result = filterRoute(route);
|
|
@@ -63,7 +46,7 @@ const useUserStore = defineStore("cosey-user", () => {
|
|
|
63
46
|
return mapRoute(routes);
|
|
64
47
|
};
|
|
65
48
|
const addDynamicRoutes = async () => {
|
|
66
|
-
const filteredRoutes = filterRoutes(getAllDynamicRoutes());
|
|
49
|
+
const filteredRoutes = filterRoutes([...getAllDynamicRoutes(), ...remoteDynamicRoutes.value]);
|
|
67
50
|
router.removeRoute(NOT_FOUND_ROUTE_NAME);
|
|
68
51
|
filteredRoutes.forEach((route) => {
|
|
69
52
|
router.addRoute(route);
|
|
@@ -71,20 +54,42 @@ const useUserStore = defineStore("cosey-user", () => {
|
|
|
71
54
|
router.addRoute("Exception", NotFoundRoute);
|
|
72
55
|
dynamicRoutes.value = filteredRoutes;
|
|
73
56
|
};
|
|
57
|
+
const initializeData = async () => {
|
|
58
|
+
const setUserInfo = (_userInfo) => {
|
|
59
|
+
userInfo.value = _userInfo;
|
|
60
|
+
};
|
|
61
|
+
const setRoutes = (route) => {
|
|
62
|
+
remoteDynamicRoutes.value = defineRoutes(route);
|
|
63
|
+
};
|
|
64
|
+
if (!initialized.value) {
|
|
65
|
+
await _initializeData({
|
|
66
|
+
setUserInfo,
|
|
67
|
+
setRoutes
|
|
68
|
+
});
|
|
69
|
+
await addDynamicRoutes();
|
|
70
|
+
initialized.value = true;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
const changePassword = async (data) => {
|
|
74
|
+
await changePasswordApi?.(data).then(() => {
|
|
75
|
+
router.back();
|
|
76
|
+
});
|
|
77
|
+
};
|
|
74
78
|
const flush = async (lastPath) => {
|
|
75
79
|
persist.remove(TOKEN_NAME);
|
|
76
80
|
userInfo.value = void 0;
|
|
77
|
-
|
|
81
|
+
dynamicRoutes.value.forEach((route) => {
|
|
82
|
+
router.removeRoute(route.name);
|
|
83
|
+
});
|
|
84
|
+
dynamicRoutes.value = [];
|
|
85
|
+
remoteDynamicRoutes.value = [];
|
|
86
|
+
initialized.value = false;
|
|
78
87
|
await router.push({
|
|
79
88
|
path: routerConfig.loginPath,
|
|
80
89
|
query: {
|
|
81
90
|
redirect: lastPath
|
|
82
91
|
}
|
|
83
92
|
});
|
|
84
|
-
dynamicRoutes.value.forEach((route) => {
|
|
85
|
-
router.removeRoute(route.name);
|
|
86
|
-
});
|
|
87
|
-
dynamicRoutes.value = [];
|
|
88
93
|
};
|
|
89
94
|
const logout = async (lastPath) => {
|
|
90
95
|
await logoutApi?.();
|
|
@@ -93,12 +98,10 @@ const useUserStore = defineStore("cosey-user", () => {
|
|
|
93
98
|
return {
|
|
94
99
|
dynamicRoutes,
|
|
95
100
|
userInfo,
|
|
96
|
-
|
|
101
|
+
initialized: computed(() => initialized.value),
|
|
97
102
|
login,
|
|
98
|
-
|
|
103
|
+
initializeData,
|
|
99
104
|
changePassword,
|
|
100
|
-
setAuthorization,
|
|
101
|
-
addDynamicRoutes,
|
|
102
105
|
logout
|
|
103
106
|
};
|
|
104
107
|
});
|
package/utils/index.js
CHANGED
|
@@ -10,7 +10,7 @@ export { isBoolean, isEmpty, isFunction, isNullish, isNumber, isObject, isPlainO
|
|
|
10
10
|
export { minmax } from './number.js';
|
|
11
11
|
export { deepAssign, initObject, omitObject, omitUndefined, uniformAssign } from './object.js';
|
|
12
12
|
export { getBasename, getExtname } from './path.js';
|
|
13
|
-
export {
|
|
13
|
+
export { auid } from './string.js';
|
|
14
14
|
export { Scope, addNullablePlaceholder, bulkBindEvents, createMergedExpose, defineTemplate, getVNodeText } from './vue.js';
|
|
15
15
|
export { note, noteOnce, resetWarned, warning, warningOnce } from './warning.js';
|
|
16
16
|
export { findCSSNode, insertCSS, removeCSS, updateCSS, updateCSSByStyle } from './dynamicCSS.js';
|
package/utils/string.d.ts
CHANGED
package/utils/string.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
function uniqid(prefix = "co-") {
|
|
5
|
-
return prefix + uuid();
|
|
1
|
+
let counter = 0;
|
|
2
|
+
function auid(prefix = "__co_") {
|
|
3
|
+
return prefix + (~~(Math.random() * 1e9)).toString(36) + "-" + (++counter).toString(36);
|
|
6
4
|
}
|
|
7
5
|
|
|
8
|
-
export {
|
|
6
|
+
export { auid };
|