@ecolovo/uniapp-components 2.0.6 → 2.0.8
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/badge/badge.vue +2 -2
- package/components/badge/types.d.ts +0 -2
- package/components/badge/types.js +1 -4
- package/components/badge/types.ts +0 -6
- package/components/button/button.vue +7 -7
- package/components/button/types.d.ts +0 -2
- package/components/button/types.js +1 -4
- package/components/button/types.ts +0 -6
- package/components/checkbox/checkbox.vue +3 -3
- package/components/checkbox/types.d.ts +0 -2
- package/components/checkbox/types.js +1 -4
- package/components/checkbox/types.ts +0 -8
- package/components/checkbox-group/checkbox-group.vue +2 -2
- package/components/checkbox-group/types.d.ts +0 -2
- package/components/checkbox-group/types.js +1 -8
- package/components/checkbox-group/types.ts +0 -12
- package/components/checkbox-group2/checkbox-group2.vue +3 -3
- package/components/date-picker/date-picker.vue +5 -3
- package/components/date-picker/types.d.ts +0 -2
- package/components/date-picker/types.js +1 -4
- package/components/date-picker/types.ts +0 -8
- package/components/dialog/dialog.vue +2 -2
- package/components/dialog/types.d.ts +0 -2
- package/components/dialog/types.js +1 -4
- package/components/dialog/types.ts +0 -6
- package/components/dropdown/dropdown.vue +6 -6
- package/components/dropdown/types.d.ts +0 -2
- package/components/dropdown/types.js +1 -4
- package/components/dropdown/types.ts +0 -8
- package/components/empty/empty.vue +2 -2
- package/components/empty/types.d.ts +0 -2
- package/components/empty/types.js +1 -9
- package/components/empty/types.ts +0 -11
- package/components/flex/flex.vue +2 -2
- package/components/flex/types.d.ts +0 -2
- package/components/flex/types.js +1 -4
- package/components/flex/types.ts +0 -6
- package/components/form/form.vue +2 -2
- package/components/form/types.d.ts +0 -2
- package/components/form/types.js +1 -4
- package/components/form/types.ts +0 -6
- package/components/form-item/form-item.vue +2 -2
- package/components/form-item/types.d.ts +0 -2
- package/components/form-item/types.js +1 -4
- package/components/form-item/types.ts +0 -8
- package/components/icon/icon.vue +60 -2
- package/components/image/image.vue +3 -2
- package/components/image/types.d.ts +0 -2
- package/components/image/types.js +1 -4
- package/components/image/types.ts +0 -6
- package/components/input/input.vue +2 -2
- package/components/input/password-input.vue +2 -2
- package/components/input/types.d.ts +0 -4
- package/components/input/types.js +1 -8
- package/components/input/types.ts +0 -14
- package/components/list-page/list-page.vue +2 -2
- package/components/list-page/types.d.ts +0 -2
- package/components/list-page/types.js +1 -4
- package/components/list-page/types.ts +0 -8
- package/components/load-more/load-more.vue +2 -2
- package/components/load-more/types.d.ts +0 -2
- package/components/load-more/types.js +1 -4
- package/components/load-more/types.ts +0 -8
- package/components/loading/animations/loading-animation3.vue +19 -9
- package/components/loading/animations/loading-animation4.vue +2 -1
- package/components/loading/loading.vue +2 -2
- package/components/loading/types.d.ts +0 -2
- package/components/loading/types.js +1 -4
- package/components/loading/types.ts +0 -8
- package/components/message-box/message-box.vue +2 -2
- package/components/message-box/types.d.ts +0 -2
- package/components/message-box/types.js +1 -4
- package/components/message-box/types.ts +0 -8
- package/components/number-dialog/number-dialog.vue +2 -2
- package/components/number-dialog/types.d.ts +0 -2
- package/components/number-dialog/types.js +1 -4
- package/components/number-dialog/types.ts +0 -8
- package/components/number-input/number-input.vue +4 -4
- package/components/number-input/types.d.ts +0 -2
- package/components/number-input/types.js +1 -4
- package/components/number-input/types.ts +0 -8
- package/components/numpad/numpad.vue +2 -2
- package/components/numpad/types.d.ts +0 -2
- package/components/numpad/types.js +1 -4
- package/components/numpad/types.ts +0 -6
- package/components/page/page-body.vue +4 -2
- package/components/page/page-header.vue +7 -7
- package/components/page/page.vue +2 -2
- package/components/page/types.d.ts +0 -4
- package/components/page/types.js +1 -8
- package/components/page/types.ts +0 -14
- package/components/picker/picker-popup.vue +1 -1
- package/components/picker/picker.vue +2 -2
- package/components/picker/types.d.ts +0 -2
- package/components/picker/types.js +1 -4
- package/components/picker/types.ts +0 -6
- package/components/popover/popover-content.vue +13 -14
- package/components/popover/popover.vue +2 -2
- package/components/popover/types.d.ts +0 -2
- package/components/popover/types.js +1 -4
- package/components/popover/types.ts +0 -8
- package/components/popup/popup.vue +2 -2
- package/components/popup/types.d.ts +0 -2
- package/components/popup/types.js +1 -4
- package/components/popup/types.ts +0 -6
- package/components/price/price.vue +2 -2
- package/components/price/types.d.ts +0 -2
- package/components/price/types.js +1 -4
- package/components/price/types.ts +0 -6
- package/components/search/search.vue +2 -2
- package/components/search/types.d.ts +0 -2
- package/components/search/types.js +1 -4
- package/components/search/types.ts +0 -6
- package/components/searching/searching.vue +2 -2
- package/components/searching/types.d.ts +0 -2
- package/components/searching/types.js +1 -4
- package/components/searching/types.ts +0 -8
- package/components/switch/switch.vue +4 -3
- package/components/switch/types.d.ts +0 -2
- package/components/switch/types.js +1 -4
- package/components/switch/types.ts +0 -6
- package/components/tab/tab.vue +5 -3
- package/components/tab/types.d.ts +0 -2
- package/components/tab/types.js +1 -4
- package/components/tab/types.ts +0 -6
- package/components/textarea/textarea.vue +2 -2
- package/components/textarea/types.d.ts +0 -2
- package/components/textarea/types.js +1 -4
- package/components/textarea/types.ts +0 -8
- package/components/upload/composable.ts +3 -3
- package/components/upload/media-upload.vue +4 -3
- package/components/upload/types.d.ts +0 -2
- package/components/upload/types.js +1 -4
- package/components/upload/types.ts +0 -8
- package/composable/component-name.js +2 -2
- package/composable/component-name.ts +2 -2
- package/composable/page.js +2 -2
- package/composable/page.ts +2 -2
- package/configs/index.d.ts +9 -45
- package/configs/index.js +9 -70
- package/configs/index.ts +9 -103
- package/globals.d.ts +8 -0
- package/globals.ts +7 -0
- package/index.d.ts +0 -1
- package/index.js +0 -1
- package/index.ts +0 -1
- package/package.json +1 -2
- package/utils/upload.ts +1 -1
- package/vite.d.ts +22 -0
- package/vite.js +68 -0
- package/vite.ts +107 -0
- package/init.d.ts +0 -21
- package/init.js +0 -91
- package/init.ts +0 -119
|
@@ -48,7 +48,7 @@ const useUpload = <
|
|
|
48
48
|
event: 'update:modelValue',
|
|
49
49
|
value: UniApp.UploadMediaFile[]
|
|
50
50
|
) => void) &
|
|
51
|
-
((event: 'change', value: UniApp.UploadMediaFile[]) => void)
|
|
51
|
+
((event: 'change', value: UniApp.UploadMediaFile[]) => void),
|
|
52
52
|
>(
|
|
53
53
|
props: CommonProps,
|
|
54
54
|
emit: Emit
|
|
@@ -172,11 +172,11 @@ const useUpload = <
|
|
|
172
172
|
url: res.url,
|
|
173
173
|
type: file.type,
|
|
174
174
|
uploadStatus: 'success' as const,
|
|
175
|
-
|
|
175
|
+
}
|
|
176
176
|
: {
|
|
177
177
|
...file,
|
|
178
178
|
uploadStatus: 'error' as const,
|
|
179
|
-
|
|
179
|
+
}
|
|
180
180
|
);
|
|
181
181
|
currentValue.value = tempCurrentValue;
|
|
182
182
|
return currentValue.value[index];
|
|
@@ -83,8 +83,9 @@ import AspectCpn from '../aspect/aspect.vue';
|
|
|
83
83
|
import IconCpn from '../icon/icon.vue';
|
|
84
84
|
import ImageCpn from '../image/image.vue';
|
|
85
85
|
import LoadingCpn from '../loading/animations/loading-animation4.vue';
|
|
86
|
-
import { useUpload } from './composable
|
|
87
|
-
import { type CommonProps
|
|
86
|
+
import { useUpload } from './composable';
|
|
87
|
+
import { type CommonProps } from './types';
|
|
88
|
+
import { EC_DEFAULT_PROPS } from '../../configs';
|
|
88
89
|
|
|
89
90
|
defineOptions({
|
|
90
91
|
options: {
|
|
@@ -117,7 +118,7 @@ const props = withDefaults(defineProps<_Props>(), {
|
|
|
117
118
|
source: 'album',
|
|
118
119
|
columns: 4,
|
|
119
120
|
width: undefined,
|
|
120
|
-
...
|
|
121
|
+
...EC_DEFAULT_PROPS.mediaUpload,
|
|
121
122
|
});
|
|
122
123
|
|
|
123
124
|
const emit = defineEmits<{
|
|
@@ -28,11 +28,3 @@ export type ConfigurableMediaUploadProps = {
|
|
|
28
28
|
/** 自动上传文件 */
|
|
29
29
|
autoUpload?: boolean;
|
|
30
30
|
};
|
|
31
|
-
|
|
32
|
-
export let mediaUploadProps: ConfigurableMediaUploadProps = {};
|
|
33
|
-
|
|
34
|
-
export const setDefaultMediaUploadProps = (
|
|
35
|
-
props: ConfigurableMediaUploadProps = {}
|
|
36
|
-
) => {
|
|
37
|
-
mediaUploadProps = props;
|
|
38
|
-
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { kebabCase, pascalCase } from 'case-anything';
|
|
2
|
-
import {
|
|
2
|
+
import { EC_COMPONENT_PREFIX } from '../configs';
|
|
3
3
|
/**
|
|
4
4
|
* 给组件添加基本类名
|
|
5
5
|
*
|
|
@@ -9,7 +9,7 @@ import { componentPrefix } from '../configs';
|
|
|
9
9
|
* @param componentName 组件名称
|
|
10
10
|
*/
|
|
11
11
|
const useClassNames = (componentName) => {
|
|
12
|
-
const pascalCaseClass = pascalCase(
|
|
12
|
+
const pascalCaseClass = pascalCase(EC_COMPONENT_PREFIX) + pascalCase(componentName);
|
|
13
13
|
const kebabCaseClass = kebabCase(pascalCaseClass);
|
|
14
14
|
return [pascalCaseClass, kebabCaseClass];
|
|
15
15
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { kebabCase, pascalCase } from 'case-anything';
|
|
2
|
-
import {
|
|
2
|
+
import { EC_COMPONENT_PREFIX } from '../configs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* 给组件添加基本类名
|
|
@@ -11,7 +11,7 @@ import { componentPrefix } from '../configs';
|
|
|
11
11
|
*/
|
|
12
12
|
const useClassNames = (componentName: string): [string, string] => {
|
|
13
13
|
const pascalCaseClass =
|
|
14
|
-
pascalCase(
|
|
14
|
+
pascalCase(EC_COMPONENT_PREFIX) + pascalCase(componentName);
|
|
15
15
|
const kebabCaseClass = kebabCase(pascalCaseClass);
|
|
16
16
|
return [pascalCaseClass, kebabCaseClass];
|
|
17
17
|
};
|
package/composable/page.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { computed, onMounted, ref } from 'vue';
|
|
2
|
-
import {
|
|
2
|
+
import { EC_TABBAR_LIST } from '../configs';
|
|
3
3
|
/** 当前页面路由 */
|
|
4
4
|
const useCurrentPageRoute = () => {
|
|
5
5
|
/** 当前页面栈 */
|
|
@@ -9,7 +9,7 @@ const useCurrentPageRoute = () => {
|
|
|
9
9
|
return currentPages.value.slice(-1)[0]?.route || '';
|
|
10
10
|
});
|
|
11
11
|
/** 当前页面是否是 tabbar 页面,需配置 tabbarList */
|
|
12
|
-
const isTabbarPage = computed(() =>
|
|
12
|
+
const isTabbarPage = computed(() => EC_TABBAR_LIST.findIndex((item) => item.pagePath === currentPageRoute.value) >= 0);
|
|
13
13
|
onMounted(() => {
|
|
14
14
|
currentPages.value = getCurrentPages() || [];
|
|
15
15
|
});
|
package/composable/page.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { computed, onMounted, ref } from 'vue';
|
|
2
|
-
import {
|
|
2
|
+
import { EC_TABBAR_LIST } from '../configs';
|
|
3
3
|
|
|
4
4
|
/** 当前页面路由 */
|
|
5
5
|
const useCurrentPageRoute = () => {
|
|
@@ -12,7 +12,7 @@ const useCurrentPageRoute = () => {
|
|
|
12
12
|
/** 当前页面是否是 tabbar 页面,需配置 tabbarList */
|
|
13
13
|
const isTabbarPage = computed(
|
|
14
14
|
() =>
|
|
15
|
-
|
|
15
|
+
EC_TABBAR_LIST.findIndex(
|
|
16
16
|
(item) => item.pagePath === currentPageRoute.value
|
|
17
17
|
) >= 0
|
|
18
18
|
);
|
package/configs/index.d.ts
CHANGED
|
@@ -1,49 +1,13 @@
|
|
|
1
1
|
import type { TabBarItem } from '@ecolovo/utils';
|
|
2
2
|
/** 组件前缀 */
|
|
3
|
-
declare
|
|
3
|
+
export declare const EC_COMPONENT_PREFIX = "app";
|
|
4
4
|
/** 首页路径 */
|
|
5
|
-
declare
|
|
5
|
+
export declare const EC_HOME_PATH = "/pages/index/index";
|
|
6
|
+
/** iconFont json 文件列表 */
|
|
7
|
+
export declare const EC_ICON_FONT: IconFontJson[];
|
|
8
|
+
/** 是否使用内部 iconFont */
|
|
9
|
+
export declare const EC_USE_INNER_ICON = true;
|
|
6
10
|
/** tabbar 列表 */
|
|
7
|
-
declare
|
|
8
|
-
/**
|
|
9
|
-
|
|
10
|
-
*
|
|
11
|
-
* @param prefix 组件前缀
|
|
12
|
-
*/
|
|
13
|
-
declare function setComponentPrefix(prefix?: string): void;
|
|
14
|
-
/**
|
|
15
|
-
* 设置首页路径
|
|
16
|
-
*
|
|
17
|
-
* @param path 首页路径
|
|
18
|
-
*/
|
|
19
|
-
declare function setHomePath(path?: string): void;
|
|
20
|
-
/**
|
|
21
|
-
* 设置 tabbar 列表
|
|
22
|
-
*
|
|
23
|
-
* @param list tabbar 列表
|
|
24
|
-
*/
|
|
25
|
-
declare function setTabbarList(list?: TabBarItem[]): void;
|
|
26
|
-
interface IconInfo {
|
|
27
|
-
/** 字体文件名 */
|
|
28
|
-
fontFamily: string;
|
|
29
|
-
/** 图标前缀 */
|
|
30
|
-
prefix: string;
|
|
31
|
-
/** 图标名称 */
|
|
32
|
-
name: string;
|
|
33
|
-
}
|
|
34
|
-
/** iconfont 图标 map */
|
|
35
|
-
declare const iconMap: Map<string, IconInfo>;
|
|
36
|
-
export interface IconFontJson {
|
|
37
|
-
font_family: string;
|
|
38
|
-
css_prefix_text: string;
|
|
39
|
-
glyphs: {
|
|
40
|
-
font_class: string;
|
|
41
|
-
}[];
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* 添加一组图标,传入 iconfont.json 文件内容
|
|
45
|
-
*
|
|
46
|
-
* @param iconJson iconfont.json 文件内容
|
|
47
|
-
*/
|
|
48
|
-
declare function addIcons(iconJson: IconFontJson): void;
|
|
49
|
-
export { componentPrefix, homePath, tabbarList, setComponentPrefix, setHomePath, setTabbarList, iconMap, addIcons, };
|
|
11
|
+
export declare const EC_TABBAR_LIST: TabBarItem[];
|
|
12
|
+
/** 组件默认属性配置 */
|
|
13
|
+
export declare const EC_DEFAULT_PROPS: ComponentsProps;
|
package/configs/index.js
CHANGED
|
@@ -1,73 +1,12 @@
|
|
|
1
|
-
import defaultIconfonts from '../resources/iconfont/uniapp_ui_icon/iconfont.json';
|
|
2
1
|
/** 组件前缀 */
|
|
3
|
-
|
|
2
|
+
export const EC_COMPONENT_PREFIX = 'app';
|
|
4
3
|
/** 首页路径 */
|
|
5
|
-
|
|
4
|
+
export const EC_HOME_PATH = '/pages/index/index';
|
|
5
|
+
/** iconFont json 文件列表 */
|
|
6
|
+
export const EC_ICON_FONT = [];
|
|
7
|
+
/** 是否使用内部 iconFont */
|
|
8
|
+
export const EC_USE_INNER_ICON = true;
|
|
6
9
|
/** tabbar 列表 */
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
|
|
10
|
-
*
|
|
11
|
-
* @param prefix 组件前缀
|
|
12
|
-
*/
|
|
13
|
-
function setComponentPrefix(prefix = 'app') {
|
|
14
|
-
if (!prefix)
|
|
15
|
-
throw new Error('组件前缀不能为空');
|
|
16
|
-
componentPrefix = prefix;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* 设置首页路径
|
|
20
|
-
*
|
|
21
|
-
* @param path 首页路径
|
|
22
|
-
*/
|
|
23
|
-
function setHomePath(path = '/pages/index/index') {
|
|
24
|
-
if (!path)
|
|
25
|
-
throw new Error('app 首页不能为空');
|
|
26
|
-
homePath = path;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* 设置 tabbar 列表
|
|
30
|
-
*
|
|
31
|
-
* @param list tabbar 列表
|
|
32
|
-
*/
|
|
33
|
-
function setTabbarList(list = []) {
|
|
34
|
-
if (!list)
|
|
35
|
-
throw new Error('tabbar 列表不能为空');
|
|
36
|
-
tabbarList = list;
|
|
37
|
-
}
|
|
38
|
-
/** iconfont 图标 map */
|
|
39
|
-
const iconMap = new Map();
|
|
40
|
-
/**
|
|
41
|
-
* 添加单个图标
|
|
42
|
-
*
|
|
43
|
-
* @param fontFamily 字体文件名
|
|
44
|
-
* @param prefix 图标前缀
|
|
45
|
-
* @param name 图标名称
|
|
46
|
-
*/
|
|
47
|
-
function addIconToMap(fontFamily, prefix, name) {
|
|
48
|
-
if (iconMap.has(name)) {
|
|
49
|
-
// eslint-disable-next-line no-console
|
|
50
|
-
console.warn(`图标库 "${fontFamily}" 中的图标 "${name}" 在图标库 "${iconMap.get(name).fontFamily}" 中已存在,新的图标将会覆盖已存在的同名图标`);
|
|
51
|
-
}
|
|
52
|
-
iconMap.set(name, {
|
|
53
|
-
fontFamily,
|
|
54
|
-
prefix,
|
|
55
|
-
name,
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* 添加一组图标,传入 iconfont.json 文件内容
|
|
60
|
-
*
|
|
61
|
-
* @param iconJson iconfont.json 文件内容
|
|
62
|
-
*/
|
|
63
|
-
function addIcons(iconJson) {
|
|
64
|
-
const fontFamily = iconJson.font_family;
|
|
65
|
-
const prefix = iconJson.css_prefix_text;
|
|
66
|
-
const glyphs = iconJson.glyphs;
|
|
67
|
-
glyphs.forEach((glyph) => {
|
|
68
|
-
addIconToMap(fontFamily, prefix, glyph.font_class);
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
// 添加内部图标库
|
|
72
|
-
addIcons(defaultIconfonts);
|
|
73
|
-
export { componentPrefix, homePath, tabbarList, setComponentPrefix, setHomePath, setTabbarList, iconMap, addIcons, };
|
|
10
|
+
export const EC_TABBAR_LIST = [];
|
|
11
|
+
/** 组件默认属性配置 */
|
|
12
|
+
export const EC_DEFAULT_PROPS = {};
|
package/configs/index.ts
CHANGED
|
@@ -1,108 +1,14 @@
|
|
|
1
|
-
import defaultIconfonts from '../resources/iconfont/uniapp_ui_icon/iconfont.json';
|
|
2
1
|
import type { TabBarItem } from '@ecolovo/utils';
|
|
3
2
|
|
|
4
3
|
/** 组件前缀 */
|
|
5
|
-
|
|
4
|
+
export const EC_COMPONENT_PREFIX = 'app';
|
|
6
5
|
/** 首页路径 */
|
|
7
|
-
|
|
6
|
+
export const EC_HOME_PATH = '/pages/index/index';
|
|
7
|
+
/** iconFont json 文件列表 */
|
|
8
|
+
export const EC_ICON_FONT: IconFontJson[] = [];
|
|
9
|
+
/** 是否使用内部 iconFont */
|
|
10
|
+
export const EC_USE_INNER_ICON = true;
|
|
8
11
|
/** tabbar 列表 */
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
* 设置组件前缀
|
|
13
|
-
*
|
|
14
|
-
* @param prefix 组件前缀
|
|
15
|
-
*/
|
|
16
|
-
function setComponentPrefix(prefix: string = 'app') {
|
|
17
|
-
if (!prefix) throw new Error('组件前缀不能为空');
|
|
18
|
-
componentPrefix = prefix;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* 设置首页路径
|
|
23
|
-
*
|
|
24
|
-
* @param path 首页路径
|
|
25
|
-
*/
|
|
26
|
-
function setHomePath(path: string = '/pages/index/index') {
|
|
27
|
-
if (!path) throw new Error('app 首页不能为空');
|
|
28
|
-
homePath = path;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* 设置 tabbar 列表
|
|
33
|
-
*
|
|
34
|
-
* @param list tabbar 列表
|
|
35
|
-
*/
|
|
36
|
-
function setTabbarList(list: TabBarItem[] = []) {
|
|
37
|
-
if (!list) throw new Error('tabbar 列表不能为空');
|
|
38
|
-
tabbarList = list;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
interface IconInfo {
|
|
42
|
-
/** 字体文件名 */
|
|
43
|
-
fontFamily: string;
|
|
44
|
-
/** 图标前缀 */
|
|
45
|
-
prefix: string;
|
|
46
|
-
/** 图标名称 */
|
|
47
|
-
name: string;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/** iconfont 图标 map */
|
|
51
|
-
const iconMap: Map<string, IconInfo> = new Map();
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* 添加单个图标
|
|
55
|
-
*
|
|
56
|
-
* @param fontFamily 字体文件名
|
|
57
|
-
* @param prefix 图标前缀
|
|
58
|
-
* @param name 图标名称
|
|
59
|
-
*/
|
|
60
|
-
function addIconToMap(fontFamily: string, prefix: string, name: string) {
|
|
61
|
-
if (iconMap.has(name)) {
|
|
62
|
-
// eslint-disable-next-line no-console
|
|
63
|
-
console.warn(
|
|
64
|
-
`图标库 "${fontFamily}" 中的图标 "${name}" 在图标库 "${
|
|
65
|
-
iconMap.get(name)!.fontFamily
|
|
66
|
-
}" 中已存在,新的图标将会覆盖已存在的同名图标`
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
iconMap.set(name, {
|
|
70
|
-
fontFamily,
|
|
71
|
-
prefix,
|
|
72
|
-
name,
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export interface IconFontJson {
|
|
77
|
-
font_family: string;
|
|
78
|
-
css_prefix_text: string;
|
|
79
|
-
glyphs: { font_class: string }[];
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* 添加一组图标,传入 iconfont.json 文件内容
|
|
84
|
-
*
|
|
85
|
-
* @param iconJson iconfont.json 文件内容
|
|
86
|
-
*/
|
|
87
|
-
function addIcons(iconJson: IconFontJson) {
|
|
88
|
-
const fontFamily = iconJson.font_family;
|
|
89
|
-
const prefix = iconJson.css_prefix_text;
|
|
90
|
-
const glyphs = iconJson.glyphs;
|
|
91
|
-
glyphs.forEach((glyph) => {
|
|
92
|
-
addIconToMap(fontFamily, prefix, glyph.font_class);
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// 添加内部图标库
|
|
97
|
-
addIcons(defaultIconfonts);
|
|
98
|
-
|
|
99
|
-
export {
|
|
100
|
-
componentPrefix,
|
|
101
|
-
homePath,
|
|
102
|
-
tabbarList,
|
|
103
|
-
setComponentPrefix,
|
|
104
|
-
setHomePath,
|
|
105
|
-
setTabbarList,
|
|
106
|
-
iconMap,
|
|
107
|
-
addIcons,
|
|
108
|
-
};
|
|
12
|
+
export const EC_TABBAR_LIST: TabBarItem[] = [];
|
|
13
|
+
/** 组件默认属性配置 */
|
|
14
|
+
export const EC_DEFAULT_PROPS: ComponentsProps = {};
|
package/globals.d.ts
CHANGED
|
@@ -21,6 +21,14 @@ declare global {
|
|
|
21
21
|
deltaY: number;
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
+
/** iconFont Json 文件内容 */
|
|
25
|
+
interface IconFontJson {
|
|
26
|
+
font_family: string;
|
|
27
|
+
css_prefix_text: string;
|
|
28
|
+
glyphs: {
|
|
29
|
+
font_class: string;
|
|
30
|
+
}[];
|
|
31
|
+
}
|
|
24
32
|
namespace UniApp {
|
|
25
33
|
type EventWithDetail<T extends Record<string, any>> = {
|
|
26
34
|
detail: T;
|
package/globals.ts
CHANGED
|
@@ -25,6 +25,13 @@ declare global {
|
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
/** iconFont Json 文件内容 */
|
|
29
|
+
interface IconFontJson {
|
|
30
|
+
font_family: string;
|
|
31
|
+
css_prefix_text: string;
|
|
32
|
+
glyphs: { font_class: string }[];
|
|
33
|
+
}
|
|
34
|
+
|
|
28
35
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
29
36
|
namespace UniApp {
|
|
30
37
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
package/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecolovo/uniapp-components",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.8",
|
|
4
4
|
"description": "Ecolovo UniApp Vue3 组件库",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"components",
|
|
@@ -35,7 +35,6 @@
|
|
|
35
35
|
"globals": "^17.4.0",
|
|
36
36
|
"jiti": "^2.7.0",
|
|
37
37
|
"miniprogram-api-typings": "^5.2.1",
|
|
38
|
-
"prettier": "^2.8.8",
|
|
39
38
|
"sass-embedded": "^1.100.0",
|
|
40
39
|
"typescript": "^5.9.3",
|
|
41
40
|
"vite": "^8.1.3",
|
package/utils/upload.ts
CHANGED
package/vite.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
import type { TabBarItem } from '@ecolovo/utils';
|
|
3
|
+
export interface ComponentsConfigs {
|
|
4
|
+
/** 组件前缀,默认为 'app' */
|
|
5
|
+
prefix?: string;
|
|
6
|
+
/** 首页路径 */
|
|
7
|
+
homePath?: string;
|
|
8
|
+
/** iconFont json 文件列表 */
|
|
9
|
+
iconFonts?: IconFontJson[];
|
|
10
|
+
/** 是否使用内部 iconFont */
|
|
11
|
+
useInnerIcon?: boolean;
|
|
12
|
+
/** tabbar 页面列表 */
|
|
13
|
+
tabbarList?: TabBarItem[];
|
|
14
|
+
/** 组件默认参数配置 */
|
|
15
|
+
componentsProps?: ComponentsProps;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* 覆盖 @ecolovo/uniapp-components 库中 configs/index 导出变量的默认值。
|
|
19
|
+
* 原理:在 load 阶段拦截库的 configs/index 源码,将 `export const xxx = 默认值;`
|
|
20
|
+
* 中的默认值替换为插件配置的字面量,不修改库源文件本身。
|
|
21
|
+
*/
|
|
22
|
+
export default function configComponents(options?: ComponentsConfigs): Plugin;
|
package/vite.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
const configKeys = {
|
|
3
|
+
prefix: 'EC_COMPONENT_PREFIX',
|
|
4
|
+
homePath: 'EC_HOME_PATH',
|
|
5
|
+
iconFonts: 'EC_ICON_FONT',
|
|
6
|
+
useInnerIcon: 'EC_USE_INNER_ICON',
|
|
7
|
+
tabbarList: 'EC_TABBAR_LIST',
|
|
8
|
+
componentsProps: 'EC_DEFAULT_PROPS',
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* 匹配 uniapp-components 库中的 configs/index 入口文件(.ts / .js 两种产物)
|
|
12
|
+
*/
|
|
13
|
+
const CONFIGS_INDEX_RE = /@ecolovo[\\/]uniapp-components[\\/]configs[\\/]index\.([cm]?[jt]s)$/;
|
|
14
|
+
/** 将配置值序列化为合法的 JS 表达式 */
|
|
15
|
+
function serializeValue(value) {
|
|
16
|
+
return JSON.stringify(value, null, '\t');
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* 覆盖 @ecolovo/uniapp-components 库中 configs/index 导出变量的默认值。
|
|
20
|
+
* 原理:在 load 阶段拦截库的 configs/index 源码,将 `export const xxx = 默认值;`
|
|
21
|
+
* 中的默认值替换为插件配置的字面量,不修改库源文件本身。
|
|
22
|
+
*/
|
|
23
|
+
export default function configComponents(options = {}) {
|
|
24
|
+
// 转换结果缓存(key: 文件路径)
|
|
25
|
+
const cache = new Map();
|
|
26
|
+
return {
|
|
27
|
+
name: 'vite-plugin-config-ecolovo-components',
|
|
28
|
+
enforce: 'pre',
|
|
29
|
+
config() {
|
|
30
|
+
return {
|
|
31
|
+
optimizeDeps: {
|
|
32
|
+
// 避免依赖预构建(esbuild)抢先打包该库,确保 load 钩子能拦截到源码
|
|
33
|
+
exclude: ['@ecolovo/uniapp-components'],
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
load(id) {
|
|
38
|
+
const file = id.split('?')[0];
|
|
39
|
+
const posixPath = file.replace(/\\/g, '/');
|
|
40
|
+
// 只处理库的 configs/index 运行时源码,跳过类型声明文件
|
|
41
|
+
if (/\.d\.ts$/.test(posixPath) ||
|
|
42
|
+
!CONFIGS_INDEX_RE.test(posixPath)) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
const cached = cache.get(file);
|
|
46
|
+
if (cached !== undefined)
|
|
47
|
+
return cached;
|
|
48
|
+
let result = fs.readFileSync(file, 'utf-8');
|
|
49
|
+
for (const [key, value] of Object.entries(options)) {
|
|
50
|
+
// 值为 undefined 时保留库的默认值
|
|
51
|
+
if (value === undefined)
|
|
52
|
+
continue;
|
|
53
|
+
const realKey = configKeys[key];
|
|
54
|
+
// 匹配 `export const KEY ... = 默认值;`,默认值以语句内首个分号/换行结束
|
|
55
|
+
const re = new RegExp(`(export\\s+(?:const|let|var)\\s+${realKey}\\b[^=]*?=\\s*)([^;\\n]+)(;)`);
|
|
56
|
+
if (!re.test(result)) {
|
|
57
|
+
this.warn(`[default-params] configs/index 中未找到导出变量 ${realKey},已跳过替换`);
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
result = result.replace(re, (_match, prefix, _old, semi) => {
|
|
61
|
+
return prefix + serializeValue(value) + semi;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
cache.set(file, result);
|
|
65
|
+
return result;
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
}
|
package/vite.ts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import type { Plugin } from 'vite';
|
|
3
|
+
import type { TabBarItem } from '@ecolovo/utils';
|
|
4
|
+
|
|
5
|
+
export interface ComponentsConfigs {
|
|
6
|
+
/** 组件前缀,默认为 'app' */
|
|
7
|
+
prefix?: string;
|
|
8
|
+
/** 首页路径 */
|
|
9
|
+
homePath?: string;
|
|
10
|
+
/** iconFont json 文件列表 */
|
|
11
|
+
iconFonts?: IconFontJson[];
|
|
12
|
+
/** 是否使用内部 iconFont */
|
|
13
|
+
useInnerIcon?: boolean;
|
|
14
|
+
/** tabbar 页面列表 */
|
|
15
|
+
tabbarList?: TabBarItem[];
|
|
16
|
+
/** 组件默认参数配置 */
|
|
17
|
+
componentsProps?: ComponentsProps;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const configKeys = {
|
|
21
|
+
prefix: 'EC_COMPONENT_PREFIX',
|
|
22
|
+
homePath: 'EC_HOME_PATH',
|
|
23
|
+
iconFonts: 'EC_ICON_FONT',
|
|
24
|
+
useInnerIcon: 'EC_USE_INNER_ICON',
|
|
25
|
+
tabbarList: 'EC_TABBAR_LIST',
|
|
26
|
+
componentsProps: 'EC_DEFAULT_PROPS',
|
|
27
|
+
} as const;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 匹配 uniapp-components 库中的 configs/index 入口文件(.ts / .js 两种产物)
|
|
31
|
+
*/
|
|
32
|
+
const CONFIGS_INDEX_RE =
|
|
33
|
+
/@ecolovo[\\/]uniapp-components[\\/]configs[\\/]index\.([cm]?[jt]s)$/;
|
|
34
|
+
|
|
35
|
+
/** 将配置值序列化为合法的 JS 表达式 */
|
|
36
|
+
function serializeValue(value: unknown): string {
|
|
37
|
+
return JSON.stringify(value, null, '\t');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 覆盖 @ecolovo/uniapp-components 库中 configs/index 导出变量的默认值。
|
|
42
|
+
* 原理:在 load 阶段拦截库的 configs/index 源码,将 `export const xxx = 默认值;`
|
|
43
|
+
* 中的默认值替换为插件配置的字面量,不修改库源文件本身。
|
|
44
|
+
*/
|
|
45
|
+
export default function configComponents(
|
|
46
|
+
options: ComponentsConfigs = {}
|
|
47
|
+
): Plugin {
|
|
48
|
+
// 转换结果缓存(key: 文件路径)
|
|
49
|
+
const cache = new Map<string, string>();
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
name: 'vite-plugin-config-ecolovo-components',
|
|
53
|
+
enforce: 'pre',
|
|
54
|
+
config() {
|
|
55
|
+
return {
|
|
56
|
+
optimizeDeps: {
|
|
57
|
+
// 避免依赖预构建(esbuild)抢先打包该库,确保 load 钩子能拦截到源码
|
|
58
|
+
exclude: ['@ecolovo/uniapp-components'],
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
load(id) {
|
|
63
|
+
const file = id.split('?')[0];
|
|
64
|
+
const posixPath = file.replace(/\\/g, '/');
|
|
65
|
+
|
|
66
|
+
// 只处理库的 configs/index 运行时源码,跳过类型声明文件
|
|
67
|
+
if (
|
|
68
|
+
/\.d\.ts$/.test(posixPath) ||
|
|
69
|
+
!CONFIGS_INDEX_RE.test(posixPath)
|
|
70
|
+
) {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const cached = cache.get(file);
|
|
75
|
+
if (cached !== undefined) return cached;
|
|
76
|
+
|
|
77
|
+
let result = fs.readFileSync(file, 'utf-8');
|
|
78
|
+
|
|
79
|
+
for (const [key, value] of Object.entries(options)) {
|
|
80
|
+
// 值为 undefined 时保留库的默认值
|
|
81
|
+
if (value === undefined) continue;
|
|
82
|
+
|
|
83
|
+
const realKey = configKeys[key as keyof typeof configKeys];
|
|
84
|
+
|
|
85
|
+
// 匹配 `export const KEY ... = 默认值;`,默认值以语句内首个分号/换行结束
|
|
86
|
+
const re = new RegExp(
|
|
87
|
+
`(export\\s+(?:const|let|var)\\s+${realKey}\\b[^=]*?=\\s*)([^;\\n]+)(;)`
|
|
88
|
+
);
|
|
89
|
+
if (!re.test(result)) {
|
|
90
|
+
this.warn(
|
|
91
|
+
`[default-params] configs/index 中未找到导出变量 ${realKey},已跳过替换`
|
|
92
|
+
);
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
result = result.replace(
|
|
96
|
+
re,
|
|
97
|
+
(_match, prefix: string, _old: string, semi: string) => {
|
|
98
|
+
return prefix + serializeValue(value) + semi;
|
|
99
|
+
}
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
cache.set(file, result);
|
|
104
|
+
return result;
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
}
|