@ecolovo/uniapp-components 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/components/aspect/aspect.vue +43 -0
- package/components/badge/badge.vue +88 -0
- package/components/button/button.vue +409 -0
- package/components/checkbox/checkbox.vue +183 -0
- package/components/checkbox-group/checkbox-group.vue +101 -0
- package/components/checkbox-group2/checkbox-group2.vue +138 -0
- package/components/checkbox-group2/checkbox.vue +103 -0
- package/components/data-list/data-list.vue +130 -0
- package/components/date-picker/date-picker-view.vue +181 -0
- package/components/date-picker/date-picker.vue +237 -0
- package/components/datetime-picker/datetime-picker-view.vue +209 -0
- package/components/datetime-picker/datetime-picker.vue +235 -0
- package/components/dialog/dialog-content.vue +162 -0
- package/components/dialog/dialog.vue +166 -0
- package/components/dropdown/dropdown.vue +145 -0
- package/components/empty/empty.vue +102 -0
- package/components/flex/flex.vue +76 -0
- package/components/form/form.vue +43 -0
- package/components/form/mixin.js +13 -0
- package/components/form-item/form-item.vue +141 -0
- package/components/icon/icon.vue +114 -0
- package/components/image/image.vue +61 -0
- package/components/input/input.vue +154 -0
- package/components/input/password-input.vue +95 -0
- package/components/list-page/list-page.js +10 -0
- package/components/list-page/list-page.vue +150 -0
- package/components/load-more/load-more.vue +97 -0
- package/components/loading/animations/loading-animation1.vue +92 -0
- package/components/loading/animations/loading-animation2.vue +28 -0
- package/components/loading/animations/loading-animation3.vue +81 -0
- package/components/loading/animations/loading-animation4.vue +74 -0
- package/components/loading/loading.vue +91 -0
- package/components/message-box/message-box.vue +60 -0
- package/components/number-dialog/number-dialog.vue +360 -0
- package/components/number-input/number-input.vue +352 -0
- package/components/numpad/numpad.vue +224 -0
- package/components/page/page-body.vue +227 -0
- package/components/page/page-footer.vue +75 -0
- package/components/page/page-header.vue +222 -0
- package/components/page/page.vue +128 -0
- package/components/picker/picker-popup.vue +295 -0
- package/components/picker/picker.vue +151 -0
- package/components/popover/popover-content.vue +255 -0
- package/components/popover/popover-mask.vue +113 -0
- package/components/popover/popover.vue +84 -0
- package/components/popup/popup-content.vue +162 -0
- package/components/popup/popup.vue +168 -0
- package/components/price/price.vue +104 -0
- package/components/search/search.vue +220 -0
- package/components/searching/searching.vue +86 -0
- package/components/selector/selector.vue +86 -0
- package/components/switch/switch.vue +180 -0
- package/components/tab/tab.vue +235 -0
- package/components/table/table.vue +112 -0
- package/components/textarea/textarea.vue +192 -0
- package/components/time-picker/time-picker-view.vue +127 -0
- package/components/time-picker/time-picker.vue +140 -0
- package/components/uploader/download.js +81 -0
- package/components/uploader/file-uploader.vue +52 -0
- package/components/uploader/files.js +225 -0
- package/components/uploader/media-uploader.vue +133 -0
- package/components/uploader/mixin.js +106 -0
- package/components/uploader/uni.js +38 -0
- package/components/uploader/upload-button.vue +29 -0
- package/components/uploader/uploader copy.vue +547 -0
- package/components/uploader/uploader.vue +117 -0
- package/configs/index.js +41 -0
- package/easyCom.js +25 -0
- package/init.js +17 -0
- package/mixins/componentName.js +32 -0
- package/mixins/listPage.js +1 -0
- package/mixins/windowInfo.js +1 -0
- package/package.json +12 -0
- package/resources/iconfont/uniapp_ui_icon/demo.css +539 -0
- package/resources/iconfont/uniapp_ui_icon/demo_index.html +555 -0
- package/resources/iconfont/uniapp_ui_icon/iconfont.css +78 -0
- package/resources/iconfont/uniapp_ui_icon/iconfont.js +1 -0
- package/resources/iconfont/uniapp_ui_icon/iconfont.json +121 -0
- package/resources/iconfont/uniapp_ui_icon/iconfont.woff2 +0 -0
- package/resources/image/empty.svg +13 -0
- package/styles/global.scss +24 -0
- package/styles/index.scss +2 -0
- package/styles/utils/css-var.scss +87 -0
- package/styles/utils/ellipsis.scss +26 -0
- package/styles/utils/global-var.scss +11 -0
- package/styles/utils/index.scss +5 -0
- package/styles/utils/selector.scss +5 -0
- package/styles/utils/z-index.scss +10 -0
- package/styles/var/component.scss +242 -0
- package/styles/var/index.scss +2 -0
- package/styles/var/theme.scss +40 -0
- package/utils/date.js +151 -0
- package/utils/floor.js +20 -0
- package/utils/freezeDeep.js +19 -0
- package/utils/price.js +32 -0
- package/utils/round.js +22 -0
- package/utils/windowInfo.js +77 -0
package/utils/date.js
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 将Date 对象、时间戳或时间格式字符串转为 Date 对象
|
|
3
|
+
* @param {Date | number | string} dateValue Date 对象、时间戳或时间格式字符串
|
|
4
|
+
* @returns {Date} Date 对象
|
|
5
|
+
*/
|
|
6
|
+
export function toDate(dateValue) {
|
|
7
|
+
if (dateValue instanceof Date) return new Date(dateValue);
|
|
8
|
+
if (typeof dateValue === 'number') return new Date(dateValue);
|
|
9
|
+
if (!dateValue) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
if (typeof dateValue !== 'string') {
|
|
13
|
+
throw new Error("dateValue's type is invalid");
|
|
14
|
+
}
|
|
15
|
+
// 兼容 iOS 日期格式
|
|
16
|
+
const result = new Date(dateValue.replace(/-/g, '/'));
|
|
17
|
+
if (isNaN(result.getTime())) {
|
|
18
|
+
throw new Error('dateValue cannot be parsed to Date object');
|
|
19
|
+
}
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 格式化日期
|
|
25
|
+
*
|
|
26
|
+
* format 参数说明:
|
|
27
|
+
* - Y: 年
|
|
28
|
+
* - M: 月
|
|
29
|
+
* - D: 日
|
|
30
|
+
* - H: 时
|
|
31
|
+
* - m: 分
|
|
32
|
+
* - s: 秒
|
|
33
|
+
* - S: 毫秒
|
|
34
|
+
* - w: 星期
|
|
35
|
+
* - W: 星期(中文)
|
|
36
|
+
* @param {Date | undefined} date 要格式化的日期对象
|
|
37
|
+
* @param {string} format 格式化参数 默认值 YYYY-MM-DD
|
|
38
|
+
* @returns {string} 格式化后的日期
|
|
39
|
+
*/
|
|
40
|
+
export function formatDate(date, format = formatDate.DATE_WITH_YEAR) {
|
|
41
|
+
if (!date) {
|
|
42
|
+
return '';
|
|
43
|
+
}
|
|
44
|
+
const fullYear = date.getFullYear().toString();
|
|
45
|
+
const year = fullYear.substring(fullYear.length - 2);
|
|
46
|
+
const month = (date.getMonth() + 1).toString();
|
|
47
|
+
const day = date.getDate().toString();
|
|
48
|
+
const hour = date.getHours().toString();
|
|
49
|
+
const min = date.getMinutes().toString();
|
|
50
|
+
const sec = date.getSeconds().toString();
|
|
51
|
+
const ms = date.getMilliseconds().toString();
|
|
52
|
+
const week = date.getDay().toString();
|
|
53
|
+
let weekCN = '';
|
|
54
|
+
switch (week) {
|
|
55
|
+
case '0':
|
|
56
|
+
weekCN = '日';
|
|
57
|
+
break;
|
|
58
|
+
case '1':
|
|
59
|
+
weekCN = '一';
|
|
60
|
+
break;
|
|
61
|
+
case '2':
|
|
62
|
+
weekCN = '二';
|
|
63
|
+
break;
|
|
64
|
+
case '3':
|
|
65
|
+
weekCN = '三';
|
|
66
|
+
break;
|
|
67
|
+
case '4':
|
|
68
|
+
weekCN = '四';
|
|
69
|
+
break;
|
|
70
|
+
case '5':
|
|
71
|
+
weekCN = '五';
|
|
72
|
+
break;
|
|
73
|
+
case '6':
|
|
74
|
+
weekCN = '六';
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const replacement = [
|
|
79
|
+
{ reg: 'Y{3,4}', val: fullYear, pad: 0 },
|
|
80
|
+
{ reg: 'Y{1,2}', val: year, pad: 0 },
|
|
81
|
+
{ reg: 'M{1,2}', val: month, pad: 2 },
|
|
82
|
+
{ reg: 'D{1,2}', val: day, pad: 2 },
|
|
83
|
+
{ reg: 'H{1,2}', val: hour, pad: 2 },
|
|
84
|
+
{ reg: 'm{1,2}', val: min, pad: 2 },
|
|
85
|
+
{ reg: 's{1,2}', val: sec, pad: 2 },
|
|
86
|
+
{ reg: 'S{1,3}', val: ms, pad: 3 },
|
|
87
|
+
{ reg: 'w', val: week, pad: 0 },
|
|
88
|
+
{ reg: 'W', val: weekCN, pad: 0 },
|
|
89
|
+
];
|
|
90
|
+
|
|
91
|
+
for (let i = 0; i < replacement.length; i++) {
|
|
92
|
+
const r = replacement[i];
|
|
93
|
+
format = format.replace(new RegExp(r.reg, 'g'), function (m) {
|
|
94
|
+
return r.pad > 0 ? r.val.padStart(Math.min(r.pad, m.length), '0') : r.val;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
return format;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** 月日 */
|
|
101
|
+
formatDate.DATE = 'MM-DD';
|
|
102
|
+
/** 年月日 */
|
|
103
|
+
formatDate.DATE_WITH_YEAR = 'YYYY-MM-DD';
|
|
104
|
+
/** 时分秒 */
|
|
105
|
+
formatDate.TIME = 'HH:mm:ss';
|
|
106
|
+
/** 时分秒.毫秒 */
|
|
107
|
+
formatDate.TIME_MS = 'HH:mm:ss.SSS';
|
|
108
|
+
/** 时分 */
|
|
109
|
+
formatDate.TIME_MINUTE = 'HH:mm';
|
|
110
|
+
/** 月日 时分秒 */
|
|
111
|
+
formatDate.DATE_TIME = 'MM-DD HH:mm:ss';
|
|
112
|
+
/** 月日 时分秒.毫秒 */
|
|
113
|
+
formatDate.DATE_TIME_MS = 'MM-DD HH:mm:ss.SSS';
|
|
114
|
+
/** 年月日 时分秒 */
|
|
115
|
+
formatDate.DATE_TIME_WITH_YEAR = 'YYYY-MM-DD HH:mm:ss';
|
|
116
|
+
/** 年月日 时分秒.毫秒 */
|
|
117
|
+
formatDate.DATE_TIME_MS_WITH_YEAR = 'YYYY-MM-DD HH:mm:ss.SSS';
|
|
118
|
+
/** 月日 时分 */
|
|
119
|
+
formatDate.DATE_MINUTE = 'MM-DD HH:mm';
|
|
120
|
+
/** 年月日 时分 */
|
|
121
|
+
formatDate.DATE_MINUTE_WITH_YEAR = 'YYYY-MM-DD HH:mm';
|
|
122
|
+
|
|
123
|
+
/** 时区差 */
|
|
124
|
+
const TIMEZONE_OFFSET = new Date().getTimezoneOffset() * 60 * 1000;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* 获取时间的UTC相对时间戳
|
|
128
|
+
* @param {number | string | Date} date 时间
|
|
129
|
+
* @returns {number} 毫秒数
|
|
130
|
+
*/
|
|
131
|
+
function toDayTimestamp(date) {
|
|
132
|
+
let d = null;
|
|
133
|
+
if (typeof date === 'number') {
|
|
134
|
+
return date - TIMEZONE_OFFSET;
|
|
135
|
+
} else if (typeof date === 'string') {
|
|
136
|
+
d = toDate(date);
|
|
137
|
+
} else if (!(date instanceof Date)) {
|
|
138
|
+
d = new Date();
|
|
139
|
+
}
|
|
140
|
+
return d.getTime() - TIMEZONE_OFFSET;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* 获取两个时间的天数差
|
|
145
|
+
* @param {number | string | Date} day1 时间1
|
|
146
|
+
* @param {number | string | Date} day2 时间2
|
|
147
|
+
* @returns {number} 天数差,负数: day1 < day2
|
|
148
|
+
*/
|
|
149
|
+
export function daysDiff(day1, day2) {
|
|
150
|
+
return Math.floor(toDayTimestamp(day1) / 8.64e7) - Math.floor(toDayTimestamp(day2) / 8.64e7);
|
|
151
|
+
}
|
package/utils/floor.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { round } from './round';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 向下取值
|
|
5
|
+
* @param {number} val 需要处理的数据
|
|
6
|
+
* @param {number} precision 保留小数位数,默认不保留
|
|
7
|
+
* @returns {number} 处理后的数据
|
|
8
|
+
*/
|
|
9
|
+
export function floor(val, precision = 0) {
|
|
10
|
+
return Math.floor(+round(val, precision) + 'e' + precision) / Math.pow(10, precision);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 向下取值,并保留 2 位小数
|
|
15
|
+
* @param {number} val 需要处理的数据
|
|
16
|
+
* @returns {number} 处理后的数据
|
|
17
|
+
*/
|
|
18
|
+
export function floor2(val) {
|
|
19
|
+
return floor(val, 2);
|
|
20
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 深度冻结一个对象
|
|
3
|
+
*
|
|
4
|
+
* 注意:传入的对象和返回的对象是同一个引用,慎用!!
|
|
5
|
+
*
|
|
6
|
+
* @template T
|
|
7
|
+
* @param {T} obj 要被冻结的对象
|
|
8
|
+
* @returns {Readonly<T>}
|
|
9
|
+
*/
|
|
10
|
+
export function freezeDeep(obj) {
|
|
11
|
+
if (!(typeof obj === 'object' && obj)) {
|
|
12
|
+
return obj;
|
|
13
|
+
} else {
|
|
14
|
+
for (let key in obj) {
|
|
15
|
+
freezeDeep(obj[key]);
|
|
16
|
+
}
|
|
17
|
+
return Object.freeze(obj);
|
|
18
|
+
}
|
|
19
|
+
}
|
package/utils/price.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 格式化价格
|
|
3
|
+
* @param {number} price 价格
|
|
4
|
+
* @returns {FormattedPrice}
|
|
5
|
+
*/
|
|
6
|
+
export function formatPrice(price) {
|
|
7
|
+
if (isNaN(price)) {
|
|
8
|
+
return {
|
|
9
|
+
price: '',
|
|
10
|
+
negative: false,
|
|
11
|
+
integer: '',
|
|
12
|
+
decimal: '',
|
|
13
|
+
number: NaN,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
price = Number(price);
|
|
17
|
+
let negative = false;
|
|
18
|
+
if (price < 0) {
|
|
19
|
+
negative = true;
|
|
20
|
+
price = -price;
|
|
21
|
+
}
|
|
22
|
+
const integer = Math.floor(price).toString();
|
|
23
|
+
const decimal = (Math.round(+price + 'e' + 2) % 100).toString().padStart(2, '0');
|
|
24
|
+
const formattedPrice = `${negative ? '-' : ''}${integer}.${decimal}`;
|
|
25
|
+
return {
|
|
26
|
+
price: formattedPrice, // 价格字符串
|
|
27
|
+
negative,
|
|
28
|
+
integer, // 整数部分
|
|
29
|
+
decimal, // 小数部分
|
|
30
|
+
number: Number(formattedPrice),
|
|
31
|
+
};
|
|
32
|
+
}
|
package/utils/round.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 四舍五入处理
|
|
3
|
+
* @param {number} val 需要处理的数据
|
|
4
|
+
* @param {number} precision 保留小数位数,默认不保留
|
|
5
|
+
* @returns {number} 处理后的数据
|
|
6
|
+
*/
|
|
7
|
+
export function round(val, precision = 0) {
|
|
8
|
+
if (val.toString().indexOf('e') >= 0) {
|
|
9
|
+
const exponential = val.toString().split('e');
|
|
10
|
+
return Math.round(exponential[0] + 'e' + (+exponential[1] + precision)) / Math.pow(10, precision);
|
|
11
|
+
}
|
|
12
|
+
return Math.round(+val + 'e' + precision) / Math.pow(10, precision);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 四舍五入处理,并保留 2 位小数
|
|
17
|
+
* @param {number} val 需要处理的数据
|
|
18
|
+
* @returns {number} 处理后的数据
|
|
19
|
+
*/
|
|
20
|
+
export function round2(val) {
|
|
21
|
+
return round(val, 2);
|
|
22
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/** 默认导航栏高度 */
|
|
2
|
+
const NAV_TITLE_HEIGHT = 44;
|
|
3
|
+
/** 胶囊按钮位置信息
|
|
4
|
+
* @type {UniApp.GetMenuButtonBoundingClientRectRes | null}
|
|
5
|
+
*/
|
|
6
|
+
let menuButton = null;
|
|
7
|
+
/** 系统信息
|
|
8
|
+
* @type {UniApp.GetWindowInfoResult | null}
|
|
9
|
+
*/
|
|
10
|
+
let windowInfo = null;
|
|
11
|
+
/** 导航栏高度 */
|
|
12
|
+
let navBarHeight = NAV_TITLE_HEIGHT;
|
|
13
|
+
/** 导航栏顶部距离 */
|
|
14
|
+
let navBarTopOffset = 0;
|
|
15
|
+
/** 导航栏底部距离 */
|
|
16
|
+
let navBarBottomOffset = NAV_TITLE_HEIGHT;
|
|
17
|
+
/** 底部安全区域高度
|
|
18
|
+
* @type {number}
|
|
19
|
+
*/
|
|
20
|
+
let safeAreaInsetBottom = uni.upx2px(50);
|
|
21
|
+
|
|
22
|
+
/* #ifdef MP-WEIXIN || MP-ALIPAY */
|
|
23
|
+
menuButton = uni.getMenuButtonBoundingClientRect();
|
|
24
|
+
/* #endif */
|
|
25
|
+
windowInfo = uni.getWindowInfo();
|
|
26
|
+
// eslint-disable-next-line no-console
|
|
27
|
+
console.log('windowInfo:', windowInfo);
|
|
28
|
+
|
|
29
|
+
if (menuButton) {
|
|
30
|
+
if (navBarHeight < menuButton.height) {
|
|
31
|
+
navBarHeight = menuButton.height + 12;
|
|
32
|
+
}
|
|
33
|
+
navBarTopOffset = menuButton.top - (navBarHeight - menuButton.height) / 3;
|
|
34
|
+
} else {
|
|
35
|
+
navBarTopOffset = windowInfo.safeArea.top || windowInfo.statusBarHeight;
|
|
36
|
+
}
|
|
37
|
+
navBarBottomOffset = navBarTopOffset + navBarHeight;
|
|
38
|
+
const _safeAreaBottom = windowInfo.screenHeight - windowInfo.safeArea.bottom;
|
|
39
|
+
if (_safeAreaBottom) {
|
|
40
|
+
safeAreaInsetBottom = _safeAreaBottom;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** mixin */
|
|
44
|
+
const windowInfoMixin = {
|
|
45
|
+
computed: {
|
|
46
|
+
/** 胶囊按钮位置信息 */
|
|
47
|
+
menuButton: () => menuButton,
|
|
48
|
+
/** 胶囊按钮宽度 */
|
|
49
|
+
menuButtonWidth() {
|
|
50
|
+
return this.menuButton ? 'calc(100vw - ' + this.menuButton.left + 'px)' : '0px';
|
|
51
|
+
},
|
|
52
|
+
/** 系统信息 */
|
|
53
|
+
windowInfo: () => windowInfo,
|
|
54
|
+
/** 导航栏高度 */
|
|
55
|
+
navBarHeight: () => navBarHeight,
|
|
56
|
+
/** 导航栏顶部距离 */
|
|
57
|
+
navBarTopOffset: () => navBarTopOffset,
|
|
58
|
+
/** 导航栏底部距离 */
|
|
59
|
+
navBarBottomOffset: () => navBarBottomOffset,
|
|
60
|
+
/** 底部安全区域高度 */
|
|
61
|
+
safeAreaInsetBottom: () => safeAreaInsetBottom,
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @typedef {ComponentDefinition<{}, {}, ComputedDefinition<typeof windowInfoMixin['computed']>>['$vm']} WindowInfoMixin
|
|
67
|
+
*/
|
|
68
|
+
|
|
69
|
+
export {
|
|
70
|
+
menuButton,
|
|
71
|
+
windowInfo,
|
|
72
|
+
navBarHeight,
|
|
73
|
+
navBarTopOffset,
|
|
74
|
+
navBarBottomOffset,
|
|
75
|
+
safeAreaInsetBottom,
|
|
76
|
+
windowInfoMixin,
|
|
77
|
+
};
|