hy-app 0.2.5 → 0.2.7
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/common/index.ts +2 -1
- package/common/shakeService.ts +60 -0
- package/components/hy-action-sheet/hy-action-sheet.vue +184 -0
- package/components/hy-action-sheet/index.scss +123 -0
- package/components/hy-action-sheet/props.ts +18 -0
- package/components/hy-action-sheet/typing.d.ts +96 -0
- package/components/hy-address-picker/hy-address-picker.vue +75 -91
- package/components/hy-avatar/hy-avatar.vue +64 -73
- package/components/hy-button/hy-button.vue +3 -3
- package/components/hy-button/typing.d.ts +35 -31
- package/components/hy-cell/typing.d.ts +27 -24
- package/components/hy-empty/hy-empty.vue +30 -37
- package/components/hy-empty/icon.ts +78 -0
- package/components/hy-empty/index.scss +2 -1
- package/components/hy-empty/props.ts +10 -9
- package/components/hy-empty/typing.d.ts +39 -14
- package/components/hy-float-button/hy-float-button.vue +183 -17
- package/components/hy-float-button/props.ts +17 -15
- package/components/hy-float-button/typing.d.ts +51 -27
- package/components/hy-icon/hy-icon.vue +39 -41
- package/components/hy-icon/props.ts +17 -16
- package/components/hy-icon/typing.d.ts +24 -20
- package/components/hy-image/hy-image.vue +69 -104
- package/components/hy-image/index.scss +21 -5
- package/components/hy-image/props.ts +11 -10
- package/components/hy-image/typing.d.ts +23 -19
- package/components/hy-modal/hy-modal.vue +42 -54
- package/components/hy-modal/index.scss +56 -32
- package/components/hy-modal/props.ts +15 -14
- package/components/hy-modal/typing.d.ts +23 -17
- package/components/hy-popover/hy-popover.vue +200 -0
- package/components/hy-popover/index.scss +83 -0
- package/components/hy-popover/props.ts +13 -0
- package/components/hy-popover/typing.d.ts +56 -0
- package/components/hy-popup/index.scss +2 -2
- package/components/hy-popup/props.ts +7 -7
- package/components/hy-popup/typing.d.ts +17 -17
- package/components/hy-qrcode/hy-qrcode.vue +44 -45
- package/components/hy-rate/props.ts +6 -6
- package/components/hy-signature/props.ts +14 -14
- package/components/hy-tooltip/index.scss +2 -2
- package/components/hy-transition/hy-transition.vue +64 -72
- package/components/hy-transition/typing.d.ts +10 -6
- package/composables/index.ts +4 -2
- package/composables/usePopover.ts +221 -0
- package/composables/useQueue.ts +52 -0
- package/libs/css/_config.scss +5 -0
- package/libs/css/_function.scss +89 -0
- package/libs/css/mixin.scss +146 -21
- package/libs/css/vars.css +3 -1
- package/package.json +2 -2
- package/theme.scss +2 -1
- package/utils/inside.ts +96 -108
- package/utils/inspect.ts +48 -40
- package/utils/utils.ts +170 -187
package/libs/css/mixin.scss
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
@use "../../theme.scss";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
$modifier-separator: '--' !default;
|
|
6
|
-
$state-prefix: 'is-' !default;
|
|
2
|
+
@import "config";
|
|
3
|
+
@import "function";
|
|
4
|
+
|
|
7
5
|
|
|
8
6
|
@mixin b($block) {
|
|
9
7
|
$B: $namespace + '-' + $block !global;
|
|
@@ -31,36 +29,75 @@ $state-prefix: 'is-' !default;
|
|
|
31
29
|
}
|
|
32
30
|
}
|
|
33
31
|
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
/* 定义元素(e),对于伪类,会自动将 e 嵌套在 伪类 底下 */
|
|
33
|
+
@mixin e($element...) {
|
|
36
34
|
$selector: &;
|
|
37
|
-
$
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
$B +
|
|
42
|
-
|
|
43
|
-
$unit +
|
|
44
|
-
','};
|
|
45
|
-
}
|
|
35
|
+
$selectors: "";
|
|
36
|
+
|
|
37
|
+
@if containsPseudo($selector) {
|
|
38
|
+
@each $item in $element {
|
|
39
|
+
$selectors: #{$selectors + "." + $B + $element-separator + $item + ","};
|
|
40
|
+
}
|
|
46
41
|
|
|
47
|
-
@if hitAllSpecialNestRule($selector) {
|
|
48
42
|
@at-root {
|
|
49
43
|
#{$selector} {
|
|
50
|
-
#{$
|
|
44
|
+
#{$selectors} {
|
|
51
45
|
@content;
|
|
52
46
|
}
|
|
53
47
|
}
|
|
54
48
|
}
|
|
55
|
-
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@else {
|
|
52
|
+
@each $item in $element {
|
|
53
|
+
$selectors: #{$selectors + $selector + $element-separator + $item + ","};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
56
|
@at-root {
|
|
57
|
-
#{$
|
|
57
|
+
#{$selectors} {
|
|
58
58
|
@content;
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
|
|
65
|
+
/* 定义元素(e),对于伪类,会自动将 e 嵌套在 伪类 底下 */
|
|
66
|
+
@mixin edeep($element...) {
|
|
67
|
+
$selector: &;
|
|
68
|
+
$selectors: "";
|
|
69
|
+
|
|
70
|
+
@if containsPseudo($selector) {
|
|
71
|
+
@each $item in $element {
|
|
72
|
+
$selectors: #{$selectors + "." + $B + $element-separator + $item + ","};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@at-root {
|
|
76
|
+
#{$selector} {
|
|
77
|
+
:deep() {
|
|
78
|
+
#{$selectors} {
|
|
79
|
+
@content;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
@else {
|
|
87
|
+
@each $item in $element {
|
|
88
|
+
$selectors: #{$selectors + $selector + $element-separator + $item + ","};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
@at-root {
|
|
92
|
+
:deep() {
|
|
93
|
+
#{$selectors} {
|
|
94
|
+
@content;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
64
101
|
/* 状态,生成 is-$state 类名 */
|
|
65
102
|
@mixin is($states...) {
|
|
66
103
|
@at-root {
|
|
@@ -92,6 +129,10 @@ $state-prefix: 'is-' !default;
|
|
|
92
129
|
}
|
|
93
130
|
}
|
|
94
131
|
|
|
132
|
+
/**
|
|
133
|
+
* 圆角形状
|
|
134
|
+
* @param $shape circle-半圆形,square-方形带圆角
|
|
135
|
+
*/
|
|
95
136
|
@mixin borderRadio($shape) {
|
|
96
137
|
@include m($shape) {
|
|
97
138
|
@if $shape == circle {
|
|
@@ -103,6 +144,90 @@ $state-prefix: 'is-' !default;
|
|
|
103
144
|
}
|
|
104
145
|
}
|
|
105
146
|
|
|
147
|
+
/**
|
|
148
|
+
* 正方形实现尖角样式,适用于背景不透明情况
|
|
149
|
+
* @param $size 正方形边长
|
|
150
|
+
* @param $bg 正方形背景颜色
|
|
151
|
+
* @param $z-index z-index属性值,不得大于外部包裹器
|
|
152
|
+
* @param $box-shadow 阴影
|
|
153
|
+
*/
|
|
154
|
+
@mixin squareArrow($size, $bg, $z-index, $box-shadow) {
|
|
155
|
+
@include e(arrow) {
|
|
156
|
+
position: absolute;
|
|
157
|
+
width: $size;
|
|
158
|
+
height: $size;
|
|
159
|
+
z-index: $z-index;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
@include e(arrow-down) {
|
|
163
|
+
transform: translateX(-50%);
|
|
164
|
+
bottom: 0;
|
|
165
|
+
|
|
166
|
+
&:after {
|
|
167
|
+
content: "";
|
|
168
|
+
width: $size;
|
|
169
|
+
height: $size;
|
|
170
|
+
background-color: $bg;
|
|
171
|
+
position: absolute;
|
|
172
|
+
left: 0;
|
|
173
|
+
bottom: calc(-1 * $size / 2);
|
|
174
|
+
transform: rotateZ(45deg);
|
|
175
|
+
box-shadow: $box-shadow;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
@include e(arrow-up) {
|
|
180
|
+
transform: translateX(-50%);
|
|
181
|
+
top: 0;
|
|
182
|
+
|
|
183
|
+
&:after {
|
|
184
|
+
content: "";
|
|
185
|
+
width: $size;
|
|
186
|
+
height: $size;
|
|
187
|
+
background-color: $bg;
|
|
188
|
+
position: absolute;
|
|
189
|
+
left: 0;
|
|
190
|
+
top: calc(-1 * $size / 2);
|
|
191
|
+
transform: rotateZ(45deg);
|
|
192
|
+
box-shadow: $box-shadow;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
@include e(arrow-left) {
|
|
197
|
+
transform: translateY(-50%);
|
|
198
|
+
left: 0;
|
|
199
|
+
|
|
200
|
+
&:after {
|
|
201
|
+
content: "";
|
|
202
|
+
width: $size;
|
|
203
|
+
height: $size;
|
|
204
|
+
background-color: $bg;
|
|
205
|
+
position: absolute;
|
|
206
|
+
left: calc(-1 * $size / 2);
|
|
207
|
+
top: 0;
|
|
208
|
+
transform: rotateZ(45deg);
|
|
209
|
+
box-shadow: $box-shadow;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
@include e(arrow-right) {
|
|
214
|
+
transform: translateY(-50%);
|
|
215
|
+
right: 0;
|
|
216
|
+
|
|
217
|
+
&:after {
|
|
218
|
+
content: "";
|
|
219
|
+
width: $size;
|
|
220
|
+
height: $size;
|
|
221
|
+
background-color: $bg;
|
|
222
|
+
position: absolute;
|
|
223
|
+
right: calc(-1 * $size / 2);
|
|
224
|
+
top: 0;
|
|
225
|
+
transform: rotateZ(45deg);
|
|
226
|
+
box-shadow: $box-shadow;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
106
231
|
|
|
107
232
|
/* flex布局 */
|
|
108
233
|
@mixin flex($direction: row) {
|
|
@@ -135,4 +260,4 @@ $state-prefix: 'is-' !default;
|
|
|
135
260
|
-webkit-line-clamp: $lineNumber;
|
|
136
261
|
overflow: hidden;
|
|
137
262
|
text-overflow: ellipsis;
|
|
138
|
-
}
|
|
263
|
+
}
|
package/libs/css/vars.css
CHANGED
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
--hy-background--empty: #F3F3F3;
|
|
20
20
|
--hy-background--hover: rgba(0,0,0,0.05);
|
|
21
21
|
--hy-background--active: #FFFFFF;
|
|
22
|
+
--hy-background--close: #f0f0f0;
|
|
22
23
|
|
|
23
24
|
--hy-border-line: 1rpx solid #c2c2c4;
|
|
24
25
|
--hy-border-color: #c2c2c4;
|
|
@@ -50,8 +51,9 @@
|
|
|
50
51
|
--hy-background--empty: #3A3A44;
|
|
51
52
|
--hy-background--hover: rgba(255,255,255,0.2);
|
|
52
53
|
--hy-background--active: #000000;
|
|
54
|
+
--hy-background--close: #323233;
|
|
53
55
|
|
|
54
56
|
--hy-border-line: 1rpx solid #3c3f44;
|
|
55
57
|
--hy-border-color: #3c3f44;
|
|
56
58
|
--hy-border-color--2: #FFFFFF;
|
|
57
|
-
}
|
|
59
|
+
}
|
package/package.json
CHANGED
package/theme.scss
CHANGED
|
@@ -34,7 +34,7 @@ $hy-text-color--grey: var(--hy-text-color--grey, #999) !default; // 辅助灰色
|
|
|
34
34
|
$hy-text-color--placeholder: var(--hy-text-color--placeholder, #808080) !default; // 输入框提示颜色
|
|
35
35
|
$hy-text-color--disabled: var(--hy-text-color--disabled, #c0c0c0) !default; // 禁用文字颜色
|
|
36
36
|
$hy-border-color: var(--hy-border-color, #c0c0c0) !default; // 边框颜色
|
|
37
|
-
$hy-text-color
|
|
37
|
+
$hy-text-color--hover: var(--hy-text-color--hover, #58595b)!default; // 点击状态文字颜色
|
|
38
38
|
|
|
39
39
|
|
|
40
40
|
/* 背景色 */
|
|
@@ -48,6 +48,7 @@ $hy-background--empty: var(--hy-background--empty, #F3F3F3) !default; // 搜索
|
|
|
48
48
|
$hy-background--hover: var(--hy-background--hover, rgba(0,0,0,0.1)) !default; // 点击状态
|
|
49
49
|
$hy-light-background-mask: var(--hy-light-background-mask, rgba(0, 0, 0, 0.5)); //遮罩颜色
|
|
50
50
|
$hy-background--active: var(--hy-background--active, #131313); // 选中背景色
|
|
51
|
+
$hy-background--close: var(--hy-background--close, #f0f0f0); // 选中背景色
|
|
51
52
|
|
|
52
53
|
/* 文字尺寸 */
|
|
53
54
|
$hy-font-size-sm: 24rpx; // 提示文字大小
|
package/utils/inside.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// 内部使用方法
|
|
2
|
-
import { inject } from
|
|
2
|
+
import { inject } from 'vue'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* 生成bem规则类名
|
|
@@ -18,33 +18,31 @@ export const bem = (
|
|
|
18
18
|
change?: string[],
|
|
19
19
|
): string | string[] => {
|
|
20
20
|
// 类名前缀
|
|
21
|
-
const prefix = `hy-${name}
|
|
22
|
-
const classes: Record<string, string | boolean> = {}
|
|
21
|
+
const prefix = `hy-${name}--`
|
|
22
|
+
const classes: Record<string, string | boolean> = {}
|
|
23
23
|
if (fixed) {
|
|
24
24
|
fixed.map((item: string) => {
|
|
25
25
|
// 这里的类名,会一直存在
|
|
26
|
-
classes[prefix + props[item]] = true
|
|
27
|
-
if (item ===
|
|
28
|
-
classes[prefix + props[item] +
|
|
26
|
+
classes[prefix + props[item]] = true
|
|
27
|
+
if (item === 'type' && props['plain']) {
|
|
28
|
+
classes[prefix + props[item] + '__plain'] = true
|
|
29
29
|
}
|
|
30
|
-
})
|
|
30
|
+
})
|
|
31
31
|
}
|
|
32
32
|
if (change) {
|
|
33
33
|
change.map((item: string) => {
|
|
34
34
|
// 这里的类名,会根据this[item]的值为true或者false,而进行添加或者移除某一个类
|
|
35
|
-
props[item]
|
|
36
|
-
|
|
37
|
-
: delete classes[prefix + item];
|
|
38
|
-
});
|
|
35
|
+
props[item] ? (classes[prefix + item] = props[item]) : delete classes[prefix + item]
|
|
36
|
+
})
|
|
39
37
|
}
|
|
40
38
|
return (
|
|
41
39
|
Object.keys(classes)
|
|
42
40
|
// 支付宝,头条小程序无法动态绑定一个数组类名,否则解析出来的结果会带有",",而导致失效
|
|
43
41
|
// #ifdef MP-ALIPAY || MP-TOUTIAO || MP-LARK
|
|
44
|
-
.join(
|
|
42
|
+
.join(' ')
|
|
45
43
|
// #endif
|
|
46
|
-
)
|
|
47
|
-
}
|
|
44
|
+
)
|
|
45
|
+
}
|
|
48
46
|
|
|
49
47
|
/**
|
|
50
48
|
* @description 在u-form的子组件内容发生变化,或者失去焦点时,尝试通知u-form执行校验方法
|
|
@@ -53,8 +51,7 @@ export const bem = (
|
|
|
53
51
|
*/
|
|
54
52
|
export function formValidate(event) {
|
|
55
53
|
// const formItem = $parent.call(instance, "u-form-item");
|
|
56
|
-
const form = inject(
|
|
57
|
-
console.log(form, "form");
|
|
54
|
+
const form = inject('uForm')
|
|
58
55
|
// 如果发生变化的input或者textarea等,其父组件中有u-form-item或者u-form等,就执行form的validate方法
|
|
59
56
|
// 同时将form-item的pros传递给form,让其进行精确对象验证
|
|
60
57
|
// if (formItem && form) {
|
|
@@ -68,18 +65,18 @@ export function formValidate(event) {
|
|
|
68
65
|
*/
|
|
69
66
|
export function error(err: string) {
|
|
70
67
|
// 开发环境才提示,生产环境不会提示
|
|
71
|
-
if (process.env.NODE_ENV ===
|
|
72
|
-
console.error(`华玥组件提示:${err}`)
|
|
68
|
+
if (process.env.NODE_ENV === 'development') {
|
|
69
|
+
console.error(`华玥组件提示:${err}`)
|
|
73
70
|
}
|
|
74
71
|
}
|
|
75
72
|
|
|
76
73
|
export const sleep = (value = 30) => {
|
|
77
74
|
return new Promise((resolve) => {
|
|
78
75
|
setTimeout(() => {
|
|
79
|
-
resolve()
|
|
80
|
-
}, value)
|
|
81
|
-
})
|
|
82
|
-
}
|
|
76
|
+
resolve()
|
|
77
|
+
}, value)
|
|
78
|
+
})
|
|
79
|
+
}
|
|
83
80
|
|
|
84
81
|
/**
|
|
85
82
|
* @param {Number} len uuid的长度
|
|
@@ -87,67 +84,62 @@ export const sleep = (value = 30) => {
|
|
|
87
84
|
* @param {Nubmer} radix 生成uuid的基数(意味着返回的字符串都是这个基数),2-二进制,8-八进制,10-十进制,16-十六进制
|
|
88
85
|
*/
|
|
89
86
|
export function guid(len = 32, firstU = true, radix = null) {
|
|
90
|
-
const chars =
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
radix = radix || chars.length;
|
|
87
|
+
const chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('')
|
|
88
|
+
const uuid = []
|
|
89
|
+
radix = radix || chars.length
|
|
94
90
|
|
|
95
91
|
if (len) {
|
|
96
92
|
// 如果指定uuid长度,只是取随机的字符,0|x为位运算,能去掉x的小数位,返回整数位
|
|
97
|
-
for (let i = 0; i < len; i++) uuid[i] = chars[0 | (Math.random() * radix)]
|
|
93
|
+
for (let i = 0; i < len; i++) uuid[i] = chars[0 | (Math.random() * radix)]
|
|
98
94
|
} else {
|
|
99
|
-
let r
|
|
95
|
+
let r
|
|
100
96
|
// rfc4122标准要求返回的uuid中,某些位为固定的字符
|
|
101
|
-
uuid[8] = uuid[13] = uuid[18] = uuid[23] =
|
|
102
|
-
uuid[14] =
|
|
97
|
+
uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-'
|
|
98
|
+
uuid[14] = '4'
|
|
103
99
|
|
|
104
100
|
for (let i = 0; i < 36; i++) {
|
|
105
101
|
if (!uuid[i]) {
|
|
106
|
-
r = 0 | (Math.random() * 16)
|
|
107
|
-
uuid[i] = chars[i == 19 ? (r & 0x3) | 0x8 : r]
|
|
102
|
+
r = 0 | (Math.random() * 16)
|
|
103
|
+
uuid[i] = chars[i == 19 ? (r & 0x3) | 0x8 : r]
|
|
108
104
|
}
|
|
109
105
|
}
|
|
110
106
|
}
|
|
111
107
|
// 移除第一个字符,并用u替代,因为第一个字符为数值时,该guuid不能用作id或者class
|
|
112
108
|
if (firstU) {
|
|
113
|
-
uuid.shift()
|
|
114
|
-
return `hy${uuid.join(
|
|
109
|
+
uuid.shift()
|
|
110
|
+
return `hy${uuid.join('')}`
|
|
115
111
|
}
|
|
116
|
-
return uuid.join(
|
|
112
|
+
return uuid.join('')
|
|
117
113
|
}
|
|
118
114
|
|
|
119
115
|
/**
|
|
120
116
|
* @description 获取设备信息
|
|
121
117
|
* */
|
|
122
118
|
export const getWindowInfo = (): UniNamespace.GetWindowInfoResult => {
|
|
123
|
-
let ret: UniNamespace.GetWindowInfoResult
|
|
119
|
+
let ret: UniNamespace.GetWindowInfoResult
|
|
124
120
|
// #ifdef APP || H5 || MP-WEIXIN
|
|
125
|
-
ret = uni.getWindowInfo()
|
|
121
|
+
ret = uni.getWindowInfo()
|
|
126
122
|
// #endif
|
|
127
|
-
return ret
|
|
128
|
-
}
|
|
123
|
+
return ret
|
|
124
|
+
}
|
|
129
125
|
|
|
130
126
|
function pickExclude(obj, keys) {
|
|
131
127
|
// 某些情况下,type可能会为
|
|
132
|
-
if (
|
|
133
|
-
|
|
134
|
-
Object.prototype.toString.call(obj),
|
|
135
|
-
)
|
|
136
|
-
) {
|
|
137
|
-
return {};
|
|
128
|
+
if (!['[object Object]', '[object File]'].includes(Object.prototype.toString.call(obj))) {
|
|
129
|
+
return {}
|
|
138
130
|
}
|
|
139
131
|
return Object.keys(obj).reduce((prev, key) => {
|
|
140
132
|
if (!keys.includes(key)) {
|
|
141
|
-
prev[key] = obj[key]
|
|
133
|
+
prev[key] = obj[key]
|
|
142
134
|
}
|
|
143
|
-
return prev
|
|
144
|
-
}, {})
|
|
135
|
+
return prev
|
|
136
|
+
}, {})
|
|
145
137
|
}
|
|
146
138
|
|
|
147
139
|
function formatImage(res) {
|
|
148
140
|
return res.tempFiles.map((item) => ({
|
|
149
|
-
...pickExclude(item, [
|
|
150
|
-
type:
|
|
141
|
+
...pickExclude(item, ['path']),
|
|
142
|
+
type: 'image',
|
|
151
143
|
url: item.path,
|
|
152
144
|
thumb: item.path,
|
|
153
145
|
size: item.size,
|
|
@@ -155,14 +147,14 @@ function formatImage(res) {
|
|
|
155
147
|
name: item.name,
|
|
156
148
|
file: item,
|
|
157
149
|
// #endif
|
|
158
|
-
}))
|
|
150
|
+
}))
|
|
159
151
|
}
|
|
160
152
|
|
|
161
153
|
function formatVideo(res) {
|
|
162
154
|
return [
|
|
163
155
|
{
|
|
164
|
-
...pickExclude(res, [
|
|
165
|
-
type:
|
|
156
|
+
...pickExclude(res, ['tempFilePath', 'thumbTempFilePath', 'errMsg']),
|
|
157
|
+
type: 'video',
|
|
166
158
|
url: res.tempFilePath,
|
|
167
159
|
thumb: res.thumbTempFilePath,
|
|
168
160
|
size: res.size,
|
|
@@ -171,25 +163,25 @@ function formatVideo(res) {
|
|
|
171
163
|
file: res,
|
|
172
164
|
// #endif
|
|
173
165
|
},
|
|
174
|
-
]
|
|
166
|
+
]
|
|
175
167
|
}
|
|
176
168
|
|
|
177
169
|
function formatMedia(res) {
|
|
178
170
|
return res.tempFiles.map((item) => ({
|
|
179
|
-
...pickExclude(item, [
|
|
171
|
+
...pickExclude(item, ['fileType', 'thumbTempFilePath', 'tempFilePath']),
|
|
180
172
|
type: res.type,
|
|
181
173
|
url: item.tempFilePath,
|
|
182
|
-
thumb: res.type ===
|
|
174
|
+
thumb: res.type === 'video' ? item.thumbTempFilePath : item.tempFilePath,
|
|
183
175
|
size: item.size,
|
|
184
176
|
// #ifdef H5
|
|
185
177
|
file: item,
|
|
186
178
|
// #endif
|
|
187
|
-
}))
|
|
179
|
+
}))
|
|
188
180
|
}
|
|
189
181
|
|
|
190
182
|
function formatFile(res) {
|
|
191
183
|
return res.tempFiles.map((item) => ({
|
|
192
|
-
...pickExclude(item, [
|
|
184
|
+
...pickExclude(item, ['path']),
|
|
193
185
|
url: item.path,
|
|
194
186
|
size: item.size,
|
|
195
187
|
// #ifdef H5
|
|
@@ -197,7 +189,7 @@ function formatFile(res) {
|
|
|
197
189
|
type: item.type,
|
|
198
190
|
file: item,
|
|
199
191
|
// #endif
|
|
200
|
-
}))
|
|
192
|
+
}))
|
|
201
193
|
}
|
|
202
194
|
|
|
203
195
|
export function chooseFile({
|
|
@@ -213,18 +205,18 @@ export function chooseFile({
|
|
|
213
205
|
}: any) {
|
|
214
206
|
return new Promise((resolve, reject) => {
|
|
215
207
|
switch (accept) {
|
|
216
|
-
case
|
|
208
|
+
case 'image':
|
|
217
209
|
uni.chooseImage({
|
|
218
210
|
count: multiple ? Math.min(maxCount, 9) : 1,
|
|
219
211
|
sourceType: capture,
|
|
220
212
|
sizeType,
|
|
221
213
|
success: (res) => resolve(formatImage(res)),
|
|
222
214
|
fail: reject,
|
|
223
|
-
})
|
|
224
|
-
break
|
|
215
|
+
})
|
|
216
|
+
break
|
|
225
217
|
// #ifdef MP-WEIXIN
|
|
226
218
|
// 只有微信小程序才支持chooseMedia接口
|
|
227
|
-
case
|
|
219
|
+
case 'media':
|
|
228
220
|
wx.chooseMedia({
|
|
229
221
|
count: multiple ? Math.min(maxCount, 9) : 1,
|
|
230
222
|
sourceType: capture,
|
|
@@ -233,10 +225,10 @@ export function chooseFile({
|
|
|
233
225
|
camera,
|
|
234
226
|
success: (res) => resolve(formatMedia(res)),
|
|
235
227
|
fail: reject,
|
|
236
|
-
})
|
|
237
|
-
break
|
|
228
|
+
})
|
|
229
|
+
break
|
|
238
230
|
// #endif
|
|
239
|
-
case
|
|
231
|
+
case 'video':
|
|
240
232
|
uni.chooseVideo({
|
|
241
233
|
sourceType: capture,
|
|
242
234
|
compressed,
|
|
@@ -244,18 +236,18 @@ export function chooseFile({
|
|
|
244
236
|
camera,
|
|
245
237
|
success: (res) => resolve(formatVideo(res)),
|
|
246
238
|
fail: reject,
|
|
247
|
-
})
|
|
248
|
-
break
|
|
239
|
+
})
|
|
240
|
+
break
|
|
249
241
|
// #ifdef MP-WEIXIN || H5
|
|
250
242
|
// 只有微信小程序才支持chooseMessageFile接口
|
|
251
|
-
case
|
|
243
|
+
case 'file':
|
|
252
244
|
// #ifdef MP-WEIXIN
|
|
253
245
|
wx.chooseMessageFile({
|
|
254
246
|
count: multiple ? maxCount : 1,
|
|
255
247
|
type: accept,
|
|
256
248
|
success: (res) => resolve(formatFile(res)),
|
|
257
249
|
fail: reject,
|
|
258
|
-
})
|
|
250
|
+
})
|
|
259
251
|
// #endif
|
|
260
252
|
// #ifdef H5
|
|
261
253
|
// 需要hx2.9.9以上才支持uni.chooseFile
|
|
@@ -264,39 +256,39 @@ export function chooseFile({
|
|
|
264
256
|
type: accept,
|
|
265
257
|
success: (res) => resolve(formatFile(res)),
|
|
266
258
|
fail: reject,
|
|
267
|
-
}
|
|
259
|
+
}
|
|
268
260
|
if (extension.length && extension.length > 0) {
|
|
269
|
-
params.extension = extension
|
|
261
|
+
params.extension = extension
|
|
270
262
|
}
|
|
271
|
-
uni.chooseFile(params)
|
|
263
|
+
uni.chooseFile(params)
|
|
272
264
|
// #endif
|
|
273
|
-
break
|
|
265
|
+
break
|
|
274
266
|
// #endif
|
|
275
267
|
default:
|
|
276
268
|
// 此为保底选项,在accept不为上面任意一项的时候选取全部文件
|
|
277
269
|
// #ifdef MP-WEIXIN
|
|
278
270
|
wx.chooseMessageFile({
|
|
279
271
|
count: multiple ? maxCount : 1,
|
|
280
|
-
type:
|
|
272
|
+
type: 'all',
|
|
281
273
|
success: (res) => resolve(formatFile(res)),
|
|
282
274
|
fail: reject,
|
|
283
|
-
})
|
|
275
|
+
})
|
|
284
276
|
// #endif
|
|
285
277
|
// #ifdef H5
|
|
286
278
|
// 需要hx2.9.9以上才支持uni.chooseFile
|
|
287
279
|
let paramsFile = {
|
|
288
280
|
count: multiple ? maxCount : 1,
|
|
289
|
-
type:
|
|
281
|
+
type: 'all',
|
|
290
282
|
success: (res) => resolve(formatFile(res)),
|
|
291
283
|
fail: reject,
|
|
292
|
-
}
|
|
284
|
+
}
|
|
293
285
|
if (extension.length && extension.length > 0) {
|
|
294
|
-
paramsFile.extension = extension
|
|
286
|
+
paramsFile.extension = extension
|
|
295
287
|
}
|
|
296
|
-
uni.chooseFile(paramsFile)
|
|
288
|
+
uni.chooseFile(paramsFile)
|
|
297
289
|
// #endif
|
|
298
290
|
}
|
|
299
|
-
})
|
|
291
|
+
})
|
|
300
292
|
}
|
|
301
293
|
|
|
302
294
|
/**
|
|
@@ -310,28 +302,27 @@ export function chooseFile({
|
|
|
310
302
|
export function priceFormat(
|
|
311
303
|
number: string | number,
|
|
312
304
|
decimals = 0,
|
|
313
|
-
decimalPoint =
|
|
314
|
-
thousandsSeparator =
|
|
305
|
+
decimalPoint = '.',
|
|
306
|
+
thousandsSeparator = ',',
|
|
315
307
|
) {
|
|
316
|
-
number = `${number}`.replace(/[^0-9+-Ee.]/g,
|
|
317
|
-
const n = !isFinite(+number) ? 0 : +number
|
|
318
|
-
const prec = !isFinite(+decimals) ? 0 : Math.abs(decimals)
|
|
319
|
-
const sep =
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
let s = "";
|
|
308
|
+
number = `${number}`.replace(/[^0-9+-Ee.]/g, '')
|
|
309
|
+
const n = !isFinite(+number) ? 0 : +number
|
|
310
|
+
const prec = !isFinite(+decimals) ? 0 : Math.abs(decimals)
|
|
311
|
+
const sep = typeof thousandsSeparator === 'undefined' ? ',' : thousandsSeparator
|
|
312
|
+
const dec = typeof decimalPoint === 'undefined' ? '.' : decimalPoint
|
|
313
|
+
let s = ''
|
|
323
314
|
|
|
324
|
-
s = (prec ? n +
|
|
325
|
-
const re = /(-?\d+)(\d{3})
|
|
315
|
+
s = (prec ? n + '' : `${Math.round(n)}`).split('.')
|
|
316
|
+
const re = /(-?\d+)(\d{3})/
|
|
326
317
|
while (re.test(s[0])) {
|
|
327
|
-
s[0] = s[0].replace(re, `$1${sep}$2`)
|
|
318
|
+
s[0] = s[0].replace(re, `$1${sep}$2`)
|
|
328
319
|
}
|
|
329
320
|
|
|
330
|
-
if ((s[1] ||
|
|
331
|
-
s[1] = s[1] ||
|
|
332
|
-
s[1] += new Array(prec - s[1].length + 1).join(
|
|
321
|
+
if ((s[1] || '').length < prec) {
|
|
322
|
+
s[1] = s[1] || ''
|
|
323
|
+
s[1] += new Array(prec - s[1].length + 1).join('0')
|
|
333
324
|
}
|
|
334
|
-
return s.join(dec)
|
|
325
|
+
return s.join(dec)
|
|
335
326
|
}
|
|
336
327
|
|
|
337
328
|
/**
|
|
@@ -340,20 +331,17 @@ export function priceFormat(
|
|
|
340
331
|
* @return {string}
|
|
341
332
|
* */
|
|
342
333
|
export const formatName = (name: string): string => {
|
|
343
|
-
let value =
|
|
334
|
+
let value = ''
|
|
344
335
|
if (name.length === 2) {
|
|
345
|
-
value = name.substring(0, 1) +
|
|
336
|
+
value = name.substring(0, 1) + '*'
|
|
346
337
|
} else if (name.length > 2) {
|
|
347
|
-
let char =
|
|
338
|
+
let char = ''
|
|
348
339
|
for (let i = 0, len = name.length - 2; i < len; i++) {
|
|
349
|
-
char +=
|
|
340
|
+
char += '*'
|
|
350
341
|
}
|
|
351
|
-
value =
|
|
352
|
-
name.substring(0, 1) +
|
|
353
|
-
char +
|
|
354
|
-
name.substring(name.length - 1, name.length);
|
|
342
|
+
value = name.substring(0, 1) + char + name.substring(name.length - 1, name.length)
|
|
355
343
|
} else {
|
|
356
|
-
value = name
|
|
344
|
+
value = name
|
|
357
345
|
}
|
|
358
|
-
return value
|
|
359
|
-
}
|
|
346
|
+
return value
|
|
347
|
+
}
|