@peng_kai/kit 0.3.0-beta.7 → 0.3.0-beta.9
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/antd/hooks/useAntdDrawer.ts +6 -1
- package/antd/hooks/useAntdModal.ts +1 -0
- package/libs/fingerprintjs.ts +4 -0
- package/package.json +22 -22
- package/request/interceptors/getDeviceInfo.ts +22 -0
- package/utils/LocaleManager.ts +1 -0
- package/utils/blockchain.ts +4 -0
- package/utils/locale/LocaleManager.ts +22 -11
- package/utils/locale/helpers.ts +10 -1
- package/utils/storage.ts +31 -0
|
@@ -6,7 +6,12 @@ import type { ComponentProps } from 'vue-component-type-helpers';
|
|
|
6
6
|
import type { Writable } from 'type-fest';
|
|
7
7
|
import { useTemplateRefs } from '../../vue';
|
|
8
8
|
|
|
9
|
-
const defaultDrawerProps: DrawerProps = {
|
|
9
|
+
const defaultDrawerProps: DrawerProps = {
|
|
10
|
+
open: false,
|
|
11
|
+
destroyOnClose: true,
|
|
12
|
+
rootClassName: 'antd-cover__basic-drawer',
|
|
13
|
+
maskClosable: false,
|
|
14
|
+
};
|
|
10
15
|
|
|
11
16
|
interface IComponentConfig<Comp extends Component> {
|
|
12
17
|
is: Comp
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peng_kai/kit",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.3.0-beta.
|
|
4
|
+
"version": "0.3.0-beta.9",
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "",
|
|
7
7
|
"license": "ISC",
|
|
@@ -14,25 +14,25 @@
|
|
|
14
14
|
},
|
|
15
15
|
"peerDependencies": {
|
|
16
16
|
"ant-design-vue": "4.2.5",
|
|
17
|
-
"vue": "3.5.
|
|
18
|
-
"vue-router": "4.
|
|
17
|
+
"vue": "3.5.13",
|
|
18
|
+
"vue-router": "4.5.0"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@aws-sdk/client-s3": "^3.667.0",
|
|
22
22
|
"@aws-sdk/lib-storage": "^3.667.0",
|
|
23
|
-
"@babel/generator": "^7.
|
|
24
|
-
"@babel/parser": "^7.
|
|
25
|
-
"@babel/traverse": "^7.
|
|
26
|
-
"@babel/types": "^7.
|
|
23
|
+
"@babel/generator": "^7.26.5",
|
|
24
|
+
"@babel/parser": "^7.26.7",
|
|
25
|
+
"@babel/traverse": "^7.26.7",
|
|
26
|
+
"@babel/types": "^7.26.7",
|
|
27
27
|
"@ckeditor/ckeditor5-vue": "^5.1.0",
|
|
28
|
-
"@fingerprintjs/fingerprintjs": "^4.5.
|
|
29
|
-
"@tanstack/vue-query": "^5.
|
|
30
|
-
"@vueuse/components": "^
|
|
31
|
-
"@vueuse/core": "^
|
|
32
|
-
"@vueuse/router": "^
|
|
28
|
+
"@fingerprintjs/fingerprintjs": "^4.5.1",
|
|
29
|
+
"@tanstack/vue-query": "^5.64.2",
|
|
30
|
+
"@vueuse/components": "^12.5.0",
|
|
31
|
+
"@vueuse/core": "^12.5.0",
|
|
32
|
+
"@vueuse/router": "^12.5.0",
|
|
33
33
|
"a-calc": "^2.2.10",
|
|
34
34
|
"archiver": "^7.0.1",
|
|
35
|
-
"axios": "^1.7.
|
|
35
|
+
"axios": "^1.7.9",
|
|
36
36
|
"bignumber.js": "^9.1.2",
|
|
37
37
|
"chokidar": "^3.6.0",
|
|
38
38
|
"crypto-es": "^2.1.0",
|
|
@@ -43,11 +43,11 @@
|
|
|
43
43
|
"localstorage-slim": "^2.7.1",
|
|
44
44
|
"lodash-es": "^4.17.21",
|
|
45
45
|
"nprogress": "^0.2.0",
|
|
46
|
-
"pinia": "^2.
|
|
46
|
+
"pinia": "^2.3.1",
|
|
47
47
|
"tsx": "^4.16.00",
|
|
48
|
-
"vue": "^3.5.
|
|
49
|
-
"vue-i18n": "^
|
|
50
|
-
"vue-router": "^4.
|
|
48
|
+
"vue": "^3.5.13",
|
|
49
|
+
"vue-i18n": "^11.0.1",
|
|
50
|
+
"vue-router": "^4.5.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@ckeditor/ckeditor5-adapter-ckfinder": "^41.1.0",
|
|
@@ -82,14 +82,14 @@
|
|
|
82
82
|
"@ckeditor/ckeditor5-upload": "^41.1.0",
|
|
83
83
|
"@ckeditor/ckeditor5-word-count": "^41.1.0",
|
|
84
84
|
"@peng_kai/lint": "^0.1.0",
|
|
85
|
-
"@types/archiver": "^6.0.
|
|
85
|
+
"@types/archiver": "^6.0.3",
|
|
86
86
|
"@types/crypto-js": "^4.2.2",
|
|
87
87
|
"@types/lodash-es": "^4.17.12",
|
|
88
|
-
"@types/node": "^20.16
|
|
88
|
+
"@types/node": "^20.17.16",
|
|
89
89
|
"@types/nprogress": "^0.2.3",
|
|
90
90
|
"ant-design-vue": "^4.2.5",
|
|
91
|
-
"type-fest": "^4.
|
|
92
|
-
"typescript": "^5.
|
|
93
|
-
"vue-component-type-helpers": "^2.
|
|
91
|
+
"type-fest": "^4.33.0",
|
|
92
|
+
"typescript": "^5.7.3",
|
|
93
|
+
"vue-component-type-helpers": "^2.2.0"
|
|
94
94
|
}
|
|
95
95
|
}
|
|
@@ -25,6 +25,7 @@ export function getDeviceInfo(callback: (base: Record<string, any>, all: GetResu
|
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
req.headers.set('Device', callback(base, result));
|
|
28
|
+
req.headers.set('Device-Id', getDeviceID(base.visitor_id));
|
|
28
29
|
req.headers.set('Accept-Date', getCurrentTimeZone());
|
|
29
30
|
|
|
30
31
|
return req;
|
|
@@ -38,3 +39,24 @@ function getCurrentTimeZone() {
|
|
|
38
39
|
const tzOffset = now.getTimezoneOffset() / 60;
|
|
39
40
|
return toBase64([time, tz, tzOffset, describe].join('|'));
|
|
40
41
|
}
|
|
42
|
+
|
|
43
|
+
function getDeviceID(visitorId: string) {
|
|
44
|
+
const key = 'APP_DEVICE_ID';
|
|
45
|
+
const oldId = localStorage.getItem(key);
|
|
46
|
+
const newId = oldId || visitorId || generateRandomStringSecure(32);
|
|
47
|
+
newId !== oldId && localStorage.setItem(key, newId);
|
|
48
|
+
return newId;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function generateRandomStringSecure(length: number) {
|
|
52
|
+
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
53
|
+
const randomValues = new Uint32Array(length);
|
|
54
|
+
window.crypto.getRandomValues(randomValues); // 浏览器内置加密 API
|
|
55
|
+
|
|
56
|
+
let result = '';
|
|
57
|
+
for (let i = 0; i < length; i++) {
|
|
58
|
+
result += chars[randomValues[i] % chars.length];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return result;
|
|
62
|
+
}
|
package/utils/LocaleManager.ts
CHANGED
package/utils/blockchain.ts
CHANGED
|
@@ -40,6 +40,10 @@ export function getScanBrowser(chain: string, hash: string, type: 'transaction'
|
|
|
40
40
|
},
|
|
41
41
|
'DOGE': () => `https://dogechain.info/${evmType()}/${hash}`,
|
|
42
42
|
'BTC': () => `https://mempool.space/${evmType()}/${hash}`,
|
|
43
|
+
'TON': () => {
|
|
44
|
+
const _type = type === 'transaction' ? '/transactions' : '';
|
|
45
|
+
return `https://tonscan.com${_type}/${hash}`;
|
|
46
|
+
},
|
|
43
47
|
}[_chain] ?? (() => '');
|
|
44
48
|
|
|
45
49
|
return urlFn();
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { mapKeys } from 'lodash-es';
|
|
2
|
+
import { normalizeLocaleCode } from './helpers';
|
|
2
3
|
|
|
3
4
|
interface ILocaleMeta {
|
|
4
5
|
label: string
|
|
@@ -59,20 +60,10 @@ export class LocaleManager {
|
|
|
59
60
|
const localeTargets = [searchParams.get('locale'), searchParams.get('lang'), this.getStorageLocale(), navigator.language]
|
|
60
61
|
.filter(locale => !!locale)
|
|
61
62
|
.map(locale => locale!.replace('_', '-'));
|
|
62
|
-
// 区域代码矩阵,2级数组的第1项是这个区域的标识(也是这个语言对应的文件名:en-US.json),后面是这个区域的代码
|
|
63
|
-
const codeMatrix = this.localesAvailable.map(locale => [locale, ...this.localeMetas[locale].codes]);
|
|
64
63
|
let localeFinal = '';
|
|
65
64
|
|
|
66
65
|
for (const target of localeTargets) {
|
|
67
|
-
|
|
68
|
-
const matched = codes.some(code => code.toUpperCase().startsWith(target.toUpperCase()));
|
|
69
|
-
|
|
70
|
-
if (matched) {
|
|
71
|
-
localeFinal = codes[0];
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
66
|
+
localeFinal = this.findMatchingLocale(target);
|
|
76
67
|
if (localeFinal)
|
|
77
68
|
break;
|
|
78
69
|
}
|
|
@@ -110,6 +101,26 @@ export class LocaleManager {
|
|
|
110
101
|
return meta;
|
|
111
102
|
}
|
|
112
103
|
|
|
104
|
+
/**
|
|
105
|
+
* 获取可用的区域
|
|
106
|
+
*/
|
|
107
|
+
public findMatchingLocale(targetLocale: string) {
|
|
108
|
+
targetLocale = normalizeLocaleCode(targetLocale);
|
|
109
|
+
const codeMatrix = this.localesAvailable.map(locale => [locale, ...this.localeMetas[locale].codes]);
|
|
110
|
+
let matchedLocale = '';
|
|
111
|
+
|
|
112
|
+
for (const codes of codeMatrix) {
|
|
113
|
+
const matched = codes.some(code => code.toUpperCase().startsWith(targetLocale.toUpperCase()));
|
|
114
|
+
|
|
115
|
+
if (matched) {
|
|
116
|
+
matchedLocale = codes[0];
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return matchedLocale;
|
|
122
|
+
}
|
|
123
|
+
|
|
113
124
|
private clearUrlLocale() {
|
|
114
125
|
const url = new URL(location.href);
|
|
115
126
|
url.searchParams.delete('locale');
|
package/utils/locale/helpers.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { I18nOptions } from 'vue-i18n';
|
|
1
2
|
import { omitBy } from '../../libs/lodash-es';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -5,7 +6,7 @@ import { omitBy } from '../../libs/lodash-es';
|
|
|
5
6
|
*/
|
|
6
7
|
export function normalizeLocaleCode(code: string) {
|
|
7
8
|
// 移除所有空白字符并转换为小写
|
|
8
|
-
const normalized = code.replace(/\s/g, '').toLowerCase();
|
|
9
|
+
const normalized = code.replace(/\s/g, '').replace('_', '-').toLowerCase();
|
|
9
10
|
|
|
10
11
|
// 处理特殊情况:中文
|
|
11
12
|
if (normalized === 'zh-cn' || normalized === 'zh-hans')
|
|
@@ -32,6 +33,14 @@ export function omitLocale(modules: Record<string, any>, excludes: string[] = []
|
|
|
32
33
|
return omitBy(modules, (_, path) => excludes.some(locale => path.includes(locale)));
|
|
33
34
|
}
|
|
34
35
|
|
|
36
|
+
/** 添加语言格式 */
|
|
37
|
+
export function addDatetimeFormat<T extends string>(name: T, config: NonNullable<I18nOptions['datetimeFormats']>[string][string]) {
|
|
38
|
+
return {
|
|
39
|
+
[name]: config,
|
|
40
|
+
[`${name}-utc`]: { ...config, timeZone: 'UTC' },
|
|
41
|
+
} as Record<T | `${T}-utc`, typeof config>;
|
|
42
|
+
}
|
|
43
|
+
|
|
35
44
|
/**
|
|
36
45
|
* 加密 JSON 消息
|
|
37
46
|
*/
|
package/utils/storage.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type MaybeRefOrGetter, computed, isReactive, reactive, toValue } from 'vue';
|
|
2
|
+
|
|
3
|
+
export class StorageKey<F extends Record<string, string | number>> {
|
|
4
|
+
public factors: F;
|
|
5
|
+
private split = '_';
|
|
6
|
+
|
|
7
|
+
public constructor(factors: F, private order: Array<keyof F>) {
|
|
8
|
+
this.factors = isReactive(factors) ? factors : reactive(factors) as F;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 构建存储键
|
|
13
|
+
* @param parts 键的部分
|
|
14
|
+
* @param excludeFactors 排除键的因素
|
|
15
|
+
*/
|
|
16
|
+
public build(parts: Array<MaybeRefOrGetter<F[string]>>, excludeFactors: Array<keyof F> | boolean = false) {
|
|
17
|
+
const finalKey = computed(() => {
|
|
18
|
+
const thisKeys = parts.map(k => String(toValue(k)));
|
|
19
|
+
const factorKeys = Array.isArray(excludeFactors)
|
|
20
|
+
? this.order.filter(k => !excludeFactors?.includes(k)).map(k => this.factors[k])
|
|
21
|
+
: excludeFactors
|
|
22
|
+
? []
|
|
23
|
+
: this.order.map(k => this.factors[k]);
|
|
24
|
+
const thisStr = thisKeys.join(this.split);
|
|
25
|
+
const factorStr = factorKeys.join(this.split);
|
|
26
|
+
return `${factorStr}${factorStr ? this.split : ''}${thisStr}`;
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
return finalKey;
|
|
30
|
+
}
|
|
31
|
+
}
|