tui-modal.vue 6.9 KB

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