|
1 | 1 | <template>
|
2 | 2 | <view :class="classes">
|
3 |
| - <nut-popup |
4 |
| - pop-class="popclass" |
5 |
| - :visible="visible" |
6 |
| - position="bottom" |
7 |
| - round |
8 |
| - @click-overlay="close" |
9 |
| - > |
10 |
| - <view class="nut-actionsheet-panel"> |
| 3 | + <nut-popup pop-class="popclass" :visible="visible" position="bottom" round @click-overlay="close"> |
| 4 | + <view class="nut-actionsheet-panel" :class="{ 'nut-actionsheet-safebottom': safeAreaInsetBottom }"> |
11 | 5 | <view v-if="title" class="nut-actionsheet-title">{{ title }}</view>
|
12 |
| - <view class="nut-actionsheet-item desc" v-if="description">{{ |
13 |
| - description |
14 |
| - }}</view> |
15 |
| - <view class="nut-actionsheet-menu" v-if="menuItems.length"> |
16 |
| - <view |
17 |
| - v-for="(item, index) of menuItems" |
18 |
| - class="nut-actionsheet-item" |
19 |
| - :class="{ 'nut-actionsheet-item-disabled': item.disable }" |
20 |
| - :style="{ color: isHighlight(item) }" |
21 |
| - :key="index" |
22 |
| - @click="chooseItem(item, index)" |
23 |
| - >{{ item[optionTag] |
24 |
| - }}<view class="subdesc">{{ item[optionSubTag] }}</view> |
| 6 | + <slot></slot> |
| 7 | + <view v-if="!slotDefault"> |
| 8 | + <view class="nut-actionsheet-item desc" v-if="description">{{ description }}</view> |
| 9 | + <view class="nut-actionsheet-menu" v-if="menuItems.length"> |
| 10 | + <view |
| 11 | + v-for="(item, index) of menuItems" |
| 12 | + class="nut-actionsheet-item" |
| 13 | + :class="{ 'nut-actionsheet-item-disabled': item.disable, 'nut-actionsheet-item-loading': item.loading }" |
| 14 | + :style="{ color: isHighlight(item) || item.color }" |
| 15 | + :key="index" |
| 16 | + @click="chooseItem(item, index)" |
| 17 | + > |
| 18 | + <nut-icon v-if="item.loading" name="loading"> </nut-icon> |
| 19 | + <view v-else> {{ item[optionTag] }}</view> |
| 20 | + <view class="subdesc">{{ item[optionSubTag] }}</view> |
| 21 | + </view> |
| 22 | + </view> |
| 23 | + <view class="nut-actionsheet-cancel" v-if="cancelTxt" @click="cancelActionSheet"> |
| 24 | + {{ cancelTxt }} |
25 | 25 | </view>
|
26 |
| - </view> |
27 |
| - <view |
28 |
| - class="nut-actionsheet-cancel" |
29 |
| - v-if="cancelTxt" |
30 |
| - @click="cancelActionSheet" |
31 |
| - > |
32 |
| - {{ cancelTxt }} |
33 | 26 | </view>
|
34 | 27 | </view>
|
35 | 28 | </nut-popup>
|
36 | 29 | </view>
|
37 | 30 | </template>
|
38 |
| -<script> |
| 31 | +<script lang="ts"> |
39 | 32 | import { createComponent } from '../../utils/create';
|
40 |
| -import { computed } from 'vue'; |
| 33 | +import { computed, useSlots } from 'vue'; |
41 | 34 | const { componentName, create } = createComponent('actionsheet');
|
42 | 35 | import { popupProps } from '../popup/index.vue';
|
43 | 36 | export default create({
|
@@ -74,43 +67,46 @@ export default create({
|
74 | 67 | menuItems: {
|
75 | 68 | type: Array,
|
76 | 69 | default: () => []
|
| 70 | + }, |
| 71 | + safeAreaInsetBottom: { |
| 72 | + type: Boolean, |
| 73 | + default: false |
77 | 74 | }
|
78 | 75 | },
|
79 |
| - emits: ['cancel', 'choose', 'update:visible'], |
| 76 | + emits: ['cancel', 'choose', 'update:visible', 'close'], |
80 | 77 |
|
81 | 78 | setup(props, { emit }) {
|
| 79 | + const slotDefault = !!useSlots().default; |
82 | 80 | const classes = computed(() => {
|
83 | 81 | const prefixCls = componentName;
|
84 | 82 | return {
|
85 | 83 | [prefixCls]: true
|
86 | 84 | };
|
87 | 85 | });
|
88 | 86 |
|
89 |
| - const isHighlight = (item) => { |
90 |
| - return props.chooseTagValue && |
91 |
| - props.chooseTagValue === item[props.optionTag] |
92 |
| - ? props.color |
93 |
| - : '#1a1a1a'; |
| 87 | + const isHighlight = (item: { [x: string]: string }) => { |
| 88 | + return props.chooseTagValue && props.chooseTagValue === item[props.optionTag] ? props.color : ''; |
94 | 89 | };
|
95 | 90 |
|
96 | 91 | const cancelActionSheet = () => {
|
97 | 92 | emit('cancel');
|
98 | 93 | emit('update:visible', false);
|
99 | 94 | };
|
100 | 95 |
|
101 |
| - const chooseItem = (item, index) => { |
102 |
| - if (!item.disable) { |
| 96 | + const chooseItem = (item: { disable: boolean; loading: boolean }, index: any) => { |
| 97 | + if (!item.disable && !item.loading) { |
103 | 98 | emit('choose', item, index);
|
104 | 99 | emit('update:visible', false);
|
105 | 100 | }
|
106 | 101 | };
|
107 | 102 |
|
108 |
| - const close = () => { |
109 |
| - emit('close'); |
| 103 | + const close = (e: Event) => { |
| 104 | + emit('close', e); |
110 | 105 | emit('update:visible', false);
|
111 | 106 | };
|
112 | 107 |
|
113 | 108 | return {
|
| 109 | + slotDefault, |
114 | 110 | isHighlight,
|
115 | 111 | cancelActionSheet,
|
116 | 112 | chooseItem,
|
|
0 commit comments