tui-dialog.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <template>
  2. <view>
  3. <view v-if="show" class="tui-dialog" :style="{background:backgroundColor,borderRadius:radius}" @tap.stop="stopEvent">
  4. <view class="tui-dialog__hd">
  5. <view class="tui-dialog__title" :style="{color:titleColor}">{{title}}
  6. <slot name="title"></slot>
  7. </view>
  8. </view>
  9. <view class="tui-dialog__bd" :style="{color:contentColor}">
  10. <slot name="content"></slot>
  11. </view>
  12. <view class="tui-dialog__ft">
  13. <block v-if="buttons && buttons.length">
  14. <view v-for="(item,index) in buttons" :key="index" :style="{color:item.color || '#333'}" class="tui-dialog__btn" :data-index="index" @tap="buttonTap">{{item.text}}</view>
  15. </block>
  16. <slot name="footer" v-else></slot>
  17. </view>
  18. </view>
  19. <view @tap="close" class="tui-dialog__mask" :class="{'tui-mask_hidden':!show}" v-if="mask"></view>
  20. </view>
  21. </template>
  22. <script>
  23. export default {
  24. name:'tuiDialog',
  25. emits: ['click','close'],
  26. props: {
  27. title: {
  28. type: String,
  29. default: ''
  30. },
  31. maskClosable: {
  32. type: Boolean,
  33. default: true
  34. },
  35. mask: {
  36. type: Boolean,
  37. default: true
  38. },
  39. show: {
  40. type: Boolean,
  41. default: false
  42. },
  43. buttons: {
  44. type: Array,
  45. default () {
  46. return []
  47. }
  48. },
  49. backgroundColor:{
  50. type:String,
  51. default:'#fff'
  52. },
  53. radius:{
  54. type:String,
  55. default:'12px'
  56. },
  57. titleColor:{
  58. type:String,
  59. default:'#333'
  60. },
  61. contentColor:{
  62. type:String,
  63. default:'#999'
  64. }
  65. },
  66. methods: {
  67. buttonTap(e) {
  68. const {
  69. index
  70. } = e.currentTarget.dataset;
  71. this.$emit('click', {
  72. index,
  73. item: this.buttons[index]
  74. });
  75. },
  76. close() {
  77. if (!this.maskClosable) return;
  78. this.$emit('close', {});
  79. },
  80. stopEvent() {}
  81. }
  82. }
  83. </script>
  84. <style>
  85. .tui-dialog {
  86. position: fixed;
  87. z-index: 5000;
  88. top: 50%;
  89. left: 16px;
  90. right: 16px;
  91. transform: translateY(-50%);
  92. text-align: center;
  93. overflow: hidden;
  94. display: flex;
  95. flex-direction: column;
  96. max-height: 90%;
  97. }
  98. .tui-dialog__hd {
  99. padding: 32px 24px 16px
  100. }
  101. .tui-dialog__title {
  102. font-weight: 700;
  103. font-size: 17px;
  104. line-height: 1.4
  105. }
  106. .tui-dialog__bd {
  107. overflow-y: auto;
  108. -webkit-overflow-scrolling: touch;
  109. padding: 0 24px;
  110. margin-bottom: 32px;
  111. font-size: 15px;
  112. line-height: 1.4;
  113. word-wrap: break-word;
  114. -webkit-hyphens: auto;
  115. hyphens: auto;
  116. }
  117. .tui-dialog__ft {
  118. display: flex;
  119. position: relative;
  120. line-height: 56px;
  121. min-height: 56px;
  122. font-size: 17px
  123. }
  124. .tui-dialog__ft:after {
  125. content: " ";
  126. position: absolute;
  127. left: 0;
  128. top: 0;
  129. right: 0;
  130. height: 1px;
  131. border-top: 1px solid rgba(0, 0, 0, .1);
  132. transform-origin: 0 0;
  133. transform: scaleY(.5)
  134. }
  135. .tui-dialog__btn {
  136. display: block;
  137. flex: 1;
  138. font-weight: 700;
  139. text-decoration: none;
  140. -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  141. position: relative
  142. }
  143. .tui-dialog__btn:active {
  144. background-color: #ECECEC
  145. }
  146. .tui-dialog__btn:first-child::after {
  147. width: 0;
  148. border-left: 0;
  149. }
  150. .tui-dialog__btn::after {
  151. content: " ";
  152. position: absolute;
  153. left: 0;
  154. top: 0;
  155. width: 1px;
  156. bottom: 0;
  157. border-left: 1px solid rgba(0,0,0,.1);
  158. transform-origin: 0 0;
  159. transform: scaleX(.5)
  160. }
  161. .tui-dialog__mask.tui-mask_hidden {
  162. opacity: 0;
  163. transform: scale3d(1, 1, 0)
  164. }
  165. .tui-dialog__mask {
  166. position: fixed;
  167. z-index: 1000;
  168. top: 0;
  169. right: 0;
  170. left: 0;
  171. bottom: 0;
  172. background: rgba(0, 0, 0, .6);
  173. opacity: 1;
  174. transform: scale3d(1, 1, 1);
  175. transition: all .2s ease-in
  176. }
  177. </style>