@hzw-tech/utils 0.0.1
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/.eslintrc-auto-import.json +103 -0
- package/.vscode/extensions.json +12 -0
- package/.vscode/html.code-snippets +25 -0
- package/.vscode/scss.code-snippets +77 -0
- package/.vscode/settings.json +102 -0
- package/.vscode/tailwind.json +56 -0
- package/.vscode/typescript.code-snippets +162 -0
- package/.vscode/vue.code-snippets +40 -0
- package/LICENSE +21 -0
- package/dist/eslint.d.ts +6 -0
- package/dist/eslint.js +43 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/main.d.ts +3 -0
- package/dist/styles/_classes.scss +80 -0
- package/dist/styles/_reset.scss +111 -0
- package/dist/styles/index.css +4927 -0
- package/dist/styles/index.css.map +1 -0
- package/dist/styles/index.scss +2 -0
- package/dist/styles/reference/_config.scss +209 -0
- package/dist/styles/reference/_functions.scss +17 -0
- package/dist/styles/reference/_index.scss +3 -0
- package/dist/styles/reference/_mixins.scss +209 -0
- package/dist/ts/bem.d.ts +49 -0
- package/dist/ts/config.d.ts +13 -0
- package/dist/ts/reg.d.ts +17 -0
- package/dist/ts/request.d.ts +51 -0
- package/dist/ts/utils.d.ts +128 -0
- package/dist/ts/validators.d.ts +29 -0
- package/dist/types/global.d.ts +188 -0
- package/dist/types/index.d.ts +24 -0
- package/dist/types/window.d.ts +13 -0
- package/dist/vite.d.ts +30 -0
- package/dist/vite.js +42 -0
- package/eslint.config.mjs +3 -0
- package/index.html +12 -0
- package/package.json +56 -0
- package/readme.md +115 -0
- package/rollup.config.mjs +28 -0
- package/tsconfig.json +19 -0
- package/vite.config.mts +38 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import type { GConfig } from './config';
|
|
2
|
+
declare function getConfig(): GConfig;
|
|
3
|
+
declare function getType(data: any): string;
|
|
4
|
+
declare function isJson(data: string): boolean;
|
|
5
|
+
declare function isEmpty(value: any): boolean;
|
|
6
|
+
interface IStorage {
|
|
7
|
+
set: (key: string, value: any, replace?: boolean) => any;
|
|
8
|
+
get: <T = any>(key: string) => T;
|
|
9
|
+
remove: (key: string) => void;
|
|
10
|
+
clear: () => void;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* 本地存储,set存储时传入replace=true表示替换原来的字段,false则先获取原先字段并Object.assign来合并,prefix表示存储前缀,默认是hzw-
|
|
14
|
+
* @param type sessionStorage还是localStorage
|
|
15
|
+
* @returns Object {set:'存储方法',get:'获取方法'}
|
|
16
|
+
*/
|
|
17
|
+
declare function storageHandler(type?: string): IStorage;
|
|
18
|
+
/**
|
|
19
|
+
* 合并对象参数,对象数据缺省传递时会自动补全属性值
|
|
20
|
+
* 如果旧对象有问题,返回新对象,反之返回旧对象
|
|
21
|
+
* 如果oldObj在newObj中对应属性为undefined,则使用oldObj对应属性值
|
|
22
|
+
* 否则如果oldObj属性为object,且则进行递归判断
|
|
23
|
+
* 其他情况下,比如oldObj和newObj类型不一致等,不做处理,以newObj为准
|
|
24
|
+
* 注意:newObj传递的null或0或空字符串与旧值不一致也会覆盖旧值
|
|
25
|
+
*/
|
|
26
|
+
declare function mergeObject<T>(oldObj: any, newObj: any): T;
|
|
27
|
+
declare function debounce(fn: any, delay?: number): (...params: any[]) => void;
|
|
28
|
+
declare function throttle(fn: any, delay?: number): (...params: any[]) => void;
|
|
29
|
+
declare function clone<T>(source: any): T;
|
|
30
|
+
declare function urlParser(url: string): Record<string, any> | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* 根据value查找对象的key
|
|
33
|
+
* @param obj object对象
|
|
34
|
+
* @param value 值
|
|
35
|
+
* @returns 键
|
|
36
|
+
*/
|
|
37
|
+
declare function objectKey(obj: Record<string, any>, value: any): string;
|
|
38
|
+
/**
|
|
39
|
+
* 通用的创建下载链接的功能
|
|
40
|
+
* @param {Blob | string} res - 表示要下载的数据,可以是 Blob 对象或下载链接。
|
|
41
|
+
* @param {string} fileName - 下载文件的名称。
|
|
42
|
+
* @returns {void}
|
|
43
|
+
*/
|
|
44
|
+
declare function createDownloadLink(res: Blob | string, fileName: string): void;
|
|
45
|
+
/**
|
|
46
|
+
* 从一维数组中的元素或者元素的属性中删除指定值
|
|
47
|
+
* @param arr
|
|
48
|
+
* @param find
|
|
49
|
+
* @param property
|
|
50
|
+
*/
|
|
51
|
+
declare function arrayDelete<T>(arr: T[], find: any, property?: string): void;
|
|
52
|
+
declare function getAssetsFile(url: string): string;
|
|
53
|
+
/**
|
|
54
|
+
* 初始化console日志,当浏览器url中输入?debug=1时,开启debug模式
|
|
55
|
+
* const log=logger('[PERMISSION]');
|
|
56
|
+
* log('test');
|
|
57
|
+
* @param prefix 日志前缀
|
|
58
|
+
* @param color 日志颜色
|
|
59
|
+
* @returns console日志
|
|
60
|
+
*/
|
|
61
|
+
declare function logger(prefix?: string, color?: string): ((...params: any[]) => void);
|
|
62
|
+
declare function kebabCaseToCamelCase(str: string): string;
|
|
63
|
+
/**
|
|
64
|
+
* 枚举或对象类型根据值获取key
|
|
65
|
+
* @param data enum或者object对象
|
|
66
|
+
* @param value
|
|
67
|
+
* @returns key
|
|
68
|
+
*/
|
|
69
|
+
declare function enumGetKeyByValue(data: any, value: any): string | undefined;
|
|
70
|
+
declare function getByteLength(str: string): number;
|
|
71
|
+
/**
|
|
72
|
+
* 代码修改逻辑后用户本地存储的数据不一致时,
|
|
73
|
+
* 可以修改package.json的version,此时会清除localStorage
|
|
74
|
+
*/
|
|
75
|
+
declare function clearLocalStorage(): void;
|
|
76
|
+
declare function isNumeric(value: any): value is number | string;
|
|
77
|
+
declare function encodeToLetters(str: string): string;
|
|
78
|
+
declare function decodeFromLetters(encoded: string): string;
|
|
79
|
+
declare function cls(classes: string[]): string;
|
|
80
|
+
/**
|
|
81
|
+
* 手机号中间4位隐藏
|
|
82
|
+
* @param phone 手机号
|
|
83
|
+
* @returns 隐藏后的手机号
|
|
84
|
+
*/
|
|
85
|
+
declare function phoneHider(phone: string): string;
|
|
86
|
+
export declare const utils: {
|
|
87
|
+
getConfig: typeof getConfig;
|
|
88
|
+
getType: typeof getType;
|
|
89
|
+
isJson: typeof isJson;
|
|
90
|
+
isEmpty: typeof isEmpty;
|
|
91
|
+
storageHandler: typeof storageHandler;
|
|
92
|
+
mergeObject: typeof mergeObject;
|
|
93
|
+
debounce: typeof debounce;
|
|
94
|
+
throttle: typeof throttle;
|
|
95
|
+
clone: typeof clone;
|
|
96
|
+
urlParser: typeof urlParser;
|
|
97
|
+
objectKey: typeof objectKey;
|
|
98
|
+
createDownloadLink: typeof createDownloadLink;
|
|
99
|
+
arrayDelete: typeof arrayDelete;
|
|
100
|
+
getAssetsFile: typeof getAssetsFile;
|
|
101
|
+
logger: typeof logger;
|
|
102
|
+
kebabCaseToCamelCase: typeof kebabCaseToCamelCase;
|
|
103
|
+
enumGetKeyByValue: typeof enumGetKeyByValue;
|
|
104
|
+
getByteLength: typeof getByteLength;
|
|
105
|
+
clearLocalStorage: typeof clearLocalStorage;
|
|
106
|
+
isNumeric: typeof isNumeric;
|
|
107
|
+
encodeToLetters: typeof encodeToLetters;
|
|
108
|
+
decodeFromLetters: typeof decodeFromLetters;
|
|
109
|
+
cls: typeof cls;
|
|
110
|
+
phoneHider: typeof phoneHider;
|
|
111
|
+
aes: {
|
|
112
|
+
encrypt(data: any, secretKey?: string): string;
|
|
113
|
+
decrypt(encryptedData: any, secretKey?: string): any;
|
|
114
|
+
};
|
|
115
|
+
storage: {
|
|
116
|
+
set: (key: string, value: any, replace?: boolean) => any;
|
|
117
|
+
get: <T = any>(key: string) => T;
|
|
118
|
+
remove: (key: string) => void;
|
|
119
|
+
clear: () => void;
|
|
120
|
+
};
|
|
121
|
+
session: {
|
|
122
|
+
set: (key: string, value: any, replace?: boolean) => any;
|
|
123
|
+
get: <T = any>(key: string) => T;
|
|
124
|
+
remove: (key: string) => void;
|
|
125
|
+
clear: () => void;
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
declare function validatePhoneEmail(rule: any, value: any, callback: any): void;
|
|
2
|
+
declare function validateEmail(rule: any, value: any, callback: any): void;
|
|
3
|
+
declare function validateEmailAddress(rule: any, value: any, callback: any): void;
|
|
4
|
+
declare function validatePassword(rule: any, value: any, callback: any): void;
|
|
5
|
+
declare function validateCheckPass(rule: any, value: string, callback: any): void;
|
|
6
|
+
declare function validatePhone(rule: any, value: any, callback: any): void;
|
|
7
|
+
declare function validatePhoneNumber(rule: any, value: any, callback: any): void;
|
|
8
|
+
declare function validateRealName(rule: string, value: string, callback: any): void;
|
|
9
|
+
declare function validateZh(rule: any, value: any, callback: any): void;
|
|
10
|
+
declare function validateEn(rule: any, value: any, callback: any): void;
|
|
11
|
+
declare function validateResearchPlan(rule: any, value: any, callback: any): void;
|
|
12
|
+
declare function validateUsername(rule: any, value: any, callback: any): void;
|
|
13
|
+
declare function validatePasswordWithSymbol(rule: any, value: any, callback: any): void;
|
|
14
|
+
export declare const validators: {
|
|
15
|
+
validatePhoneEmail: typeof validatePhoneEmail;
|
|
16
|
+
validateEmail: typeof validateEmail;
|
|
17
|
+
validateEmailAddress: typeof validateEmailAddress;
|
|
18
|
+
validatePassword: typeof validatePassword;
|
|
19
|
+
validateCheckPass: typeof validateCheckPass;
|
|
20
|
+
validatePhone: typeof validatePhone;
|
|
21
|
+
validatePhoneNumber: typeof validatePhoneNumber;
|
|
22
|
+
validateRealName: typeof validateRealName;
|
|
23
|
+
validateZh: typeof validateZh;
|
|
24
|
+
validateEn: typeof validateEn;
|
|
25
|
+
validateResearchPlan: typeof validateResearchPlan;
|
|
26
|
+
validateUsername: typeof validateUsername;
|
|
27
|
+
validatePasswordWithSymbol: typeof validatePasswordWithSymbol;
|
|
28
|
+
};
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,188 @@
|
|
|
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 ApiRequest: typeof import('../ts/request').ApiRequest
|
|
10
|
+
const EffectScope: typeof import('vue').EffectScope
|
|
11
|
+
const acceptHMRUpdate: typeof import('pinia').acceptHMRUpdate
|
|
12
|
+
const bem: typeof import('../ts/bem').bem
|
|
13
|
+
const computed: typeof import('vue').computed
|
|
14
|
+
const config: typeof import('../ts/config').config
|
|
15
|
+
const createApp: typeof import('vue').createApp
|
|
16
|
+
const createPinia: typeof import('pinia').createPinia
|
|
17
|
+
const css: typeof import('../ts/bem').css
|
|
18
|
+
const customRef: typeof import('vue').customRef
|
|
19
|
+
const defineAsyncComponent: typeof import('vue').defineAsyncComponent
|
|
20
|
+
const defineComponent: typeof import('vue').defineComponent
|
|
21
|
+
const defineStore: typeof import('pinia').defineStore
|
|
22
|
+
const effectScope: typeof import('vue').effectScope
|
|
23
|
+
const getActivePinia: typeof import('pinia').getActivePinia
|
|
24
|
+
const getCurrentInstance: typeof import('vue').getCurrentInstance
|
|
25
|
+
const getCurrentScope: typeof import('vue').getCurrentScope
|
|
26
|
+
const getCurrentWatcher: typeof import('vue').getCurrentWatcher
|
|
27
|
+
const h: typeof import('vue').h
|
|
28
|
+
const inject: typeof import('vue').inject
|
|
29
|
+
const isProxy: typeof import('vue').isProxy
|
|
30
|
+
const isReactive: typeof import('vue').isReactive
|
|
31
|
+
const isReadonly: typeof import('vue').isReadonly
|
|
32
|
+
const isRef: typeof import('vue').isRef
|
|
33
|
+
const isShallow: typeof import('vue').isShallow
|
|
34
|
+
const mapActions: typeof import('pinia').mapActions
|
|
35
|
+
const mapGetters: typeof import('pinia').mapGetters
|
|
36
|
+
const mapState: typeof import('pinia').mapState
|
|
37
|
+
const mapStores: typeof import('pinia').mapStores
|
|
38
|
+
const mapWritableState: typeof import('pinia').mapWritableState
|
|
39
|
+
const markRaw: typeof import('vue').markRaw
|
|
40
|
+
const nextTick: typeof import('vue').nextTick
|
|
41
|
+
const onActivated: typeof import('vue').onActivated
|
|
42
|
+
const onBeforeMount: typeof import('vue').onBeforeMount
|
|
43
|
+
const onBeforeUnmount: typeof import('vue').onBeforeUnmount
|
|
44
|
+
const onBeforeUpdate: typeof import('vue').onBeforeUpdate
|
|
45
|
+
const onDeactivated: typeof import('vue').onDeactivated
|
|
46
|
+
const onErrorCaptured: typeof import('vue').onErrorCaptured
|
|
47
|
+
const onMounted: typeof import('vue').onMounted
|
|
48
|
+
const onRenderTracked: typeof import('vue').onRenderTracked
|
|
49
|
+
const onRenderTriggered: typeof import('vue').onRenderTriggered
|
|
50
|
+
const onScopeDispose: typeof import('vue').onScopeDispose
|
|
51
|
+
const onServerPrefetch: typeof import('vue').onServerPrefetch
|
|
52
|
+
const onUnmounted: typeof import('vue').onUnmounted
|
|
53
|
+
const onUpdated: typeof import('vue').onUpdated
|
|
54
|
+
const onWatcherCleanup: typeof import('vue').onWatcherCleanup
|
|
55
|
+
const provide: typeof import('vue').provide
|
|
56
|
+
const reactive: typeof import('vue').reactive
|
|
57
|
+
const readonly: typeof import('vue').readonly
|
|
58
|
+
const ref: typeof import('vue').ref
|
|
59
|
+
const reg: typeof import('../ts/reg').reg
|
|
60
|
+
const request: typeof import('../ts/request').request
|
|
61
|
+
const resolveComponent: typeof import('vue').resolveComponent
|
|
62
|
+
const setActivePinia: typeof import('pinia').setActivePinia
|
|
63
|
+
const setMapStoreSuffix: typeof import('pinia').setMapStoreSuffix
|
|
64
|
+
const shallowReactive: typeof import('vue').shallowReactive
|
|
65
|
+
const shallowReadonly: typeof import('vue').shallowReadonly
|
|
66
|
+
const shallowRef: typeof import('vue').shallowRef
|
|
67
|
+
const storeToRefs: typeof import('pinia').storeToRefs
|
|
68
|
+
const toRaw: typeof import('vue').toRaw
|
|
69
|
+
const toRef: typeof import('vue').toRef
|
|
70
|
+
const toRefs: typeof import('vue').toRefs
|
|
71
|
+
const toValue: typeof import('vue').toValue
|
|
72
|
+
const triggerRef: typeof import('vue').triggerRef
|
|
73
|
+
const unref: typeof import('vue').unref
|
|
74
|
+
const useAttrs: typeof import('vue').useAttrs
|
|
75
|
+
const useCssModule: typeof import('vue').useCssModule
|
|
76
|
+
const useCssVars: typeof import('vue').useCssVars
|
|
77
|
+
const useId: typeof import('vue').useId
|
|
78
|
+
const useModel: typeof import('vue').useModel
|
|
79
|
+
const useSlots: typeof import('vue').useSlots
|
|
80
|
+
const useTemplateRef: typeof import('vue').useTemplateRef
|
|
81
|
+
const utils: typeof import('../ts/utils').utils
|
|
82
|
+
const validators: typeof import('../ts/validators').validators
|
|
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, Slot, Slots, ComponentPublicInstance, ComputedRef, DirectiveBinding, ExtractDefaultPropTypes, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, ShallowRef, MaybeRef, MaybeRefOrGetter, VNode, WritableComputedRef } from 'vue'
|
|
92
|
+
import('vue')
|
|
93
|
+
// @ts-ignore
|
|
94
|
+
export type { IBem, IBemCss } from '../ts/bem'
|
|
95
|
+
import('../ts/bem')
|
|
96
|
+
// @ts-ignore
|
|
97
|
+
export type { GConfig } from '../ts/config'
|
|
98
|
+
import('../ts/config')
|
|
99
|
+
// @ts-ignore
|
|
100
|
+
export type { ApiRequest, IRequestConfig } from '../ts/request'
|
|
101
|
+
import('../ts/request')
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// for vue template auto import
|
|
105
|
+
import { UnwrapRef } from 'vue'
|
|
106
|
+
declare module 'vue' {
|
|
107
|
+
interface GlobalComponents {}
|
|
108
|
+
interface ComponentCustomProperties {
|
|
109
|
+
readonly ApiRequest: UnwrapRef<typeof import('../ts/request')['ApiRequest']>
|
|
110
|
+
readonly EffectScope: UnwrapRef<typeof import('vue')['EffectScope']>
|
|
111
|
+
readonly acceptHMRUpdate: UnwrapRef<typeof import('pinia')['acceptHMRUpdate']>
|
|
112
|
+
readonly bem: UnwrapRef<typeof import('../ts/bem')['bem']>
|
|
113
|
+
readonly computed: UnwrapRef<typeof import('vue')['computed']>
|
|
114
|
+
readonly config: UnwrapRef<typeof import('../ts/config')['config']>
|
|
115
|
+
readonly createApp: UnwrapRef<typeof import('vue')['createApp']>
|
|
116
|
+
readonly createPinia: UnwrapRef<typeof import('pinia')['createPinia']>
|
|
117
|
+
readonly css: UnwrapRef<typeof import('../ts/bem')['css']>
|
|
118
|
+
readonly customRef: UnwrapRef<typeof import('vue')['customRef']>
|
|
119
|
+
readonly defineAsyncComponent: UnwrapRef<typeof import('vue')['defineAsyncComponent']>
|
|
120
|
+
readonly defineComponent: UnwrapRef<typeof import('vue')['defineComponent']>
|
|
121
|
+
readonly defineStore: UnwrapRef<typeof import('pinia')['defineStore']>
|
|
122
|
+
readonly effectScope: UnwrapRef<typeof import('vue')['effectScope']>
|
|
123
|
+
readonly getActivePinia: UnwrapRef<typeof import('pinia')['getActivePinia']>
|
|
124
|
+
readonly getCurrentInstance: UnwrapRef<typeof import('vue')['getCurrentInstance']>
|
|
125
|
+
readonly getCurrentScope: UnwrapRef<typeof import('vue')['getCurrentScope']>
|
|
126
|
+
readonly getCurrentWatcher: UnwrapRef<typeof import('vue')['getCurrentWatcher']>
|
|
127
|
+
readonly h: UnwrapRef<typeof import('vue')['h']>
|
|
128
|
+
readonly inject: UnwrapRef<typeof import('vue')['inject']>
|
|
129
|
+
readonly isProxy: UnwrapRef<typeof import('vue')['isProxy']>
|
|
130
|
+
readonly isReactive: UnwrapRef<typeof import('vue')['isReactive']>
|
|
131
|
+
readonly isReadonly: UnwrapRef<typeof import('vue')['isReadonly']>
|
|
132
|
+
readonly isRef: UnwrapRef<typeof import('vue')['isRef']>
|
|
133
|
+
readonly isShallow: UnwrapRef<typeof import('vue')['isShallow']>
|
|
134
|
+
readonly mapActions: UnwrapRef<typeof import('pinia')['mapActions']>
|
|
135
|
+
readonly mapGetters: UnwrapRef<typeof import('pinia')['mapGetters']>
|
|
136
|
+
readonly mapState: UnwrapRef<typeof import('pinia')['mapState']>
|
|
137
|
+
readonly mapStores: UnwrapRef<typeof import('pinia')['mapStores']>
|
|
138
|
+
readonly mapWritableState: UnwrapRef<typeof import('pinia')['mapWritableState']>
|
|
139
|
+
readonly markRaw: UnwrapRef<typeof import('vue')['markRaw']>
|
|
140
|
+
readonly nextTick: UnwrapRef<typeof import('vue')['nextTick']>
|
|
141
|
+
readonly onActivated: UnwrapRef<typeof import('vue')['onActivated']>
|
|
142
|
+
readonly onBeforeMount: UnwrapRef<typeof import('vue')['onBeforeMount']>
|
|
143
|
+
readonly onBeforeUnmount: UnwrapRef<typeof import('vue')['onBeforeUnmount']>
|
|
144
|
+
readonly onBeforeUpdate: UnwrapRef<typeof import('vue')['onBeforeUpdate']>
|
|
145
|
+
readonly onDeactivated: UnwrapRef<typeof import('vue')['onDeactivated']>
|
|
146
|
+
readonly onErrorCaptured: UnwrapRef<typeof import('vue')['onErrorCaptured']>
|
|
147
|
+
readonly onMounted: UnwrapRef<typeof import('vue')['onMounted']>
|
|
148
|
+
readonly onRenderTracked: UnwrapRef<typeof import('vue')['onRenderTracked']>
|
|
149
|
+
readonly onRenderTriggered: UnwrapRef<typeof import('vue')['onRenderTriggered']>
|
|
150
|
+
readonly onScopeDispose: UnwrapRef<typeof import('vue')['onScopeDispose']>
|
|
151
|
+
readonly onServerPrefetch: UnwrapRef<typeof import('vue')['onServerPrefetch']>
|
|
152
|
+
readonly onUnmounted: UnwrapRef<typeof import('vue')['onUnmounted']>
|
|
153
|
+
readonly onUpdated: UnwrapRef<typeof import('vue')['onUpdated']>
|
|
154
|
+
readonly onWatcherCleanup: UnwrapRef<typeof import('vue')['onWatcherCleanup']>
|
|
155
|
+
readonly provide: UnwrapRef<typeof import('vue')['provide']>
|
|
156
|
+
readonly reactive: UnwrapRef<typeof import('vue')['reactive']>
|
|
157
|
+
readonly readonly: UnwrapRef<typeof import('vue')['readonly']>
|
|
158
|
+
readonly ref: UnwrapRef<typeof import('vue')['ref']>
|
|
159
|
+
readonly reg: UnwrapRef<typeof import('../ts/reg')['reg']>
|
|
160
|
+
readonly request: UnwrapRef<typeof import('../ts/request')['request']>
|
|
161
|
+
readonly resolveComponent: UnwrapRef<typeof import('vue')['resolveComponent']>
|
|
162
|
+
readonly setActivePinia: UnwrapRef<typeof import('pinia')['setActivePinia']>
|
|
163
|
+
readonly setMapStoreSuffix: UnwrapRef<typeof import('pinia')['setMapStoreSuffix']>
|
|
164
|
+
readonly shallowReactive: UnwrapRef<typeof import('vue')['shallowReactive']>
|
|
165
|
+
readonly shallowReadonly: UnwrapRef<typeof import('vue')['shallowReadonly']>
|
|
166
|
+
readonly shallowRef: UnwrapRef<typeof import('vue')['shallowRef']>
|
|
167
|
+
readonly storeToRefs: UnwrapRef<typeof import('pinia')['storeToRefs']>
|
|
168
|
+
readonly toRaw: UnwrapRef<typeof import('vue')['toRaw']>
|
|
169
|
+
readonly toRef: UnwrapRef<typeof import('vue')['toRef']>
|
|
170
|
+
readonly toRefs: UnwrapRef<typeof import('vue')['toRefs']>
|
|
171
|
+
readonly toValue: UnwrapRef<typeof import('vue')['toValue']>
|
|
172
|
+
readonly triggerRef: UnwrapRef<typeof import('vue')['triggerRef']>
|
|
173
|
+
readonly unref: UnwrapRef<typeof import('vue')['unref']>
|
|
174
|
+
readonly useAttrs: UnwrapRef<typeof import('vue')['useAttrs']>
|
|
175
|
+
readonly useCssModule: UnwrapRef<typeof import('vue')['useCssModule']>
|
|
176
|
+
readonly useCssVars: UnwrapRef<typeof import('vue')['useCssVars']>
|
|
177
|
+
readonly useId: UnwrapRef<typeof import('vue')['useId']>
|
|
178
|
+
readonly useModel: UnwrapRef<typeof import('vue')['useModel']>
|
|
179
|
+
readonly useSlots: UnwrapRef<typeof import('vue')['useSlots']>
|
|
180
|
+
readonly useTemplateRef: UnwrapRef<typeof import('vue')['useTemplateRef']>
|
|
181
|
+
readonly utils: UnwrapRef<typeof import('../ts/utils')['utils']>
|
|
182
|
+
readonly validators: UnwrapRef<typeof import('../ts/validators')['validators']>
|
|
183
|
+
readonly watch: UnwrapRef<typeof import('vue')['watch']>
|
|
184
|
+
readonly watchEffect: UnwrapRef<typeof import('vue')['watchEffect']>
|
|
185
|
+
readonly watchPostEffect: UnwrapRef<typeof import('vue')['watchPostEffect']>
|
|
186
|
+
readonly watchSyncEffect: UnwrapRef<typeof import('vue')['watchSyncEffect']>
|
|
187
|
+
}
|
|
188
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 通用接口返回,status是状态码,message一般请求错误会返回信息,data是具体返回数据
|
|
3
|
+
*/
|
|
4
|
+
declare interface GRes<T> {
|
|
5
|
+
message: string
|
|
6
|
+
status: number
|
|
7
|
+
data: T
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* 通用分页接口返回,在通用接口返回基础上数据格式细分了分页信息
|
|
11
|
+
* records是数据的数组,total是数据总量,size是每页数据数量
|
|
12
|
+
*/
|
|
13
|
+
declare type GRecords<T> = GRes<{ records: T[], total: number, size: number }>
|
|
14
|
+
declare interface GOption<T> {
|
|
15
|
+
label: string
|
|
16
|
+
value: T
|
|
17
|
+
disabled?: boolean
|
|
18
|
+
}
|
|
19
|
+
declare interface GKeyValue<T> {
|
|
20
|
+
key: string
|
|
21
|
+
value: T
|
|
22
|
+
}
|
|
23
|
+
declare module '*.js'
|
|
24
|
+
declare module '*.vue'
|
package/dist/vite.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
declare module '@hzwtech.com/utils/dist/vite' {
|
|
2
|
+
import type { Options as AutoImportOptions } from 'unplugin-auto-import/types'
|
|
3
|
+
import type { Plugin } from 'vite'
|
|
4
|
+
|
|
5
|
+
export interface ScssOptions {
|
|
6
|
+
additionalData: string
|
|
7
|
+
[key: string]: any
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Configure unplugin-auto-import for Vite
|
|
12
|
+
* @param options - Configuration options
|
|
13
|
+
*/
|
|
14
|
+
export function autoImport(options?: Partial<AutoImportOptions>): Plugin
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* SCSS configuration options
|
|
18
|
+
*/
|
|
19
|
+
export function scss(opt?: ScssOptions): ScssOptions
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Default export containing both autoImport and scss
|
|
23
|
+
*/
|
|
24
|
+
const viteConfig: {
|
|
25
|
+
autoImport: typeof autoImport
|
|
26
|
+
scss: typeof scss
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export default viteConfig
|
|
30
|
+
}
|
package/dist/vite.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import process from 'node:process'
|
|
2
|
+
import AutoImportVite from 'unplugin-auto-import/vite'
|
|
3
|
+
|
|
4
|
+
function scss(options) {
|
|
5
|
+
let additionalData = ''
|
|
6
|
+
if (options && options.additionalData) {
|
|
7
|
+
additionalData = options.additionalData
|
|
8
|
+
}
|
|
9
|
+
return {
|
|
10
|
+
additionalData: `
|
|
11
|
+
@use "@hzwtech.com/utils/dist/styles/reference/index.scss" as *;
|
|
12
|
+
${additionalData}
|
|
13
|
+
`,
|
|
14
|
+
...options,
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function autoImport(options) {
|
|
18
|
+
const { mode } = process.env
|
|
19
|
+
const isPublish = mode === 'publish'
|
|
20
|
+
const optDefault = {
|
|
21
|
+
imports: ['pinia', 'vue'],
|
|
22
|
+
eslintrc: {
|
|
23
|
+
enabled: true,
|
|
24
|
+
globalsPropValue: 'writable',
|
|
25
|
+
},
|
|
26
|
+
vueTemplate: true,
|
|
27
|
+
dirs: ['./src/ts'],
|
|
28
|
+
dts: isPublish ? './src/types/global.d.ts' : false,
|
|
29
|
+
dtsMode: 'overwrite',
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (!isPublish && !optDefault.imports.includes('@hzwtech.com/utils')) {
|
|
33
|
+
optDefault.imports.push({ '@hzwtech.com/utils': ['utils', 'css', 'bem'] })
|
|
34
|
+
}
|
|
35
|
+
const opt = Object.assign({}, optDefault, options)
|
|
36
|
+
return AutoImportVite(opt)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export default {
|
|
40
|
+
autoImport,
|
|
41
|
+
scss,
|
|
42
|
+
}
|
package/index.html
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>dev</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<div id="app"></div>
|
|
10
|
+
<script type="module" src="/src/main.ts"></script>
|
|
11
|
+
</body>
|
|
12
|
+
</html>
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hzw-tech/utils",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"description": "通用前端工具包,包含请求,正则校验,全局ts声明等",
|
|
6
|
+
"author": "hzw-tech",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"typescript",
|
|
10
|
+
"bem",
|
|
11
|
+
"reg",
|
|
12
|
+
"utils"
|
|
13
|
+
],
|
|
14
|
+
"main": "dist/index.js",
|
|
15
|
+
"module": "dist/index.js",
|
|
16
|
+
"types": "dist/index.d.ts",
|
|
17
|
+
"scripts": {
|
|
18
|
+
"start": "cross-env mode=publish vite --host --port 9999",
|
|
19
|
+
"build": "rimraf dist && pnpm run sass && pnpm run build-rollup",
|
|
20
|
+
"build-rollup": "cross-env mode=publish rollup -c",
|
|
21
|
+
"build-ts": "tsc && tsc --module esnext",
|
|
22
|
+
"sass": "sass src/styles:src/styles",
|
|
23
|
+
"release": "npm publish --access public",
|
|
24
|
+
"lint": "eslint --fix src/**/*.ts"
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"@antfu/eslint-config": "^6.1.0",
|
|
28
|
+
"eslint-plugin-format": "^1.0.2",
|
|
29
|
+
"sass": "^1.93.3",
|
|
30
|
+
"unplugin-auto-import": "^20.2.0",
|
|
31
|
+
"vue": "^3.5.18",
|
|
32
|
+
"typescript": "^5.7.3",
|
|
33
|
+
"pinia": "^3.0.3",
|
|
34
|
+
"axios": "^1.11.0",
|
|
35
|
+
"crypto-js": "^4.2.0",
|
|
36
|
+
"element-plus": "^2.10.5",
|
|
37
|
+
"vite": "^7.0.6"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@vitejs/plugin-vue": "^6.0.1",
|
|
41
|
+
"json-bigint": "^1.0.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@rollup/plugin-commonjs": "^28.0.2",
|
|
45
|
+
"@rollup/plugin-node-resolve": "^16.0.0",
|
|
46
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
47
|
+
"@rollup/plugin-typescript": "^12.1.2",
|
|
48
|
+
"@types/crypto-js": "^4.2.2",
|
|
49
|
+
"@types/json-bigint": "^1.0.4",
|
|
50
|
+
"cross-env": "^10.1.0",
|
|
51
|
+
"rimraf": "^6.0.1",
|
|
52
|
+
"rollup": "^4.34.4",
|
|
53
|
+
"rollup-plugin-copy": "^3.5.0",
|
|
54
|
+
"tslib": "^2.8.1"
|
|
55
|
+
}
|
|
56
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# @hzw-tech/utils
|
|
2
|
+
|
|
3
|
+
简称ftw,ts前端工具包,包含常用css类以及ts工具方法等。
|
|
4
|
+
|
|
5
|
+
## 1.安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm i @hzw-tech/utils
|
|
9
|
+
// 或
|
|
10
|
+
yarn add @hzw-tech/utils
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## 2.使用
|
|
14
|
+
|
|
15
|
+
### vue项目使用
|
|
16
|
+
|
|
17
|
+
main.ts文件中:
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import hzwUtils from '@hzw-tech/utils'
|
|
21
|
+
import { createPinia } from 'pinia'
|
|
22
|
+
import { createApp } from 'vue'
|
|
23
|
+
import App from './App.vue'
|
|
24
|
+
import '@hzw-tech/utils/dist/styles/index.scss'// 引入全局样式文件
|
|
25
|
+
|
|
26
|
+
const app = createApp(App)
|
|
27
|
+
app.use(router)
|
|
28
|
+
app.mount('#app')
|
|
29
|
+
app.use(hzwUtils, { storage: { prefix: 'hzw' } })
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
之后可以在ts文件和vue中使用bem,utils等工具方法,比如
|
|
33
|
+
|
|
34
|
+
```html
|
|
35
|
+
<template>
|
|
36
|
+
<h1 :class="[css.bm('color', 'red')]">132</h1>
|
|
37
|
+
</template>
|
|
38
|
+
<script>
|
|
39
|
+
console.log('aes:', utils.aes.encrypt('test'))
|
|
40
|
+
</script>
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### ts支持
|
|
45
|
+
|
|
46
|
+
在项目的tsconfig.json中将@hzw-tech/utils相关ts声明文件加入到types中,这样可以在ts中获得类型提示
|
|
47
|
+
|
|
48
|
+
```json
|
|
49
|
+
{
|
|
50
|
+
"compilerOptions": {
|
|
51
|
+
"types": ["@hzw-tech/utils/dist/types/index", "@hzw-tech/utils/dist/types/global"]
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### vite配置
|
|
57
|
+
|
|
58
|
+
在vite中配置autoImport后,会将ftw的相关方法注入到ts和vue文件中
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
import vite from '@hzw-tech/utils/dist/vite'
|
|
62
|
+
import vue from '@vitejs/plugin-vue'
|
|
63
|
+
import { defineConfig } from 'vite'
|
|
64
|
+
|
|
65
|
+
// https://vite.dev/config/
|
|
66
|
+
export default defineConfig({
|
|
67
|
+
plugins: [vue(), vite.autoImport()],
|
|
68
|
+
css: {
|
|
69
|
+
preprocessorOptions: {
|
|
70
|
+
// 引入通用的全局mixin和变量
|
|
71
|
+
scss: vite.scss(),
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
})
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### 主题修改,自定义scss变量
|
|
78
|
+
|
|
79
|
+
1.新建一个scss文件,比如src/styles/index.scss,内容如下:
|
|
80
|
+
|
|
81
|
+
```scss
|
|
82
|
+
@forward '@hzw-tech/utils/dist/styles/reference/config.scss' with (
|
|
83
|
+
$colors: (
|
|
84
|
+
'red': blue,
|
|
85
|
+
//你的自定义变量
|
|
86
|
+
)
|
|
87
|
+
);
|
|
88
|
+
@forward '@hzw-tech/utils/dist/styles/reference/index.scss';
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
2.修改vite中全局变量以及mixins的引用
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
{
|
|
96
|
+
css: {
|
|
97
|
+
// https://vitejs.dev/config/shared-options.html#css-preprocessoroptions
|
|
98
|
+
preprocessorOptions: {
|
|
99
|
+
scss: {
|
|
100
|
+
additionalData: '@use "@/styles/index.scss" as *;'
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## 3.工具列表
|
|
108
|
+
|
|
109
|
+
[bem](./dist/ts/bem.d.ts)
|
|
110
|
+
[reg](./dist/ts/reg.d.ts)
|
|
111
|
+
[request](./dist/ts/request.d.ts)
|
|
112
|
+
[validators](./dist/ts/validators.d.ts)
|
|
113
|
+
[utils](./dist/ts/utils.d.ts)
|
|
114
|
+
|
|
115
|
+
[通用样式大全](./dist/styles/index.css)
|