tui-modal.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. <template>
  2. <view @touchmove.stop.prevent>
  3. <view class="tui-modal-box" :style="{width:width,padding:padding,borderRadius:radius}" :class="[(fadeIn || show)?'tui-modal-normal':'tui-modal-scale',show?'tui-modal-show':'']">
  4. <view v-if="!custom">
  5. <view class="tui-modal-title" v-if="title">{{title}}</view>
  6. <view class="tui-modal-content" :class="[title?'':'tui-mtop']" :style="{color:color,fontSize:size+'rpx'}">{{content}}</view>
  7. <view class="tui-modalBtn-box" :class="[button.length!=2?'tui-flex-column':'']">
  8. <block v-for="(item,index) in button" :key="index">
  9. <!-- :style="{background: item.customStyle.bgColor ? item.customStyle.bgColor : '',color: item.customStyle.color ? item.customStyle.color : ''}" -->
  10. <button class="tui-modal-btn" :class="[(!item.customStyle && ('tui-'+(item.type || 'primary')+(item.plain?'-outline':''))),button.length!=2?'tui-btn-width':'',button.length>2?'tui-mbtm':'',shape=='circle'?'tui-circle-btn':'']"
  11. :style="{background: item.customStyle.bgColor ? item.customStyle.bgColor : '',color: item.customStyle.color ? item.customStyle.color : '',fontSize: item.customStyle.fontSize ? item.customStyle.fontSize : ''}"
  12. :hover-class="!item.customStyle && ('tui-'+(item.plain?'outline':(item.type || 'primary'))+'-hover')" :data-index="index" @tap="handleClick">{{item.text || "确定"}}</button>
  13. </block>
  14. </view>
  15. </view>
  16. <view v-else>
  17. <slot></slot>
  18. </view>
  19. </view>
  20. <view class="tui-modal-mask" :class="[show?'tui-mask-show':'']" @tap="handleClickCancel"></view>
  21. </view>
  22. </template>
  23. <script>
  24. export default {
  25. name: 'tuiModal',
  26. props: {
  27. //是否显示
  28. show: {
  29. type: Boolean,
  30. default: false
  31. },
  32. width: {
  33. type: String,
  34. default: '84%'
  35. },
  36. padding: {
  37. type: String,
  38. default: '40rpx 64rpx'
  39. },
  40. radius: {
  41. type: String,
  42. default: '24rpx'
  43. },
  44. //标题
  45. title: {
  46. type: String,
  47. default: ''
  48. },
  49. //内容
  50. content: {
  51. type: String,
  52. default: ''
  53. },
  54. //内容字体颜色
  55. color: {
  56. type: String,
  57. default: '#999'
  58. },
  59. //内容字体大小 rpx
  60. size: {
  61. type: Number,
  62. default: 28
  63. },
  64. //形状 circle, square
  65. shape: {
  66. type: String,
  67. default: 'square'
  68. },
  69. button: {
  70. type: Array,
  71. default: function() {
  72. return [{
  73. text: '取消',
  74. type: 'danger',
  75. plain: true //是否空心
  76. }, {
  77. text: '确定',
  78. type: 'danger',
  79. plain: false
  80. }]
  81. }
  82. },
  83. //点击遮罩 是否可关闭
  84. maskClosable: {
  85. type: Boolean,
  86. default: true
  87. },
  88. //淡入效果,自定义弹框插入input输入框时传true
  89. fadeIn: {
  90. type: Boolean,
  91. default: false
  92. },
  93. //自定义弹窗内容
  94. custom: {
  95. type: Boolean,
  96. default: false
  97. }
  98. },
  99. data() {
  100. return {
  101. }
  102. },
  103. methods: {
  104. handleClick(e) {
  105. if (!this.show) return
  106. const dataset = e.currentTarget.dataset
  107. this.$emit('click', {
  108. index: Number(dataset.index)
  109. })
  110. },
  111. handleClickCancel() {
  112. if (!this.maskClosable) return
  113. this.$emit('cancel')
  114. }
  115. }
  116. }
  117. </script>
  118. <style scoped>
  119. .tui-modal-box {
  120. position: fixed;
  121. left: 50%;
  122. top: 50%;
  123. margin: auto;
  124. background-color: #fff;
  125. z-index: 9999998;
  126. transition: all 0.3s ease-in-out;
  127. opacity: 0;
  128. box-sizing: border-box;
  129. visibility: hidden;
  130. }
  131. .tui-modal-scale {
  132. transform: translate(-50%, -50%) scale(0);
  133. }
  134. .tui-modal-normal {
  135. transform: translate(-50%, -50%) scale(1);
  136. }
  137. .tui-modal-show {
  138. opacity: 1;
  139. visibility: visible;
  140. }
  141. .tui-modal-mask {
  142. position: fixed;
  143. top: 0;
  144. left: 0;
  145. right: 0;
  146. bottom: 0;
  147. background-color: rgba(0, 0, 0, 0.6);
  148. z-index: 9999996;
  149. transition: all 0.3s ease-in-out;
  150. opacity: 0;
  151. visibility: hidden;
  152. }
  153. .tui-mask-show {
  154. visibility: visible;
  155. opacity: 1;
  156. }
  157. .tui-modal-title {
  158. text-align: center;
  159. font-size: 34rpx;
  160. color: #333;
  161. padding-top: 20rpx;
  162. font-weight: bold;
  163. }
  164. .tui-modal-content {
  165. text-align: center;
  166. color: #999;
  167. font-size: 28rpx;
  168. padding-top: 20rpx;
  169. padding-bottom: 60rpx;
  170. }
  171. .tui-mtop {
  172. margin-top: 30rpx;
  173. }
  174. .tui-mbtm {
  175. margin-bottom: 30rpx;
  176. }
  177. .tui-modalBtn-box {
  178. width: 100%;
  179. display: flex;
  180. align-items: center;
  181. justify-content: space-between
  182. }
  183. .tui-flex-column {
  184. flex-direction: column;
  185. }
  186. .tui-modal-btn {
  187. width: 46%;
  188. height: 68rpx;
  189. line-height: 68rpx;
  190. position: relative;
  191. border-radius: 10rpx;
  192. font-size: 26rpx;
  193. overflow: visible;
  194. margin-left: 0;
  195. margin-right: 0;
  196. }
  197. .tui-modal-btn::after {
  198. content: " ";
  199. position: absolute;
  200. width: 200%;
  201. height: 200%;
  202. -webkit-transform-origin: 0 0;
  203. transform-origin: 0 0;
  204. -webkit-transform: scale(0.5, 0.5);
  205. transform: scale(0.5, 0.5);
  206. left: 0;
  207. top: 0;
  208. border-radius: 20rpx;
  209. }
  210. .tui-btn-width {
  211. width: 80% !important;
  212. }
  213. .tui-primary {
  214. background: #5677fc;
  215. color: #fff;
  216. }
  217. .tui-primary-hover {
  218. background: #4a67d6;
  219. color: #e5e5e5;
  220. }
  221. .tui-primary-outline {
  222. color: #5677fc;
  223. background: transparent;
  224. }
  225. .tui-primary-outline::after {
  226. border: 1px solid #5677fc;
  227. }
  228. .tui-danger {
  229. background: #F3B574;
  230. color: #fff;
  231. }
  232. .tui-danger-hover {
  233. background: #d53912;
  234. color: #e5e5e5;
  235. }
  236. .tui-danger-outline {
  237. color: #F3B574;
  238. background: transparent;
  239. }
  240. .tui-danger-outline::after {
  241. border: 1px solid #F3B574;
  242. }
  243. .tui-red {
  244. background: #e41f19;
  245. color: #fff;
  246. }
  247. .tui-red-hover {
  248. background: #c51a15;
  249. color: #e5e5e5;
  250. }
  251. .tui-red-outline {
  252. color: #e41f19;
  253. background: transparent;
  254. }
  255. .tui-red-outline::after {
  256. border: 1px solid #e41f19;
  257. }
  258. .tui-warning {
  259. background: #ff7900;
  260. color: #fff;
  261. }
  262. .tui-warning-hover {
  263. background: #e56d00;
  264. color: #e5e5e5;
  265. }
  266. .tui-warning-outline {
  267. color: #ff7900;
  268. background: transparent;
  269. }
  270. .tui-warning-outline::after {
  271. border: 1px solid #ff7900;
  272. }
  273. .tui-green {
  274. background: #19be6b;
  275. color: #fff;
  276. }
  277. .tui-green-hover {
  278. background: #16ab60;
  279. color: #e5e5e5;
  280. }
  281. .tui-green-outline {
  282. color: #19be6b;
  283. background: transparent;
  284. }
  285. .tui-green-outline::after {
  286. border: 1px solid #19be6b;
  287. }
  288. .tui-white {
  289. background: #fff;
  290. color: #333;
  291. }
  292. .tui-white-hover {
  293. background: #f7f7f9;
  294. color: #666;
  295. }
  296. .tui-white-outline {
  297. color: #333;
  298. background: transparent;
  299. }
  300. .tui-white-outline::after {
  301. border: 1px solid #333;
  302. }
  303. .tui-gray {
  304. background: #ededed;
  305. color: #999;
  306. }
  307. .tui-gray-hover {
  308. background: #d5d5d5;
  309. color: #898989;
  310. }
  311. .tui-gray-outline {
  312. color: #999;
  313. background: transparent;
  314. }
  315. .tui-gray-outline::after {
  316. border: 1px solid #999;
  317. }
  318. .tui-outline-hover {
  319. opacity: 0.6;
  320. }
  321. .tui-circle-btn {
  322. border-radius: 40rpx !important;
  323. }
  324. .tui-circle-btn::after {
  325. border-radius: 80rpx !important;
  326. }
  327. </style>