tui-modal.vue 6.3 KB

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