123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- 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>
- );
- }
- });
|