hy-app 0.2.1 → 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/components/hy-button/index.scss +2 -0
- package/components/hy-cell/index.scss +0 -15
- package/components/hy-code-input/hy-code-input.vue +224 -0
- package/components/hy-code-input/index.scss +108 -0
- package/components/hy-code-input/props.ts +21 -0
- package/components/hy-code-input/typing.d.ts +65 -0
- package/components/hy-config-provider/hy-config-provider.vue +0 -1
- package/components/hy-config-provider/props.ts +1 -1
- package/components/hy-dropdown/props.ts +1 -1
- package/components/hy-dropdown-item/hy-dropdown-item.vue +2 -5
- package/components/hy-dropdown-item/index.scss +11 -13
- package/components/hy-grid/hy-grid.vue +7 -8
- package/components/hy-grid/props.ts +4 -0
- package/components/hy-grid/typing.d.ts +15 -0
- package/components/hy-icon/index.scss +2 -1
- package/components/hy-login/TheUserLogin.vue +0 -1
- package/components/hy-menu/hy-menu.vue +159 -0
- package/components/hy-menu/index.scss +58 -0
- package/components/hy-menu/props.ts +12 -0
- package/components/hy-menu/typing.d.ts +57 -0
- package/components/hy-modal/hy-modal.vue +5 -5
- package/components/hy-modal/index.scss +0 -6
- package/components/hy-notify/hy-notify.vue +169 -0
- package/components/hy-notify/index.scss +25 -0
- package/components/hy-notify/props.ts +14 -0
- package/components/hy-notify/typing.d.ts +44 -0
- package/components/hy-pagination/hy-pagination.vue +125 -0
- package/components/hy-pagination/index.scss +46 -0
- package/components/hy-pagination/props.ts +15 -0
- package/components/hy-pagination/typing.d.ts +44 -0
- package/components/hy-picker/index.scss +4 -0
- package/components/hy-scroll-list/index.scss +1 -1
- package/components/hy-search/index.scss +1 -2
- package/components/hy-signature/canvasHelper.ts +51 -0
- package/components/hy-signature/hy-signature.vue +656 -0
- package/components/hy-signature/index.scss +29 -0
- package/components/hy-signature/props.ts +29 -0
- package/components/hy-signature/typing.d.ts +181 -0
- package/components/hy-slider/index.scss +5 -1
- package/components/hy-subsection/hy-subsection.vue +15 -13
- package/components/hy-subsection/props.ts +2 -2
- package/components/hy-subsection/typing.d.ts +1 -1
- package/components/hy-swipe-action/hy-swipe-action.vue +288 -248
- package/components/hy-swipe-action/index.scss +34 -0
- package/components/hy-swipe-action/index.ts +34 -0
- package/components/hy-swipe-action/props.ts +15 -9
- package/components/hy-swipe-action/typing.d.ts +20 -22
- package/components/hy-swiper/index.scss +5 -0
- package/components/hy-tabBar/hy-tabBar.vue +96 -0
- package/components/hy-tabBar/index.scss +169 -0
- package/components/hy-tabBar/props.ts +13 -0
- package/components/hy-tabBar/typing.d.ts +54 -0
- package/components/hy-tabs/index.scss +2 -2
- package/components/hy-tag/index.scss +1 -1
- package/components/hy-text/index.scss +2 -2
- package/components/hy-textarea/hy-textarea.vue +5 -5
- package/components/hy-textarea/index.scss +5 -6
- package/components/hy-tooltip/index.scss +2 -2
- package/components/hy-upload/index.scss +1 -2
- package/components/hy-watermark/hy-watermark.vue +603 -0
- package/components/hy-watermark/index.scss +15 -0
- package/components/hy-watermark/props.ts +23 -0
- package/components/hy-watermark/typing.d.ts +76 -0
- package/components/index.ts +2 -2
- package/composables/index.ts +1 -0
- package/composables/useTouch.ts +48 -0
- package/index.ts +1 -1
- package/libs/css/mixin.scss +52 -13
- package/libs/css/vars.css +12 -2
- package/package.json +2 -2
- package/theme.scss +24 -46
- package/typing/modules/common.d.ts +1 -1
- package/utils/inspect.ts +20 -0
- package/utils/utils.ts +52 -22
- package/components/hy-swipe-action/index.wxs +0 -235
- package/components/hy-swipe-action/wxs.js +0 -15
- package/components/yk-tabbar/props.ts +0 -49
- package/components/yk-tabbar/yk-tabbar.vue +0 -224
package/components/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import HyTabBr from "./hy-tabBar/hy-tabBar.vue";
|
|
2
2
|
import Dialog from "./dialog";
|
|
3
3
|
/* #ifdef H5 */
|
|
4
4
|
import DialogService from "./message";
|
|
@@ -63,7 +63,7 @@ import HyUpload from "./hy-upload/hy-upload.vue";
|
|
|
63
63
|
import HyWarn from "./hy-warn/hy-warn.vue";
|
|
64
64
|
|
|
65
65
|
const install = (Vue: any) => {
|
|
66
|
-
Vue.component("
|
|
66
|
+
Vue.component("hy-tabBar", HyTabBr);
|
|
67
67
|
|
|
68
68
|
Vue.component("HyAddressPicker", HyAddressPicker);
|
|
69
69
|
Vue.component("HyAvatar", HyAvatar);
|
package/composables/index.ts
CHANGED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { ref } from "vue";
|
|
2
|
+
|
|
3
|
+
export function useTouch() {
|
|
4
|
+
const direction = ref<string>("");
|
|
5
|
+
const deltaX = ref<number>(0);
|
|
6
|
+
const deltaY = ref<number>(0);
|
|
7
|
+
const offsetX = ref<number>(0);
|
|
8
|
+
const offsetY = ref<number>(0);
|
|
9
|
+
const startX = ref<number>(0);
|
|
10
|
+
const startY = ref<number>(0);
|
|
11
|
+
|
|
12
|
+
function touchStart(event: any) {
|
|
13
|
+
const touch = event.touches[0];
|
|
14
|
+
direction.value = "";
|
|
15
|
+
deltaX.value = 0;
|
|
16
|
+
deltaY.value = 0;
|
|
17
|
+
offsetX.value = 0;
|
|
18
|
+
offsetY.value = 0;
|
|
19
|
+
startX.value = touch.clientX;
|
|
20
|
+
startY.value = touch.clientY;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function touchMove(event: any) {
|
|
24
|
+
const touch = event.touches[0];
|
|
25
|
+
deltaX.value = touch.clientX - startX.value;
|
|
26
|
+
deltaY.value = touch.clientY - startY.value;
|
|
27
|
+
offsetX.value = Math.abs(deltaX.value);
|
|
28
|
+
offsetY.value = Math.abs(deltaY.value);
|
|
29
|
+
direction.value =
|
|
30
|
+
offsetX.value > offsetY.value
|
|
31
|
+
? "horizontal"
|
|
32
|
+
: offsetX.value < offsetY.value
|
|
33
|
+
? "vertical"
|
|
34
|
+
: "";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
touchStart,
|
|
39
|
+
touchMove,
|
|
40
|
+
direction,
|
|
41
|
+
deltaX,
|
|
42
|
+
deltaY,
|
|
43
|
+
offsetX,
|
|
44
|
+
offsetY,
|
|
45
|
+
startX,
|
|
46
|
+
startY,
|
|
47
|
+
};
|
|
48
|
+
}
|
package/index.ts
CHANGED
package/libs/css/mixin.scss
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
@use "../../theme.scss";
|
|
2
|
-
$namespace: hy;
|
|
3
|
-
$
|
|
2
|
+
$namespace: 'hy' !default;
|
|
3
|
+
$common-separator: '-' !default;
|
|
4
|
+
$element-separator: '__' !default;
|
|
5
|
+
$modifier-separator: '--' !default;
|
|
6
|
+
$state-prefix: 'is-' !default;
|
|
4
7
|
|
|
5
8
|
@mixin b($block) {
|
|
6
9
|
$B: $namespace + '-' + $block !global;
|
|
@@ -28,6 +31,53 @@ $modifier-separator: '--';
|
|
|
28
31
|
}
|
|
29
32
|
}
|
|
30
33
|
|
|
34
|
+
@mixin e($element) {
|
|
35
|
+
$E: $element !global;
|
|
36
|
+
$selector: &;
|
|
37
|
+
$currentSelector: '';
|
|
38
|
+
@each $unit in $element {
|
|
39
|
+
$currentSelector: #{$currentSelector +
|
|
40
|
+
'.' +
|
|
41
|
+
$B +
|
|
42
|
+
$element-separator +
|
|
43
|
+
$unit +
|
|
44
|
+
','};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@if hitAllSpecialNestRule($selector) {
|
|
48
|
+
@at-root {
|
|
49
|
+
#{$selector} {
|
|
50
|
+
#{$currentSelector} {
|
|
51
|
+
@content;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
} @else {
|
|
56
|
+
@at-root {
|
|
57
|
+
#{$currentSelector} {
|
|
58
|
+
@content;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/* 状态,生成 is-$state 类名 */
|
|
65
|
+
@mixin is($states...) {
|
|
66
|
+
@at-root {
|
|
67
|
+
@each $state in $states {
|
|
68
|
+
&.#{$state-prefix + $state} {
|
|
69
|
+
@content;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/* 添加伪类元素 */
|
|
75
|
+
@mixin pseudo($pseudo) {
|
|
76
|
+
@at-root #{&}#{':#{$pseudo}'} {
|
|
77
|
+
@content;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
31
81
|
@mixin themeColor($type, $bg-color: transparent, $border-color: transparent, $color: #FFFFFF) {
|
|
32
82
|
@include m($type) {
|
|
33
83
|
background-color: $bg-color;
|
|
@@ -62,17 +112,6 @@ $modifier-separator: '--';
|
|
|
62
112
|
flex-direction: $direction;
|
|
63
113
|
}
|
|
64
114
|
|
|
65
|
-
/* 状态,生成 is-$state 类名 */
|
|
66
|
-
@mixin when($states...) {
|
|
67
|
-
@at-root {
|
|
68
|
-
@each $state in $states {
|
|
69
|
-
&.#{$state-prefix + $state} {
|
|
70
|
-
@content;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
115
|
/* 几行出现省略号 */
|
|
77
116
|
@mixin line-feed($line: 1) {
|
|
78
117
|
display: -webkit-box;
|
package/libs/css/vars.css
CHANGED
|
@@ -5,19 +5,24 @@
|
|
|
5
5
|
--hy-text-color--2: #67676c;
|
|
6
6
|
--hy-text-color--3: #929295;
|
|
7
7
|
--hy-text-color--4: rgba(0, 0, 0, 0.1);
|
|
8
|
-
--hy-icon-color: #
|
|
8
|
+
--hy-icon-color: #999;
|
|
9
|
+
--hy-text-color--grey: #67676c;
|
|
9
10
|
--hy-text-color--placeholder: rgba(0, 0, 0, 0.25);
|
|
10
11
|
--hy-text-color--disabled: rgba(0, 0, 0, 0.25);
|
|
11
12
|
|
|
12
13
|
--hy-background: #f8f8f8;
|
|
13
14
|
--hy-background--2: #FFFFFF;
|
|
14
15
|
--hy-background--3: rgb(238, 238, 239);
|
|
16
|
+
--hy-background--track: #F6F6F6;
|
|
15
17
|
--hy-background--container: #FFFFFF;
|
|
16
18
|
--hy-background--disabled: rgba(0, 0, 0, 0.04);
|
|
17
19
|
--hy-background--empty: #F3F3F3;
|
|
18
|
-
--hy-background--hover: rgba(0,0,0,0.
|
|
20
|
+
--hy-background--hover: rgba(0,0,0,0.05);
|
|
21
|
+
--hy-background--active: #FFFFFF;
|
|
19
22
|
|
|
20
23
|
--hy-border-line: 1rpx solid #c2c2c4;
|
|
24
|
+
--hy-border-color: #c2c2c4;
|
|
25
|
+
--hy-border-color--2: #c9cacc;
|
|
21
26
|
}
|
|
22
27
|
|
|
23
28
|
.hy-theme--dark {
|
|
@@ -32,16 +37,21 @@
|
|
|
32
37
|
--hy-text-color-3: #6a6a71;
|
|
33
38
|
--hy-text-color--4: rgba(255, 255, 255, 0.1);
|
|
34
39
|
--hy-icon-color: #FFFFFF;
|
|
40
|
+
--hy-text-color--grey: #98989f;
|
|
35
41
|
--hy-text-color--placeholder: rgba(255, 255, 255, 0.25);
|
|
36
42
|
--hy-text-color--disabled: rgba(255, 255, 255, 0.25);
|
|
37
43
|
|
|
38
44
|
--hy-background: #1b1b1f;
|
|
39
45
|
--hy-background--2: #161616;
|
|
40
46
|
--hy-background--3: #646566;
|
|
47
|
+
--hy-background--track: #3A3A44;
|
|
41
48
|
--hy-background--container: #242424;
|
|
42
49
|
--hy-background--disabled: rgba(255, 255, 255, 0.08);
|
|
43
50
|
--hy-background--empty: #3A3A44;
|
|
44
51
|
--hy-background--hover: rgba(255,255,255,0.2);
|
|
52
|
+
--hy-background--active: #000000;
|
|
45
53
|
|
|
46
54
|
--hy-border-line: 1rpx solid #3c3f44;
|
|
55
|
+
--hy-border-color: #3c3f44;
|
|
56
|
+
--hy-border-color--2: #FFFFFF;
|
|
47
57
|
}
|
package/package.json
CHANGED
package/theme.scss
CHANGED
|
@@ -24,30 +24,30 @@ $hy-info-dark: var(--hy-info--dark, #82848a) !default;
|
|
|
24
24
|
$hy-info-disabled: var(--hy-info--disabled, #c8c9cc) !default;
|
|
25
25
|
$hy-info-light: var(--hy-info--light, #f4f4f5) !default;
|
|
26
26
|
|
|
27
|
+
/* 字体颜色 */
|
|
28
|
+
$hy-text-color: var(--hy-text-color, #3c3c43) !default; // 一般用于基础文字
|
|
29
|
+
$hy-text-color--2: var(--hy-text-color--2, #67676c) !default; // 一般用于提示
|
|
30
|
+
$hy-text-color--3: var(--hy-text-color--3, #929295) !default; // 一般用于浅色提示
|
|
31
|
+
$hy-text-color--4: var(--hy-text-color--4, rgba(0, 0, 0, 0.1)) !default; // 一般用于浅色
|
|
32
|
+
$hy-icon-color: var(--hy-icon-color, #606266) !default; // 一般用于icon
|
|
33
|
+
$hy-text-color--grey: var(--hy-text-color--grey, #999) !default; // 辅助灰色,如加载更多的提示信息
|
|
34
|
+
$hy-text-color--placeholder: var(--hy-text-color--placeholder, #808080) !default; // 输入框提示颜色
|
|
35
|
+
$hy-text-color--disabled: var(--hy-text-color--disabled, #c0c0c0) !default; // 禁用文字颜色
|
|
36
|
+
$hy-border-color: var(--hy-border-color, #c0c0c0) !default; // 边框颜色
|
|
37
|
+
$hy-text-color-hover: var(--hy-text-color-hover, #58595b)!default; // 点击状态文字颜色
|
|
27
38
|
|
|
28
|
-
$hy-dark-bg-disabled: rgba(48, 48, 56, 0.51) !default;
|
|
29
|
-
$hy-dark-color: #ffffff !default;
|
|
30
|
-
$hy-dark-icon: #7C7C7C !default;
|
|
31
|
-
$hy-dark-color2: var(#f2270c) !default;
|
|
32
|
-
$hy-dark-color3: var(rgba(232, 230, 227, 0.8)) !default;
|
|
33
|
-
$hy-dark-color-gray: var(#c0c0c0) !default;
|
|
34
|
-
$hy-dark-text-disabled: #c0c0c0 !default;
|
|
35
|
-
$hy-dark-border-color: var(#3a3a3c) !default;
|
|
36
39
|
|
|
37
|
-
/*
|
|
38
|
-
$hy-
|
|
39
|
-
$hy-
|
|
40
|
-
$hy-
|
|
41
|
-
$hy-
|
|
40
|
+
/* 背景色 */
|
|
41
|
+
$hy-background: var(--hy-background, #f8f8f8) !default; // 背景色
|
|
42
|
+
$hy-background--2: var(--hy-background--2, #ffffff) !default; // 弹窗背景色
|
|
43
|
+
$hy-background--3: var(--hy-background--3, #646566) !default; // 弹窗背景色
|
|
44
|
+
$hy-background--container: var(--hy-background--container, #ffffff) !default; // 容器背景色
|
|
45
|
+
$hy-background--disabled: var(--hy-background--disabled, #F5F5F5); // 禁用背景色
|
|
46
|
+
$hy-background--track: var(--hy-background--track, #F6F6F6) !default;
|
|
47
|
+
$hy-background--empty: var(--hy-background--empty, #F3F3F3) !default; // 搜索背景色
|
|
48
|
+
$hy-background--hover: var(--hy-background--hover, rgba(0,0,0,0.1)) !default; // 点击状态
|
|
42
49
|
$hy-light-background-mask: var(--hy-light-background-mask, rgba(0, 0, 0, 0.5)); //遮罩颜色
|
|
43
|
-
$hy-
|
|
44
|
-
|
|
45
|
-
/* 文字基本颜色 */
|
|
46
|
-
$hy-light-color: var(--hy-light-color, #333) !default; //基本色
|
|
47
|
-
$hy-text-color-hover: var(--hy-text-color-hover, #58595b)!default;
|
|
48
|
-
|
|
49
|
-
$hy-tips-color: #909193FF;
|
|
50
|
-
$hy-color-disable-icon: #c8c9cc;
|
|
50
|
+
$hy-background--active: var(--hy-background--active, #131313); // 选中状态值
|
|
51
51
|
|
|
52
52
|
/* 文字尺寸 */
|
|
53
53
|
$hy-font-size-sm: 12px;
|
|
@@ -68,7 +68,8 @@ $hy-font-size-hint: 26rpx;
|
|
|
68
68
|
|
|
69
69
|
/* 边框颜色 */
|
|
70
70
|
$hy-border-color-light: var(--hy-border-color-light, #c8c7cc) !default;
|
|
71
|
-
$hy-border-color: var(--hy-border-color, #
|
|
71
|
+
$hy-border-color: var(--hy-border-color, #c2c2c4) !default;
|
|
72
|
+
$hy-border-color--2: var(--hy-border-color--2, #c9cacc) !default;
|
|
72
73
|
|
|
73
74
|
/* 图片尺寸 */
|
|
74
75
|
$hy-img-size-sm: var(--hy-img-size-sm, 45rpx) !default;
|
|
@@ -97,27 +98,4 @@ $hy-border-margin-padding-sm: var(--hy-border-margin-padding-sm, 10rpx) !default
|
|
|
97
98
|
$hy-border-margin-padding-base: var(--hy-border-margin-padding-base, 20rpx) !default;
|
|
98
99
|
$hy-border-margin-padding-lg: var(--hy-border-margin-padding-lg, 30rpx) !default;
|
|
99
100
|
/* 底部线条 */
|
|
100
|
-
$hy-border-line: var(--hy-border-line, 1rpx solid #
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
/* 字体 */
|
|
104
|
-
$hy-text-color: var(--hy-text-color, #3c3c43) !default; // 一般用于文字
|
|
105
|
-
$hy-text-color--2: var(--hy-text-color--2, #67676c) !default; // 一般用于icon
|
|
106
|
-
$hy-text-color--3: var(--hy-text-color--3, #929295) !default; // 一般用于icon
|
|
107
|
-
$hy-text-color--4: var(--hy-text-color--4, #929295) !default; // 一般用于icon
|
|
108
|
-
$hy-icon-color: var(--hy-icon-color, #606266) !default; // 一般用于icon
|
|
109
|
-
$hy-text-color--grey: var(--hy-text-color-3, #999) !default; // 辅助灰色,如加载更多的提示信息
|
|
110
|
-
$hy-text-color--placeholder: var(--hy-text-color--placeholder, #808080) !default; // 输入框提示颜色
|
|
111
|
-
$hy-text-color--disabled: var(--hy-text-color--disabled, #c0c0c0) !default; // 禁用文字颜色
|
|
112
|
-
$hy-border-color: var(--hy-border-color, #c0c0c0) !default;
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
/* 背景色 */
|
|
116
|
-
$hy-background: var(--hy-background, #f8f8f8) !default; // 背景色
|
|
117
|
-
$hy-background--2: var(--hy-background--2, #ffffff) !default; // 弹窗背景色
|
|
118
|
-
$hy-background--3: var(--hy-background--3, #646566) !default; // 弹窗背景色
|
|
119
|
-
$hy-background--container: var(--hy-background--container, #ffffff) !default; // 容器背景色
|
|
120
|
-
$hy-background--disabled: var(--hy-background--disabled, #F5F5F5); // 禁用背景色
|
|
121
|
-
$hy-background--track: var(--hy-background--track, #c6c7cb) !default;
|
|
122
|
-
$hy-background--empty: var(--hy-background--empty, #f6f6f7) !default; // 搜索背景色
|
|
123
|
-
$hy-background--hover: var(--hy-background--hover, #707070) !default; // 点击状态
|
|
101
|
+
$hy-border-line: var(--hy-border-line, 1rpx solid #c2c2c4) !default;
|
package/utils/inspect.ts
CHANGED
|
@@ -113,3 +113,23 @@ export const isChinese = (zh: string): boolean => {
|
|
|
113
113
|
const reg = /^[\u4e00-\u9fa5]+$/gi;
|
|
114
114
|
return reg.test(zh);
|
|
115
115
|
};
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* 是否为base64图片
|
|
119
|
+
* @param {string} url
|
|
120
|
+
* @return
|
|
121
|
+
*/
|
|
122
|
+
export function isBase64Image(url: string) {
|
|
123
|
+
// 使用正则表达式检查URL是否以"data:image"开头,这是Base64图片的常见前缀
|
|
124
|
+
return /^data:image\/(png|jpg|jpeg|gif|bmp);base64,/.test(url);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* 是否图片
|
|
129
|
+
* @param {string} url
|
|
130
|
+
* @return
|
|
131
|
+
*/
|
|
132
|
+
export function isImage(url: string) {
|
|
133
|
+
// 使用正则表达式检查URL是否以"data:image"开头,这是Base64图片的常见前缀
|
|
134
|
+
return /(\.jpg|\.jpeg|\.png|\.gif|\.bmp|\.webp)$/i.test(url);
|
|
135
|
+
}
|
package/utils/utils.ts
CHANGED
|
@@ -364,7 +364,10 @@ const random = (min: number | string, max: number | string): number => {
|
|
|
364
364
|
const range = (min = 0, max = 0, value = 0) => {
|
|
365
365
|
return Math.max(min, Math.min(max, Number(value)));
|
|
366
366
|
};
|
|
367
|
-
|
|
367
|
+
|
|
368
|
+
export type RectResultType<T extends boolean> = T extends true
|
|
369
|
+
? UniApp.NodeInfo[]
|
|
370
|
+
: UniApp.NodeInfo;
|
|
368
371
|
/**
|
|
369
372
|
* 查询节点信息
|
|
370
373
|
* 目前此方法在支付宝小程序中无法获取组件跟接点的尺寸,为支付宝的bug(2020-07-21)
|
|
@@ -372,32 +375,59 @@ let instance: any;
|
|
|
372
375
|
* @param selector 元素类名或id
|
|
373
376
|
* @param all 是否获取多个相同元素数值
|
|
374
377
|
* @param ins 在微信小程序里,因为utils文件里面获取不到instance值所以必须通过ins这个传过来
|
|
378
|
+
* @param useFields 是否使用 fields 方法获取节点信息
|
|
375
379
|
*/
|
|
376
380
|
const getRect = (
|
|
377
381
|
selector: string,
|
|
378
|
-
all?:
|
|
382
|
+
all?: T,
|
|
379
383
|
ins?: any,
|
|
380
|
-
|
|
381
|
-
|
|
384
|
+
useFields?: boolean,
|
|
385
|
+
): Promise<RectResultType<T>> => {
|
|
386
|
+
return new Promise<RectResultType<T>>((resolve, reject) => {
|
|
387
|
+
let query: UniNamespace.SelectorQuery | null = null;
|
|
382
388
|
// TODO: 在微信小程序里,因为utils文件里面获取不到instance值所以必须通过ins这个传过来
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
.
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
389
|
+
if (ins) {
|
|
390
|
+
query = uni.createSelectorQuery().in(ins);
|
|
391
|
+
} else {
|
|
392
|
+
query = uni.createSelectorQuery();
|
|
393
|
+
}
|
|
394
|
+
const method = all ? "selectAll" : "select";
|
|
395
|
+
|
|
396
|
+
const callback = (rect: UniApp.NodeInfo | UniApp.NodeInfo[]) => {
|
|
397
|
+
if (all && Array.isArray(rect) && rect.length > 0) {
|
|
398
|
+
resolve(rect as RectResultType<T>);
|
|
399
|
+
} else if (!all && rect) {
|
|
400
|
+
resolve(rect as RectResultType<T>);
|
|
401
|
+
} else {
|
|
402
|
+
reject(new Error("No nodes found"));
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
if (useFields) {
|
|
407
|
+
query[method](selector)
|
|
408
|
+
.fields({ size: true, node: true }, callback)
|
|
409
|
+
.exec();
|
|
410
|
+
} else {
|
|
411
|
+
query[method](selector).boundingClientRect(callback).exec();
|
|
412
|
+
}
|
|
413
|
+
// // #ifdef MP-WEIXIN
|
|
414
|
+
// instance = ins;
|
|
415
|
+
// // #endif
|
|
416
|
+
// // #ifndef APP-NVUE
|
|
417
|
+
// uni
|
|
418
|
+
// .createSelectorQuery()
|
|
419
|
+
// .in(instance)
|
|
420
|
+
// [all ? "selectAll" : "select"](selector)
|
|
421
|
+
// .boundingClientRect((rect) => {
|
|
422
|
+
// if (all && Array.isArray(rect) && rect.length) {
|
|
423
|
+
// resolve(rect as UniApp.NodeInfo[]);
|
|
424
|
+
// }
|
|
425
|
+
// if (!all && rect) {
|
|
426
|
+
// resolve(rect as UniApp.NodeInfo);
|
|
427
|
+
// }
|
|
428
|
+
// })
|
|
429
|
+
// .exec();
|
|
430
|
+
// // #endif
|
|
401
431
|
});
|
|
402
432
|
};
|
|
403
433
|
|
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 此为wxs模块,只支持APP-VUE,微信和QQ小程序以及H5平台
|
|
3
|
-
* wxs内部不支持es6语法,变量只能使用var定义,无法使用解构,箭头函数等特性
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
// 开始触摸
|
|
8
|
-
function touchstart(event, ownerInstance) {
|
|
9
|
-
// 触发事件的组件的ComponentDescriptor实例
|
|
10
|
-
var instance = event.instance
|
|
11
|
-
// wxs内的局部变量快照,此快照是属于整个组件的,在touchstart和touchmove事件中都能获取到相同的结果
|
|
12
|
-
var state = instance.getState()
|
|
13
|
-
if (state.disabled) return
|
|
14
|
-
var touches = event.touches
|
|
15
|
-
// 如果进行的是多指触控,不允许进行操作
|
|
16
|
-
if (touches && touches.length > 1) return
|
|
17
|
-
// 标识当前为滑动中状态
|
|
18
|
-
state.moving = true
|
|
19
|
-
// 记录触摸开始点的坐标值
|
|
20
|
-
state.startX = touches[0].pageX
|
|
21
|
-
state.startY = touches[0].pageY
|
|
22
|
-
|
|
23
|
-
ownerInstance.callMethod('closeOther')
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// 触摸滑动
|
|
27
|
-
function touchmove(event, ownerInstance) {
|
|
28
|
-
// 触发事件的组件的ComponentDescriptor实例
|
|
29
|
-
var instance = event.instance
|
|
30
|
-
// wxs内的局部变量快照
|
|
31
|
-
var state = instance.getState()
|
|
32
|
-
if (state.disabled || !state.moving) return
|
|
33
|
-
var touches = event.touches
|
|
34
|
-
var pageX = touches[0].pageX
|
|
35
|
-
var pageY = touches[0].pageY
|
|
36
|
-
var moveX = pageX - state.startX
|
|
37
|
-
var moveY = pageY - state.startY
|
|
38
|
-
var buttonsWidth = state.buttonsWidth
|
|
39
|
-
|
|
40
|
-
// 移动的X轴距离大于Y轴距离,也即终点与起点位置连线,与X轴夹角小于45度时,禁止页面滚动
|
|
41
|
-
if (Math.abs(moveX) > Math.abs(moveY) || Math.abs(moveX) > state.threshold) {
|
|
42
|
-
event.preventDefault && event.preventDefault()
|
|
43
|
-
event.stopPropagation && event.stopPropagation()
|
|
44
|
-
}
|
|
45
|
-
// 如果移动的X轴距离小于Y轴距离,也即终点位置与起点位置连线,与Y轴夹角小于45度时,认为是页面上下滑动,而不是左右滑动单元格
|
|
46
|
-
if (Math.abs(moveX) < Math.abs(moveY)) return
|
|
47
|
-
|
|
48
|
-
// 限制右滑的距离,不允许内容部分往右偏移,右滑会导致X轴偏移值大于0,以此做判断
|
|
49
|
-
// 此处不能直接return,因为滑动过程中会缺失某些关键点坐标,会导致错乱,最好的办法就是
|
|
50
|
-
// 在超出后,设置为0
|
|
51
|
-
if (state.status === 'open') {
|
|
52
|
-
// 在开启状态下,向左滑动,需忽略
|
|
53
|
-
if (moveX < 0) moveX = 0
|
|
54
|
-
// 想要收起菜单,最大能移动的距离为按钮的总宽度
|
|
55
|
-
if (moveX > buttonsWidth) moveX = buttonsWidth
|
|
56
|
-
// 如果是已经打开了的状态,向左滑动时,移动收起菜单
|
|
57
|
-
moveSwipeAction(-buttonsWidth + moveX, instance, ownerInstance)
|
|
58
|
-
} else {
|
|
59
|
-
// 关闭状态下,右滑动需忽略
|
|
60
|
-
if (moveX > 0) moveX = 0
|
|
61
|
-
// 滑动的距离不允许超过所有按钮的总宽度,此时只能是左滑,最终设置按钮的总宽度,同时为负数
|
|
62
|
-
if (Math.abs(moveX) > buttonsWidth) moveX = -buttonsWidth
|
|
63
|
-
// 只要是在滑过程中,就不断移动单元格内容部分,从而使隐藏的菜单显示出来
|
|
64
|
-
moveSwipeAction(moveX, instance, ownerInstance)
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// 触摸结束
|
|
69
|
-
function touchend(event, ownerInstance) {
|
|
70
|
-
// 触发事件的组件的ComponentDescriptor实例
|
|
71
|
-
var instance = event.instance
|
|
72
|
-
// wxs内的局部变量快照
|
|
73
|
-
var state = instance.getState()
|
|
74
|
-
if (!state.moving || state.disabled) return
|
|
75
|
-
var touches = event.changedTouches ? event.changedTouches[0] : {}
|
|
76
|
-
var pageX = touches.pageX
|
|
77
|
-
var pageY = touches.pageY
|
|
78
|
-
var moveX = pageX - state.startX
|
|
79
|
-
if (state.status === 'open') {
|
|
80
|
-
// 在展开的状态下,继续左滑,无需操作
|
|
81
|
-
if (moveX < 0) return
|
|
82
|
-
// 在开启状态下,点击一下内容区域,moveX为0,也即没有进行移动,这时执行收起菜单逻辑
|
|
83
|
-
if (moveX === 0) {
|
|
84
|
-
return closeSwipeAction(instance, ownerInstance)
|
|
85
|
-
}
|
|
86
|
-
// 在开启状态下,滑动距离小于阈值,则默认为不关闭,同时恢复原来的打开状态
|
|
87
|
-
if (Math.abs(moveX) < state.threshold) {
|
|
88
|
-
openSwipeAction(instance, ownerInstance)
|
|
89
|
-
} else {
|
|
90
|
-
// 如果滑动距离大于阈值,则执行收起逻辑
|
|
91
|
-
closeSwipeAction(instance, ownerInstance)
|
|
92
|
-
}
|
|
93
|
-
} else {
|
|
94
|
-
// 在关闭的状态下,右滑,无需操作
|
|
95
|
-
if (moveX > 0) return
|
|
96
|
-
// 理由同上
|
|
97
|
-
if (Math.abs(moveX) < state.threshold) {
|
|
98
|
-
closeSwipeAction(instance, ownerInstance)
|
|
99
|
-
} else {
|
|
100
|
-
openSwipeAction(instance, ownerInstance)
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// 获取过渡时间
|
|
106
|
-
function getDuration(value) {
|
|
107
|
-
if (value.toString().indexOf('s') >= 0) return value
|
|
108
|
-
return value > 30 ? value + 'ms' : value + 's'
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// 滑动结束时判断滑动的方向
|
|
112
|
-
function getMoveDirection(instance, ownerInstance) {
|
|
113
|
-
var state = instance.getState()
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// 移动滑动选择器内容区域,同时显示出其隐藏的菜单
|
|
117
|
-
function moveSwipeAction(moveX, instance, ownerInstance) {
|
|
118
|
-
var state = instance.getState()
|
|
119
|
-
// 获取所有按钮的实例,需要通过它去设置按钮的位移
|
|
120
|
-
var buttons = ownerInstance.selectAllComponents('.hy-swipe-action-item__right__button')
|
|
121
|
-
|
|
122
|
-
// 设置菜单内容部分的偏移
|
|
123
|
-
instance.requestAnimationFrame(function() {
|
|
124
|
-
instance.setStyle({
|
|
125
|
-
// 设置translateX的值
|
|
126
|
-
'transition': 'none',
|
|
127
|
-
transform: 'translateX(' + moveX + 'px)',
|
|
128
|
-
'-webkit-transform': 'translateX(' + moveX + 'px)'
|
|
129
|
-
})
|
|
130
|
-
})
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// 一次性展开滑动菜单
|
|
134
|
-
function openSwipeAction(instance, ownerInstance) {
|
|
135
|
-
var state = instance.getState()
|
|
136
|
-
// 获取所有按钮的实例,需要通过它去设置按钮的位移
|
|
137
|
-
var buttons = ownerInstance.selectAllComponents('.hy-swipe-action-item__right__button')
|
|
138
|
-
// 处理duration单位问题
|
|
139
|
-
var duration = getDuration(state.duration)
|
|
140
|
-
// 展开过程中,是向左移动,所以X的偏移应该为负值
|
|
141
|
-
var buttonsWidth = -state.buttonsWidth
|
|
142
|
-
instance.requestAnimationFrame(function() {
|
|
143
|
-
// 设置菜单主体内容
|
|
144
|
-
instance.setStyle({
|
|
145
|
-
'transition': 'transform ' + duration,
|
|
146
|
-
'transform': 'translateX(' + buttonsWidth + 'px)',
|
|
147
|
-
'-webkit-transform': 'translateX(' + buttonsWidth + 'px)',
|
|
148
|
-
})
|
|
149
|
-
})
|
|
150
|
-
setStatus('open', instance, ownerInstance)
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// 标记菜单的当前状态,open-已经打开,close-已经关闭
|
|
154
|
-
function setStatus(status, instance, ownerInstance) {
|
|
155
|
-
var state = instance.getState()
|
|
156
|
-
state.status = status
|
|
157
|
-
ownerInstance.callMethod('setState', status)
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// 一次性收起滑动菜单
|
|
161
|
-
function closeSwipeAction(instance, ownerInstance) {
|
|
162
|
-
var state = instance.getState()
|
|
163
|
-
// 获取所有按钮的实例,需要通过它去设置按钮的位移
|
|
164
|
-
var buttons = ownerInstance.selectAllComponents('.hy-swipe-action-item__right__button')
|
|
165
|
-
var len = buttons.length
|
|
166
|
-
// 处理duration单位问题
|
|
167
|
-
var duration = getDuration(state.duration)
|
|
168
|
-
instance.requestAnimationFrame(function() {
|
|
169
|
-
// 设置菜单主体内容
|
|
170
|
-
instance.setStyle({
|
|
171
|
-
'transition': 'transform ' + duration,
|
|
172
|
-
'transform': 'translateX(0px)',
|
|
173
|
-
'-webkit-transform': 'translateX(0px)'
|
|
174
|
-
})
|
|
175
|
-
// 设置各个隐藏的按钮为收起的状态
|
|
176
|
-
for (var i = len - 1; i >= 0; i--) {
|
|
177
|
-
buttons[i].setStyle({
|
|
178
|
-
'transition': 'transform ' + duration,
|
|
179
|
-
'transform': 'translateX(0px)',
|
|
180
|
-
'-webkit-transform': 'translateX(0px)'
|
|
181
|
-
})
|
|
182
|
-
}
|
|
183
|
-
})
|
|
184
|
-
setStatus('close', instance, ownerInstance)
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// status的状态发生变化
|
|
188
|
-
function statusChange(newValue, oldValue, ownerInstance, instance) {
|
|
189
|
-
var state = instance.getState()
|
|
190
|
-
if (state.disabled) return
|
|
191
|
-
// 打开或关闭单元格
|
|
192
|
-
if (newValue === 'close' && state.status === 'open') {
|
|
193
|
-
closeSwipeAction(instance, ownerInstance)
|
|
194
|
-
} else if(newValue === 'open' && state.status === 'close') {
|
|
195
|
-
openSwipeAction(instance, ownerInstance)
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// 菜单尺寸发生变化
|
|
200
|
-
function sizeChange(newValue, oldValue, ownerInstance, instance) {
|
|
201
|
-
// wxs内的局部变量快照
|
|
202
|
-
var state = instance.getState()
|
|
203
|
-
// 临时防止nv_disabled报错
|
|
204
|
-
if (!state || !newValue) {
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
state.disabled = newValue.disabled
|
|
208
|
-
state.duration = newValue.duration
|
|
209
|
-
state.show = newValue.show
|
|
210
|
-
state.threshold = newValue.threshold
|
|
211
|
-
state.buttons = newValue.buttons
|
|
212
|
-
|
|
213
|
-
if (state.buttons) {
|
|
214
|
-
var len = state.buttons.length
|
|
215
|
-
var buttonsWidth = 0
|
|
216
|
-
var buttons = newValue.buttons
|
|
217
|
-
for (var i = 0; i < len; i++) {
|
|
218
|
-
buttonsWidth += buttons[i].width
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
state.buttonsWidth = buttonsWidth
|
|
222
|
-
|
|
223
|
-
// 支持默认打开
|
|
224
|
-
if (state.show) {
|
|
225
|
-
openSwipeAction(instance, ownerInstance)
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
module.exports = {
|
|
230
|
-
touchstart: touchstart,
|
|
231
|
-
touchmove: touchmove,
|
|
232
|
-
touchend: touchend,
|
|
233
|
-
sizeChange: sizeChange,
|
|
234
|
-
statusChange: statusChange
|
|
235
|
-
}
|