restructure/src/components/Modal/index.vue

56 lines
1.0 KiB
Vue
Raw Normal View History

2022-05-24 09:09:30 +08:00
<template>
2022-05-24 10:02:06 +08:00
<n-modal
v-bind="getModalOptions"
:style="`width:${getModalOptions.width}px`"
2022-05-24 16:52:14 +08:00
:title="options.title"
2022-05-24 10:02:06 +08:00
>
<n-card :bordered="false">
2022-05-24 09:09:30 +08:00
<slot name="Context" />
</n-card>
</n-modal>
</template>
<script>
2022-05-25 14:36:06 +08:00
import { defineComponent, computed } from 'vue'
2022-05-24 09:09:30 +08:00
export default defineComponent({
props: {
2022-05-24 09:20:29 +08:00
options: {
type: Object,
default: () => {}
2022-05-24 09:09:30 +08:00
}
},
emits: {
2022-05-25 14:36:06 +08:00
onConfirm: null,
2022-05-24 09:09:30 +08:00
onClose: (value) => {
return value
}
},
setup(props, { emit }) {
const getModalOptions = computed(() => {
2022-05-24 10:02:06 +08:00
return {
...props.options,
2022-05-25 14:36:06 +08:00
width: props.options.width || 600,
preset: props.options.preset || 'dialog',
showIcon: !!props.options.showIcon
2022-05-24 10:02:06 +08:00
}
2022-05-24 09:09:30 +08:00
})
2022-05-25 14:36:06 +08:00
const handleConfirm = function() {
emit('onConfirm')
return false
2022-05-24 09:09:30 +08:00
}
2022-05-24 10:02:06 +08:00
const handleClose = function() {
2022-05-24 09:09:30 +08:00
emit('onClose', true)
}
return {
getModalOptions,
2022-05-25 14:36:06 +08:00
handleConfirm,
2022-05-24 10:02:06 +08:00
handleClose
2022-05-24 09:09:30 +08:00
}
}
})
</script>
<style scoped lang='scss'>
</style>