index.vue
4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<template>
<view class="button-bar">
<view v-if="showMoreButton" class="more-link" @click="toggleMore">更多</view>
<view class="button-grid" :style="{ gridTemplateColumns: gridColumns }">
<view v-for="(btn, idx) in visibleButtons" :key="idx" class="action-button" :class="buttonClass(btn)" :style="buttonStyle(btn)" @click="emitClick(btn)">{{ btn.text }}</view>
</view>
<view v-if="moreVisible" class="popover-mask" @click="closeMore"></view>
<view v-if="moreVisible" class="more-popover" :style="popoverStyle()">
<view v-for="(btn, idx) in moreButtons" :key="idx" class="menu-item" :class="menuClass(btn)" :style="menuStyle(btn)" @click="emitMoreClick(btn)">{{ btn.text }}</view>
</view>
</view>
</template>
<script>
export default {
name: 'DetailButtons',
props: {
buttons: { type: Array, default: () => [] }
},
data() {
return { moreVisible: false }
},
computed: {
effectiveButtons() {
const list = this.buttons || []
return list.filter(it => it && it.visible !== false)
},
showMoreButton() {
return (this.effectiveButtons || []).length >= 4
},
visibleButtons() {
const list = this.effectiveButtons || []
if (list.length <= 3) return list
return list.slice(0, 2)
},
moreButtons() {
const list = this.effectiveButtons || []
return list.length >= 4 ? list.slice(2) : []
},
gridColumns() {
const len = (this.effectiveButtons || []).length
if (this.showMoreButton) return '1fr 1fr'
if (len <= 1) return '1fr'
if (len === 2) return '1fr 1fr'
return '1fr 1fr 1fr'
}
},
methods: {
toggleMore() { this.moreVisible = !this.moreVisible },
closeMore() { this.moreVisible = false },
emitClick(btn) {
if (!btn || btn.disabled) return
this.$emit('click', btn)
},
emitMoreClick(btn) { this.emitClick(btn); this.closeMore() },
buttonClass(btn) {
const v = (btn && btn.variant) || 'outline'
let cls = ''
if (v === 'primary') cls = 'action-button--primary'
else if (v === 'danger') cls = 'action-button--danger'
else cls = 'action-button--outline'
if (btn && btn.disabled) cls += ' is-disabled'
return cls
},
buttonStyle(btn) { return (btn && btn.style) ? btn.style : {} },
menuClass(btn) {
const v = (btn && btn.variant) || 'outline'
if (v === 'danger') return 'menu-item--danger'
return 'menu-item--primary'
},
menuStyle(btn) { return (btn && btn.style) ? btn.style : {} },
popoverStyle() { return { left: '24rpx' } }
}
}
</script>
<style lang="scss" scoped>
.button-bar {
position: fixed;
left: 0;
right: 0;
bottom: 0;
background: #fff;
padding: 16rpx 24rpx;
box-shadow: 0 -8rpx 24rpx rgba(0, 0, 0, 0.03);
padding-bottom: calc(16rpx + env(safe-area-inset-bottom));
display: flex;
align-items: center;
gap: 24rpx;
position: fixed;
z-index: 10;
}
.more-link {
color: $theme-primary;
font-size: 28rpx;
line-height: 1;
padding: 20rpx 0;
}
.button-grid {
flex: 1;
display: grid;
gap: 16rpx;
}
.action-button {
text-align: center;
padding: 20rpx 0;
border-radius: 12rpx;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.action-button--outline { border: 2rpx solid $theme-primary; color: $theme-primary; background: #fff; }
.action-button--primary { border: 2rpx solid $theme-primary; background: $theme-primary; color: #fff; }
.action-button--danger { border: 2rpx solid #ff4d4f; background: #ff4d4f; color: #fff; }
.is-disabled { opacity: 0.5; }
.popover-mask {
position: fixed;
left: 0;
right: 0;
top: 0;
bottom: 0;
background: transparent;
z-index: 9;
}
.more-popover {
position: absolute;
bottom: calc(100% + 12rpx);
background: #fff;
border-radius: 12rpx;
box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.06);
padding: 8rpx 0;
min-width: 360rpx;
z-index: 11;
}
.menu-item {
padding: 16rpx 20rpx;
font-size: 28rpx;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.menu-item--primary { color: $theme-primary; }
.menu-item--danger { color: #ff4d4f; }
</style>