12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- import { Dialog } from 'vant'
- import { defineComponent, PropType, reactive, watch } from 'vue'
- import styles from './index.module.less'
- export default defineComponent({
- name: 'o-dialog',
- props: {
- show: {
- type: Boolean,
- default: false
- },
- message: {
- type: String,
- default: ''
- },
- title: {
- type: String,
- default: '提示'
- },
- confirmButtonText: {
- type: String,
- default: '确认'
- },
- cancelButtonText: {
- type: String,
- default: '取消'
- },
- showConfirmButton: {
- type: Boolean,
- default: true
- },
- showCancelButton: {
- type: Boolean,
- default: false
- },
- messageAlign: {
- type: String as PropType<'left' | 'center' | 'right'>,
- default: 'center'
- },
- dialogMarginTop: {
- type: String,
- default: '0px'
- }
- },
- emits: ['cancel', 'confirm', 'update:show'],
- setup(props, { emit }) {
- const state = reactive({
- show: props.show || false
- })
- // 监听状态
- watch(
- () => props.show,
- () => {
- state.show = props.show
- }
- )
- return () => (
- <Dialog
- class={styles.oDialog}
- style={{
- marginTop: props.dialogMarginTop
- }}
- v-model:show={state.show}
- message={props.message}
- messageAlign={props.messageAlign}
- confirmButtonText={props.confirmButtonText}
- cancelButtonText={props.cancelButtonText}
- showConfirmButton={props.showConfirmButton}
- showCancelButton={props.showCancelButton}
- onConfirm={() => {
- emit('update:show', false)
- emit('confirm')
- }}
- onCancel={() => {
- emit('update:show', false)
- emit('cancel')
- }}
- >
- {{
- title: () => (
- <div class={styles.dialogTitle}>
- <i></i>
- {props.title}
- </div>
- )
- }}
- </Dialog>
- )
- }
- })
|