papayaui 0.2.18 → 0.2.20
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/collapse/collapse.scss +2 -0
- package/components/collapse/collapse.vue +32 -48
- package/components/collapse/demo.vue +5 -0
- package/components/collapse/props.ts +8 -2
- package/components/collapse-item/collapse-item.scss +1 -1
- package/components/collapse-item/collapse-item.vue +61 -55
- package/components/collapse-item/props.ts +10 -1
- package/components/picker-popup/picker-popup.vue +4 -4
- package/components/picker-popup/props.ts +1 -1
- package/demos/collapse/demo-5.vue +19 -0
- package/package.json +1 -1
- package/.DS_Store +0 -0
|
@@ -5,42 +5,45 @@
|
|
|
5
5
|
</template>
|
|
6
6
|
|
|
7
7
|
<script setup lang="ts">
|
|
8
|
-
import {
|
|
8
|
+
import { computed, ref, watch } from 'vue'
|
|
9
9
|
import useNamespace from '../../core/useNamespace'
|
|
10
|
-
import type { CollapseItemInstance } from '../collapse-item/
|
|
11
|
-
import type { CollapseItemValue } from '../collapse-item/props'
|
|
10
|
+
import type { CollapseItemInstance, CollapseItemValue } from '../collapse-item/props'
|
|
12
11
|
import { collapseEmits, collapseProps } from './props'
|
|
13
12
|
|
|
14
|
-
export interface CollapseProvideData {
|
|
15
|
-
modelValue: Ref<CollapseItemValue[]>
|
|
16
|
-
setChildren: (node: CollapseItemInstance) => void
|
|
17
|
-
onChildExpand: (name: CollapseItemValue, expanded: boolean) => void
|
|
18
|
-
}
|
|
19
|
-
|
|
20
13
|
const ns = useNamespace('collapse')
|
|
21
14
|
|
|
22
15
|
const props = defineProps(collapseProps)
|
|
23
16
|
const emit = defineEmits(collapseEmits)
|
|
24
17
|
|
|
25
18
|
const children = ref<CollapseItemInstance[]>([])
|
|
26
|
-
const
|
|
19
|
+
const expandedValue = ref<CollapseItemValue | CollapseItemValue[]>('')
|
|
20
|
+
|
|
21
|
+
const _modelValue = computed({
|
|
22
|
+
get() {
|
|
23
|
+
return props.modelValue ?? expandedValue.value
|
|
24
|
+
},
|
|
25
|
+
set(val) {
|
|
26
|
+
expandedValue.value = val
|
|
27
|
+
emit('update:modelValue', val)
|
|
28
|
+
},
|
|
29
|
+
})
|
|
27
30
|
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
const updateExpanded = () => {
|
|
32
|
+
children.value.forEach((child) => {
|
|
33
|
+
child.updateExpanded()
|
|
34
|
+
})
|
|
31
35
|
}
|
|
32
36
|
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
?
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
const onChange = (name: CollapseItemValue, expanded: boolean) => {
|
|
38
|
+
const newModelValue = props.accordion
|
|
39
|
+
? expanded
|
|
40
|
+
? name
|
|
41
|
+
: ''
|
|
42
|
+
: children.value.flatMap((child) => {
|
|
43
|
+
const nodeExpanded = child.name === name ? expanded : child.expanded
|
|
44
|
+
return nodeExpanded ? child.name : []
|
|
40
45
|
})
|
|
41
|
-
|
|
42
|
-
expandedValues.value = Array.isArray(newModelValue) ? newModelValue : [newModelValue]
|
|
43
|
-
emit('update:modelValue', newModelValue)
|
|
46
|
+
_modelValue.value = newModelValue
|
|
44
47
|
emit('change', newModelValue)
|
|
45
48
|
|
|
46
49
|
if (expanded) {
|
|
@@ -50,39 +53,20 @@ const onChildExpand = (name: CollapseItemValue, expanded: boolean) => {
|
|
|
50
53
|
}
|
|
51
54
|
}
|
|
52
55
|
|
|
53
|
-
/**
|
|
54
|
-
* 切换所有面板展开状态,传 true 为全部展开,false 为全部收起,不传参为全部切换
|
|
55
|
-
*/
|
|
56
|
-
const toggleAll = (options: boolean | { expanded: boolean; skipDisabled: boolean }) => {
|
|
57
|
-
children.value.forEach((node) => {
|
|
58
|
-
if (typeof options === 'boolean') {
|
|
59
|
-
node?.toggle(options)
|
|
60
|
-
} else {
|
|
61
|
-
// 跳过禁用的复选框
|
|
62
|
-
if (options.skipDisabled && node.disabled) return
|
|
63
|
-
node?.toggle(options.expanded)
|
|
64
|
-
}
|
|
65
|
-
})
|
|
66
|
-
}
|
|
67
|
-
|
|
68
56
|
watch(
|
|
69
|
-
|
|
70
|
-
(
|
|
71
|
-
|
|
57
|
+
_modelValue,
|
|
58
|
+
() => {
|
|
59
|
+
updateExpanded()
|
|
72
60
|
},
|
|
73
61
|
{
|
|
74
62
|
immediate: true,
|
|
75
63
|
},
|
|
76
64
|
)
|
|
77
65
|
|
|
78
|
-
provide<CollapseProvideData>(`${ns.b()}-provide`, {
|
|
79
|
-
modelValue: expandedValues,
|
|
80
|
-
setChildren,
|
|
81
|
-
onChildExpand,
|
|
82
|
-
})
|
|
83
|
-
|
|
84
66
|
defineExpose({
|
|
85
|
-
|
|
67
|
+
children,
|
|
68
|
+
modelValue: _modelValue,
|
|
69
|
+
onChange,
|
|
86
70
|
})
|
|
87
71
|
</script>
|
|
88
72
|
|
|
@@ -14,6 +14,10 @@
|
|
|
14
14
|
<DocDemoBlock title="自定义标题内容">
|
|
15
15
|
<Demo4 />
|
|
16
16
|
</DocDemoBlock>
|
|
17
|
+
|
|
18
|
+
<DocDemoBlock title="嵌套使用">
|
|
19
|
+
<Demo5 />
|
|
20
|
+
</DocDemoBlock>
|
|
17
21
|
<pa-safe-bottom />
|
|
18
22
|
</template>
|
|
19
23
|
|
|
@@ -23,6 +27,7 @@ import Demo1 from '../../demos/collapse/demo-1.vue'
|
|
|
23
27
|
import Demo2 from '../../demos/collapse/demo-2.vue'
|
|
24
28
|
import Demo3 from '../../demos/collapse/demo-3.vue'
|
|
25
29
|
import Demo4 from '../../demos/collapse/demo-4.vue'
|
|
30
|
+
import Demo5 from '../../demos/collapse/demo-5.vue'
|
|
26
31
|
</script>
|
|
27
32
|
|
|
28
33
|
<style lang="scss" scoped></style>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { ExtractPropTypes, PropType } from 'vue'
|
|
1
|
+
import type { ExtractPropTypes, PropType, Ref } from 'vue'
|
|
2
2
|
import { isUndefined } from '../../utils'
|
|
3
|
-
import type { CollapseItemValue } from '../collapse-item/props'
|
|
3
|
+
import type { CollapseItemInstance, CollapseItemValue } from '../collapse-item/props'
|
|
4
4
|
|
|
5
5
|
export const collapseProps = {
|
|
6
6
|
/**
|
|
@@ -29,3 +29,9 @@ export const collapseEmits = {
|
|
|
29
29
|
|
|
30
30
|
export type CollapseProps = ExtractPropTypes<typeof collapseProps>
|
|
31
31
|
export type CollapseEmits = typeof collapseEmits
|
|
32
|
+
|
|
33
|
+
export type CollapseExpose = {
|
|
34
|
+
children: Ref<CollapseItemInstance[]>
|
|
35
|
+
modelValue: Ref<CollapseItemValue | CollapseItemValue[] | undefined>
|
|
36
|
+
onChange: (name: CollapseItemValue, expanded: boolean) => void
|
|
37
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<view
|
|
3
3
|
:class="[
|
|
4
4
|
ns.b(),
|
|
5
|
-
ns.is('border',
|
|
5
|
+
ns.is('border', index !== 0 && props.border),
|
|
6
6
|
ns.is('expanded', expanded),
|
|
7
7
|
ns.is('disabled', disabled),
|
|
8
8
|
ns.is('readonly', readonly),
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
:title="title"
|
|
15
15
|
:icon="icon"
|
|
16
16
|
:value="value"
|
|
17
|
-
:is-link="isLink"
|
|
18
|
-
:border="
|
|
17
|
+
:is-link="isLink && !disabled"
|
|
18
|
+
:border="border"
|
|
19
19
|
@click.stop="onClick"
|
|
20
20
|
>
|
|
21
21
|
<template #title>
|
|
@@ -36,94 +36,100 @@
|
|
|
36
36
|
</template>
|
|
37
37
|
|
|
38
38
|
<script setup lang="ts">
|
|
39
|
-
import { computed,
|
|
40
|
-
import
|
|
41
|
-
import useNamespace, { defaultNamespace } from '../../core/useNamespace'
|
|
39
|
+
import { computed, getCurrentInstance, onMounted, ref, type CSSProperties } from 'vue'
|
|
40
|
+
import useNamespace from '../../core/useNamespace'
|
|
42
41
|
import { useRect } from '../../hooks'
|
|
43
|
-
import {
|
|
42
|
+
import { getParentInstance } from '../../utils/component'
|
|
44
43
|
import Cell from '../cell/cell.vue'
|
|
45
|
-
import type {
|
|
46
|
-
import type
|
|
47
|
-
import { collapseItemProps } from './props'
|
|
48
|
-
|
|
49
|
-
export interface CollapseItemInstance {
|
|
50
|
-
index: Ref<number>
|
|
51
|
-
/** 唯一标识符 */
|
|
52
|
-
name?: Ref<CollapseItemProps['name']>
|
|
53
|
-
/** 打开状态 */
|
|
54
|
-
expanded: Ref<boolean>
|
|
55
|
-
/** 禁用状态 */
|
|
56
|
-
disabled: Ref<boolean>
|
|
57
|
-
/** 切换打开状态 */
|
|
58
|
-
toggle: (show?: boolean) => void
|
|
59
|
-
}
|
|
44
|
+
import type { CollapseExpose, CollapseProps } from '../collapse'
|
|
45
|
+
import { collapseItemProps, type CollapseItemValue } from './props'
|
|
60
46
|
|
|
61
47
|
const ns = useNamespace('collapse-item')
|
|
62
48
|
|
|
63
|
-
const instance = getCurrentInstance()
|
|
64
|
-
|
|
65
49
|
const props = defineProps(collapseItemProps)
|
|
66
50
|
|
|
67
|
-
const
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
const collapseProvide = inject<CollapseProvideData>(`${defaultNamespace}-collapse-provide`, {
|
|
71
|
-
modelValue: ref([]),
|
|
72
|
-
setChildren: noop,
|
|
73
|
-
onChildExpand: noop,
|
|
74
|
-
})
|
|
51
|
+
const instance = getCurrentInstance()
|
|
52
|
+
const parent = getParentInstance<CollapseProps, CollapseExpose>(instance, 'collapse')
|
|
75
53
|
|
|
76
|
-
const
|
|
77
|
-
const
|
|
54
|
+
const index = ref<number | undefined>()
|
|
55
|
+
const name = computed(() => props.name ?? index.value ?? 0)
|
|
56
|
+
const expanded = ref(false)
|
|
78
57
|
const wrapperAnimation = ref<CSSProperties>()
|
|
58
|
+
let animating = false
|
|
79
59
|
|
|
80
60
|
const getRect = () => {
|
|
81
61
|
if (!instance) return Promise.resolve(null)
|
|
82
62
|
return useRect(instance, `.${ns.e('content')}`)
|
|
83
63
|
}
|
|
84
64
|
|
|
85
|
-
const
|
|
65
|
+
const updateExpanded = () => {
|
|
66
|
+
if (!parent || animating) return
|
|
67
|
+
|
|
68
|
+
const parentVal = parent.exposed.modelValue.value
|
|
69
|
+
const newExpanded = parent.props.accordion
|
|
70
|
+
? parentVal === name.value
|
|
71
|
+
: (parentVal as CollapseItemValue[]).includes(name.value)
|
|
72
|
+
if (newExpanded !== expanded.value) {
|
|
73
|
+
setContentAnimate(newExpanded)
|
|
74
|
+
}
|
|
75
|
+
expanded.value = newExpanded
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const setContentAnimate = async (show: boolean, duration = 300) => {
|
|
86
79
|
const rect = await getRect()
|
|
87
80
|
if (!rect) return
|
|
88
|
-
const height = show ? rect.height : 0
|
|
89
81
|
|
|
82
|
+
animating = true
|
|
90
83
|
const animation = uni.createAnimation({
|
|
84
|
+
duration: 0,
|
|
91
85
|
timingFunction: 'ease-in-out',
|
|
92
86
|
})
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
87
|
+
if (show) {
|
|
88
|
+
animation.height(rect.height).step({
|
|
89
|
+
duration,
|
|
90
|
+
})
|
|
91
|
+
animation.height('auto').step()
|
|
92
|
+
} else {
|
|
93
|
+
animation.height(rect.height).step()
|
|
94
|
+
// TODO: 这里第二步动画需要延迟执行,否则执行后无效果
|
|
95
|
+
setTimeout(() => {
|
|
96
|
+
animation.height(0).step({
|
|
97
|
+
duration,
|
|
98
|
+
})
|
|
99
|
+
wrapperAnimation.value = animation.export()
|
|
100
|
+
}, 16)
|
|
101
|
+
}
|
|
96
102
|
wrapperAnimation.value = animation.export()
|
|
103
|
+
setTimeout(() => {
|
|
104
|
+
animating = false
|
|
105
|
+
}, duration)
|
|
97
106
|
}
|
|
98
107
|
|
|
99
108
|
const onClick = () => {
|
|
100
109
|
if (props.disabled || props.readonly) return
|
|
101
|
-
|
|
102
|
-
toggle()
|
|
110
|
+
parent?.exposed.onChange(name.value, !expanded.value)
|
|
103
111
|
}
|
|
104
112
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
113
|
+
const init = () => {
|
|
114
|
+
if (parent && parent.exposed) {
|
|
115
|
+
// 操作父组件的children对象,按照添加顺序记录子组件的index
|
|
116
|
+
index.value = parent.exposed.children.value.length
|
|
117
|
+
parent.exposed.children.value.push({
|
|
110
118
|
name,
|
|
111
119
|
expanded,
|
|
112
|
-
|
|
113
|
-
toggle,
|
|
120
|
+
updateExpanded,
|
|
114
121
|
})
|
|
115
|
-
toggle(expanded.value)
|
|
116
122
|
}
|
|
117
|
-
}
|
|
123
|
+
}
|
|
118
124
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
125
|
+
onMounted(() => {
|
|
126
|
+
init()
|
|
127
|
+
updateExpanded()
|
|
123
128
|
})
|
|
124
129
|
|
|
125
130
|
defineExpose({
|
|
126
|
-
|
|
131
|
+
updateExpanded,
|
|
132
|
+
setContentAnimate,
|
|
127
133
|
})
|
|
128
134
|
</script>
|
|
129
135
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ExtractPropTypes, PropType } from 'vue'
|
|
1
|
+
import type { ExtractPropTypes, PropType, Ref } from 'vue'
|
|
2
2
|
|
|
3
3
|
export const collapseItemProps = {
|
|
4
4
|
/**
|
|
@@ -50,3 +50,12 @@ export const collapseItemProps = {
|
|
|
50
50
|
export type CollapseItemValue = string | number
|
|
51
51
|
|
|
52
52
|
export type CollapseItemProps = ExtractPropTypes<typeof collapseItemProps>
|
|
53
|
+
|
|
54
|
+
export interface CollapseItemInstance {
|
|
55
|
+
/** 唯一标识符 */
|
|
56
|
+
name: Ref<NonNullable<CollapseItemProps['name']>>
|
|
57
|
+
/** 打开状态 */
|
|
58
|
+
expanded: Ref<boolean>
|
|
59
|
+
/** 切换打开状态 */
|
|
60
|
+
updateExpanded: () => void
|
|
61
|
+
}
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
:use-slot="!!$slots.default"
|
|
38
38
|
:custom-class="itemClass"
|
|
39
39
|
:custom-style="itemStyle"
|
|
40
|
-
@click="onSelect(item[valueKey])"
|
|
40
|
+
@click="onSelect(item[valueKey], item)"
|
|
41
41
|
>
|
|
42
42
|
<slot v-if="$slots.default" :item="item" :isCreate="!!item.__isCreate" />
|
|
43
43
|
</ListItem>
|
|
@@ -221,13 +221,13 @@ const onCreate = async () => {
|
|
|
221
221
|
}
|
|
222
222
|
newOption.__isCreate = true
|
|
223
223
|
createOptions.value.unshift(newOption)
|
|
224
|
-
onSelect(searchText.value)
|
|
224
|
+
onSelect(searchText.value, newOption)
|
|
225
225
|
emit('create', searchText.value)
|
|
226
226
|
onClearSearch()
|
|
227
227
|
}
|
|
228
228
|
|
|
229
|
-
const onSelect = async (value: OptionValue) => {
|
|
230
|
-
emit('select', value)
|
|
229
|
+
const onSelect = async (value: OptionValue, item: Option) => {
|
|
230
|
+
emit('select', value, item)
|
|
231
231
|
if (_onSelect(value) && !showView.value.confirm) {
|
|
232
232
|
onOk()
|
|
233
233
|
}
|
|
@@ -125,7 +125,7 @@ export const pickerPopupEmits = {
|
|
|
125
125
|
...bottomPopupEmits,
|
|
126
126
|
'update:modelValue': (value: OptionValue | OptionValue[]) =>
|
|
127
127
|
isString(value) || isNumber(value) || isArray(value),
|
|
128
|
-
select: (
|
|
128
|
+
select: (value: OptionValue, _item: Option) => !isUndefined(value),
|
|
129
129
|
change: (item: Option | Option[]) => !isUndefined(item),
|
|
130
130
|
/**
|
|
131
131
|
* 新增选项
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<pa-collapse v-model="collapseValue">
|
|
3
|
+
<pa-collapse-item title="测试" :border="false">
|
|
4
|
+
<pa-collapse v-model="collapseChildValue" :border="false">
|
|
5
|
+
<pa-collapse-item title="嵌套测试" :border="false">
|
|
6
|
+
嵌套内容,嵌套内容,嵌套内容
|
|
7
|
+
</pa-collapse-item>
|
|
8
|
+
</pa-collapse>
|
|
9
|
+
<view>测试内容,测试内容,测试内容</view>
|
|
10
|
+
</pa-collapse-item>
|
|
11
|
+
</pa-collapse>
|
|
12
|
+
</template>
|
|
13
|
+
|
|
14
|
+
<script setup lang="ts">
|
|
15
|
+
import { ref } from 'vue'
|
|
16
|
+
|
|
17
|
+
const collapseValue = ref<number[]>([])
|
|
18
|
+
const collapseChildValue = ref<number[]>([])
|
|
19
|
+
</script>
|
package/package.json
CHANGED
package/.DS_Store
DELETED
|
Binary file
|