@sys-designer/create-vue 1.0.0
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/README.md +52 -0
- package/cli.mjs +133 -0
- package/package.json +26 -0
- package/template/.env.development +13 -0
- package/template/.env.electron +13 -0
- package/template/.env.production +11 -0
- package/template/.eslintrc-auto-import.json +96 -0
- package/template/README.md +2 -0
- package/template/_gitignore +32 -0
- package/template/build/proxy.ts +34 -0
- package/template/build/utils.ts +71 -0
- package/template/common/routes.ts +7 -0
- package/template/index.css +10 -0
- package/template/index.html +23 -0
- package/template/package.json +51 -0
- package/template/public/favicon.ico +0 -0
- package/template/src/App.vue +18 -0
- package/template/src/assets/styles/reset.scss +0 -0
- package/template/src/assets/styles/vars.scss +0 -0
- package/template/src/env.d.ts +5 -0
- package/template/src/main.ts +13 -0
- package/template/src/router/index.ts +44 -0
- package/template/src/store/global.ts +60 -0
- package/template/src/store/index.ts +9 -0
- package/template/src/store/user.ts +61 -0
- package/template/src/types/auto-imports.d.ts +93 -0
- package/template/src/types/components.d.ts +22 -0
- package/template/src/utils/crypto.ts +160 -0
- package/template/src/utils/dsl.ts +101 -0
- package/template/src/utils/index.ts +30 -0
- package/template/src/utils/is.ts +122 -0
- package/template/src/utils/request.ts +51 -0
- package/template/src/views/index.vue +23 -0
- package/template/src/vite-env.d.ts +31 -0
- package/template/tsconfig.json +37 -0
- package/template/tsconfig.node.json +20 -0
- package/template/vite.config.ts +99 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { defineStore } from 'pinia';
|
|
2
|
+
|
|
3
|
+
const PLUGIN_BASE_URL = import.meta.env.VITE_PLUGIN_BASE_URL || '/plugins';
|
|
4
|
+
|
|
5
|
+
export interface PageInfo {
|
|
6
|
+
title?: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface MenuItem {
|
|
10
|
+
name: string
|
|
11
|
+
id: string
|
|
12
|
+
key: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const useGlobal = defineStore('global', {
|
|
16
|
+
state: () => {
|
|
17
|
+
return {
|
|
18
|
+
data: {
|
|
19
|
+
projectId: '',
|
|
20
|
+
query: {} as any,
|
|
21
|
+
params: {} as any,
|
|
22
|
+
routerName: '' as string,
|
|
23
|
+
pluginBaseUrl: PLUGIN_BASE_URL as string,
|
|
24
|
+
page: {} as PageInfo,
|
|
25
|
+
securityKey: '' as string,
|
|
26
|
+
menu: {
|
|
27
|
+
name: ''
|
|
28
|
+
} as MenuItem
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
getters: {
|
|
33
|
+
projectId: state => state.data.projectId,
|
|
34
|
+
query: state => state.data.query,
|
|
35
|
+
params: state => state.data.params,
|
|
36
|
+
pluginBaseUrl: state => state.data.pluginBaseUrl,
|
|
37
|
+
routerName: state => state.data.routerName,
|
|
38
|
+
securityKey: state => state.data.securityKey,
|
|
39
|
+
},
|
|
40
|
+
actions: {
|
|
41
|
+
getProjectId() {
|
|
42
|
+
return this.data.projectId;
|
|
43
|
+
},
|
|
44
|
+
setProjectId(projectId: string) {
|
|
45
|
+
this.data.projectId = projectId;
|
|
46
|
+
},
|
|
47
|
+
setSecurityKey(key: string) {
|
|
48
|
+
this.data.securityKey = key;
|
|
49
|
+
},
|
|
50
|
+
setQuery(query: any) {
|
|
51
|
+
this.data.query = query || {};
|
|
52
|
+
},
|
|
53
|
+
setParams(params: any) {
|
|
54
|
+
this.data.params = params || {};
|
|
55
|
+
},
|
|
56
|
+
setRouterName(name: string) {
|
|
57
|
+
this.data.routerName = name;
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { defineStore } from 'pinia';
|
|
2
|
+
export interface UserInfo {
|
|
3
|
+
userId: number;
|
|
4
|
+
username: string;
|
|
5
|
+
nickname?: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const useUser = defineStore('user',{
|
|
9
|
+
persist: {
|
|
10
|
+
storage: localStorage,
|
|
11
|
+
},
|
|
12
|
+
state: () => {
|
|
13
|
+
return {
|
|
14
|
+
data: {
|
|
15
|
+
token: '',
|
|
16
|
+
userInfo: {
|
|
17
|
+
userId: null,
|
|
18
|
+
username: '',
|
|
19
|
+
} as unknown as UserInfo,
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
getters: {
|
|
24
|
+
userId: (state) => state.data.userInfo.userId,
|
|
25
|
+
username: (state) => state.data.userInfo.username,
|
|
26
|
+
},
|
|
27
|
+
actions: {
|
|
28
|
+
isLogin(){
|
|
29
|
+
if(!this.getToken()){
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
return this.userId ? true : false;
|
|
33
|
+
},
|
|
34
|
+
getUserInfo() {
|
|
35
|
+
return this.data.userInfo;
|
|
36
|
+
},
|
|
37
|
+
getUserId() {
|
|
38
|
+
if(!this.isLogin()){
|
|
39
|
+
return '';
|
|
40
|
+
}
|
|
41
|
+
return this.data.userInfo.userId;
|
|
42
|
+
},
|
|
43
|
+
getToken() {
|
|
44
|
+
return this.data.token;
|
|
45
|
+
},
|
|
46
|
+
setToken(token: string) {
|
|
47
|
+
this.data.token = token;
|
|
48
|
+
},
|
|
49
|
+
setUserInfo(userInfo: UserInfo) {
|
|
50
|
+
return this.data.userInfo = userInfo;
|
|
51
|
+
},
|
|
52
|
+
async logout() {
|
|
53
|
+
this.data.token = '';
|
|
54
|
+
this.data.userInfo.userId = null as any;
|
|
55
|
+
this.data.userInfo.nickname = '';
|
|
56
|
+
this.data.userInfo.username = '';
|
|
57
|
+
},
|
|
58
|
+
async refreshPermission(): Promise<void> {
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/* prettier-ignore */
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
// noinspection JSUnusedGlobalSymbols
|
|
5
|
+
// Generated by unplugin-auto-import
|
|
6
|
+
// biome-ignore lint: disable
|
|
7
|
+
export {}
|
|
8
|
+
declare global {
|
|
9
|
+
const EffectScope: typeof import('vue')['EffectScope']
|
|
10
|
+
const acceptHMRUpdate: typeof import('pinia')['acceptHMRUpdate']
|
|
11
|
+
const computed: typeof import('vue')['computed']
|
|
12
|
+
const createApp: typeof import('vue')['createApp']
|
|
13
|
+
const createPinia: typeof import('pinia')['createPinia']
|
|
14
|
+
const customRef: typeof import('vue')['customRef']
|
|
15
|
+
const defineAsyncComponent: typeof import('vue')['defineAsyncComponent']
|
|
16
|
+
const defineComponent: typeof import('vue')['defineComponent']
|
|
17
|
+
const defineStore: typeof import('pinia')['defineStore']
|
|
18
|
+
const effectScope: typeof import('vue')['effectScope']
|
|
19
|
+
const getActivePinia: typeof import('pinia')['getActivePinia']
|
|
20
|
+
const getCurrentInstance: typeof import('vue')['getCurrentInstance']
|
|
21
|
+
const getCurrentScope: typeof import('vue')['getCurrentScope']
|
|
22
|
+
const h: typeof import('vue')['h']
|
|
23
|
+
const inject: typeof import('vue')['inject']
|
|
24
|
+
const isProxy: typeof import('vue')['isProxy']
|
|
25
|
+
const isReactive: typeof import('vue')['isReactive']
|
|
26
|
+
const isReadonly: typeof import('vue')['isReadonly']
|
|
27
|
+
const isRef: typeof import('vue')['isRef']
|
|
28
|
+
const mapActions: typeof import('pinia')['mapActions']
|
|
29
|
+
const mapGetters: typeof import('pinia')['mapGetters']
|
|
30
|
+
const mapState: typeof import('pinia')['mapState']
|
|
31
|
+
const mapStores: typeof import('pinia')['mapStores']
|
|
32
|
+
const mapWritableState: typeof import('pinia')['mapWritableState']
|
|
33
|
+
const markRaw: typeof import('vue')['markRaw']
|
|
34
|
+
const nextTick: typeof import('vue')['nextTick']
|
|
35
|
+
const onActivated: typeof import('vue')['onActivated']
|
|
36
|
+
const onBeforeMount: typeof import('vue')['onBeforeMount']
|
|
37
|
+
const onBeforeRouteLeave: typeof import('vue-router')['onBeforeRouteLeave']
|
|
38
|
+
const onBeforeRouteUpdate: typeof import('vue-router')['onBeforeRouteUpdate']
|
|
39
|
+
const onBeforeUnmount: typeof import('vue')['onBeforeUnmount']
|
|
40
|
+
const onBeforeUpdate: typeof import('vue')['onBeforeUpdate']
|
|
41
|
+
const onDeactivated: typeof import('vue')['onDeactivated']
|
|
42
|
+
const onErrorCaptured: typeof import('vue')['onErrorCaptured']
|
|
43
|
+
const onMounted: typeof import('vue')['onMounted']
|
|
44
|
+
const onRenderTracked: typeof import('vue')['onRenderTracked']
|
|
45
|
+
const onRenderTriggered: typeof import('vue')['onRenderTriggered']
|
|
46
|
+
const onScopeDispose: typeof import('vue')['onScopeDispose']
|
|
47
|
+
const onServerPrefetch: typeof import('vue')['onServerPrefetch']
|
|
48
|
+
const onUnmounted: typeof import('vue')['onUnmounted']
|
|
49
|
+
const onUpdated: typeof import('vue')['onUpdated']
|
|
50
|
+
const onWatcherCleanup: typeof import('vue')['onWatcherCleanup']
|
|
51
|
+
const provide: typeof import('vue')['provide']
|
|
52
|
+
const reactive: typeof import('vue')['reactive']
|
|
53
|
+
const readonly: typeof import('vue')['readonly']
|
|
54
|
+
const ref: typeof import('vue')['ref']
|
|
55
|
+
const resolveComponent: typeof import('vue')['resolveComponent']
|
|
56
|
+
const setActivePinia: typeof import('pinia')['setActivePinia']
|
|
57
|
+
const setMapStoreSuffix: typeof import('pinia')['setMapStoreSuffix']
|
|
58
|
+
const shallowReactive: typeof import('vue')['shallowReactive']
|
|
59
|
+
const shallowReadonly: typeof import('vue')['shallowReadonly']
|
|
60
|
+
const shallowRef: typeof import('vue')['shallowRef']
|
|
61
|
+
const storeToRefs: typeof import('pinia')['storeToRefs']
|
|
62
|
+
const toRaw: typeof import('vue')['toRaw']
|
|
63
|
+
const toRef: typeof import('vue')['toRef']
|
|
64
|
+
const toRefs: typeof import('vue')['toRefs']
|
|
65
|
+
const toValue: typeof import('vue')['toValue']
|
|
66
|
+
const triggerRef: typeof import('vue')['triggerRef']
|
|
67
|
+
const unref: typeof import('vue')['unref']
|
|
68
|
+
const useAttrs: typeof import('vue')['useAttrs']
|
|
69
|
+
const useCssModule: typeof import('vue')['useCssModule']
|
|
70
|
+
const useCssVars: typeof import('vue')['useCssVars']
|
|
71
|
+
const useDialog: typeof import('naive-ui')['useDialog']
|
|
72
|
+
const useId: typeof import('vue')['useId']
|
|
73
|
+
const useLink: typeof import('vue-router')['useLink']
|
|
74
|
+
const useLoadingBar: typeof import('naive-ui')['useLoadingBar']
|
|
75
|
+
const useMessage: typeof import('naive-ui')['useMessage']
|
|
76
|
+
const useModal: typeof import('naive-ui')['useModal']
|
|
77
|
+
const useModel: typeof import('vue')['useModel']
|
|
78
|
+
const useNotification: typeof import('naive-ui')['useNotification']
|
|
79
|
+
const useRoute: typeof import('vue-router')['useRoute']
|
|
80
|
+
const useRouter: typeof import('vue-router')['useRouter']
|
|
81
|
+
const useSlots: typeof import('vue')['useSlots']
|
|
82
|
+
const useTemplateRef: typeof import('vue')['useTemplateRef']
|
|
83
|
+
const watch: typeof import('vue')['watch']
|
|
84
|
+
const watchEffect: typeof import('vue')['watchEffect']
|
|
85
|
+
const watchPostEffect: typeof import('vue')['watchPostEffect']
|
|
86
|
+
const watchSyncEffect: typeof import('vue')['watchSyncEffect']
|
|
87
|
+
}
|
|
88
|
+
// for type re-export
|
|
89
|
+
declare global {
|
|
90
|
+
// @ts-ignore
|
|
91
|
+
export type { Component, ComponentPublicInstance, ComputedRef, DirectiveBinding, ExtractDefaultPropTypes, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, MaybeRef, MaybeRefOrGetter, VNode, WritableComputedRef } from 'vue'
|
|
92
|
+
import('vue')
|
|
93
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
// Generated by unplugin-vue-components
|
|
4
|
+
// Read more: https://github.com/vuejs/core/pull/3399
|
|
5
|
+
export {}
|
|
6
|
+
|
|
7
|
+
/* prettier-ignore */
|
|
8
|
+
declare module 'vue' {
|
|
9
|
+
export interface GlobalComponents {
|
|
10
|
+
NButton: typeof import('naive-ui')['NButton']
|
|
11
|
+
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
|
|
12
|
+
NDialogProvider: typeof import('naive-ui')['NDialogProvider']
|
|
13
|
+
NInput: typeof import('naive-ui')['NInput']
|
|
14
|
+
NLoadingBarProvider: typeof import('naive-ui')['NLoadingBarProvider']
|
|
15
|
+
NMessageProvider: typeof import('naive-ui')['NMessageProvider']
|
|
16
|
+
NNotificationProvider: typeof import('naive-ui')['NNotificationProvider']
|
|
17
|
+
NSelect: typeof import('naive-ui')['NSelect']
|
|
18
|
+
NSpace: typeof import('naive-ui')['NSpace']
|
|
19
|
+
RouterLink: typeof import('vue-router')['RouterLink']
|
|
20
|
+
RouterView: typeof import('vue-router')['RouterView']
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import CryptoJS from 'crypto-js';
|
|
2
|
+
import forge from 'node-forge';
|
|
3
|
+
export interface CryptoKey {
|
|
4
|
+
key: string;
|
|
5
|
+
iv: string;
|
|
6
|
+
length?: number;
|
|
7
|
+
encryptKey?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface EncryptData {
|
|
11
|
+
data: string;
|
|
12
|
+
key: string;
|
|
13
|
+
rawData?: Record<string, any>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface DecryptData {
|
|
17
|
+
data: string;
|
|
18
|
+
key: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface LoadPrivateKeyFunction {
|
|
22
|
+
(key: string): Promise<string>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export class CryptoData {
|
|
26
|
+
private privateKey: string = '';
|
|
27
|
+
private publicKey: string = '';
|
|
28
|
+
private cryptoKey?: CryptoKey;
|
|
29
|
+
|
|
30
|
+
private generatorKey(length = 16): string {
|
|
31
|
+
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
32
|
+
let list: string[] = [];
|
|
33
|
+
for (let i = 0; i < length; i++) {
|
|
34
|
+
const ch = chars.charAt(Math.floor(Math.random() * chars.length));
|
|
35
|
+
list.push(ch);
|
|
36
|
+
}
|
|
37
|
+
return list.join('');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
private generatorIv() {
|
|
41
|
+
const chars = '0123456789abcdef';
|
|
42
|
+
let list: string[] = [];
|
|
43
|
+
for (let i = 0; i < 16; i++) {
|
|
44
|
+
const ch = chars.charAt(Math.floor(Math.random() * chars.length));
|
|
45
|
+
list.push(ch);
|
|
46
|
+
}
|
|
47
|
+
return list.join('');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public getKey(): CryptoKey {
|
|
51
|
+
this.cryptoKey = {
|
|
52
|
+
key: this.generatorKey(),
|
|
53
|
+
iv: this.generatorIv(),
|
|
54
|
+
length: 16,
|
|
55
|
+
}
|
|
56
|
+
return this.cryptoKey;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public setKey(key: CryptoKey): void {
|
|
60
|
+
this.cryptoKey = key;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public getPublicKey(): string {
|
|
64
|
+
return this.publicKey;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public getPrivateKey(): string {
|
|
68
|
+
return this.privateKey;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public setPublicKey(key: string): void {
|
|
72
|
+
this.publicKey = key;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public setPrivateKey(key: string): void {
|
|
76
|
+
this.privateKey = key;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
public async enryptByPublicKey(input: string): Promise<string> {
|
|
80
|
+
return rsaEncrypt(input, this.getPublicKey());
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
public encryptByKey(rawData: any, key?: CryptoKey): string {
|
|
85
|
+
if (!key) {
|
|
86
|
+
key = this.getKey();
|
|
87
|
+
}
|
|
88
|
+
const text = typeof rawData !== 'string' ? JSON.stringify(rawData) : rawData;
|
|
89
|
+
const dataStr = String(text);
|
|
90
|
+
const keyBytes = this.padKey(key.key);
|
|
91
|
+
const ivBytes = CryptoJS.enc.Utf8.parse(key.iv);
|
|
92
|
+
|
|
93
|
+
const encrypted = CryptoJS.AES.encrypt(dataStr, keyBytes, {
|
|
94
|
+
iv: ivBytes,
|
|
95
|
+
mode: CryptoJS.mode.CBC,
|
|
96
|
+
padding: CryptoJS.pad.Pkcs7,
|
|
97
|
+
});
|
|
98
|
+
const data = encrypted.toString();
|
|
99
|
+
return data;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public async encrypt(rawData: any): Promise<EncryptData> {
|
|
103
|
+
const key = this.getKey();
|
|
104
|
+
if (!key.encryptKey) {
|
|
105
|
+
key.encryptKey = await rsaEncrypt(key.iv + ':' + key.key, this.getPublicKey());
|
|
106
|
+
}
|
|
107
|
+
const data = rawData ? this.encryptByKey(rawData, key) : '';
|
|
108
|
+
return {
|
|
109
|
+
data: data,
|
|
110
|
+
key: key.encryptKey,
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
private padKey(key: string) {
|
|
115
|
+
const keyStr = String(key);
|
|
116
|
+
if (keyStr.length === 16) {
|
|
117
|
+
return CryptoJS.enc.Utf8.parse(keyStr);
|
|
118
|
+
}
|
|
119
|
+
if (keyStr.length < 16) {
|
|
120
|
+
return CryptoJS.enc.Utf8.parse(keyStr.padEnd(16, '0'));
|
|
121
|
+
}
|
|
122
|
+
return CryptoJS.enc.Utf8.parse(keyStr.substring(0, 16));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
public decryptByKey(data: string, key?: CryptoKey): string {
|
|
126
|
+
if (!key) {
|
|
127
|
+
key = this.getKey();
|
|
128
|
+
}
|
|
129
|
+
const keyBytes = this.padKey(key.key);
|
|
130
|
+
const ivBytes = CryptoJS.enc.Utf8.parse(key.iv);
|
|
131
|
+
const decrypted = CryptoJS.AES.decrypt(data, keyBytes, {
|
|
132
|
+
iv: ivBytes,
|
|
133
|
+
mode: CryptoJS.mode.CBC,
|
|
134
|
+
padding: CryptoJS.pad.Pkcs7,
|
|
135
|
+
});
|
|
136
|
+
const str = decrypted.toString(CryptoJS.enc.Utf8);
|
|
137
|
+
return str;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export const CRYPTO = new CryptoData();
|
|
142
|
+
|
|
143
|
+
function toPemPublicKey(rawKey: string): string {
|
|
144
|
+
return `-----BEGIN PUBLIC KEY-----
|
|
145
|
+
${rawKey}
|
|
146
|
+
-----END PUBLIC KEY-----`
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
async function rsaEncrypt(str: string, key: string) {
|
|
150
|
+
const publicKey = forge.pki.publicKeyFromPem(toPemPublicKey(key));
|
|
151
|
+
const encrypted = publicKey.encrypt(
|
|
152
|
+
forge.util.encodeUtf8(str),
|
|
153
|
+
'RSA-OAEP',
|
|
154
|
+
{
|
|
155
|
+
md: forge.md.sha256.create(),
|
|
156
|
+
mgf1: { md: forge.md.sha256.create() }
|
|
157
|
+
}
|
|
158
|
+
);
|
|
159
|
+
return forge.util.encode64(encrypted);
|
|
160
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { isObject } from './is'
|
|
2
|
+
export function buildDsl(method: string, args: Array<string | object>, fields: Array<string | object>): string {
|
|
3
|
+
return `${method}${buildDslArgs(args)}${buildDslFields(fields)}`
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export function buildDslForList(argsList: Array<any>, cb: Function, key?: string) {
|
|
7
|
+
const querys = {} as any
|
|
8
|
+
argsList.forEach((it, index) => {
|
|
9
|
+
querys['_' + (key ? key + '_' : '') + index] = cb(it)
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
return querys
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function resolveQueryResult(data: any, cb?: Function) {
|
|
16
|
+
if (!data || Array.isArray(data)) {
|
|
17
|
+
return data
|
|
18
|
+
}
|
|
19
|
+
const result = {} as any
|
|
20
|
+
Object.keys(data).map(key => {
|
|
21
|
+
if (key.startsWith('_')) {
|
|
22
|
+
const strs = key.split('_')
|
|
23
|
+
const field = strs.length == 2 ? 'data' : strs[1]
|
|
24
|
+
if (!result[field]) {
|
|
25
|
+
result[field] = []
|
|
26
|
+
}
|
|
27
|
+
result[field] = result[field].concat(data[key])
|
|
28
|
+
} else {
|
|
29
|
+
if (result[key]) {
|
|
30
|
+
result[key] = result[key].concat(data[key])
|
|
31
|
+
} else {
|
|
32
|
+
result[key] = data[key]
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
return cb ? cb(result) : result
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
function buildDslArgs(args: Array<any>): string {
|
|
41
|
+
const strs = [] as Array<string>
|
|
42
|
+
if (args && args.length > 0) {
|
|
43
|
+
args.forEach(e => {
|
|
44
|
+
const key = e.key
|
|
45
|
+
const value = e.value
|
|
46
|
+
if (isObject(value)) {
|
|
47
|
+
let str = key + ':{'
|
|
48
|
+
const keys = Object.keys(value)
|
|
49
|
+
keys.forEach((vk, _k) => {
|
|
50
|
+
let v = value[vk]
|
|
51
|
+
if(Array.isArray(v)){
|
|
52
|
+
v = '['+v.join(',')+']';
|
|
53
|
+
str = str+vk+':'+v+',';
|
|
54
|
+
}else if (v || v === 0 || v === false) {
|
|
55
|
+
str = str + vk + ':' + (typeof v === 'string' ? `"${v}"` : v)
|
|
56
|
+
str = str + ','
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
if (str.endsWith(',')) {
|
|
60
|
+
str = str.substring(0, str.length - 1)
|
|
61
|
+
}
|
|
62
|
+
strs.push(str + '}')
|
|
63
|
+
} else {
|
|
64
|
+
let val = typeof value === 'string' ? `"${value}"` : value
|
|
65
|
+
if(Array.isArray(value)){
|
|
66
|
+
val = '['+value.join(',')+']';
|
|
67
|
+
}
|
|
68
|
+
if(val===undefined || val===null){
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
strs.push(`${key}:${val}`)
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
if (strs.length > 0) {
|
|
76
|
+
return `(${strs.join(',')})`
|
|
77
|
+
}
|
|
78
|
+
return ''
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function buildDslFields(fields: Array<string | object>): string {
|
|
82
|
+
const list = [] as any
|
|
83
|
+
buildDslField(list, fields)
|
|
84
|
+
return `{${list.join(',')}}`
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function buildDslField(list: Array<any>, fields: Array<string | object>) {
|
|
88
|
+
if (fields && fields.length > 0) {
|
|
89
|
+
fields.forEach(e => {
|
|
90
|
+
if (typeof e === 'string') {
|
|
91
|
+
list.push(e)
|
|
92
|
+
} else {
|
|
93
|
+
Object.keys(e).forEach(field => {
|
|
94
|
+
const tempList: string[] = []
|
|
95
|
+
buildDslField(tempList, (e as any)[field])
|
|
96
|
+
list.push(`${field}{${tempList.join(',')}}`)
|
|
97
|
+
})
|
|
98
|
+
}
|
|
99
|
+
})
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const baseUrl = import.meta.env.VITE_GLOB_API_URL || '';
|
|
2
|
+
const queryUrl = baseUrl + (import.meta.env.VITE_GLOB_API_PATH || '/graphql/query');
|
|
3
|
+
const homePageUrl = import.meta.env.VITE_HOME_PAGE_URL
|
|
4
|
+
const product = import.meta.env.VITE_PRODUCT
|
|
5
|
+
|
|
6
|
+
export {
|
|
7
|
+
queryUrl,
|
|
8
|
+
baseUrl,
|
|
9
|
+
homePageUrl,
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export * from './request';
|
|
13
|
+
export * from './dsl';
|
|
14
|
+
export * from './crypto';
|
|
15
|
+
|
|
16
|
+
export function redirectHomePage(data?: any) {
|
|
17
|
+
if (isElectronEnv()) {
|
|
18
|
+
window.electronAPI.setGlobal(data);
|
|
19
|
+
window.electronAPI.sendLoginSuccess(data);
|
|
20
|
+
} else {
|
|
21
|
+
window.location.replace(`${homePageUrl}?token=${data.token}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function isElectronEnv(): boolean {
|
|
26
|
+
if (product === 'electron') {
|
|
27
|
+
return true
|
|
28
|
+
}
|
|
29
|
+
return false
|
|
30
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
const toString = Object.prototype.toString;
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @description: 判断值是否未某个类型
|
|
5
|
+
*/
|
|
6
|
+
export function is(val: unknown, type: string) {
|
|
7
|
+
return toString.call(val) === `[object ${type}]`;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @description: 是否为函数
|
|
12
|
+
*/
|
|
13
|
+
export function isFunction<T = Function>(val: unknown): val is T {
|
|
14
|
+
return is(val, 'Function') || is(val, 'AsyncFunction');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @description: 是否已定义
|
|
19
|
+
*/
|
|
20
|
+
export const isDef = <T = unknown>(val?: T): val is T => {
|
|
21
|
+
return typeof val !== 'undefined';
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const isUnDef = <T = unknown>(val?: T): val is T => {
|
|
25
|
+
return !isDef(val);
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* @description: 是否为对象
|
|
29
|
+
*/
|
|
30
|
+
export const isObject = (val: any): val is Record<any, any> => {
|
|
31
|
+
return val !== null && is(val, 'Object');
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @description: 是否为时间
|
|
36
|
+
*/
|
|
37
|
+
export function isDate(val: unknown): val is Date {
|
|
38
|
+
return is(val, 'Date');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @description: 是否为数值
|
|
43
|
+
*/
|
|
44
|
+
export function isNumber(val: unknown): val is number {
|
|
45
|
+
return is(val, 'Number');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @description: 是否为AsyncFunction
|
|
50
|
+
*/
|
|
51
|
+
export function isAsyncFunction<T = any>(val: unknown): val is () => Promise<T> {
|
|
52
|
+
return is(val, 'AsyncFunction');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function isVNode(val: any) {
|
|
56
|
+
return isObject(val) && val.__v_isVNode
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @description: 是否为promise
|
|
61
|
+
*/
|
|
62
|
+
export function isPromise<T = any>(val: unknown): val is Promise<T> {
|
|
63
|
+
return is(val, 'Promise');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @description: 是否为字符串
|
|
68
|
+
*/
|
|
69
|
+
export function isString(val: unknown): val is string {
|
|
70
|
+
return is(val, 'String');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @description: 是否为boolean类型
|
|
75
|
+
*/
|
|
76
|
+
export function isBoolean(val: unknown): val is boolean {
|
|
77
|
+
return is(val, 'Boolean');
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @description: 是否为数组
|
|
82
|
+
*/
|
|
83
|
+
export function isArray(val: any): val is Array<any> {
|
|
84
|
+
return val && Array.isArray(val);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @description: 是否客户端
|
|
89
|
+
*/
|
|
90
|
+
export const isClient = () => {
|
|
91
|
+
return typeof window !== 'undefined';
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @description: 是否为浏览器
|
|
96
|
+
*/
|
|
97
|
+
export const isWindow = (val: any): val is Window => {
|
|
98
|
+
return typeof window !== 'undefined' && is(val, 'Window');
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export const isElement = (val: unknown): val is Element => {
|
|
102
|
+
return isObject(val) && !!val.tagName;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export const isServer = typeof window === 'undefined';
|
|
106
|
+
|
|
107
|
+
// 是否为图片节点
|
|
108
|
+
export function isImageDom(o: Element) {
|
|
109
|
+
return o && ['IMAGE', 'IMG'].includes(o.tagName);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function isNull(val: unknown): val is null {
|
|
113
|
+
return val === null;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function isNullAndUnDef(val: unknown): val is null | undefined {
|
|
117
|
+
return isUnDef(val) && isNull(val);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function isNullOrUnDef(val: unknown): val is null | undefined {
|
|
121
|
+
return isUnDef(val) || isNull(val);
|
|
122
|
+
}
|