index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <template>
  2. <view class="tui-modal__container" :class="[show ? 'tui-modal-show' : '']" :style="{zIndex:zIndex}">
  3. <view class="tui-modal-box"
  4. :class="[fadeIn || show ? 'tui-modal-normal' : 'tui-modal-scale', show ? 'tui-modal-show' : '']">
  5. <view v-if="!custom">
  6. <view class="tui-modal-title" v-if="title">{{ title }}</view>
  7. <view class="tui-modal-content" :class="[title ? '' : 'tui-mtop']"
  8. >{{ content }}</view>
  9. <view class="tui-modalBtn-box">
  10. <view class="tui-modal-btn flex-center tui-modal-btn-cancel" @tap="handleClick(0)">{{cancelText}}</view>
  11. <view class="tui-modal-btn flex-center tui-modal-btn-confirm" @tap="handleClick(1)">{{confirmText}}</view>
  12. </view>
  13. </view>
  14. <view v-else>
  15. <slot></slot>
  16. </view>
  17. </view>
  18. <view v-if="isMask" class="tui-modal-mask" :class="[show ? 'tui-mask-show' : '']"
  19. :style="{zIndex:maskZIndex,background:maskColor}" @tap="handleClickCancel"
  20. @touchmove.stop.prevent></view>
  21. </view>
  22. </template>
  23. <script>
  24. export default {
  25. name: 'tuiModal',
  26. emits: ['click', 'cancel'],
  27. props: {
  28. //是否显示
  29. show: {
  30. type: Boolean,
  31. default: false
  32. },
  33. //标题
  34. title: {
  35. type: String,
  36. default: ''
  37. },
  38. //内容
  39. content: {
  40. type: String,
  41. default: ''
  42. },
  43. cancelText:{
  44. type: String,
  45. default: '取消'
  46. },
  47. confirmText:{
  48. type: String,
  49. default: '确定'
  50. },
  51. //点击遮罩 是否可关闭
  52. maskClosable: {
  53. type: Boolean,
  54. default: true
  55. },
  56. //是否显示mask
  57. isMask: {
  58. type: Boolean,
  59. default: true
  60. },
  61. maskColor: {
  62. type: String,
  63. default: 'rgba(0, 0, 0, 0.6)'
  64. },
  65. //淡入效果,自定义弹框插入input输入框时传true
  66. fadeIn: {
  67. type: Boolean,
  68. default: false
  69. },
  70. //自定义弹窗内容
  71. custom: {
  72. type: Boolean,
  73. default: false
  74. },
  75. //容器z-index
  76. zIndex: {
  77. type: Number,
  78. default: 9997
  79. },
  80. //mask z-index
  81. maskZIndex: {
  82. type: Number,
  83. default: 9990
  84. }
  85. },
  86. data() {
  87. return {};
  88. },
  89. methods: {
  90. handleClick(index) {
  91. if (!this.show) return;
  92. this.$emit('click', {
  93. index: Number(index)
  94. });
  95. },
  96. handleClickCancel() {
  97. if (!this.maskClosable) return;
  98. this.$emit('cancel');
  99. }
  100. }
  101. };
  102. </script>
  103. <style scoped>
  104. .tui-modal__container {
  105. width: 100%;
  106. height: 100%;
  107. position: fixed;
  108. left: 0;
  109. top: 0;
  110. display: flex;
  111. align-items: center;
  112. justify-content: center;
  113. visibility: hidden;
  114. }
  115. .tui-modal-box {
  116. position: relative;
  117. opacity: 0;
  118. visibility: hidden;
  119. box-sizing: border-box;
  120. transition: all 0.3s ease-in-out;
  121. width:600rpx;
  122. padding: 40rpx;
  123. border-radius:32rpx;
  124. background-color: #fff;
  125. z-index: 9999;
  126. }
  127. .tui-modal-scale {
  128. transform: scale(0);
  129. }
  130. .tui-modal-normal {
  131. transform: scale(1);
  132. }
  133. .tui-modal-show {
  134. opacity: 1;
  135. visibility: visible;
  136. }
  137. .tui-modal-mask {
  138. position: fixed;
  139. top: 0;
  140. left: 0;
  141. right: 0;
  142. bottom: 0;
  143. transition: all 0.3s ease-in-out;
  144. opacity: 0;
  145. visibility: hidden;
  146. }
  147. .tui-mask-show {
  148. visibility: visible;
  149. opacity: 1;
  150. }
  151. .tui-modal-title {
  152. text-align: center;
  153. font-size: 32rpx;
  154. line-height: 52rpx;
  155. color: #333;
  156. font-weight: 500;
  157. }
  158. .tui-modal-content {
  159. text-align: center;
  160. color: #666;
  161. font-size: 30rpx;
  162. line-height: 40rpx;
  163. margin: 24rpx auto 40rpx;
  164. }
  165. .tui-mtop {
  166. margin-top: 30rpx;
  167. }
  168. .tui-mbtm {
  169. margin-bottom: 30rpx;
  170. }
  171. .tui-modalBtn-box {
  172. width: 100%;
  173. display: flex;
  174. align-items: center;
  175. justify-content: space-between;
  176. }
  177. .tui-flex-column {
  178. flex-direction: column;
  179. }
  180. .tui-modal-btn {
  181. width: 244rpx;
  182. height: 72rpx;
  183. border-radius: 36rpx;
  184. font-size: 26rpx;
  185. }
  186. .tui-modal-btn-cancel{
  187. border: 1px solid var(--view-theme);
  188. color: var(--view-theme);
  189. }
  190. .tui-modal-btn-confirm{
  191. background-color: var(--view-theme);
  192. color: #fff;
  193. }
  194. </style>