index.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <div
  3. v-if="showDialog"
  4. class="dialog"
  5. :class="[!isPC ? 'dialog-h5' : '', center ? 'center' : '']"
  6. @click.stop.prevent="toggleView(clickType.OUTSIDE)"
  7. >
  8. <main
  9. class="dialog-main"
  10. :class="[!backgroundDialog ? 'dialog-main-back' : '']"
  11. @click.stop.prevent="toggleView(clickType.INSIDE)"
  12. >
  13. <header
  14. v-if="isHeaderShowDialog"
  15. class="dialog-main-header"
  16. >
  17. <h1 class="dialog-main-title">
  18. {{ showTitle }}
  19. </h1>
  20. <i
  21. class="icon icon-close"
  22. @click="close"
  23. />
  24. </header>
  25. <div
  26. class="dialog-main-content"
  27. :class="[isUniFrameWork && isH5 ? 'dialog-main-content-uniapp' : '']"
  28. >
  29. <slot />
  30. </div>
  31. <footer
  32. v-if="isFooterShowDialog"
  33. class="dialog-main-footer"
  34. >
  35. <button
  36. class="btn btn-cancel"
  37. @click="close"
  38. >
  39. {{ TUITranslateService.t('component.取消') }}
  40. </button>
  41. <button
  42. class="btn btn-default"
  43. @click="submit"
  44. >
  45. {{ TUITranslateService.t('component.确定') }}
  46. </button>
  47. </footer>
  48. </main>
  49. </div>
  50. </template>
  51. <script lang="ts" setup>
  52. import { ref, watchEffect } from '../../../adapter-vue';
  53. import { TUITranslateService } from '@tencentcloud/chat-uikit-engine';
  54. import { isPC, isH5, isUniFrameWork } from '../../../utils/env';
  55. const clickType = {
  56. OUTSIDE: 'outside',
  57. INSIDE: 'inside',
  58. };
  59. const props = defineProps({
  60. show: {
  61. type: Boolean,
  62. default: false,
  63. },
  64. isHeaderShow: {
  65. type: Boolean,
  66. default: true,
  67. },
  68. isFooterShow: {
  69. type: Boolean,
  70. default: true,
  71. },
  72. background: {
  73. type: Boolean,
  74. default: true,
  75. },
  76. title: {
  77. type: String,
  78. default: '',
  79. },
  80. center: {
  81. type: Boolean,
  82. default: false,
  83. },
  84. });
  85. const showDialog = ref(false);
  86. const isHeaderShowDialog = ref(true);
  87. const isFooterShowDialog = ref(true);
  88. const backgroundDialog = ref(true);
  89. const showTitle = ref('');
  90. watchEffect(() => {
  91. showDialog.value = props.show;
  92. showTitle.value = props.title;
  93. isHeaderShowDialog.value = props.isHeaderShow;
  94. isFooterShowDialog.value = props.isFooterShow;
  95. backgroundDialog.value = props.background;
  96. });
  97. const emit = defineEmits(['update:show', 'submit']);
  98. const toggleView = (type: string) => {
  99. if (type === clickType.OUTSIDE) {
  100. close();
  101. }
  102. };
  103. const close = () => {
  104. showDialog.value = !showDialog.value;
  105. emit('update:show', showDialog.value);
  106. };
  107. const submit = () => {
  108. emit('submit');
  109. close();
  110. };
  111. </script>
  112. <style lang="scss" scoped src="./style/dialog.scss"></style>