ykt-wxapp/components/button-footer.vue

58 lines
1.7 KiB
Vue
Raw Normal View History

2026-01-19 18:52:18 +08:00
<template>
2026-01-23 14:36:28 +08:00
<view v-if="showCancel || showConfirm" class="relative flex px-15 py-12 bg-white text-center"
2026-02-10 13:52:54 +08:00
:class="showShadow ? 'shadow-up' : ''">
<view v-if="showCancel && customCancel" class="relative" :style="widthStyle">
<slot name="cancel"></slot>
</view>
<view v-else-if="showCancel" class="py-10 text-base border-primary rounded text-primary rounded" :style="widthStyle"
2026-01-19 18:52:18 +08:00
@click="cancel()">
{{ cancelText }}
</view>
2026-02-10 13:52:54 +08:00
<view v-if="showConfirm && customConfirm" :class="showCancel && showConfirm ? 'ml-15' : ''" :style="widthStyle">
<slot name="confirm"></slot>
</view>
<view v-else-if="showConfirm" class="py-10 text-base border-primary bg-primary text-white rounded"
:class="showCancel && showConfirm ? 'ml-15' : ''" :style="widthStyle" @click="confirm()">
2026-01-19 18:52:18 +08:00
{{ confirmText }}
</view>
</view>
</template>
<script setup>
2026-02-10 13:52:54 +08:00
import { computed, useSlots, ref } from "vue";
2026-01-19 18:52:18 +08:00
import useDebounce from '@/utils/useDebounce';
const emits = defineEmits(['cancel', 'confirm']);
const props = defineProps({
2026-02-10 13:52:54 +08:00
showShadow: {
2026-01-19 18:52:18 +08:00
type: Boolean,
2026-02-10 13:52:54 +08:00
default: true
2026-01-19 18:52:18 +08:00
},
cancelText: {
type: String,
default: '取消'
},
confirmText: {
type: String,
default: '确认'
},
showCancel: {
type: Boolean,
default: true
},
showConfirm: {
type: Boolean,
default: true
}
})
const cancel = useDebounce(() => emits('cancel'));
const confirm = useDebounce(() => emits('confirm'));
2026-02-10 13:52:54 +08:00
const slots = useSlots();
const customCancel = computed(() => !!slots.cancel);
const customConfirm = computed(() => !!slots.confirm);
const widthStyle = computed(() => {
const val = [props.showCancel, props.showConfirm].filter(Boolean);
return `width: ${100 / (val.length || 1)}%`
})
2026-01-19 18:52:18 +08:00
</script>