modal.vue 6.2 KB

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