hy-app 0.5.13 → 0.5.14
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 +3 -0
- package/components/hy-cell-item/hy-cell-item.vue +161 -161
- package/components/hy-cell-item/props.ts +59 -66
- package/components/hy-config-provider/index.scss +5 -8
- package/components/hy-folding-panel/hy-folding-panel-group.vue +163 -0
- package/components/hy-index-bar/hy-index-bar.vue +197 -0
- package/components/hy-index-bar/index.scss +65 -0
- package/components/hy-index-bar/props.ts +94 -0
- package/components/hy-index-bar/typing.d.ts +36 -0
- package/components/hy-number-step/hy-number-step.vue +367 -367
- package/components/hy-number-step/index.scss +14 -5
- package/components/hy-qrcode/qrcode.js.bak +1434 -0
- package/components/hy-table/hy-table.vue +30 -13
- package/components/hy-table/index.scss +6 -1
- package/components/hy-table/props.ts +1 -1
- package/components/hy-tag/index.scss +4 -13
- package/global.d.ts +92 -91
- package/libs/utils/utils.ts +503 -521
- package/package.json +2 -2
- package/web-types.json +1 -1
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="hy-index-bar" :class="indexBarClass" :style="indexBarStyle">
|
|
3
|
+
<view class="hy-index-bar__index--list">
|
|
4
|
+
<view
|
|
5
|
+
v-for="(item, index) in indexList"
|
|
6
|
+
:key="index"
|
|
7
|
+
class="hy-index-bar__index--list__item"
|
|
8
|
+
:class="{ 'is-active': modelValue === indexValue(item) }"
|
|
9
|
+
:style="getIndexItemStyle(indexValue(item))"
|
|
10
|
+
@click="handleIndexClick(indexValue(item), $event)"
|
|
11
|
+
@touchstart="handleTouchStart($event)"
|
|
12
|
+
@touchmove="handleTouchMove($event)"
|
|
13
|
+
@touchend="handleTouchEnd"
|
|
14
|
+
>
|
|
15
|
+
{{ indexValue(item) }}
|
|
16
|
+
</view>
|
|
17
|
+
|
|
18
|
+
<!-- 索引字母提示 -->
|
|
19
|
+
<hy-transition :show="showToast && isTouching" :customStyle="toastStyle">
|
|
20
|
+
<view class="hy-index-bar__toast">
|
|
21
|
+
<text class="hy-index-bar__toast--text">{{ modelValue }}</text>
|
|
22
|
+
</view>
|
|
23
|
+
</hy-transition>
|
|
24
|
+
</view>
|
|
25
|
+
</view>
|
|
26
|
+
</template>
|
|
27
|
+
|
|
28
|
+
<script lang="ts">
|
|
29
|
+
export default {
|
|
30
|
+
name: 'hy-index-bar',
|
|
31
|
+
options: {
|
|
32
|
+
addGlobalClass: true,
|
|
33
|
+
virtualHost: true,
|
|
34
|
+
styleIsolation: 'shared'
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
</script>
|
|
38
|
+
|
|
39
|
+
<script setup lang="ts">
|
|
40
|
+
import { computed, ref, onMounted, getCurrentInstance, nextTick } from 'vue'
|
|
41
|
+
import type { CSSProperties } from 'vue'
|
|
42
|
+
import type { IIndexBarEmits, IIndexItem } from './typing'
|
|
43
|
+
import { addUnit, getRect, sleep } from '../../libs'
|
|
44
|
+
import indexBarProps from './props'
|
|
45
|
+
// 组件
|
|
46
|
+
import HyTransition from '../hy-transition/hy-transition.vue'
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 索引栏组件,用于快速定位列表内容的索引栏组件,支持点击和滑动两种交互方式
|
|
50
|
+
* @displayName hy-index-bar
|
|
51
|
+
*/
|
|
52
|
+
defineOptions({})
|
|
53
|
+
|
|
54
|
+
const props = defineProps(indexBarProps)
|
|
55
|
+
const emit = defineEmits<IIndexBarEmits>()
|
|
56
|
+
|
|
57
|
+
// 获取当前组件实例
|
|
58
|
+
const instance = getCurrentInstance()
|
|
59
|
+
|
|
60
|
+
// 使用props中的activeIndex,同时保持内部状态用于点击事件
|
|
61
|
+
const isTouching = ref<boolean>(false)
|
|
62
|
+
const lastIndex = ref<string>('')
|
|
63
|
+
const toastStyle = ref<CSSProperties>({
|
|
64
|
+
position: 'absolute',
|
|
65
|
+
left: '-150rpx',
|
|
66
|
+
zIndex: 10
|
|
67
|
+
})
|
|
68
|
+
// 缓存索引栏高度和索引项高度
|
|
69
|
+
const indexBarRect = ref<UniNamespace.NodeInfo>()
|
|
70
|
+
const itemHeight = ref<number>(0)
|
|
71
|
+
|
|
72
|
+
const indexBarClass = computed<string[]>(() => {
|
|
73
|
+
return [`hy-index-bar--${props.position}`]
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
const indexBarStyle = computed<CSSProperties>(() => {
|
|
77
|
+
return {
|
|
78
|
+
width: addUnit(props.width),
|
|
79
|
+
height: addUnit(props.height),
|
|
80
|
+
...props.customStyle
|
|
81
|
+
}
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
const indexValue = computed(() => {
|
|
85
|
+
return (item: IIndexItem) => {
|
|
86
|
+
return typeof item === 'object' && item !== null ? item.index : item
|
|
87
|
+
}
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
// 缓存索引项样式,避免重复计算
|
|
91
|
+
const indexItemStyles = computed(() => {
|
|
92
|
+
// 计算通用样式部分
|
|
93
|
+
const commonStyle = {
|
|
94
|
+
width: addUnit(props.width),
|
|
95
|
+
height: addUnit(props.width),
|
|
96
|
+
fontSize: addUnit(props.indexSize)
|
|
97
|
+
} as CSSProperties
|
|
98
|
+
console.log(
|
|
99
|
+
props.indexList.reduce((styles: Record<string, CSSProperties>, item: IIndexItem) => {
|
|
100
|
+
const isActive = props.modelValue === indexValue.value(item)
|
|
101
|
+
styles[indexValue.value(item)] = {
|
|
102
|
+
...commonStyle,
|
|
103
|
+
color: isActive ? props.activeIndexColor : props.indexColor,
|
|
104
|
+
backgroundColor: isActive ? props.activeIndexBgColor : props.indexBgColor
|
|
105
|
+
}
|
|
106
|
+
return styles
|
|
107
|
+
}, {})
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
// 为每个索引项创建样式对象并缓存
|
|
111
|
+
return props.indexList.reduce((styles: Record<string, CSSProperties>, item: IIndexItem) => {
|
|
112
|
+
const isActive = props.modelValue === indexValue.value(item)
|
|
113
|
+
styles[indexValue.value(item)] = {
|
|
114
|
+
...commonStyle,
|
|
115
|
+
color: isActive ? props.activeIndexColor : props.indexColor,
|
|
116
|
+
backgroundColor: isActive ? props.activeIndexBgColor : props.indexBgColor
|
|
117
|
+
}
|
|
118
|
+
return styles
|
|
119
|
+
}, {})
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
// 获取索引项样式的便捷方法
|
|
123
|
+
const getIndexItemStyle = (index: string) => {
|
|
124
|
+
console.log(index, '===')
|
|
125
|
+
return indexItemStyles.value[index] || {}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const handleIndexClick = (index: string, event: any) => {
|
|
129
|
+
emit('update:modelValue', index)
|
|
130
|
+
emit('click', index, event)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const handleTouchStart = (event: any) => {
|
|
134
|
+
isTouching.value = true
|
|
135
|
+
handleTouchMove(event)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// 触摸移动事件处理
|
|
139
|
+
const handleTouchMove = (event: any) => {
|
|
140
|
+
// 获取触摸点坐标
|
|
141
|
+
const touch = event.touches ? event.touches[0] : event
|
|
142
|
+
const touchY = (touch.clientY || touch.y) - indexBarRect.value?.top!
|
|
143
|
+
|
|
144
|
+
// 计算当前触摸的索引位置
|
|
145
|
+
const index = Math.min(
|
|
146
|
+
Math.max(Math.floor(touchY / itemHeight.value), 0),
|
|
147
|
+
props.indexList.length - 1
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
const clickedIndex = props.indexList[index]?.index || props.indexList[index]
|
|
151
|
+
if (clickedIndex) {
|
|
152
|
+
// 只有当索引发生变化时才更新activeIndex
|
|
153
|
+
if (clickedIndex !== props.modelValue) {
|
|
154
|
+
emit('update:modelValue', clickedIndex)
|
|
155
|
+
emit('scroll', clickedIndex)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// 只有当索引发生变化时才更新toast
|
|
159
|
+
if (clickedIndex !== lastIndex.value) {
|
|
160
|
+
lastIndex.value = clickedIndex
|
|
161
|
+
|
|
162
|
+
// 计算Toast的位置 - 使其与当前索引项对齐
|
|
163
|
+
let toastTop =
|
|
164
|
+
indexBarRect.value?.top! + index * itemHeight.value - 25 + itemHeight.value / 2
|
|
165
|
+
// #ifdef H5
|
|
166
|
+
toastTop = toastTop + 44 // h5需要加上导航栏高度
|
|
167
|
+
// #endif
|
|
168
|
+
toastStyle.value.top = addUnit(toastTop)
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const handleTouchEnd = async () => {
|
|
174
|
+
await sleep(1000)
|
|
175
|
+
isTouching.value = false
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* 获取列表元素属性值
|
|
180
|
+
* */
|
|
181
|
+
const init = () => {
|
|
182
|
+
nextTick(() => {
|
|
183
|
+
getRect('.hy-index-bar__index--list', false, instance).then((rect) => {
|
|
184
|
+
indexBarRect.value = rect
|
|
185
|
+
itemHeight.value = rect.height! / props.indexList.length
|
|
186
|
+
})
|
|
187
|
+
})
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
onMounted(() => {
|
|
191
|
+
init()
|
|
192
|
+
})
|
|
193
|
+
</script>
|
|
194
|
+
|
|
195
|
+
<style lang="scss" scoped>
|
|
196
|
+
@import './index.scss';
|
|
197
|
+
</style>
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
@use "../../libs/css/mixin" as *;
|
|
2
|
+
@use "../../libs/css/theme" as *;
|
|
3
|
+
|
|
4
|
+
@include b(index-bar) {
|
|
5
|
+
position: fixed;
|
|
6
|
+
top: 0;
|
|
7
|
+
bottom: 0;
|
|
8
|
+
display: flex;
|
|
9
|
+
flex-direction: column;
|
|
10
|
+
justify-content: center;
|
|
11
|
+
align-items: center;
|
|
12
|
+
z-index: 999;
|
|
13
|
+
transform: translateZ(0);
|
|
14
|
+
-webkit-transform: translateZ(0);
|
|
15
|
+
|
|
16
|
+
@include m(left) {
|
|
17
|
+
left: 0;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@include m(right) {
|
|
21
|
+
right: 0;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@include e(index) {
|
|
25
|
+
@include m(list) {
|
|
26
|
+
display: flex;
|
|
27
|
+
flex-direction: column;
|
|
28
|
+
align-items: center;
|
|
29
|
+
margin-right: $hy-border-margin-padding-base;
|
|
30
|
+
|
|
31
|
+
@include e(item) {
|
|
32
|
+
display: flex;
|
|
33
|
+
align-items: center;
|
|
34
|
+
justify-content: center;
|
|
35
|
+
color: $hy-text-color--3;
|
|
36
|
+
margin: 2rpx 0;
|
|
37
|
+
border-radius: $hy-border-radius-sm;
|
|
38
|
+
|
|
39
|
+
@include is(active) {
|
|
40
|
+
position: relative;
|
|
41
|
+
color: $hy-primary;
|
|
42
|
+
background: $hy-background--hover;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@include e(toast) {
|
|
49
|
+
width: 50px;
|
|
50
|
+
height: 50px;
|
|
51
|
+
border-radius: 100px 100px 0 100px;
|
|
52
|
+
text-align: center;
|
|
53
|
+
color: #ffffff;
|
|
54
|
+
background-color: #c9c9c9;
|
|
55
|
+
transform: rotate(-45deg);
|
|
56
|
+
display: flex;
|
|
57
|
+
justify-content: center;
|
|
58
|
+
align-items: center;
|
|
59
|
+
|
|
60
|
+
@include m(text) {
|
|
61
|
+
transform: rotate(45deg);
|
|
62
|
+
font-size: $hy-font-size-lg;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { CSSProperties, PropType } from 'vue'
|
|
2
|
+
import type { IIndexItem } from './typing'
|
|
3
|
+
|
|
4
|
+
const indexBarProps = {
|
|
5
|
+
/**
|
|
6
|
+
* 当前激活的索引
|
|
7
|
+
*/
|
|
8
|
+
modelValue: {
|
|
9
|
+
type: String,
|
|
10
|
+
default: '',
|
|
11
|
+
required: true
|
|
12
|
+
},
|
|
13
|
+
/**
|
|
14
|
+
* 索引列表数据
|
|
15
|
+
*/
|
|
16
|
+
indexList: {
|
|
17
|
+
type: Array as PropType<IIndexItem[]>,
|
|
18
|
+
default: () => []
|
|
19
|
+
},
|
|
20
|
+
/**
|
|
21
|
+
* 索引栏位置
|
|
22
|
+
* @values left, right
|
|
23
|
+
*/
|
|
24
|
+
position: {
|
|
25
|
+
type: String,
|
|
26
|
+
default: 'right'
|
|
27
|
+
},
|
|
28
|
+
/**
|
|
29
|
+
* 是否显示索引字母提示
|
|
30
|
+
*/
|
|
31
|
+
showToast: {
|
|
32
|
+
type: Boolean,
|
|
33
|
+
default: true
|
|
34
|
+
},
|
|
35
|
+
/**
|
|
36
|
+
* 索引项颜色
|
|
37
|
+
*/
|
|
38
|
+
indexColor: {
|
|
39
|
+
type: String,
|
|
40
|
+
default: ''
|
|
41
|
+
},
|
|
42
|
+
/**
|
|
43
|
+
* 激活索引项颜色
|
|
44
|
+
*/
|
|
45
|
+
activeIndexColor: {
|
|
46
|
+
type: String,
|
|
47
|
+
default: ''
|
|
48
|
+
},
|
|
49
|
+
/**
|
|
50
|
+
* 索引项背景色
|
|
51
|
+
*/
|
|
52
|
+
indexBgColor: {
|
|
53
|
+
type: String,
|
|
54
|
+
default: 'transparent'
|
|
55
|
+
},
|
|
56
|
+
/**
|
|
57
|
+
* 激活索引项背景色
|
|
58
|
+
*/
|
|
59
|
+
activeIndexBgColor: {
|
|
60
|
+
type: String,
|
|
61
|
+
default: ''
|
|
62
|
+
},
|
|
63
|
+
/**
|
|
64
|
+
* 索引项大小
|
|
65
|
+
*/
|
|
66
|
+
indexSize: {
|
|
67
|
+
type: [Number, String],
|
|
68
|
+
default: 12
|
|
69
|
+
},
|
|
70
|
+
/**
|
|
71
|
+
* 索引栏高度
|
|
72
|
+
*/
|
|
73
|
+
height: {
|
|
74
|
+
type: [Number, String],
|
|
75
|
+
default: '100%'
|
|
76
|
+
},
|
|
77
|
+
/**
|
|
78
|
+
* 索引栏宽度
|
|
79
|
+
*/
|
|
80
|
+
width: {
|
|
81
|
+
type: [Number, String],
|
|
82
|
+
default: 20
|
|
83
|
+
},
|
|
84
|
+
/**
|
|
85
|
+
* 自定义样式
|
|
86
|
+
*/
|
|
87
|
+
customStyle: Object as PropType<CSSProperties>,
|
|
88
|
+
/**
|
|
89
|
+
* 自定义外部类名
|
|
90
|
+
*/
|
|
91
|
+
customClass: String
|
|
92
|
+
} as const
|
|
93
|
+
|
|
94
|
+
export default indexBarProps
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ExtractPropTypes } from 'vue'
|
|
2
|
+
import type indexBarProps from './props'
|
|
3
|
+
|
|
4
|
+
export interface HyIndexBarProps extends ExtractPropTypes<typeof indexBarProps> {}
|
|
5
|
+
|
|
6
|
+
export interface IndexType {
|
|
7
|
+
/**
|
|
8
|
+
* 索引值
|
|
9
|
+
*/
|
|
10
|
+
index: string
|
|
11
|
+
/**
|
|
12
|
+
* 索引对应的内容
|
|
13
|
+
*/
|
|
14
|
+
title: string
|
|
15
|
+
/**
|
|
16
|
+
* 索引对应的列表数据
|
|
17
|
+
*/
|
|
18
|
+
data?: any[]
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface IIndexItem extends IndexType {}
|
|
22
|
+
|
|
23
|
+
export interface IIndexBarEmits {
|
|
24
|
+
/**
|
|
25
|
+
* 点击索引时触发的事件
|
|
26
|
+
*/
|
|
27
|
+
(e: 'click', index: string, event: Event): void
|
|
28
|
+
/**
|
|
29
|
+
* 滚动到指定索引时触发的事件
|
|
30
|
+
*/
|
|
31
|
+
(e: 'scroll', index: string): void
|
|
32
|
+
/**
|
|
33
|
+
* 改变索引值
|
|
34
|
+
*/
|
|
35
|
+
(e: 'update:modelValue', index: string): void
|
|
36
|
+
}
|