tui-modal.vue 8.4 KB

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