modal.vue 6.2 KB

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