index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <template>
  2. <div
  3. v-if="_isShow"
  4. class="pop"
  5. @click.stop.prevent="toggleView(clickType.OUTSIDE)"
  6. >
  7. <main
  8. class="pop-main"
  9. :class="[!isPC ? 'pop-main-h5' : '']"
  10. @click.stop.prevent="toggleView(clickType.INSIDE)"
  11. >
  12. <header
  13. v-if="isHeaderShow"
  14. class="pop-main-header"
  15. >
  16. <h1 class="pop-main-title">
  17. {{ title }}
  18. </h1>
  19. </header>
  20. <div
  21. class="pop-main-content"
  22. :class="[isUniFrameWork && isH5 ? 'pop-main-content-uniapp' : '']"
  23. >
  24. <slot />
  25. </div>
  26. <footer class="pop-main-footer">
  27. <button
  28. v-if="isConfirmButtonShow"
  29. class="btn btn-confirm"
  30. @click="popConfirm()"
  31. >
  32. {{ TUITranslateService.t(confirmButtonText) }}
  33. </button>
  34. <button
  35. v-if="isCancelButtonShow"
  36. class="btn btn-cancel"
  37. @click="popCancel()"
  38. >
  39. {{ TUITranslateService.t(cancelButtonText) }}
  40. </button>
  41. </footer>
  42. </main>
  43. </div>
  44. </template>
  45. <script lang="ts" setup>
  46. import { ref, toRefs, watchEffect } from '../../../adapter-vue';
  47. import {
  48. TUIGlobal,
  49. TUITranslateService,
  50. } from '@tencentcloud/chat-uikit-engine';
  51. import { isUniFrameWork } from '../../../utils/env';
  52. const props = withDefaults(
  53. defineProps<{
  54. isShow: boolean;
  55. title?: string;
  56. isHeaderShow?: boolean;
  57. isConfirmButtonShow?: boolean;
  58. isCancelButtonShow?: boolean;
  59. confirmButtonText?: string;
  60. cancelButtonText?: string;
  61. }>(),
  62. {
  63. isShow: false,
  64. isHeaderShow: false,
  65. isConfirmButtonShow: true,
  66. isCancelButtonShow: true,
  67. confirmButtonText: '确定',
  68. cancelButtonText: '取消',
  69. },
  70. );
  71. const { isShow } = toRefs(props);
  72. const clickType = {
  73. OUTSIDE: 'outside',
  74. INSIDE: 'inside',
  75. };
  76. const isPC = ref(TUIGlobal.getPlatform() === 'pc');
  77. const isH5 = ref(TUIGlobal.getPlatform() === 'h5');
  78. const _isShow = ref<boolean>(false);
  79. const emit = defineEmits(['update:show', 'popConfirm']);
  80. const toggleView = (type: string) => {
  81. if (type === clickType.OUTSIDE) {
  82. popCancel();
  83. }
  84. };
  85. watchEffect(() => {
  86. _isShow.value = isShow.value;
  87. });
  88. function popCancel() {
  89. _isShow.value = !_isShow.value;
  90. emit('update:show', _isShow.value);
  91. }
  92. function popConfirm() {
  93. emit('popConfirm');
  94. popCancel();
  95. }
  96. </script>
  97. <style lang="scss" scoped>
  98. $pop-bg-color: #fff;
  99. $pop-header: #333;
  100. $confirm-bg-color: #006EFF;
  101. $confirm-text-color: #fff;
  102. $concel-bg-color: #666;
  103. $content-color: #333;
  104. .pop {
  105. background: rgba(0, 0, 0, .3);
  106. position: fixed;
  107. width: 100%;
  108. height: 100%;
  109. left: 0;
  110. top: 0;
  111. z-index: 6;
  112. display: flex;
  113. justify-content: center;
  114. align-items: center;
  115. &-main {
  116. min-width: 368px;
  117. border-radius: 10px;
  118. padding: 20px 30px;
  119. max-width: 380px;
  120. background: $pop-bg-color;
  121. &-header {
  122. display: flex;
  123. justify-content: space-between;
  124. align-items: center;
  125. font-size: 16px;
  126. line-height: 30px;
  127. font-weight: 500;
  128. color: $pop-header;
  129. }
  130. &-title {
  131. font-size: 16px;
  132. line-height: 30px;
  133. font-family: PingFangSC-Medium;
  134. font-weight: 500;
  135. color: $content-color;
  136. }
  137. &-content {
  138. font-size: 14px;
  139. display: flex;
  140. justify-content: center;
  141. align-items: center;
  142. margin-bottom: 20px;
  143. font-weight: 400;
  144. color: $content-color;
  145. }
  146. &-footer {
  147. display: flex;
  148. justify-content: flex-end;
  149. }
  150. }
  151. }
  152. .pop-main-h5 {
  153. min-width: 220px;
  154. max-width: 260px;
  155. }
  156. .btn {
  157. padding: 8px 20px;
  158. margin: 0 6px;
  159. border-radius: 4px;
  160. border: none;
  161. font-size: 14px;
  162. text-align: center;
  163. line-height: 20px;
  164. &-cancel {
  165. // border: 1px solid #dddddd;
  166. color: $concel-bg-color;
  167. }
  168. &-confirm {
  169. background: $confirm-bg-color;
  170. border: 1px solid $confirm-bg-color;
  171. color: $confirm-text-color;
  172. }
  173. }
  174. </style>