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
|
@@ -1,161 +1,161 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<view
|
|
3
|
-
:class="cellClass"
|
|
4
|
-
:hover-class="hoverClass"
|
|
5
|
-
:style="customStyle"
|
|
6
|
-
:hover-stay-time="250"
|
|
7
|
-
@tap="clickHandler"
|
|
8
|
-
>
|
|
9
|
-
<view class="hy-cell-item__left">
|
|
10
|
-
<view v-if="icon || $slots.icon" class="hy-cell-item__left--icon">
|
|
11
|
-
<!-- @slot 图标插槽 -->
|
|
12
|
-
<slot v-if="$slots.icon" name="icon" :icon="item?.icon"></slot>
|
|
13
|
-
<hy-icon
|
|
14
|
-
v-else
|
|
15
|
-
:size="iconSize"
|
|
16
|
-
:name="icon?.name"
|
|
17
|
-
:color="!!(disabled || cellConfig?.disabled.value) ? '#FFFFFF3F' : icon?.color"
|
|
18
|
-
:bold="icon?.bold"
|
|
19
|
-
:customPrefix="icon?.customPrefix"
|
|
20
|
-
:imgMode="icon?.imgMode"
|
|
21
|
-
:width="icon?.width"
|
|
22
|
-
:height="icon?.height"
|
|
23
|
-
:top="icon?.top"
|
|
24
|
-
:stop="icon?.stop"
|
|
25
|
-
:round="icon?.round"
|
|
26
|
-
:customStyle="icon?.customStyle"
|
|
27
|
-
:customClass="icon?.customClass"
|
|
28
|
-
></hy-icon>
|
|
29
|
-
</view>
|
|
30
|
-
<view class="hy-cell-item__left--title">
|
|
31
|
-
<!-- @slot 列表标题插槽 -->
|
|
32
|
-
<slot v-if="$slots.title" name="title" :title="title"></slot>
|
|
33
|
-
<text v-else class="hy-cell-item__left--title__text">
|
|
34
|
-
{{ title }}
|
|
35
|
-
</text>
|
|
36
|
-
<!-- @slot 列表小标题插槽 -->
|
|
37
|
-
<slot v-if="$slots.sub" name="sub" :sub="sub"></slot>
|
|
38
|
-
<text v-else-if="sub" class="hy-cell-item__left--title__sub">
|
|
39
|
-
{{ sub }}
|
|
40
|
-
</text>
|
|
41
|
-
</view>
|
|
42
|
-
</view>
|
|
43
|
-
<view
|
|
44
|
-
class="hy-cell-item__center"
|
|
45
|
-
:style="{
|
|
46
|
-
justifyContent:
|
|
47
|
-
cellConfig?.arrange.value === 'left'
|
|
48
|
-
? 'flex-start'
|
|
49
|
-
: cellConfig?.arrange.value === 'right'
|
|
50
|
-
? 'flex-end'
|
|
51
|
-
: 'center'
|
|
52
|
-
}"
|
|
53
|
-
>
|
|
54
|
-
<!-- @slot 值内容插槽 -->
|
|
55
|
-
<slot v-if="$slots.value" name="value" :record="item"></slot>
|
|
56
|
-
<text v-else-if="value" class="hy-cell-item__center--value">
|
|
57
|
-
{{ value }}
|
|
58
|
-
</text>
|
|
59
|
-
</view>
|
|
60
|
-
<view
|
|
61
|
-
:class="[
|
|
62
|
-
'hy-cell-item__right',
|
|
63
|
-
`hy-cell-item__right--${cellConfig?.arrowDirection.value}`
|
|
64
|
-
]"
|
|
65
|
-
v-if="cellConfig?.isRightIcon.value"
|
|
66
|
-
>
|
|
67
|
-
<!-- @slot 右边按钮插槽 -->
|
|
68
|
-
<slot v-if="$slots['right-icon']" name="right-icon" :icon="rightIcon"></slot>
|
|
69
|
-
<hy-icon
|
|
70
|
-
v-else
|
|
71
|
-
:name="rightIcon?.name || IconConfig.RIGHT"
|
|
72
|
-
:color="!!(disabled || cellConfig?.disabled.value) ? '#FFFFFF3F' : rightIcon?.color"
|
|
73
|
-
:bold="rightIcon?.bold"
|
|
74
|
-
:customPrefix="rightIcon?.customPrefix"
|
|
75
|
-
:imgMode="rightIcon?.imgMode"
|
|
76
|
-
:width="rightIcon?.width"
|
|
77
|
-
:height="rightIcon?.height"
|
|
78
|
-
:stop="rightIcon?.stop"
|
|
79
|
-
:round="rightIcon?.round"
|
|
80
|
-
:customStyle="rightIcon?.customStyle"
|
|
81
|
-
:customClass="rightIcon?.customClass"
|
|
82
|
-
></hy-icon>
|
|
83
|
-
</view>
|
|
84
|
-
</view>
|
|
85
|
-
</template>
|
|
86
|
-
|
|
87
|
-
<script lang="ts">
|
|
88
|
-
export default {
|
|
89
|
-
name: 'hy-cell-item',
|
|
90
|
-
options: {
|
|
91
|
-
virtualHost: true,
|
|
92
|
-
styleIsolation: 'shared'
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
</script>
|
|
96
|
-
|
|
97
|
-
<script setup lang="ts">
|
|
98
|
-
import { computed, inject } from 'vue'
|
|
99
|
-
import cellItemProps from './props'
|
|
100
|
-
import type { ICellContext } from './typing'
|
|
101
|
-
import { IconConfig } from '../../libs'
|
|
102
|
-
import type { ICellEmits } from '../hy-cell/typing'
|
|
103
|
-
// 组件
|
|
104
|
-
import HyIcon from '../hy-icon/hy-icon.vue'
|
|
105
|
-
|
|
106
|
-
const props = defineProps(cellItemProps)
|
|
107
|
-
const emit = defineEmits<ICellEmits>()
|
|
108
|
-
const cellConfig = inject<ICellContext>('hy-cell')
|
|
109
|
-
|
|
110
|
-
// 单元格类名
|
|
111
|
-
const cellClass = computed(() => {
|
|
112
|
-
return [
|
|
113
|
-
'hy-cell-item',
|
|
114
|
-
`hy-cell-item--${cellConfig?.size.value}`,
|
|
115
|
-
cellConfig?.border.value && 'hy-border__bottom',
|
|
116
|
-
(props.disabled || cellConfig?.disabled.value) && 'hy-cell-item__disabled',
|
|
117
|
-
props.customClass
|
|
118
|
-
]
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
// 计算什么时候出现点击状态
|
|
122
|
-
const hoverClass = computed(() => {
|
|
123
|
-
if (!(props.disabled || cellConfig?.disabled.value) && cellConfig?.clickable.value) {
|
|
124
|
-
return 'hy-cell-item__clickable'
|
|
125
|
-
} else {
|
|
126
|
-
return ''
|
|
127
|
-
}
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
// 图标大小
|
|
131
|
-
const iconSize = computed(() => {
|
|
132
|
-
switch (cellConfig?.size.value) {
|
|
133
|
-
case 'large':
|
|
134
|
-
return 25
|
|
135
|
-
case 'medium':
|
|
136
|
-
return 20
|
|
137
|
-
case 'small':
|
|
138
|
-
return 15
|
|
139
|
-
}
|
|
140
|
-
})
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* 点击cell
|
|
144
|
-
* */
|
|
145
|
-
const clickHandler = (e: Event) => {
|
|
146
|
-
if (cellConfig?.disabled.value || props.disabled) return
|
|
147
|
-
if (props.stop) e.stopPropagation()
|
|
148
|
-
|
|
149
|
-
emit('click', props.name)
|
|
150
|
-
cellConfig?.onClick(props.name)
|
|
151
|
-
if (props.url) {
|
|
152
|
-
|
|
153
|
-
url: props.url
|
|
154
|
-
})
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
</script>
|
|
158
|
-
|
|
159
|
-
<style lang="scss" scoped>
|
|
160
|
-
@import './index.scss';
|
|
161
|
-
</style>
|
|
1
|
+
<template>
|
|
2
|
+
<view
|
|
3
|
+
:class="cellClass"
|
|
4
|
+
:hover-class="hoverClass"
|
|
5
|
+
:style="customStyle"
|
|
6
|
+
:hover-stay-time="250"
|
|
7
|
+
@tap="clickHandler"
|
|
8
|
+
>
|
|
9
|
+
<view class="hy-cell-item__left">
|
|
10
|
+
<view v-if="icon || $slots.icon" class="hy-cell-item__left--icon">
|
|
11
|
+
<!-- @slot 图标插槽 -->
|
|
12
|
+
<slot v-if="$slots.icon" name="icon" :icon="item?.icon"></slot>
|
|
13
|
+
<hy-icon
|
|
14
|
+
v-else
|
|
15
|
+
:size="iconSize"
|
|
16
|
+
:name="icon?.name"
|
|
17
|
+
:color="!!(disabled || cellConfig?.disabled.value) ? '#FFFFFF3F' : icon?.color"
|
|
18
|
+
:bold="icon?.bold"
|
|
19
|
+
:customPrefix="icon?.customPrefix"
|
|
20
|
+
:imgMode="icon?.imgMode"
|
|
21
|
+
:width="icon?.width"
|
|
22
|
+
:height="icon?.height"
|
|
23
|
+
:top="icon?.top"
|
|
24
|
+
:stop="icon?.stop"
|
|
25
|
+
:round="icon?.round"
|
|
26
|
+
:customStyle="icon?.customStyle"
|
|
27
|
+
:customClass="icon?.customClass"
|
|
28
|
+
></hy-icon>
|
|
29
|
+
</view>
|
|
30
|
+
<view class="hy-cell-item__left--title">
|
|
31
|
+
<!-- @slot 列表标题插槽 -->
|
|
32
|
+
<slot v-if="$slots.title" name="title" :title="title"></slot>
|
|
33
|
+
<text v-else class="hy-cell-item__left--title__text">
|
|
34
|
+
{{ title }}
|
|
35
|
+
</text>
|
|
36
|
+
<!-- @slot 列表小标题插槽 -->
|
|
37
|
+
<slot v-if="$slots.sub" name="sub" :sub="sub"></slot>
|
|
38
|
+
<text v-else-if="sub" class="hy-cell-item__left--title__sub">
|
|
39
|
+
{{ sub }}
|
|
40
|
+
</text>
|
|
41
|
+
</view>
|
|
42
|
+
</view>
|
|
43
|
+
<view
|
|
44
|
+
class="hy-cell-item__center"
|
|
45
|
+
:style="{
|
|
46
|
+
justifyContent:
|
|
47
|
+
cellConfig?.arrange.value === 'left'
|
|
48
|
+
? 'flex-start'
|
|
49
|
+
: cellConfig?.arrange.value === 'right'
|
|
50
|
+
? 'flex-end'
|
|
51
|
+
: 'center'
|
|
52
|
+
}"
|
|
53
|
+
>
|
|
54
|
+
<!-- @slot 值内容插槽 -->
|
|
55
|
+
<slot v-if="$slots.value" name="value" :record="item"></slot>
|
|
56
|
+
<text v-else-if="value" class="hy-cell-item__center--value">
|
|
57
|
+
{{ value }}
|
|
58
|
+
</text>
|
|
59
|
+
</view>
|
|
60
|
+
<view
|
|
61
|
+
:class="[
|
|
62
|
+
'hy-cell-item__right',
|
|
63
|
+
`hy-cell-item__right--${cellConfig?.arrowDirection.value}`
|
|
64
|
+
]"
|
|
65
|
+
v-if="cellConfig?.isRightIcon.value"
|
|
66
|
+
>
|
|
67
|
+
<!-- @slot 右边按钮插槽 -->
|
|
68
|
+
<slot v-if="$slots['right-icon']" name="right-icon" :icon="rightIcon"></slot>
|
|
69
|
+
<hy-icon
|
|
70
|
+
v-else
|
|
71
|
+
:name="rightIcon?.name || IconConfig.RIGHT"
|
|
72
|
+
:color="!!(disabled || cellConfig?.disabled.value) ? '#FFFFFF3F' : rightIcon?.color"
|
|
73
|
+
:bold="rightIcon?.bold"
|
|
74
|
+
:customPrefix="rightIcon?.customPrefix"
|
|
75
|
+
:imgMode="rightIcon?.imgMode"
|
|
76
|
+
:width="rightIcon?.width"
|
|
77
|
+
:height="rightIcon?.height"
|
|
78
|
+
:stop="rightIcon?.stop"
|
|
79
|
+
:round="rightIcon?.round"
|
|
80
|
+
:customStyle="rightIcon?.customStyle"
|
|
81
|
+
:customClass="rightIcon?.customClass"
|
|
82
|
+
></hy-icon>
|
|
83
|
+
</view>
|
|
84
|
+
</view>
|
|
85
|
+
</template>
|
|
86
|
+
|
|
87
|
+
<script lang="ts">
|
|
88
|
+
export default {
|
|
89
|
+
name: 'hy-cell-item',
|
|
90
|
+
options: {
|
|
91
|
+
virtualHost: true,
|
|
92
|
+
styleIsolation: 'shared'
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
</script>
|
|
96
|
+
|
|
97
|
+
<script setup lang="ts">
|
|
98
|
+
import { computed, inject } from 'vue'
|
|
99
|
+
import cellItemProps from './props'
|
|
100
|
+
import type { ICellContext } from './typing'
|
|
101
|
+
import { IconConfig } from '../../libs'
|
|
102
|
+
import type { ICellEmits } from '../hy-cell/typing'
|
|
103
|
+
// 组件
|
|
104
|
+
import HyIcon from '../hy-icon/hy-icon.vue'
|
|
105
|
+
|
|
106
|
+
const props = defineProps(cellItemProps)
|
|
107
|
+
const emit = defineEmits<ICellEmits>()
|
|
108
|
+
const cellConfig = inject<ICellContext>('hy-cell')
|
|
109
|
+
|
|
110
|
+
// 单元格类名
|
|
111
|
+
const cellClass = computed(() => {
|
|
112
|
+
return [
|
|
113
|
+
'hy-cell-item',
|
|
114
|
+
`hy-cell-item--${cellConfig?.size.value}`,
|
|
115
|
+
cellConfig?.border.value && 'hy-border__bottom',
|
|
116
|
+
(props.disabled || cellConfig?.disabled.value) && 'hy-cell-item__disabled',
|
|
117
|
+
props.customClass
|
|
118
|
+
]
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
// 计算什么时候出现点击状态
|
|
122
|
+
const hoverClass = computed(() => {
|
|
123
|
+
if (!(props.disabled || cellConfig?.disabled.value) && cellConfig?.clickable.value) {
|
|
124
|
+
return 'hy-cell-item__clickable'
|
|
125
|
+
} else {
|
|
126
|
+
return ''
|
|
127
|
+
}
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
// 图标大小
|
|
131
|
+
const iconSize = computed(() => {
|
|
132
|
+
switch (cellConfig?.size.value) {
|
|
133
|
+
case 'large':
|
|
134
|
+
return 25
|
|
135
|
+
case 'medium':
|
|
136
|
+
return 20
|
|
137
|
+
case 'small':
|
|
138
|
+
return 15
|
|
139
|
+
}
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* 点击cell
|
|
144
|
+
* */
|
|
145
|
+
const clickHandler = (e: Event) => {
|
|
146
|
+
if (cellConfig?.disabled.value || props.disabled) return
|
|
147
|
+
if (props.stop) e.stopPropagation()
|
|
148
|
+
|
|
149
|
+
emit('click', props.name)
|
|
150
|
+
cellConfig?.onClick(props.name)
|
|
151
|
+
if (props.url) {
|
|
152
|
+
uni.navigateTo({
|
|
153
|
+
url: props.url
|
|
154
|
+
})
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
</script>
|
|
158
|
+
|
|
159
|
+
<style lang="scss" scoped>
|
|
160
|
+
@import './index.scss';
|
|
161
|
+
</style>
|
|
@@ -1,66 +1,59 @@
|
|
|
1
|
-
import type { CSSProperties, PropType } from 'vue'
|
|
2
|
-
import type { HyIconProps } from '../hy-icon/typing'
|
|
3
|
-
|
|
4
|
-
const cellItemProps = {
|
|
5
|
-
/** 头部标题 */
|
|
6
|
-
title: String,
|
|
7
|
-
/** 标题下面小提示 */
|
|
8
|
-
sub: String,
|
|
9
|
-
/** 是否禁用cell */
|
|
10
|
-
disabled: {
|
|
11
|
-
type: Boolean,
|
|
12
|
-
default: false
|
|
13
|
-
},
|
|
14
|
-
/** 右侧的内容 */
|
|
15
|
-
value: String,
|
|
16
|
-
/** 图标,接收icon对象 */
|
|
17
|
-
icon: {
|
|
18
|
-
type: Object as PropType<HyIconProps>
|
|
19
|
-
},
|
|
20
|
-
/** 右边图标,默认是向左图标 */
|
|
21
|
-
rightIcon: {
|
|
22
|
-
type: Object as PropType<HyIconProps>
|
|
23
|
-
},
|
|
24
|
-
/**
|
|
25
|
-
* 右侧箭头的方向
|
|
26
|
-
* @values left,up,down
|
|
27
|
-
* */
|
|
28
|
-
arrowDirection: {
|
|
29
|
-
type: String,
|
|
30
|
-
default: 'right'
|
|
31
|
-
},
|
|
32
|
-
/**
|
|
33
|
-
* 点击后跳转的URL地址
|
|
34
|
-
* */
|
|
35
|
-
url: {
|
|
36
|
-
type: String,
|
|
37
|
-
default: ''
|
|
38
|
-
},
|
|
39
|
-
/**
|
|
40
|
-
*
|
|
41
|
-
* */
|
|
42
|
-
|
|
43
|
-
type:
|
|
44
|
-
default:
|
|
45
|
-
},
|
|
46
|
-
/**
|
|
47
|
-
*
|
|
48
|
-
* */
|
|
49
|
-
|
|
50
|
-
type:
|
|
51
|
-
default:
|
|
52
|
-
},
|
|
53
|
-
/**
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
/** 定义需要用到的外部样式 */
|
|
61
|
-
customStyle: Object as PropType<CSSProperties>,
|
|
62
|
-
/** 自定义外部类名 */
|
|
63
|
-
customClass: String
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export default cellItemProps
|
|
1
|
+
import type { CSSProperties, PropType } from 'vue'
|
|
2
|
+
import type { HyIconProps } from '../hy-icon/typing'
|
|
3
|
+
|
|
4
|
+
const cellItemProps = {
|
|
5
|
+
/** 头部标题 */
|
|
6
|
+
title: String,
|
|
7
|
+
/** 标题下面小提示 */
|
|
8
|
+
sub: String,
|
|
9
|
+
/** 是否禁用cell */
|
|
10
|
+
disabled: {
|
|
11
|
+
type: Boolean,
|
|
12
|
+
default: false
|
|
13
|
+
},
|
|
14
|
+
/** 右侧的内容 */
|
|
15
|
+
value: String,
|
|
16
|
+
/** 图标,接收icon对象 */
|
|
17
|
+
icon: {
|
|
18
|
+
type: Object as PropType<HyIconProps>
|
|
19
|
+
},
|
|
20
|
+
/** 右边图标,默认是向左图标 */
|
|
21
|
+
rightIcon: {
|
|
22
|
+
type: Object as PropType<HyIconProps>
|
|
23
|
+
},
|
|
24
|
+
/**
|
|
25
|
+
* 右侧箭头的方向
|
|
26
|
+
* @values left,up,down
|
|
27
|
+
* */
|
|
28
|
+
arrowDirection: {
|
|
29
|
+
type: String,
|
|
30
|
+
default: 'right'
|
|
31
|
+
},
|
|
32
|
+
/**
|
|
33
|
+
* 点击后跳转的URL地址
|
|
34
|
+
* */
|
|
35
|
+
url: {
|
|
36
|
+
type: String,
|
|
37
|
+
default: ''
|
|
38
|
+
},
|
|
39
|
+
/**
|
|
40
|
+
* 点击cell是否阻止事件传播
|
|
41
|
+
* */
|
|
42
|
+
stop: {
|
|
43
|
+
type: Boolean,
|
|
44
|
+
default: true
|
|
45
|
+
},
|
|
46
|
+
/**
|
|
47
|
+
* 标识符,用于在click事件中进行返回
|
|
48
|
+
* */
|
|
49
|
+
name: {
|
|
50
|
+
type: [String, Number],
|
|
51
|
+
default: ''
|
|
52
|
+
},
|
|
53
|
+
/** 定义需要用到的外部样式 */
|
|
54
|
+
customStyle: Object as PropType<CSSProperties>,
|
|
55
|
+
/** 自定义外部类名 */
|
|
56
|
+
customClass: String
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export default cellItemProps
|
|
@@ -5,14 +5,11 @@
|
|
|
5
5
|
@include b(config-provider) {
|
|
6
6
|
box-sizing: border-box;
|
|
7
7
|
width: 100%;
|
|
8
|
-
|
|
9
|
-
height: calc(100vh -
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
/* #endif */
|
|
14
|
-
overflow-y: auto;
|
|
15
|
-
overflow-x: hidden;
|
|
8
|
+
height: calc(100vh - var(--window-top));
|
|
9
|
+
height: calc(100vh - var(--window-top) - constant(safe-area-inset-bottom));
|
|
10
|
+
height: calc(100vh - var(--window-top) - env(safe-area-inset-bottom));
|
|
11
|
+
//overflow-y: auto;
|
|
12
|
+
//overflow-x: hidden;
|
|
16
13
|
background-color: $hy-background;
|
|
17
14
|
color: $hy-text-color;
|
|
18
15
|
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="hy-folding-panel-group">
|
|
3
|
+
<slot></slot>
|
|
4
|
+
</view>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script lang="ts">
|
|
8
|
+
export default {
|
|
9
|
+
name: "hy-folding-panel-group"
|
|
10
|
+
};
|
|
11
|
+
</script>
|
|
12
|
+
|
|
13
|
+
<script setup lang="ts">
|
|
14
|
+
import { provide, ref, watch, onMounted, nextTick, getCurrentInstance } from 'vue';
|
|
15
|
+
import type { Ref } from 'vue';
|
|
16
|
+
|
|
17
|
+
// Props定义
|
|
18
|
+
const props = defineProps({
|
|
19
|
+
/**
|
|
20
|
+
* 当前激活的面板索引,支持v-model
|
|
21
|
+
*/
|
|
22
|
+
modelValue: {
|
|
23
|
+
type: Number,
|
|
24
|
+
default: -1
|
|
25
|
+
},
|
|
26
|
+
/**
|
|
27
|
+
* 是否手风琴模式,默认true
|
|
28
|
+
*/
|
|
29
|
+
accordion: {
|
|
30
|
+
type: Boolean,
|
|
31
|
+
default: true
|
|
32
|
+
},
|
|
33
|
+
/**
|
|
34
|
+
* 是否禁用整个折叠面板组
|
|
35
|
+
*/
|
|
36
|
+
disabled: {
|
|
37
|
+
type: Boolean,
|
|
38
|
+
default: false
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// 事件定义
|
|
43
|
+
const emit = defineEmits<{
|
|
44
|
+
(e: 'update:modelValue', value: number): void;
|
|
45
|
+
(e: 'change', index: number): void;
|
|
46
|
+
(e: 'open', index: number): void;
|
|
47
|
+
(e: 'close', index: number): void;
|
|
48
|
+
}>();
|
|
49
|
+
|
|
50
|
+
// 内部激活索引
|
|
51
|
+
const activeIndex = ref(props.modelValue);
|
|
52
|
+
|
|
53
|
+
// 监听v-model变化
|
|
54
|
+
watch(() => props.modelValue, (newVal) => {
|
|
55
|
+
activeIndex.value = newVal;
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// 监听内部激活索引变化
|
|
59
|
+
watch(activeIndex, (newVal) => {
|
|
60
|
+
emit('update:modelValue', newVal);
|
|
61
|
+
emit('change', newVal);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// 提供给子组件的方法
|
|
65
|
+
const updateActiveIndex = (index: number) => {
|
|
66
|
+
if (props.disabled) return;
|
|
67
|
+
|
|
68
|
+
if (props.accordion) {
|
|
69
|
+
// 手风琴模式下,如果点击的是当前激活的索引,则关闭(设为-1)
|
|
70
|
+
const wasActive = activeIndex.value === index;
|
|
71
|
+
activeIndex.value = wasActive ? -1 : index;
|
|
72
|
+
|
|
73
|
+
// 触发相应的事件
|
|
74
|
+
if (!wasActive) {
|
|
75
|
+
emit('open', index);
|
|
76
|
+
} else {
|
|
77
|
+
emit('close', index);
|
|
78
|
+
}
|
|
79
|
+
} else {
|
|
80
|
+
// 非手风琴模式下,这里不做特殊处理,由子组件自己控制
|
|
81
|
+
activeIndex.value = index;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// 提供给子组件的配置
|
|
86
|
+
provide('hy-folding-panel-group', {
|
|
87
|
+
accordion: props.accordion,
|
|
88
|
+
disabled: props.disabled,
|
|
89
|
+
activeIndex,
|
|
90
|
+
updateActiveIndex
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// 自动为子组件设置索引
|
|
94
|
+
onMounted(() => {
|
|
95
|
+
nextTick(() => {
|
|
96
|
+
const children = getCurrentInstance()?.proxy?.$el?.querySelectorAll('.hy-folding-panel-item');
|
|
97
|
+
children?.forEach((child, index) => {
|
|
98
|
+
const vueComponent = (child as any).__vueParentComponent?.proxy;
|
|
99
|
+
if (vueComponent && vueComponent.$options.name === 'hy-folding-panel-item') {
|
|
100
|
+
vueComponent.index = index;
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// 对外暴露的方法
|
|
107
|
+
defineExpose({
|
|
108
|
+
/**
|
|
109
|
+
* 打开指定索引的面板
|
|
110
|
+
*/
|
|
111
|
+
open: (index: number) => {
|
|
112
|
+
if (props.disabled) return;
|
|
113
|
+
activeIndex.value = index;
|
|
114
|
+
emit('open', index);
|
|
115
|
+
},
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* 关闭所有面板
|
|
119
|
+
*/
|
|
120
|
+
closeAll: () => {
|
|
121
|
+
if (props.disabled) return;
|
|
122
|
+
const prevIndex = activeIndex.value;
|
|
123
|
+
activeIndex.value = -1;
|
|
124
|
+
if (prevIndex !== -1) {
|
|
125
|
+
emit('close', prevIndex);
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* 切换指定索引面板的状态
|
|
131
|
+
*/
|
|
132
|
+
toggle: (index: number) => {
|
|
133
|
+
if (props.disabled) return;
|
|
134
|
+
updateActiveIndex(index);
|
|
135
|
+
},
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* 关闭指定索引的面板
|
|
139
|
+
*/
|
|
140
|
+
close: (index: number) => {
|
|
141
|
+
if (props.disabled) return;
|
|
142
|
+
if (activeIndex.value === index) {
|
|
143
|
+
activeIndex.value = -1;
|
|
144
|
+
emit('close', index);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
</script>
|
|
149
|
+
|
|
150
|
+
<style lang="scss" scoped>
|
|
151
|
+
.hy-folding-panel-group {
|
|
152
|
+
width: 100%;
|
|
153
|
+
background-color: #ffffff;
|
|
154
|
+
border-radius: 8px;
|
|
155
|
+
overflow: hidden;
|
|
156
|
+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
.hy-folding-panel-group--disabled {
|
|
160
|
+
opacity: 0.6;
|
|
161
|
+
pointer-events: none;
|
|
162
|
+
}
|
|
163
|
+
</style>
|