index.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import { Dialog } from 'vant';
  2. import { defineComponent, PropType, reactive, watch } from 'vue';
  3. import styles from './index.module.less';
  4. export default defineComponent({
  5. name: 'o-dialog',
  6. props: {
  7. show: {
  8. type: Boolean,
  9. default: false
  10. },
  11. message: {
  12. type: String,
  13. default: ''
  14. },
  15. title: {
  16. type: String,
  17. default: '提示'
  18. },
  19. confirmButtonText: {
  20. type: String,
  21. default: '确认'
  22. },
  23. cancelButtonText: {
  24. type: String,
  25. default: '取消'
  26. },
  27. showConfirmButton: {
  28. type: Boolean,
  29. default: true
  30. },
  31. showCancelButton: {
  32. type: Boolean,
  33. default: false
  34. },
  35. messageAlign: {
  36. type: String as PropType<'left' | 'center' | 'right'>,
  37. default: 'center'
  38. },
  39. dialogMarginTop: {
  40. type: String,
  41. default: '0px'
  42. },
  43. allowHtml: {
  44. type: Boolean,
  45. default: false
  46. }
  47. },
  48. emits: ['cancel', 'confirm', 'update:show'],
  49. setup(props, { emit }) {
  50. const state = reactive({
  51. show: props.show || false
  52. });
  53. // 监听状态
  54. watch(
  55. () => props.show,
  56. () => {
  57. state.show = props.show;
  58. }
  59. );
  60. return () => (
  61. <Dialog
  62. class={styles.oDialog}
  63. style={{
  64. marginTop: props.dialogMarginTop
  65. }}
  66. v-model:show={state.show}
  67. message={props.message}
  68. messageAlign={props.messageAlign}
  69. allowHtml={props.allowHtml}
  70. confirmButtonText={props.confirmButtonText}
  71. cancelButtonText={props.cancelButtonText}
  72. showConfirmButton={props.showConfirmButton}
  73. showCancelButton={props.showCancelButton}
  74. onConfirm={() => {
  75. emit('update:show', false);
  76. emit('confirm');
  77. }}
  78. onCancel={() => {
  79. emit('update:show', false);
  80. emit('cancel');
  81. }}>
  82. {{
  83. title: () => (
  84. <div class={styles.dialogTitle}>
  85. <i></i>
  86. {props.title}
  87. </div>
  88. )
  89. }}
  90. </Dialog>
  91. );
  92. }
  93. });