uview-pro 0.2.2 → 0.2.4
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/changelog.md +44 -0
- package/components/u-action-sheet/u-action-sheet.vue +10 -3
- package/components/u-alert-tips/u-alert-tips.vue +13 -2
- package/components/u-avatar/u-avatar.vue +16 -2
- package/components/u-avatar-cropper/weCropper.js +36 -8
- package/components/u-avatar-cropper/weCropper.ts +28 -7
- package/components/u-back-top/u-back-top.vue +4 -1
- package/components/u-button/u-button.vue +11 -1
- package/components/u-calendar/types.ts +3 -1
- package/components/u-calendar/u-calendar.vue +172 -17
- package/components/u-car-keyboard/u-car-keyboard.vue +22 -3
- package/components/u-cell-item/u-cell-item.vue +13 -2
- package/components/u-checkbox/u-checkbox.vue +78 -62
- package/components/u-checkbox-group/types.ts +1 -1
- package/components/u-checkbox-group/u-checkbox-group.vue +77 -26
- package/components/u-circle-progress/u-circle-progress.vue +6 -2
- package/components/u-city-select/u-city-select.vue +32 -4
- package/components/u-collapse/u-collapse.vue +131 -14
- package/components/u-collapse-item/u-collapse-item.vue +132 -60
- package/components/u-column-notice/u-column-notice.vue +40 -6
- package/components/u-count-down/u-count-down.vue +20 -4
- package/components/u-count-to/u-count-to.vue +9 -2
- package/components/u-divider/u-divider.vue +10 -2
- package/components/u-dropdown/u-dropdown.vue +16 -3
- package/components/u-dropdown-item/u-dropdown-item.vue +6 -1
- package/components/u-field/u-field.vue +23 -4
- package/components/u-form/u-form.vue +5 -1
- package/components/u-form-item/u-form-item.vue +37 -7
- package/components/u-full-screen/u-full-screen.vue +8 -1
- package/components/u-grid-item/u-grid-item.vue +5 -1
- package/components/u-icon/u-icon.vue +15 -2
- package/components/u-image/u-image.vue +10 -2
- package/components/u-input/u-input.vue +19 -4
- package/components/u-keyboard/u-keyboard.vue +13 -2
- package/components/u-lazy-load/u-lazy-load.vue +10 -8
- package/components/u-line-progress/u-line-progress.vue +9 -1
- package/components/u-loading/u-loading.vue +7 -1
- package/components/u-loadmore/u-loadmore.vue +6 -1
- package/components/u-message-input/u-message-input.vue +19 -4
- package/components/u-modal/u-modal.vue +8 -1
- package/components/u-navbar/u-navbar.vue +18 -4
- package/components/u-no-network/u-no-network.vue +3 -1
- package/components/u-notice-bar/u-notice-bar.vue +6 -1
- package/components/u-number-keyboard/u-number-keyboard.vue +19 -6
- package/components/u-picker/u-picker.vue +49 -10
- package/components/u-popup/u-popup.vue +19 -3
- package/components/u-radio/u-radio.vue +19 -5
- package/components/u-radio-group/u-radio-group.vue +11 -1
- package/components/u-read-more/u-read-more.vue +7 -1
- package/components/u-row-notice/u-row-notice.vue +37 -6
- package/components/u-search/u-search.vue +14 -2
- package/components/u-section/u-section.vue +7 -1
- package/components/u-select/u-select.vue +22 -5
- package/components/u-skeleton/u-skeleton.vue +18 -3
- package/components/u-slider/u-slider.vue +11 -2
- package/components/u-steps/u-steps.vue +11 -2
- package/components/u-sticky/u-sticky.vue +4 -1
- package/components/u-swipe-action/u-swipe-action.vue +8 -1
- package/components/u-swiper/u-swiper.vue +31 -6
- package/components/u-switch/u-switch.vue +6 -1
- package/components/u-tabbar/u-tabbar.vue +22 -4
- package/components/u-tabs/u-tabs.vue +8 -1
- package/components/u-tabs-swiper/u-tabs-swiper.vue +21 -3
- package/components/u-tag/u-tag.vue +9 -1
- package/components/u-text/types.ts +4 -1
- package/components/u-text/u-text.vue +18 -3
- package/components/u-upload/types.ts +8 -2
- package/components/u-upload/u-upload.vue +17 -3
- package/iconfont.css +2 -1
- package/index.ts +11 -2
- package/libs/css/style.vue.scss +1 -1
- package/libs/function/$parent.ts +4 -1
- package/libs/function/colorGradient.ts +18 -4
- package/libs/function/deepMerge.ts +2 -1
- package/libs/function/getParent.ts +5 -1
- package/libs/function/md5.ts +17 -5
- package/libs/function/queryParams.ts +5 -1
- package/libs/function/test.ts +7 -3
- package/libs/function/timeFormat.ts +2 -1
- package/libs/function/type2icon.ts +4 -1
- package/libs/hooks/index.ts +1 -1
- package/libs/hooks/useComponent.ts +759 -0
- package/libs/hooks/useEmitter.ts +4 -2
- package/libs/hooks/useParent.ts +22 -20
- package/libs/index.ts +34 -5
- package/libs/request/index.ts +24 -5
- package/libs/util/async-validator.d.ts +16 -3
- package/libs/util/emitter.ts +12 -2
- package/libs/util/eventBus.ts +86 -0
- package/libs/util/logger.ts +364 -0
- package/libs/util/mitt.ts +4 -1
- package/package.json +1 -1
- package/readme.md +3 -1
- package/types/global.d.ts +39 -3
|
@@ -4,7 +4,14 @@
|
|
|
4
4
|
<view>
|
|
5
5
|
<scroll-view scroll-x class="u-scroll-view" :scroll-left="scrollLeft" scroll-with-animation>
|
|
6
6
|
<view class="u-scroll-box" :id="id" :class="{ 'u-tabs-scroll-flex': !isScroll }">
|
|
7
|
-
<view
|
|
7
|
+
<view
|
|
8
|
+
class="u-tab-item u-line-1"
|
|
9
|
+
:id="'u-tab-item-' + index"
|
|
10
|
+
v-for="(item, index) in list"
|
|
11
|
+
:key="index"
|
|
12
|
+
@tap="clickTab(index)"
|
|
13
|
+
:style="tabItemStyle(index)"
|
|
14
|
+
>
|
|
8
15
|
<u-badge :count="item[count] || item['count'] || 0" :offset="offset" size="mini"></u-badge>
|
|
9
16
|
{{ item[name] || item['name'] }}
|
|
10
17
|
</view>
|
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<view class="u-tabs" :style="{ zIndex: zIndex, background: bgColor }">
|
|
3
|
-
<scroll-view
|
|
3
|
+
<scroll-view
|
|
4
|
+
scroll-x
|
|
5
|
+
class="u-scroll-view"
|
|
6
|
+
:scroll-left="scrollLeft"
|
|
7
|
+
scroll-with-animation
|
|
8
|
+
:style="{ zIndex: Number(zIndex) + 1 }"
|
|
9
|
+
>
|
|
4
10
|
<view class="u-tabs-scroll-box" :class="{ 'u-tabs-scroll-flex': !isScroll }">
|
|
5
|
-
<view
|
|
11
|
+
<view
|
|
12
|
+
class="u-tabs-item"
|
|
13
|
+
:style="tabItemStyle(index)"
|
|
14
|
+
v-for="(item, index) in getTabs"
|
|
15
|
+
:key="index"
|
|
16
|
+
:class="[preId + index]"
|
|
17
|
+
@tap="emitTabChange(index)"
|
|
18
|
+
>
|
|
6
19
|
<u-badge :count="item[count] || item['count'] || 0" :offset="offset" size="mini"></u-badge>
|
|
7
20
|
{{ item[name] || item['name'] }}
|
|
8
21
|
</view>
|
|
@@ -96,7 +109,12 @@ function tabItemStyle(index: number) {
|
|
|
96
109
|
height: props.height + 'rpx',
|
|
97
110
|
lineHeight: props.height + 'rpx',
|
|
98
111
|
padding: `0 ${Number(props.gutter) / 2}rpx`,
|
|
99
|
-
color:
|
|
112
|
+
color:
|
|
113
|
+
tabsInfo.value.length > 0
|
|
114
|
+
? tabsInfo.value[index]
|
|
115
|
+
? tabsInfo.value[index].color
|
|
116
|
+
: props.activeColor
|
|
117
|
+
: props.inactiveColor,
|
|
100
118
|
fontSize: props.fontSize + 'rpx',
|
|
101
119
|
zIndex: Number(props.zIndex) + 2,
|
|
102
120
|
fontWeight: index == getCurrent.value && props.bold ? 'bold' : 'normal'
|
|
@@ -8,7 +8,15 @@
|
|
|
8
8
|
>
|
|
9
9
|
{{ text }}
|
|
10
10
|
<view class="u-icon-wrap" @tap.stop>
|
|
11
|
-
<u-icon
|
|
11
|
+
<u-icon
|
|
12
|
+
@click="close"
|
|
13
|
+
size="22"
|
|
14
|
+
v-if="closeable"
|
|
15
|
+
:color="closeIconColor"
|
|
16
|
+
name="close"
|
|
17
|
+
class="u-close-icon"
|
|
18
|
+
:style="[iconStyle]"
|
|
19
|
+
></u-icon>
|
|
12
20
|
</view>
|
|
13
21
|
</view>
|
|
14
22
|
</template>
|
|
@@ -35,7 +35,10 @@ export const TextProps = {
|
|
|
35
35
|
/** 字体大小 */
|
|
36
36
|
size: { type: [String, Number] as PropType<string | number>, default: 28 },
|
|
37
37
|
/** 图标样式 */
|
|
38
|
-
iconStyle: {
|
|
38
|
+
iconStyle: {
|
|
39
|
+
type: [Object, String] as PropType<Record<string, any> | string>,
|
|
40
|
+
default: () => ({ fontSize: '15px' })
|
|
41
|
+
},
|
|
39
42
|
/** 文字样式 */
|
|
40
43
|
textStyle: { type: [Object, String] as PropType<Record<string, any> | string>, default: () => ({}) },
|
|
41
44
|
/** 文字装饰 */
|
|
@@ -17,7 +17,13 @@
|
|
|
17
17
|
<u-icon :name="props.prefixIcon" :custom-style="$u.toStyle(props.iconStyle)"></u-icon>
|
|
18
18
|
</view>
|
|
19
19
|
<!-- 价格模式 -->
|
|
20
|
-
<text
|
|
20
|
+
<text
|
|
21
|
+
v-if="props.mode === 'price'"
|
|
22
|
+
:class="['u-text__price', props.type && `u-text__value--${props.type}`]"
|
|
23
|
+
:style="textValueStyle"
|
|
24
|
+
>
|
|
25
|
+
¥{{ displayValue }}
|
|
26
|
+
</text>
|
|
21
27
|
<!-- link 模式 -->
|
|
22
28
|
<u-link v-else-if="props.mode === 'link'" :href="props.href" underLine>{{ displayValue }}</u-link>
|
|
23
29
|
<template v-else-if="props.openType && isMp">
|
|
@@ -44,7 +50,12 @@
|
|
|
44
50
|
</button>
|
|
45
51
|
</template>
|
|
46
52
|
<!-- 默认模式 -->
|
|
47
|
-
<text
|
|
53
|
+
<text
|
|
54
|
+
v-else
|
|
55
|
+
class="u-text__value"
|
|
56
|
+
:style="textValueStyle"
|
|
57
|
+
:class="[props.type && `u-text__value--${props.type}`, props.lines ? `u-line-${props.lines}` : '']"
|
|
58
|
+
>
|
|
48
59
|
{{ displayValue }}
|
|
49
60
|
</text>
|
|
50
61
|
<!-- 后缀图标 -->
|
|
@@ -184,7 +195,11 @@ const textValueStyle = computed(() => {
|
|
|
184
195
|
fontWeight: props.bold ? 'bold' : 'normal',
|
|
185
196
|
wordWrap: props.wordWrap,
|
|
186
197
|
fontSize: $u.addUnit(props.size),
|
|
187
|
-
lineHeight: props.lineHeight
|
|
198
|
+
lineHeight: props.lineHeight
|
|
199
|
+
? typeof props.lineHeight === 'number'
|
|
200
|
+
? `${props.lineHeight}px`
|
|
201
|
+
: props.lineHeight
|
|
202
|
+
: undefined
|
|
188
203
|
};
|
|
189
204
|
if (props.lines) {
|
|
190
205
|
style['display'] = '-webkit-box';
|
|
@@ -64,9 +64,15 @@ export const UploadProps = {
|
|
|
64
64
|
/** 是否显示提示 */
|
|
65
65
|
showTips: { type: Boolean, default: true },
|
|
66
66
|
/** 上传前钩子,返回true或Promise */
|
|
67
|
-
beforeUpload: {
|
|
67
|
+
beforeUpload: {
|
|
68
|
+
type: Function as PropType<((index: number, files: any[]) => boolean | Promise<any>) | null>,
|
|
69
|
+
default: null
|
|
70
|
+
},
|
|
68
71
|
/** 删除前钩子,返回true或Promise */
|
|
69
|
-
beforeRemove: {
|
|
72
|
+
beforeRemove: {
|
|
73
|
+
type: Function as PropType<((index: number, files: any[]) => boolean | Promise<any>) | null>,
|
|
74
|
+
default: null
|
|
75
|
+
},
|
|
70
76
|
/** 如果上传后的返回值为json字符串,是否转为json格式 */
|
|
71
77
|
toJson: { type: Boolean, default: true }
|
|
72
78
|
};
|
|
@@ -28,7 +28,13 @@
|
|
|
28
28
|
:percent="item.progress"
|
|
29
29
|
></u-line-progress>
|
|
30
30
|
<view @tap.stop="retry(index)" v-if="item.error" class="u-error-btn">点击重试</view>
|
|
31
|
-
<image
|
|
31
|
+
<image
|
|
32
|
+
@tap.stop="doPreviewImage(item.url || item.path, index)"
|
|
33
|
+
class="u-preview-image"
|
|
34
|
+
v-if="!item.isImage"
|
|
35
|
+
:src="item.url || item.path"
|
|
36
|
+
:mode="imageMode"
|
|
37
|
+
></image>
|
|
32
38
|
</view>
|
|
33
39
|
<slot name="file" :file="lists"></slot>
|
|
34
40
|
<view style="display: inline-block" @tap="selectFile" v-if="Number(maxCount) > lists.length">
|
|
@@ -259,7 +265,11 @@ async function uploadFile(index = 0) {
|
|
|
259
265
|
// 明白意思即可,无需纠结this.$u.$parent.call(this)的细节
|
|
260
266
|
let beforeResponse = props.beforeUpload(index, lists.value);
|
|
261
267
|
// 判断是否返回了promise
|
|
262
|
-
if (
|
|
268
|
+
if (
|
|
269
|
+
typeof beforeResponse === 'object' &&
|
|
270
|
+
beforeResponse !== null &&
|
|
271
|
+
typeof (beforeResponse as Promise<any>).then === 'function'
|
|
272
|
+
) {
|
|
263
273
|
await (beforeResponse as Promise<any>)
|
|
264
274
|
.then(() => {
|
|
265
275
|
// promise返回成功,不进行动作,继续上传
|
|
@@ -349,7 +359,11 @@ function deleteItem(index: number) {
|
|
|
349
359
|
// 此处钩子执行 原理同before-remove参数,见上方注释
|
|
350
360
|
let beforeResponse = props.beforeRemove(index, lists.value);
|
|
351
361
|
// 判断是否返回了promise
|
|
352
|
-
if (
|
|
362
|
+
if (
|
|
363
|
+
typeof beforeResponse === 'object' &&
|
|
364
|
+
beforeResponse !== null &&
|
|
365
|
+
typeof (beforeResponse as Promise<any>).then === 'function'
|
|
366
|
+
) {
|
|
353
367
|
await (beforeResponse as Promise<any>)
|
|
354
368
|
.then(() => {
|
|
355
369
|
// promise返回成功,不进行动作,继续上传
|
package/iconfont.css
CHANGED
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
format('woff2'),
|
|
24
24
|
url('//at.alicdn.com/t/font_1529455_k4s6di1d1.woff?t=1596960292384') format('woff'),
|
|
25
25
|
url('//at.alicdn.com/t/font_1529455_k4s6di1d1.ttf?t=1596960292384') format('truetype'),
|
|
26
|
-
/* chrome, firefox, opera, Safari, Android, iOS 4.2+ */
|
|
26
|
+
/* chrome, firefox, opera, Safari, Android, iOS 4.2+ */
|
|
27
|
+
url('//at.alicdn.com/t/font_1529455_k4s6di1d1.svg?t=1596960292384#iconfont') format('svg');
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
/* #endif */
|
package/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { $u, type RequestOptions } from './libs';
|
|
2
2
|
import type { UViewProOptions } from './types/global';
|
|
3
|
+
import { logger } from './libs/util/logger';
|
|
3
4
|
|
|
4
5
|
declare const uni: {
|
|
5
6
|
[key: string]: any;
|
|
@@ -13,8 +14,16 @@ declare const uni: {
|
|
|
13
14
|
// $u挂载到uni对象上
|
|
14
15
|
const install = (app: any, options?: UViewProOptions): void => {
|
|
15
16
|
uni.$u = $u;
|
|
16
|
-
if (options
|
|
17
|
-
|
|
17
|
+
if (options) {
|
|
18
|
+
// 配置主题
|
|
19
|
+
if (options.theme) {
|
|
20
|
+
$u.color = $u.deepMerge($u.color, options.theme);
|
|
21
|
+
}
|
|
22
|
+
// 设置调试模式
|
|
23
|
+
logger
|
|
24
|
+
.setDebugMode(options?.log?.debug ?? true)
|
|
25
|
+
.setPrefix(options?.log?.prefix)
|
|
26
|
+
.setShowCallerInfo(options?.log?.showCallerInfo ?? true);
|
|
18
27
|
}
|
|
19
28
|
// 可扩展更多配置项
|
|
20
29
|
app.config.globalProperties.$u = $u;
|
package/libs/css/style.vue.scss
CHANGED
package/libs/function/$parent.ts
CHANGED
|
@@ -4,7 +4,10 @@
|
|
|
4
4
|
// 值(默认为undefined),就是查找最顶层的$parent
|
|
5
5
|
import { type ComponentInternalInstance, getCurrentInstance } from 'vue';
|
|
6
6
|
|
|
7
|
-
export default function $parent(
|
|
7
|
+
export default function $parent(
|
|
8
|
+
componentName?: string,
|
|
9
|
+
_instance: ComponentInternalInstance | null | undefined = null
|
|
10
|
+
) {
|
|
8
11
|
const instance: ComponentInternalInstance | null | undefined = _instance || getCurrentInstance();
|
|
9
12
|
let parent = instance && (instance.parent as ComponentInternalInstance | null | undefined);
|
|
10
13
|
|
|
@@ -5,7 +5,11 @@
|
|
|
5
5
|
* @param step 颜色等分的份额
|
|
6
6
|
* @returns 渐变色数组
|
|
7
7
|
*/
|
|
8
|
-
function colorGradient(
|
|
8
|
+
function colorGradient(
|
|
9
|
+
startColor: string = 'rgb(0, 0, 0)',
|
|
10
|
+
endColor: string = 'rgb(255, 255, 255)',
|
|
11
|
+
step: number = 10
|
|
12
|
+
): string[] {
|
|
9
13
|
const startRGB = hexToRgb(startColor, false) as [number, number, number]; // 转换为rgb数组模式
|
|
10
14
|
const [startR, startG, startB] = startRGB;
|
|
11
15
|
const endRGB = hexToRgb(endColor, false) as [number, number, number];
|
|
@@ -17,7 +21,9 @@ function colorGradient(startColor: string = 'rgb(0, 0, 0)', endColor: string = '
|
|
|
17
21
|
const colorArr: string[] = [];
|
|
18
22
|
for (let i = 0; i < step; i++) {
|
|
19
23
|
// 计算每一步的hex值
|
|
20
|
-
const hex = rgbToHex(
|
|
24
|
+
const hex = rgbToHex(
|
|
25
|
+
`rgb(${Math.round(sR * i + startR)},${Math.round(sG * i + startG)},${Math.round(sB * i + startB)})`
|
|
26
|
+
);
|
|
21
27
|
colorArr.push(hex as string);
|
|
22
28
|
}
|
|
23
29
|
return colorArr;
|
|
@@ -41,7 +47,11 @@ function hexToRgb(sColor: string, str: boolean = true): [number, number, number]
|
|
|
41
47
|
sColor = sColorNew;
|
|
42
48
|
}
|
|
43
49
|
// 处理六位的颜色值
|
|
44
|
-
const sColorChange: [number, number, number] = [
|
|
50
|
+
const sColorChange: [number, number, number] = [
|
|
51
|
+
parseInt('0x' + sColor.slice(1, 3)),
|
|
52
|
+
parseInt('0x' + sColor.slice(3, 5)),
|
|
53
|
+
parseInt('0x' + sColor.slice(5, 7))
|
|
54
|
+
];
|
|
45
55
|
if (!str) {
|
|
46
56
|
return sColorChange;
|
|
47
57
|
} else {
|
|
@@ -110,7 +120,11 @@ function colorToRgba(color: string, alpha: number = 0.3): string {
|
|
|
110
120
|
}
|
|
111
121
|
sColor = sColorNew;
|
|
112
122
|
}
|
|
113
|
-
const sColorChange: [number, number, number] = [
|
|
123
|
+
const sColorChange: [number, number, number] = [
|
|
124
|
+
parseInt('0x' + sColor.slice(1, 3)),
|
|
125
|
+
parseInt('0x' + sColor.slice(3, 5)),
|
|
126
|
+
parseInt('0x' + sColor.slice(5, 7))
|
|
127
|
+
];
|
|
114
128
|
return `rgba(${sColorChange.join(',')},${alpha})`;
|
|
115
129
|
} else {
|
|
116
130
|
return sColor;
|
|
@@ -8,7 +8,8 @@ import deepClone from './deepClone';
|
|
|
8
8
|
*/
|
|
9
9
|
function deepMerge<T extends object, S extends object>(target: T = {} as T, source: S = {} as S): T & S {
|
|
10
10
|
target = deepClone(target);
|
|
11
|
-
if (typeof target !== 'object' || target === null || typeof source !== 'object' || source === null)
|
|
11
|
+
if (typeof target !== 'object' || target === null || typeof source !== 'object' || source === null)
|
|
12
|
+
return target as T & S;
|
|
12
13
|
const merged: any = Array.isArray(target) ? target.slice() : Object.assign({}, target);
|
|
13
14
|
for (const prop in source) {
|
|
14
15
|
if (!Object.prototype.hasOwnProperty.call(source, prop)) continue;
|
|
@@ -13,7 +13,11 @@ interface VueInstance {
|
|
|
13
13
|
* @param keys 需要获取的参数名数组或对象
|
|
14
14
|
* @returns 父组件参数对象
|
|
15
15
|
*/
|
|
16
|
-
export default function getParent(
|
|
16
|
+
export default function getParent(
|
|
17
|
+
this: VueInstance,
|
|
18
|
+
name: string,
|
|
19
|
+
keys: string[] | Record<string, any>
|
|
20
|
+
): Record<string, any> {
|
|
17
21
|
let parent = this.$parent;
|
|
18
22
|
// 通过while历遍,这里主要是为了H5需要多层解析的问题
|
|
19
23
|
while (parent) {
|
package/libs/function/md5.ts
CHANGED
|
@@ -112,7 +112,10 @@ function rstr2b64(input: string): string {
|
|
|
112
112
|
let output = '';
|
|
113
113
|
const len: number = input.length;
|
|
114
114
|
for (let i = 0; i < len; i += 3) {
|
|
115
|
-
const triplet: number =
|
|
115
|
+
const triplet: number =
|
|
116
|
+
(input.charCodeAt(i) << 16) |
|
|
117
|
+
(i + 1 < len ? input.charCodeAt(i + 1) << 8 : 0) |
|
|
118
|
+
(i + 2 < len ? input.charCodeAt(i + 2) : 0);
|
|
116
119
|
for (let j = 0; j < 4; j++) {
|
|
117
120
|
if (i * 8 + j * 6 > input.length * 8) output += b64pad;
|
|
118
121
|
else output += tab.charAt((triplet >>> (6 * (3 - j))) & 0x3f);
|
|
@@ -187,8 +190,15 @@ function str2rstr_utf8(input: string): string {
|
|
|
187
190
|
/* Encode output as utf-8 */
|
|
188
191
|
if (x <= 0x7f) output += String.fromCharCode(x);
|
|
189
192
|
else if (x <= 0x7ff) output += String.fromCharCode(0xc0 | ((x >>> 6) & 0x1f), 0x80 | (x & 0x3f));
|
|
190
|
-
else if (x <= 0xffff)
|
|
191
|
-
|
|
193
|
+
else if (x <= 0xffff)
|
|
194
|
+
output += String.fromCharCode(0xe0 | ((x >>> 12) & 0x0f), 0x80 | ((x >>> 6) & 0x3f), 0x80 | (x & 0x3f));
|
|
195
|
+
else if (x <= 0x1fffff)
|
|
196
|
+
output += String.fromCharCode(
|
|
197
|
+
0xf0 | ((x >>> 18) & 0x07),
|
|
198
|
+
0x80 | ((x >>> 12) & 0x3f),
|
|
199
|
+
0x80 | ((x >>> 6) & 0x3f),
|
|
200
|
+
0x80 | (x & 0x3f)
|
|
201
|
+
);
|
|
192
202
|
}
|
|
193
203
|
return output;
|
|
194
204
|
}
|
|
@@ -200,7 +210,8 @@ function str2rstr_utf8(input: string): string {
|
|
|
200
210
|
*/
|
|
201
211
|
function str2rstr_utf16le(input: string): string {
|
|
202
212
|
let output = '';
|
|
203
|
-
for (let i = 0; i < input.length; i++)
|
|
213
|
+
for (let i = 0; i < input.length; i++)
|
|
214
|
+
output += String.fromCharCode(input.charCodeAt(i) & 0xff, (input.charCodeAt(i) >>> 8) & 0xff);
|
|
204
215
|
return output;
|
|
205
216
|
}
|
|
206
217
|
|
|
@@ -211,7 +222,8 @@ function str2rstr_utf16le(input: string): string {
|
|
|
211
222
|
*/
|
|
212
223
|
function str2rstr_utf16be(input: string): string {
|
|
213
224
|
let output = '';
|
|
214
|
-
for (let i = 0; i < input.length; i++)
|
|
225
|
+
for (let i = 0; i < input.length; i++)
|
|
226
|
+
output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xff, input.charCodeAt(i) & 0xff);
|
|
215
227
|
return output;
|
|
216
228
|
}
|
|
217
229
|
|
|
@@ -5,7 +5,11 @@
|
|
|
5
5
|
* @param arrayFormat 数组参数格式,indices/brackets/repeat/comma,默认brackets
|
|
6
6
|
* @returns url参数字符串
|
|
7
7
|
*/
|
|
8
|
-
function queryParams(
|
|
8
|
+
function queryParams(
|
|
9
|
+
data: Record<string, any> = {},
|
|
10
|
+
isPrefix: boolean = true,
|
|
11
|
+
arrayFormat: 'indices' | 'brackets' | 'repeat' | 'comma' = 'brackets'
|
|
12
|
+
): string {
|
|
9
13
|
const prefix = isPrefix ? '?' : '';
|
|
10
14
|
const _result: string[] = [];
|
|
11
15
|
if (!['indices', 'brackets', 'repeat', 'comma'].includes(arrayFormat)) arrayFormat = 'brackets';
|
package/libs/function/test.ts
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
* 验证电子邮箱格式
|
|
3
3
|
*/
|
|
4
4
|
function email(value: string): boolean {
|
|
5
|
-
return /[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?/.test(
|
|
5
|
+
return /[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?/.test(
|
|
6
|
+
value
|
|
7
|
+
);
|
|
6
8
|
}
|
|
7
9
|
|
|
8
10
|
/**
|
|
@@ -59,9 +61,11 @@ function idCard(value: string): boolean {
|
|
|
59
61
|
*/
|
|
60
62
|
function carNo(value: string): boolean {
|
|
61
63
|
// 新能源车牌
|
|
62
|
-
const xreg =
|
|
64
|
+
const xreg =
|
|
65
|
+
/^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}(([0-9]{5}[DF]$)|([DF][A-HJ-NP-Z0-9][0-9]{4}$))/;
|
|
63
66
|
// 旧车牌
|
|
64
|
-
const creg =
|
|
67
|
+
const creg =
|
|
68
|
+
/^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳]{1}$/;
|
|
65
69
|
if (value.length === 7) {
|
|
66
70
|
return creg.test(value);
|
|
67
71
|
} else if (value.length === 8) {
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
if (!String.prototype.padStart) {
|
|
4
4
|
// 为了方便表示这里 fillString 用了ES6 的默认参数,不影响理解
|
|
5
5
|
String.prototype.padStart = function (this: string, maxLength: number, fillString: string = ' '): string {
|
|
6
|
-
if (Object.prototype.toString.call(fillString) !== '[object String]')
|
|
6
|
+
if (Object.prototype.toString.call(fillString) !== '[object String]')
|
|
7
|
+
throw new TypeError('fillString must be String');
|
|
7
8
|
let str = this;
|
|
8
9
|
if (str.length >= maxLength) return String(str);
|
|
9
10
|
let fillLength = maxLength - str.length,
|
|
@@ -4,7 +4,10 @@
|
|
|
4
4
|
* @param fill 是否使用fill填充实体的图标,默认false
|
|
5
5
|
* @returns 图标名称字符串
|
|
6
6
|
*/
|
|
7
|
-
function type2icon(
|
|
7
|
+
function type2icon(
|
|
8
|
+
type: 'primary' | 'info' | 'error' | 'warning' | 'success' = 'success',
|
|
9
|
+
fill: boolean = false
|
|
10
|
+
): string {
|
|
8
11
|
// 如果非预置值,默认为success
|
|
9
12
|
if (!['primary', 'info', 'error', 'warning', 'success'].includes(type)) type = 'success';
|
|
10
13
|
let iconName = '';
|
package/libs/hooks/index.ts
CHANGED